Reworked glide tiggering mechanic to be more usable

This commit is contained in:
Maximilian P. Käfer 2020-11-15 22:39:41 +01:00
parent 631c817382
commit 938a176a9f

View File

@ -10,36 +10,32 @@ import org.bukkit.event.player.*;
public class SpawnListener implements Listener { public class SpawnListener implements Listener {
Map<String, Boolean> activePlayers = new HashMap<>();
Map<String, Boolean> canceledEvents = new HashMap<>(); Map<String, Boolean> canceledEvents = new HashMap<>();
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onMove(PlayerMoveEvent e) { public void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer(); Player player = e.getPlayer();
Location location = player.getLocation(); Location location = player.getLocation();
if(isInSpawn(location)) activePlayers.put(player.getName(), true); if(isInSpawn(location) && player.getVelocity().getY() < 0 && !player.isOnGround() && !canceledEvents.get(player.getName()) && player.getFallDistance() > 1) {
else if(activePlayers.get(player.getName()) && player.getVelocity().getY() < 0) {
player.setGliding(true); player.setGliding(true);
canceledEvents.put(player.getName(), true); canceledEvents.put(player.getName(), true);
activePlayers.put(player.getName(), false);
} }
} }
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
activePlayers.put(e.getPlayer().getName(), isInSpawn(e.getPlayer().getLocation()));
canceledEvents.put(e.getPlayer().getName(), false); canceledEvents.put(e.getPlayer().getName(), false);
} }
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent e) { public void onPlayerQuit(PlayerQuitEvent e) {
activePlayers.remove(e.getPlayer().getName());
canceledEvents.remove(e.getPlayer().getName()); canceledEvents.remove(e.getPlayer().getName());
} }
private boolean isInSpawn(Location location) { private boolean isInSpawn(Location location) {
return (location.getX() <= -277 && location.getX() >= -302) return (location.getX() <= -277 + 3 && location.getX() >= -302 - 3)
&& (location.getZ() <= -172 && location.getZ() >= -191); && (location.getZ() <= -172 + 3 && location.getZ() >= -191 - 3);
} }
@EventHandler @EventHandler