2015-05-16 18:58:58 +02:00
|
|
|
package mineplex.game.clans.items.legendaries;
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
import mineplex.core.common.util.UtilAction;
|
|
|
|
import mineplex.core.common.util.UtilAlg;
|
|
|
|
import mineplex.core.common.util.UtilMath;
|
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2015-05-16 18:58:58 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
2015-06-01 18:25:20 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2015-05-16 18:58:58 +02:00
|
|
|
|
|
|
|
public class MagneticBlade extends LegendaryItem
|
|
|
|
{
|
|
|
|
|
2015-06-01 18:25:20 +02:00
|
|
|
public static final double PULL_RANGE = 10d;
|
|
|
|
|
2015-05-16 18:58:58 +02:00
|
|
|
public MagneticBlade()
|
|
|
|
{
|
2015-06-09 21:46:38 +02:00
|
|
|
super("Magnetic Blade", "Pull enemies closer with special abilities!", Material.RECORD_6);
|
2015-05-16 18:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(Player wielder)
|
|
|
|
{
|
|
|
|
if (isHoldingRightClick() && canPull())
|
|
|
|
{
|
|
|
|
pullPlayers(wielder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-01 18:25:20 +02:00
|
|
|
public void onAttack(CustomDamageEvent event, Player wielder)
|
2015-05-16 18:58:58 +02:00
|
|
|
{
|
2015-06-01 18:25:20 +02:00
|
|
|
event.AddKnockback("Magnetic Blade", -0.5d); // Pull players with negative knockback
|
|
|
|
log("Negative knockback!");
|
2015-05-16 18:58:58 +02:00
|
|
|
// TODO: Apply negative knockback with [???] velocity/power to victims of attacks
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pullPlayers(Player player)
|
2015-06-01 18:25:20 +02:00
|
|
|
{
|
|
|
|
log("Pulling players!");
|
|
|
|
Vector direction = player.getLocation().getDirection().normalize().multiply(10.0d);
|
|
|
|
Location target = player.getEyeLocation().add(direction);
|
|
|
|
|
|
|
|
double targetDistance = player.getLocation().distance(target);
|
|
|
|
|
|
|
|
for (Player other : player.getWorld().getPlayers())
|
|
|
|
{
|
|
|
|
double otherDistance = player.getLocation().distance(other.getLocation());
|
|
|
|
double otherTargetDistance = target.distance(other.getLocation());
|
|
|
|
|
|
|
|
// If player is in-front of us and within pulling range
|
|
|
|
if (otherTargetDistance < targetDistance && otherDistance <= PULL_RANGE)
|
|
|
|
{
|
|
|
|
UtilAction.velocity(other, UtilAlg.getTrajectory(other, player), 0.3, false, 0, 0, 1, true);
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 18:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean canPull()
|
|
|
|
{
|
|
|
|
return true; // TODO: Implement cooldown? (Sounds OP without one)
|
|
|
|
}
|
|
|
|
}
|