From 0a06a69e654a48925e55dcd27bfc1804cb4e2722 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 29 Jul 2018 14:20:16 +0200 Subject: [PATCH] Fix shops not being shown after re-join --- .../listeners/ShopUpdateListener.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java index 28599fa..dd72872 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java @@ -23,16 +23,24 @@ public class ShopUpdateListener implements Listener { @EventHandler public void onPlayerLeave(PlayerQuitEvent e) { - for (Shop shop : plugin.getShopUtils().getShops()) { - if (shop.hasItem()) { - shop.getItem().resetVisible(e.getPlayer()); + // If done without delay, Bukkit#getOnlinePlayers() would still + // contain the player even though he left, so the shop updater + // would show the shop again. + new BukkitRunnable(){ + @Override + public void run() { + for (Shop shop : plugin.getShopUtils().getShops()) { + if (shop.hasItem()) { + shop.getItem().resetVisible(e.getPlayer()); + } + if (shop.hasHologram()) { + shop.getHologram().resetVisible(e.getPlayer()); + } + } + + plugin.getShopUtils().resetPlayerLocation(e.getPlayer()); } - if (shop.hasHologram()) { - shop.getHologram().resetVisible(e.getPlayer()); - } - } - - plugin.getShopUtils().resetPlayerLocation(e.getPlayer()); + }.runTaskLater(plugin, 1L); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)