/me/insanj/TreeOctopus/TreeOctopus.java

https://bitbucket.org/insanj/treeoctopus · Java · 122 lines · 62 code · 21 blank · 39 comment · 12 complexity · f50c3f113e8f259ca998c38c9be2d70e 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. Production began on Tuesday, August 2nd, 2011.
  5. Last edited on: 8/13/11
  6. Pacific Northwest Tree Octopus Version 1.1!
  7. Special thanks to:
  8. Camcade, Carlthealpaca, and Gonjigas for design and publicity and pretty much everything but the coding and whatnot.
  9. Works with the current CraftBukkit Build (#1000).
  10. All other information should be available at bukkit.org under The Pacific Northwest Tree Octopus.
  11. Currently supports:
  12. Permissions plugin, version 3.1.6!
  13. THIS VERSION CURRENT HAS TWO CLASSES:
  14. TreeOctopus.java
  15. TreeOctopusListener.java
  16. */
  17. package me.insanj.TreeOctopus;
  18. import java.util.ArrayList;
  19. import java.util.logging.Logger;
  20. import org.bukkit.ChatColor;
  21. import org.bukkit.plugin.Plugin;
  22. import org.bukkit.plugin.PluginManager;
  23. import org.bukkit.command.Command;
  24. import org.bukkit.command.CommandSender;
  25. import org.bukkit.entity.Player;
  26. import org.bukkit.event.Event;
  27. import org.bukkit.plugin.java.JavaPlugin;
  28. import com.nijiko.permissions.PermissionHandler;
  29. import com.nijikokun.bukkit.Permissions.Permissions;
  30. public class TreeOctopus extends JavaPlugin
  31. {
  32. private static final Logger log = Logger.getLogger("Minecraft");
  33. OctopusBlockListener blockListener = new OctopusBlockListener(this);
  34. OctopusPlayerListener playerListener = new OctopusPlayerListener(this);
  35. private static final String version = "1.1";
  36. ArrayList<Player> users = new ArrayList<Player>();
  37. public static boolean permissions;
  38. public PermissionHandler permissionHandler;
  39. @Override
  40. public void onEnable(){
  41. setupPermissions();
  42. PluginManager pm = getServer().getPluginManager();
  43. pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
  44. pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this);
  45. log.info("{TreeOctopus} plugin version " + version + " has successfully started.");
  46. }
  47. @Override
  48. public void onDisable() {
  49. log.info("{TreeOctopus} plugin version " + version + " disabled.");
  50. }
  51. private void setupPermissions() {
  52. Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
  53. if (this.permissionHandler == null) {
  54. if (permissionsPlugin != null)
  55. this.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
  56. else{
  57. log.info("{TreeOctopus} could not detect a Permissions system, which is fine, but everyone will have to use the command to disable.");
  58. permissions = false;
  59. }
  60. }//end if
  61. }//end setupPermissions()
  62. @Override
  63. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
  64. {
  65. if(commandLabel.equalsIgnoreCase("octopus")){
  66. sender.sendMessage(ChatColor.RED + "You have disabled the TreeOctopus plugin. Farewell, traveler.");
  67. users.add((Player) sender);
  68. }
  69. return true;
  70. }//end method onCommand()
  71. public boolean enabled(Player player){
  72. if( permissions == false && !users.contains(player) )
  73. return true;
  74. else if( permissions == true && permissionHandler.has(player, "TreeOctopus.disable") )
  75. return false;
  76. return false;
  77. }//end enabled()
  78. }//end class TreeOctopus
  79. /***********************************Contents of "plugin.yml":*******************************
  80. name: TreeOctopus
  81. version: 1.0
  82. author: insanj
  83. main: me.insanj.TreeOctopus.TreeOctopus
  84. description: Placing gold on trees summons the holy Tree Octopus.
  85. website: http://forums.bukkit.org/threads/the-pacific-northwest-tree-octopus.29301/
  86. commands:
  87. octopus:
  88. #Use the following permission as a substitute for this command.
  89. permissions: replicator.disable
  90. description: Disables the plugin, because it is enabled by default.
  91. usage: /<command>
  92. ******************************************************************************************/