1.15.2 Help with packets and Particles

Discussion in 'Spigot Plugin Development' started by ArKeid0s, Feb 19, 2020.

  1. So, I have a problem I want to remove the sweeping particles on the client side. I have a piece of code but it not working and I am quit new with packets.
    Can someone help me ?
    Code (Java):
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            CraftPlayer cP = (CraftPlayer) player;
            PlayerConnection pC = cP.getHandle().playerConnection;
            pSP = new PacketsSoundsParticles(pC);
            player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(100);
        }
    Code (Java):
    package fr.arkeidos.heozitems;

    import java.lang.reflect.Field;

    import org.bukkit.Particle;

    import net.minecraft.server.v1_15_R1.MinecraftKey;
    import net.minecraft.server.v1_15_R1.Packet;
    import net.minecraft.server.v1_15_R1.PacketPlayOutNamedSoundEffect;
    import net.minecraft.server.v1_15_R1.PacketPlayOutWorldParticles;
    import net.minecraft.server.v1_15_R1.PlayerConnection;
    import net.minecraft.server.v1_15_R1.SoundEffect;

    public class PacketsSoundsParticles extends PlayerConnection {

        public PacketsSoundsParticles(PlayerConnection originalConnection) {
            super((originalConnection.getPlayer().getHandle()).server, originalConnection.networkManager, originalConnection.getPlayer().getHandle());
        }

        public void sendPacket(Packet<?> packet) {
            if (packet instanceof PacketPlayOutNamedSoundEffect) {
                PacketPlayOutNamedSoundEffect p = (PacketPlayOutNamedSoundEffect)packet;
                try {
                    Field soundEffectField = p.getClass().getDeclaredField("a");
                    Field minecraftKeyField = SoundEffect.class.getDeclaredField("b");
                    soundEffectField.setAccessible(true);
                    minecraftKeyField.setAccessible(true);
                    SoundEffect soundEffect = (SoundEffect)soundEffectField.get(packet);
                    MinecraftKey key = (MinecraftKey)minecraftKeyField.get(soundEffect);
                    if (key.getKey().toLowerCase().contains("entity.player.attack"))
                        return;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (packet instanceof PacketPlayOutWorldParticles) {
                PacketPlayOutWorldParticles p = (PacketPlayOutWorldParticles)packet;
                try {
                    Field particleField = p.getClass().getDeclaredField("a");
                    particleField.setAccessible(true);
                    Particle particle = (Particle) particleField.get(packet);
                    if (particle == Particle.SWEEP_ATTACK || particle == Particle.DAMAGE_INDICATOR)
                        return;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            super.sendPacket(packet);
        }
    }
     
    Thanks in advance