Solved PacketPlayOutWorldParticles not working!

Discussion in 'Spigot Plugin Development' started by Orangemaster123, May 26, 2017.

  1. When i use PacketPlayOutWorldParticles it says the constructor PacketPlayOutWorldParticles() is underfined.

    Here is my code for PacketPlayOutWorldParticles.
    Code (Text):


    PacketPlayOutWorldParticles heart = new PacketPlayOutWorldParticles(
    EnumParticle.HEART,
    true,
    player.getLocation().getX(),
    player.getLocation().getY(),
    player.getLocation().getZ(),
    0,
    0,
    0,

    10,

    300,

    null

    );

     
    Any ideas on how to fix this?
     
  2. What version of Spigot are you using?
     
  3. version 1.8.8
     
  4. Hm, well can't really remember what it looked like that long ago, but I'm not sure what that "null" you have in there is for. The current constructor takes a varargs int list at the end instead of whatever you have as null- maybe try just leaving that off?

    Sorry, I was actually hoping you were going to say you were on a current version so I could tell you to just use the spawnParticle API.
     
  5. I dont really understand what this means, but i think this is the problem. When i hover over the imported class for PacketPlayOutWorldParticles its says "This element neither has attached source nor attached Javadoc and hence no Javadoc could be found." Do you have any idea what this actually means?
     
    #5 Orangemaster123, May 26, 2017
    Last edited: May 26, 2017
  6. That just means your IDE doesn't know about the class.

    If it's undefined, perhaps you haven't imported CraftBukkit, the server library, into your plugin.
     
  7. Is there a fix for this? I have imported spigot which I'm pretty sure comes with craftbukkit.
     
  8. Fix for what? That's no bug.
    If the constructor is "undefined", that means you're supplying the wrong order of arguments to it.
    The one and only constructor for the class is as follows:
    Code (Text):
    PacketPlayOutWorldParticles(EnumParticle arg0, boolean arg1, float arg2, float arg3, float arg4, float arg5, float arg6, float arg7, float arg8, int arg9, int... arg10)
    Note the varargs int at the end - you don't actually need to supply anything there, almost as if you were missing an argument - varargs is an array of varying length, like int[] but for constructors and methods where more than one of a type are welcome.
    Code (Text):
    void example(int... args) {}
    Code (Text):
    example();
    example(1);
    example(1, 1, 5);
    int[] args = new int[] {1, 2, 3, 4, 5};
    example(args);
    Getting back to your problem, your arguments don't match the required order.
    Code (Text):
    PacketPlayOutWorldParticles heart = new PacketPlayOutWorldParticles(EnumParticle.HEART, true, (float) player.getLocation().getX(), (float) player.getLocation().getY(), (float) player.getLocation().getZ(), 0, 0, 0, 10, 300);
    The above will fix your issue.
    The constructor's arguments are labelled arg1, arg2, etc., which is not at all explanatory.

    Here's some pseudocode representing the proper arguments:
    Code (Text):
    PacketPlayOutWorldParticles(EnumParticle particleType, boolean visibleFromFarAway, float x, float y, float z, float offsetX, float offsetY, float offsetZ, float speed, int amount, int... data);
    Because Location.getX() returns a double, which is not a float, your IDE will complain when you don't cast it to the correct type for the constructor "(float)". Using the literal 0 does not exhibit this issue, but if you wanted to use another number, you can suffix it with "f", as in 2f. This denotes the literal as a float, without the need to cast.

    Hopefully this helps :3
     
    • Like Like x 1
    • Friendly Friendly x 1
  9. Thanks so much this worked!
     
    • Like Like x 1