Solved Lifting a player.

Discussion in 'Plugin Development' started by Fergym, Oct 14, 2015.

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

    Fergym

    Okay, so, basically, I'm working on a plugin right now called HubJetPacks, and was wondering if it would be possible to lift a player upon them interacting with a material. I have the EventHandler set up, and I'm now wondering how to do this. Thanks.
     
  2. Offline

    Zombie_Striker

    @Fergym
    player,setVelocity(player.getVelocity().add(0,1,0));
     
    Last edited: Oct 14, 2015
    Fergym likes this.
  3. Offline

    Fergym

    Shows a couple of errors:
    - The method add(Vector) in the type Vector is not applicable for the arguments (int,
    int, int)
    - Line breakpoint: PlayerListener [line: 27] - onPlayerUse(PlayerInteractEvent)
    Code:
    if(player.getItemInHand().getType() == Material.BLAZE_ROD){
                player.setVelocity(player.getVelocity().add(0,1,0));
        }
     
  4. Offline

    Zombie_Striker

    @Fergym My bad. I though it took in a vector.

    Try this instead:
    Code:
    int x = player.getVelocity().getX();
    int y = player.getVelocity().getY();
    int z = player.getVelocity().getZ();
    
    player.setVelocity(x,y+1,z);
    This will send the player staight up into the air
     
  5. Offline

    Fergym

    Weird, still shows errors:
    Type mismatch: cannot convert from double to int
     
  6. Offline

    Zombie_Striker

    @Fergym
    Then that is most likely a problem with your IDE, since x,y and z are all integers, and +1 should still make it an integer.

    Try refreshing your workbench, close it and open it again. That error should not be happening.

    [edit] do you have anything that is also named x,y, or z?
     
  7. Offline

    Fergym

    Using Eclipse Luna, refreshed, opened and closed, nothing else named x,y or z. :/
     
  8. Offline

    Xerox262

    Try changing type of x, y and z from int to doubles?
    player.getVelocity().getX(); returns a double
     
  9. Offline

    Zombie_Striker

    @Xerox262
    @Fergym

    Sorry, you have to cast the double to an int. Forgot that.
    Code:
    int x = (int)player.getVelocity().getX();
     
    Fergym likes this.
  10. Offline

    Xerox262

    Yea, but it's better if he keeps it as a douible, it keeps it at it's exact velocity instead of rounding up or down
     
  11. Offline

    Chloe-chan

    Use double instead of int.
    Code:
    double x = player.getVelocity().getX();
    double y = player.getVelocity().getY();
    double z = player.getVelocity().getZ();
    player.setVelocity(x, y + 1, z);
     
  12. Offline

    Fergym

    [STRIKETHROUGH]Did try that upon seeing the error, I'll try it again, however I think it produced a separate error.[/STRIKETHROUGH]

    Yeah, I thought about casting the int as it was in CTRL + Space :p

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Oct 14, 2015
  13. Offline

    Chloe-chan

    Don't cast into an int, it will truncate the values of the double, which can affect the player's velocity.
    Why bother using int when getX() returns a double, and setX() accepts a double too ?
     
  14. Offline

    Xerox262

    player.setVelocity(player.getVelocity().add(0,1,0));
    Just so you know, this would've worked if you would have used doubles instead of ints player.setVelocity(player.getVelocity().add(0.0,1.0,0.0));
     
    Zombie_Striker likes this.
  15. Offline

    Fergym

    Sorry, my bad. I still get errors though when using player.setVelocity(player.getVelocity().add(0.0,1.0,0.0));
    or player.setVelocity(x, y +1, z);
    The Error is "The method add/setVelocity(Vector) in the type Vector is not applicable for the arguments (double, double, double)"
    For both of them.
     
    Last edited: Oct 14, 2015
  16. Offline

    Chloe-chan

    You can either
    Code:
    double x = player.getVelocity().getX();
    double y = player.getVelocity().getY();
    double z = player.getVelocity().getZ();
    player.setVelocity(x, y + 1, z);
    or
    Code:
    player.setVelocity(player.getVelocity().add(new Vector(0.0, 1.0, 0.0)));
     
    Xerox262 likes this.
  17. Offline

    Fergym

    Thank you :) Sorry it took so long.
     
  18. Offline

    Chloe-chan

    Glad it worked out for you. Mark as filled if your problem is solved.
     
  19. Offline

    DoggyCode™

    solved*
     
  20. Offline

    Chloe-chan

    Well yea, you get the point.
     
    DoggyCode™ likes this.
  21. Offline

    DoggyCode™

    :p I always do
     
Thread Status:
Not open for further replies.

Share This Page