mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-25 03:42:24 +00:00
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:
parent
bc9354eb95
commit
c0415a1e27
@ -11,6 +11,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -22,6 +23,18 @@ public class ShopUpdateListener implements Listener {
|
||||
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)
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
restartShopUpdater(e.getPlayer());
|
||||
@ -75,8 +88,15 @@ public class ShopUpdateListener implements Listener {
|
||||
plugin.getUpdater().start();
|
||||
}
|
||||
|
||||
hideShops(p, false);
|
||||
}
|
||||
|
||||
private void hideShops(Player p, boolean onlyItem) {
|
||||
for (Shop shop : plugin.getShopUtils().getShops()) {
|
||||
if (!onlyItem) {
|
||||
if (shop.getHologram() != null) shop.getHologram().hidePlayer(p);
|
||||
}
|
||||
|
||||
if (shop.getItem() != null) shop.getItem().setVisible(p, false);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user