@@ -0,0 +1,2635 @@
+package vg.civcraft.mc.civmodcore.inventory.items;%0A%0Aimport java.util.Objects;%0Aimport java.util.function.Consumer;%0Aimport javax.annotation.Nonnull;%0Aimport org.bukkit.Bukkit;%0Aimport org.bukkit.Material;%0Aimport org.bukkit.inventory.ItemStack;%0Aimport org.bukkit.inventory.meta.ItemMeta;%0A%0Apublic class ItemBuilder %7B%0A%0A%09private Material material;%0A%09private ItemMeta meta;%0A%09private int amount;%0A%0A%09private ItemBuilder() %7B%0A%09%09this.amount = 1;%0A%09%7D%0A%0A%09/**%0A%09 * @param material The material to set for this item.%0A%09 * @return Returns this builder.%0A%09 *%0A%09 * @throws IllegalArgumentException Throws an IAE if the given material fails am%0A%09 *                                  %7B@link ItemUtils#isValidItemMaterial(Material)%7D test.%0A%09 */%0A%09public ItemBuilder material(@Nonnull final Material material) %7B%0A%09%09if (!ItemUtils.isValidItemMaterial(material)) %7B%0A%09%09%09throw new IllegalArgumentException(%22That is not a valid item material!%22);%0A%09%09%7D%0A%09%09this.material = material;%0A%09%09return this;%0A%09%7D%0A%0A%09/**%0A%09 * @param %3CT%3E The type to cast the item meta to.%0A%09 * @param handler The item meta handler.%0A%09 * @return Returns this builder.%0A%09 *%0A%09 * @throws NullPointerException Throws an NPE if a new item meta needs to be created, but the new meta is null.%0A%09 * @throws ClassCastException Throws an CCE if the item meta cannot be cast to the inferred type.%0A%09 */%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public %3CT%3E ItemBuilder meta(@Nonnull final Consumer%3CT%3E handler) %7B%0A%09%09if (this.meta == null %7C%7C !Bukkit.getItemFactory().isApplicable(this.meta, this.material)) %7B%0A%09%09%09this.meta = Objects.requireNonNull(%0A%09%09%09%09%09Bukkit.getItemFactory().getItemMeta(this.material),%0A%09%09%09%09%09%22Tried to create an item meta for %5B%22 + this.material + %22%5D but it returned null!%22);%0A%09%09%7D%0A%09%09handler.accept((T) this.meta);%0A%09%09return this;%0A%09%7D%0A%0A%09/**%0A%09 * @param amount The amount to set for this item.%0A%09 * @return Returns this builder.%0A%09 *%0A%09 * @throws IllegalArgumentException Throws an IAE if the given amount is less than or equal to zero.%0A%09 */%0A%09public ItemBuilder amount(final int amount) %7B%0A%09%09if (amount %3C= 0) %7B%0A%09%09%09throw new IllegalArgumentException(%22Item amount cannot be less than or equal to zero!%22);%0A%09%09%7D%0A%09%09this.amount = amount;%0A%09%09return this;%0A%09%7D%0A%0A%09/**%0A%09 * @return Returns a new ItemStack based on the builder.%0A%09 */%0A%09public ItemStack build() %7B%0A%09%09final var item = new ItemStack(this.material, this.amount);%0A%09%09item.setItemMeta(this.meta);%0A%09%09return item;%0A%09%7D%0A%0A%09/**%0A%09 * Creates a new builder with the given material.%0A%09 *%0A%09 * @param material The material to set for the builder.%0A%09 * @return Returns a new builder.%0A%09 */%0A%09public static ItemBuilder builder(@Nonnull final Material material) %7B%0A%09%09return new ItemBuilder().material(material);%0A%09%7D%0A%0A%7D%0A

Add ItemBuilder