diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java index 90067799..cb1c0fa8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/Countingwand.java @@ -40,14 +40,15 @@ public class Countingwand { ColorConfig.HIGHLIGHT + "Rechtsklick" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Setzt die 2. Position"), false, clickType -> { }).getItemStack(); + private final Map> selections = new HashMap<>(); public boolean isCountingwand(final ItemStack item) { - return Countingwand.WAND_ITEM.isSimilar(item); + return WAND_ITEM.isSimilar(item); } public void checkSelection(final Point point, final boolean pos1, final Player p) { - Pair selection = Countingwand.selections.get(p.getUniqueId().toString()); + Pair selection = selections.get(p.getUniqueId().toString()); final boolean newPos; if (selection != null) { if (pos1) { @@ -61,7 +62,7 @@ public class Countingwand { } else { selection = new Pair<>(null, point); } - Countingwand.selections.put(p.getUniqueId().toString(), selection); + selections.put(p.getUniqueId().toString(), selection); newPos = true; } @@ -89,6 +90,10 @@ public class Countingwand { } } + public void removePlayer(Player p) { + selections.remove(p); + } + public int getAmount(final Point point1, final Point point2) { if (point1 == null || point2 == null) { return 0; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java index 0342c0e1..9f913a1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/countingwand/CountingwandListener.java @@ -28,6 +28,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; @Linked(LinkageType.LISTENER) @@ -56,4 +57,9 @@ public class CountingwandListener implements Listener { event.setCancelled(true); Countingwand.checkSelection(Point.fromLocation(Objects.requireNonNull(event.getClickedBlock()).getLocation()), false, event.getPlayer()); } + + @EventHandler + public void onLeave(PlayerQuitEvent event) { + Countingwand.removePlayer(event.getPlayer()); + } } \ No newline at end of file