Mineplex2018-withcommit/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MagneticMaul.java

67 lines
1.9 KiB
Java
Raw Normal View History

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