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..6da64c8 100644 --- a/src/de/craftinc/gates/commands/CommandHelp.java +++ b/src/de/craftinc/gates/commands/CommandHelp.java @@ -19,88 +19,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(TextUtil.titleSize("Craft Inc. Gates Help")); + 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..ad63836 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()); @@ -76,19 +71,16 @@ public class CommandInfo extends BaseCommand { sendMessage(TextUtil.titleSize("Information about closest gate: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'")); } - String openHiddenMessage = ChatColor.DARK_AQUA + "This gate is"; + String openMessage = ChatColor.DARK_AQUA + "This gate is"; if (gate.isOpen()) - openHiddenMessage += ChatColor.AQUA + " open"; + openMessage += ChatColor.AQUA + " open"; else - openHiddenMessage += ChatColor.AQUA + " closed"; + openMessage += ChatColor.AQUA + " closed"; - if (gate.isHidden()) - openHiddenMessage += ChatColor.DARK_AQUA + " and" + ChatColor.AQUA + " hidden"; + openMessage += ".\n"; - openHiddenMessage += ".\n"; - - sendMessage(openHiddenMessage); + sendMessage(openMessage); if (gate.getLocation() != null) sendMessage(ChatColor.DARK_AQUA + "location: " + ChatColor.AQUA + "( " + (int) gate.getLocation().getX() + @@ -108,6 +100,8 @@ public class CommandInfo extends BaseCommand { if (gate.getAllowsVehicles()) sendMessage(ChatColor.DARK_AQUA + "You can ride through this gate."); + sendMessage(ChatColor.DARK_AQUA + "This gate is made of " + + ChatColor.AQUA + gate.getMaterial() + ChatColor.DARK_AQUA + "."); if (this.sender instanceof Player) { HashSet set = new HashSet<>(); diff --git a/src/de/craftinc/gates/commands/CommandList.java b/src/de/craftinc/gates/commands/CommandList.java index 00fb769..d710d5a 100644 --- a/src/de/craftinc/gates/commands/CommandList.java +++ b/src/de/craftinc/gates/commands/CommandList.java @@ -25,12 +25,11 @@ import de.craftinc.gates.controllers.PermissionController; import org.bukkit.ChatColor; import de.craftinc.gates.models.Gate; -import de.craftinc.gates.Plugin; 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 +63,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 +147,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..7cad51c 100644 --- a/src/de/craftinc/gates/commands/CommandLocation.java +++ b/src/de/craftinc/gates/commands/CommandLocation.java @@ -23,7 +23,6 @@ import de.craftinc.gates.util.GateBlockChangeSender; import org.bukkit.ChatColor; import org.bukkit.Location; -import de.craftinc.gates.Plugin; import org.bukkit.block.Block; public class CommandLocation extends BaseLocationCommand { @@ -62,9 +61,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..8e46233 --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandMaterial.java @@ -0,0 +1,45 @@ +package de.craftinc.gates.commands; + +import de.craftinc.gates.controllers.PermissionController; +import de.craftinc.gates.models.GateMaterial; +import de.craftinc.gates.util.GateBlockChangeSender; +import org.bukkit.ChatColor; + +import java.security.InvalidParameterException; + +public class CommandMaterial extends BaseCommand { + + public CommandMaterial() { + aliases.add("material"); + aliases.add("m"); + + requiredParameters.add("id"); + requiredParameters.add("material"); + + senderMustBePlayer = false; + hasGateParam = true; + helpDescription = "Change the material of a gate"; + requiredPermission = PermissionController.permissionManage; + needsPermissionAtCurrentLocation = false; + shouldPersistToDisk = true; + } + + public void perform() { + GateMaterial material; + try { + material = new GateMaterial(parameters.get(1)); + } catch (InvalidParameterException e) { + sendMessage(ChatColor.RED + "Invalid material!"); + return; + } + + try { + gate.setMaterial(material); + } catch (Exception e) { + sendMessage(ChatColor.RED + "Frame invalid. Gate is now closed!"); + } + + GateBlockChangeSender.updateGateBlocks(gate); + sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " uses now " + material.toString() + " as material."); + } +} diff --git a/src/de/craftinc/gates/commands/CommandNearby.java b/src/de/craftinc/gates/commands/CommandNearby.java index 7449ff4..656ea9f 100644 --- a/src/de/craftinc/gates/commands/CommandNearby.java +++ b/src/de/craftinc/gates/commands/CommandNearby.java @@ -1,9 +1,7 @@ package de.craftinc.gates.commands; import de.craftinc.gates.models.Gate; -import de.craftinc.gates.controllers.GatesManager; import de.craftinc.gates.controllers.PermissionController; -import de.craftinc.gates.Plugin; import de.craftinc.gates.util.GateBlockChangeSender; import de.craftinc.gates.util.TextUtil; @@ -25,8 +23,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..8186b6c 100644 --- a/src/de/craftinc/gates/commands/CommandNew.java +++ b/src/de/craftinc/gates/commands/CommandNew.java @@ -21,13 +21,12 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import de.craftinc.gates.models.Gate; -import de.craftinc.gates.controllers.GatesManager; -import de.craftinc.gates.Plugin; public class CommandNew extends BaseLocationCommand { public CommandNew() { aliases.add("new"); + aliases.add("create"); aliases.add("n"); requiredParameters.add("id"); @@ -43,7 +42,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..e21ddd3 100644 --- a/src/de/craftinc/gates/commands/CommandRemove.java +++ b/src/de/craftinc/gates/commands/CommandRemove.java @@ -20,8 +20,6 @@ import de.craftinc.gates.controllers.PermissionController; import de.craftinc.gates.util.GateBlockChangeSender; import org.bukkit.ChatColor; -import de.craftinc.gates.Plugin; - public class CommandRemove extends BaseCommand { public CommandRemove() { @@ -43,7 +41,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..4d5230c 100644 --- a/src/de/craftinc/gates/commands/CommandRename.java +++ b/src/de/craftinc/gates/commands/CommandRename.java @@ -19,9 +19,6 @@ package de.craftinc.gates.commands; import de.craftinc.gates.controllers.PermissionController; import org.bukkit.ChatColor; -import de.craftinc.gates.controllers.GatesManager; -import de.craftinc.gates.Plugin; - public class CommandRename extends BaseCommand { public CommandRename() { @@ -30,23 +27,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 69% rename from src/de/craftinc/gates/commands/CommandOpen.java rename to src/de/craftinc/gates/commands/CommandTriggerOpen.java index bd7e04f..c85d431 100644 --- a/src/de/craftinc/gates/commands/CommandOpen.java +++ b/src/de/craftinc/gates/commands/CommandTriggerOpen.java @@ -20,16 +20,14 @@ import de.craftinc.gates.controllers.PermissionController; import de.craftinc.gates.util.GateBlockChangeSender; import org.bukkit.ChatColor; -import de.craftinc.gates.Plugin; +public class CommandTriggerOpen extends BaseCommand { -public class CommandOpen 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,21 +37,16 @@ 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); - } - - sendMessage(ChatColor.GREEN + "The gate was opened."); + gatesManager.handleGateLocationChange(gate, null, null, null); + sendMessage(ChatColor.GREEN + "The gate is now " + (gate.isOpen() ? "open." : "closed.")); } 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()); - } - } -} diff --git a/src/de/craftinc/gates/listeners/BlockBreakListener.java b/src/de/craftinc/gates/listeners/BlockBreakListener.java index abe2e0e..af7916d 100644 --- a/src/de/craftinc/gates/listeners/BlockBreakListener.java +++ b/src/de/craftinc/gates/listeners/BlockBreakListener.java @@ -19,6 +19,7 @@ package de.craftinc.gates.listeners; import de.craftinc.gates.models.Gate; import de.craftinc.gates.Plugin; import de.craftinc.gates.util.GateBlockChangeSender; +import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -34,7 +35,7 @@ public class BlockBreakListener implements Listener { Gate gate = Plugin.getPlugin().getGatesManager().getGateAtFrameLocation(event.getBlock().getLocation()); - if (gate != null && !gate.isHidden()) { + if (gate != null && gate.getMaterial().getMaterial() != Material.AIR) { try { gate.setOpen(false); } catch (Exception ignored) {} diff --git a/src/de/craftinc/gates/models/Gate.java b/src/de/craftinc/gates/models/Gate.java index c063360..e220b2b 100644 --- a/src/de/craftinc/gates/models/Gate.java +++ b/src/de/craftinc/gates/models/Gate.java @@ -33,10 +33,10 @@ public class Gate implements ConfigurationSerializable { private Set gateBlockLocations = new HashSet<>(); /* Locations of the blocks inside the gate */ private Set gateFrameBlocks = new HashSet<>(); private Location exit; - private boolean isHidden = false; private boolean isOpen = false; private boolean allowsVehicles = true; private String id; + private GateMaterial material = new GateMaterial(Material.PORTAL); /** * You should never create two gates with the same 'id'. Also see 'setId(String id)'. @@ -63,6 +63,15 @@ public class Gate implements ConfigurationSerializable { } } + public GateMaterial getMaterial() { + return material; + } + + public void setMaterial(GateMaterial material) throws Exception { + this.material = material; + validate(); + } + /** * @return This method might return a 'null' data. */ @@ -127,15 +136,6 @@ public class Gate implements ConfigurationSerializable { this.id = id.toLowerCase(); } - public boolean isHidden() { - return isHidden; - } - - public void setHidden(boolean isHidden) throws Exception { - this.isHidden = isHidden; - this.validate(); - } - public boolean isOpen() { return isOpen; } @@ -216,17 +216,25 @@ public class Gate implements ConfigurationSerializable { throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)"); } - if (!isHidden() && Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) { + validateFrame(); + } - for (Block b : gateFrameBlocks) { + private void validateFrame() throws Exception { + boolean isAir = material.getMaterial() == Material.AIR; + boolean ignore = !Plugin.getPlugin().getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey); - if (b.getType() == Material.AIR) { - isOpen = false; - this.gateBlockLocations = new HashSet<>(); - this.gateFrameBlocks = new HashSet<>(); + if (isAir || ignore) { + return; + } - throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))"); - } + for (Block b : gateFrameBlocks) { + + if (b.getType() == Material.AIR) { + isOpen = false; + this.gateBlockLocations = new HashSet<>(); + this.gateFrameBlocks = new HashSet<>(); + + throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))"); } } } @@ -238,7 +246,7 @@ public class Gate implements ConfigurationSerializable { static private String locationKey = "location"; static private String gateBlocksKey = "gateBlocks"; static private String exitKey = "exit"; - static private String isHiddenKey = "hidden"; + static private String materialKey = "material"; static private String isOpenKey = "open"; static private String allowsVehiclesKey = "allowsVehiclesKey"; @@ -248,7 +256,7 @@ public class Gate implements ConfigurationSerializable { id = map.get(idKey).toString().toLowerCase(); location = (Location) map.get(locationKey); exit = (Location) map.get(exitKey); - isHidden = (Boolean) map.get(isHiddenKey); + material = new GateMaterial((String)map.get(materialKey)); isOpen = (Boolean) map.get(isOpenKey); allowsVehicles = (Boolean) map.get(allowsVehiclesKey); gateBlockLocations = (Set) map.get(gateBlocksKey); @@ -272,10 +280,10 @@ public class Gate implements ConfigurationSerializable { Map retVal = new HashMap<>(); retVal.put(idKey, id); - retVal.put(isHiddenKey, isHidden); retVal.put(isOpenKey, isOpen); retVal.put(allowsVehiclesKey, allowsVehicles); retVal.put(gateBlocksKey, gateBlockLocations); + retVal.put(materialKey, material.toString()); if (exit != null) { retVal.put(exitKey, exit.serialize()); diff --git a/src/de/craftinc/gates/models/GateMaterial.java b/src/de/craftinc/gates/models/GateMaterial.java index ee7d5e9..24ace90 100644 --- a/src/de/craftinc/gates/models/GateMaterial.java +++ b/src/de/craftinc/gates/models/GateMaterial.java @@ -5,13 +5,19 @@ import org.bukkit.Material; import java.security.InvalidParameterException; public class GateMaterial { - private Material material; + GateMaterial(Material material) { + this.material = material; + } + public GateMaterial(String materialString) throws InvalidParameterException { Material material; switch (materialString) { + case "air": + material = Material.AIR; + break; case "sapling": material = Material.SAPLING; break; @@ -85,6 +91,60 @@ public class GateMaterial { this.material = material; } + @Override + public String toString() { + switch (material) { + case AIR: + return "air"; + case SAPLING: + return "sapling"; + case STATIONARY_WATER: + return "water"; + case STATIONARY_LAVA: + return "lava"; + case WEB: + return "cobweb"; + case LONG_GRASS: + return "grass"; + case DEAD_BUSH: + return "dead bush"; + case YELLOW_FLOWER: + return "dandelion"; + case RED_ROSE: + return "poppy"; + case BROWN_MUSHROOM: + return "brown mushroom"; + case RED_MUSHROOM: + return "red mushroom"; + case TORCH: + return "torch"; + case REDSTONE_TORCH_OFF: + return "redstone torch (off)"; + case REDSTONE_TORCH_ON: + return "redstone torch (on)"; + case FENCE: + return "fence"; + case PORTAL: + return "nether portal"; + case IRON_FENCE: + return "iron bars"; + case THIN_GLASS: + return "glass pane"; + case FENCE_GATE: + return "fence gate"; + case NETHER_FENCE: + return "nether brick fence"; + case NETHER_WARTS: + return "nether wart"; + case ENDER_PORTAL: + return "end portal"; + case COBBLE_WALL: + return "cobblestone wall"; + default: + return "nether portal"; + } + } + public Material getMaterial() { return material; } diff --git a/src/de/craftinc/gates/util/ConfigurationUtil.java b/src/de/craftinc/gates/util/ConfigurationUtil.java index 1c8c480..ec75948 100644 --- a/src/de/craftinc/gates/util/ConfigurationUtil.java +++ b/src/de/craftinc/gates/util/ConfigurationUtil.java @@ -16,12 +16,6 @@ */ package de.craftinc.gates.util; -import de.craftinc.gates.Plugin; -import de.craftinc.gates.models.GateMaterial; - -import java.security.InvalidParameterException; -import java.util.logging.Level; - public class ConfigurationUtil { public static final String confMaxGateBlocksKey = "maxGateBlocks"; public static final String confPlayerGateBlockUpdateRadiusKey = "playerGateBlockUpdateRadius"; @@ -33,17 +27,4 @@ public class ConfigurationUtil { public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage"; public static final String confSaveOnChangesKey = "saveOnChanges"; public static final String confHighlightDurationKey = "highlightDuration"; - public static final String confGateMaterialKey = "gateMaterial"; - - - static GateMaterial getPortalMaterial() { - String materialString = Plugin.getPlugin().getConfig().getString(confGateMaterialKey); - - try { - return new GateMaterial(materialString); - } catch (InvalidParameterException ignored) { - Plugin.log(Level.WARNING, "Gate material invalid! Please check and correct your configuration file!"); - return new GateMaterial("nether portal"); - } - } } diff --git a/src/de/craftinc/gates/util/GateBlockChangeSender.java b/src/de/craftinc/gates/util/GateBlockChangeSender.java index 54a3a8c..d447d64 100644 --- a/src/de/craftinc/gates/util/GateBlockChangeSender.java +++ b/src/de/craftinc/gates/util/GateBlockChangeSender.java @@ -76,7 +76,7 @@ public class GateBlockChangeSender { } for (Gate g : gatesNearby) { - if (!g.isOpen() || g.isHidden()) { + if (!g.isOpen()) { continue; } sendGateBlockChanges(g, true, player); @@ -124,7 +124,7 @@ public class GateBlockChangeSender { } } - boolean isVisible = gate.isOpen() && !gate.isHidden() && !remove; + boolean isVisible = gate.isOpen() && !remove; for (Player p : playersNearby) { sendGateBlockChanges(gate, isVisible, p); } @@ -157,7 +157,7 @@ public class GateBlockChangeSender { Material material; if (isVisible) { - GateMaterial gm = getPortalMaterial(); + GateMaterial gm = gate.getMaterial(); data = gm.getData(gate.getDirection()); material = gm.getMaterial(); } else {