From 8e5b61c7a0fc1c8cc8d4a89972e382e14853ff0d Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 10 Apr 2017 20:05:31 +0200 Subject: [PATCH] Reload shops when a world loads after initializing the shops --- .../listeners/ShopUpdateListener.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java index 33feeba..4e0aac5 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java @@ -3,6 +3,7 @@ package de.epiceric.shopchest.listeners; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.event.ShopUpdateEvent; import de.epiceric.shopchest.shop.Shop; +import de.epiceric.shopchest.utils.Callback; import de.epiceric.shopchest.utils.ShopUpdater; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -12,6 +13,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.world.WorldLoadEvent; import org.bukkit.scheduler.BukkitRunnable; public class ShopUpdateListener implements Listener { @@ -59,6 +61,23 @@ public class ShopUpdateListener implements Listener { }.runTaskLater(plugin, 1L); } + @EventHandler + public void onWorldLoad(WorldLoadEvent e) { + final String worldName = e.getWorld().getName(); + + plugin.getShopUtils().reloadShops(false, false, new Callback(plugin) { + @Override + public void onResult(Object result) { + int amount = -1; + if (result instanceof Integer) { + amount = (int) result; + } + plugin.getLogger().info(String.format("Reloaded %d shops because a new world '%s' was loaded", amount, worldName)); + plugin.debug(String.format("Reloaded %d shops because a new world '%s' was loaded", amount, worldName)); + } + }); + } + private void restartShopUpdater(Player p) { if (!plugin.getUpdater().isRunning()) { plugin.setUpdater(new ShopUpdater(plugin));