2013-09-05 05:55:42 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2013-09-06 07:58:58 +02:00
|
|
|
import java.util.HashSet;
|
2013-09-05 05:55:42 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.WitherSkull;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.block.Action;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2013-09-06 07:58:58 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2013-09-05 05:55:42 +02:00
|
|
|
|
|
|
|
import mineplex.core.common.util.C;
|
|
|
|
import mineplex.core.common.util.F;
|
|
|
|
import mineplex.core.common.util.UtilAction;
|
|
|
|
import mineplex.core.common.util.UtilAlg;
|
|
|
|
import mineplex.core.common.util.UtilBlock;
|
|
|
|
import mineplex.core.common.util.UtilEnt;
|
|
|
|
import mineplex.core.common.util.UtilMath;
|
2014-04-11 07:33:31 +02:00
|
|
|
import mineplex.core.common.util.UtilParticle;
|
2013-09-05 05:55:42 +02:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2014-04-11 07:33:31 +02:00
|
|
|
import mineplex.core.common.util.UtilParticle.ParticleType;
|
2013-09-05 05:55:42 +02:00
|
|
|
import mineplex.core.recharge.Recharge;
|
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
2015-01-29 01:54:59 +01:00
|
|
|
import nautilus.game.arcade.kit.SmashPerk;
|
2013-09-05 05:55:42 +02:00
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
public class PerkWitherSkull extends SmashPerk
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
2013-09-06 07:58:58 +02:00
|
|
|
private HashMap<WitherSkull, Vector> _active = new HashMap<WitherSkull, Vector>();
|
|
|
|
private HashSet<Player> _ignoreControl = new HashSet<Player>();
|
2013-09-05 05:55:42 +02:00
|
|
|
|
|
|
|
public PerkWitherSkull()
|
|
|
|
{
|
|
|
|
super("Wither Skull", new String[]
|
|
|
|
{
|
|
|
|
C.cYellow + "Hold Block" + C.cGray + " to use " + C.cGreen + "Wither Skull"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW) // Happen BEFORE super is triggered
|
|
|
|
public void activate(PlayerInteractEvent event)
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
if (event.isCancelled())
|
|
|
|
return;
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
Player player = event.getPlayer();
|
2013-09-05 05:55:42 +02:00
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
if (!isSuperActive(player))
|
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
return;
|
2013-09-05 05:55:42 +02:00
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
if (UtilBlock.usable(event.getClickedBlock()))
|
2013-09-05 05:55:42 +02:00
|
|
|
return;
|
2015-01-29 01:54:59 +01:00
|
|
|
|
|
|
|
if (!isSuperActive(player))
|
|
|
|
if (!event.getPlayer().getItemInHand().getType().toString().contains("_SWORD"))
|
|
|
|
return;
|
|
|
|
|
2013-09-05 05:55:42 +02:00
|
|
|
if (!Kit.HasKit(player))
|
|
|
|
return;
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
if (!Recharge.Instance.use(player, GetName(), isSuperActive(player) ? 1000 : 6000, !isSuperActive(player), !isSuperActive(player)))
|
2013-09-05 05:55:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
//Fire
|
|
|
|
WitherSkull skull = player.launchProjectile(WitherSkull.class);
|
2015-01-29 01:54:59 +01:00
|
|
|
|
|
|
|
if (!isSuperActive(player))
|
|
|
|
skull.setDirection(player.getLocation().getDirection());
|
2013-09-06 07:58:58 +02:00
|
|
|
|
2014-04-11 07:33:31 +02:00
|
|
|
_active.put(skull, player.getLocation().getDirection().multiply(0.6));
|
2013-09-05 05:55:42 +02:00
|
|
|
|
|
|
|
//Sound
|
|
|
|
player.getWorld().playSound(player.getLocation(), Sound.WITHER_SHOOT, 1f, 1f);
|
|
|
|
|
|
|
|
//Inform
|
2015-01-29 01:54:59 +01:00
|
|
|
if (!isSuperActive(player))
|
|
|
|
UtilPlayer.message(player, F.main("Skill", "You launched " + F.skill(GetName()) + "."));
|
2013-09-06 07:58:58 +02:00
|
|
|
|
|
|
|
//Control
|
2015-01-29 01:54:59 +01:00
|
|
|
if (!isSuperActive(player))
|
|
|
|
_ignoreControl.remove(player);
|
|
|
|
else
|
|
|
|
_ignoreControl.add(player);
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2015-01-29 01:54:59 +01:00
|
|
|
public void cleanAndControl(UpdateEvent event)
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.TICK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Iterator<WitherSkull> skullIterator = _active.keySet().iterator();
|
|
|
|
|
|
|
|
while (skullIterator.hasNext())
|
|
|
|
{
|
|
|
|
WitherSkull skull = skullIterator.next();
|
2013-09-06 07:58:58 +02:00
|
|
|
Player player = (Player)skull.getShooter();
|
2013-09-05 05:55:42 +02:00
|
|
|
|
|
|
|
if (!skull.isValid())
|
|
|
|
{
|
|
|
|
skullIterator.remove();
|
|
|
|
skull.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
if (_ignoreControl.contains(player))
|
|
|
|
continue;
|
|
|
|
|
2013-09-06 07:58:58 +02:00
|
|
|
if (player.isBlocking() && !_ignoreControl.contains(player))
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
skull.setDirection(player.getLocation().getDirection());
|
|
|
|
skull.setVelocity(player.getLocation().getDirection().multiply(0.6));
|
2013-09-06 07:58:58 +02:00
|
|
|
_active.put(skull, player.getLocation().getDirection().multiply(0.6));
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-06 07:58:58 +02:00
|
|
|
_ignoreControl.add(player);
|
|
|
|
skull.setDirection(_active.get(skull));
|
|
|
|
skull.setVelocity(_active.get(skull));
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2015-01-29 01:54:59 +01:00
|
|
|
public void explode(EntityExplodeEvent event)
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
if (!_active.containsKey(event.getEntity()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
|
|
|
WitherSkull skull = (WitherSkull)event.getEntity();
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, skull.getLocation(), 0, 0, 0, 0, 1);
|
|
|
|
|
|
|
|
explode(skull, event.getLocation(), (LivingEntity)skull.getShooter());
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2015-01-29 01:54:59 +01:00
|
|
|
public void explodeDamage(CustomDamageEvent event)
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
if (event.IsCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetProjectile() != null && event.GetProjectile() instanceof WitherSkull)
|
|
|
|
event.SetCancelled("Wither Skull Cancel");
|
|
|
|
}
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
//Sometimes wither skulls do entity attack damage (non-explosion)... cancel it!
|
2013-09-05 05:55:42 +02:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2015-01-29 01:54:59 +01:00
|
|
|
public void directHitDamageCancel(CustomDamageEvent event)
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
if (event.IsCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetCause() != DamageCause.ENTITY_ATTACK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetDamageInitial() != 7)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player damager = event.GetDamagerPlayer(false);
|
|
|
|
if (damager == null) return;
|
|
|
|
|
|
|
|
if (!Kit.HasKit(damager))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!Manager.IsAlive(damager))
|
|
|
|
return;
|
|
|
|
|
|
|
|
event.SetCancelled("Wither Skull Direct Hit");
|
|
|
|
}
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
private void explode(WitherSkull skull, Location loc, LivingEntity shooter)
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
|
|
|
double scale = 0.4 + 0.6 * Math.min(1, skull.getTicksLived()/20d);
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
//Players
|
|
|
|
HashMap<Player, Double> players = UtilPlayer.getInRadius(skull.getLocation(), 7);
|
|
|
|
for (Player player : players.keySet())
|
2013-09-05 05:55:42 +02:00
|
|
|
{
|
2015-01-29 01:54:59 +01:00
|
|
|
if (!Manager.GetGame().IsAlive(player))
|
2013-09-05 05:55:42 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
//Damage Event
|
2015-01-29 01:54:59 +01:00
|
|
|
Manager.GetDamage().NewDamageEvent(player, (LivingEntity)skull.getShooter(), null,
|
|
|
|
DamageCause.CUSTOM, 2 + 10 * players.get(player) * scale, true, true, false,
|
|
|
|
UtilEnt.getName((LivingEntity)skull.getShooter()), GetName());
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
2015-01-29 01:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void knockback(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetReason() == null || !event.GetReason().contains(GetName()))
|
|
|
|
return;
|
2013-09-05 05:55:42 +02:00
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
event.AddKnockback(GetName(), 1.5);
|
2013-09-05 05:55:42 +02:00
|
|
|
}
|
|
|
|
}
|