From bb4833a2e97bdc315ad212eaf77ae768b4f354a6 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Mon, 22 May 2023 17:05:13 +0200 Subject: [PATCH] Categories --- .../net/Indyuce/mmoitems/stat/Elements.java | 1 + .../Indyuce/mmoitems/stat/StatsCategory.java | 23 +++++++++++++++++ .../Indyuce/mmoitems/stat/type/ItemStat.java | 25 ++++++++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StatsCategory.java diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java index 7cf842a7..d7d6fa1e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java @@ -50,6 +50,7 @@ public class Elements extends ItemStat i if (event.getAction() == InventoryAction.PICKUP_ALL) new ElementsEdition(inv.getPlayer(), inv.getEdited()).open(inv.getPage()); + if (event.getAction() == InventoryAction.PICKUP_HALF) if (inv.getEditedSection().contains("element")) { inv.getEditedSection().set("element", null); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StatsCategory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StatsCategory.java new file mode 100644 index 00000000..8aba6c21 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StatsCategory.java @@ -0,0 +1,23 @@ +package net.Indyuce.mmoitems.stat; + +import org.jetbrains.annotations.Nullable; + +/** + * mmoitems + * 22/05/2023 + * + * @author Roch Blondiaux (Kiwix). + */ +public enum StatsCategory { + MMOCORE, + ELEMENTS, + RESTORE, + NONE; + + public static final String NBT_PATH = "mmoitems-stats"; + + public @Nullable String id() { + if (this == NONE) return null; + return name().toLowerCase(); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java index bbcefc55..e21139cf 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java @@ -6,6 +6,7 @@ import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; +import net.Indyuce.mmoitems.stat.StatsCategory; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import org.bukkit.Material; @@ -21,6 +22,7 @@ public abstract class ItemStat, S extends StatData> private final String id, name, configPath, nbtPath; @NotNull private final Material material; + private final StatsCategory category; private final String[] lore; private final List compatibleTypes; @@ -32,11 +34,17 @@ public abstract class ItemStat, S extends StatData> */ private boolean enabled = true; + public ItemStat(@NotNull String id, @NotNull Material material, @NotNull String name, String[] lore, String[] types, Material... materials) { + this(id, StatsCategory.NONE, material, name, lore, types, materials); + } + /** * Initializes an item stat * * @param id The item stat ID, used internally. Also determines the * lower case path for config files + * @param category The category of the stats, mainly used to display the item + * stat in an edition sub gui. * @param material The material used to display the stat in the item * edition GUI * @param name The stat name which has a translation in the language @@ -47,8 +55,9 @@ public abstract class ItemStat, S extends StatData> * @param materials Materials compatible with the item stat (eg Shield * Pattern), any if empty */ - public ItemStat(@NotNull String id, @NotNull Material material, @NotNull String name, String[] lore, String[] types, Material... materials) { + public ItemStat(@NotNull String id, @NotNull StatsCategory category, @NotNull Material material, @NotNull String name, String[] lore, String[] types, Material... materials) { this.id = id; + this.category = category; this.material = material; this.lore = lore == null ? new String[0] : lore; this.compatibleTypes = types == null ? new ArrayList<>() : Arrays.asList(types); @@ -166,7 +175,7 @@ public abstract class ItemStat, S extends StatData> /** * @return The stat ID * @deprecated Use getId() instead. Type is no longer an util since they can - * now be registered from external plugins + * now be registered from external plugins */ @Deprecated @NotNull @@ -184,8 +193,8 @@ public abstract class ItemStat, S extends StatData> /** * @return The NBT path used by the stat to save data in an item's NBTTags. - * The format is 'MMOITEMS_' followed by the stat name in capital - * letters only using _ + * The format is 'MMOITEMS_' followed by the stat name in capital + * letters only using _ */ @NotNull public String getNBTPath() { @@ -271,4 +280,12 @@ public abstract class ItemStat, S extends StatData> */ @NotNull public abstract S getClearStatData(); + + /** + * @return The stat's category + */ + @NotNull + public StatsCategory getCategory() { + return category; + } } \ No newline at end of file