2013-10-25 10:20:14 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.WeakHashMap;
|
|
|
|
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Projectile;
|
|
|
|
import org.bukkit.entity.Snowball;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.block.Action;
|
|
|
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.C;
|
|
|
|
import mineplex.core.common.util.UtilBlock;
|
|
|
|
import mineplex.core.common.util.UtilEnt;
|
|
|
|
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 mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
|
|
|
|
|
|
|
import nautilus.game.arcade.kit.Perk;
|
|
|
|
|
|
|
|
public class PerkBlizzardFinn extends Perk
|
|
|
|
{
|
|
|
|
private HashMap<Player, Long> _active = new HashMap<Player, Long>();
|
|
|
|
private WeakHashMap<Projectile, Player> _snowball = new WeakHashMap<Projectile, Player>();
|
|
|
|
|
|
|
|
public PerkBlizzardFinn()
|
|
|
|
{
|
|
|
|
super("Blizzard", new String[]
|
|
|
|
{
|
|
|
|
C.cYellow + "Block" + C.cGray + " with Diamond Sword to use " + C.cGreen + "Blizzard"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Activate(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled())
|
|
|
|
return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (UtilBlock.usable(event.getClickedBlock()))
|
|
|
|
return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (!event.getPlayer().getItemInHand().getType().toString().contains("DIAMOND_SWORD"))
|
|
|
|
return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
Player player = event.getPlayer();
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (!Kit.HasKit(player))
|
|
|
|
return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2014-04-03 06:48:58 +02:00
|
|
|
if (!Recharge.Instance.use(player, GetName(), 2000, true, false))
|
2013-10-25 10:20:14 +02:00
|
|
|
return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
_active.put(player, System.currentTimeMillis());
|
|
|
|
}
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Update(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.TICK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
|
|
{
|
|
|
|
if (!_active.containsKey(player))
|
|
|
|
continue;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (!player.isBlocking())
|
|
|
|
{
|
|
|
|
_active.remove(player);
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-27 05:24:28 +01:00
|
|
|
|
|
|
|
if (UtilTime.elapsed(_active.get(player), 1000))
|
2013-10-25 10:20:14 +02:00
|
|
|
{
|
|
|
|
_active.remove(player);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Snowball
|
|
|
|
for (int i=0 ; i<4 ; i++)
|
|
|
|
{
|
|
|
|
Snowball snow = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), Snowball.class);
|
|
|
|
double x = 0.1 - (UtilMath.r(20)/100d);
|
|
|
|
double y = UtilMath.r(20)/100d;
|
|
|
|
double z = 0.1 - (UtilMath.r(20)/100d);
|
|
|
|
snow.setVelocity(player.getLocation().getDirection().add(new Vector(x,y,z)).multiply(2));
|
|
|
|
_snowball.put(snow, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Effect
|
|
|
|
player.getWorld().playSound(player.getLocation(), Sound.STEP_SNOW, 0.1f, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void Snowball(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetCause() != DamageCause.PROJECTILE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Projectile proj = event.GetProjectile();
|
|
|
|
if (proj == null) return;
|
|
|
|
|
|
|
|
if (!(proj instanceof Snowball))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!_snowball.containsKey(proj))
|
|
|
|
return;
|
|
|
|
|
|
|
|
LivingEntity damagee = event.GetDamageeEntity();
|
|
|
|
if (damagee == null) return;
|
2013-10-27 05:24:28 +01:00
|
|
|
|
|
|
|
event.SetCancelled("Snowball Damage");
|
2013-10-25 10:20:14 +02:00
|
|
|
|
|
|
|
if (damagee instanceof Player)
|
|
|
|
return;
|
|
|
|
|
|
|
|
damagee.setVelocity(proj.getVelocity().multiply(0.15).add(new Vector(0, 0.15, 0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void SnowballForm(ProjectileHitEvent event)
|
|
|
|
{
|
|
|
|
if (!(event.getEntity() instanceof Snowball))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_snowball.remove(event.getEntity()) == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Manager.GetBlockRestore().Snow(event.getEntity().getLocation().getBlock(), (byte)1, (byte)7, 2000, 250, 0);
|
|
|
|
}
|
|
|
|
}
|