java bukkit double jump

Solutions on MaxInterview for java bukkit double jump by the best coders in the world

showing results for - "java bukkit double jump"
Jonathan
26 Jun 2019
1import java.util.ArrayList;
2import java.util.List;
3
4import org.bukkit.GameMode;
5import org.bukkit.entity.Player;
6import org.bukkit.event.EventHandler;
7import org.bukkit.event.Listener;
8import org.bukkit.event.player.PlayerJoinEvent;
9import org.bukkit.event.player.PlayerMoveEvent;
10import org.bukkit.event.player.PlayerQuitEvent;
11import org.bukkit.event.player.PlayerToggleFlightEvent;
12
13public class DoubleJump implements Listener {
14
15	private List<Player> doubleJump;
16	
17	public DoubleJump() {
18		doubleJump = new ArrayList<>();
19	}
20
21	@EventHandler
22	public void onJoin(PlayerJoinEvent event) {
23		event.getPlayer().setAllowFlight(true);
24	}
25
26	@EventHandler
27	public void onQuit(PlayerQuitEvent event) {
28		doubleJump.remove(event.getPlayer());
29	}
30
31	@EventHandler
32	public void onToggleFlight(PlayerToggleFlightEvent event) {
33		Player player = event.getPlayer();
34		GameMode gameMode = player.getGameMode();
35		
36		if(gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR || player.isFlying()) {
37			return;
38		}
39
40		event.setCancelled(true);
41		doubleJump.add(player);
42
43		player.setAllowFlight(false);
44		player.setFlying(false);
45		player.setVelocity(player.getLocation().getDirection().multiply(1.5).setY(1));
46	}
47
48	@EventHandler
49	public void onHitGround(PlayerMoveEvent event) {
50		Player player = event.getPlayer();
51
52		if ((player.isOnGround() || event.getTo().getBlock().isLiquid()) && doubleJump.remove(player)) {
53			player.setAllowFlight(true);
54		}
55	}
56}