#DoubleJump problem

1 messages · Page 1 of 1 (latest)

royal linden
dire vector
#

that works

#

anyway

#

are you 100% you commented out that other velocity line

#

because currently thats the only thing that could be causing this issue

royal linden
#
public class DoubleJump implements Listener {

    private final HashSet<UUID> cooldown = new HashSet<>();

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        event.getPlayer().setAllowFlight(true);
        cooldown.add(event.getPlayer().getUniqueId());
    }

    @EventHandler
    public void onFly(PlayerToggleFlightEvent event) {
        Player player = event.getPlayer();

        if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
            event.setCancelled(true);
            if (cooldown.contains(player.getUniqueId())) {
                //player.getLocation().setY(event.getPlayer().getLocation().getY() - .1);
                return;
            }
            player.setVelocity(player.getLocation().getDirection().setY(1));
            player.playSound(player.getLocation(), Sound.WITHER_SHOOT,1.0f, 1.0f);
            cooldown.add(player.getUniqueId());
        }
    }

    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        Location location = player.getLocation().clone();
        if (cooldown.contains(player.getUniqueId())) {
            if (location.add(0, -0.5, 0).getBlock().getType().isSolid()) {
                cooldown.remove(player.getUniqueId());
                System.out.println("Removed players UUID!");
            }
        }
    }

    @EventHandler
    public void onGamemodeChange(PlayerGameModeChangeEvent event) {
        if (event.getNewGameMode() == GameMode.SURVIVAL || event.getNewGameMode() == GameMode.ADVENTURE) {
            event.getPlayer().setAllowFlight(true);
        }
    }
}
dire vector
#

ok lets do some trial and error using stupid stuff quickly

#

when the cooldown is added

#

remove the players ability to fly

#

when the cooldown is removed, give the ability back

royal linden
#
public class DoubleJump implements Listener {

    private final HashSet<UUID> cooldown = new HashSet<>();

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        event.getPlayer().setAllowFlight(true);
        cooldown.add(event.getPlayer().getUniqueId());
    }

    @EventHandler
    public void onFly(PlayerToggleFlightEvent event) {
        Player player = event.getPlayer();

        if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
            event.setCancelled(true);
            if (cooldown.contains(player.getUniqueId())) {
                //player.getLocation().setY(event.getPlayer().getLocation().getY() - .1);
                return;
            }
            player.setVelocity(player.getLocation().getDirection().setY(1));
            player.playSound(player.getLocation(), Sound.WITHER_SHOOT,1.0f, 1.0f);
            cooldown.add(player.getUniqueId());
            player.setAllowFlight(false);
        }
    }

    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        Location location = player.getLocation().clone();
        if (cooldown.contains(player.getUniqueId())) {
            if (location.add(0, -0.5, 0).getBlock().getType().isSolid()) {
                cooldown.remove(player.getUniqueId());
                player.setAllowFlight(true);
                System.out.println("Removed players UUID!");
            }
        }
    }

    @EventHandler
    public void onGamemodeChange(PlayerGameModeChangeEvent event) {
        if (event.getNewGameMode() == GameMode.SURVIVAL || event.getNewGameMode() == GameMode.ADVENTURE) {
            event.getPlayer().setAllowFlight(true);
        }
    }
}```
like this?
dire vector
#

yeah

#

see if that works

#

doing it like that since I know mineplex and hypixel do that too

royal linden
#

now it works perfectly fine

dire vector
#

oh

#

so it couldve been an issue when the event was being cancelled

royal linden
#

but sometimes I get falldamage, could you help me cancelling that?

dire vector
#

but now they cant fly at all when cooldown is added, so no chance of doing it again

royal linden
#

oh

dire vector
#

including non-double jump fall damage or all fall damage?

royal linden
#

non-double jump fall damage

#

oh no wait, I need no fall damage at all, but I can do this at my own ig

#

but can I use the double jump code now or is this smth like the wrong way?

dire vector
#

make a Set or something of when a player double jumps, and next time they take damage (EntityDamageEvent), check if its for DamageCause.FALL, and if it is, cancel it and remove them from the set

#

no its fine if it works

#

remove that commented line tho

#

otherwise if you want to yeet all fall damage, just listen to the EntityDamageEvent and if its damage cause FALL, then cancel it

royal linden
#

Oh, and one more question:
Im not sure if I am wrong or not but I think I get the Y-Boost in Gamemode 1 too when flying up, how can I fix that?

dire vector
#

that code wont be doing it

#

there is a very slight Y boost in normal minecraft when you do fly so it could be that

royal linden
#

ohh

#

okay

#

thank you soooo much :)

dire vector
#

took longer to solve than it shouldve lol

#

note to self: dont trust Event#setCancelled

royal linden
#

lol

#

Ive tried to do that like 6 months ago

#

but back then I couldnt do that

dire vector
#

to a simple problem, there'll always be a stupid explanation

royal linden
#

yeah, thank you :)

royal linden
dire vector
#

yes

#

thatll work