Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkThrower.java

137 lines
3.6 KiB
Java
Raw Normal View History

2014-03-05 07:39:48 +01:00
package nautilus.game.arcade.kit.perks;
import java.util.HashSet;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerDropItemEvent;
2014-03-05 07:39:48 +01:00
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
2014-03-05 07:39:48 +01:00
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextTop;
2014-03-05 07:39:48 +01:00
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Perk;
public class PerkThrower extends Perk implements IThrown
{
public PerkThrower(ArcadeManager manager)
{
super("Thrower", new String[]
{
C.cGray + "You can also pick up team mates!",
C.cYellow + "Drop Weapon" + C.cGray + " to " + C.cGreen + "Throw Sheep / Players",
2014-03-05 07:39:48 +01:00
});
}
@EventHandler
public void Throw(PlayerDropItemEvent event)
2014-03-05 07:39:48 +01:00
{
Player thrower = event.getPlayer();
if (thrower.getPassenger() == null)
return;
Entity throwee = thrower.getPassenger();
if (throwee == null)
return;
thrower.eject();
Entity throweeStack = throwee.getPassenger();
if (throweeStack != null)
{
throwee.eject();
throweeStack.leaveVehicle();
final Entity fThrower = thrower;
final Entity fThroweeStack = throweeStack;
Manager.GetPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.GetPlugin(), new Runnable()
{
public void run()
{
fThrower.setPassenger(fThroweeStack);
}
}, 2);
UtilPlayer.message(thrower, F.main("Game", "You threw " + UtilEnt.getName(throwee) + "."));
2014-03-05 07:39:48 +01:00
}
//Throw
UtilAction.velocity(throwee, thrower.getLocation().getDirection(), 1.4, false, 0, 0.3, 0.8, true);
Manager.GetProjectile().AddThrow(throwee, thrower, this, -1, true, false, true, false, 2d);
//Audio
thrower.getWorld().playSound(thrower.getLocation(), Sound.SHEEP_IDLE, 2f, 3f);
//Disallow stacking for 0.5s
Recharge.Instance.useForce(thrower, "Sheep Stack", 500);
}
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)
{
if (target == null)
return;
if (target instanceof Player)
{
if (!Manager.GetGame().IsAlive((Player)target))
{
return;
}
}
else
{
return;
}
2014-03-05 07:39:48 +01:00
//Damage Event
Manager.GetDamage().NewDamageEvent(target, data.GetThrower(), null,
DamageCause.CUSTOM, 6, false, true, false,
UtilEnt.getName(data.GetThrower()), GetName());
//Bounce
Vector dir = UtilAlg.getTrajectory(data.GetThrown(), target);
if (dir.getY() < 0) dir.setY(0);
UtilAction.velocity(target, dir, 1.2, false, 0, 0.4, 1, true);
dir = UtilAlg.getTrajectory(target, data.GetThrown());
if (dir.getY() < 0) dir.setY(0);
UtilAction.velocity(data.GetThrown(), dir, 0.2, false, 0, 0.2, 1, true);
2014-03-05 07:39:48 +01:00
//Effect
data.GetThrown().getWorld().playSound(data.GetThrown().getLocation(), Sound.SHEEP_IDLE, 3f, 5f);
}
@Override
public void Idle(ProjectileUser data)
{
}
@Override
public void Expire(ProjectileUser data)
{
}
}