Reload shops when a world loads after initializing the shops

This commit is contained in:
Eric 2017-04-10 20:05:31 +02:00
parent 8140db76c5
commit 8e5b61c7a0

View File

@ -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));