From e54427ad7ad62e73f35b51b8bb7dd9b841a03d5e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 22 Oct 2023 17:21:48 +0200 Subject: [PATCH] Add REntityServer.getPlayers, REntityServer.getEntities and REntityServer.getEntitiesByType --- .../src/de/steamwar/entity/REntityServer.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 667bcce..721f429 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -33,15 +33,13 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; +import java.util.stream.Collectors; public class REntityServer implements Listener { @@ -109,10 +107,17 @@ public class REntityServer implements Listener { } public void removePlayer(Player player) { + if (!viewDistance.containsKey(player)) { + return; + } forChunkInView(player, lastLocation.remove(player), (x, z) -> removePlayerFromChunk(player, x, z)); viewDistance.remove(player); } + public List getPlayers() { + return new ArrayList<>(viewDistance.keySet()); + } + public void close() { TinyProtocol.instance.removeFilter(useEntity, filter); for(Player player : lastLocation.keySet().toArray(new Player[0])) { @@ -159,6 +164,14 @@ public class REntityServer implements Listener { entityMap.remove(entity.entityId); } + public List getEntities() { + return new ArrayList<>(entityMap.values()); + } + + public List getEntitiesByType(Class clazz) { + return entityMap.values().stream().filter(clazz::isInstance).map(clazz::cast).collect(Collectors.toList()); + } + private void addEntityToChunk(REntity entity) { entities.computeIfAbsent(entityToId(entity), i -> new HashSet<>()).add(entity); } -- 2.39.2