@EventHandler public void onBlockInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); final FileConfiguration configuration = plugin.getConfig(); if (!(event.getAction() == Action.RIGHT_CLICK_BLOCK)) { return; } final Optional sign = SignEnum.forMaterial(event.getClickedBlock().getType()); if(!sign.isPresent()){ return; } final org.bukkit.block.Sign signBlock = (org.bukkit.block.Sign) event.getClickedBlock().getState(); final BlockData blockData = signBlock.getBlockData(); if (!(blockData instanceof Directional)) { return; } final Directional directional = (Directional) blockData; final Block attached = signBlock.getBlock().getRelative(directional.getFacing().getOppositeFace()); if (attached.getType() == Material.CHEST || attached.getType() == Material.TRAPPED_CHEST) { for (int i = 0; i < plugin.getLayoutLore().size(); i++) { if (!plugin.getLayoutLore().get(i).equals(signBlock.getLine(i))) { return; } } //TODO: permission check final ChestLocation chestLocation = ChestLocation.getLocationFromLocation(signBlock.getLocation()); if (plugin.getSigns().containsKey(chestLocation) && !plugin.getSigns().get(chestLocation).contains(player.getUniqueId())) { player.sendMessage(Utils.colorChat(configuration.getString("messages.no-access-sign"))); return; } if (!plugin.getSigns().containsKey(chestLocation)) { event.getClickedBlock().breakNaturally(); return; } final Chest chest = (Chest) attached.getState(); final Inventory blockInventory = chest.getBlockInventory(); double priceMultiplier = 2.0; double totalSale = 0.0D; int slot = 0; final NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setGroupingUsed(true); final HashMap amounts = new HashMap<>(); final HashMap prices = new HashMap<>(); String type; for (ItemStack itemStack : blockInventory) { if (itemStack == null || itemStack.getType() == Material.AIR) { slot++; } type = itemStack != null ? itemStack.getType().toString().toLowerCase() : null; type = type != null ? type.replace("_", "") : null; if (plugin.getPrices().containsKey(type) && plugin.getPrices().get(type) > 0) { chest.getInventory().setItem(slot, new ItemStack(Material.AIR)); totalSale = totalSale + plugin.getPrices().get(type) * itemStack.getAmount() * priceMultiplier; if (prices.containsKey(itemStack.getType())) { prices.put(itemStack.getType(), prices.get(itemStack.getType()) + plugin.getPrices().get(type) * itemStack.getAmount() * priceMultiplier); } prices.put(itemStack.getType(), plugin.getPrices().get(type) * itemStack.getAmount() * priceMultiplier ); if (amounts.containsKey(itemStack.getType())) { amounts.put( itemStack.getType(), amounts.get(itemStack.getType()) + itemStack.getAmount() ); } amounts.put( itemStack.getType(), itemStack.getAmount() ); } } final EconomyResponse response = plugin.getEconomy().depositPlayer(player, totalSale); if (response.transactionSuccess()) { player.sendMessage(Utils.colorChat(plugin.getConfig().getString("messages.sale")) .replace("%amount%", numberFormat.format(totalSale))); if (plugin.getConfig().getBoolean("breakdown")) { for (Map.Entry entry : amounts.entrySet()) { final Material material = entry.getKey(); final Integer value = entry.getValue(); player.sendMessage(Utils.colorChat(plugin.getConfig().getString("messages.breakdown")) .replaceAll("%amount%", value.toString()) .replace("%item%", StringUtils.capitalize(material.name().toLowerCase() .replace("_", " "))) .replace("%price%", numberFormat.format(prices.get(material)))); } } } } }