/me/insanj/BlockBlocker/BlockBlocker.java

https://bitbucket.org/insanj/blockblocker · Java · 103 lines · 54 code · 16 blank · 33 comment · 2 complexity · 1882db3e2899995450b079f297cf23a3 MD5 · raw file

  1. /*
  2. Created by Julian Weiss (insanj), updates frequent on Google+ (and sometimes Twitter)!
  3. Please do not modify or decompile at any date, but feel free to distribute with credit.
  4. Designed and created entirely on Wednesday, August 10th, 2011.
  5. Last edited on: 8/12/11
  6. BlockBlocker version 1.1!
  7. Special thanks to:
  8. powback, for the idea and design!
  9. RugRats, for more ideas in the 1.1 update.
  10. Works with the current CraftBukkit Build (#1000).
  11. All other information should be available at bukkit.org under BlockBlocker.
  12. THIS VERSION CURRENT HAS TWO CLASSES:
  13. BlockBlocker.java
  14. BlockBlockerListener.java
  15. */
  16. package me.insanj.BlockBlocker;
  17. import java.io.File;
  18. import java.io.FileWriter;
  19. import java.util.logging.Logger;
  20. import org.bukkit.ChatColor;
  21. import org.bukkit.command.Command;
  22. import org.bukkit.command.CommandSender;
  23. import org.bukkit.entity.Player;
  24. import org.bukkit.event.Event;
  25. import org.bukkit.plugin.PluginManager;
  26. import org.bukkit.plugin.java.JavaPlugin;
  27. public class BlockBlocker extends JavaPlugin{
  28. BlockBlockerListener blockListener = new BlockBlockerListener(this);
  29. Logger log = Logger.getLogger("Minecraft");
  30. String version = "1.1";
  31. public void onEnable(){
  32. PluginManager pm = getServer().getPluginManager();
  33. pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
  34. log.info("{BlockBlocker} version " + version + " (by insanj) has been enabled!");
  35. }
  36. public void onDisable(){
  37. log.info("{BlockBlocker} version " + version + " (by insanj) has been disabled.");
  38. }
  39. @Override
  40. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  41. if(commandLabel.equalsIgnoreCase("block")){
  42. generateConfig();
  43. if(sender instanceof Player)
  44. sender.sendMessage(ChatColor.GREEN + "Config generated successfully.");
  45. else
  46. log.info("Config generated successfully.");
  47. }
  48. return true;
  49. }//end onCommand()
  50. public void generateConfig(){
  51. try{
  52. new File("plugins/BlockBlocker").mkdir();
  53. File file = new File("plugins/BlockBlocker/blocked.txt");
  54. FileWriter output = new FileWriter(file, false);
  55. output.write("Use this config file to list material names to have them blocked.\n");
  56. output.write("Applicable materials can be found in the Bukkit javadocs. A few are already set below.\n");
  57. output.write("sign\n");
  58. output.write("sign_post\n");
  59. output.write("torch\n");
  60. output.write("redstone_torch\n");
  61. output.write("button\n");
  62. output.write("lever\n");
  63. output.close();
  64. } catch(Exception e){
  65. log.severe("{BlockBlocker} couldn't generate a config file: ");
  66. e.printStackTrace();
  67. }
  68. }//end generateConfig()
  69. }//end class BlockBlocker
  70. /***********************************Contents of "plugin.yml":*******************************
  71. name: BlockBlocker
  72. version: 1.1
  73. author: insanj
  74. main: me.insanj.BlockBlocker.BlockBlocker
  75. description: Doesn't allow any user to place a block against a sign.
  76. commands:
  77. block:
  78. description: Generates the config file, to allow multiple blocked items.
  79. usage: /<command>
  80. ******************************************************************************************/