package dev.kske.spawnfly; import java.util.*; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.*; import org.bukkit.event.entity.EntityToggleGlideEvent; import org.bukkit.event.player.*; public class SpawnListener implements Listener { int x1, y1, z1, x2, y2, z2; Map canceledEvents = new HashMap<>(); @SuppressWarnings("deprecation") @EventHandler public void onMove(PlayerMoveEvent e) { Player player = e.getPlayer(); Location location = player.getLocation(); if(isInSpawn(location) && player.getVelocity().getY() < 0 && !player.isOnGround() && !canceledEvents.get(player.getName()) && player.getFallDistance() > 1) { player.setGliding(true); canceledEvents.put(player.getName(), true); } } @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { canceledEvents.put(e.getPlayer().getName(), false); } @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { canceledEvents.remove(e.getPlayer().getName()); } private boolean isInSpawn(Location location) { return (location.getX() <= -277 + 3 && location.getX() >= -302 - 3) && (location.getZ() <= -172 + 3 && location.getZ() >= -191 - 3); } @EventHandler public void cancelEvent(EntityToggleGlideEvent e) { if(canceledEvents.get(e.getEntity().getName()) && e.getEntity().getVelocity().getY() != 0 && !e.getEntity().isOnGround()) e.setCancelled(true); else { e.setCancelled(false); canceledEvents.put(e.getEntity().getName(), false); } } public void setCoordinates(int x1, int y1, int z1, int x2, int y2, int z2) { this.x1 = x1; this.y1 = y1; this.z1 = z1; this.x2 = x2; this.y2 = y2; this.z2 = z2; } }