diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 6ff78e19..911872ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -58,10 +58,7 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; @@ -77,6 +74,7 @@ public class SimulatorCursor implements Listener { private Map cursorType = Collections.synchronizedMap(new HashMap<>()); private Map cursors = Collections.synchronizedMap(new HashMap<>()); + private final Set calculating = new HashSet<>(); public static boolean isSimulatorItem(ItemStack itemStack) { return ItemUtils.isItem(itemStack, "simulator"); @@ -115,6 +113,9 @@ public class SimulatorCursor implements Listener { public void onPlayerQuit(PlayerQuitEvent event) { cursorType.remove(event.getPlayer()); cursors.remove(event.getPlayer()); + synchronized (calculating) { + calculating.remove(event.getPlayer()); + } } private static final Map LAST_SNEAKS = new HashMap<>(); @@ -141,11 +142,18 @@ public class SimulatorCursor implements Listener { } } - public synchronized void calcCursor(Player player) { + public void calcCursor(Player player) { + synchronized (calculating) { + if (calculating.contains(player)) return; + calculating.add(player); + } if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { if (removeCursor(player) || SimulatorWatcher.show(null, player)) { SWUtils.sendToActionbar(player, ""); } + synchronized (calculating) { + calculating.remove(player); + } return; } Simulator simulator = SimulatorStorage.getSimulator(player); @@ -160,10 +168,16 @@ public class SimulatorCursor implements Listener { } else { SWUtils.sendToActionbar(player, "§eOpen Simulator"); } + synchronized (calculating) { + calculating.remove(player); + } return; } showCursor(player, rayTraceResult, simulator != null); + synchronized (calculating) { + calculating.remove(player); + } } private synchronized boolean removeCursor(Player player) {