public class command implements CommandExecutor, Listener {
private HashMap<Location, Chest> chests = new HashMap<>();
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!(sender instanceof Player)) {
return true;
}
if(cmd.getName().equalsIgnoreCase("cmd")) {
Player p = (Player) sender;
Location pl = p.getLocation();
pl.getBlock().setType(Material.CHEST);
Chest chest = (Chest) pl.getBlock().getState();
chests.put(chest.getLocation(), chest);
return true;
}
return true;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Action a = e.getAction();
Player p = e.getPlayer();
if(a != Action.RIGHT_CLICK_BLOCK) return;
Block block = e.getClickedBlock();
if(block.getType() == Material.AIR) return;
Chest chest = (Chest) block.getState();
if(chest == chests.get(chest.getLocation())) {
e.setCancelled(true);
p.sendMessage("chest");
} else {
p.sendMessage("not chest!");
return;
}
}
}