Respawn shop item after teleport

Sometimes it disappeared after teleporting, because the chunk
has not been loaded yet. Now, after 15 ticks, the shop item will
be respawned after a teleport.
This commit is contained in:
Eric 2017-06-17 13:38:07 +02:00
parent bc9354eb95
commit c0415a1e27

View File

@ -11,6 +11,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -22,6 +23,18 @@ public class ShopUpdateListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent e) {
// Wait till the chunk should have loaded on the client
new BukkitRunnable() {
@Override
public void run() {
hideShops(e.getPlayer(), true);
plugin.getShopUtils().updateShops(e.getPlayer(), true);
}
}.runTaskLater(plugin, 15L);
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
restartShopUpdater(e.getPlayer()); restartShopUpdater(e.getPlayer());
@ -75,8 +88,15 @@ public class ShopUpdateListener implements Listener {
plugin.getUpdater().start(); plugin.getUpdater().start();
} }
hideShops(p, false);
}
private void hideShops(Player p, boolean onlyItem) {
for (Shop shop : plugin.getShopUtils().getShops()) { for (Shop shop : plugin.getShopUtils().getShops()) {
if (shop.getHologram() != null) shop.getHologram().hidePlayer(p); if (!onlyItem) {
if (shop.getHologram() != null) shop.getHologram().hidePlayer(p);
}
if (shop.getItem() != null) shop.getItem().setVisible(p, false); if (shop.getItem() != null) shop.getItem().setVisible(p, false);
} }
} }