Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkPaintballMachineGun.java
Chiss 3ba848567c paintball added
hg additions
minor changes to other games
2013-10-05 07:49:05 +10:00

125 lines
3.4 KiB
Java

package nautilus.game.arcade.kit.perks;
import java.util.HashSet;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilBlock;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.kit.Perk;
public class PerkPaintballMachineGun extends Perk
{
private HashSet<Projectile> _balls = new HashSet<Projectile>();
public PerkPaintballMachineGun()
{
super("Rifle", new String[]
{
C.cYellow + "Right-Click" + C.cGray + " to use " + C.cGreen + "Machine Gun"
});
}
@EventHandler
public void Shoot(PlayerInteractEvent event)
{
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() != Material.DIAMOND_BARDING)
return;
Player player = event.getPlayer();
if (!Kit.HasKit(player))
return;
GameTeam team = Manager.GetGame().GetTeam(player);
if (team == null)
return;
event.setCancelled(true);
Vector rand = new Vector(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5);
rand.multiply(0.15);
if (team.GetColor() == ChatColor.AQUA)
{
Projectile proj = player.launchProjectile(Snowball.class);
proj.setVelocity(proj.getVelocity().multiply(1.6).add(rand));
_balls.add(proj);
//Sound
player.getWorld().playSound(player.getLocation(), Sound.CHICKEN_EGG_POP, 1.5f, 2f);
}
else
{
Projectile proj = player.launchProjectile(EnderPearl.class);
proj.setVelocity(proj.getVelocity().multiply(1.6).add(rand));
_balls.add(proj);
//Sound
player.getWorld().playSound(player.getLocation(), Sound.CHICKEN_EGG_POP, 1.5f, 1.75f);
}
//Slow
Manager.GetCondition().Factory().Slow("Firing", player, player, 0.9, 1, false, false, false, false);
}
@EventHandler
public void Damage(CustomDamageEvent event)
{
if (event.GetProjectile() == null)
return;
if (!_balls.contains(event.GetProjectile()))
return;
//Negate
event.AddMod("Negate", "Negate", -event.GetDamageInitial(), false);
event.AddMod("Paintball", "Machine Gun", 8, true);
if (event.GetDamageePlayer() == null)
return;
double r = Math.random();
ItemStack item = null;
if (r > 0.75) item= event.GetDamageePlayer().getInventory().getHelmet();
else if (r > 0.50) item= event.GetDamageePlayer().getInventory().getChestplate();
else if (r > 0.25) item= event.GetDamageePlayer().getInventory().getLeggings();
else item= event.GetDamageePlayer().getInventory().getBoots();
LeatherArmorMeta meta = (LeatherArmorMeta)item.getItemMeta();
//Color
if (event.GetProjectile() instanceof Snowball)
meta.setColor(Color.AQUA);
else
meta.setColor(Color.FUCHSIA);
item.setItemMeta(meta);
}
}