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.core.common.util.UtilWorld; import mineplex.game.clans.clans.ClansManager; import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class MagneticMaul extends LegendaryItem { public static final double PULL_RANGE = 10d; public MagneticMaul() { super("Magnetic Maul", "Pull enemies closer with special abilities!", Material.RECORD_5); } @Override public void update(Player wielder) { Location loc = wielder.getLocation(); if (ClansManager.getInstance().getClaimMap().containsKey(UtilWorld.chunkToStr(loc.getChunk()))) { if (!ClansManager.getInstance().getClaimMap().get(UtilWorld.chunkToStr(loc.getChunk())).isSafe(wielder.getLocation())) { return; } } if (isHoldingRightClick() && canPull()) { pullEntities(wielder); } } @Override public void onAttack(CustomDamageEvent event, Player wielder) { event.AddKnockback("Magnetic Blade", -0.5d); // Pull players with negative knockback 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) } }