Added suppliers to itemstackbuilder

This commit is contained in:
Auxilor
2021-06-17 11:14:47 +01:00
parent 4039439fda
commit 74ca2e82ef

View File

@@ -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<T extends ItemMeta> {
@@ -63,6 +64,16 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Set the ItemStack amount.
*
* @param amount The amount.
* @return The builder.
*/
public AbstractItemStackBuilder<T> setAmount(@NotNull final Supplier<Integer> amount) {
return setAmount(amount.get());
}
/**
* Add an enchantment to the item.
*
@@ -76,6 +87,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Add an enchantment to the item.
*
* @param enchantment The enchantment.
* @param level The level.
* @return The builder.
*/
public AbstractItemStackBuilder<T> addEnchantment(@NotNull final Supplier<Enchantment> enchantment,
@NotNull final Supplier<Integer> level) {
return addEnchantment(enchantment.get(), level.get());
}
/**
* Set the item display name.
*
@@ -87,6 +110,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Set the item display name.
*
* @param name The name.
* @return The builder.
*/
public AbstractItemStackBuilder<T> setDisplayName(@NotNull final Supplier<String> name) {
String result = name.get();
return result == null ? this : setDisplayName(name.get());
}
/**
* Add lore line.
*
@@ -102,6 +137,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Add lore line.
*
* @param line The line.
* @return The builder.
*/
public AbstractItemStackBuilder<T> addLoreLine(@NotNull final Supplier<String> line) {
String result = line.get();
return result == null ? this : addLoreLine(line.get());
}
/**
* Add lore lines.
*
@@ -119,6 +166,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Add lore lines.
*
* @param lines The lines.
* @return The builder.
*/
public AbstractItemStackBuilder<T> addLoreLines(@NotNull final Supplier<List<String>> lines) {
List<String> result = lines.get();
return result == null ? this : addLoreLines(lines.get());
}
/**
* Add ItemFlags.
*
@@ -131,6 +190,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Add ItemFlags.
*
* @param itemFlags The flags.
* @return The builder.
*/
public AbstractItemStackBuilder<T> addItemFlag(@NotNull final Supplier<ItemFlag[]> itemFlags) {
ItemFlag[] result = itemFlags.get();
return result == null ? this : addItemFlag(result);
}
/**
* Write meta key.
*
@@ -149,6 +220,22 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Write meta key.
*
* @param key The key.
* @param type The type.
* @param value The value.
* @param <A> The type.
* @param <B> The type.
* @return The builder.
*/
public <A, B> AbstractItemStackBuilder<T> writeMetaKey(@NotNull final Supplier<NamespacedKey> key,
@NotNull final Supplier<PersistentDataType<A, B>> type,
@NotNull final Supplier<B> value) {
return writeMetaKey(key.get(), type.get(), value.get());
}
/**
* Set unbreakable.
*
@@ -161,6 +248,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Set unbreakable.
*
* @param unbreakable If the item should be unbreakable.
* @return The builder.
*/
public AbstractItemStackBuilder<T> setUnbreakable(@NotNull final Supplier<Boolean> unbreakable) {
Boolean result = unbreakable.get();
return result == null ? this : setUnbreakable(unbreakable);
}
/**
* Set custom model data.
*
@@ -173,6 +272,18 @@ public abstract class AbstractItemStackBuilder<T extends ItemMeta> {
return this;
}
/**
* Set custom model data.
*
* @param data The data.
* @return The builder.
*/
public AbstractItemStackBuilder<T> setCustomModelData(@NotNull final Supplier<Integer> data) {
Integer result = data.get();
return result == null ? this : setCustomModelData(result);
}
/**
* Build the item.
*