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:
parent
02fd7a4916
commit
2d830b2f9f
@ -77,12 +77,13 @@ public class Gate implements ConfigurationSerializable
|
||||
this.location = location;
|
||||
|
||||
if (isOpen) {
|
||||
if (this.gateBlockLocations == null || this.gateBlockLocations.size() == 0 ) {
|
||||
findPortalBlocks();
|
||||
}
|
||||
|
||||
validate();
|
||||
}
|
||||
else {
|
||||
this.gateBlockLocations = new HashSet<Location>();
|
||||
this.gateFrameBlocks = new HashSet<Block>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -211,17 +212,26 @@ public class Gate implements ConfigurationSerializable
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
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)");
|
||||
}
|
||||
|
||||
@ -230,7 +240,10 @@ public class Gate implements ConfigurationSerializable
|
||||
for (Block b : gateFrameBlocks) {
|
||||
|
||||
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))");
|
||||
}
|
||||
}
|
||||
|
@ -57,37 +57,29 @@ public class CommandLocation extends BaseLocationCommand
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
boolean gateOpen = gate.isOpen();
|
||||
|
||||
if (gateOpen) {
|
||||
gate.setOpen(false);
|
||||
GateBlockChangeSender.updateGateBlocks(gate);
|
||||
}
|
||||
|
||||
Location oldLocation = gate.getLocation();
|
||||
Set<Location> oldGateBlockLocations = gate.getGateBlockLocations();
|
||||
Set<Block> oldFrameBlocks = gate.getGateFrameBlocks();
|
||||
|
||||
gate.setLocation(playerLocation);
|
||||
|
||||
if (gateOpen) {
|
||||
gate.setOpen(true);
|
||||
try
|
||||
{
|
||||
if (gate.isOpen()) {
|
||||
GateBlockChangeSender.updateGateBlocks(gate, true);
|
||||
}
|
||||
|
||||
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks);
|
||||
GateBlockChangeSender.updateGateBlocks(gate);
|
||||
gate.setLocation(playerLocation);
|
||||
|
||||
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
|
||||
}
|
||||
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(new CommandOpen().getUsageTemplate(true, true));
|
||||
}
|
||||
finally {
|
||||
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks);
|
||||
GateBlockChangeSender.updateGateBlocks(gate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ public class CommandOpen extends BaseCommand
|
||||
}
|
||||
|
||||
gate.setOpen(true);
|
||||
|
||||
GateBlockChangeSender.updateGateBlocks(gate);
|
||||
|
||||
if (needsGateManagerUpdate) {
|
||||
|
@ -110,14 +110,20 @@ public class GateBlockChangeSender
|
||||
/**
|
||||
* Sends block changes to players near a given gate.
|
||||
* @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) {
|
||||
throw new IllegalArgumentException("'gate must not be 'null'!");
|
||||
}
|
||||
|
||||
Location gateLocation = gate.getLocation();
|
||||
|
||||
if (gate.getGateBlockLocations().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Player> playersNearby = new ArrayList<Player>();
|
||||
|
||||
int searchRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey);
|
||||
@ -131,7 +137,7 @@ public class GateBlockChangeSender
|
||||
|
||||
Material material;
|
||||
|
||||
if (gate.isOpen() && !gate.isHidden() && !deleted) {
|
||||
if (gate.isOpen() && !gate.isHidden() && !remove) {
|
||||
material = Material.PORTAL;
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user