Code cleanup for PerkDirtCannon
Cleans up some bad code in PerkDirtCannon and now removes the dirt blocks on death.
This commit is contained in:
parent
7470078da9
commit
765958a421
@ -1,5 +1,7 @@
|
||||
package nautilus.game.arcade.kit.perks;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.EntityEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -10,6 +12,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -17,7 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.projectile.IThrown;
|
||||
@ -31,15 +34,13 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
|
||||
private long _lastDirt;
|
||||
private double _targetKnockback;
|
||||
private double _playerKnockback;
|
||||
|
||||
private static final ItemStack DIRT_ITEM = new ItemBuilder(Material.DIRT).setTitle(C.cGreen + "Throwable Dirt").setGlow(true).build();
|
||||
|
||||
public PerkDirtCannon(double targetKnockback, double playerKnockback)
|
||||
public PerkDirtCannon(double targetKnockback)
|
||||
{
|
||||
super("Dirt Cannon", new String[] { C.cYellow + "Right-Click" + C.cGray + " to fire " + C.cGreen + "Dirt Cannon" });
|
||||
_targetKnockback = targetKnockback;
|
||||
_playerKnockback = playerKnockback;
|
||||
_lastDirt = 0;
|
||||
}
|
||||
|
||||
@ -58,7 +59,7 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDirtItem(player.getItemInHand()))
|
||||
if (!DIRT_ITEM.isSimilar(player.getItemInHand()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -67,11 +68,6 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilEnt.isGrounded(player))
|
||||
{
|
||||
player.setVelocity(player.getLocation().getDirection().setY(0.25).multiply(-_playerKnockback));
|
||||
}
|
||||
|
||||
int amount = player.getInventory().getItemInHand().getAmount() - 1;
|
||||
|
||||
@ -103,7 +99,7 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
{
|
||||
for (Player player : Manager.GetGame().GetPlayers(true))
|
||||
{
|
||||
if (!Kit.HasKit(player) || player.getInventory().contains(DIRT_ITEM, 4))
|
||||
if (!Kit.HasKit(player) || UtilInv.contains(player, "Throwable", Material.DIRT, (byte) 0, 4))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -126,7 +122,7 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (isDirtItem(event.getItemInHand()))
|
||||
if (DIRT_ITEM.isSimilar(event.getItemInHand()))
|
||||
{
|
||||
event.getPlayer().sendMessage(F.main("Game", "You cannot place your skill item."));
|
||||
event.setCancelled(true);
|
||||
@ -136,13 +132,28 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (isDirtItem(event.getItemDrop().getItemStack()))
|
||||
if (DIRT_ITEM.isSimilar(event.getItemDrop().getItemStack()))
|
||||
{
|
||||
event.getPlayer().sendMessage(F.main("Game", "You cannot drop this item."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event)
|
||||
{
|
||||
Iterator<ItemStack> iterator = event.getDrops().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
ItemStack itemStack = iterator.next();
|
||||
if (DIRT_ITEM.isSimilar(itemStack))
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Collide(LivingEntity target, Block block, ProjectileUser data)
|
||||
{
|
||||
@ -172,25 +183,5 @@ public class PerkDirtCannon extends Perk implements IThrown
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private boolean isDirtItem(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemStack.getItemMeta() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemStack.getItemMeta().getDisplayName().equals(DIRT_ITEM.getItemMeta().getDisplayName()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user