package mineplex.game.clans.items.legendaries; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; public class WindBlade extends LegendaryItem { public static final double FLIGHT_VELOCITY = 0.75d; public static final int MAX_FLIGHT_TIME = 80; // Max flight of 80 ticks private long _flightTime; // Time (in ticks) since last touching ground and flying public WindBlade() { super("Wind Blade", "Activate flying ability to take flight for 80 ticks before landing!", Material.RECORD_8); // TODO: Configurable? _flightTime = 0; } @Override public void update(Player wielder) { Entity entity = (Entity) wielder; // Check if player is attempting to fly and activate if (isHoldingRightClick() && canPropel()) { propelPlayer(wielder); } // Check if player has touched down if (entity.isOnGround()) { _flightTime = 0; } } private void propelPlayer(Player player) { _flightTime++; Vector direction = player.getLocation().getDirection().normalize(); direction.multiply(FLIGHT_VELOCITY); // Set velocity magnitude player.setVelocity(direction); player.setFallDistance(0f); // To prevent bug with fall distances killing players inappropriately. } private boolean canPropel() { return _flightTime <= MAX_FLIGHT_TIME; } }