From aacff6b895184932730b41b2d7f870bde669c6f8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 13 Apr 2021 21:29:56 +0200 Subject: [PATCH] Reordering a lot of Stuff --- .../spectatesystem/PacketProcessor.java | 1 + .../spectatesystem/elements/REntity.java | 74 ++++++++++++++----- .../spectatesystem/elements/RPlayer.java | 1 - 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index fe14625..971afe7 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -418,6 +418,7 @@ class PacketProcessor { break; case (byte) 0xFF: //Tick + execSync(() -> REntity.tickFire()); if(!source.async()) tickFinished = true; break; diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index f2f651f..ed0abd5 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -31,12 +31,32 @@ import java.util.Map; public abstract class REntity { + public static void tickFire() { + getEntities().forEach((integer, entity) -> { + if(entity.fireTick > 0) + entity.fireTick--; + if(entity.fireTick == 0) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 0); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher); + } + }); + } + protected static final WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); private static final Map entities = new HashMap<>(); + private static Map getEntities() { + return entities; + } + private final int internalId; protected final Entity entity; + private int fireTick; protected REntity(int internalId, Entity entity){ this.internalId = internalId; @@ -55,6 +75,27 @@ public abstract class REntity { for(REntity entity : entities.values()){ entity.sendToPlayer(player); entity.sendLocation(player); + if(entity.fireTick != 0) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.entity.getId(), dataWatcher, false); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + if(entity.entity.isSneaking()) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); + dataWatcher.markDirty(dataWatcherObject); + + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.entity.getId(), dataWatcher, false); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } } } @@ -112,16 +153,15 @@ public abstract class REntity { dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); dataWatcher.markDirty(dataWatcherObject); - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); - - for(Player player : Bukkit.getOnlinePlayers()){ - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + sendDataWatcher(dataWatcher); } public void setOnFire(boolean perma) { - if(!perma) - entity.setOnFire(21, false); + if(!perma) { + fireTick = 21; + } else { + fireTick = -1; + } DataWatcher dataWatcher = new DataWatcher(null); @@ -129,11 +169,7 @@ public abstract class REntity { dataWatcher.register(dataWatcherObject, (byte) 1); dataWatcher.markDirty(dataWatcherObject); - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); - - for(Player player : Bukkit.getOnlinePlayers()){ - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + sendDataWatcher(dataWatcher); } public void setBowDrawn(boolean drawn, int hand) { @@ -143,11 +179,7 @@ public abstract class REntity { dataWatcher.register(dataWatcherObject, (byte) ((drawn?1:0) + (hand * 2))); dataWatcher.markDirty(dataWatcherObject); - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); - - for(Player player : Bukkit.getOnlinePlayers()){ - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } + sendDataWatcher(dataWatcher); } public void damage() { @@ -186,4 +218,12 @@ public abstract class REntity { protected void spawnEntity(PlayerConnection connection){ connection.sendPacket(new PacketPlayOutSpawnEntity(entity)); } + + private void sendDataWatcher(DataWatcher dataWatcher) { + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } } diff --git a/src/de/steamwar/spectatesystem/elements/RPlayer.java b/src/de/steamwar/spectatesystem/elements/RPlayer.java index 0276fa8..8f83a4b 100644 --- a/src/de/steamwar/spectatesystem/elements/RPlayer.java +++ b/src/de/steamwar/spectatesystem/elements/RPlayer.java @@ -54,7 +54,6 @@ public class RPlayer extends REntity { public RPlayer(UUID uuid, String name, int internalId){ super(internalId, createPlayer(uuid, name)); - //TODO Damage team.addEntry(entity.getName()); }