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