From 1bb5453b04dfe250316801e6d6bb5aec45269fef Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 25 Nov 2016 23:21:15 -0500 Subject: [PATCH] Added the *cannon bow* --- .../components/magic/MagicComponent.java | 38 ++++++++------- .../magic/tricks/CannonBowListener.java | 47 +++++++++++++++++++ 2 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 src/alisolarflare/components/magic/tricks/CannonBowListener.java diff --git a/src/alisolarflare/components/magic/MagicComponent.java b/src/alisolarflare/components/magic/MagicComponent.java index eeec5cd..8d5dcc9 100644 --- a/src/alisolarflare/components/magic/MagicComponent.java +++ b/src/alisolarflare/components/magic/MagicComponent.java @@ -1,18 +1,20 @@ -package alisolarflare.components.magic; - -import org.bukkit.plugin.java.JavaPlugin; - -import alisolarflare.architecture.Component; -import alisolarflare.components.magic.tricks.AliArrowListener; -import alisolarflare.components.magic.tricks.BoomBowDeathListener; -import alisolarflare.components.magic.tricks.BoomBowListener; - -public class MagicComponent extends Component{ - - @Override - public void register(JavaPlugin plugin) { - registerListener(plugin, new AliArrowListener(plugin)); - registerListener(plugin, new BoomBowDeathListener()); - registerListener(plugin, new BoomBowListener(plugin)); - } -} +package alisolarflare.components.magic; + +import org.bukkit.plugin.java.JavaPlugin; + +import alisolarflare.architecture.Component; +import alisolarflare.components.magic.tricks.AliArrowListener; +import alisolarflare.components.magic.tricks.BoomBowDeathListener; +import alisolarflare.components.magic.tricks.BoomBowListener; +import alisolarflare.components.magic.tricks.CannonBowListener; + +public class MagicComponent extends Component{ + + @Override + public void register(JavaPlugin plugin) { + registerListener(plugin, new AliArrowListener(plugin)); + registerListener(plugin, new BoomBowDeathListener()); + registerListener(plugin, new BoomBowListener(plugin)); + registerListener(plugin, new CannonBowListener()); + } +} diff --git a/src/alisolarflare/components/magic/tricks/CannonBowListener.java b/src/alisolarflare/components/magic/tricks/CannonBowListener.java new file mode 100644 index 0000000..83cf9f1 --- /dev/null +++ b/src/alisolarflare/components/magic/tricks/CannonBowListener.java @@ -0,0 +1,47 @@ +package alisolarflare.components.magic.tricks; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.inventory.ItemStack; + +public class CannonBowListener implements Listener { + + public CannonBowListener(){ + } + + @EventHandler + public void onProjectileLaunch(ProjectileLaunchEvent event){ + if(event.getEntity().getType() != EntityType.ARROW) + return; + Arrow arrow = (Arrow) event.getEntity(); + if (!(arrow.isCritical()) || !(arrow.getShooter() instanceof Player)) + return; + Player player = (Player) arrow.getShooter(); + ItemStack bow; + if ((bow = player.getInventory().getItemInMainHand()).getType() != Material.BOW) + return; + if (!bow.containsEnchantment(Enchantment.PROTECTION_EXPLOSIONS)) + return; + if(!(bow.getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS) == 10)) + return; + if (!bow.getItemMeta().getDisplayName().toUpperCase().contains("CANNON BOW")) + return; + if (!player.getInventory().contains(Material.TNT)) + return; + + Entity tnt = arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); + tnt.setVelocity(arrow.getVelocity()); + arrow.remove(); + + + return; + + } +} \ No newline at end of file