diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 54e657e..80b319c 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -142,6 +142,7 @@ public class Plugin extends JavaPlugin commands.add(new CommandInfo()); commands.add(new CommandHide()); commands.add(new CommandUnhide()); + commands.add(new CommandExitOpen()); // Register events diff --git a/src/de/craftinc/gates/commands/CommandExitOpen.java b/src/de/craftinc/gates/commands/CommandExitOpen.java new file mode 100644 index 0000000..552c8d4 --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandExitOpen.java @@ -0,0 +1,64 @@ +package de.craftinc.gates.commands; + + +import de.craftinc.gates.Plugin; +import de.craftinc.gates.util.GateBlockChangeSender; +import org.bukkit.ChatColor; + +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 = Plugin.permissionManage; + + needsPermissionAtCurrentLocation = true; + shouldPersistToDisk = true; + senderMustBePlayer = true; + } + + + public void perform() + { + try + { + gate.setExit(player.getLocation()); + sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand."); + + 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 aac7f6d..f9cd682 100644 --- a/src/de/craftinc/gates/commands/CommandHelp.java +++ b/src/de/craftinc/gates/commands/CommandHelp.java @@ -44,6 +44,7 @@ public class CommandHelp extends BaseCommand allUsageStrings.add( new CommandInfo().getUsageTemplate(true, true) ); allUsageStrings.add( new CommandHide().getUsageTemplate(true, true) ); allUsageStrings.add( new CommandUnhide().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandExitOpen().getUsageTemplate(true, true) ); Collections.sort(allUsageStrings);