diff --git a/src/de/craftinc/gates/Gate.java b/src/de/craftinc/gates/Gate.java index 5f83a25..bcfbaae 100644 --- a/src/de/craftinc/gates/Gate.java +++ b/src/de/craftinc/gates/Gate.java @@ -37,6 +37,8 @@ public class Gate implements ConfigurationSerializable protected boolean isHidden = false; protected boolean isOpen = false; + + protected boolean allowsVehicles = true; protected String id; @@ -167,6 +169,18 @@ public class Gate implements ConfigurationSerializable } + public void setAllowsVehicles(boolean allowsVehicles) + { + this.allowsVehicles = allowsVehicles; + } + + + public boolean getAllowsVehicles() + { + return this.allowsVehicles; + } + + /** * * @return Will never return 'null' but might return an empty Set. @@ -265,7 +279,8 @@ public class Gate implements ConfigurationSerializable static protected String locationPitchKey = "locationPitch"; static protected String exitYawKey = "exitYaw"; static protected String exitPitchKey = "exitPitch"; - + static protected String allowsVehiclesKey = "allowsVehiclesKey"; + @SuppressWarnings("unchecked") public Gate(Map map) @@ -273,10 +288,6 @@ public class Gate implements ConfigurationSerializable try { id = map.get(idKey).toString().toLowerCase(); - if (id == null) { - throw new Exception("gates need to have an id"); - } - isHidden = (Boolean)map.get(isHiddenKey); isOpen = (Boolean)map.get(isOpenKey); @@ -292,6 +303,10 @@ public class Gate implements ConfigurationSerializable location.setPitch(((Number)map.get(locationPitchKey)).floatValue()); location.setYaw(((Number)map.get(locationYawKey)).floatValue()); } + + if (map.containsKey(allowsVehiclesKey)) { + allowsVehicles = (Boolean)map.get(allowsVehiclesKey); + } gateBlockLocations = new HashSet(); List> serializedGateBlocks = (List>)map.get(gateBlocksKey); @@ -327,6 +342,7 @@ public class Gate implements ConfigurationSerializable retVal.put(exitKey, LocationUtil.serializeLocation(exit)); retVal.put(isHiddenKey, isHidden); retVal.put(isOpenKey, isOpen); + retVal.put(allowsVehiclesKey, allowsVehiclesKey); if (exit != null) { retVal.put(exitPitchKey, exit.getPitch()); diff --git a/src/de/craftinc/gates/GatesManager.java b/src/de/craftinc/gates/GatesManager.java index ba149bf..2df21c7 100644 --- a/src/de/craftinc/gates/GatesManager.java +++ b/src/de/craftinc/gates/GatesManager.java @@ -41,7 +41,7 @@ public class GatesManager protected FileConfiguration gatesConfig; protected static final String gatesPath = "gates"; // path to gates inside the yaml file protected static final String storageVersionPath = "version"; - protected static final int storageVersion = 1; + protected static final int storageVersion = 2; protected int chunkRadius; diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 18b7e63..d690f37 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -147,6 +147,8 @@ public class Plugin extends JavaPlugin commands.add(new CommandUnhide()); commands.add(new CommandExitOpen()); commands.add(new CommandNearby()); + commands.add(new CommandAllowRiding()); + commands.add(new CommandDenyRiding()); // Register events diff --git a/src/de/craftinc/gates/commands/CommandAllowRiding.java b/src/de/craftinc/gates/commands/CommandAllowRiding.java new file mode 100644 index 0000000..a770988 --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandAllowRiding.java @@ -0,0 +1,46 @@ +/* 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.Plugin; + +public class CommandAllowRiding extends BaseCommand +{ + public CommandAllowRiding() + { + aliases.add("allowRiding"); + aliases.add("ar"); + + requiredParameters.add("id"); + + helpDescription = "Allow players to travel while riding."; + + requiredPermission = Plugin.permissionManage; + + needsPermissionAtCurrentLocation = false; + shouldPersistToDisk = true; + + senderMustBePlayer = false; + } + + @Override + protected void perform() + { + gate.setAllowsVehicles(true); + } +} diff --git a/src/de/craftinc/gates/commands/CommandDenyRiding.java b/src/de/craftinc/gates/commands/CommandDenyRiding.java new file mode 100644 index 0000000..5802c62 --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandDenyRiding.java @@ -0,0 +1,45 @@ +/* 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.Plugin; + +public class CommandDenyRiding extends BaseCommand +{ + public CommandDenyRiding() + { + aliases.add("denyRiding"); + aliases.add("dr"); + + requiredParameters.add("id"); + + helpDescription = "Allow players NOT to travel while riding."; + + requiredPermission = Plugin.permissionManage; + + needsPermissionAtCurrentLocation = false; + shouldPersistToDisk = true; + + senderMustBePlayer = false; + } + + @Override + protected void perform() + { + gate.setAllowsVehicles(false); + } +} diff --git a/src/de/craftinc/gates/listeners/PlayerMoveListener.java b/src/de/craftinc/gates/listeners/PlayerMoveListener.java index 0e6ec9d..733bee7 100644 --- a/src/de/craftinc/gates/listeners/PlayerMoveListener.java +++ b/src/de/craftinc/gates/listeners/PlayerMoveListener.java @@ -104,10 +104,20 @@ public class PlayerMoveListener implements Listener player.getLocation().getPitch() ); - // Riding (eject player) + // Riding final Entity vehicle = player.getVehicle(); final boolean vehicleIsSuitable = (vehicle != null) && (vehicle instanceof Vehicle); + if (vehicle != null && (!vehicleIsSuitable) || !gate.getAllowsVehicles()) { + + if (!gate.getAllowsVehicles()) { + // TODO: display not allowed message + } + + return; + } + + // (eject player) if (vehicleIsSuitable) { vehicle.eject(); vehicle.remove(); @@ -126,7 +136,7 @@ public class PlayerMoveListener implements Listener scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - // TODO: the code below should be executed after the chunk got loaded and not after a fixed time! + // FIXME: the code below should be executed after the chunk got loaded and not after a fixed time! // create a new entity at the destination location final Vehicle newVehicle = VehicleCloner.clone((Vehicle)vehicle, destLocation); diff --git a/src/de/craftinc/gates/persistence/MigrationUtil.java b/src/de/craftinc/gates/persistence/MigrationUtil.java index 9010bc7..9b07408 100644 --- a/src/de/craftinc/gates/persistence/MigrationUtil.java +++ b/src/de/craftinc/gates/persistence/MigrationUtil.java @@ -31,7 +31,7 @@ public class MigrationUtil { public static boolean performMigration(int storageVersion, int currentVersion, List gates) { - if (currentVersion == 1 && storageVersion == 0) { + if (storageVersion == 0 && currentVersion >= 1) { for (Gate g : gates) { @@ -46,6 +46,15 @@ public class MigrationUtil return true; } + else if (storageVersion == 1 && currentVersion >= 2) { + + for (Gate g : gates) { + + g.setAllowsVehicles(true); + } + + return true; + } else { Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!"); return false;