diff --git a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java index b63c79f51..ce6816a31 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java @@ -41,9 +41,9 @@ import org.maxgamer.quickshop.Util.Util; public class RealDisplayItem implements DisplayItem { private static QuickShop plugin = QuickShop.instance; - volatile boolean pendingRemoval; + boolean pendingRemoval; @Nullable private ItemStack guardedIstack; - @Nullable private volatile Item item; + @Nullable private Item item; private ItemStack originalItemStack; private Shop shop; @@ -130,7 +130,7 @@ public class RealDisplayItem implements DisplayItem { } @Override - public synchronized void remove() { + public void remove() { if (this.item == null) { Util.debugLog("Ignore the Item removing because the Item is already gone."); return; @@ -207,40 +207,35 @@ public class RealDisplayItem implements DisplayItem { Util.debugLog("Canceled the displayItem spawning because the ItemStack is null."); return; } - + if (item != null && item.isValid() && !item.isDead()) { + Util.debugLog( + "Warning: Spawning the Dropped Item for DisplayItem when there is already an existing Dropped Item, May cause a duplicated Dropped Item!"); + StackTraceElement[] traces = Thread.currentThread().getStackTrace(); + for (StackTraceElement trace : traces) { + Util.debugLog( + trace.getClassName() + "#" + trace.getMethodName() + "#" + trace.getLineNumber()); + } + } if (!Util.isDisplayAllowBlock( Objects.requireNonNull(getDisplayLocation()).getBlock().getType())) { Util.debugLog( "Can't spawn the displayItem because there is not an AIR block above the shopblock."); return; } - - synchronized (this) { - if (item != null && item.isValid() && !item.isDead()) { - Util.debugLog( - "Warning: Spawning the Dropped Item for DisplayItem when there is already an existing Dropped Item, May cause a duplicated Dropped Item!"); - StackTraceElement[] traces = Thread.currentThread().getStackTrace(); - for (StackTraceElement trace : traces) { - Util.debugLog( - trace.getClassName() + "#" + trace.getMethodName() + "#" + trace.getLineNumber()); - } - } - ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = - new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.REALITEM); - Bukkit.getPluginManager().callEvent(shopDisplayItemSpawnEvent); - if (shopDisplayItemSpawnEvent.isCancelled()) { - Util.debugLog( - "Canceled the displayItem spawning because a plugin setCancelled the spawning event, usually this is a QuickShop Add on"); - return; - } - - this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); - this.item = - this.shop.getLocation().getWorld().dropItem(getDisplayLocation(), this.guardedIstack); - this.item.setItemStack(this.guardedIstack); - safeGuard(this.item); + ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = + new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.REALITEM); + Bukkit.getPluginManager().callEvent(shopDisplayItemSpawnEvent); + if (shopDisplayItemSpawnEvent.isCancelled()) { + Util.debugLog( + "Canceled the displayItem spawning because a plugin setCancelled the spawning event, usually this is a QuickShop Add on"); + return; } + this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); + this.item = + this.shop.getLocation().getWorld().dropItem(getDisplayLocation(), this.guardedIstack); + this.item.setItemStack(this.guardedIstack); + safeGuard(this.item); } @Override @@ -254,8 +249,11 @@ public class RealDisplayItem implements DisplayItem { } @Override - public synchronized boolean isSpawned() { - return this.item == null ? false : this.item.isValid(); + public boolean isSpawned() { + if (this.item == null) { + return false; + } + return this.item.isValid(); } @Override diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 350c370b7..271b14d49 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -19,23 +19,19 @@ package org.maxgamer.quickshop.Shop; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.sql.SQLException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.stream.Collectors; import org.bukkit.Bukkit; @@ -66,9 +62,9 @@ import org.maxgamer.quickshop.Util.Util; /** Manage a lot of shops. */ public class ShopManager { - private final ConcurrentHashMap>> shops = - new ConcurrentHashMap<>(); - private final Set loadedShops = Sets.newConcurrentHashSet(); + private final HashMap>> shops = + new HashMap<>(); + private final Set loadedShops = Sets.newHashSet(); private HashMap actions = new HashMap<>(); private QuickShop plugin; private boolean useFastShopSearchAlgorithm = false; @@ -1193,10 +1189,13 @@ public class ShopManager { * * @return All shop in the database */ - public List getAllShops() { - List shops = new ArrayList<>(); - for (HashMap> shopChunkMap : this.shops.values()) { - for (HashMap shopData : shopChunkMap.values()) { + public Collection getAllShops() { + //noinspection unchecked + HashMap>> worldsMap = + (HashMap>>) getShops().clone(); + Collection shops = new ArrayList<>(); + for (HashMap> shopMapData : worldsMap.values()) { + for (HashMap shopData : shopMapData.values()) { shops.addAll(shopData.values()); } } @@ -1209,7 +1208,7 @@ public class ShopManager { * @return a hashmap of World - Chunk - Shop */ @NotNull - public ConcurrentHashMap>> getShops() { + public HashMap>> getShops() { return this.shops; } @@ -1252,7 +1251,10 @@ public class ShopManager { private Iterator>> worlds; public ShopIterator() { - worlds = Collections.unmodifiableCollection(getShops().values()).iterator(); + //noinspection unchecked + HashMap>> worldsMap = + (HashMap>>) getShops().clone(); + worlds = worldsMap.values().iterator(); } /** Returns true if there is still more shops to iterate over. */ diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java index 8810f4693..d4d8ae645 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java @@ -34,12 +34,10 @@ public class DisplayDupeRemoverWatcher extends BukkitRunnable { private Queue checkQueue = new LinkedList<>(); @Override - @Deprecated public void run() { checkQueue.forEach(DisplayItem::removeDupe); } - @Deprecated public void add(@NotNull DisplayItem displayItem) { checkQueue.offer(displayItem); }