needs to cancel right click mortar event before arrow check is done

master
Soper Aylamo 2021-05-05 03:09:38 -04:00
parent 99539fea58
commit 8011bc3f78
Signed by: Soper
GPG Key ID: A27AC885ACC3BEAE
1 changed files with 16 additions and 20 deletions

View File

@ -23,23 +23,20 @@ public class MortarInteract implements Listener {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand();
Block block = event.getClickedBlock();
if((item.getType() == Material.ARROW)
if((block != null
&& item.getType() == Material.ARROW)
&& item.hasItemMeta()
&& item.getItemMeta().hasDisplayName()
&& item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")){
if(block == null) {
player.sendMessage("Block is null.");
return;
}
else if(block.getBlockData().getMaterial() == Material.BREWING_STAND){
&& item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")
&& block.getBlockData().getMaterial() == Material.BREWING_STAND){
player.sendMessage("Block is an brewing stand.");
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true);
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")){
player.sendMessage("Block is a mortar.");
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true);
MortarHandler mortarHandler = new MortarHandler(new Mortar(block));
mortarHandler.fireShell(new Shell(item));
if(item.getAmount() > 1) item.setAmount(item.getAmount()-1);
@ -48,4 +45,3 @@ public class MortarInteract implements Listener {
}
}
}
}