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

78 lines
2.1 KiB
Java
Raw Normal View History

package nautilus.game.arcade.kit.perks;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.kit.Perk;
public class PerkRadar extends Perk
{
private HashMap<Player, Long> _lastTick = new HashMap<Player, Long>();
public PerkRadar()
{
super("Radar Scanner", new String[]
{
C.cYellow + "Hold Compass" + C.cGray + " to use " + C.cGreen + "Radar Scanner",
"Ticks get faster when you are near a Hider!"
});
}
@EventHandler
public void Update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Player player : UtilServer.getPlayers())
{
if (!UtilGear.isMat(player.getItemInHand(), Material.COMPASS))
continue;
if (!Kit.HasKit(player) || !Manager.IsAlive(player))
continue;
double closest = 999;
for (Player other : UtilServer.getPlayers())
{
if (other.equals(player))
continue;
if (!Manager.IsAlive(other))
continue;
if (Manager.GetColor(other) != ChatColor.AQUA)
continue;
double dist = UtilMath.offset(other, player);
if (dist < closest)
closest = dist;
}
double scale = Math.max(0, Math.min(1, (closest - 2) / 8d));
//Bi-Directional Cooldown
if (_lastTick.containsKey(player) && !UtilTime.elapsed(_lastTick.get(player), (long)(2000 * scale)) && !Recharge.Instance.usable(player, "Radar"))
return;
_lastTick.put(player, System.currentTimeMillis());
Recharge.Instance.useForce(player, "Radar", (long)(2000 * scale));
player.getWorld().playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, (float)(2 - 1*scale));
}
}
}