SteamWar/SpigotCore
Archiviert
13
0

Merge branch 'master' into NoGravityREntity
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
zOnlyKroks 2023-01-17 12:30:30 +01:00
Commit 901fe54754
2 geänderte Dateien mit 17 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -59,7 +59,9 @@ public class RArmorStand extends REntity {
@Override
void spawn(Consumer<Object> packetSink) {
super.spawn(packetSink);
packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value));
if(size != null && size != Size.NORMAL)
packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value));
}
public enum Size {

Datei anzeigen

@ -30,7 +30,6 @@ 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;
@ -46,6 +45,7 @@ public class REntityServer implements Listener {
private final HashMap<Long, HashSet<REntity>> entities = new HashMap<>();
private final HashMap<Long, Set<Player>> players = new HashMap<>();
private final HashMap<Player, Location> lastLocation = new HashMap<>();
private final HashMap<Player, Integer> viewDistance = new HashMap<>();
public REntityServer() {
Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance());
@ -54,12 +54,13 @@ public class REntityServer implements Listener {
public void addPlayer(Player player) {
Location location = player.getLocation();
lastLocation.put(player, location);
viewDistance.put(player, viewRadius(player));
forChunkInView(player, location, (x, z) -> addPlayerToChunk(player, x, z));
}
public void removePlayer(Player player) {
Location location = lastLocation.remove(player);
forChunkInView(player, location, (x, z) -> removePlayerFromChunk(player, x, z));
forChunkInView(player, lastLocation.remove(player), (x, z) -> removePlayerFromChunk(player, x, z));
viewDistance.remove(player);
}
public void close() {
@ -117,8 +118,6 @@ public class REntityServer implements Listener {
entities.remove(id);
}
//TODO on settings, on respawn? on boatmove?
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
@ -134,14 +133,18 @@ public class REntityServer implements Listener {
if(fromX == toX && fromZ == toZ)
return;
int viewDistance = viewRadius(player);
lastLocation.put(player, to);
int toViewDistance = viewRadius(player);
forChunkInView(player, from, (x, z) -> {
if(Math.abs(x - toX) > viewDistance || Math.abs(z - toX) > viewDistance) {
if(Math.abs(x - toX) > toViewDistance || Math.abs(z - toZ) > toViewDistance) {
removePlayerFromChunk(player, x, z);
}
});
int fromViewDistance = this.viewDistance.put(player, toViewDistance);
forChunkInView(player, to, (x, z) -> {
if(Math.abs(x - fromX) > viewDistance || Math.abs(z - fromZ) > viewDistance) {
if(Math.abs(x - fromX) > fromViewDistance || Math.abs(z - fromZ) > fromViewDistance) {
addPlayerToChunk(player, x, z);
}
});
@ -171,7 +174,7 @@ public class REntityServer implements Listener {
private void forChunkInView(Player player, Location location, BiConsumer<Integer, Integer> func) {
int chunkX = posToChunk(location.getX());
int chunkZ = posToChunk(location.getZ());
int viewDistance = viewRadius(player);
int viewDistance = this.viewDistance.get(player);
for(int x = chunkX - viewDistance; x <= chunkX + viewDistance; x++) {
for(int z = chunkZ - viewDistance; z <= chunkZ + viewDistance; z++) {
@ -190,7 +193,7 @@ public class REntityServer implements Listener {
private void removePlayerFromChunk(Player player, int x, int z) {
long id = chunkToId(x, z);
players.getOrDefault(id, Collections.emptySet()).remove(player);
players.get(id).remove(player);
for(REntity entity : entities.getOrDefault(id, emptyEntities)) {
entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
}
@ -221,7 +224,6 @@ public class REntityServer implements Listener {
}
private long chunkToId(int x, int z) {
//TODO negative coord clash?
return (long) x << 32 + z;
return ((long) x << 32) + z;
}
}