- package me.juze.DropPlugin;
- import java.util.logging.Logger;
- import java.util.Iterator;
- import org.bukkit.Bukkit;
- import org.bukkit.command.*;
- import org.bukkit.entity.Player;
- import org.bukkit.ChatColor;
- import org.bukkit.World;
- public class DPCommandHandler {
- /**************************************
- * Added by ChrizC. *
- * Adds and handles commands. *
- **************************************/
- private final DropPlugin plugin;
- public final Logger log = Logger.getLogger("Minecraft");
- public static final String LOG_PREFIX = "[DropPlugin] ";
- DPConfigHandler config;
- DPHelpHandler help;
- Player player;
- public DPCommandHandler(DropPlugin instance, DPConfigHandler config) {
- plugin = instance;
- this.config = config;
- }
- public void setupCmds() {
- PluginCommand drop = plugin.getCommand("dropplugin");
- CommandExecutor commandExecutor = new CommandExecutor() {
- public boolean onCommand( CommandSender sender, Command command, String label, String[] args ) {
- if (sender instanceof Player) {
- player = (Player)sender;
- if (args.length != 0) {
- drop(sender, args);
- }
- } else {
- consoledrop(sender, args);
- }
- return true;
- }
- };
- if (drop != null) {
- drop.setExecutor(commandExecutor);
- }
- }
- /**************************************
- * Messy code, seperate all messages *
- * into a seperate class or file? *
- * Do I want LOG_PREFIX here? -Juze *
- **************************************/
- public void drop(CommandSender event, String[] args) {
- if (args[0].equals("reload")) {
- if (args.length == 2) {
- if (args[1].equals("all")) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.reload")) {
- config.reloadConfig("all");
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "All configuration files reloaded!");
- log.info(LOG_PREFIX + "All configuration files reloaded!");
- }
- } else if (Bukkit.getServer().getWorld(args[1]) != null) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.reload")) {
- config.reloadConfig(args[1]);
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "Configuration file for world " + ChatColor.YELLOW + args[1] + ChatColor.GRAY + " reloaded!");
- log.info(LOG_PREFIX + "Configuration file for world " + args[1] + " reloaded!");
- }
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "Not a valid world.");
- }
- }
- } else if (args[0].equals("enable")) {
- if (args.length > 2) {
- if (Bukkit.getServer().getWorld(args[2]) != null) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.enable")) {
- config.setProperty("drop." + args[1], true, player, args[2]);
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
- }
- } else if (args[2].equals("all")) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.enable")) {
- if (config.isValidBlock(args[1])) {
- Iterator<World> i = config.worlds.iterator();
- while (i.hasNext()) {
- World w = i.next();
- config.setPropertySilent("drop." + args[1], true, w.getName());
- }
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "Drop " + ChatColor.YELLOW + args[1] + ChatColor.GRAY + " enabled for all worlds.");
- log.info(LOG_PREFIX + "Drop " + args[1] + " enabled for all worlds.");
- } else {
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "That drop doesn't exist.");
- }
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
- }
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "Not a valid world.");
- }
- } else if (args.length == 2) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.enable")) {
- config.setProperty("drop." + args[1], true, player, player.getWorld().getName());
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
- }
- }
- } else if (args[0].equals("disable")) {
- if (args.length > 2) {
- if (Bukkit.getServer().getWorld(args[2]) != null) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.disable")) {
- config.setProperty("drop." + args[1], false, player, args[2]);
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
- }
- } else if (args[2].equals("all")) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.disable")) {
- if (config.isValidBlock(args[1])) {
- Iterator<World> i = config.worlds.iterator();
- while (i.hasNext()) {
- World w = i.next();
- config.setPropertySilent("drop." + args[1], false, w.getName());
- }
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "Drop " + ChatColor.YELLOW + args[1] + ChatColor.GRAY + " disabled for all worlds.");
- log.info(LOG_PREFIX + "Drop " + args[1] + " disabled for all worlds.");
- } else {
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "That drop doesn't exist.");
- }
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
- }
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "Not a valid world.");
- }
- } else if (args.length == 2) {
- if (DPPermissionsHandler.checkAccess(player, "DropPlugin.admin.disable")) {
- config.setProperty("drop." + args[1], false, player, player.getWorld().getName());
- } else {
- player.sendMessage(ChatColor.RED + LOG_PREFIX + "You don't have permission to do this...");
- }
- }
- } else if (args[0].equals("help")) {
- player.sendMessage(ChatColor.GRAY + LOG_PREFIX + "/drops help - Coming soon! -Juze");
- } else if (args[0].equals("version")) {
- player.sendMessage(ChatColor.YELLOW + LOG_PREFIX + "v" + plugin.getDescription().getVersion());
- }
- }
- public void consoledrop(CommandSender event, String[] args) {
- if (args[0].equals("reload")) {
- if (args.length == 2) {
- if (args[1].equals("all")) {
- config.reloadConfig("all");
- log.info(LOG_PREFIX + "All configuration files reloaded!");
- } else if (Bukkit.getServer().getWorld(args[1]) != null) {
- config.reloadConfig(args[1]);
- log.info(LOG_PREFIX + "Configuration file for world " + args[1] + " reloaded!");
- } else {
- log.info(LOG_PREFIX + "Not a valid world.");
- }
- }
- } else if (args[0].equals("enable")) {
- if (args.length > 2) {
- if (Bukkit.getServer().getWorld(args[2]) != null) {
- config.setPropertySilent("drop." + args[1], true, args[2]);
- log.info(LOG_PREFIX + "Drop " + args[1] + " enabled for world " + args[2] + ".");
- } else if (args[2].equals("all")) {
- if (config.isValidBlock(args[1])) {
- Iterator<World> i = config.worlds.iterator();
- while (i.hasNext()) {
- World w = i.next();
- config.setPropertySilent("drop." + args[1], true, w.getName());
- }
- log.info(LOG_PREFIX + "Drop " + args[1] + " enabled for all worlds.");
- } else {
- log.info(LOG_PREFIX + "That drop doesn't exist.");
- }
- } else {
- log.info(LOG_PREFIX + "Not a valid world.");
- }
- } else {
- log.info(LOG_PREFIX + "You must specify a world.");
- }
- } else if (args[0].equals("disable")) {
- if (args.length > 2) {
- if (Bukkit.getServer().getWorld(args[2]) != null) {
- config.setPropertySilent("drop." + args[1], false, args[2]);
- log.info(LOG_PREFIX + "Drop " + args[1] + " disabled for world " + args[2] + ".");
- } else if (args[2].equals("all")) {
- if (config.isValidBlock(args[1])) {
- Iterator<World> i = config.worlds.iterator();
- while (i.hasNext()) {
- World w = i.next();
- config.setPropertySilent("drop." + args[1], false, w.getName());
- }
- log.info(LOG_PREFIX + "Drop " + args[1] + " disabled for all worlds.");
- } else {
- log.info(LOG_PREFIX + "That drop doesn't exist.");
- }
- } else {
- log.info(LOG_PREFIX + "Not a valid world.");
- }
- } else {
- log.info(LOG_PREFIX + "You must specify a world.");
- }
- } else if (args[0].equals("help")) {
- help.consoleHelp();
- } else if (args[0].equals("version")) {
- log.info(LOG_PREFIX + "v" + plugin.getDescription().getVersion());
- }
- }
- }