Revert "Fixes thread safety"

This reverts commit 752d5c72


Former-commit-id: 1adf256dd2f0560cd51d70a5f73a3cc48d2c0bf6
This commit is contained in:
Ghost_chu committed 2020-01-24 18:12:21 +08:00
1 parent 1ad927cd30
commit ac02fd9784
3 files changed
+44 -46

No files matched your search

@@ -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
@@ -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<String, HashMap<ShopChunk, HashMap<Location, Shop>>> shops =
new ConcurrentHashMap<>();
private final Set<Shop> loadedShops = Sets.newConcurrentHashSet();
private final HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> shops =
new HashMap<>();
private final Set<Shop> loadedShops = Sets.newHashSet();
private HashMap<UUID, Info> 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<Shop> getAllShops() {
List<Shop> shops = new ArrayList<>();
for (HashMap<ShopChunk, HashMap<Location, Shop>> shopChunkMap : this.shops.values()) {
for (HashMap<Location, Shop> shopData : shopChunkMap.values()) {
public Collection<Shop> getAllShops() {
//noinspection unchecked
HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> worldsMap =
(HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>) getShops().clone();
Collection<Shop> shops = new ArrayList<>();
for (HashMap<ShopChunk, HashMap<Location, Shop>> shopMapData : worldsMap.values()) {
for (HashMap<Location, Shop> shopData : shopMapData.values()) {
shops.addAll(shopData.values());
}
}
@@ -1209,7 +1208,7 @@ public class ShopManager {
* @return a hashmap of World - Chunk - Shop
*/
@NotNull
public ConcurrentHashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> getShops() {
public HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> getShops() {
return this.shops;
}
@@ -1252,7 +1251,10 @@ public class ShopManager {
private Iterator<HashMap<ShopChunk, HashMap<Location, Shop>>> worlds;
public ShopIterator() {
worlds = Collections.unmodifiableCollection(getShops().values()).iterator();
//noinspection unchecked
HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> worldsMap =
(HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>) getShops().clone();
worlds = worldsMap.values().iterator();
}
/** Returns true if there is still more shops to iterate over. */
@@ -34,12 +34,10 @@ public class DisplayDupeRemoverWatcher extends BukkitRunnable {
private Queue<DisplayItem> checkQueue = new LinkedList<>();
@Override
@Deprecated
public void run() {
checkQueue.forEach(DisplayItem::removeDupe);
}
@Deprecated
public void add(@NotNull DisplayItem displayItem) {
checkQueue.offer(displayItem);
}