From 777702194dec9764e3c8984cc048a8de07e7f52d Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 15 May 2021 16:29:09 +0200 Subject: [PATCH] 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"); } }