Don't unload shops on chunk unload

This commit is contained in:
Eric 2020-02-24 20:35:13 +01:00
parent c681a9fe31
commit bcf3f5c9cb
3 changed files with 0 additions and 71 deletions

View File

@ -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<Shop> shops;
public ShopsUnloadedEvent(Collection<Shop> shops) {
this.shops = shops;
}
public Collection<Shop> getShops() {
return shops;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -17,7 +17,6 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class ShopUpdateListener implements Listener { public class ShopUpdateListener implements Listener {
@ -126,18 +125,4 @@ public class ShopUpdateListener implements Listener {
newLoadedChunks.add(e.getChunk()); 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);
}
}
} }

View File

@ -3,7 +3,6 @@ package de.epiceric.shopchest.utils;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.event.ShopsLoadedEvent; import de.epiceric.shopchest.event.ShopsLoadedEvent;
import de.epiceric.shopchest.event.ShopsUnloadedEvent;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType; 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<Shop> unloadedShops = new HashSet<>();
Iterator<Shop> 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 * Update hologram and item of all shops for a player
* @param player Player to show the updates * @param player Player to show the updates