diff --git a/src/main/java/net/knarcraft/knargui/item/AbstractGUIItemFactory.java b/src/main/java/net/knarcraft/knargui/item/AbstractGUIItemFactory.java index da6cce5..8349736 100644 --- a/src/main/java/net/knarcraft/knargui/item/AbstractGUIItemFactory.java +++ b/src/main/java/net/knarcraft/knargui/item/AbstractGUIItemFactory.java @@ -15,7 +15,7 @@ import java.util.function.Consumer; * @param
A child class implementing this class
*/ @SuppressWarnings("unused") -public abstract class AbstractGUIItemFactory> { +public abstract class AbstractGUIItemFactory> implements GUIItemFactory { private final ItemStack itemStack; private B child; @@ -37,45 +37,30 @@ public abstract class AbstractGUIItemFactory * * @param childThe child class extending this
*/ - protected void setChild(B child) { + protected void setChild(@NotNull B child) { this.child = child; } - /** - * Builds the item as described in previous calls - * - * @returnThe output of this factory
- */ + @Override + @NotNull public ItemStack build() { return this.itemStack; } - /** - * Sets the name of this factory's item - * - * @param nameThe new item name
- * @returnThe factory. Used for chaining commands
- */ - public B setName(String name) { + @Override + @NotNull + public B setName(@NotNull String name) { return changeItemMeta((meta) -> meta.setDisplayName(name)); } - /** - * Sets the lore for this factory's item - * - * @param loreThe new lore
- * @returnThe factory. Used for chaining commands
- */ - public B setLore(ListTrue if the item should look enchanted
- * @returnThe factory. Used for chaining commands
- */ + @Override + @NotNull public B setEnchanted(boolean enchanted) { if (enchanted) { changeItemMeta((meta) -> meta.addEnchant(Enchantment.MENDING, 1, true)); @@ -87,25 +72,15 @@ public abstract class AbstractGUIItemFactory } } - /** - * Changes some metadata for this factory's item - * - * @param actionThe action to be run on the metadata
- * @returnThe factory. Used for chaining commands
- */ - protected B changeItemMeta(ConsumerThe type of metadata to change
- * @param actionThe action to be run on the metadata
- * @paramThe type of the metadata
- * @returnThe factory. Used for chaining commands
- */ - protectedThe metadata for this factory's item
- */ - protectedThe material to use for the new item
+ * @returnThe output of this factory
*/ - public GUIItemFactory(Material material) { - super(new ItemStack(material, 1)); - setChild(this); - } + @NotNull + ItemStack build(); /** - * Instantiates a new item factory + * Sets the name of this factory's item * - * @param materialThe material to use for the new item
- * @param amountThe number of items to be displayed
+ * @param nameThe new item name
+ * @returnThe factory. Used for chaining commands
*/ - public GUIItemFactory(Material material, int amount) { - super(new ItemStack(material, amount)); - setChild(this); - } + @NotNull + GUIItemFactory setName(@NotNull String name); /** - * Instantiates a new item factory + * Sets the lore for this factory's item * - * @param itemStackThe item stack to modify
+ * @param loreThe new lore
+ * @returnThe factory. Used for chaining commands
*/ - public GUIItemFactory(ItemStack itemStack) { - super(itemStack); - setChild(this); - } + @NotNull + GUIItemFactory setLore(@NotNull ListTrue if the item should look enchanted
+ * @returnThe factory. Used for chaining commands
+ */ + @NotNull + GUIItemFactory setEnchanted(boolean enchanted); + + /** + * Changes some metadata for this factory's item + * + * @param actionThe action to be run on the metadata
+ * @returnThe factory. Used for chaining commands
+ */ + @NotNull + GUIItemFactory changeItemMeta(@NotNull ConsumerThe type of metadata to change
+ * @param actionThe action to be run on the metadata
+ * @paramThe type of the metadata
+ * @returnThe factory. Used for chaining commands
+ */ + @NotNullThe metadata for this factory's item
+ */ + @NotNullThe factory. Used for chaining commands
*/ - public PlayerHeadGUIItemFactory useSkin(OfflinePlayer player) { + @NotNull + public PlayerHeadGUIItemFactory useSkin(@NotNull OfflinePlayer player) { return changeItemMeta(SkullMeta.class, (meta) -> meta.setOwningPlayer(player)); } @@ -47,7 +49,8 @@ public class PlayerHeadGUIItemFactory extends AbstractGUIItemFactoryThe factory. Used for chaining commands
*/ - public PlayerHeadGUIItemFactory useSkin(PlayerProfile playerProfile) { + @NotNull + public PlayerHeadGUIItemFactory useSkin(@NotNull PlayerProfile playerProfile) { return changeItemMeta(SkullMeta.class, (meta) -> meta.setOwnerProfile(playerProfile)); } @@ -57,7 +60,8 @@ public class PlayerHeadGUIItemFactory extends AbstractGUIItemFactoryThe factory. Used for chaining commands
*/ - public PlayerHeadGUIItemFactory useSkin(UUID uuid) { + @NotNull + public PlayerHeadGUIItemFactory useSkin(@NotNull UUID uuid) { return useSkin(Bukkit.getOfflinePlayer(uuid)); } @@ -71,7 +75,8 @@ public class PlayerHeadGUIItemFactory extends AbstractGUIItemFactoryThe factory. Used for chaining commands
*/ - public PlayerHeadGUIItemFactory useSkin(String textureId) { + @NotNull + public PlayerHeadGUIItemFactory useSkin(@NotNull String textureId) { //Get the texture id from a Base64 encoded JSON string if (!textureId.isBlank() && textureId.length() % 4 == 0) { String decoded = new String(Base64.getDecoder().decode(textureId)); @@ -94,7 +99,8 @@ public class PlayerHeadGUIItemFactory extends AbstractGUIItemFactoryThe factory. Used for chaining commands
*/ - public PlayerHeadGUIItemFactory useSkin(URL url) { + @NotNull + public PlayerHeadGUIItemFactory useSkin(@NotNull URL url) { PlayerProfile profile = Bukkit.createPlayerProfile(UUID.randomUUID()); profile.getTextures().setSkin(url); return changeItemMeta(SkullMeta.class, (meta) -> meta.setOwnerProfile(profile)); diff --git a/src/main/java/net/knarcraft/knargui/item/SimpleGUIItemFactory.java b/src/main/java/net/knarcraft/knargui/item/SimpleGUIItemFactory.java new file mode 100644 index 0000000..e18607a --- /dev/null +++ b/src/main/java/net/knarcraft/knargui/item/SimpleGUIItemFactory.java @@ -0,0 +1,44 @@ +package net.knarcraft.knargui.item; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * A class for crating visual items for the GUI + */ +@SuppressWarnings("unused") +public class SimpleGUIItemFactory extends AbstractGUIItemFactoryThe material to use for the new item
+ */ + public SimpleGUIItemFactory(@NotNull Material material) { + super(new ItemStack(material, 1)); + setChild(this); + } + + /** + * Instantiates a new item factory + * + * @param materialThe material to use for the new item
+ * @param amountThe number of items to be displayed
+ */ + public SimpleGUIItemFactory(@NotNull Material material, int amount) { + super(new ItemStack(material, amount)); + setChild(this); + } + + /** + * Instantiates a new item factory + * + * @param itemStackThe item stack to modify
+ */ + public SimpleGUIItemFactory(@NotNull ItemStack itemStack) { + super(itemStack); + setChild(this); + } + +}