Solved PacketPlayOutWorldParticles Particle Type

Discussion in 'Spigot Plugin Development' started by TKUIYEAGER1, Aug 6, 2018.

  1. As title says, how can I get the type or name of the particle?
     
  2. use this to recover the particles EnumParticle
     
  3. Regarding 1.13:
    https://wiki.vg/Protocol#Particle
    There is a table with all names & IDs.

    Try to pass:
    Code (Java):
    Particle.REGISTRY.get(new MinecraftKey("<particlename>"))
    to the constructur of the PacketPlayOutWorldParticle, the other values are the common particle properties (as shown in the wiki.vg table above).

    There is no EnumParticle. Not within bukkit, not within spigot, neither within NMS.
     
  4. I already have the packet now I want to get its type so I can compare it to other types.
     
  5. There is no getter method.
    You need to get the field "net.minecraft.server.v1_13_R1.PacketPlayOutWorldParticles.j" by refelctions out of the packet instance.

    So does it work like i suggested with the Particles.REGISTRY and the MinecraftKey? Or how do you create a new instance?
     
  6. I don't mess with packets and reflections a lot, do you have an example or a more detailed explanation?
     
  7. You first…
    Show me where and how you create an instance of the Packet, then i show you how to get the type out of it.
     
  8. Basically what I am trying to do is to prevent Heart particles from showing.
    I am using TheSourceCode code (he is a youtuber) for checking which packets are written and read (https://github.com/The-SourceCode/A...ener/src/me/tsccoding/packets/PacketMain.java). Now I need to check if the particle type is hearts.
     
  9. Meh… i don't like YT tutorials… just a personal thing.
    Code (Java):
    PacketPlayOutWorldParticles particle // ... wherever this comes from in your case ...
    try {
        Field paramField = particle.getClass().getDeclaredField("j");
        paramField.setAccessible(true);
        ParticleParam param = (ParticleParam) paramField.get(particle);
        // either compare it with #equals or find out what the method #a -> String Returns, maybe the particle Name
        // just try it and do some debug outputs to console
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        // do whatever you want to do if it fails to do a valid check
    }
    EDIT: Maybe you can cast ParticleParam to ParticleType, since ParticleType implements ParticleParam...
     
  10. Code (Java):
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.FOOTSTEP, true,
                    (float) loc.getX(), (float) (loc.getY()+0.1), (float) loc.getZ(), 0, 0, 0, 0, 20, 10);
     
  11. That's not 1.13, is it?

    EDIT: OP didn't told us yet, what version he/she uses, too.
     
  12. I get errors for this code:
    Code (Java):
    public void write(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise channelPromise)
                        throws Exception {
                    if (packet instanceof PacketPlayOutWorldParticles) {
                        PacketPlayOutWorldParticles packetPlayOutWorldParticles = (PacketPlayOutWorldParticles) packet;
                        Bukkit.getServer().broadcastMessage("1");
                        try {
                            Field paramField = PacketPlayOutWorldParticles.class.getDeclaredField("j");
                            paramField.setAccessible(true);
                            ParticleParam param = (ParticleParam) paramField.get(packetPlayOutWorldParticles);
                            ParticleType paramType = (ParticleType) param;
                            Bukkit.getServer().broadcastMessage(paramType.toString());
                        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
                                | IllegalAccessException e) {
                            e.printStackTrace();
                        }
                    }
                    super.write(channelHandlerContext, packet, channelPromise);
                }

    Error:
    Code (Text):
    [16:49:15 INFO]: 1
    [16:49:15 WARN]: java.lang.IllegalArgumentException: Can not set net.minecraft.server.v1_13_R1.ParticleParam field net.minecraft.server.v1_13_R1.PacketPlayOutWorldParticles.j to java.lang.String
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(Unknown Source)
    [16:49:15 WARN]:        at java.base/java.lang.reflect.Field.get(Unknown Source)
    [16:49:15 WARN]:        at me.tkuiyeager1.nomobhearts.Main$1.write(Main.java:67)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831)
    [16:49:15 WARN]:        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1071)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:300)
    [16:49:15 WARN]:        at net.minecraft.server.v1_13_R1.NetworkManager.lambda$4(NetworkManager.java:199)
    [16:49:15 WARN]:        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    [16:49:15 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    [16:49:15 WARN]:        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:465)
    [16:49:15 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    [16:49:15 WARN]:        at java.base/java.lang.Thread.run(Unknown Source)
    [16:49:15 INFO]: 1
    [16:49:15 WARN]: java.lang.IllegalArgumentException: Can not set net.minecraft.server.v1_13_R1.ParticleParam field net.minecraft.server.v1_13_R1.PacketPlayOutWorldParticles.j to java.lang.String
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
    [16:49:15 WARN]:        at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(Unknown Source)
    [16:49:15 WARN]:        at java.base/java.lang.reflect.Field.get(Unknown Source)
    [16:49:15 WARN]:        at me.tkuiyeager1.nomobhearts.Main$1.write(Main.java:67)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831)
    [16:49:15 WARN]:        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1071)
    [16:49:15 WARN]:        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:300)
    [16:49:15 WARN]:        at net.minecraft.server.v1_13_R1.NetworkManager.lambda$4(NetworkManager.java:199)
    [16:49:15 WARN]:        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    [16:49:15 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    [16:49:15 WARN]:        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:465)
    [16:49:15 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    [16:49:15 WARN]:        at java.base/java.lang.Thread.run(Unknown Source)

    It is stuck on saying the error is in line 67 which was a comment before, at the current code here line 67 is:
    Code (Text):
    ParticleParam param = (ParticleParam) paramField.get(packetPlayOutWorldParticles);
     
  13. Try "packetPlayOutWorldParticles.getClass()" instead of "PacketPlayOutWorldParticles.class" when assigning paramField.
    And check if "ParticleParam param" is a instance of "ParticleType" before casting it.
     
  14. @Michel_0 It still doesn't work I have the ParticleType but how can I compare it to Heart ParticleType?
     
  15. What does this return?
    What returns paramType.a()?
    Is the ParticleParam object a instance of ParticleType?
     
  16. Yes I can cast it but the .toString() gives some net.minecraft..........ParticleType?asa2123132asd1 bla bla, but it changes almost every time server restart, I need to get the actual name and I don't know how.
     
  17. Why you don’t use Player#spawnParticle or World#spawnParticle ?
     
  18. I have a packet for particles play out world and I need to check if the played particles are hearts.
     
  19. particleType.a() uses the REGISTRY to receive the result, you got a good Chance, that this is the name.