mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-26 01:05:12 +01:00
Don't unload shops on chunk unload
This commit is contained in:
parent
c681a9fe31
commit
bcf3f5c9cb
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<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
|
||||
* @param player Player to show the updates
|
||||
|
Loading…
Reference in New Issue
Block a user