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

138 lines
3.3 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.kit.perks;
2013-08-29 08:13:05 +02:00
import org.bukkit.Color;
2013-08-27 17:14:08 +02:00
import org.bukkit.Effect;
2013-08-29 08:13:05 +02:00
import org.bukkit.FireworkEffect;
2013-08-27 17:14:08 +02:00
import org.bukkit.Location;
import org.bukkit.Sound;
2013-08-29 08:13:05 +02:00
import org.bukkit.FireworkEffect.Type;
2013-08-27 17:14:08 +02:00
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.kit.Perk;
public class PerkBlink extends Perk
{
private String _name = "";
private double _range;
private long _recharge;
public PerkBlink(String name, double range, long recharge)
{
super("Leaper", new String[]
{
2013-08-29 08:13:05 +02:00
C.cYellow + "Right-Click" + C.cGray + " with Axe to " + C.cGreen + name
2013-08-27 17:14:08 +02:00
});
_name = name;
_range = range;
_recharge = recharge;
}
@EventHandler
public void Leap(PlayerInteractEvent event)
{
if (event.isCancelled())
return;
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
if (UtilBlock.usable(event.getClickedBlock()))
return;
if (event.getPlayer().getItemInHand() == null)
return;
if (!event.getPlayer().getItemInHand().getType().toString().contains("_AXE"))
return;
Player player = event.getPlayer();
if (!Kit.HasKit(player))
return;
if (!Recharge.Instance.use(player, _name, _recharge, true))
return;
//Smoke Trail
Block lastSmoke = player.getLocation().getBlock();
double curRange = 0;
while (curRange <= _range)
{
Location newTarget = player.getLocation().add(new Vector(0,0.2,0)).add(player.getLocation().getDirection().multiply(curRange));
if (!UtilBlock.airFoliage(newTarget.getBlock()) ||
!UtilBlock.airFoliage(newTarget.getBlock().getRelative(BlockFace.UP)))
break;
//Progress Forwards
curRange += 0.2;
//Smoke Trail
if (!lastSmoke.equals(newTarget.getBlock()))
2013-08-29 08:13:05 +02:00
{
2013-08-27 17:14:08 +02:00
lastSmoke.getWorld().playEffect(lastSmoke.getLocation(), Effect.SMOKE, 4);
2013-08-29 08:13:05 +02:00
}
2013-08-27 17:14:08 +02:00
lastSmoke = newTarget.getBlock();
}
//Modify Range
curRange -= 0.4;
if (curRange < 0)
curRange = 0;
//Destination
Location loc = player.getLocation().add(player.getLocation().getDirection().multiply(curRange).add(new Vector(0, 0.4, 0)));
if (curRange > 0)
2013-08-29 08:13:05 +02:00
{
//Firework
FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.BLACK).with(Type.BALL).trail(false).build();
try
{
Manager.GetFirework().playFirework(player.getEyeLocation(), effect);
player.getWorld().playSound(player.getLocation(), Sound.ZOMBIE_UNFECT, 2f, 2f);
}
catch (Exception e)
{
e.printStackTrace();
}
2013-08-27 17:14:08 +02:00
player.teleport(loc);
2013-08-29 08:13:05 +02:00
//Firework
try
{
Manager.GetFirework().playFirework(player.getEyeLocation(), effect);
player.getWorld().playSound(player.getLocation(), Sound.ZOMBIE_UNFECT, 2f, 2f);
}
catch (Exception e)
{
e.printStackTrace();
}
}
2013-08-27 17:14:08 +02:00
player.setFallDistance(0);
//Inform
UtilPlayer.message(player, F.main("Game", "You used " + F.skill(_name) + "."));
}
}