diff --git a/src/de/craftinc/gates/listeners/PlayerRespawnListener.java b/src/de/craftinc/gates/listeners/PlayerRespawnListener.java index 12bb81f..30712b3 100644 --- a/src/de/craftinc/gates/listeners/PlayerRespawnListener.java +++ b/src/de/craftinc/gates/listeners/PlayerRespawnListener.java @@ -33,6 +33,6 @@ public class PlayerRespawnListener implements Listener System.out.println("player: " + event.getPlayer()); System.out.println("position: " + event.getPlayer().getLocation()); - GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getRespawnLocation()); + GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getRespawnLocation(), true); } } diff --git a/src/de/craftinc/gates/listeners/PlayerTeleportListener.java b/src/de/craftinc/gates/listeners/PlayerTeleportListener.java index 3f7cb48..c7fd479 100644 --- a/src/de/craftinc/gates/listeners/PlayerTeleportListener.java +++ b/src/de/craftinc/gates/listeners/PlayerTeleportListener.java @@ -32,6 +32,6 @@ public class PlayerTeleportListener implements Listener return; } - GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getTo()); + GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getTo(), true); } } diff --git a/src/de/craftinc/gates/util/GateBlockChangeSender.java b/src/de/craftinc/gates/util/GateBlockChangeSender.java index ccbb434..12022bf 100644 --- a/src/de/craftinc/gates/util/GateBlockChangeSender.java +++ b/src/de/craftinc/gates/util/GateBlockChangeSender.java @@ -19,6 +19,7 @@ package de.craftinc.gates.util; import de.craftinc.gates.Plugin; import de.craftinc.gates.Gate; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -29,17 +30,15 @@ import java.util.Set; public class GateBlockChangeSender { - public static void updateGateBlocks(final Player player) - { - if (player == null) { - throw new IllegalArgumentException("'player' must not be 'null'!"); - } - - updateGateBlocks(player, player.getLocation()); - } - - - public static void updateGateBlocks(final Player player, final Location location) + /** + * Sends gate blocks to player at a given location. Will send the updates either immediately or + * immediately and after a short delay. + * @param player A player to send block changes to. Must not be null! + * @param location The location to look for gates nearby. Must not be null! + * @param sendDelayed Set to 'true' if the block changes shall be send a second time after a one + * second delay. + */ + public static void updateGateBlocks(final Player player, final Location location, boolean sendDelayed) { if (player == null) { throw new IllegalArgumentException("'player' must not be 'null'!"); @@ -68,10 +67,45 @@ public class GateBlockChangeSender } } } + + if (sendDelayed) { + Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.getPlugin(), new Runnable() + { + @Override + public void run() + { + updateGateBlocks(player, location, false); + } + }, 20L); + } } + /** + * This method calls: updateGateBlocks(player, location, false); + */ + public static void updateGateBlocks(final Player player, final Location location) + { + updateGateBlocks(player, location, false); + } + /** + * This method calls: updateGateBlocks(player, player.getLocation(), false); + */ + public static void updateGateBlocks(final Player player) + { + if (player == null) { + throw new IllegalArgumentException("'player' must not be 'null'!"); + } + + updateGateBlocks(player, player.getLocation(), false); + } + + + /** + * Sends block changes to players near a given gate. + * @param gate Must not be 'null'! + */ public static void updateGateBlocks(final Gate gate) { if (gate == null) {