From 74ca2e82efc98934ad4e7de6717de841c705f6df Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Jun 2021 11:14:47 +0100 Subject: [PATCH] Added suppliers to itemstackbuilder --- .../items/AbstractItemStackBuilder.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/eco-api/src/main/java/com/willfp/eco/internal/items/AbstractItemStackBuilder.java b/eco-api/src/main/java/com/willfp/eco/internal/items/AbstractItemStackBuilder.java index ffee007f..50c95858 100644 --- a/eco-api/src/main/java/com/willfp/eco/internal/items/AbstractItemStackBuilder.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/items/AbstractItemStackBuilder.java @@ -16,6 +16,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; @SuppressWarnings("unchecked") public abstract class AbstractItemStackBuilder { @@ -63,6 +64,16 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Set the ItemStack amount. + * + * @param amount The amount. + * @return The builder. + */ + public AbstractItemStackBuilder setAmount(@NotNull final Supplier amount) { + return setAmount(amount.get()); + } + /** * Add an enchantment to the item. * @@ -76,6 +87,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Add an enchantment to the item. + * + * @param enchantment The enchantment. + * @param level The level. + * @return The builder. + */ + public AbstractItemStackBuilder addEnchantment(@NotNull final Supplier enchantment, + @NotNull final Supplier level) { + return addEnchantment(enchantment.get(), level.get()); + } + /** * Set the item display name. * @@ -87,6 +110,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Set the item display name. + * + * @param name The name. + * @return The builder. + */ + public AbstractItemStackBuilder setDisplayName(@NotNull final Supplier name) { + String result = name.get(); + + return result == null ? this : setDisplayName(name.get()); + } + /** * Add lore line. * @@ -102,6 +137,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Add lore line. + * + * @param line The line. + * @return The builder. + */ + public AbstractItemStackBuilder addLoreLine(@NotNull final Supplier line) { + String result = line.get(); + + return result == null ? this : addLoreLine(line.get()); + } + /** * Add lore lines. * @@ -119,6 +166,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Add lore lines. + * + * @param lines The lines. + * @return The builder. + */ + public AbstractItemStackBuilder addLoreLines(@NotNull final Supplier> lines) { + List result = lines.get(); + + return result == null ? this : addLoreLines(lines.get()); + } + /** * Add ItemFlags. * @@ -131,6 +190,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Add ItemFlags. + * + * @param itemFlags The flags. + * @return The builder. + */ + public AbstractItemStackBuilder addItemFlag(@NotNull final Supplier itemFlags) { + ItemFlag[] result = itemFlags.get(); + + return result == null ? this : addItemFlag(result); + } + /** * Write meta key. * @@ -149,6 +220,22 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Write meta key. + * + * @param key The key. + * @param type The type. + * @param value The value. + * @param The type. + * @param The type. + * @return The builder. + */ + public AbstractItemStackBuilder writeMetaKey(@NotNull final Supplier key, + @NotNull final Supplier> type, + @NotNull final Supplier value) { + return writeMetaKey(key.get(), type.get(), value.get()); + } + /** * Set unbreakable. * @@ -161,6 +248,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Set unbreakable. + * + * @param unbreakable If the item should be unbreakable. + * @return The builder. + */ + public AbstractItemStackBuilder setUnbreakable(@NotNull final Supplier unbreakable) { + Boolean result = unbreakable.get(); + + return result == null ? this : setUnbreakable(unbreakable); + } + /** * Set custom model data. * @@ -173,6 +272,18 @@ public abstract class AbstractItemStackBuilder { return this; } + /** + * Set custom model data. + * + * @param data The data. + * @return The builder. + */ + public AbstractItemStackBuilder setCustomModelData(@NotNull final Supplier data) { + Integer result = data.get(); + + return result == null ? this : setCustomModelData(result); + } + /** * Build the item. *