Double Jump Problem

Discussion in 'Plugin Development' started by BrennyMullan, Jun 21, 2014.

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

    BrennyMullan

    Im creating a little plugin that uses the firework to double jump

    Player can right click the firework twice to give him two jumps, first one being from the ground and the second one in the air however the problem i am having is if the player only jumps once and lands back on the ground without finishing the double jump, the next time they try it they will have 3 jumps available instead of two.

    Code:
    public static ArrayList<Player> firework = new ArrayList<Player>();
    public static int jumps;
     
    //Playerinteract
    if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
    if (player.getItemInHand().getT,ype() == Material.FIREWORK){
           event.setCancelled(true);
           if (!firework.contains(player)) {
                Vector vector = player.getEyeLocation().getDirection();
                vector.multiply(1);
                vector.setY(0.8);
                player.setVelocity(vector);
                jumps++;
               if (jumps == 2){
               firework.add(player);
               jumps = 0;
    }
    }
     
    //Playermove
    if (PlayerInteract.firework.contains(p)){
          if (p.isOnGround()){
          PlayerInteract.firework.remove(p);
          }
            }
    
     
  2. Offline

    Epixpenguin

    Check when the player is back on the ground and set your int jumps to 0.
     
  3. Offline

    Zupsub

    Why do you multiply with 1?
    I'm convinced, your static jumps aren't what you want. Would make more sense, if every player has a jump var. => look at OOP. Make a new class with a field jump and a bukkit player.
     
  4. Offline

    werter318

    Zupsub Actually, you can just use a HashMap<UUID, Integer> for this.
     
  5. Offline

    BrennyMullan

    Code:java
    1. //PlayerInteract
    2. public static HashMap<Player, Integer> jump = new HashMap<Player, Integer>();
    3. if (!jump.containsKey(player)) {
    4. jump.put(player, 1);
    5. Vector vector = player.getEyeLocation().getDirection();
    6. vector.multiply(1);
    7. vector.setY(0.8);
    8. player.setVelocity(vector);
    9. }else if (jump.get(player) < 2){
    10. Vector vector = player.getEyeLocation().getDirection();
    11. vector.multiply(1);
    12. vector.setY(0.8);
    13. player.setVelocity(vector);
    14. int j = jump.get(player);
    15. jump.put(player, j+1);
    16. }
    17.  
    18. //PlayerMove
    19. if (b.getType() != Material.AIR
    20. || b.getRelative(BlockFace.DOWN).getType() != Material.AIR) {
    21. if (PlayerInteract.jump.containsKey(p)){
    22. PlayerInteract.jump.remove(p);
    23. }
    24.  
    25. }


    Works fine apart from if they take off from the ground, if they click twice while in mid air it will give them the double jump but if they click first from the ground they will get 3 jumps instead of 2 because of the playermove code im sure. mazentheamazin @Graysoldier

    Bump this up

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    AoH_Ruthless

    BrennyMullan
    Instead of commenting out part of your code, we need both full events. You have a PlayerInteractEvent.jump and I'm positive you have a static PlayerInteractEvent ... remove static identifiers. Firstly, you can't listen for an event in Bukkit if it static, and second, static modifiers are generally a bad practice and don't look like they are useful for this application.
     
  7. Offline

    BrennyMullan

    AoH_Ruthless of course the event is not static. The interact event is long and has other code in it aside from this which is why i never showed the lot. The PlayerInteractEvent.jump is

    Code:java
    1. public static HashMap<Player, Integer> jump = new HashMap<Player, Integer>();


    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page