From 11d3d8ff08a703ea6ab32d5288619d293ce5e3d7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 12 Apr 2021 18:14:46 +0200 Subject: [PATCH] Moar Packets --- .../spectatesystem/PacketProcessor.java | 23 +++++++++++++++- .../spectatesystem/elements/REntity.java | 26 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index f2a53ec..bf5b5d5 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -305,6 +305,22 @@ class PacketProcessor { packetCounter.clear(); } + private void bow() { + //TODO implement Bow + } + + private void damage() throws IOException { + int entityId = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).damage()); + } + + private void fireTick() throws IOException { + int entityId = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).setOnFire()); + } + private void process(){ try{ @@ -343,6 +359,11 @@ class PacketProcessor { case 0x09: fireballSpawn(); break; + case 0x0A: + case 0x0B: + damage(); + case 0x0C: + fireTick(); case 0x30: block(); break; @@ -392,7 +413,7 @@ class PacketProcessor { 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..17a98a9 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -104,6 +104,8 @@ public abstract class REntity { } public void sneak(boolean sneaking) { + entity.setSneaking(sneaking); + DataWatcher dataWatcher = new DataWatcher(null); DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); @@ -117,6 +119,30 @@ public abstract class REntity { } } + public void setOnFire() { + entity.setOnFire(21, false); + + 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.getId(), dataWatcher, false); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + + public void damage() { + PacketPlayOutEntityStatus packet = new PacketPlayOutEntityStatus(entity, (byte) 2); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + public void animation(byte animation) { PacketPlayOutAnimation packet = new PacketPlayOutAnimation(entity, animation); for(Player player : Bukkit.getOnlinePlayers()){