Fixed a bug where players got teleported at the old location of a gate when a new location has been set.

This commit is contained in:
Tobias Ottenweller 2013-07-06 17:13:28 +02:00
parent 02fd7a4916
commit 2d830b2f9f
4 changed files with 42 additions and 30 deletions

View File

@ -77,12 +77,13 @@ public class Gate implements ConfigurationSerializable
this.location = location; this.location = location;
if (isOpen) { if (isOpen) {
if (this.gateBlockLocations == null || this.gateBlockLocations.size() == 0 ) {
findPortalBlocks(); findPortalBlocks();
}
validate(); validate();
} }
else {
this.gateBlockLocations = new HashSet<Location>();
this.gateFrameBlocks = new HashSet<Block>();
}
} }
@ -211,17 +212,26 @@ public class Gate implements ConfigurationSerializable
} }
if (location == null) { if (location == null) {
setOpen(false); isOpen = false;
this.gateBlockLocations = new HashSet<Location>();
this.gateFrameBlocks = new HashSet<Block>();
throw new Exception("Gate got closed. It has no location."); throw new Exception("Gate got closed. It has no location.");
} }
if (exit == null) { if (exit == null) {
setOpen(false); isOpen = false;
this.gateBlockLocations = new HashSet<Location>();
this.gateFrameBlocks = new HashSet<Block>();
throw new Exception("Gate got closed. It has no exit."); throw new Exception("Gate got closed. It has no exit.");
} }
if (gateBlockLocations.size() == 0) { if (gateBlockLocations.size() == 0) {
setOpen(false); isOpen = false;
this.gateBlockLocations = new HashSet<Location>();
this.gateFrameBlocks = new HashSet<Block>();
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)"); throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
} }
@ -230,7 +240,10 @@ public class Gate implements ConfigurationSerializable
for (Block b : gateFrameBlocks) { for (Block b : gateFrameBlocks) {
if (b.getType() == Material.AIR) { if (b.getType() == Material.AIR) {
setOpen(false); isOpen = false;
this.gateBlockLocations = new HashSet<Location>();
this.gateFrameBlocks = new HashSet<Block>();
throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))"); throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))");
} }
} }

View File

@ -57,37 +57,29 @@ public class CommandLocation extends BaseLocationCommand
return; return;
} }
try
{
boolean gateOpen = gate.isOpen();
if (gateOpen) {
gate.setOpen(false);
GateBlockChangeSender.updateGateBlocks(gate);
}
Location oldLocation = gate.getLocation(); Location oldLocation = gate.getLocation();
Set<Location> oldGateBlockLocations = gate.getGateBlockLocations(); Set<Location> oldGateBlockLocations = gate.getGateBlockLocations();
Set<Block> oldFrameBlocks = gate.getGateFrameBlocks(); Set<Block> oldFrameBlocks = gate.getGateFrameBlocks();
gate.setLocation(playerLocation); try
{
if (gateOpen) { if (gate.isOpen()) {
gate.setOpen(true); GateBlockChangeSender.updateGateBlocks(gate, true);
} }
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks); gate.setLocation(playerLocation);
GateBlockChangeSender.updateGateBlocks(gate);
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location."); sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
} }
catch (Exception e) catch (Exception e)
{ {
GateBlockChangeSender.updateGateBlocks(gate);
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(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, true)); sendMessage(new CommandOpen().getUsageTemplate(true, true));
} }
finally {
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks);
GateBlockChangeSender.updateGateBlocks(gate);
}
} }
} }

View File

@ -53,6 +53,7 @@ public class CommandOpen extends BaseCommand
} }
gate.setOpen(true); gate.setOpen(true);
GateBlockChangeSender.updateGateBlocks(gate); GateBlockChangeSender.updateGateBlocks(gate);
if (needsGateManagerUpdate) { if (needsGateManagerUpdate) {

View File

@ -110,14 +110,20 @@ public class GateBlockChangeSender
/** /**
* Sends block changes to players near a given gate. * Sends block changes to players near a given gate.
* @param gate Must not be 'null'! * @param gate Must not be 'null'!
* @param remove Set to true if all visible gate blocks shall be removed.
*/ */
public static void updateGateBlocks(final Gate gate, boolean deleted) public static void updateGateBlocks(final Gate gate, boolean remove)
{ {
if (gate == null) { if (gate == null) {
throw new IllegalArgumentException("'gate must not be 'null'!"); throw new IllegalArgumentException("'gate must not be 'null'!");
} }
Location gateLocation = gate.getLocation(); Location gateLocation = gate.getLocation();
if (gate.getGateBlockLocations().isEmpty()) {
return;
}
ArrayList<Player> playersNearby = new ArrayList<Player>(); ArrayList<Player> playersNearby = new ArrayList<Player>();
int searchRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey); int searchRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey);
@ -131,7 +137,7 @@ public class GateBlockChangeSender
Material material; Material material;
if (gate.isOpen() && !gate.isHidden() && !deleted) { if (gate.isOpen() && !gate.isHidden() && !remove) {
material = Material.PORTAL; material = Material.PORTAL;
} }
else { else {