From 64a7ac50faf3f91a54931288eb76ed3247156cda Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sun, 1 Jan 2017 13:27:07 +0100 Subject: [PATCH] Command cleanup. Stub commands for material and teleport added. --- src/de/craftinc/gates/Plugin.java | 18 +--- .../craftinc/gates/commands/BaseCommand.java | 12 +-- .../craftinc/gates/commands/CommandClose.java | 53 ------------ .../gates/commands/CommandDenyRiding.java | 41 --------- .../craftinc/gates/commands/CommandExit.java | 7 +- .../gates/commands/CommandExitOpen.java | 76 ---------------- .../craftinc/gates/commands/CommandHelp.java | 86 +++++-------------- .../craftinc/gates/commands/CommandHide.java | 57 ------------ .../craftinc/gates/commands/CommandInfo.java | 7 +- .../craftinc/gates/commands/CommandList.java | 6 +- .../gates/commands/CommandLocation.java | 4 +- .../gates/commands/CommandMaterial.java | 23 +++++ .../gates/commands/CommandNearby.java | 3 +- .../craftinc/gates/commands/CommandNew.java | 2 +- .../gates/commands/CommandRemove.java | 2 +- .../gates/commands/CommandRename.java | 7 -- .../gates/commands/CommandTeleport.java | 23 +++++ ...mmandOpen.java => CommandTriggerOpen.java} | 23 ++--- ...iding.java => CommandTriggerVehicles.java} | 20 +++-- .../gates/commands/CommandUnhide.java | 46 ---------- 20 files changed, 110 insertions(+), 406 deletions(-) delete mode 100644 src/de/craftinc/gates/commands/CommandClose.java delete mode 100644 src/de/craftinc/gates/commands/CommandDenyRiding.java delete mode 100644 src/de/craftinc/gates/commands/CommandExitOpen.java delete mode 100644 src/de/craftinc/gates/commands/CommandHide.java create mode 100644 src/de/craftinc/gates/commands/CommandMaterial.java create mode 100644 src/de/craftinc/gates/commands/CommandTeleport.java rename src/de/craftinc/gates/commands/{CommandOpen.java => CommandTriggerOpen.java} (74%) rename src/de/craftinc/gates/commands/{CommandAllowRiding.java => CommandTriggerVehicles.java} (68%) delete mode 100644 src/de/craftinc/gates/commands/CommandUnhide.java diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 263aa2e..93d0327 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -94,9 +94,7 @@ public class Plugin extends JavaPlugin { @Override public void onDisable() { - // Save gates gatesManager.saveGatesToDisk(); - log("Disabled"); } @@ -122,18 +120,14 @@ public class Plugin extends JavaPlugin { commands.add(new CommandRemove()); commands.add(new CommandLocation()); commands.add(new CommandExit()); - commands.add(new CommandOpen()); + commands.add(new CommandTriggerOpen()); commands.add(new CommandRename()); - commands.add(new CommandClose()); commands.add(new CommandList()); commands.add(new CommandInfo()); - commands.add(new CommandHide()); - commands.add(new CommandUnhide()); - commands.add(new CommandExitOpen()); commands.add(new CommandNearby()); - commands.add(new CommandAllowRiding()); - commands.add(new CommandDenyRiding()); - + commands.add(new CommandTriggerVehicles()); + commands.add(new CommandMaterial()); + commands.add(new CommandTeleport()); // Register events this.registerEventListeners(); @@ -168,7 +162,6 @@ public class Plugin extends JavaPlugin { } } - // -------------------------------------------- // // Commands // -------------------------------------------- // @@ -184,7 +177,6 @@ public class Plugin extends JavaPlugin { return this.baseCommand; } - @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { List parameters = new ArrayList<>(Arrays.asList(args)); @@ -192,7 +184,6 @@ public class Plugin extends JavaPlugin { return true; } - private void handleCommand(CommandSender sender, List parameters) { if (parameters.size() == 0) { this.commands.get(0).execute(sender, parameters); @@ -220,7 +211,6 @@ public class Plugin extends JavaPlugin { log(Level.INFO, msg); } - public static void log(Level level, String msg) { Logger.getLogger("Minecraft").log(level, "[" + instance.getDescription().getFullName() + "] " + msg); } diff --git a/src/de/craftinc/gates/commands/BaseCommand.java b/src/de/craftinc/gates/commands/BaseCommand.java index a13a986..4c9774c 100644 --- a/src/de/craftinc/gates/commands/BaseCommand.java +++ b/src/de/craftinc/gates/commands/BaseCommand.java @@ -33,6 +33,7 @@ import de.craftinc.gates.util.TextUtil; public abstract class BaseCommand { PermissionController permissionController; + GatesManager gatesManager; List aliases = new ArrayList<>(); List requiredParameters = new ArrayList<>(); @@ -58,6 +59,7 @@ public abstract class BaseCommand { } public BaseCommand() { + gatesManager = Plugin.getPlugin().getGatesManager(); permissionController = Plugin.getPlugin().getPermissionController(); } @@ -69,14 +71,14 @@ public abstract class BaseCommand { return; } - if (this.senderMustBePlayer) { + if (sender instanceof Player) { this.player = (Player)sender; } this.perform(); if (this.shouldPersistToDisk && getSaveOnChanges()) { - Plugin.getPlugin().getGatesManager().saveGatesToDisk(); + gatesManager.saveGatesToDisk(); } } @@ -93,12 +95,10 @@ public abstract class BaseCommand { } boolean setGateUsingParameter(String param) { - GatesManager gateManager = Plugin.getPlugin().getGatesManager(); - - if (!gateManager.gateExists(param)) { + if (!gatesManager.gateExists(param)) { return false; } else { - gate = gateManager.getGateWithId(param); + gate = gatesManager.getGateWithId(param); return true; } } diff --git a/src/de/craftinc/gates/commands/CommandClose.java b/src/de/craftinc/gates/commands/CommandClose.java deleted file mode 100644 index 3222fee..0000000 --- a/src/de/craftinc/gates/commands/CommandClose.java +++ /dev/null @@ -1,53 +0,0 @@ -/* Craft Inc. Gates - Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program (LGPLv3). If not, see . -*/ -package de.craftinc.gates.commands; - -import java.util.logging.Level; - -import de.craftinc.gates.controllers.PermissionController; -import de.craftinc.gates.util.GateBlockChangeSender; -import org.bukkit.ChatColor; - -import de.craftinc.gates.Plugin; - -public class CommandClose extends BaseCommand { - - public CommandClose() { - aliases.add("close"); - aliases.add("c"); - - requiredParameters.add("id"); - helpDescription = "Closes a gate to prevent players from using it."; - requiredPermission = PermissionController.permissionManage; - needsPermissionAtCurrentLocation = false; - shouldPersistToDisk = true; - senderMustBePlayer = false; - } - - @Override - public void perform() { - try { - gate.setOpen(false); - GateBlockChangeSender.updateGateBlocks(gate); - sendMessage(ChatColor.GREEN + "The gate was closed."); - } catch (Exception e) { - sendMessage(ChatColor.RED + "Opening the gate failed! See server log for more information"); - Plugin.log(Level.WARNING, e.getMessage()); - e.printStackTrace(); - } - } -} diff --git a/src/de/craftinc/gates/commands/CommandDenyRiding.java b/src/de/craftinc/gates/commands/CommandDenyRiding.java deleted file mode 100644 index 143b383..0000000 --- a/src/de/craftinc/gates/commands/CommandDenyRiding.java +++ /dev/null @@ -1,41 +0,0 @@ -/* Craft Inc. Gates - Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program (LGPLv3). If not, see . -*/ -package de.craftinc.gates.commands; - -import de.craftinc.gates.controllers.PermissionController; -import org.bukkit.ChatColor; - -public class CommandDenyRiding extends BaseCommand { - - public CommandDenyRiding() { - aliases.add("denyRiding"); - aliases.add("dr"); - - requiredParameters.add("id"); - helpDescription = "Deny players to travel while riding."; - requiredPermission = PermissionController.permissionManage; - needsPermissionAtCurrentLocation = false; - shouldPersistToDisk = true; - senderMustBePlayer = false; - } - - @Override - protected void perform() { - gate.setAllowsVehicles(false); - sendMessage(ChatColor.GREEN + "Traveling while riding is now disabled for this gate."); - } -} diff --git a/src/de/craftinc/gates/commands/CommandExit.java b/src/de/craftinc/gates/commands/CommandExit.java index ec6939e..e55b87c 100644 --- a/src/de/craftinc/gates/commands/CommandExit.java +++ b/src/de/craftinc/gates/commands/CommandExit.java @@ -30,25 +30,20 @@ public class CommandExit extends BaseCommand { public CommandExit() { aliases.add("exit"); aliases.add("e"); - requiredParameters.add("id"); - helpDescription = "Change exit of location."; - requiredPermission = PermissionController.permissionManage; - needsPermissionAtCurrentLocation = true; shouldPersistToDisk = true; senderMustBePlayer = true; } - public void perform() { try { Location oldExit = gate.getExit(); gate.setExit(player.getLocation()); sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand."); - Plugin.getPlugin().getGatesManager().handleGateExitChange(gate, oldExit); + gatesManager.handleGateExitChange(gate, oldExit); } catch (Exception e) { GateBlockChangeSender.updateGateBlocks(gate); sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information"); diff --git a/src/de/craftinc/gates/commands/CommandExitOpen.java b/src/de/craftinc/gates/commands/CommandExitOpen.java deleted file mode 100644 index 8c4ccd5..0000000 --- a/src/de/craftinc/gates/commands/CommandExitOpen.java +++ /dev/null @@ -1,76 +0,0 @@ -/* Craft Inc. Gates - Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program (LGPLv3). If not, see . -*/ -package de.craftinc.gates.commands; - - -import de.craftinc.gates.controllers.PermissionController; -import de.craftinc.gates.Plugin; -import de.craftinc.gates.util.GateBlockChangeSender; -import org.bukkit.ChatColor; -import org.bukkit.Location; - -import java.util.logging.Level; - -public class CommandExitOpen extends BaseCommand { - - public CommandExitOpen() { - aliases.add("exitopen"); - aliases.add("eo"); - - requiredParameters.add("id"); - helpDescription = "Change exit of location and open that gate afterwards."; - requiredPermission = PermissionController.permissionManage; - needsPermissionAtCurrentLocation = true; - shouldPersistToDisk = true; - senderMustBePlayer = true; - } - - - public void perform() { - try { - Location oldExit = gate.getExit(); - gate.setExit(player.getLocation()); - sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand."); - Plugin.getPlugin().getGatesManager().handleGateExitChange(gate, oldExit); - - try { - boolean needsGateManagerUpdate = false; - - if (gate.getGateBlockLocations().isEmpty()) { - needsGateManagerUpdate = true; - } - - gate.setOpen(true); - - GateBlockChangeSender.updateGateBlocks(gate); - - if (needsGateManagerUpdate) { - Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, null, null, null); - } - - sendMessage(ChatColor.GREEN + "The gate was opened."); - } catch (Exception e) { - sendMessage(ChatColor.RED + e.getMessage()); - } - } catch (Exception e) { - GateBlockChangeSender.updateGateBlocks(gate); - sendMessage(ChatColor.RED + "Setting the exit for the gate failed! This gate is now closed! (See server log for more information.)"); - Plugin.log(Level.WARNING, e.getMessage()); - e.printStackTrace(); - } - } -} diff --git a/src/de/craftinc/gates/commands/CommandHelp.java b/src/de/craftinc/gates/commands/CommandHelp.java index f637c8d..5154b43 100644 --- a/src/de/craftinc/gates/commands/CommandHelp.java +++ b/src/de/craftinc/gates/commands/CommandHelp.java @@ -17,90 +17,50 @@ package de.craftinc.gates.commands; import de.craftinc.gates.controllers.PermissionController; -import de.craftinc.gates.util.TextUtil; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; public class CommandHelp extends BaseCommand { - private static List> helpPages; - - static { - // sort the usage strings - List allUsageStrings = new ArrayList<>(); - - allUsageStrings.add(new CommandHelp().getUsageTemplate(true)); - allUsageStrings.add(new CommandNew().getUsageTemplate(true)); - allUsageStrings.add(new CommandRemove().getUsageTemplate(true)); - allUsageStrings.add(new CommandLocation().getUsageTemplate(true)); - allUsageStrings.add(new CommandExit().getUsageTemplate(true)); - allUsageStrings.add(new CommandOpen().getUsageTemplate(true)); - allUsageStrings.add(new CommandRename().getUsageTemplate(true)); - allUsageStrings.add(new CommandClose().getUsageTemplate(true)); - allUsageStrings.add(new CommandList().getUsageTemplate(true)); - allUsageStrings.add(new CommandInfo().getUsageTemplate(true)); - allUsageStrings.add(new CommandHide().getUsageTemplate(true)); - allUsageStrings.add(new CommandUnhide().getUsageTemplate(true)); - allUsageStrings.add(new CommandExitOpen().getUsageTemplate(true)); - allUsageStrings.add(new CommandNearby().getUsageTemplate(true)); - - Collections.sort(allUsageStrings); - - - // put 5 commands on one page - helpPages = new ArrayList<>(); - - while (!allUsageStrings.isEmpty()) { - int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size(); - List currentHelpPage = new ArrayList<>(allUsageStrings.subList(0, toIndex)); - helpPages.add(currentHelpPage); - - allUsageStrings.removeAll(currentHelpPage); - } - } - + private static List help; public CommandHelp() { aliases.add("help"); aliases.add("?"); - - optionalParameters.add("page"); helpDescription = "prints this help page"; - requiredPermission = PermissionController.permissionInfo; - hasGateParam = false; needsPermissionAtCurrentLocation = false; shouldPersistToDisk = false; senderMustBePlayer = false; } - public void perform() { - int page; + sendMessage(getHelp()); + } - if (parameters.size() > 0) { - try { - page = Integer.parseInt(parameters.get(0)); - } catch (NumberFormatException e) { - // wasn't an integer - page = 1; - } - } else { - page = 1; + private List getHelp() { + if (help == null) { + help = Arrays.asList( + new CommandHelp().getUsageTemplate(true), + new CommandNew().getUsageTemplate(true), + new CommandRemove().getUsageTemplate(true), + new CommandLocation().getUsageTemplate(true), + new CommandExit().getUsageTemplate(true), + new CommandTriggerOpen().getUsageTemplate(true), + new CommandRename().getUsageTemplate(true), + new CommandList().getUsageTemplate(true), + new CommandInfo().getUsageTemplate(true), + new CommandNearby().getUsageTemplate(true), + new CommandTriggerVehicles().getUsageTemplate(true), + new CommandTeleport().getUsageTemplate(true), + new CommandMaterial().getUsageTemplate(true) + ); + Collections.sort(help); } - sendMessage(TextUtil.titleSize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")")); - - page -= 1; - if (page < 0 || page >= helpPages.size()) { - sendMessage("This page does not exist"); - return; - } - - sendMessage(helpPages.get(page)); + return help; } } - diff --git a/src/de/craftinc/gates/commands/CommandHide.java b/src/de/craftinc/gates/commands/CommandHide.java deleted file mode 100644 index af60973..0000000 --- a/src/de/craftinc/gates/commands/CommandHide.java +++ /dev/null @@ -1,57 +0,0 @@ -/* Craft Inc. Gates - Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program (LGPLv3). If not, see . -*/ -package de.craftinc.gates.commands; - -import java.util.logging.Level; - -import de.craftinc.gates.controllers.PermissionController; -import de.craftinc.gates.util.GateBlockChangeSender; -import org.bukkit.ChatColor; - -import de.craftinc.gates.Plugin; - - -public class CommandHide extends BaseCommand { - - public CommandHide() { - aliases.add("hide"); - aliases.add("h"); - - requiredParameters.add("id"); - - helpDescription = "Makes a gate NOT consist of gate blocks while open."; - - requiredPermission = PermissionController.permissionManage; - - needsPermissionAtCurrentLocation = false; - shouldPersistToDisk = true; - senderMustBePlayer = false; - } - - - public void perform() { - try { - gate.setHidden(true); - GateBlockChangeSender.updateGateBlocks(gate); - sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden."); - } catch (Exception e) { - sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information"); - Plugin.log(Level.WARNING, e.getMessage()); - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/de/craftinc/gates/commands/CommandInfo.java b/src/de/craftinc/gates/commands/CommandInfo.java index 81ede3c..51a47f2 100644 --- a/src/de/craftinc/gates/commands/CommandInfo.java +++ b/src/de/craftinc/gates/commands/CommandInfo.java @@ -32,20 +32,15 @@ public class CommandInfo extends BaseCommand { public CommandInfo() { aliases.add("info"); aliases.add("i"); - optionalParameters.add("id"); - helpDescription = "Print detailed information about a certain or the closest gate."; - requiredPermission = PermissionController.permissionInfo; - needsPermissionAtCurrentLocation = false; shouldPersistToDisk = false; senderMustBePlayer = false; hasGateParam = false; } - public void perform() { if (this.parameters.size() > 0) { @@ -64,7 +59,7 @@ public class CommandInfo extends BaseCommand { } Player p = (Player) this.sender; - this.gate = Plugin.getPlugin().getGatesManager().getNearestGate(p.getLocation()); + this.gate = gatesManager.getNearestGate(p.getLocation()); if (!this.hasPermission() || this.gate == null) { sendMessage(ChatColor.RED + "There is either no gate nearby or you do not have permission to " + this.helpDescription.toLowerCase()); diff --git a/src/de/craftinc/gates/commands/CommandList.java b/src/de/craftinc/gates/commands/CommandList.java index 00fb769..5c16264 100644 --- a/src/de/craftinc/gates/commands/CommandList.java +++ b/src/de/craftinc/gates/commands/CommandList.java @@ -30,7 +30,7 @@ import de.craftinc.gates.util.TextUtil; public class CommandList extends BaseCommand { - private static final int linesPerPage = 10; + private static final int linesPerPage = 15; /* this is actually not true. the font used by Minecraft is not monospaced. but there seems to be no (easy) way to calculate @@ -64,7 +64,7 @@ public class CommandList extends BaseCommand { } if (page > allPages.size() || page < 1) { - sendMessage(ChatColor.RED + "The requested page is not availible"); + sendMessage(ChatColor.RED + "The requested page is not available"); return; } @@ -148,7 +148,7 @@ public class CommandList extends BaseCommand { * Method for getting a collection of gates the player is allowed to see. */ private Collection getAllGates() { - Collection gates = Plugin.getPlugin().getGatesManager().allGates(); + Collection gates = gatesManager.allGates(); // create a copy since we cannot iterate over a collection while modifying it! Collection gatesCopy = new ArrayList<>(gates); diff --git a/src/de/craftinc/gates/commands/CommandLocation.java b/src/de/craftinc/gates/commands/CommandLocation.java index 09314e6..4dac6b9 100644 --- a/src/de/craftinc/gates/commands/CommandLocation.java +++ b/src/de/craftinc/gates/commands/CommandLocation.java @@ -62,9 +62,9 @@ public class CommandLocation extends BaseLocationCommand { sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location."); } catch (Exception e) { sendMessage(ChatColor.RED + "There seems to be no frame at your new location! The gate got closed!" + ChatColor.AQUA + " You should build a frame now and execute:"); - sendMessage(new CommandOpen().getUsageTemplate(true)); + sendMessage(new CommandTriggerOpen().getUsageTemplate(true)); } finally { - Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks); + gatesManager.handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks); GateBlockChangeSender.updateGateBlocks(gate); } } diff --git a/src/de/craftinc/gates/commands/CommandMaterial.java b/src/de/craftinc/gates/commands/CommandMaterial.java new file mode 100644 index 0000000..3aecc47 --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandMaterial.java @@ -0,0 +1,23 @@ +package de.craftinc.gates.commands; + +import de.craftinc.gates.controllers.PermissionController; + +public class CommandMaterial extends BaseCommand { + + public CommandMaterial() { + aliases.add("material"); + aliases.add("m"); + + requiredParameters.add("id"); + + senderMustBePlayer = false; + hasGateParam = true; + helpDescription = "Change the material of a gate"; + requiredPermission = PermissionController.permissionManage; + needsPermissionAtCurrentLocation = false; + shouldPersistToDisk = true; + } + + public void perform() { + } +} diff --git a/src/de/craftinc/gates/commands/CommandNearby.java b/src/de/craftinc/gates/commands/CommandNearby.java index 7449ff4..7b3512c 100644 --- a/src/de/craftinc/gates/commands/CommandNearby.java +++ b/src/de/craftinc/gates/commands/CommandNearby.java @@ -25,8 +25,7 @@ public class CommandNearby extends BaseLocationCommand { } public void perform() { - GatesManager manager = Plugin.getPlugin().getGatesManager(); - Set nearbyGates = manager.getNearbyGates(player.getLocation().getChunk()); + Set nearbyGates = gatesManager.getNearbyGates(player.getLocation().getChunk()); if (nearbyGates == null) { player.sendMessage("There are no gates near you!"); diff --git a/src/de/craftinc/gates/commands/CommandNew.java b/src/de/craftinc/gates/commands/CommandNew.java index 6194c7a..1a85891 100644 --- a/src/de/craftinc/gates/commands/CommandNew.java +++ b/src/de/craftinc/gates/commands/CommandNew.java @@ -28,6 +28,7 @@ public class CommandNew extends BaseLocationCommand { public CommandNew() { aliases.add("new"); + aliases.add("create"); aliases.add("n"); requiredParameters.add("id"); @@ -43,7 +44,6 @@ public class CommandNew extends BaseLocationCommand { public void perform() { String id = parameters.get(0); - GatesManager gatesManager = Plugin.getPlugin().getGatesManager(); if (gatesManager.gateExists(id)) { sendMessage(ChatColor.RED + "Creating the gate failed! " + "A gate with the supplied id already exists!"); diff --git a/src/de/craftinc/gates/commands/CommandRemove.java b/src/de/craftinc/gates/commands/CommandRemove.java index 8ab4bec..7a75a0e 100644 --- a/src/de/craftinc/gates/commands/CommandRemove.java +++ b/src/de/craftinc/gates/commands/CommandRemove.java @@ -43,7 +43,7 @@ public class CommandRemove extends BaseCommand { } public void perform() { - Plugin.getPlugin().getGatesManager().handleDeletion(gate); + gatesManager.handleDeletion(gate); GateBlockChangeSender.updateGateBlocks(gate, true); sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted."); } diff --git a/src/de/craftinc/gates/commands/CommandRename.java b/src/de/craftinc/gates/commands/CommandRename.java index 4731e4c..9cc8e3d 100644 --- a/src/de/craftinc/gates/commands/CommandRename.java +++ b/src/de/craftinc/gates/commands/CommandRename.java @@ -30,23 +30,16 @@ public class CommandRename extends BaseCommand { hasGateParam = true; senderMustBePlayer = false; - requiredParameters.add("current name"); requiredParameters.add("new name"); - helpDescription = "Changes the id of a gate."; - requiredPermission = PermissionController.permissionManage; - needsPermissionAtCurrentLocation = false; shouldPersistToDisk = true; - senderMustBePlayer = false; } - public void perform() { String newId = parameters.get(1); - GatesManager gatesManager = Plugin.getPlugin().getGatesManager(); if (gatesManager.gateExists(newId)) { sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + "."); diff --git a/src/de/craftinc/gates/commands/CommandTeleport.java b/src/de/craftinc/gates/commands/CommandTeleport.java new file mode 100644 index 0000000..8574b2c --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandTeleport.java @@ -0,0 +1,23 @@ +package de.craftinc.gates.commands; + +import de.craftinc.gates.controllers.PermissionController; + +public class CommandTeleport extends BaseCommand { + + public CommandTeleport() { + aliases.add("teleport"); + aliases.add("t"); + + requiredParameters.add("id"); + + senderMustBePlayer = true; + hasGateParam = true; + helpDescription = "Teleport to the location of a gate"; + requiredPermission = PermissionController.permissionManage; + needsPermissionAtCurrentLocation = false; + shouldPersistToDisk = false; + } + + public void perform() { + } +} diff --git a/src/de/craftinc/gates/commands/CommandOpen.java b/src/de/craftinc/gates/commands/CommandTriggerOpen.java similarity index 74% rename from src/de/craftinc/gates/commands/CommandOpen.java rename to src/de/craftinc/gates/commands/CommandTriggerOpen.java index bd7e04f..3139287 100644 --- a/src/de/craftinc/gates/commands/CommandOpen.java +++ b/src/de/craftinc/gates/commands/CommandTriggerOpen.java @@ -22,14 +22,14 @@ import org.bukkit.ChatColor; import de.craftinc.gates.Plugin; -public class CommandOpen extends BaseCommand { +public class CommandTriggerOpen extends BaseCommand { - public CommandOpen() { - aliases.add("open"); + public CommandTriggerOpen() { + aliases.add("triggerOpen"); aliases.add("o"); requiredParameters.add("id"); - helpDescription = "Open a gate so players can use it."; + helpDescription = "Open/close a gate."; requiredPermission = PermissionController.permissionManage; needsPermissionAtCurrentLocation = false; @@ -39,20 +39,15 @@ public class CommandOpen extends BaseCommand { public void perform() { try { - boolean needsGateManagerUpdate = false; - - if (gate.getGateBlockLocations().isEmpty()) { - needsGateManagerUpdate = true; + if (!gate.isOpen() && gate.getExit() == null && player != null) { + gate.setExit(player.getLocation()); + sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand."); } - gate.setOpen(true); + gate.setOpen(gate.isOpen()); GateBlockChangeSender.updateGateBlocks(gate); - - if (needsGateManagerUpdate) { - Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, null, null, null); - } - + gatesManager.handleGateLocationChange(gate, null, null, null); sendMessage(ChatColor.GREEN + "The gate was opened."); } catch (Exception e) { sendMessage(ChatColor.RED + e.getMessage()); diff --git a/src/de/craftinc/gates/commands/CommandAllowRiding.java b/src/de/craftinc/gates/commands/CommandTriggerVehicles.java similarity index 68% rename from src/de/craftinc/gates/commands/CommandAllowRiding.java rename to src/de/craftinc/gates/commands/CommandTriggerVehicles.java index 9b42533..3ab3a9b 100644 --- a/src/de/craftinc/gates/commands/CommandAllowRiding.java +++ b/src/de/craftinc/gates/commands/CommandTriggerVehicles.java @@ -19,25 +19,29 @@ package de.craftinc.gates.commands; import de.craftinc.gates.controllers.PermissionController; import org.bukkit.ChatColor; -public class CommandAllowRiding extends BaseCommand { +public class CommandTriggerVehicles extends BaseCommand { - public CommandAllowRiding() { - aliases.add("allowRiding"); - aliases.add("ar"); + public CommandTriggerVehicles() { + aliases.add("vehicles"); + aliases.add("v"); requiredParameters.add("id"); - helpDescription = "Allow players to travel while riding."; + helpDescription = "Allow/deny players to travel while riding."; requiredPermission = PermissionController.permissionManage; needsPermissionAtCurrentLocation = false; shouldPersistToDisk = true; - senderMustBePlayer = false; } @Override protected void perform() { - gate.setAllowsVehicles(true); - sendMessage(ChatColor.GREEN + "Traveling while riding is now enabled for this gate."); + gate.setAllowsVehicles(gate.getAllowsVehicles()); + + if (gate.getAllowsVehicles()) { + sendMessage(ChatColor.GREEN + "Traveling while riding is now enabled for this gate."); + } else { + sendMessage(ChatColor.GREEN + "Traveling while riding is now disabled for this gate."); + } } } diff --git a/src/de/craftinc/gates/commands/CommandUnhide.java b/src/de/craftinc/gates/commands/CommandUnhide.java deleted file mode 100644 index 89dcc89..0000000 --- a/src/de/craftinc/gates/commands/CommandUnhide.java +++ /dev/null @@ -1,46 +0,0 @@ -/* Craft Inc. Gates - Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program (LGPLv3). If not, see . -*/ -package de.craftinc.gates.commands; - -import de.craftinc.gates.controllers.PermissionController; -import de.craftinc.gates.util.GateBlockChangeSender; -import org.bukkit.ChatColor; - -public class CommandUnhide extends BaseCommand { - - public CommandUnhide() { - aliases.add("unhide"); - aliases.add("u"); - - requiredParameters.add("id"); - helpDescription = "Make that gate visible"; - requiredPermission = PermissionController.permissionManage; - needsPermissionAtCurrentLocation = false; - shouldPersistToDisk = true; - senderMustBePlayer = false; - } - - public void perform() { - try { - gate.setHidden(false); - GateBlockChangeSender.updateGateBlocks(gate); - sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible."); - } catch (Exception e) { - sendMessage(ChatColor.RED + e.getMessage()); - } - } -}