diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index f2a53ec..971afe7 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -305,6 +305,27 @@ class PacketProcessor { packetCounter.clear(); } + private void bow() throws IOException { + int entityId = source.rInt(); + boolean drawn = source.rBoolean(); + int hand = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, hand)); + } + + private void damage() throws IOException { + int entityId = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).damage()); + } + + private void fireTick() throws IOException { + int entityId = source.rInt(); + boolean perma = source.rBoolean(); + + execSync(() -> REntity.getEntity(entityId).setOnFire(perma)); + } + private void process(){ try{ @@ -343,6 +364,15 @@ class PacketProcessor { case 0x09: fireballSpawn(); break; + case 0x0A: + bow(); + break; + case 0x0B: + damage(); + break; + case 0x0C: + fireTick(); + break; case 0x30: block(); break; @@ -388,11 +418,12 @@ class PacketProcessor { break; case (byte) 0xFF: //Tick + execSync(() -> REntity.tickFire()); if(!source.async()) tickFinished = true; break; default: - Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing"); + Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing: " + packetType); source.close(); } } diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index fc11e99..ccc5171 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -31,12 +31,33 @@ 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 +76,22 @@ 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); + entity.sendDataWatcher(dataWatcher); + } + if(entity.entity.isSneaking()) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher); + } } } } @@ -104,13 +141,45 @@ public abstract class REntity { } public void sneak(boolean sneaking) { + entity.setSneaking(sneaking); + DataWatcher dataWatcher = new DataWatcher(null); DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); dataWatcher.markDirty(dataWatcherObject); - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); + sendDataWatcher(dataWatcher); + } + + public void setOnFire(boolean perma) { + if(!perma) { + fireTick = 21; + } else { + fireTick = -1; + } + + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher); + } + + public void setBowDrawn(boolean drawn, int hand) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) ((drawn?1:0) + (hand * 2))); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher); + } + + public void damage() { + PacketPlayOutEntityStatus packet = new PacketPlayOutEntityStatus(entity, (byte) 2); for(Player player : Bukkit.getOnlinePlayers()){ ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); @@ -145,4 +214,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()); }