From a689ba31b0aecb65b0decd1a228cd04b5c6c3cd2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 15 May 2021 17:30:14 +0200 Subject: [PATCH] Fix /dt clear on not Detonator items Signed-off-by: Chaoscaot --- .../steamwar/bausystem/commands/CommandDetonator.java | 6 +++--- .../src/de/steamwar/bausystem/world/Detonator.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 28b91c0..ca2bb9c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -89,19 +89,19 @@ public class CommandDetonator extends SWCommand { @Register("clear") public void clearCommand(Player p) { if (!permissionCheck(p)) return; - p.getInventory().setItemInMainHand(Detonator.clearDetonator(p.getInventory().getItemInMainHand())); + Detonator.clear(p); } @Register("delete") public void deleteCommand(Player p) { if (!permissionCheck(p)) return; - p.getInventory().setItemInMainHand(Detonator.clearDetonator(p.getInventory().getItemInMainHand())); + Detonator.clear(p); } @Register("reset") public void resetCommand(Player p) { if (!permissionCheck(p)) return; - p.getInventory().setItemInMainHand(Detonator.clearDetonator(p.getInventory().getItemInMainHand())); + Detonator.clear(p); } private boolean permissionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 81d7295..2a94007 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -239,6 +239,16 @@ public class Detonator implements Listener { return item; } + public static void clear(Player player) { + VersionedRunnable.call(new VersionedRunnable(() -> PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).clear(), 12), new VersionedRunnable(() -> { + if (player.getInventory().getItemInMainHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + player.sendMessage(BauSystem.PREFIX + "§cDu hast keinen Detonator im Inventar"); + return; + } + player.getInventory().setItemInMainHand(clearDetonator(player.getInventory().getItemInMainHand())); + }, 15)); + } + public static ItemStack clearDetonator(ItemStack item) { ItemMeta meta = item.getItemMeta(); PersistentDataContainer container = meta.getPersistentDataContainer(); -- 2.39.5