From 93aaf02e3c63db15efe4839a2e8b189df6739dc0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 15 May 2021 16:26:01 +0200 Subject: [PATCH] Fix KillAllCommand Signed-off-by: yoyosource --- .../features/other/KillAllCommand.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java index b783035d..52d0ccfd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java @@ -33,6 +33,9 @@ import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + @Linked(LinkageType.COMMAND) public class KillAllCommand extends SWCommand { @@ -56,19 +59,26 @@ public class KillAllCommand extends SWCommand { @Register public void genericCommand(Player player, RegionSelectionType regionSelectionType) { Region region = Region.getRegion(player.getLocation()); + AtomicLong count = new AtomicLong(0); if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.getInstance() == region) { - long removedEntities = WORLD.getEntities() + WORLD.getEntities() .stream() .filter(e -> !(e instanceof Player)) - .peek(Entity::remove).count(); - RegionUtils.actionBar(GlobalRegion.getInstance(), "§a" + removedEntities + " Entities aus der Welt entfernt"); + .forEach(entity -> { + entity.remove(); + count.incrementAndGet(); + }); + RegionUtils.actionBar(GlobalRegion.getInstance(), "§a" + count.get() + " Entities aus der Welt entfernt"); } else { - long removedEntities = WORLD.getEntities() + 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"); + .forEach(entity -> { + entity.remove(); + count.incrementAndGet(); + }); + RegionUtils.actionBar(region, "§a" + count.get() + " Entities aus der Region entfernt"); } }