Fixed issue #18. Gates with 'null' as location did cause exceptions at many locations.

This commit is contained in:
Tobias Ottenweller 2013-05-17 20:13:49 +02:00
parent cac6eb6022
commit ed2683affc
6 changed files with 33 additions and 18 deletions

View File

@ -177,7 +177,7 @@ public abstract class BaseGate
throw new Exception("Gate got closed. It has no exit.");
}
if (gateBlockLocations.size() == 0) {
if (gateBlockLocations == null || gateBlockLocations.size() == 0) {
setOpen(false);
throw new Exception("Gate got closed. The frame is missing or broken.");
}

View File

@ -142,8 +142,10 @@ public class Gate extends BaseGate implements ConfigurationSerializable
retVal.put(exitYawKey, exit.getYaw());
}
retVal.put(locationPitchKey, location.getPitch());
retVal.put(locationYawKey, location.getYaw());
if (location != null) {
retVal.put(locationPitchKey, location.getPitch());
retVal.put(locationYawKey, location.getYaw());
}
List<Map<String, Object>> serializedGateBlocks = new ArrayList<Map<String, Object>>();

View File

@ -142,7 +142,7 @@ public abstract class BaseCommand
*/
protected boolean hasPermission()
{
if (Plugin.permission == null) // fallback Ð use the standard bukkit permission system
if (Plugin.permission == null) // fallback <EFBFBD> use the standard bukkit permission system
{
return this.sender.hasPermission(this.requiredPermission);
}
@ -156,7 +156,7 @@ public abstract class BaseCommand
}
else
{
// sender is no player Ð there is no information about the senders locations
// sender is no player <EFBFBD> there is no information about the senders locations
return Plugin.permission.has(this.sender, this.requiredPermission);
}
@ -206,16 +206,22 @@ public abstract class BaseCommand
return false;
}
boolean permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
boolean permAtLocation;
if (this.gate.getLocation() == null) {
permAtLocation = true;
}
else {
permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
}
boolean permAtExit;
if (this.gate.getExit() == null)
{
if (this.gate.getExit() == null) {
permAtExit = true;
}
else
{
else {
permAtExit = Plugin.permission.has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
}

View File

@ -48,6 +48,8 @@ public class CommandCreate extends BaseLocationCommand
Location playerLocation = getValidPlayerLocation();
Plugin.log("player location:" + playerLocation);
if (playerLocation != null)
{
try
@ -63,7 +65,7 @@ public class CommandCreate extends BaseLocationCommand
else
{
sendMessage(ChatColor.GREEN + "Gate with id \"" + id + "\" was created.");
sendMessage("Now you should build a frame and:");
sendMessage("Now you should build a frame and execute:");
sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
}
}

View File

@ -144,10 +144,12 @@ public class CommandList extends BaseCommand
for (Gate gate : gatesCopy) {
boolean permissionAtGateLocation = Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
if (!permissionAtGateLocation) {
gates.remove(gate);
continue;
if (gate.getLocation() != null) {
boolean permissionAtGateLocation = Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
if (!permissionAtGateLocation) {
gates.remove(gate);
continue;
}
}
if (gate.getExit() != null) {

View File

@ -51,10 +51,13 @@ public class GateUtil
}
// Check if the gate is open and useable
if (g.getLocation() == null) {
continue;
}
World gateWorld = g.getLocation().getWorld();
if (!g.isOpen() || !gateWorld.equals(playerWorld))
{
if (!g.isOpen() || !gateWorld.equals(playerWorld)) {
continue;
}