From 9388e1abd5e2ccaf37b3a831f9417aae7330105e Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 19:35:32 +0100 Subject: [PATCH] Add velocity --- .../bausystem/commands/CommandTPSLimiter.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 1827ecd..8365aa7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Particle; @@ -31,6 +32,8 @@ import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -46,41 +49,38 @@ public class CommandTPSLimiter implements CommandExecutor { private BukkitTask tpsLimiter = null; public CommandTPSLimiter() { - /* - - steamwar - ProtocolLib - 1.0 - system - ${main.basedir}/lib/ProtocolLib.jar - - */ - /*ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Core.getInstance(), PacketType.Play.Server.ENTITY_VELOCITY) { - @Override - public void onPacketSending(PacketEvent event) { - if (currentTPSLimit == 20) { - return; - } - - StructureModifier structureModifier = event.getPacket().getIntegers(); - structureModifier.write(1, 0); - structureModifier.write(2, 0); - structureModifier.write(3, 0); - // PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity() - } - });*/ - /*PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(entity); - for(Player player : Bukkit.getOnlinePlayers()){ - PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; - connection.sendPacket(packet); - - - } - world.getEntities().stream().filter(entity -> entity instanceof TNT).forEach(entity -> entity.setVelocity(0, 0, 0));*/ Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { if (currentTPSLimit == 20) { return; } + world.getEntities().stream().filter(entity -> entity instanceof TNTPrimed).forEach(entity -> { + /*DataWatcher dataWatcher = new DataWatcher(entity); + System.out.println("Let " + entity.getName() + " sneak " + sneaking); + dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), sneaking ? (byte)0x02 : (byte)0x40); + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet); + }*/ + + net.minecraft.server.v1_15_R1.Entity serverEntitiy = ((CraftEntity) entity).getHandle(); + + PacketPlayOutEntityVelocity packet1 = new PacketPlayOutEntityVelocity(entity.getEntityId(), new Vec3D(0, 0, 0)); + + PacketPlayOutEntityTeleport packet2 = new PacketPlayOutEntityTeleport(serverEntitiy); + + DataWatcher dataWatcher = new DataWatcher(serverEntitiy); + dataWatcher.register(new DataWatcherObject<>(5, DataWatcherRegistry.i), true); + dataWatcher.register(new DataWatcherObject<>(7, DataWatcherRegistry.b), 80); + PacketPlayOutEntityMetadata packet3 = new PacketPlayOutEntityMetadata(serverEntitiy.getId(), dataWatcher, false); + + Bukkit.getOnlinePlayers().forEach(player -> { + PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; + connection.sendPacket(packet1); + connection.sendPacket(packet2); + connection.sendPacket(packet3); + }); + }); world.getEntities().stream().filter(entity -> entity instanceof TNTPrimed).forEach(entity -> { Location location = entity.getLocation(); world.spawnParticle(Particle.BARRIER, location.getX(), location.getY() + 0.49, location.getZ(), 1);