diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 871b0be40..cad803127 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -27,10 +27,7 @@ import org.maxgamer.quickshop.Shop.ShopLoader; import org.maxgamer.quickshop.Shop.ShopManager; import org.maxgamer.quickshop.Util.Timer; import org.maxgamer.quickshop.Util.*; -import org.maxgamer.quickshop.Watcher.DisplayWatcher; -import org.maxgamer.quickshop.Watcher.LogWatcher; -import org.maxgamer.quickshop.Watcher.SyncTaskWatcher; -import org.maxgamer.quickshop.Watcher.UpdateWatcher; +import org.maxgamer.quickshop.Watcher.*; //import com.griefcraft.lwc.LWCPlugin; @Getter @@ -136,6 +133,7 @@ public class QuickShop extends JavaPlugin { private ShopManager shopManager; private ShopProtectionListener shopProtectListener; private SyncTaskWatcher syncTaskWatcher; + private ShopVaildWatcher shopVaildWatcher; /** * Use SpoutPlugin to get item / block names */ @@ -426,6 +424,7 @@ public class QuickShop extends JavaPlugin { shopProtectListener = new ShopProtectionListener(this); displayWatcher = new DisplayWatcher(this); syncTaskWatcher = new SyncTaskWatcher(this); + shopVaildWatcher = new ShopVaildWatcher(this); Bukkit.getServer().getPluginManager().registerEvents(blockListener, this); Bukkit.getServer().getPluginManager().registerEvents(playerListener, this); Bukkit.getServer().getPluginManager().registerEvents(chatListener, this); @@ -449,12 +448,15 @@ public class QuickShop extends JavaPlugin { getLogger().info("QuickShop Loaded! " + enableTimer.endTimer() + " ms."); /* Delay the Ecoonomy system load, give a chance to let economy system regiser. */ /* And we have a listener to listen the ServiceRegisterEvent :) */ + Util.debugLog("Loading economy system..."); new BukkitRunnable() { @Override public void run() { loadEcon(); } }.runTaskLater(this, 1); + Util.debugLog("Registering shop watcher..."); + shopVaildWatcher.runTaskTimer(this,0,20*60); } /** @@ -904,6 +906,7 @@ public class QuickShop extends JavaPlugin { } if (selectedVersion == 46) { getConfig().set("shop.use-protection-checking-filter", true); + getConfig().set("shop.max-shops-checks-in-once",100); getConfig().set("config-version", 47); selectedVersion = 47; } diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java index 790c3a2ee..466726d1a 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java @@ -1,56 +1,44 @@ package org.maxgamer.quickshop.Watcher; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.*; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.Shop; import org.maxgamer.quickshop.Shop.ShopChunk; +import org.maxgamer.quickshop.Util.Util; /** - * @author Netherfoam Maintains the display items, restoring them when needed. - * Also deletes invalid items. + * Check the shops after server booted up, make sure shop can correct self-deleted when container lost. */ -@Deprecated -public class ShopVaildWatcher implements Runnable { +public class ShopVaildWatcher extends BukkitRunnable { private QuickShop plugin; + private Queue checkQueue = new LinkedList<>(); - @Deprecated public ShopVaildWatcher(@NotNull QuickShop plugin) { this.plugin = plugin; } @Override public void run() { - List toRemove = new ArrayList<>(); - for (Entry>> inWorld : plugin.getShopManager().getShops().entrySet()) { - // This world - World world = Bukkit.getWorld(inWorld.getKey()); - if (world == null) { - continue; // world not loaded. + int checkedShops = 0; + int maxCheckShops = plugin.getConfig().getInt("shop.max-shops-checks-in-once"); + Shop shop = checkQueue.poll(); + while (shop != null){ + if(shop.isLoaded() && !shop.isValid()){ + shop.delete(); + Util.debugLog("Removed shop at "+shop.getLocation()+" cause the container is missing or not a usable container."); } - for (Entry> inChunk : inWorld.getValue().entrySet()) { - if (!world.isChunkLoaded(inChunk.getKey().getX(), inChunk.getKey().getZ())) { - // If the chunk is not loaded, next chunk! - continue; - } - for (Shop shop : inChunk.getValue().values()) { - // Validate the shop. - if (!shop.isValid()) { - toRemove.add(shop); - } - } + checkedShops ++; + if(checkedShops >= maxCheckShops){ + Util.debugLog("Shop check reached the limit, force exit and wait next check window."); } - } - // Now we can remove it. - for (Shop shop : toRemove) { - shop.delete(); + shop = checkQueue.poll(); } } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6b36c3460..5695bd92e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -236,6 +236,9 @@ shop: # - PLUGIN##LISTENER##EVENT #Example: - QuickShop##org.maxgamer.Listeners.BlockListener##org.bukkit.event.block.BlockPlaceEvent + #How many shops can be checked in once? (Container exists check) + max-shops-checks-in-once: 100 + #Add display name to the spawned DisplayItem entity? display-item-use-name: true