Breaks boom bow when durability = 0

This commit is contained in:
alisolarflare 2016-11-26 02:23:11 -05:00
parent 68f8a3fd77
commit 30686980e6

View file

@ -1,107 +1,110 @@
package alisolarflare.components.magic.tricks; package alisolarflare.components.magic.tricks;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
public class BoomBowListener implements Listener { public class BoomBowListener implements Listener {
JavaPlugin plugin; JavaPlugin plugin;
public BoomBowListener(JavaPlugin plugin){ public BoomBowListener(JavaPlugin plugin){
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler @EventHandler
public void ClickEvent(PlayerInteractEvent event){ public void ClickEvent(PlayerInteractEvent event){
FlyBowBoost(event); FlyBowBoost(event);
} }
public void FlyBowBoost(PlayerInteractEvent event){ public void FlyBowBoost(PlayerInteractEvent event){
//ACTION SANITATION //ACTION SANITATION
if(!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) return; if(!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) return;
if(!(event.getPlayer().isGliding())) return; if(!(event.getPlayer().isGliding())) return;
if(!(event.getMaterial() == Material.BOW)) return; if(!(event.getMaterial() == Material.BOW)) return;
//BOW SANITATION //BOW SANITATION
ItemStack bow = event.getItem(); ItemStack bow = event.getItem();
if(!(bow.containsEnchantment(Enchantment.ARROW_KNOCKBACK))) return; if(!(bow.containsEnchantment(Enchantment.ARROW_KNOCKBACK))) return;
if(!(bow.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK) == 3)) return; if(!(bow.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK) == 3)) return;
if(!(bow.getItemMeta().getDisplayName().contains("BOOM BOW"))) return; if(!(bow.getItemMeta().getDisplayName().contains("BOOM BOW"))) return;
//PLAYER SANITATION //PLAYER SANITATION
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.getGameMode().equals(GameMode.CREATIVE))return; if(player.getGameMode().equals(GameMode.CREATIVE))return;
if(bow.containsEnchantment(Enchantment.ARROW_INFINITE)){ if(bow.containsEnchantment(Enchantment.ARROW_INFINITE)){
//HAS INIFINITY //HAS INIFINITY
Activate(event); Activate(event);
}else if((player.getInventory().contains(Material.TNT))){ }else if((player.getInventory().contains(Material.TNT))){
//HAS TNT //HAS TNT
Activate(event); Activate(event);
//Reduce tnt by 1 //Reduce tnt by 1
int tntSlot = player.getInventory().first(Material.TNT); int tntSlot = player.getInventory().first(Material.TNT);
ItemStack tntStack = player.getInventory().getItem(tntSlot); ItemStack tntStack = player.getInventory().getItem(tntSlot);
if(tntStack.getAmount() > 3){ if(tntStack.getAmount() > 3){
tntStack.setAmount(tntStack.getAmount()-3); tntStack.setAmount(tntStack.getAmount()-3);
}else{ }else{
player.getInventory().remove(tntStack); player.getInventory().remove(tntStack);
} }
if (bow.getDurability() < 0){
}else{ player.getInventory().clear(player.getInventory().getHeldItemSlot());
return; }
}
} }else{
return;
}
}
public void Activate(PlayerInteractEvent event){
//INIT - Player variables
Player player = event.getPlayer();
Location playerLocation = player.getLocation(); public void Activate(PlayerInteractEvent event){
ItemStack boomBow = player.getInventory().getItemInMainHand(); //INIT - Player variables
Player player = event.getPlayer();
//TODO: NERF - boomDecay Location playerLocation = player.getLocation();
//TODO: NERF - endCrystal ItemStack boomBow = player.getInventory().getItemInMainHand();
//TODO: NERF - healthReduction
//TODO: NERF - localized //TODO: NERF - boomDecay
//TODO: NERF - endCrystal
if(BoomBowRule.boomDecay) //TODO: NERF - healthReduction
new BoomDecayTask(player).runTaskTimer(plugin, 1, 1); //TODO: NERF - localized
if(BoomBowRule.endCrystal){
//BoomBowCyrstalSpawn if(BoomBowRule.boomDecay)
} new BoomDecayTask(player).runTaskTimer(plugin, 1, 1);
if(BoomBowRule.healthReduction){ if(BoomBowRule.endCrystal){
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 400, -1)); //BoomBowCyrstalSpawn
} }
if(BoomBowRule.localized); if(BoomBowRule.healthReduction){
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 400, -1));
}
//SET - Player Velocity if(BoomBowRule.localized);
player.setVelocity(playerLocation.getDirection().normalize().multiply(3.0));
//CREATE - Explosion + damage //SET - Player Velocity
player.getWorld().playSound(playerLocation, Sound.ENTITY_GENERIC_EXPLODE, 10, -20); player.setVelocity(playerLocation.getDirection().normalize().multiply(3.0));
player.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, playerLocation, 2);
player.damage(7.42425, player); //CREATE - Explosion + damage
boomBow.setDurability((short) (boomBow.getDurability() + 3)); player.getWorld().playSound(playerLocation, Sound.ENTITY_GENERIC_EXPLODE, 10, -20);
if(boomBow.getDurability() < 0){ player.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, playerLocation, 2);
player.getInventory().setItemInMainHand(null); player.damage(7.42425, player);
player.getWorld().playSound(playerLocation, Sound.ENTITY_ITEM_BREAK, 0, 0) boomBow.setDurability((short) (boomBow.getDurability() + 3));
; if(boomBow.getDurability() < 0){
} player.getInventory().setItemInMainHand(null);
player.getWorld().playSound(playerLocation, Sound.ENTITY_ITEM_BREAK, 0, 0)
} ;
} }
}
}