From f5d958286a70f6d472d75ac5437916960ab1b455 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Mar 2024 08:36:51 +0100 Subject: [PATCH] Nametag fix for Replay, Tablist fix for replay --- .../src/de/steamwar/entity/REntity.java | 23 ++++++++-------- .../src/de/steamwar/entity/REntityServer.java | 6 +++++ .../src/de/steamwar/entity/RPlayer.java | 26 +++++-------------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index fad5851..5f97b0d 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -52,8 +52,11 @@ public class REntity { @Getter protected final UUID uuid; + @Getter protected double x; + @Getter protected double y; + @Getter protected double z; private byte yaw; private byte pitch; @@ -257,18 +260,6 @@ public class REntity { return isGlowing; } - public double getX() { - return x; - } - - public double getY() { - return y; - } - - public double getZ() { - return z; - } - private static int spawnPacketOffset() { switch (Core.getVersion()) { case 8: @@ -309,6 +300,10 @@ public class REntity { return packet; } + void list(Consumer packetSink) { + // empty for regular entity + } + private static final Function livingSpawnPacketGenerator = Core.getVersion() >= 19 ? REntity::spawnPacketGenerator : entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, Core.getVersion() == 8 ? 2 : 0); void spawn(Consumer packetSink) { if(entityType.isAlive()) { @@ -365,6 +360,10 @@ public class REntity { packetSink.accept(packet); } + void delist(Consumer packetSink) { + // empty for regular entity + } + double x() { return x; } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index c3b7fb8..442d05d 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -129,6 +129,7 @@ public class REntityServer implements Listener { void addEntity(REntity entity) { entityMap.put(entity.entityId, entity); addEntityToChunk(entity); + entity.list(packet -> updateEntity(entity, packet)); entity.spawn(packet -> updateEntity(entity, packet)); } @@ -140,6 +141,7 @@ public class REntityServer implements Listener { if(!entity.isHidden()) onMissing(players.get(fromId), players.get(toId), entity::despawn); + onMissing(players.get(fromId), players.get(toId), entity::delist); removeEntityFromChunk(entity); } @@ -150,6 +152,7 @@ public class REntityServer implements Listener { return; addEntityToChunk(entity); + onMissing(players.get(toId), players.get(fromId), entity::list); if(!entity.isHidden()) onMissing(players.get(toId), players.get(fromId), entity::spawn); } @@ -166,6 +169,7 @@ public class REntityServer implements Listener { void removeEntity(REntity entity) { entity.despawn(packet -> updateEntity(entity, packet)); removeEntityFromChunk(entity); + entity.delist(packet -> updateEntity(entity, packet)); entityMap.remove(entity.entityId); } @@ -265,6 +269,7 @@ public class REntityServer implements Listener { long id = chunkToId(x, z); players.computeIfAbsent(id, i -> new HashSet<>()).add(player); for(REntity entity : entities.getOrDefault(id, emptyEntities)) { + entity.list(packet -> TinyProtocol.instance.sendPacket(player, packet)); if(!entity.isHidden()) entity.spawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); } @@ -281,6 +286,7 @@ public class REntityServer implements Listener { for(REntity entity : entities.getOrDefault(id, emptyEntities)) { if(!entity.isHidden()) entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); + entity.delist(packet -> TinyProtocol.instance.sendPacket(player, packet)); } } diff --git a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index c0f3a6b..1aa10d8 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -36,21 +36,9 @@ import java.util.UUID; import java.util.function.Consumer; import java.util.function.Function; +@Getter public class RPlayer extends REntity { - /* - private static final String SCOREBOARD_TEAMNAME = "Replay"; - private static final Team team; - - static { - if(FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME) == null) - team = FightScoreboard.getBukkit().registerNewTeam(SCOREBOARD_TEAMNAME); - else - team = FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME); - team.setNameTagVisibility(NameTagVisibility.NEVER); - } - */ - private static int skinPartsIndex() { switch(Core.getVersion()) { case 8: @@ -73,19 +61,21 @@ public class RPlayer extends REntity { private static final Object skinPartsDataWatcher = BountifulWrapper.impl.getDataWatcherObject(skinPartsIndex(), Byte.class); - @Getter private final String name; public RPlayer(REntityServer server, UUID uuid, String name, Location location) { super(server, EntityType.PLAYER, uuid, location,0); this.name = name; - //team.addEntry(name); server.addEntity(this); } @Override - void spawn(Consumer packetSink) { + void list(Consumer packetSink) { packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, new GameProfile(uuid, name), GameMode.CREATIVE)); + } + + @Override + void spawn(Consumer packetSink) { packetSink.accept(getNamedSpawnPacket()); packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F)); @@ -97,9 +87,7 @@ public class RPlayer extends REntity { } @Override - void despawn(Consumer packetSink) { - //team.removeEntry(name); - super.despawn(packetSink); + void delist(Consumer packetSink) { packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE)); }