diff --git a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java index 7e0e7a7..5513d2b 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java @@ -59,7 +59,9 @@ public class RArmorStand extends REntity { @Override void spawn(Consumer 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 { diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 97ecc3a..70a5fee 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -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> entities = new HashMap<>(); private final HashMap> players = new HashMap<>(); private final HashMap lastLocation = new HashMap<>(); + private final HashMap 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 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; } }