Java:
public static List<ItemStack> getRenamedItems(Inventory inventory, Material expectedMaterial, String expectedName) {
List<ItemStack> stacks = new ArrayList<>();
for(ItemStack stack : inventory.getStorageContents()) {
if(stack != null && stack.getType() == expectedMaterial && stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
if(meta.hasDisplayName() && meta.getDisplayName().equals(expectedName)) {
stacks.add(stack);
}
}
}
return stacks;
}
Player player = ...;
List<ItemStack> stacks = getRenamedItems(player.getInventory(), Material.CAKE, "Kougelhopf");
int cakes = stacks.stream().mapToInt(ItemStack::getAmount).sum();
// ou
int cakes = 0;
for(ItemStack cakeStack : stacks)
cakes += cakeStack.getAmount();
Dernière édition: