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; public class MagneticBlade extends LegendaryItem { public static final double PULL_RANGE = 10d; public MagneticBlade() { super("Magnetic Blade", "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 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) } }