Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 10.50 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package me.juze.DropPlugin;
  2.  
  3. import java.util.logging.Logger;
  4. import java.util.Iterator;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.command.*;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.World;
  10.  
  11. public class DPCommandHandler {
  12.     /**************************************
  13.      * Added by ChrizC.                   *
  14.      * Adds and handles commands.         *
  15.      **************************************/
  16.  
  17.     private final DropPlugin plugin;
  18.     public final Logger log = Logger.getLogger("Minecraft");
  19.     public static final String LOG_PREFIX = "[DropPlugin] ";
  20.     DPConfigHandler config;
  21.     DPHelpHandler help;
  22.     Player player;
  23.  
  24.     public DPCommandHandler(DropPlugin instance, DPConfigHandler config) {
  25.         plugin = instance;
  26.         this.config = config;
  27.     }
  28.  
  29.     public void setupCmds() {
  30.         PluginCommand drop = plugin.getCommand("dropplugin");
  31.         CommandExecutor commandExecutor = new CommandExecutor() {
  32.             public boolean onCommand( CommandSender sender, Command command, String label, String[] args ) {
  33.                 if (sender instanceof Player) {
  34.                     player = (Player)sender;
  35.                     if (args.length != 0) {
  36.                         drop(sender, args);
  37.                     }
  38.                 } else {
  39.                     consoledrop(sender, args);
  40.                 }
  41.                 return true;
  42.             }
  43.         };
  44.         if (drop != null) {
  45.             drop.setExecutor(commandExecutor);
  46.         }
  47.     }
  48.  
  49.     /**************************************
  50.      * Messy code, seperate all messages  *
  51.      * into a seperate class or file?     *
  52.      * Do I want LOG_PREFIX here? -Juze   *
  53.      **************************************/
  54.  
  55.     public void drop(CommandSender event, String[] args) {
  56.         if (args[0].equals("reload")) {
  57.             if (args.length == 2) {
  58.                 if (args[1].equals("all")) {
  59.                     if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.reload")) {
  60.                         config.reloadConfig("all");
  61.                         player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "All configuration files reloaded!");
  62.                         log.info(LOG_PREFIX + "All configuration files reloaded!");
  63.                     }
  64.                 } else if (Bukkit.getServer().getWorld(args[1]) != null) {
  65.                     if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.reload")) {
  66.                         config.reloadConfig(args[1]);
  67.                         player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "Configuration file for world " + ChatColor.YELLOW + args[1] + ChatColor.GRAY + " reloaded!");
  68.                         log.info(LOG_PREFIX + "Configuration file for world " + args[1] + " reloaded!");
  69.                     }
  70.                 } else {
  71.                     player.sendMessage(ChatColor.RED + LOG_PREFIX + "Not a valid world.");
  72.                 }
  73.             }
  74.         } else if (args[0].equals("enable")) {
  75.             if (args.length > 2) {
  76.                 if (Bukkit.getServer().getWorld(args[2]) != null) {
  77.                     if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.enable")) {
  78.                         config.setProperty("drop." + args[1], true, player, args[2]);
  79.                     } else {
  80.                         player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
  81.                     }
  82.                 } else if (args[2].equals("all")) {
  83.                     if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.enable")) {
  84.                         if (config.isValidBlock(args[1])) {
  85.                             Iterator<World> i = config.worlds.iterator();
  86.                             while (i.hasNext()) {
  87.                                 World w = i.next();
  88.                                 config.setPropertySilent("drop." + args[1], true, w.getName());
  89.                             }
  90.                             player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "Drop " + ChatColor.YELLOW + args[1] + ChatColor.GRAY + " enabled for all worlds.");
  91.                             log.info(LOG_PREFIX + "Drop " + args[1] + " enabled for all worlds.");
  92.                         } else {
  93.                             player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "That drop doesn't exist.");
  94.                         }
  95.                     } else {
  96.                         player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
  97.                     }
  98.                 } else {
  99.                     player.sendMessage(ChatColor.RED + LOG_PREFIX + "Not a valid world.");
  100.                 }
  101.             } else if (args.length == 2) {
  102.                 if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.enable")) {
  103.                     config.setProperty("drop." + args[1], true, player, player.getWorld().getName());
  104.                 } else {
  105.                     player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
  106.                 }
  107.             }
  108.         } else if (args[0].equals("disable")) {
  109.             if (args.length > 2) {
  110.                 if (Bukkit.getServer().getWorld(args[2]) != null) {
  111.                     if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.disable")) {
  112.                         config.setProperty("drop." + args[1], false, player, args[2]);
  113.                     } else {
  114.                         player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
  115.                     }
  116.                 } else if (args[2].equals("all")) {
  117.                     if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.disable")) {
  118.                         if (config.isValidBlock(args[1])) {
  119.                             Iterator<World> i = config.worlds.iterator();
  120.                             while (i.hasNext()) {
  121.                                 World w = i.next();
  122.                                 config.setPropertySilent("drop." + args[1], false, w.getName());
  123.                             }
  124.                             player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "Drop " + ChatColor.YELLOW + args[1] + ChatColor.GRAY + " disabled for all worlds.");
  125.                             log.info(LOG_PREFIX + "Drop " + args[1] + " disabled for all worlds.");
  126.                         } else {
  127.                             player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "That drop doesn't exist.");
  128.                         }
  129.                     } else {
  130.                         player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
  131.                     }
  132.                 } else {
  133.                     player.sendMessage(ChatColor.RED + LOG_PREFIX + "Not a valid world.");
  134.                 }
  135.             } else if (args.length == 2) {
  136.                 if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.disable")) {
  137.                     config.setProperty("drop." + args[1], false, player, player.getWorld().getName());
  138.                 } else {
  139.                     player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
  140.                 }
  141.             }
  142.         } else if (args[0].equals("help")) {
  143.             player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "/drops help - Coming soon! -Juze");
  144.         } else if (args[0].equals("version")) {
  145.             player.sendMessage(ChatColor.YELLOW + LOG_PREFIX + "v" + plugin.getDescription().getVersion());
  146.         }
  147.     }
  148.  
  149.     public void consoledrop(CommandSender event, String[] args) {
  150.         if (args[0].equals("reload")) {
  151.             if (args.length == 2) {
  152.                 if (args[1].equals("all")) {
  153.                     config.reloadConfig("all");
  154.                     log.info(LOG_PREFIX + "All configuration files reloaded!");
  155.                 } else if (Bukkit.getServer().getWorld(args[1]) != null) {
  156.                     config.reloadConfig(args[1]);
  157.                     log.info(LOG_PREFIX + "Configuration file for world " + args[1] + " reloaded!");
  158.                 } else {
  159.                     log.info(LOG_PREFIX + "Not a valid world.");
  160.                 }
  161.             }
  162.         } else if (args[0].equals("enable")) {
  163.             if (args.length > 2) {
  164.                 if (Bukkit.getServer().getWorld(args[2]) != null) {
  165.                     config.setPropertySilent("drop." + args[1], true, args[2]);
  166.                     log.info(LOG_PREFIX + "Drop " + args[1] + " enabled for world " + args[2] + ".");
  167.                 } else if (args[2].equals("all")) {
  168.                     if (config.isValidBlock(args[1])) {
  169.                         Iterator<World> i = config.worlds.iterator();
  170.                         while (i.hasNext()) {
  171.                             World w = i.next();
  172.                             config.setPropertySilent("drop." + args[1], true, w.getName());
  173.                         }
  174.                         log.info(LOG_PREFIX + "Drop " + args[1] + " enabled for all worlds.");
  175.                     } else {
  176.                         log.info(LOG_PREFIX + "That drop doesn't exist.");
  177.                     }
  178.                 } else {
  179.                     log.info(LOG_PREFIX + "Not a valid world.");
  180.                 }
  181.             } else {
  182.                 log.info(LOG_PREFIX + "You must specify a world.");
  183.             }
  184.         } else if (args[0].equals("disable")) {
  185.             if (args.length > 2) {
  186.                 if (Bukkit.getServer().getWorld(args[2]) != null) {
  187.                     config.setPropertySilent("drop." + args[1], false, args[2]);
  188.                     log.info(LOG_PREFIX + "Drop " + args[1] + " disabled for world " + args[2] + ".");
  189.                 } else if (args[2].equals("all")) {
  190.                     if (config.isValidBlock(args[1])) {
  191.                         Iterator<World> i = config.worlds.iterator();
  192.                         while (i.hasNext()) {
  193.                             World w = i.next();
  194.                             config.setPropertySilent("drop." + args[1], false, w.getName());
  195.                         }
  196.                         log.info(LOG_PREFIX + "Drop " + args[1] + " disabled for all worlds.");
  197.                     } else {
  198.                         log.info(LOG_PREFIX + "That drop doesn't exist.");
  199.                     }
  200.                 } else {
  201.                     log.info(LOG_PREFIX + "Not a valid world.");
  202.                 }
  203.             } else {
  204.                 log.info(LOG_PREFIX + "You must specify a world.");
  205.             }
  206.         } else if (args[0].equals("help")) {
  207.             help.consoleHelp();
  208.         } else if (args[0].equals("version")) {
  209.             log.info(LOG_PREFIX + "v" + plugin.getDescription().getVersion());
  210.         }
  211.     }
  212. }