SteamWar/SpigotCore
Archiviert
13
0

Add REntityServer.getPlayers, REntityServer.getEntities and REntityServer.getEntitiesByType #246

Zusammengeführt
Lixfel hat 1 Commits von PlayersAndEntitesFromREntityServer nach master 2023-10-22 17:23:57 +02:00 zusammengeführt

Datei anzeigen

@ -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<Player> 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<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) {
entities.computeIfAbsent(entityToId(entity), i -> new HashSet<>()).add(entity);
}