diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index be496eb..198bc60 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -2,12 +2,14 @@ package de.steamwar.spectatesystem; import de.steamwar.spectatesystem.elements.REntity; import de.steamwar.spectatesystem.elements.RPlayer; +import de.steamwar.spectatesystem.elements.RTnT; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.minecraft.server.v1_15_R1.Block; import org.bukkit.Bukkit; +import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; @@ -66,6 +68,24 @@ class PacketProcessor { REntity.getEntity(entityId).animation(animation); } + private void tntSpawn() throws IOException { + int entityId = source.rInt(); + + new RTnT(entityId); + } + + private void entityVelocity() throws IOException { + int entityId = source.rInt(); + + double dX = source.rDouble(); + double dY = source.rDouble(); + double dZ = source.rDouble(); + + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + REntity.getEntity(entityId).setMotion(dX, dY, dZ); + }); + } + private void send(ChatMessageType type) throws IOException { String message = source.rString(); @@ -73,25 +93,36 @@ class PacketProcessor { Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(type, text)); } - private World world = null; + private static final World world = Bukkit.getWorlds().get(0); private void block() throws IOException { - if (world == null) { - world = Bukkit.getWorlds().get(0); - } - int x = source.rInt(); byte y = source.rByte(); int z = source.rInt(); int blockState = source.rInt(); + if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { + blockState = Config.ObfuscateWith; + } CraftBlockData craftBlockData = CraftBlockData.fromData(Block.REGISTRY_ID.fromId(blockState)); Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { world.getBlockAt(x, y, z).setBlockData(craftBlockData); }); } + private void particle() throws IOException { + double x = source.rDouble(); + double y = source.rDouble(); + double z = source.rDouble(); + + String particleName = source.rString(); + + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1); + }); + } + private void process(){ try{ while(!source.isClosed()){ @@ -111,9 +142,18 @@ class PacketProcessor { case 0x04: entityAnimation(); break; + case 0x05: + tntSpawn(); + break; + case 0x06: + entityVelocity(); + break; case 0x30: block(); break; + case 0x31: + particle(); + break; case (byte) 0xA0: send(ChatMessageType.CHAT); break; diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index cc9b18b..44e39b2 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -58,12 +58,12 @@ public abstract class REntity { } public void sneak(boolean sneaking) { - entity.setSneaking(sneaking); - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(0, entity.getDataWatcher(), sneaking); + /*entity.setSneaking(sneaking); + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(7, entity.getDataWatcher(), sneaking); for(Player player : Bukkit.getOnlinePlayers()){ PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; connection.sendPacket(packet); - } + }*/ } public void animation(byte animation) { @@ -74,6 +74,10 @@ public abstract class REntity { } } + public void setMotion(double dX, double dY, double dZ) { + entity.setMot(dX, dY, dZ); + } + private void sendToPlayer(Player player){ spawnEntity(((CraftPlayer)player).getHandle().playerConnection); } diff --git a/src/de/steamwar/spectatesystem/elements/RParticle.java b/src/de/steamwar/spectatesystem/elements/RParticle.java index a66db11..8d3b93e 100644 --- a/src/de/steamwar/spectatesystem/elements/RParticle.java +++ b/src/de/steamwar/spectatesystem/elements/RParticle.java @@ -2,6 +2,8 @@ package de.steamwar.spectatesystem.elements; public class RParticle { - public RParticle(){ + public RParticle() { + } + } diff --git a/src/de/steamwar/spectatesystem/elements/RTnT.java b/src/de/steamwar/spectatesystem/elements/RTnT.java new file mode 100644 index 0000000..61c5ae0 --- /dev/null +++ b/src/de/steamwar/spectatesystem/elements/RTnT.java @@ -0,0 +1,29 @@ +package de.steamwar.spectatesystem.elements; + +import net.minecraft.server.v1_15_R1.*; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_15_R1.CraftServer; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; + +public class RTnT extends REntity { + + private static World world = null; + + public RTnT(int internalId) { + super(internalId, createTnT()); + } + + @Override + protected void spawnEntity(PlayerConnection connection) { + connection.sendPacket(new PacketPlayOutSpawnEntity(entity)); + } + + private static EntityTNTPrimed createTnT() { + if (world == null) { + MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); + world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); + } + return new EntityTNTPrimed(world, 0, 0, 0, null); + } + +}