added check for shell in hand

master
Soper Aylamo 2021-05-04 23:32:24 -04:00
parent 501bd77d4e
commit 99539fea58
3 changed files with 19 additions and 14 deletions

View File

@ -1,7 +1,6 @@
package xyz.soper.arty.debug;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Nameable;
import org.bukkit.block.Block;
import org.bukkit.block.Container;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -24,21 +23,29 @@ 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")){
if((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){
player.sendMessage("Block is an 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")){
player.sendMessage("Block is a mortar.");
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true);
MortarHandler mortarHandler = new MortarHandler(new Mortar(block));
player.sendMessage(mortarHandler.fireShell(new Shell(item)));
mortarHandler.fireShell(new Shell(item));
if(item.getAmount() > 1) item.setAmount(item.getAmount()-1);
else player.getInventory().setItemInMainHand(null);
}
}
}
}
}

View File

@ -11,9 +11,8 @@ public class MortarHandler {
this.mortar = mortar;
}
public String /*void*/ fireShell(Shell shell){
public void fireShell(Shell shell){
mortar.block.getWorld().playSound(mortar.location, "entity.generic.explode", 1, 1.5F);
return "DEBUG: Shell has been fired.";
}
}