diff --git a/src/xyz/soper/arty/event/Listener/MortarInteract.java b/src/xyz/soper/arty/event/Listener/MortarInteract.java index 2f08760..b134414 100644 --- a/src/xyz/soper/arty/event/Listener/MortarInteract.java +++ b/src/xyz/soper/arty/event/Listener/MortarInteract.java @@ -8,6 +8,7 @@ import org.bukkit.block.Container; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -23,13 +24,18 @@ public class MortarInteract implements Listener { Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); Block block = event.getClickedBlock(); + if(block == null) return; if(block.getBlockData().getMaterial() == Material.BREWING_STAND){ Nameable brewingStandMortar = (Nameable) event.getClickedBlock().getState(); String blockName = brewingStandMortar.getCustomName(); + if(blockName == null) return; if(blockName.equals(ChatColor.GRAY + "Basic Mortar") || blockName.equals(ChatColor.GRAY + "Mortar")){ + if(event.getAction() == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true); if((item.getType() == Material.ARROW) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")){ MortarHandler mortarHandler = new MortarHandler(new Mortar(block)); - mortarHandler.fireShell(new Shell(item)); + player.sendMessage(mortarHandler.fireShell(new Shell(item))); + if(item.getAmount() > 1) item.setAmount(item.getAmount()-1); + else player.getInventory().setItemInMainHand(null); } } } diff --git a/src/xyz/soper/arty/item/Mortar.java b/src/xyz/soper/arty/item/Mortar.java index de06593..f48c7a7 100644 --- a/src/xyz/soper/arty/item/Mortar.java +++ b/src/xyz/soper/arty/item/Mortar.java @@ -8,7 +8,7 @@ import org.bukkit.block.Container; public class Mortar { - Location location; + public Location location; public static String BASIC_MORTAR_NAME = ChatColor.GRAY + "Basic Mortar"; public static String NORMAL_MORTAR_NAME = ChatColor.GRAY + "Mortar"; @@ -23,7 +23,10 @@ public class Mortar { public double velocityMultiplier; //Multiplier applied to the shell's velocity public boolean incendiaryCapable; //Is the mortar fit to fire an incendiary-type shell? + public Block block; + public Mortar(Block mortar){ + block = mortar; location = mortar.getLocation(); Nameable brewingStandMortar = (Nameable) mortar.getState(); String mortarName = brewingStandMortar.getCustomName(); diff --git a/src/xyz/soper/arty/util/MortarHandler.java b/src/xyz/soper/arty/util/MortarHandler.java index 7fed2e2..89a4654 100644 --- a/src/xyz/soper/arty/util/MortarHandler.java +++ b/src/xyz/soper/arty/util/MortarHandler.java @@ -11,8 +11,9 @@ public class MortarHandler { this.mortar = mortar; } - public void fireShell(Shell shell){ - + public String /*void*/ fireShell(Shell shell){ + mortar.block.getWorld().playSound(mortar.location, "entity.generic.explode", 1, 1.5F); + return "DEBUG: Shell has been fired."; } } \ No newline at end of file