From 1150685c358e9d21b8fa6ed488f56db375176a69 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Thu, 24 Dec 2020 00:40:28 +0100 Subject: [PATCH] !Rolled back API changes --- .../gui/edition/EditionInventory.java | 7 +-- .../mmoitems/gui/edition/ElementsEdition.java | 11 ++-- .../net/Indyuce/mmoitems/stat/Abilities.java | 5 +- .../Indyuce/mmoitems/stat/ArrowParticles.java | 25 +++++---- .../mmoitems/stat/ArrowPotionEffects.java | 33 ++++++------ .../net/Indyuce/mmoitems/stat/Commands.java | 21 ++++---- .../mmoitems/stat/CompatibleTypes.java | 21 ++++---- .../net/Indyuce/mmoitems/stat/Crafting.java | 3 +- .../Indyuce/mmoitems/stat/CustomSounds.java | 22 ++++---- .../net/Indyuce/mmoitems/stat/DyeColor.java | 22 ++++---- .../net/Indyuce/mmoitems/stat/Effects.java | 33 ++++++------ .../net/Indyuce/mmoitems/stat/Elements.java | 22 ++++---- .../net/Indyuce/mmoitems/stat/Enchants.java | 30 ++++++----- .../net/Indyuce/mmoitems/stat/GemSockets.java | 23 ++++---- .../mmoitems/stat/GrantedPermissions.java | 30 ++++++----- .../Indyuce/mmoitems/stat/ItemParticles.java | 19 ++++--- .../mmoitems/stat/ItemTypeRestriction.java | 22 ++++---- .../java/net/Indyuce/mmoitems/stat/Lore.java | 21 ++++---- .../Indyuce/mmoitems/stat/MaterialStat.java | 17 +++--- .../net/Indyuce/mmoitems/stat/NBTTags.java | 23 ++++---- .../mmoitems/stat/PermanentEffects.java | 53 +++++++++++-------- .../net/Indyuce/mmoitems/stat/Permission.java | 24 +++++---- .../Indyuce/mmoitems/stat/PotionColor.java | 22 ++++---- .../Indyuce/mmoitems/stat/PotionEffects.java | 32 +++++------ .../Indyuce/mmoitems/stat/RequiredClass.java | 24 +++++---- .../net/Indyuce/mmoitems/stat/RevisionID.java | 18 ++++--- .../mmoitems/stat/ShieldPatternStat.java | 36 +++++++------ .../Indyuce/mmoitems/stat/UpgradeStat.java | 3 +- .../Indyuce/mmoitems/stat/data/EmptyData.java | 17 ------ .../stat/data/random/RandomStatData.java | 4 -- .../mmoitems/stat/type/BooleanStat.java | 22 ++++---- .../mmoitems/stat/type/DoubleStat.java | 5 +- .../mmoitems/stat/type/InternalStat.java | 3 +- .../Indyuce/mmoitems/stat/type/ItemStat.java | 26 ++++----- .../mmoitems/stat/type/StringListStat.java | 23 ++++---- .../mmoitems/stat/type/StringStat.java | 16 +++--- 36 files changed, 397 insertions(+), 341 deletions(-) delete mode 100644 src/main/java/net/Indyuce/mmoitems/stat/data/EmptyData.java diff --git a/src/main/java/net/Indyuce/mmoitems/gui/edition/EditionInventory.java b/src/main/java/net/Indyuce/mmoitems/gui/edition/EditionInventory.java index c8a01f47..5a65fb7c 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/edition/EditionInventory.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/edition/EditionInventory.java @@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.gui.edition; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; @@ -20,7 +21,6 @@ import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.item.template.TemplateModifier; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.gui.PluginInventory; -import net.Indyuce.mmoitems.stat.data.EmptyData; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.util.AltChar; @@ -82,14 +82,15 @@ public abstract class EditionInventory extends PluginInventory { * @param stat The stat which data we are looking for * @return Optional which contains the corresponding random stat data */ - public RandomStatData getEventualStatData(ItemStat stat) { + public Optional getEventualStatData(ItemStat stat) { + /* * The item data map used to display what the player is currently * editing. If he is editing a stat modifier, use the modifier item data * map. Otherwise, use the base item data map */ Map map = editedModifier != null ? editedModifier.getItemData() : template.getBaseItemData(); - return map.getOrDefault(stat, new EmptyData()); + return map.containsKey(stat) ? Optional.of(map.get(stat)) : Optional.empty(); } public void registerTemplateEdition() { diff --git a/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java b/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java index 6f36b6a6..35316567 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java @@ -20,6 +20,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class ElementsEdition extends EditionInventory { private static final int[] slots = { 19, 25, 20, 24, 28, 34, 29, 33, 30, 32, 37, 43, 38, 42, 39, 41 }; @@ -38,10 +39,10 @@ public class ElementsEdition extends EditionInventory { ItemMeta attackMeta = attack.getItemMeta(); attackMeta.setDisplayName(ChatColor.GREEN + element.getName() + " Damage"); List attackLore = new ArrayList<>(); - RandomStatData statData = getEventualStatData(ItemStats.ELEMENTS); + Optional statData = getEventualStatData(ItemStats.ELEMENTS); attackLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN - + (statData.isPresent() && ((RandomElementListData) statData).hasDamage(element) - ? ((RandomElementListData) statData).getDamage(element) + " (%)" + + (statData.isPresent() && ((RandomElementListData) statData.get()).hasDamage(element) + ? ((RandomElementListData) statData.get()).getDamage(element) + " (%)" : "---")); attackLore.add(""); attackLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); @@ -54,8 +55,8 @@ public class ElementsEdition extends EditionInventory { defenseMeta.setDisplayName(ChatColor.GREEN + element.getName() + " Defense"); List defenseLore = new ArrayList<>(); defenseLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN - + (statData.isPresent() && ((RandomElementListData) statData).hasDefense(element) - ? ((RandomElementListData) statData).getDefense(element) + " (%)" + + (statData.isPresent() && ((RandomElementListData) statData.get()).hasDefense(element) + ? ((RandomElementListData) statData.get()).getDefense(element) + " (%)" : "---")); defenseLore.add(""); defenseLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java b/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java index ce0e8782..2cef9f24 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java @@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.stat; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; @@ -130,9 +131,9 @@ public class Abilities extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { lore.add(ChatColor.GRAY + "Current Abilities: " + ChatColor.GOLD - + (statData.isPresent() ? ((RandomAbilityListData) statData).getAbilities().size() : 0)); + + (statData.isPresent() ? ((RandomAbilityListData) statData.get()).getAbilities().size() : 0)); lore.add(""); lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit the item abilities."); } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java b/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java index bee8613b..9ad06ac7 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java @@ -1,8 +1,18 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Particle; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -18,13 +28,6 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Particle; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; public class ArrowParticles extends ItemStat { public ArrowParticles() { @@ -124,9 +127,9 @@ public class ArrowParticles extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { - ArrowParticlesData cast = (ArrowParticlesData) statData; + ArrowParticlesData cast = (ArrowParticlesData) statData.get(); lore.add(ChatColor.GRAY + "Current Value:"); lore.add(ChatColor.GRAY + "* Particle: " + ChatColor.GOLD @@ -140,8 +143,8 @@ public class ArrowParticles extends ItemStat { "&7* Color: &c&l" + cast.getRed() + "&7 - &a&l" + cast.getGreen() + "&7 - &9&l" + cast.getBlue())); else lore.add(ChatColor.GRAY + "* Speed: " + ChatColor.WHITE + cast.getSpeed()); - } - else lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None"); + } else + lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None"); lore.add(""); lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit."); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java b/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java index 326506b7..292d9805 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java @@ -1,8 +1,24 @@ package net.Indyuce.mmoitems.stat; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.potion.PotionEffectType; + import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -20,19 +36,6 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.potion.PotionEffectType; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; public class ArrowPotionEffects extends ItemStat { private final DecimalFormat durationFormat = new DecimalFormat("0.#"); @@ -95,10 +98,10 @@ public class ArrowPotionEffects extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - RandomPotionEffectListData data = (RandomPotionEffectListData) statData; + RandomPotionEffectListData data = (RandomPotionEffectListData) statData.get(); for (RandomPotionEffectData effect : data.getEffects()) lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().toLowerCase().replace("_", " ")) + ChatColor.GRAY + " Level: " + ChatColor.GREEN + effect.getAmplifier() + ChatColor.GRAY + " Duration: " + ChatColor.GREEN diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Commands.java b/src/main/java/net/Indyuce/mmoitems/stat/Commands.java index f3e7c03b..3abc143c 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Commands.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Commands.java @@ -1,9 +1,19 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -19,13 +29,6 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class Commands extends ItemStat { private static final int max = 15; @@ -108,9 +111,9 @@ public class Commands extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { lore.add(ChatColor.GRAY + "Current Commands: " + ChatColor.RED - + (statData.isPresent() ? ((CommandListData) statData).getCommands().size() : "0")); + + (statData.isPresent() ? ((CommandListData) statData.get()).getCommands().size() : "0")); lore.add(""); lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit item commands."); } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java b/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java index 3397430b..19c426aa 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java @@ -1,7 +1,17 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonParser; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -15,13 +25,6 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class CompatibleTypes extends ItemStat { public CompatibleTypes() { @@ -67,11 +70,11 @@ public class CompatibleTypes extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - ((StringListData) statData).getList().forEach(str -> lore.add(ChatColor.GRAY + str)); + ((StringListData) statData.get()).getList().forEach(str -> lore.add(ChatColor.GRAY + str)); } else lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item."); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Crafting.java b/src/main/java/net/Indyuce/mmoitems/stat/Crafting.java index 1011b21f..362b503d 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Crafting.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Crafting.java @@ -1,6 +1,7 @@ package net.Indyuce.mmoitems.stat; import java.util.List; +import java.util.Optional; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; @@ -40,7 +41,7 @@ public class Crafting extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to access the crafting edition menu."); lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove all crafting recipes."); } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java b/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java index c901f3fe..4b7cd97a 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java @@ -1,5 +1,15 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -16,14 +26,6 @@ import net.Indyuce.mmoitems.stat.type.GemStoneStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; public class CustomSounds extends ItemStat implements GemStoneStat { public CustomSounds() { @@ -80,11 +82,11 @@ public class CustomSounds extends ItemStat implements GemStoneStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - SoundListData data = (SoundListData) statData; + SoundListData data = (SoundListData) statData.get(); data.mapData() .forEach((sound, soundData) -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN diff --git a/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java b/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java index dd0cdb51..47c08e6e 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java @@ -1,5 +1,15 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.meta.LeatherArmorMeta; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -12,14 +22,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.meta.LeatherArmorMeta; - -import java.util.List; public class DyeColor extends ItemStat { public DyeColor() { @@ -62,8 +64,8 @@ public class DyeColor extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { - lore.add(ChatColor.GRAY + "Current Value: " + (statData.isPresent() ? ChatColor.GREEN + statData.toString() : ChatColor.RED + "None")); + public void whenDisplayed(List lore, Optional statData) { + lore.add(ChatColor.GRAY + "Current Value: " + (statData.isPresent() ? ChatColor.GREEN + statData.get().toString() : ChatColor.RED + "None")); lore.add(""); lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the dye color."); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Effects.java b/src/main/java/net/Indyuce/mmoitems/stat/Effects.java index a1aebb75..01f3971e 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Effects.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Effects.java @@ -1,9 +1,25 @@ package net.Indyuce.mmoitems.stat; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.potion.PotionEffectType; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -21,19 +37,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.potion.PotionEffectType; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; public class Effects extends ItemStat { private final DecimalFormat durationFormat = new DecimalFormat("0.#"); @@ -88,11 +91,11 @@ public class Effects extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - RandomPotionEffectListData data = (RandomPotionEffectListData) statData; + RandomPotionEffectListData data = (RandomPotionEffectListData) statData.get(); for (RandomPotionEffectData effect : data.getEffects()) lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().toLowerCase().replace("_", " ")) + ChatColor.GRAY + " Level: " + ChatColor.GREEN + effect.getAmplifier() + ChatColor.GRAY + " Duration: " + ChatColor.GREEN diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Elements.java b/src/main/java/net/Indyuce/mmoitems/stat/Elements.java index 89b742ed..7c33d65b 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Elements.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Elements.java @@ -1,5 +1,15 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -17,14 +27,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; public class Elements extends ItemStat { public Elements() { @@ -74,11 +76,11 @@ public class Elements extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - RandomElementListData data = (RandomElementListData) statData; + RandomElementListData data = (RandomElementListData) statData.get(); data.getDamageElements().forEach( element -> lore.add(ChatColor.GRAY + "* " + element.getName() + " Damage: " + ChatColor.RED + data.getDamage(element) + " (%)")); data.getDefenseElements().forEach( diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java b/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java index 74861026..70381af7 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java @@ -1,5 +1,19 @@ package net.Indyuce.mmoitems.stat; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -14,18 +28,6 @@ import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; public class Enchants extends ItemStat { public Enchants() { @@ -81,11 +83,11 @@ public class Enchants extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - RandomEnchantListData data = (RandomEnchantListData) statData; + RandomEnchantListData data = (RandomEnchantListData) statData.get(); data.getEnchants().forEach(enchant -> lore.add(ChatColor.GRAY + "* " + MMOUtils.caseOnWords(enchant.getKey().getKey().replace("_", " ")) + " " + data.getLevel(enchant).toString())); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/GemSockets.java b/src/main/java/net/Indyuce/mmoitems/stat/GemSockets.java index 8626c281..4058c534 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/GemSockets.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/GemSockets.java @@ -1,9 +1,20 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -17,14 +28,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class GemSockets extends ItemStat { public GemSockets() { @@ -105,11 +108,11 @@ public class GemSockets extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - GemSocketsData data = (GemSocketsData) statData; + GemSocketsData data = (GemSocketsData) statData.get(); data.getEmptySlots().forEach(socket -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + socket + " Gem Socket")); } else diff --git a/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java b/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java index 22b2b203..581249f4 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java @@ -1,7 +1,18 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonParser; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -16,18 +27,11 @@ import net.Indyuce.mmoitems.stat.type.StringListStat; import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class GrantedPermissions extends StringListStat implements GemStoneStat { public GrantedPermissions() { - super("GRANTED_PERMISSIONS", Material.NAME_TAG, "Granted Permissions", new String[] { "A list of permissions that will,", "be granted by the item." }, new String[] { "all" }); + super("GRANTED_PERMISSIONS", Material.NAME_TAG, "Granted Permissions", + new String[] { "A list of permissions that will,", "be granted by the item." }, new String[] { "all" }); } @Override @@ -66,11 +70,11 @@ public class GrantedPermissions extends StringListStat implements GemStoneStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(element -> lore.add(ChatColor.GRAY + MMOLib.plugin.parseColors(element))); } else @@ -91,8 +95,8 @@ public class GrantedPermissions extends StringListStat implements GemStoneStat { @Override public void whenLoaded(ReadMMOItem mmoitem) { if (mmoitem.getNBT().hasTag(getNBTPath())) { - mmoitem.setData(ItemStats.GRANTED_PERMISSIONS, new StringListData( - new JsonParser().parse(mmoitem.getNBT().getString(getNBTPath())).getAsJsonArray())); + mmoitem.setData(ItemStats.GRANTED_PERMISSIONS, + new StringListData(new JsonParser().parse(mmoitem.getNBT().getString(getNBTPath())).getAsJsonArray())); } } } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java b/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java index cb14f330..46c8d5e7 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java @@ -1,7 +1,17 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Particle; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -17,13 +27,6 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Particle; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; public class ItemParticles extends ItemStat { public ItemParticles() { @@ -48,7 +51,7 @@ public class ItemParticles extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to setup the item particles."); } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java b/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java index 9e4baa01..c039a1f5 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java @@ -1,5 +1,15 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; @@ -13,14 +23,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.StringStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class ItemTypeRestriction extends StringStat { public ItemTypeRestriction() { @@ -100,11 +102,11 @@ public class ItemTypeRestriction extends StringStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(el -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + el)); } else lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any type."); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Lore.java b/src/main/java/net/Indyuce/mmoitems/stat/Lore.java index 8455fdb7..3e58a751 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Lore.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Lore.java @@ -1,7 +1,17 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonParser; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -17,13 +27,6 @@ import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class Lore extends StringListStat implements GemStoneStat { public Lore() { @@ -66,11 +69,11 @@ public class Lore extends StringListStat implements GemStoneStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(element -> lore.add(ChatColor.GRAY + MMOLib.plugin.parseColors(element))); } else diff --git a/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java b/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java index d19de388..60328b53 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java @@ -1,5 +1,12 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -18,12 +25,6 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.api.util.EnumUtils; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; -import java.util.Optional; public class MaterialStat extends ItemStat { public MaterialStat() { @@ -69,10 +70,10 @@ public class MaterialStat extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { lore.add(ChatColor.GRAY + "Current Value: " + (statData.isPresent() - ? ChatColor.GREEN + MMOUtils.caseOnWords(((MaterialData) statData).getMaterial().name().toLowerCase().replace("_", " ")) + ? ChatColor.GREEN + MMOUtils.caseOnWords(((MaterialData) statData.get()).getMaterial().name().toLowerCase().replace("_", " ")) : ChatColor.RED + "None")); lore.add(""); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java b/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java index 9873d5ca..85b2b4e3 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java @@ -1,7 +1,18 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonParser; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -14,14 +25,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.StringListStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class NBTTags extends StringListStat { public NBTTags() { @@ -69,10 +72,10 @@ public class NBTTags extends StringListStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(str -> lore.add(ChatColor.GRAY + str)); } else diff --git a/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java b/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java index d451b615..0a3ee5fc 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java @@ -1,8 +1,22 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.potion.PotionEffectType; + import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -20,22 +34,15 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; +/** + * This class has not been updated for the item generation update!!! The potion + * amplifier and duration are not numeric formulas but flat values.... TODO + */ public class PermanentEffects extends ItemStat { public PermanentEffects() { - super("PERM_EFFECTS", Material.POTION, "Permanent Effects", - new String[] { "The potion effects your", "item grants to the holder." }, new String[] { "!miscellaneous", "!block", "all" }); + super("PERM_EFFECTS", Material.POTION, "Permanent Effects", new String[] { "The potion effects your", "item grants to the holder." }, + new String[] { "!miscellaneous", "!block", "all" }); } @Override @@ -69,7 +76,7 @@ public class PermanentEffects extends ItemStat { inv.getEditedSection().set("perm-effects", null); inv.registerTemplateEdition(); inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + last.substring(0, 1).toUpperCase() - + last.substring(1).toLowerCase() + "�7."); + + last.substring(1).toLowerCase() + "."); } } } @@ -92,10 +99,10 @@ public class PermanentEffects extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - RandomPotionEffectListData data = (RandomPotionEffectListData) statData; + RandomPotionEffectListData data = (RandomPotionEffectListData) statData.get(); for (RandomPotionEffectData effect : data.getEffects()) lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().replace("_", " ").toLowerCase()) + " " + effect.getAmplifier().toString()); @@ -115,8 +122,8 @@ public class PermanentEffects extends ItemStat { String permEffectFormat = ItemStat.translate("perm-effect"); ((PotionEffectListData) data).getEffects().forEach(effect -> { - lore.add(permEffectFormat.replace("#", MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType()) - + " " + MMOUtils.intToRoman(effect.getLevel()))); + lore.add(permEffectFormat.replace("#", + MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType()) + " " + MMOUtils.intToRoman(effect.getLevel()))); object.addProperty(effect.getType().getName(), effect.getLevel()); }); @@ -130,13 +137,13 @@ public class PermanentEffects extends ItemStat { PotionEffectListData effects = new PotionEffectListData(); JsonElement element = new JsonParser().parse(mmoitem.getNBT().getString("MMOITEMS_PERM_EFFECTS")); - if(!element.isJsonObject()) { - MMOItems.plugin.getLogger().warning("Couldn't load perm effects from " + mmoitem.getType() - + "." + mmoitem.getId() + ", the NBTData isn't a json object!"); + if (!element.isJsonObject()) { + MMOItems.plugin.getLogger().warning( + "Couldn't load perm effects from " + mmoitem.getType() + "." + mmoitem.getId() + ", the NBTData isn't a json object!"); return; } - element.getAsJsonObject().entrySet().forEach(entry -> - effects.add(new PotionEffectData(PotionEffectType.getByName(entry.getKey()), entry.getValue().getAsInt()))); + element.getAsJsonObject().entrySet() + .forEach(entry -> effects.add(new PotionEffectData(PotionEffectType.getByName(entry.getKey()), entry.getValue().getAsInt()))); mmoitem.setData(ItemStats.PERM_EFFECTS, effects); } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Permission.java b/src/main/java/net/Indyuce/mmoitems/stat/Permission.java index 70d52fc3..1d7f271f 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Permission.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Permission.java @@ -1,5 +1,16 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -18,15 +29,6 @@ import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.item.NBTItem; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Sound; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; public class Permission extends StringListStat implements ItemRestriction, GemStoneStat { public Permission() { @@ -72,11 +74,11 @@ public class Permission extends StringListStat implements ItemRestriction, GemSt } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(el -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + el)); } else diff --git a/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java b/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java index e99e36be..96bb1fd9 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java @@ -1,5 +1,15 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.meta.PotionMeta; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -10,14 +20,6 @@ import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.StringStat; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.meta.PotionMeta; - -import java.util.List; public class PotionColor extends StringStat { public PotionColor() { @@ -61,9 +63,9 @@ public class PotionColor extends StringStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { - lore.add(statData.isPresent() ? ChatColor.GREEN + statData.toString() : ChatColor.RED + "Uncolored"); + lore.add(statData.isPresent() ? ChatColor.GREEN + statData.get().toString() : ChatColor.RED + "Uncolored"); lore.add(""); lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java b/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java index 5d594272..61dc2eef 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java @@ -1,5 +1,20 @@ package net.Indyuce.mmoitems.stat; +import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionEffectType; + import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -15,19 +30,6 @@ import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffectType; - -import java.text.DecimalFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Set; public class PotionEffects extends ItemStat { private final DecimalFormat durationFormat = new DecimalFormat("0.#"); @@ -88,11 +90,11 @@ public class PotionEffects extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - PotionEffectListData data = (PotionEffectListData) statData; + PotionEffectListData data = (PotionEffectListData) statData.get(); for (PotionEffectData effect : data.getEffects()) lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().toLowerCase().replace("_", " ")) + " " + MMOUtils.intToRoman(effect.getLevel()) + " " + ChatColor.GRAY + "(" + ChatColor.GREEN diff --git a/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java b/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java index b870887e..ce68e91e 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java @@ -1,5 +1,16 @@ package net.Indyuce.mmoitems.stat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.regex.Pattern; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; @@ -17,15 +28,6 @@ import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.item.NBTItem; import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.version.VersionMaterial; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Sound; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; public class RequiredClass extends StringListStat implements ItemRestriction, GemStoneStat { public RequiredClass() { @@ -77,11 +79,11 @@ public class RequiredClass extends StringListStat implements ItemRestriction, Ge } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(el -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + el)); } else diff --git a/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java b/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java index 3b0c227d..3a694320 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java @@ -1,5 +1,13 @@ package net.Indyuce.mmoitems.stat; +import java.util.List; +import java.util.Optional; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; @@ -10,12 +18,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; public class RevisionID extends ItemStat { public RevisionID() { @@ -60,9 +62,9 @@ public class RevisionID extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { - NumericStatFormula data = (NumericStatFormula) statData; + NumericStatFormula data = (NumericStatFormula) statData.get(); lore.add(ChatColor.GRAY + "Current Revision ID: " + ChatColor.GREEN + ((int) data.getBase())); } else lore.add(ChatColor.GRAY + "Current Revision ID: " + ChatColor.GREEN + "1"); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java b/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java index 05b43654..58b354b3 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java @@ -1,17 +1,10 @@ package net.Indyuce.mmoitems.stat; -import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; -import net.Indyuce.mmoitems.api.edition.StatEdition; -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.data.ShieldPatternData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.StringStat; -import net.mmogroup.mmolib.api.util.AltChar; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; + import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -25,9 +18,18 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.meta.BlockStateMeta; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; +import net.Indyuce.mmoitems.ItemStats; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.api.edition.StatEdition; +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.data.ShieldPatternData; +import net.Indyuce.mmoitems.stat.data.random.RandomStatData; +import net.Indyuce.mmoitems.stat.data.type.StatData; +import net.Indyuce.mmoitems.stat.type.StringStat; +import net.mmogroup.mmolib.api.util.AltChar; public class ShieldPatternStat extends StringStat { public ShieldPatternStat() { @@ -126,11 +128,11 @@ public class ShieldPatternStat extends StringStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - ShieldPatternData data = (ShieldPatternData) statData; + ShieldPatternData data = (ShieldPatternData) statData.get(); lore.add(ChatColor.GRAY + "* Base Color: " + (data.getBaseColor() != null ? ChatColor.GREEN + MMOUtils.caseOnWords(data.getBaseColor().name().toLowerCase().replace("_", " ")) diff --git a/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java b/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java index 4594a186..d8b0b550 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java @@ -1,6 +1,7 @@ package net.Indyuce.mmoitems.stat; import java.util.List; +import java.util.Optional; import java.util.Random; import org.apache.commons.lang.Validate; @@ -116,7 +117,7 @@ public class UpgradeStat extends ItemStat implements ConsumableItemInteraction { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to setup upgrading."); lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset."); } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/data/EmptyData.java b/src/main/java/net/Indyuce/mmoitems/stat/data/EmptyData.java deleted file mode 100644 index 2af72181..00000000 --- a/src/main/java/net/Indyuce/mmoitems/stat/data/EmptyData.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.Indyuce.mmoitems.stat.data; - -import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; - -public class EmptyData implements RandomStatData { - @Override - public StatData randomize(MMOItemBuilder builder) { - return null; - } - - @Override - public boolean isPresent() { - return false; - } -} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java b/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java index 194e2bdd..31379883 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java @@ -17,8 +17,4 @@ public interface RandomStatData { * base item template */ StatData randomize(MMOItemBuilder builder); - - default boolean isPresent() { - return true; - } } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java index 1b1af0ae..01ca5b4c 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java @@ -1,5 +1,15 @@ package net.Indyuce.mmoitems.stat.type; +import java.text.DecimalFormat; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; @@ -12,14 +22,6 @@ import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.text.DecimalFormat; -import java.util.List; public class BooleanStat extends ItemStat { private static final DecimalFormat digit = new DecimalFormat("0.#"); @@ -78,10 +80,10 @@ public class BooleanStat extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { - double chance = ((RandomBooleanData) statData).getChance(); + double chance = ((RandomBooleanData) statData.get()).getChance(); lore.add(ChatColor.GRAY + "Current Value: " + (chance >= 1 ? ChatColor.GREEN + "True" : chance <= 0 ? ChatColor.RED + "False" : ChatColor.GREEN + digit.format(chance * 100) + "% Chance")); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java index c1bc5bec..1222a4d6 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java @@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.stat.type; import java.text.DecimalFormat; import java.util.List; +import java.util.Optional; import java.util.regex.Pattern; import org.apache.commons.lang.Validate; @@ -140,9 +141,9 @@ public class DoubleStat extends ItemStat implements Upgradable { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { - NumericStatFormula data = (NumericStatFormula) statData; + NumericStatFormula data = (NumericStatFormula) statData.get(); lore.add(ChatColor.GRAY + "Base Value: " + ChatColor.GREEN + digit.format(data.getBase()) + (data.getScale() != 0 ? ChatColor.GRAY + " (+" + ChatColor.GREEN + digit.format(data.getScale()) + ChatColor.GRAY + ")" : "")); if (data.getSpread() > 0) diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java index b4d4aace..d194991c 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java @@ -1,6 +1,7 @@ package net.Indyuce.mmoitems.stat.type; import java.util.List; +import java.util.Optional; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; @@ -36,7 +37,7 @@ public abstract class InternalStat extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { // not supported } } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java index a18b12a0..8b2f151a 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java @@ -1,5 +1,14 @@ package net.Indyuce.mmoitems.stat.type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; + import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; @@ -7,13 +16,6 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; public abstract class ItemStat { private final String id, name; @@ -79,10 +81,10 @@ public abstract class ItemStat { public abstract void whenClicked(EditionInventory inv, InventoryClickEvent event); /** - * When inputing data using chat or anvil input in order to edit the edit in - * the GUI editor. IAE are handled and exception messages are sent back to - * the player. Stat edition is not canceled until a right input is given or - * the player inputs 'cancel' + * When inputing data using chat or anvil input in order to edit the item + * using the GUI editor. IAE are handled and exception messages are sent + * back to the player. Stat edition is not canceled until a right input is + * given or the player inputs 'cancel' * * @param inv Previously opened edition menu * @param message Player input @@ -109,7 +111,7 @@ public abstract class ItemStat { * @param statData Stat data being displayed, optional is empty if there is * no stat data */ - public abstract void whenDisplayed(List lore, RandomStatData statData); + public abstract void whenDisplayed(List lore, Optional statData); public String getName() { return name; diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/StringListStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/StringListStat.java index 3458fe02..8b2b7c13 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/StringListStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/StringListStat.java @@ -1,7 +1,18 @@ package net.Indyuce.mmoitems.stat.type; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import com.google.gson.JsonArray; import com.google.gson.JsonParser; + import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; @@ -13,14 +24,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.ArrayList; -import java.util.List; public class StringListStat extends ItemStat { public StringListStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { @@ -77,10 +80,10 @@ public class StringListStat extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { lore.add(ChatColor.GRAY + "Current Value:"); - StringListData data = (StringListData) statData; + StringListData data = (StringListData) statData.get(); data.getList().forEach(element -> lore.add(ChatColor.GRAY + MMOLib.plugin.parseColors(element))); } else diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java index 43630d85..606732ea 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java @@ -1,5 +1,13 @@ package net.Indyuce.mmoitems.stat.type; +import java.util.List; +import java.util.Optional; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; + import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; @@ -11,12 +19,6 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.item.ItemTag; import net.mmogroup.mmolib.api.util.AltChar; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; public class StringStat extends ItemStat { public StringStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { @@ -59,7 +61,7 @@ public class StringStat extends ItemStat { } @Override - public void whenDisplayed(List lore, RandomStatData statData) { + public void whenDisplayed(List lore, Optional statData) { if (statData.isPresent()) { String value = MMOLib.plugin.parseColors(statData.toString()); value = value.length() > 40 ? value.substring(0, 40) + "..." : value;