2015-05-16 18:58:58 +02:00
|
|
|
package mineplex.game.clans.items.legendaries;
|
|
|
|
|
2015-05-25 20:22:06 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.Entity;
|
2015-05-16 18:58:58 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2015-05-25 20:22:06 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2015-05-16 18:58:58 +02:00
|
|
|
|
|
|
|
public class WindBlade extends LegendaryItem
|
|
|
|
{
|
2015-06-01 18:25:20 +02:00
|
|
|
public static final double FLIGHT_VELOCITY = 0.75d;
|
2015-05-16 18:58:58 +02:00
|
|
|
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()
|
|
|
|
{
|
2015-06-09 21:46:38 +02:00
|
|
|
super("Wind Blade", "Activate flying ability to take flight for 80 ticks before landing!", Material.RECORD_8); // TODO: Configurable?
|
2015-05-25 20:22:06 +02:00
|
|
|
|
2015-05-16 18:58:58 +02:00
|
|
|
_flightTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(Player wielder)
|
|
|
|
{
|
2015-05-25 20:22:06 +02:00
|
|
|
Entity entity = (Entity) wielder;
|
|
|
|
|
|
|
|
// Check if player is attempting to fly and activate
|
2015-05-16 18:58:58 +02:00
|
|
|
if (isHoldingRightClick() && canPropel())
|
|
|
|
{
|
|
|
|
propelPlayer(wielder);
|
|
|
|
}
|
2015-05-25 20:22:06 +02:00
|
|
|
|
|
|
|
// Check if player has touched down
|
|
|
|
if (entity.isOnGround())
|
|
|
|
{
|
|
|
|
_flightTime = 0;
|
|
|
|
}
|
2015-05-16 18:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void propelPlayer(Player player)
|
|
|
|
{
|
|
|
|
_flightTime++;
|
2015-05-25 20:22:06 +02:00
|
|
|
Vector direction = player.getLocation().getDirection().normalize();
|
|
|
|
direction.multiply(FLIGHT_VELOCITY); // Set velocity magnitude
|
|
|
|
|
|
|
|
player.setVelocity(direction);
|
2015-06-29 22:38:51 +02:00
|
|
|
player.setFallDistance(0f); // To prevent bug with fall distances killing players inappropriately.
|
2015-05-16 18:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean canPropel()
|
|
|
|
{
|
|
|
|
return _flightTime <= MAX_FLIGHT_TIME;
|
|
|
|
}
|
|
|
|
}
|