mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
Reload shops when a world loads after initializing the shops
This commit is contained in:
parent
8140db76c5
commit
8e5b61c7a0
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user