From bcf3f5c9cb30ea89922dca62b5d5127012bdfa67 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 24 Feb 2020 20:35:13 +0100 Subject: [PATCH] Don't unload shops on chunk unload --- .../shopchest/event/ShopsUnloadedEvent.java | 33 ------------------- .../listeners/ShopUpdateListener.java | 15 --------- .../epiceric/shopchest/utils/ShopUtils.java | 23 ------------- 3 files changed, 71 deletions(-) delete mode 100644 src/main/java/de/epiceric/shopchest/event/ShopsUnloadedEvent.java diff --git a/src/main/java/de/epiceric/shopchest/event/ShopsUnloadedEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopsUnloadedEvent.java deleted file mode 100644 index e194aa1..0000000 --- a/src/main/java/de/epiceric/shopchest/event/ShopsUnloadedEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.epiceric.shopchest.event; - -import java.util.Collection; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -import de.epiceric.shopchest.shop.Shop; - -/** - * Called when shops have been unloaded and removed from the server - */ -public class ShopsUnloadedEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Collection shops; - - public ShopsUnloadedEvent(Collection shops) { - this.shops = shops; - } - - public Collection getShops() { - return shops; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } -} diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java index 5dfced6..28bfc49 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java @@ -17,7 +17,6 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.scheduler.BukkitRunnable; public class ShopUpdateListener implements Listener { @@ -126,18 +125,4 @@ public class ShopUpdateListener implements Listener { newLoadedChunks.add(e.getChunk()); } - - @EventHandler - public void onChunkUnload(ChunkUnloadEvent e) { - if (!plugin.getShopDatabase().isInitialized()) { - return; - } - - int num = plugin.getShopUtils().unloadShops(e.getChunk()); - - if (num > 0) { - String chunkStr = "[" + e.getChunk().getX() + "; " + e.getChunk().getZ() + "]"; - plugin.debug("Unloaded " + num + " shops in chunk " + chunkStr); - } - } } diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index c477562..6675c7b 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -3,7 +3,6 @@ package de.epiceric.shopchest.utils; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.event.ShopsLoadedEvent; -import de.epiceric.shopchest.event.ShopsUnloadedEvent; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop.ShopType; @@ -345,28 +344,6 @@ public class ShopUtils { }); } - /** - * Removes all shops from the given chunk from the server - * @param chunk The chunk containing the shops to unload - * @return The amount of shops that were unloaded - */ - public int unloadShops(final Chunk chunk) { - Set unloadedShops = new HashSet<>(); - - Iterator iter = getShops().iterator(); - while(iter.hasNext()) { - Shop shop = iter.next(); - if (shop.getLocation().getChunk().equals(chunk)) { - removeShop(shop, false); - unloadedShops.add(shop); - plugin.debug("Unloaded shop (#" + shop.getID() + ")"); - } - } - - Bukkit.getPluginManager().callEvent(new ShopsUnloadedEvent(Collections.unmodifiableCollection(unloadedShops))); - return unloadedShops.size(); - } - /** * Update hologram and item of all shops for a player * @param player Player to show the updates