Added a allow riding attribute to the gate class. Added code to guaranty compatibility. Added two new commands for setting the riding attribute.
This commit is contained in:
parent
0c13d0d3e3
commit
d8fff26c9e
@ -38,6 +38,8 @@ public class Gate implements ConfigurationSerializable
|
|||||||
protected boolean isHidden = false;
|
protected boolean isHidden = false;
|
||||||
protected boolean isOpen = false;
|
protected boolean isOpen = false;
|
||||||
|
|
||||||
|
protected boolean allowsVehicles = true;
|
||||||
|
|
||||||
protected String id;
|
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.
|
* @return Will never return 'null' but might return an empty Set.
|
||||||
@ -265,6 +279,7 @@ public class Gate implements ConfigurationSerializable
|
|||||||
static protected String locationPitchKey = "locationPitch";
|
static protected String locationPitchKey = "locationPitch";
|
||||||
static protected String exitYawKey = "exitYaw";
|
static protected String exitYawKey = "exitYaw";
|
||||||
static protected String exitPitchKey = "exitPitch";
|
static protected String exitPitchKey = "exitPitch";
|
||||||
|
static protected String allowsVehiclesKey = "allowsVehiclesKey";
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -273,10 +288,6 @@ public class Gate implements ConfigurationSerializable
|
|||||||
try {
|
try {
|
||||||
id = map.get(idKey).toString().toLowerCase();
|
id = map.get(idKey).toString().toLowerCase();
|
||||||
|
|
||||||
if (id == null) {
|
|
||||||
throw new Exception("gates need to have an id");
|
|
||||||
}
|
|
||||||
|
|
||||||
isHidden = (Boolean)map.get(isHiddenKey);
|
isHidden = (Boolean)map.get(isHiddenKey);
|
||||||
isOpen = (Boolean)map.get(isOpenKey);
|
isOpen = (Boolean)map.get(isOpenKey);
|
||||||
|
|
||||||
@ -293,6 +304,10 @@ public class Gate implements ConfigurationSerializable
|
|||||||
location.setYaw(((Number)map.get(locationYawKey)).floatValue());
|
location.setYaw(((Number)map.get(locationYawKey)).floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (map.containsKey(allowsVehiclesKey)) {
|
||||||
|
allowsVehicles = (Boolean)map.get(allowsVehiclesKey);
|
||||||
|
}
|
||||||
|
|
||||||
gateBlockLocations = new HashSet<Location>();
|
gateBlockLocations = new HashSet<Location>();
|
||||||
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>)map.get(gateBlocksKey);
|
List<Map<String, Object>> serializedGateBlocks = (List<Map<String, Object>>)map.get(gateBlocksKey);
|
||||||
|
|
||||||
@ -327,6 +342,7 @@ public class Gate implements ConfigurationSerializable
|
|||||||
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
|
retVal.put(exitKey, LocationUtil.serializeLocation(exit));
|
||||||
retVal.put(isHiddenKey, isHidden);
|
retVal.put(isHiddenKey, isHidden);
|
||||||
retVal.put(isOpenKey, isOpen);
|
retVal.put(isOpenKey, isOpen);
|
||||||
|
retVal.put(allowsVehiclesKey, allowsVehiclesKey);
|
||||||
|
|
||||||
if (exit != null) {
|
if (exit != null) {
|
||||||
retVal.put(exitPitchKey, exit.getPitch());
|
retVal.put(exitPitchKey, exit.getPitch());
|
||||||
|
@ -41,7 +41,7 @@ public class GatesManager
|
|||||||
protected FileConfiguration gatesConfig;
|
protected FileConfiguration gatesConfig;
|
||||||
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
||||||
protected static final String storageVersionPath = "version";
|
protected static final String storageVersionPath = "version";
|
||||||
protected static final int storageVersion = 1;
|
protected static final int storageVersion = 2;
|
||||||
|
|
||||||
protected int chunkRadius;
|
protected int chunkRadius;
|
||||||
|
|
||||||
|
@ -147,6 +147,8 @@ public class Plugin extends JavaPlugin
|
|||||||
commands.add(new CommandUnhide());
|
commands.add(new CommandUnhide());
|
||||||
commands.add(new CommandExitOpen());
|
commands.add(new CommandExitOpen());
|
||||||
commands.add(new CommandNearby());
|
commands.add(new CommandNearby());
|
||||||
|
commands.add(new CommandAllowRiding());
|
||||||
|
commands.add(new CommandDenyRiding());
|
||||||
|
|
||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
|
46
src/de/craftinc/gates/commands/CommandAllowRiding.java
Normal file
46
src/de/craftinc/gates/commands/CommandAllowRiding.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
45
src/de/craftinc/gates/commands/CommandDenyRiding.java
Normal file
45
src/de/craftinc/gates/commands/CommandDenyRiding.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -104,10 +104,20 @@ public class PlayerMoveListener implements Listener
|
|||||||
player.getLocation().getPitch()
|
player.getLocation().getPitch()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Riding (eject player)
|
// Riding
|
||||||
final Entity vehicle = player.getVehicle();
|
final Entity vehicle = player.getVehicle();
|
||||||
final boolean vehicleIsSuitable = (vehicle != null) && (vehicle instanceof Vehicle);
|
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) {
|
if (vehicleIsSuitable) {
|
||||||
vehicle.eject();
|
vehicle.eject();
|
||||||
vehicle.remove();
|
vehicle.remove();
|
||||||
@ -126,7 +136,7 @@ public class PlayerMoveListener implements Listener
|
|||||||
scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
|
scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
public void run()
|
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
|
// create a new entity at the destination location
|
||||||
final Vehicle newVehicle = VehicleCloner.clone((Vehicle)vehicle, destLocation);
|
final Vehicle newVehicle = VehicleCloner.clone((Vehicle)vehicle, destLocation);
|
||||||
|
@ -31,7 +31,7 @@ public class MigrationUtil
|
|||||||
{
|
{
|
||||||
public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> gates)
|
public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> gates)
|
||||||
{
|
{
|
||||||
if (currentVersion == 1 && storageVersion == 0) {
|
if (storageVersion == 0 && currentVersion >= 1) {
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
|
|
||||||
@ -46,6 +46,15 @@ public class MigrationUtil
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (storageVersion == 1 && currentVersion >= 2) {
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
|
||||||
|
g.setAllowsVehicles(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else {
|
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!");
|
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;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user