/src/com/zantom07/quickwarp/QuickWarp.java

https://github.com/Relick/QuickWarp · Java · 108 lines · 92 code · 16 blank · 0 comment · 7 complexity · 19d6bb4b7172e41f5f9ef65ba59b187c MD5 · raw file

  1. package com.zantom07.quickwarp;
  2. import java.util.HashMap;
  3. import java.util.logging.Logger;
  4. import org.blockface.bukkitstats.CallHome;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.Server;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.Event;
  10. import org.bukkit.permissions.Permission;
  11. import org.bukkit.permissions.PermissionDefault;
  12. import org.bukkit.plugin.Plugin;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.PluginManager;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16. import org.bukkit.util.config.Configuration;
  17. import com.nijiko.permissions.PermissionHandler;
  18. import com.nijikokun.bukkit.Permissions.Permissions;
  19. import com.zantom07.quickwarp.commands.Command_Return;
  20. import com.zantom07.quickwarp.commands.Command_Warphere;
  21. import com.zantom07.quickwarp.commands.Command_Warpto;
  22. import com.zantom07.quickwarp.commands.Command_Worldwarp;
  23. import com.zantom07.quickwarp.listeners.Listener_Player;
  24. public class QuickWarp extends JavaPlugin {
  25. public Server server;
  26. public static Configuration config;
  27. public static PermissionHandler permissionHandler;
  28. public final Logger logger = Logger.getLogger("Minecraft");
  29. private Listener_Player playerListener;
  30. private Config_Handler configHandler;
  31. public final HashMap<Player, Location> returnUsers = new HashMap<Player, Location>();
  32. @Override
  33. public void onEnable() {
  34. playerListener = new Listener_Player(this);
  35. configHandler = new Config_Handler(this);
  36. CallHome.load(this);
  37. PluginDescriptionFile pdfFile = this.getDescription();
  38. this.logger.info("[" + pdfFile.getName() + "] version ["
  39. + pdfFile.getVersion() + "] is enabled!");
  40. PluginManager pm = getServer().getPluginManager();
  41. pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener,
  42. Event.Priority.Normal, this);
  43. configHandler.checkConfig();
  44. config.load();
  45. setupPermissions();
  46. getCommand("warpto").setExecutor(new Command_Warpto(this));
  47. getCommand("warphere").setExecutor(new Command_Warphere(this));
  48. getCommand("worldwarp").setExecutor(new Command_Worldwarp(this));
  49. getCommand("return").setExecutor(new Command_Return(this));
  50. }
  51. private void setupPermissions() {
  52. if (permissionHandler != null) {
  53. return;
  54. }
  55. Plugin permissionsPlugin = this.getServer().getPluginManager()
  56. .getPlugin("Permissions");
  57. if (permissionsPlugin == null) {
  58. this.logger
  59. .info("[QuickWarp] Permissions 3 not detected, defaulting to SuperPerms / OP.");
  60. return;
  61. }
  62. permissionHandler = ((Permissions) permissionsPlugin).getHandler();
  63. this.logger.info("[QuickWarp] Found and will use "
  64. + ((Permissions) permissionsPlugin).getDescription()
  65. .getFullName());
  66. HashMap<String, Boolean> allItems = new HashMap<String, Boolean>();
  67. allItems.put("quickwarp.return", true);
  68. allItems.put("quickwarp.death", true);
  69. allItems.put("quickwarp.warpto", true);
  70. allItems.put("quickwarp.warphere", true);
  71. allItems.put("quickwarp.world", true);
  72. allItems.put("quickwarp.wwreturn", true);
  73. allItems.put("quickwarp.warpall", true);
  74. Permission perm = new Permission("quickwarp.*",
  75. "Permission for using all QuickWarp functionality.",
  76. PermissionDefault.OP, allItems);
  77. Bukkit.getServer().getPluginManager().addPermission(perm);
  78. }
  79. public boolean checkPermission(Player player, String node) {
  80. if (permissionHandler != null) {
  81. return permissionHandler.has(player, node);
  82. } else {
  83. return player.hasPermission(node);
  84. }
  85. }
  86. @Override
  87. public void onDisable() {
  88. PluginDescriptionFile pdfFile = this.getDescription();
  89. this.logger.info("[" + pdfFile.getName() + "] version ["
  90. + pdfFile.getVersion() + "] has been disabled!");
  91. }
  92. }