From 777702194dec9764e3c8984cc048a8de07e7f52d Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 15 May 2021 16:29:09 +0200 Subject: [PATCH 1/3] swapped stream.peek() to stream.foreach() --- .../bausystem/commands/CommandKillAll.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandKillAll.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandKillAll.java index b8bdfc6..389a191 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandKillAll.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandKillAll.java @@ -21,9 +21,9 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.world.regions.*; import de.steamwar.command.SWCommand; +import java.util.concurrent.atomic.AtomicLong; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public class CommandKillAll extends SWCommand { @@ -48,19 +48,26 @@ public class CommandKillAll extends SWCommand { @Register public void genericCommand(Player player, RegionSelectionType regionSelectionType) { Region region = Region.getRegion(player.getLocation()); + AtomicLong removedEntities = new AtomicLong(); if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.isGlobalRegion(region)) { - long removedEntities = WORLD.getEntities() - .stream() - .filter(e -> !(e instanceof Player)) - .peek(Entity::remove).count(); - RegionUtils.actionBar(GlobalRegion.getInstance(), "§a" + removedEntities + " Entities aus der Welt entfernt"); + WORLD.getEntities() + .stream() + .filter(e -> !(e instanceof Player)) + .forEach(entity -> { + entity.remove(); + removedEntities.getAndIncrement(); + }); + RegionUtils.actionBar(GlobalRegion.getInstance(), "§a" + removedEntities.get() + " Entities aus der Welt entfernt"); } else { - long removedEntities = WORLD.getEntities() - .stream() - .filter(e -> !(e instanceof Player)) - .filter(e -> region.inRegion(e.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) - .peek(Entity::remove).count(); - RegionUtils.actionBar(region, "§a" + removedEntities + " Entities aus der Region entfernt"); + WORLD.getEntities() + .stream() + .filter(e -> !(e instanceof Player)) + .filter(e -> region.inRegion(e.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) + .forEach(entity -> { + entity.remove(); + removedEntities.getAndIncrement(); + }); + RegionUtils.actionBar(region, "§a" + removedEntities.get() + " Entities aus der Region entfernt"); } } From db181db85be5575b46f0d08dd5d72dd0e2ba40c4 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 15 May 2021 17:17:11 +0200 Subject: [PATCH 2/3] We can spell, HOOZAH --- .../src/de/steamwar/bausystem/commands/CommandClear.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java index d1c60e4..195d0f3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -49,13 +49,13 @@ public class CommandClear extends SWCommand { public void clearPlayerCommand(Player p, Player target) { if (!permissionCheck(p)) return; clear(target); - target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von" + p.getDisplayName() + " §7geleert."); + target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von " + p.getDisplayName() + " §7geleert."); p.sendMessage(BauSystem.PREFIX + "Das Inventar von " + target.getDisplayName() + " §7wurde geleert."); } private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.WORLD)) { - player.sendMessage(BauSystem.PREFIX + "$cDu darfst hier keine fremden Inventare leeren."); + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine fremden Inventare leeren."); return false; } return true; From a689ba31b0aecb65b0decd1a228cd04b5c6c3cd2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 15 May 2021 17:30:14 +0200 Subject: [PATCH 3/3] 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();