Reworked glide tiggering mechanic to be more usable
This commit is contained in:
parent
631c817382
commit
938a176a9f
@ -10,36 +10,32 @@ import org.bukkit.event.player.*;
|
||||
|
||||
public class SpawnListener implements Listener {
|
||||
|
||||
Map<String, Boolean> activePlayers = new HashMap<>();
|
||||
Map<String, Boolean> canceledEvents = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
Location location = player.getLocation();
|
||||
if(isInSpawn(location)) activePlayers.put(player.getName(), true);
|
||||
else if(activePlayers.get(player.getName()) && player.getVelocity().getY() < 0) {
|
||||
if(isInSpawn(location) && player.getVelocity().getY() < 0 && !player.isOnGround() && !canceledEvents.get(player.getName()) && player.getFallDistance() > 1) {
|
||||
player.setGliding(true);
|
||||
canceledEvents.put(player.getName(), true);
|
||||
activePlayers.put(player.getName(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
activePlayers.put(e.getPlayer().getName(), isInSpawn(e.getPlayer().getLocation()));
|
||||
canceledEvents.put(e.getPlayer().getName(), false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
activePlayers.remove(e.getPlayer().getName());
|
||||
canceledEvents.remove(e.getPlayer().getName());
|
||||
}
|
||||
|
||||
private boolean isInSpawn(Location location) {
|
||||
return (location.getX() <= -277 && location.getX() >= -302)
|
||||
&& (location.getZ() <= -172 && location.getZ() >= -191);
|
||||
return (location.getX() <= -277 + 3 && location.getX() >= -302 - 3)
|
||||
&& (location.getZ() <= -172 + 3 && location.getZ() >= -191 - 3);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Loading…
Reference in New Issue
Block a user