package nautilus.game.arcade.kit.perks; import java.util.HashMap; import java.util.Iterator; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerToggleSneakEvent; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilAction; 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 PerkSquidSwim extends Perk { private HashMap _active = new HashMap(); public PerkSquidSwim() { super("Swimming", new String[] { C.cYellow + "Tap Crouch" + C.cGray + " to use " + C.cGreen + "Squid Thrust" }); } @EventHandler public void Use(PlayerToggleSneakEvent event) { if (event.isCancelled()) return; Player player = event.getPlayer(); if (!Kit.HasKit(player)) return; event.setCancelled(true); if (!player.getLocation().getBlock().isLiquid()) return; if (!Recharge.Instance.use(player, GetName(), 500, false)) return; //Velocity UtilAction.velocity(player, 0.9, 0.2, 2, false); //Sound player.getWorld().playSound(player.getLocation(), Sound.SPLASH, 0.5f, 0.75f); _active.put(player, System.currentTimeMillis()); } @EventHandler public void Reuse(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; Iterator swimIterator = _active.keySet().iterator(); while (swimIterator.hasNext()) { Player player = swimIterator.next(); if (UtilTime.elapsed(_active.get(player), 200)) { swimIterator.remove(); continue; } if (!player.getLocation().getBlock().isLiquid()) continue; UtilAction.velocity(player, 0.9, 0.2, 2, false); } } }