Untitled
unknown
plain_text
a year ago
2.1 kB
5
Indexable
@EventHandler
public void onPlayerUseSellWand(PlayerInteractEvent event) {
if (event.getClickedBlock() != null && (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.TRAPPED_CHEST)) {
Player player = event.getPlayer();
ItemStack wand = player.getInventory().getItemInMainHand();
if (wand.getType() == Material.BLAZE_ROD && wand.hasItemMeta() && wand.getItemMeta().hasEnchant(Enchantment.LOYALTY)) {
Chest chest = (Chest) event.getClickedBlock().getState();
if (isChestBlocked(chest)) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eSell &bWands &7| &cThe chest is locked with a block covering."));
event.setCancelled(true);
return;
}
ItemStack[] contents = chest.getInventory().getContents();
SellPrices prices = EconomyShopGUIHook.getCutSellPrices(player, contents, true);
// Filter out non-sellable items and sum the sellable items' prices
double totalSellPrice = prices.getPrices().entrySet().stream()
.filter(entry -> entry.getValue() > 0) // Check if the item is sellable by price
.mapToDouble(entry -> entry.getValue())
.sum();
if (totalSellPrice > 0) {
economy.depositPlayer(player, totalSellPrice);
chest.getInventory().clear(); // Optionally clear the chest inventory
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eSell &bWands &7| &aSold contents for $" + totalSellPrice));
decrementWandUses(wand, player);
} else {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eSell &bWands &7| &cNo sellable items in chest."));
}
event.setCancelled(true);
}
}
}Editor is loading...
Leave a Comment