Solved Double Jump

Discussion in 'Plugin Development' started by xWatermelon, Feb 2, 2013.

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

    xWatermelon

    Hi, how can I make it so when a player hits the jump key in midair they can jump again? If that isn't possible, then how can I make it so when a player clicks on gold boots s/he will get another bounce? I know about PlayerInteractEvent, but how can I make the player "bounce" again (get a boost up and forward where they are looking, just like jumping)?
     
  2. If you try to do a regular jump while you're already in the air, the Minecraft client doesn't send a packet to the server, so there's no way´╗┐ to detect it.
     
    xWatermelon likes this.
  3. onPlayerInteract, set the player velocity to about 0,1,0 for 'jump' affect?
     
    xWatermelon likes this.
  4. ZeusAllMighty11 A "jump" effect is probably about 0.25, 1 will launch them about 15-20 blocks in the air :p.
     
    xWatermelon likes this.
  5. Offline

    xWatermelon

    Would player.setVelocity(new Vector(0, 0.25, 0)) work?
     
  6. Offline

    MrTwiggy

    One work around for being able to double jump is wait until a player jumps, give them the ability to fly, and when the press the space bar again, they will start flying and you can detect it, cancel it, and activate the jump.

    It's a bit more complicated then that, but when done well, it works good.
     
    xWatermelon likes this.
  7. Couldn't they just tap and hold the space bar in the time before you detect it?
     
    xWatermelon likes this.
  8. Offline

    MrTwiggy

    That's why you cancel the fly movement before you activate the double jump.
     
    xWatermelon likes this.
  9. Offline

    xWatermelon

    Interesting... Can you show me some example code?
     
  10. That is very interesting.. Just like the TF2 scout class.. You could always use the 'jump boost' potion effect..
     
    xWatermelon likes this.
  11. But then players would always have to jump high. With the extra jump, they could have an option between regular jump and double jump.
     
    xWatermelon likes this.
  12. xWatermelon
    Well you could allow flight, and on move, check if player is flying (double jump), then setFlying(false), and add the velocity.
    Just an idea that might not work, but that's how I'd do a double jump.
     
    Jhtzb and xWatermelon like this.
  13. You even don't have to check playerMoveEvent as long as the PlayerToggleFlightEvent is doing what it says.
     
    xWatermelon likes this.
  14. When they are flying, disable it then start a delayed task to enable it. Then I just noticed in Smash server by ShotBow you have to touch the ground again before you can use the jump.
     
    xWatermelon likes this.
  15. yes i would do it like that...
     
    xWatermelon likes this.
  16. Offline

    xWatermelon

  17. That's not how to learn T__T
     
  18. The best way to learn is by trying to do it by yourself, instead of just asking for the code for it. If you don't know where to start, then it's okay to ask for some help.
    I'll try my method later, and see if it works, if it does, then I'll post it here.
     
    xWatermelon likes this.
  19. I have achieved this by: when they jump and they hold shift in mid-air they go up another block, but that code is private :)
     
    xWatermelon likes this.
  20. A wild idea appeared!
    Code:
    @EventHandler
    public void onFlightAttempt(PlayerToggleFlightEvent event) {
     
        if(!event.isFlying && event.getPlayer().getGameMode() != GameMode.CREATIVE) {
     
            event.getPlayer().setVelocity(event.getPlayer().getVelocity().add(new Vector(0,0.25,0)));
            event.setCancelled(true);
     
        }
     
    }
    On starting the jump, if a player taps twice they jump higher ;D
     
    puyttre and xWatermelon like this.
  21. MrBluebear3 wouldn't you need to stop flight? event.getPlayer().setFlying(false).
     
    xWatermelon likes this.
  22. Yeah, just added that in ;)
     
    xWatermelon likes this.
  23. Wouldn't you need player.setVelocity(player.getVelocity().add(0, 0.25, 0));
     
    MrBluebear3 and xWatermelon like this.
  24. Offline

    treestompz

    Code:
    @EventHandler
            public void onFlightAttempt(PlayerToggleFlightEvent event) {
           
                Player p = event.getPlayer();     
                p.sendMessage(ChatColor.GREEN + "**WOOSH**");
                p.playSound(p.getLocation(), Sound.IRONGOLEM_THROW, 10, -10);
                event.setCancelled(true);
                Vector v = p.getLocation().getDirection().multiply(1).setY(1);
                p.setVelocity(v);
           
            }
    That code works fine if the player is in creative. I am confused on how to make this work without a player having creative mode. Any ideas?
     
  25. set the players fly mode to true then wait for them to move up and if/when they do double jump.
     
  26. Offline

    treestompz

    SoThatsIt

    Code:
    @EventHandler
            public void setFlyOnJoin(PlayerJoinEvent event)
            {
                Player p = event.getPlayer();
                if(p.hasPermission("derp.jump"))
                {
                p.setAllowFlight(true);
                p.setFlying(true);
                }
            }
     
            @EventHandler
            public void onFlightAttempt(PlayerToggleFlightEvent event) {
                     
                Player p = event.getPlayer();
                if(p.isOp() == false && p.getGameMode() != GameMode.CREATIVE)
                {
                    p.sendMessage(ChatColor.GREEN + "**WOOSH**");
                    p.playSound(p.getLocation(), Sound.IRONGOLEM_THROW, 10, -10);
                    event.setCancelled(true);
                    Vector v = p.getLocation().getDirection().multiply(1).setY(1);
                    p.setVelocity(v);
                }
         
            }
    Sorry I am new to all this :3

    I tried setting the players fly mode to true when the player joins, but that won't work because then he will be able to fly around :/ Where should I set the player to flying? I can't in the PlayerToggleFlightEvent because that will only work if he is already flying...right?
     
  27. do it when the player initially jumps, you may have to listen to player move event and check if the players y velocity is greater than 0.
     
  28. Offline

    treestompz

    Thank you sir :)!
     
  29. here is my easy code but you can jump as many times you want does anybody know how to fix that?
    code:
    Code:
    package com.shinxs.udb.listeners;
     
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerToggleFlightEvent;
    import org.bukkit.util.Vector;
     
    import com.shinxs.udb.Main;
     
    public class DoubleJump implements Listener {
     
        public Main plugin;
       
        public DoubleJump(Main plugin) {
            Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
            this.plugin = plugin;
        }
       
        @EventHandler
        public void join(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            player.setAllowFlight(true);
        }
       
        @EventHandler
        public void setFlyOnJump(PlayerToggleFlightEvent event) {
            Player player = event.getPlayer();
           
            if(event.isFlying() && event.getPlayer().getGameMode() != GameMode.CREATIVE) {
               
                player.setFlying(false);
                Vector jump = player.getLocation().getDirection().multiply(0.2).setY(1.1);
                player.setVelocity(player.getVelocity().add(jump));
               
                event.setCancelled(true);
            }
        }
    }
     
  30. Shinxs

    Store the player somewhere and then do a simple list check
     
Thread Status:
Not open for further replies.

Share This Page