SteamWar/SpigotCore
Archiviert
13
0

Add REntityServer.getPlayers, REntityServer.getEntities and REntityServer.getEntitiesByType
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-10-22 17:21:48 +02:00
Ursprung 36c31c3b2a
Commit e54427ad7a

Datei anzeigen

@ -33,15 +33,13 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Collections; import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
public class REntityServer implements Listener { public class REntityServer implements Listener {
@ -109,10 +107,17 @@ public class REntityServer implements Listener {
} }
public void removePlayer(Player player) { public void removePlayer(Player player) {
if (!viewDistance.containsKey(player)) {
return;
}
forChunkInView(player, lastLocation.remove(player), (x, z) -> removePlayerFromChunk(player, x, z)); forChunkInView(player, lastLocation.remove(player), (x, z) -> removePlayerFromChunk(player, x, z));
viewDistance.remove(player); viewDistance.remove(player);
} }
public List<Player> getPlayers() {
return new ArrayList<>(viewDistance.keySet());
}
public void close() { public void close() {
TinyProtocol.instance.removeFilter(useEntity, filter); TinyProtocol.instance.removeFilter(useEntity, filter);
for(Player player : lastLocation.keySet().toArray(new Player[0])) { for(Player player : lastLocation.keySet().toArray(new Player[0])) {
@ -159,6 +164,14 @@ public class REntityServer implements Listener {
entityMap.remove(entity.entityId); entityMap.remove(entity.entityId);
} }
public List<REntity> getEntities() {
return new ArrayList<>(entityMap.values());
}
public <T extends REntity> List<T> getEntitiesByType(Class<T> clazz) {
return entityMap.values().stream().filter(clazz::isInstance).map(clazz::cast).collect(Collectors.toList());
}
private void addEntityToChunk(REntity entity) { private void addEntityToChunk(REntity entity) {
entities.computeIfAbsent(entityToId(entity), i -> new HashSet<>()).add(entity); entities.computeIfAbsent(entityToId(entity), i -> new HashSet<>()).add(entity);
} }