Solved setVelocity not doing anything

Discussion in 'Plugin Development' started by johnny boy, Feb 9, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    johnny boy

    Code:
        @EventHandler
        public void onEggThrow(PlayerEggThrowEvent e) {
          
            Player pl = e.getPlayer();
          
            Egg egg = e.getEgg();
              
            egg.getVelocity.multiply(10); 
          
            e.getEgg().getWorld().spawn(egg.getLocation().add(0, 0.5, 0), TNTPrimed.class);
      
        }
    My code seems to work fine apart from the part where I want the velocity to be like, let's say 10 times more. It doesn't seem to have a noticeable affect.

    EDIT: Edited code slightly, thanks timtower!
     
    Last edited by a moderator: Feb 9, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    johnny_boy likes this.
  3. Offline

    johnny boy

    oh, can I actually do that?! Thank you I'll try it now..

    Hmm doesn't do anything, unless I'm misunderstanding what it does?
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    johnny boy

    No I just want the egg to move really fast.
    @timtower
     
  6. Offline

    timtower Administrator Administrator Moderator

    Not an answer to the question.
    Is the event even running?
    Did you print the old and the new velocity?
     
  7. Offline

    johnny boy

    oh I've just realised for some reason it only changes the velocity when the egg lands?!

    EDIT: And it is running, and I've printed out the velocities and they do in fact change but only when the egg lands.
     
  8. Offline

    timtower Administrator Administrator Moderator

    And how did you found out that it only changes when it lands? You are using the PlayerEggThrowEvent
     
  9. Offline

    johnny boy

    So I'm using the wrong event for all of this. I'll go find the right one then.

    But like... Why is it called PlayerEggThrowEvent then?
     
  10. Offline

    timtower Administrator Administrator Moderator

    I am not saying that it is the wrong one, I asked how you found out that it changes when the egg lands.
     
  11. Offline

    johnny boy

    oh because I noticed it didn't print out until the egg actually landed AS SOON as it touched the ground. Sorry for misunderstanding you. And it does indeed print out the velocities, clearly showing an increase in velocity by, I'd say, 100.

    EDIT: The reason I was confused is because you said You are using the PlayerEggThrowEvent which I thought you meant you were implying that I was using the wrong event.

    This is pointless anyway and doesn't matter, but feel free to help me if you want to.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 9, 2018
  12. Offline

    Lorinthio

    My guess if this fires when the egg lands... is that the "PlayerEggThrowEvent" triggers when an egg is breaking on the ground that a player threw. Better name might be PlayerEggBrokenEvent, regardless doesn't matter.

    JavaDocs explains the event as - Called when a player throws an egg and it might hatch.

    Instead try ProjectileLaunchEvent, and check if the projectile is an egg, then multiply the velocity
     
  13. Offline

    johnny boy

    Yep thank you again, solved, again.
     
Thread Status:
Not open for further replies.

Share This Page