Solved Double Jump

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

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

    Shinxs

    what do you mean?
     
  2. Offline

    chasechocolate

    Shinxs
    Code:java
    1. public List<String> justJumped = new ArrayList<String>();
    2. if(justJumped.contains(player.getName()){
    3. //The can't jump
    4. } else {
    5. //They can jump
    6. justJumped.add(player.getName());
    7. }

    However, that would make it so they can only jump once, so I would create a scheduler to remove them from the list after some time.
     
  3. Offline

    molenzwiebel

    I would give the player a ridiculous fall distance (3000) and set allow flight to false. Then when the fall damage get's triggered, check if the fall distance is more than 3000 and if so, allow the player to fly again.
     
    microgeek likes this.
  4. Offline

    Shinxs

    i did it on another way and it works fine and you can set how many times someone can jump code:
    Code:
    package com.shinxs.doublejump.listeners;
     
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    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.doublejump.Main;
     
    public class DoubleJump implements Listener {
     
        public Main plugin;
        int timesJumped = 0;
       
        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();
            Vector jump = player.getLocation().getDirection().multiply(0.2).setY(1);
            Location loc = player.getLocation();
            Block block = loc.add(0, -1, 0).getBlock();
           
            if(event.isFlying() && event.getPlayer().getGameMode() != GameMode.CREATIVE) {
               
                if(timesJumped != 2) {
                    player.setFlying(false);
                    player.setVelocity(player.getVelocity().add(jump));
                    timesJumped++;
                }
               
                else if(timesJumped == 2) {
                    if(block.getType() != Material.AIR) {
                        player.setAllowFlight(true);
                        timesJumped = 0;
                    } else {
                        player.setFlying(false);
                        player.setAllowFlight(true);
                    }
                }
               
                event.setCancelled(true);
            }
        }
    }
     
  5. Offline

    superpeanut911

    This is awesome! I will keep this thread in mind...
     
  6. Offline

    xWatermelon

    Shinxs How high will that make them "jump"?
     
  7. Offline

    Shinxs

    this around 4 blocks but check out my plugin there you can set how high you want them to jump
     
  8. Offline

    superpeanut911

    The problem with this is that it allows fly hacking. I tested it, if you use nodus and set your nodus fly speed to .5 it bypasses NoCheat :/
     
  9. Offline

    Shinxs

    oww i actuallyhave no idea on how to fix it you should make a forum thread and send the answer to me
     
  10. Offline

    chasechocolate

    Or instead of making them allowed to fly, just listen for PlayerInteractEvent and check if they right click while holding a certain item (maybe a feather) and then launch them.
     
  11. Offline

    _Filip

    Private. eh?
    Code:
        public void onPlayerSneakEvent(PlayerToggleSneakEvent event){
            Player p = event.getPlayer();
            if (event.isSneaking()){
                if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR)){
                    p.teleport(new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY() + 2, p.getLocation().getZ()));
                }
            }
        }
    Thing is, this would work better:
    Code:
        HashMap<String, Long> previousDoubleJump = new HashMap<String, Long>();
     
        @EventHandler
        public void onPlayerSneakEvent(PlayerToggleSneakEvent event){
            Player p = event.getPlayer();
            if (event.isSneaking()){
                if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR)){
                    try{
                        if (previousDoubleJump.get(p.getWorld().getFullTime() - previousDoubleJump.get(p)) < 60){
                            return;
                        }
                    }
                    catch (NullPointerException e){
                        p.setVelocity(new Vector(0, 0.25, 0));
                        previousDoubleJump.put(p.getName(), p.getWorld().getFullTime());
                    }
                }
            }
        }
    Or, when they double jump, it stores their name and p.getWorld().getFullTime() in a HashMap
    Then next time they try to double jump, it subtracts p.getWorld().getFullTime() with the one in the HashMap and if it's less than 60 ticks, it returns.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  12. Offline

    superpeanut911

    I checked if they had a feather in their hand on the player move, and checked if their Y axis is increasing. It works well other than the fact that if you climb up stairs or if your on half slabs it gets a bit confused
     
  13. Offline

    teti100teti

    Yes it is <3

    I just got an idea how to do this :D..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  14. Offline

    110%


    That's not private, it's JumpPlus. -_- dev.bukkit.org/server-mods/jumpplus


    Oh wait... this was BEFORE Shinxs made JumpPlus. Sorry! :D :oops:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  15. Offline

    Jozeth

    My code is PRIVATE... Think before you comment.
     
  16. Offline

    Maulss

    Check if the player is on the ground, and if he is set jump(true).

    Something like this:
    Code:
    if (((CraftPlayer)p.getPlayer()).getHandle().onGround) {
    p.setJump(true);
     
  17. Offline

    110%

    ? It's not your code, and it's not my plugin.
     
  18. Offline

    Plo124

    I'm developing a plugin for my server, and I don't want them to have fly all the time, even if when you do fly, you will double jump (I set the jumping only to work in a certain area), cuz this is a survival server, and giving out fly would be a terrible thing. How would I go about making this only happen when you jump?
     
  19. Offline

    caseif

    Plo124 Do you even resurrect?
     
  20. Offline

    Plo124

    Sorry, I'm new to the forums, that's my first post :confused:
     
Thread Status:
Not open for further replies.

Share This Page