From ef1a1e7cd5d48adc02b705d678807dbf80f90d83 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 26 Oct 2024 03:19:43 +0200 Subject: [PATCH] Basic component API stuff --- .../java/net/Indyuce/mmoitems/ItemStats.java | 6 +- .../event/item/ConsumableConsumedEvent.java | 2 +- .../mmoitems/api/interaction/Consumable.java | 4 +- .../mmoitems/api/interaction/GemStone.java | 2 +- .../mmoitems/api/player/RPGPlayer.java | 2 +- .../mmoitems/api/util/NumericStatFormula.java | 41 ++-- .../comp/enchants/CrazyEnchantsStat.java | 2 +- .../AdvancedEnchantsStat.java | 2 +- .../comp/mmoinventory/stat/AccessorySet.java | 2 +- .../Indyuce/mmoitems/comp/rpg/HeroesHook.java | 2 +- .../mmoitems/gui/edition/ItemEdition.java | 192 +++++++++++---- .../gui/edition/newedit/ItemFactory.java | 59 +++++ .../mmoitems/gui/listener/GuiListener.java | 1 + .../Indyuce/mmoitems/manager/StatManager.java | 7 + .../net/Indyuce/mmoitems/stat/Abilities.java | 21 +- .../net/Indyuce/mmoitems/stat/Amphibian.java | 4 +- .../Indyuce/mmoitems/stat/AttackDamage.java | 8 + .../Indyuce/mmoitems/stat/CanDeconstruct.java | 2 +- .../net/Indyuce/mmoitems/stat/CanDeskin.java | 2 +- .../Indyuce/mmoitems/stat/CanIdentify.java | 2 +- .../Indyuce/mmoitems/stat/CanUnsocket.java | 2 +- .../mmoitems/stat/CraftingPermission.java | 3 +- .../mmoitems/stat/CustomDurability.java | 3 +- .../mmoitems/stat/CustomModelData.java | 3 +- .../Indyuce/mmoitems/stat/CustomSounds.java | 4 +- .../Indyuce/mmoitems/stat/DisplayName.java | 2 +- .../Indyuce/mmoitems/stat/DisplayedType.java | 2 +- .../net/Indyuce/mmoitems/stat/DyeColor.java | 206 ++++++++-------- .../net/Indyuce/mmoitems/stat/Effects.java | 2 +- .../net/Indyuce/mmoitems/stat/Elements.java | 26 +- .../net/Indyuce/mmoitems/stat/GemColor.java | 2 +- .../mmoitems/stat/GemUpgradeScaling.java | 2 +- .../mmoitems/stat/GrantedPermissions.java | 2 +- .../net/Indyuce/mmoitems/stat/ItemDamage.java | 2 +- .../net/Indyuce/mmoitems/stat/ItemLevel.java | 2 +- .../Indyuce/mmoitems/stat/ItemSetStat.java | 2 +- .../Indyuce/mmoitems/stat/ItemTierStat.java | 3 +- .../java/net/Indyuce/mmoitems/stat/Lore.java | 2 +- .../net/Indyuce/mmoitems/stat/LoreFormat.java | 2 +- .../mmoitems/stat/LuteAttackEffectStat.java | 2 +- .../mmoitems/stat/LuteAttackSoundStat.java | 2 +- .../net/Indyuce/mmoitems/stat/ManaCost.java | 4 +- .../Indyuce/mmoitems/stat/MaterialStat.java | 7 + .../Indyuce/mmoitems/stat/MaxItemDamage.java | 2 +- .../Indyuce/mmoitems/stat/MaxStackSize.java | 2 +- .../mmoitems/stat/MaximumDurability.java | 4 +- .../net/Indyuce/mmoitems/stat/Permission.java | 2 +- .../Indyuce/mmoitems/stat/PotionColor.java | 143 +++++------ .../Indyuce/mmoitems/stat/RandomUnsocket.java | 3 +- .../Indyuce/mmoitems/stat/RepairPower.java | 2 +- .../mmoitems/stat/RepairPowerPercent.java | 2 +- .../mmoitems/stat/RepairReference.java | 2 +- .../Indyuce/mmoitems/stat/RequiredBiomes.java | 6 +- .../Indyuce/mmoitems/stat/RequiredClass.java | 4 +- .../Indyuce/mmoitems/stat/RestoreFood.java | 2 +- .../Indyuce/mmoitems/stat/RestoreHealth.java | 2 +- .../Indyuce/mmoitems/stat/RestoreMana.java | 2 +- .../mmoitems/stat/RestoreSaturation.java | 2 +- .../Indyuce/mmoitems/stat/RestoreStamina.java | 2 +- .../net/Indyuce/mmoitems/stat/RevisionID.java | 2 +- .../mmoitems/stat/SoulbindingBreakChance.java | 2 +- .../mmoitems/stat/SoulbindingChance.java | 2 +- .../net/Indyuce/mmoitems/stat/Soulbound.java | 4 +- .../net/Indyuce/mmoitems/stat/StoredTags.java | 4 +- .../Indyuce/mmoitems/stat/SuccessRate.java | 2 +- .../Indyuce/mmoitems/stat/TooltipStat.java | 2 +- .../mmoitems/stat/TrimMaterialStat.java | 2 +- .../mmoitems/stat/TrimPatternStat.java | 2 +- .../Indyuce/mmoitems/stat/UpgradeStat.java | 2 +- .../TerminalComponentException.java | 8 + .../ConsumableItemInteraction.java | 2 +- .../{type => behaviour}/GemStoneStat.java | 5 +- .../{type => behaviour}/InternalStat.java | 2 +- .../stat/behaviour/ItemRestriction.java | 39 +++ .../{type => behaviour}/PlayerConsumable.java | 10 +- .../stat/component/DoubleComponent.java | 14 -- .../stat/component/IntegerComponent.java | 14 -- .../mmoitems/stat/component/LoreWrapper.java | 27 +++ .../mmoitems/stat/component/Mergeable.java | 6 +- .../stat/component/ObjectComponent.java | 49 ---- .../stat/component/StatComponent.java | 25 ++ .../component/builtin/AbilityComponent.java | 61 +++++ .../component/builtin/ArrayComponent.java | 28 +++ .../component/builtin/BooleanComponent.java | 37 +++ .../component/builtin/DoubleComponent.java | 28 +++ .../component/builtin/IntegerComponent.java | 33 +++ .../builtin/ItemAbilityComponent.java | 225 +++++++++++++++++ .../component/builtin/MaterialComponent.java | 68 ++++++ .../component/builtin/ObjectComponent.java | 38 +++ .../builtin/ObjectComponentImpl.java | 36 +++ .../component/builtin/StringComponent.java | 32 +++ .../mmoitems/stat/component/model/Model.java | 23 ++ .../component/model/builtin/ArrayModel.java | 24 ++ .../component/model/builtin/BooleanModel.java | 49 ++++ .../component/model/builtin/DoubleModel.java | 27 +++ .../component/model/builtin/IntegerModel.java | 25 ++ .../component/model/builtin/ObjectModel.java | 36 +++ .../stat/component/type/ComponentType.java | 195 ++++++++++++++- .../component/type/DoubleComponentType.java | 11 - .../component/type/IntegerComponentType.java | 16 -- .../component/type/ObjectComponentType.java | 16 -- .../type/builtin/ArrayComponentType.java | 94 ++++++++ .../type/builtin/BooleanComponentType.java | 59 +++++ .../type/builtin/DoubleComponentType.java | 79 ++++++ .../type/builtin/IntegerComponentType.java | 82 +++++++ .../type/builtin/ObjectComponentType.java | 112 +++++++++ .../type/builtin/StringComponentType.java | 38 +++ .../mmoitems/stat/data/AbilityData.java | 1 + .../mmoitems/stat/data/DoubleData.java | 1 + .../stat/data/dynamic/DynamicStatData.java | 16 +- .../stat/data/random/RandomAbilityData.java | 4 + .../data/random/RandomAbilityListData.java | 4 + .../data/random/RandomElementListData.java | 4 + .../data/random/RandomEnchantListData.java | 4 + .../data/random/RandomPotionEffectData.java | 4 + .../random/RandomPotionEffectListData.java | 4 + .../data/random/RandomRequiredLevelData.java | 3 + .../stat/data/random/RandomRestoreData.java | 43 ++-- .../stat/data/random/RandomStatData.java | 3 +- .../mmoitems/stat/type/BooleanStat.java | 227 +++++++++--------- .../mmoitems/stat/type/DoubleStat.java | 34 ++- .../mmoitems/stat/type/FakeElementalStat.java | 1 + .../mmoitems/stat/type/ItemRestriction.java | 38 --- .../Indyuce/mmoitems/stat/type/ItemStat.java | 43 +++- .../mmoitems/stat/type/RequiredLevelStat.java | 2 + .../mmoitems/stat/type/StringStat.java | 16 +- .../net/Indyuce/mmoitems/util/MMOUtils.java | 33 ++- .../java/net/Indyuce/mmoitems/util/Pair.java | 8 +- .../mmoitems/util/VersionDependant.java | 15 -- .../listener/reforging/RFGKeepGems.java | 2 +- pom.xml | 2 + 131 files changed, 2372 insertions(+), 669 deletions(-) create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/newedit/ItemFactory.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/annotation/TerminalComponentException.java rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/{type => behaviour}/ConsumableItemInteraction.java (96%) rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/{type => behaviour}/GemStoneStat.java (73%) rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/{type => behaviour}/InternalStat.java (89%) create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ItemRestriction.java rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/{type => behaviour}/PlayerConsumable.java (68%) delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/DoubleComponent.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/IntegerComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/LoreWrapper.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/ObjectComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/AbilityComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ArrayComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/BooleanComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/DoubleComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/IntegerComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ItemAbilityComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/MaterialComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponentImpl.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/StringComponent.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/Model.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ArrayModel.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/BooleanModel.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/DoubleModel.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/IntegerModel.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ObjectModel.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponentType.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/IntegerComponentType.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponentType.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ArrayComponentType.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/BooleanComponentType.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/DoubleComponentType.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/IntegerComponentType.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ObjectComponentType.java create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/StringComponentType.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemRestriction.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/VersionDependant.java diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java index 8344a93c..bada2889 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java @@ -181,8 +181,8 @@ public class ItemStats { BOUNCING_CRACK = new BooleanStat("BOUNCING_CRACK", Material.COBBLESTONE_WALL, "Bouncing Crack", new String[]{"If set to true, your tool will", "also break nearby blocks."}, new String[]{"tool"}).setCategory(StatCategories.TOOLS), PICKAXE_POWER = new PickaxePower(), CUSTOM_SOUNDS = new CustomSounds(), - ELEMENTS = new Elements(), - COMMANDS = new Commands(), + ELEMENTS = new Elements(), + COMMANDS = new Commands(), // STAFF_SPIRIT = new StaffSpiritStat(), LUTE_ATTACK_SOUND = new LuteAttackSoundStat(), LUTE_ATTACK_EFFECT = new LuteAttackEffectStat(), @@ -209,7 +209,7 @@ public class ItemStats { UPGRADE = new UpgradeStat(), DOWNGRADE_ON_BREAK = new BooleanStat("BREAK_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade when Broken", new String[]{"If this item's durability reaches 0,", "it will be fully repaired but also", "downgraded by one level.", "", "&cIt will only break if it cannot be", "&cdowngraded further", "", "Requires to define an &6Upgrade Template", "Required to define &6Custom Durability"}, new String[]{"equipment"}).setCategory(StatCategories.UPGRADING), DOWNGRADE_ON_DEATH = new BooleanStat("DEATH_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade on Death", new String[]{"If the wearer of this item dies, it may", "downgrade (based on &6Death Downgrade", "&6Chance &7stat)", "", "Required to define an &6Upgrade Template", "Requires keep-inventory gamerule. "}, new String[]{"equipment"}).setCategory(StatCategories.UPGRADING), - DOWNGRADE_ON_DEATH_CHANCE = new DoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", new String[]{"Probability that an item with &cDowngrade ", "&con Death&7 will be downgraded when the", "player dies. ", "", "Exceeding 100% will for sure downgrade", "one item, and roll again to downgrade", "another (with the excess probability).", "&6The same item wont be downgraded twice."}, new String[]{"equipment"}, false).setCategory(StatCategories.UPGRADING), + DOWNGRADE_ON_DEATH_CHANCE = new DoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", "Probability that an item with &cDowngrade on Death &7will be downgraded when the player dies.\n\n Exceeding 100% will for sure downgrade one item, and roll again to downgrade another (with the excess probability). The same item won't be downgraded twice.", new String[]{"equipment"}, false).setCategory(StatCategories.UPGRADING), // Unique Item Stats DYE_COLOR = new DyeColor(), diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/ConsumableConsumedEvent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/ConsumableConsumedEvent.java index e7f0c5f1..5555bb6b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/ConsumableConsumedEvent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/ConsumableConsumedEvent.java @@ -4,7 +4,7 @@ import net.Indyuce.mmoitems.api.event.PlayerDataEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.player.PlayerData; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java index 7fc3945f..229cd3ef 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java @@ -12,8 +12,8 @@ import net.Indyuce.mmoitems.api.event.item.ConsumableConsumedEvent; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.item.util.LoreUpdate; import net.Indyuce.mmoitems.api.player.PlayerData; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java index 09606dbb..17fee81a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java @@ -14,7 +14,7 @@ import net.Indyuce.mmoitems.stat.data.GemSocketsData; import net.Indyuce.mmoitems.stat.data.GemstoneData; import net.Indyuce.mmoitems.stat.data.type.Mergeable; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.StatHistory; import net.Indyuce.mmoitems.util.MMOUtils; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/RPGPlayer.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/RPGPlayer.java index b246ecd1..aee82bb6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/RPGPlayer.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/RPGPlayer.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.api.player; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.util.message.Message; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Sound; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/NumericStatFormula.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/NumericStatFormula.java index 51167e6c..d2711d6e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/NumericStatFormula.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/NumericStatFormula.java @@ -1,6 +1,9 @@ package net.Indyuce.mmoitems.api.util; import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.builtin.DoubleComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData; @@ -167,7 +170,7 @@ public class NumericStatFormula implements RandomStatData, Updatable /** * @return When the item has a certain level or tier, this is how much each level shifts - * the peak, so that it is centered at {@code base + scale*level} + * the peak, so that it is centered at {@code base + scale*level} * @see #getBase() */ public double getScale() { @@ -183,15 +186,15 @@ public class NumericStatFormula implements RandomStatData, Updatable /** * @return For gaussian distributions, there always is that INSANELY SMALL - * chance of getting an INSANELY LARGE number. - *

- * For example: At base atk dmg 10, and standard deviation 1: - *

68% of rolls will fall between 9 and 11; - *

95% of rolls will fall between 8 and 12; - *

99.7% of rolls will fall between 7 and 13; - *

10E-42 of a roll that will give you an epic 300 dmg sword - *

- * Whatever, this constrains to a minimum and maximum of output. + * chance of getting an INSANELY LARGE number. + *

+ * For example: At base atk dmg 10, and standard deviation 1: + *

68% of rolls will fall between 9 and 11; + *

95% of rolls will fall between 8 and 12; + *

99.7% of rolls will fall between 7 and 13; + *

10E-42 of a roll that will give you an epic 300 dmg sword + *

+ * Whatever, this constrains to a minimum and maximum of output. */ public double getMaxSpread() { return maxSpread; @@ -226,15 +229,15 @@ public class NumericStatFormula implements RandomStatData, Updatable * the formula is base + (scale*level). * This is the level * @return Legacy formula: ???
- * Let A = {base} + {scale} * lvl, then the returned value is a - * random value taken in respect to a gaussian distribution - * centered on A, with average spread of {spread}%, and with a - * maximum offset of {maxSpread}% (relative to average value) - *

- * Formula: Spread = Standard Deviation - * The mean, the peak is located at {base} + {scale}*lvl.
- * The 'spread' is the standard deviation of the distribution.
- * 'Max Spread' constrains the result of this operation at {mean}±{max spread} + * Let A = {base} + {scale} * lvl, then the returned value is a + * random value taken in respect to a gaussian distribution + * centered on A, with average spread of {spread}%, and with a + * maximum offset of {maxSpread}% (relative to average value) + *

+ * Formula: Spread = Standard Deviation + * The mean, the peak is located at {base} + {scale}*lvl.
+ * The 'spread' is the standard deviation of the distribution.
+ * 'Max Spread' constrains the result of this operation at {mean}±{max spread} */ public double calculate(double scaleFactor) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/CrazyEnchantsStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/CrazyEnchantsStat.java index 254f01a3..ebbde29d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/CrazyEnchantsStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/CrazyEnchantsStat.java @@ -8,7 +8,7 @@ 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.random.RandomStatData; -import net.Indyuce.mmoitems.stat.type.InternalStat; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.NotImplementedException; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/advanced_enchants/AdvancedEnchantsStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/advanced_enchants/AdvancedEnchantsStat.java index df4a1c61..a5d3ce30 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/advanced_enchants/AdvancedEnchantsStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/enchants/advanced_enchants/AdvancedEnchantsStat.java @@ -6,7 +6,7 @@ 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.random.RandomStatData; -import net.Indyuce.mmoitems.stat.type.InternalStat; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.advancedplugins.ae.api.AEAPI; import org.apache.commons.lang.Validate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmoinventory/stat/AccessorySet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmoinventory/stat/AccessorySet.java index b9b6c72b..9fa9e188 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmoinventory/stat/AccessorySet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmoinventory/stat/AccessorySet.java @@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java index b0973810..be777079 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java @@ -22,7 +22,7 @@ import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.category.StatCategory; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.RequiredLevelStat; import org.apache.commons.lang.Validate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java index be5eb1ca..65c3cd60 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java @@ -1,10 +1,23 @@ package net.Indyuce.mmoitems.gui.edition; import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.api.util.AltChar; +import io.lumine.mythic.lib.util.Lazy; import io.lumine.mythic.lib.version.VersionUtils; +import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; -import net.Indyuce.mmoitems.stat.type.InternalStat; +import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.gui.edition.newedit.ItemFactory; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; +import net.Indyuce.mmoitems.stat.category.StatCategory; +import net.Indyuce.mmoitems.stat.component.LoreWrapper; +import net.Indyuce.mmoitems.stat.component.builtin.MaterialComponent; +import net.Indyuce.mmoitems.stat.component.builtin.StringComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import net.Indyuce.mmoitems.stat.component.model.builtin.ArrayModel; +import net.Indyuce.mmoitems.stat.component.model.builtin.DoubleModel; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; @@ -16,18 +29,26 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; public class ItemEdition extends EditionInventory { - private static final int[] slots = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43}; - private static final NamespacedKey STAT_ID_KEY = new NamespacedKey(MMOItems.plugin, "StatId"); + private static final int[] SLOTS = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43, 46, 47, 48, 49, 50, 51, 52}; + private static final NamespacedKey COMPONENT_KEY = new NamespacedKey(MMOItems.plugin, "component_key"); + + private Stack explored = new Stack<>(); + Map, Model> sampleItem = new HashMap<>(); public ItemEdition(Player player, MMOItemTemplate template) { - super(player, template); + super(player, template, false); + + // TODO replace by getting info from the item + sampleItem.put(ItemStats.ATTACK_DAMAGE, new DoubleModel(new NumericStatFormula(10))); + sampleItem.put(ItemStats.MATERIAL, new MaterialComponent(Material.IRON_SWORD)); + sampleItem.put(ItemStats.NAME, new StringComponent("Super Duper Item")); + sampleItem.put(ItemStats.LORE, new ArrayModel<>()); } @Override @@ -35,71 +56,120 @@ public class ItemEdition extends EditionInventory { return "Item Edition: " + getEdited().getId(); } + private static class Entry { + final String key; + final StatCategory category; + final ComponentType ctype; + final Model model; + + private Entry(String key, StatCategory category, ComponentType ctype, Model model) { + this.key = key; + this.category = category; + this.ctype = ctype; + this.model = model; + } + } + @Override + @SuppressWarnings({"unchecked"}) public void arrangeInventory() { - int min = (page - 1) * slots.length; - int max = page * slots.length; - int n = 0; - /* - * it has to determine what stats can be applied first because otherwise - * the for loop will just let some slots empty - */ - List appliable = new ArrayList<>(getEdited().getType().getAvailableStats()).stream() - .filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).collect(Collectors.toList()); + Entry topmost = explored.isEmpty() ? null : explored.peek(); - for (int j = min; j < Math.min(appliable.size(), max); j++) { - ItemStat stat = appliable.get(j); - ItemStack item = new ItemStack(stat.getDisplayMaterial()); + // TODO define visiting object/array. and let some of these visit() impls throw RuntimeExcption + List entries = topmost != null ? + + // Explore current component + ((ComponentType) topmost.ctype).getSubcomponents().stream() + .map(pair -> new Entry(pair.getKey(), null, pair.getValue(), topmost.model == null ? null : topmost.model.getModel(pair.getKey()))) + .collect(Collectors.toList()) : + + // Explore stats + new ArrayList<>(getEdited().getType().getAvailableStats()).stream() + .filter(stat -> stat.getComponentType() != null) + .filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)) + // TODO sample item + .map(stat -> new Entry(stat.getId().toLowerCase(), stat.getCategory(), stat.getComponentType(), sampleItem.get(stat))) + .collect(Collectors.toList()); + + // Bounds and counter + int min = (page - 1) * SLOTS.length; + int max = Math.min(page * SLOTS.length, entries.size()); + int slotc = 0; + + for (int j = min; j < max; j++) { + Entry entry = entries.get(j); + + ItemStack item = entry.ctype.provideIcon(entry.model); ItemMeta meta = item.getItemMeta(); meta.addItemFlags(ItemFlag.values()); VersionUtils.addEmptyAttributeModifier(meta); - meta.setDisplayName(ChatColor.GREEN + stat.getName()); - List lore = MythicLib.plugin.parseColors(Arrays.stream(stat.getLore()).map(s -> ChatColor.GRAY + s).collect(Collectors.toList())); - lore.add(""); - if (stat.getCategory() != null) { + meta.setDisplayName(ChatColor.GREEN + entry.ctype.provideName(entry.model)); + List lore = new ArrayList<>(); + + // Display stat category + if (entry.category != null) { lore.add(0, ""); - lore.add(0, ChatColor.BLUE + stat.getCategory().getLoreTag()); + lore.add(0, ChatColor.BLUE + entry.category.getLoreTag()); } - stat.whenDisplayed(lore, getEventualStatData(stat)); + // Display component type lore + List statDesc = (List) entry.ctype.provideDescription(entry.model); + if (statDesc != null) { + lore.addAll(MythicLib.plugin.parseColors(statDesc.stream().map(s -> ChatColor.GRAY + s).collect(Collectors.toList()))); + lore.add(""); + } + + // Display current value of main stat component + try { + entry.ctype.editionUiDisplay(new LoreWrapper(lore), entry.model); + lore.add(""); + } catch (Exception ignored) { + // Pass + } + + // Lore action tags + for (String loreActionTag : (List) entry.ctype.getActionLoreTags()) + lore.add(ChatColor.YELLOW + AltChar.listDash + " " + loreActionTag); + + // Set NBT tag for exploration and edition + meta.getPersistentDataContainer().set(COMPONENT_KEY, PersistentDataType.STRING, entry.key); - meta.getPersistentDataContainer().set(STAT_ID_KEY, PersistentDataType.STRING, stat.getId()); meta.setLore(lore); item.setItemMeta(meta); - inventory.setItem(slots[n++], item); + inventory.setItem(SLOTS[slotc++], item); } - ItemStack glass = new ItemStack(Material.GRAY_STAINED_GLASS_PANE); - ItemMeta glassMeta = glass.getItemMeta(); - glassMeta.setDisplayName(ChatColor.RED + "- No Item Stat -"); - glass.setItemMeta(glassMeta); - - ItemStack next = new ItemStack(Material.ARROW); - ItemMeta nextMeta = next.getItemMeta(); - nextMeta.setDisplayName(ChatColor.GREEN + "Next Page"); - next.setItemMeta(nextMeta); - - ItemStack previous = new ItemStack(Material.ARROW); - ItemMeta previousMeta = previous.getItemMeta(); - previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page"); - previous.setItemMeta(previousMeta); - - while (n < slots.length) - inventory.setItem(slots[n++], glass); - inventory.setItem(27, page > 1 ? previous : null); - inventory.setItem(35, appliable.size() > max ? next : null); + while (slotc < SLOTS.length) inventory.setItem(SLOTS[slotc++], NO_COMPONENT.get()); + inventory.setItem(6, topmost != null ? BACK.get() : null); + inventory.setItem(27, page > 1 ? PREVIOUS_PAGE.get() : null); + inventory.setItem(35, entries.size() > max ? NEXT_PAGE.get() : null); } + private static Lazy + PREVIOUS_PAGE = Lazy.of(() -> ItemFactory.of(Material.ARROW).name("&aPrevious Page").build()), + NEXT_PAGE = Lazy.of(() -> ItemFactory.of(Material.ARROW).name("&aNext Page").build()), + BACK = Lazy.of(() -> ItemFactory.of(Material.BARRIER).name("&aBack").build()), + NO_COMPONENT = Lazy.of(() -> ItemFactory.of(Material.GRAY_STAINED_GLASS_PANE).name("&c- No Item Stat").build()); + + /* + private String pathSoFar() { + StringBuilder s = new StringBuilder(); + for (TypedComponent comp : this.explored) { + if (!s.isEmpty()) s.append("."); + s.append(comp.path); + } + return s.toString(); + } + */ + @Override public void whenClicked(InventoryClickEvent event) { event.setCancelled(true); - if (event.getInventory() != event.getClickedInventory()) - return; + if (event.getInventory() != event.getClickedInventory()) return; ItemStack item = event.getCurrentItem(); - if (!MMOUtils.isMetaItem(item, false) || event.getInventory().getItem(4) == null) - return; + if (!MMOUtils.isMetaItem(item, false) || event.getInventory().getItem(4) == null) return; if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) { page++; @@ -111,9 +181,25 @@ public class ItemEdition extends EditionInventory { refreshInventory(); } - final String tag = item.getItemMeta().getPersistentDataContainer().get(STAT_ID_KEY, PersistentDataType.STRING); - if (tag == null || tag.isEmpty()) return; + if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Back")) { + explored.pop(); + refreshInventory(); + } + // Check tag + final String tag = item.getItemMeta().getPersistentDataContainer().get(COMPONENT_KEY, PersistentDataType.STRING); + if (tag == null) return; + + // Explore stat + if (explored.isEmpty()) { + ItemStat stat = Objects.requireNonNull(MMOItems.plugin.getStats().get(tag.toUpperCase()), "No stat found with ID '" + tag + "'"); + @Nullable Model model = sampleItem.get(stat); + //Validate.notNull(component, "Component is null"); // TODO exception handling + explored.push(new Entry(stat.getId().toLowerCase(), null, stat.getComponentType(), model)); + refreshInventory(); + } + + /* // Check for OP stats final ItemStat edited = MMOItems.plugin.getStats().get(tag); if (MMOItems.plugin.hasPermissions() && MMOItems.plugin.getLanguage().opStatsEnabled @@ -123,7 +209,9 @@ public class ItemEdition extends EditionInventory { return; } + edited.whenClicked(this, event); + */ } @Deprecated diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/newedit/ItemFactory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/newedit/ItemFactory.java new file mode 100644 index 00000000..5e084a71 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/newedit/ItemFactory.java @@ -0,0 +1,59 @@ +package net.Indyuce.mmoitems.gui.edition.newedit; + +import io.lumine.mythic.lib.MythicLib; +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Arrays; +import java.util.List; + +public class ItemFactory { + private ItemStack item; + private ItemMeta meta; + + /** + * @see #of(Material) + */ + private ItemFactory() { + // Private constructor + } + + public ItemFactory material(Material material) { + this.item = new ItemStack(material); + this.meta = item.getItemMeta(); + return this; + } + + private void validateMaterial() { + Validate.notNull(meta, "No material or invalid material"); + } + + public ItemFactory name(String name) { + validateMaterial(); + meta.setDisplayName(MythicLib.plugin.parseColors(name)); + return this; + } + + public ItemFactory lore(String... lore) { + return lore(Arrays.asList(lore)); + } + + public ItemFactory lore(List lore) { + validateMaterial(); + meta.setLore(lore); + return this; + } + + + public ItemStack build() { + validateMaterial(); + item.setItemMeta(meta); + return item; + } + + public static ItemFactory of(Material mat) { + return new ItemFactory().material(mat); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java index fefd5cd1..8c8ce0f7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java @@ -19,6 +19,7 @@ import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +// TODO implement navigators public class GuiListener implements Listener { @EventHandler diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java index a14ab5e6..e6c52471 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java @@ -9,7 +9,12 @@ import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.StatCategories; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.stat.Elements; import net.Indyuce.mmoitems.stat.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import net.Indyuce.mmoitems.stat.category.StatCategory; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.legacy.LegacyConfigAdapter; @@ -103,6 +108,8 @@ public class StatManager { // Register elemental stats registerElementStats(); + Elements.updateComponentType(); + // Load stat translation objects (nothing to do with stats) final ConfigurationSection statOptions = new ConfigFile("/language", "stats").getConfig(); for (ItemStat stat : getAll()) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java index 33d69711..aaa3b11f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java @@ -17,6 +17,9 @@ import net.Indyuce.mmoitems.gui.edition.AbilityListEdition; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.skill.RegisteredSkill; import net.Indyuce.mmoitems.stat.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.component.builtin.AbilityComponent; +import net.Indyuce.mmoitems.stat.component.type.builtin.ArrayComponentType; +import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.Indyuce.mmoitems.stat.data.AbilityListData; import net.Indyuce.mmoitems.stat.data.random.RandomAbilityData; @@ -37,10 +40,22 @@ import java.util.Optional; @HasCategory(cat = "abilities") public class Abilities extends ItemStat { public Abilities() { - super("ABILITY", Material.BLAZE_POWDER, "Item Abilities", - new String[]{"Make your item cast amazing abilities", "to kill monsters or buff yourself."}, new String[]{"!block", "all"}); - } + super("ABILITY", new String[]{"!block", "all"}); +/* + ObjectComponentType abilityType = ObjectComponentType.object() + .addField("ability", AbilityComponent.type().build()) + .addField("modifiers", ObjectComponentType.object().build()) + .setFlattened(true) + .build(); + setComponentType(ArrayComponentType.arrayOf(abilityType) + .setActionLoreTags("Left click to edit abilities.", "Right click to remove all abilities.") + .setIcon(Material.FIRE_CHARGE) + .setName("Abilities") + .setLoreTrimmed("Make your item cast amazing abilities to kill monsters or buff yourself. Abilities can be actively cast, set on a timer or triggered by specific world events. Custom abilities can be created using MythicLib, MythicMobs, Fabled...") + .build()); + */ + } @Override public RandomAbilityListData whenInitialized(Object object) { Validate.isTrue(object instanceof ConfigurationSection, "Must specify a valid config section"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java index 62c585ba..ac6d4589 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java @@ -8,8 +8,8 @@ import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; import net.Indyuce.mmoitems.stat.type.ChooseStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.util.StatChoice; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/AttackDamage.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/AttackDamage.java index a546d37b..331210ca 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/AttackDamage.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/AttackDamage.java @@ -1,6 +1,7 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType; import net.Indyuce.mmoitems.stat.type.AttackWeaponStat; import org.bukkit.Material; import org.bukkit.attribute.Attribute; @@ -13,5 +14,12 @@ public class AttackDamage extends AttackWeaponStat { "Attack Damage", new String[]{"The amount of damage your weapon deals."}, Attribute.GENERIC_ATTACK_DAMAGE); + + setComponentType(DoubleComponentType.numeric() + .moreIsBetter(true) + .setIcon(Material.IRON_SWORD) + .setName("Attack Damage") + .trimLore("The amount of damage dealt by melee or ranged weapon attacks.") + .build()); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java index 6f134084..f29e6555 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java @@ -20,7 +20,7 @@ import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.type.BooleanStat; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import io.lumine.mythic.lib.api.item.NBTItem; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java index 33c05041..567e1728 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java @@ -18,7 +18,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.ParticleData; import net.Indyuce.mmoitems.stat.data.SkullTextureData; import net.Indyuce.mmoitems.stat.type.BooleanStat; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java index bfe3a963..cf621bc3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java @@ -16,7 +16,7 @@ import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.type.BooleanStat; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import io.lumine.mythic.lib.api.item.NBTItem; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java index a41f25f7..1912aaf3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java @@ -14,7 +14,7 @@ import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.data.GemSocketsData; import net.Indyuce.mmoitems.stat.data.GemstoneData; import net.Indyuce.mmoitems.stat.type.BooleanStat; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.util.Pair; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CraftingPermission.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CraftingPermission.java index 6d27a159..7b9b82e8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CraftingPermission.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CraftingPermission.java @@ -1,8 +1,7 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.annotation.HasCategory; -import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import net.Indyuce.mmoitems.stat.type.TemplateOption; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomDurability.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomDurability.java index 76a86be5..fae3c6c7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomDurability.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomDurability.java @@ -4,9 +4,8 @@ import io.lumine.mythic.lib.api.item.ItemTag; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; -import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.InternalStat; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomModelData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomModelData.java index f14ff8f2..0f793653 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomModelData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomModelData.java @@ -6,10 +6,9 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import io.lumine.mythic.lib.api.item.ItemTag; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java index eff088b8..3eb877c5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java @@ -16,9 +16,9 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.SoundsEdition; import net.Indyuce.mmoitems.stat.data.SoundData; import net.Indyuce.mmoitems.stat.data.SoundListData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.ItemStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayName.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayName.java index 0f7229df..f3e27550 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayName.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayName.java @@ -10,7 +10,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.NameData; import net.Indyuce.mmoitems.stat.type.StatHistory; import net.Indyuce.mmoitems.stat.type.StringStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayedType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayedType.java index bd2085af..d4cc5541 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayedType.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayedType.java @@ -1,7 +1,7 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.annotation.HasCategory; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java index ad198a64..46972264 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DyeColor.java @@ -9,6 +9,7 @@ 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.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType; import net.Indyuce.mmoitems.stat.data.ColorData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; @@ -29,128 +30,135 @@ import java.util.Optional; @HasCategory(cat = "item") public class DyeColor extends ItemStat { - public DyeColor() { - super("DYE_COLOR", Material.RED_DYE, "Dye Color", - new String[] { "The color of your item", "(for dyeable items).", "In RGB." }, new String[0], Material.LEATHER_HELMET, - Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.LEATHER_HORSE_ARMOR); - } + public DyeColor() { + super("DYE_COLOR", + null, Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.LEATHER_HORSE_ARMOR); - @Override - public ColorData whenInitialized(Object object) { - Validate.isTrue(object instanceof String, "Must specify a string"); - return new ColorData((String) object); - } + setComponentType(ObjectComponentType.color() + .setIcon(Material.RED_DYE) + .setName("Dye Color") + .trimLore("Sets the dye color of leather player armor and leather horse armor, in RGB (red, green, blue) format.") + .build()); + } - @Override - public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { - if (event.getAction() == InventoryAction.PICKUP_ALL) - new StatEdition(inv, ItemStats.DYE_COLOR).enable("Write in the chat the RGB color you want.", - ChatColor.AQUA + "Format: {Red} {Green} {Blue}"); + @Override + public ColorData whenInitialized(Object object) { + Validate.isTrue(object instanceof String, "Must specify a string"); + return new ColorData((String) object); + } - if (event.getAction() == InventoryAction.PICKUP_HALF) { - inv.getEditedSection().set("dye-color", null); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed Dye Color."); - } - } + @Override + public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { + if (event.getAction() == InventoryAction.PICKUP_ALL) + new StatEdition(inv, ItemStats.DYE_COLOR).enable("Write in the chat the RGB color you want.", + ChatColor.AQUA + "Format: {Red} {Green} {Blue}"); - @Override - public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { - String[] split = message.split(" "); - Validate.isTrue(split.length == 3, "Use this format: {Red} {Green} {Blue}."); - for (String str : split) { - int k = Integer.parseInt(str); - Validate.isTrue(k >= 0 && k < 256, "Color must be between 0 and 255"); - } + if (event.getAction() == InventoryAction.PICKUP_HALF) { + inv.getEditedSection().set("dye-color", null); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed Dye Color."); + } + } - inv.getEditedSection().set("dye-color", message); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Dye Color successfully changed to " + message + "."); - } + @Override + public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { + String[] split = message.split(" "); + Validate.isTrue(split.length == 3, "Use this format: {Red} {Green} {Blue}."); + for (String str : split) { + int k = Integer.parseInt(str); + Validate.isTrue(k >= 0 && k < 256, "Color must be between 0 and 255"); + } - @Override - 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."); - } + inv.getEditedSection().set("dye-color", message); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Dye Color successfully changed to " + message + "."); + } - @NotNull - @Override - public ColorData getClearStatData() { - return new ColorData(0, 0, 0); - } + @Override + 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."); + } - @Override - public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + @NotNull + @Override + public ColorData getClearStatData() { + return new ColorData(0, 0, 0); + } - // Actually ignore the NBT item altogether, we're looking at its colour this time - ItemMeta iMeta = mmoitem.getNBT().getItem().getItemMeta(); + @Override + public void whenLoaded(@NotNull ReadMMOItem mmoitem) { - if (iMeta instanceof LeatherArmorMeta) { + // Actually ignore the NBT item altogether, we're looking at its colour this time + ItemMeta iMeta = mmoitem.getNBT().getItem().getItemMeta(); - // Make a tag with thay colour property - ArrayList relevantTags = new ArrayList<>(); + if (iMeta instanceof LeatherArmorMeta) { - // Kreate and Add - relevantTags.add(new ItemTag(getNBTPath(), ((LeatherArmorMeta) iMeta).getColor())); + // Make a tag with thay colour property + ArrayList relevantTags = new ArrayList<>(); - // Cook - StatData data = getLoadedNBT(relevantTags); + // Kreate and Add + relevantTags.add(new ItemTag(getNBTPath(), ((LeatherArmorMeta) iMeta).getColor())); - // Put if nonull - if (data != null) { mmoitem.setData(this, data); } - } - } + // Cook + StatData data = getLoadedNBT(relevantTags); - /** - * For this specific stat, the NBT is not saved as a custom item, but as the color itself of the dyed item. - *

- * Just pass into here a unique ItemTag of path {@link #getNBTPath()} and of value {@link org.bukkit.Color}, - * which is unique because - */ - @Nullable - @Override - public ColorData getLoadedNBT(@NotNull ArrayList storedTags) { + // Put if nonull + if (data != null) { + mmoitem.setData(this, data); + } + } + } - // Find tag - ItemTag dyedColour = ItemTag.getTagAtPath(getNBTPath(), storedTags); + /** + * For this specific stat, the NBT is not saved as a custom item, but as the color itself of the dyed item. + *

+ * Just pass into here a unique ItemTag of path {@link #getNBTPath()} and of value {@link org.bukkit.Color}, + * which is unique because + */ + @Nullable + @Override + public ColorData getLoadedNBT(@NotNull ArrayList storedTags) { - // Found? - if (dyedColour != null) { + // Find tag + ItemTag dyedColour = ItemTag.getTagAtPath(getNBTPath(), storedTags); - // Get that colour - Color c = (Color) dyedColour.getValue(); + // Found? + if (dyedColour != null) { - // Make and return thay colour data - return new ColorData(c); - } + // Get that colour + Color c = (Color) dyedColour.getValue(); - return null; - } + // Make and return thay colour data + return new ColorData(c); + } - @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull ColorData data) { + return null; + } - // Only does anything if it is a colourable meta - if (item.getMeta() instanceof LeatherArmorMeta) { + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull ColorData data) { - // Just set the colour - ((LeatherArmorMeta) item.getMeta()).setColor(((ColorData) data).getColor()); - } - } + // Only does anything if it is a colourable meta + if (item.getMeta() instanceof LeatherArmorMeta) { - /** - * For this specific stat, the StatData is not saved as a custom NBT tag, but as the color itself of the dyed item. - *

- * Alas, this array will be empty. Check the colour of the item as a {@link LeatherArmorMeta} to read the value. - */ - @NotNull - @Override - public ArrayList getAppliedNBT(@NotNull ColorData data) { + // Just set the colour + ((LeatherArmorMeta) item.getMeta()).setColor(((ColorData) data).getColor()); + } + } - // No tags are added - return new ArrayList<>(); - } + /** + * For this specific stat, the StatData is not saved as a custom NBT tag, but as the color itself of the dyed item. + *

+ * Alas, this array will be empty. Check the colour of the item as a {@link LeatherArmorMeta} to read the value. + */ + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull ColorData data) { + + // No tags are added + return new ArrayList<>(); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java index a204e1c3..0043459b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java @@ -23,7 +23,7 @@ import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectData; import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectListData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; 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 ed4c6c5a..ec01f458 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 @@ -1,5 +1,6 @@ package net.Indyuce.mmoitems.stat; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; @@ -12,6 +13,8 @@ import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.ElementsEdition; import net.Indyuce.mmoitems.stat.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType; +import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType; import net.Indyuce.mmoitems.stat.data.ElementListData; import net.Indyuce.mmoitems.stat.data.random.RandomElementListData; import net.Indyuce.mmoitems.stat.data.type.StatData; @@ -34,10 +37,31 @@ import java.util.*; @HasCategory(cat = "elements") public class Elements extends ItemStat implements Previewable { public Elements() { - super("ELEMENT", Material.SLIME_BALL, "Elements", new String[]{"The elements of your item."}, + super("ELEMENT", new String[]{"equipment", "ornament", "gem_stone"}); } + @Deprecated + public static void updateComponentType() { + + ItemStat stat = MMOItems.plugin.getStats().get("ELEMENT"); + + + ObjectComponentType.Builder builder = ObjectComponentType.object(); + for (Element element : MythicLib.plugin.getElements().getAll()) + for (ElementStatType statType : ElementStatType.values()) + builder.addField(statType.getConcatenatedTagPath(element).toLowerCase(), DoubleComponentType.numeric() + .setIcon(element.getIcon()) + .setName(element.getName() + " " + statType.getName()) + .build()); + stat.setComponentType(builder + .setIcon(Material.MAGMA_CREAM) + .setName("Elemental Stats") + .trimLore("Have the weapon deal on-hit elemental damage, reduce or increase incoming elemental damage.") + .setActionLoreTags("Click to edit elemental stats.", "Right click to reset elements") + .build()); + } + @Override public RandomElementListData whenInitialized(Object object) { Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemColor.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemColor.java index 8eb571e4..05a31acc 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemColor.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemColor.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.ItemTag; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemUpgradeScaling.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemUpgradeScaling.java index bb41231e..4d4c3555 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemUpgradeScaling.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GemUpgradeScaling.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; import net.Indyuce.mmoitems.stat.type.ChooseStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.util.StatChoice; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java index 2c0f045d..662009a6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/GrantedPermissions.java @@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringListData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringListStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemDamage.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemDamage.java index 3a759781..efd88631 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemDamage.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemDamage.java @@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import org.bukkit.Material; import org.bukkit.inventory.meta.Damageable; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemLevel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemLevel.java index 4ba765c6..d3b4525d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemLevel.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemLevel.java @@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.InternalStat; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.NotImplementedException; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java index f56b29c4..e9827441 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java @@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTierStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTierStat.java index bb8b051e..3231e3e4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTierStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTierStat.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import org.apache.commons.lang.Validate; import org.bukkit.Material; @@ -10,7 +10,6 @@ import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.gui.edition.EditionInventory; -import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.StringStat; import io.lumine.mythic.lib.api.item.ItemTag; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Lore.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Lore.java index 95edd7c7..466df8c7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Lore.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Lore.java @@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringListData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringListStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LoreFormat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LoreFormat.java index 13c3d821..80b8d003 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LoreFormat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LoreFormat.java @@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.apache.commons.lang.Validate; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackEffectStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackEffectStat.java index 674bc5fb..2c5dfff6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackEffectStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackEffectStat.java @@ -10,7 +10,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryAction; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackSoundStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackSoundStat.java index 077c5b10..3b828f2a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackSoundStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/LuteAttackSoundStat.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.ItemTag; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java index befe2432..729959a4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java @@ -9,8 +9,8 @@ import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java index 67fe26a7..70417e83 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java @@ -12,6 +12,7 @@ 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.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.component.builtin.MaterialComponent; import net.Indyuce.mmoitems.stat.data.MaterialData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.md_5.bungee.api.ChatColor; @@ -32,6 +33,12 @@ import java.util.Optional; public class MaterialStat extends ItemStat { public MaterialStat() { super("MATERIAL", VMaterial.GRASS_BLOCK.get(), "Material", new String[] { "Your item material." }, new String[0]); + + setComponentType(MaterialComponent.Type.init() + .setIcon(org.bukkit.Material.GRASS_BLOCK) + .setName("Item Material") + .trimLore("The material of your item. This option determines quite a lot of properties of your item, like durability, interactions with blocks etc. Therefore, you should use a material that makes sense with your item use case.") + .build()); } @Override diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxItemDamage.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxItemDamage.java index 7464c407..5f1236b4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxItemDamage.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxItemDamage.java @@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.annotation.VersionDependant; import org.apache.commons.lang.Validate; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxStackSize.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxStackSize.java index 056f55eb..8abb42a7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxStackSize.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaxStackSize.java @@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.annotation.VersionDependant; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaximumDurability.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaximumDurability.java index 4df688bb..e62d0dbc 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaximumDurability.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaximumDurability.java @@ -12,8 +12,8 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.MaterialData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.type.Upgradable; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Permission.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Permission.java index 4b7b0d56..dad40c08 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Permission.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Permission.java @@ -14,7 +14,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringListData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.type.StringListStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java index f3ceb4b2..35fbaa78 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionColor.java @@ -9,6 +9,7 @@ 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.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType; import net.Indyuce.mmoitems.stat.data.ColorData; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.NotImplementedException; @@ -28,87 +29,93 @@ import java.util.Optional; @HasCategory(cat = "item") public class PotionColor extends ItemStat { - public PotionColor() { - super("POTION_COLOR", Material.POTION, "Potion Color", - new String[] { "The color of your potion.", "(Doesn't impact the effects)." }, new String[0], Material.POTION, - Material.SPLASH_POTION, Material.LINGERING_POTION, Material.TIPPED_ARROW); - } + public PotionColor() { + super("POTION_COLOR", + new String[0], + Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.TIPPED_ARROW); - @Override - public ColorData whenInitialized(Object object) { - Validate.isTrue(object instanceof String, "Must specify a string"); - return new ColorData((String) object); - } + setComponentType(ObjectComponentType.color() + .setName("Potion Color") + .setIcon(Material.POTION) + .trimLore("The potion of your color. It is purely a cosmetic option and has no effect whatsoever on the potion effects.") + .build()); + } - @Override - public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { - if (event.getAction() == InventoryAction.PICKUP_ALL) - new StatEdition(inv, ItemStats.POTION_COLOR).enable("Write in the chat the RGB color you want.", - ChatColor.AQUA + "Format: {Red} {Green} {Blue}"); + @Override + public ColorData whenInitialized(Object object) { + Validate.isTrue(object instanceof String, "Must specify a string"); + return new ColorData((String) object); + } - if (event.getAction() == InventoryAction.PICKUP_HALF) { - inv.getEditedSection().set("potion-color", null); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed Potion Color."); - } - } + @Override + public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { + if (event.getAction() == InventoryAction.PICKUP_ALL) + new StatEdition(inv, ItemStats.POTION_COLOR).enable("Write in the chat the RGB color you want.", + ChatColor.AQUA + "Format: {Red} {Green} {Blue}"); - @Override - public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { - String[] split = message.split(" "); - Validate.isTrue(split.length == 3, "Use this format: {Red} {Green} {Blue}. Example: '75 0 130' stands for Purple."); + if (event.getAction() == InventoryAction.PICKUP_HALF) { + inv.getEditedSection().set("potion-color", null); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed Potion Color."); + } + } - for (String str : split) { - int k = Integer.parseInt(str); - Validate.isTrue(k >= 0 && k < 256, "Color must be between 0 and 255"); - } + @Override + public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { + String[] split = message.split(" "); + Validate.isTrue(split.length == 3, "Use this format: {Red} {Green} {Blue}. Example: '75 0 130' stands for Purple."); - inv.getEditedSection().set("potion-color", message); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Potion Color successfully changed to " + message + "."); - } + for (String str : split) { + int k = Integer.parseInt(str); + Validate.isTrue(k >= 0 && k < 256, "Color must be between 0 and 255"); + } - @Override - public void whenLoaded(@NotNull ReadMMOItem mmoitem) { - if (!(mmoitem.getNBT().getItem().getItemMeta() instanceof PotionMeta)) - return; + inv.getEditedSection().set("potion-color", message); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Potion Color successfully changed to " + message + "."); + } - final Color color = ((PotionMeta) mmoitem.getNBT().getItem().getItemMeta()).getColor(); - if (color != null) - mmoitem.setData(this, new ColorData(color)); - } + @Override + public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + if (!(mmoitem.getNBT().getItem().getItemMeta() instanceof PotionMeta)) + return; - @Nullable - @Override - public ColorData getLoadedNBT(@NotNull ArrayList storedTags) { - throw new NotImplementedException(); - } + final Color color = ((PotionMeta) mmoitem.getNBT().getItem().getItemMeta()).getColor(); + if (color != null) + mmoitem.setData(this, new ColorData(color)); + } - @Override - public void whenDisplayed(List lore, Optional statData) { + @Nullable + @Override + public ColorData getLoadedNBT(@NotNull ArrayList storedTags) { + throw new NotImplementedException(); + } - lore.add(statData.isPresent() ? ChatColor.GREEN + statData.get().toString() : ChatColor.RED + "Uncolored"); + @Override + public void whenDisplayed(List lore, Optional statData) { - lore.add(""); - lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); - lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the potion color."); - } + lore.add(statData.isPresent() ? ChatColor.GREEN + statData.get().toString() : ChatColor.RED + "Uncolored"); - @NotNull - @Override - public ColorData getClearStatData() { - return new ColorData(0,0,0); - } + lore.add(""); + lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); + lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the potion color."); + } - @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull ColorData data) { - if (item.getItemStack().getType().name().contains("POTION") || item.getItemStack().getType() == Material.TIPPED_ARROW) - ((PotionMeta) item.getMeta()).setColor(data.getColor()); - } + @NotNull + @Override + public ColorData getClearStatData() { + return new ColorData(0, 0, 0); + } - @NotNull - @Override - public ArrayList getAppliedNBT(@NotNull ColorData data) { - throw new NotImplementedException(); - } + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull ColorData data) { + if (item.getItemStack().getType().name().contains("POTION") || item.getItemStack().getType() == Material.TIPPED_ARROW) + ((PotionMeta) item.getMeta()).setColor(data.getColor()); + } + + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull ColorData data) { + throw new NotImplementedException(); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java index e925a31a..76baf2d0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java @@ -16,9 +16,8 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.GemSocketsData; import net.Indyuce.mmoitems.stat.data.GemstoneData; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.StatHistory; import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.util.Pair; import org.bukkit.Bukkit; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java index e791c401..fdeb1ea8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java @@ -10,7 +10,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.listener.CustomSoundListener; import net.Indyuce.mmoitems.stat.annotation.HasCategory; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.util.RepairUtils; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java index 792925a8..6ab65bcd 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java @@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.stat.annotation.HasCategory; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java index 0031aa55..f6c299df 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java @@ -1,7 +1,7 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.annotation.HasCategory; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredBiomes.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredBiomes.java index fce3aebd..a7ed541d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredBiomes.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredBiomes.java @@ -3,13 +3,11 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; -import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringListData; -import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.type.StringListStat; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java index c75e0376..4d7d5ef6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredClass.java @@ -14,8 +14,8 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringListData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.type.StringListStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java index a455cd58..331d859d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java @@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java index a896e737..de02df17 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java @@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreMana.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreMana.java index 4b34941a..dc9a0f15 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreMana.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreMana.java @@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.bukkit.Material; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java index 441fb095..b860748f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java @@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreStamina.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreStamina.java index ac92ec2c..dac70f4d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreStamina.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreStamina.java @@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable; import org.bukkit.Material; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java index 5665a96c..e7b7a1b1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RevisionID.java @@ -11,7 +11,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.RevisionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.DoubleData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java index 5a2264c3..aa6918cc 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java @@ -12,7 +12,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.SoulboundData; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Bukkit; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java index 2e53d1f3..b897f87c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java @@ -12,7 +12,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.SoulboundData; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Bukkit; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java index ee934d71..6b5f517e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java @@ -16,8 +16,8 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.SoulboundData; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.InternalStat; -import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.NotImplementedException; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StoredTags.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StoredTags.java index 0fb9409b..3454a0cd 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StoredTags.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/StoredTags.java @@ -8,8 +8,8 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StoredTagsData; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; -import net.Indyuce.mmoitems.stat.type.InternalStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.NotImplementedException; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SuccessRate.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SuccessRate.java index f56ad94e..1d0f9a7e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SuccessRate.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SuccessRate.java @@ -4,7 +4,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import org.bukkit.Material; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; @HasCategory(cat = "gem_stones") public class SuccessRate extends DoubleStat implements GemStoneStat { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TooltipStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TooltipStat.java index 3dd26c88..1eee917d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TooltipStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TooltipStat.java @@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.tooltip.TooltipTexture; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; import org.apache.commons.lang.Validate; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimMaterialStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimMaterialStat.java index 8d999e5a..62a6e25f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimMaterialStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimMaterialStat.java @@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; import net.Indyuce.mmoitems.stat.type.ChooseStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.util.StatChoice; import net.Indyuce.mmoitems.stat.annotation.VersionDependant; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimPatternStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimPatternStat.java index 1e478d3f..a25be758 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimPatternStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/TrimPatternStat.java @@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.StringData; import net.Indyuce.mmoitems.stat.type.ChooseStat; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.util.StatChoice; import net.Indyuce.mmoitems.stat.annotation.VersionDependant; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java index 44ce7f81..3703a624 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java @@ -23,7 +23,7 @@ import net.Indyuce.mmoitems.gui.edition.UpgradingEdition; import net.Indyuce.mmoitems.stat.annotation.HasCategory; import net.Indyuce.mmoitems.stat.data.UpgradeData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.Validate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/annotation/TerminalComponentException.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/annotation/TerminalComponentException.java new file mode 100644 index 00000000..1222555f --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/annotation/TerminalComponentException.java @@ -0,0 +1,8 @@ +package net.Indyuce.mmoitems.stat.annotation; + +public class TerminalComponentException extends RuntimeException { + + public TerminalComponentException() { + super("Terminal component type"); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ConsumableItemInteraction.java similarity index 96% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ConsumableItemInteraction.java index 4b58e000..a9ea4da4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ConsumableItemInteraction.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmoitems.stat.type; +package net.Indyuce.mmoitems.stat.behaviour; import org.bukkit.event.inventory.InventoryClickEvent; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/GemStoneStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/GemStoneStat.java similarity index 73% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/GemStoneStat.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/GemStoneStat.java index b6b15fb2..3cbcd3c9 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/GemStoneStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/GemStoneStat.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmoitems.stat.type; +package net.Indyuce.mmoitems.stat.behaviour; /** * Statistics which must NOT be applied onto an item when socketing the gem @@ -7,4 +7,5 @@ package net.Indyuce.mmoitems.stat.type; * * @author indyuce */ -public interface GemStoneStat { } +public interface GemStoneStat { +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/InternalStat.java similarity index 89% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/InternalStat.java index 7c7b6361..6fc5c8ba 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/InternalStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/InternalStat.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmoitems.stat.type; +package net.Indyuce.mmoitems.stat.behaviour; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ItemRestriction.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ItemRestriction.java new file mode 100644 index 00000000..dfbc2dfc --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/ItemRestriction.java @@ -0,0 +1,39 @@ +package net.Indyuce.mmoitems.stat.behaviour; + +import net.Indyuce.mmoitems.api.player.RPGPlayer; +import io.lumine.mythic.lib.api.item.NBTItem; + +/** + * Stats which implement an item restriction. They are automatically collected + * in a list when registered in the StatManager. Lets other plugins implement + * stats which rely on item restrictions without having to use Bukkit events! + * + * @author cympe + */ +public interface ItemRestriction { + + /** + * @param player Player trying to use an item + * @param item The item being checked + * @param message Difference between an active and a passive check: if the + * check is active (message boolean set to true), the plugin + * should send a message to the player if he can't use the + * item for eg when he tries to equip the item. If the check + * is passive, no message needs to be sent (when the plugin + * internally needs some similar check) + * @return False if the item cannot be used + */ + boolean canUse(RPGPlayer player, NBTItem item, boolean message); + + /** + * Usually, item restrictions are checked when equipping + * an item, and prevent the item being equipped if they fail that moment. + *

+ * Setting this to true will allow items equip anyway + * and check with every use that the conditions for their usage + * are met. + */ + default boolean isDynamic() { + return false; + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/PlayerConsumable.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/PlayerConsumable.java similarity index 68% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/PlayerConsumable.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/PlayerConsumable.java index f8619a24..a8966fc6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/PlayerConsumable.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/behaviour/PlayerConsumable.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmoitems.stat.type; +package net.Indyuce.mmoitems.stat.behaviour; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import org.bukkit.entity.Player; @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; *
* Any food is a self consumable, since you eat them to * restore hunger or health or whatever, while upgrading - * consumables are not self consumables, as the are used + * consumables are not self consumables, as they are used * on other items and cannot be consumed by themselves. * * @author Gunging @@ -21,9 +21,9 @@ public interface PlayerConsumable { * Called when the item is being consumed directly by a player. * * @since 6.7 You need to specify if the item is being eaten the vanilla - * way or not. This is used to fix an issue where when eating through the - * vanilla eating animation, the default food and saturation modifier is - * applied so MMOItems needs to apply some offset to food/saturation. + * way or not. This is used to fix an issue where when eating through the + * vanilla eating animation, the default food and saturation modifier is + * applied so MMOItems needs to apply some offset to food/saturation. */ void onConsume(@NotNull VolatileMMOItem mmo, @NotNull Player player, boolean vanillaEating); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/DoubleComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/DoubleComponent.java deleted file mode 100644 index e7a7c8e1..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/DoubleComponent.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.Indyuce.mmoitems.stat.component; - - -public class DoubleComponent extends StatComponent implements Mergeable { - private double value; - - public DoubleComponent() { - } - - @Override - public void merge(DoubleComponent component) { - value += component.value; - } -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/IntegerComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/IntegerComponent.java deleted file mode 100644 index 2a9b8fca..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/IntegerComponent.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.Indyuce.mmoitems.stat.component; - - -public class IntegerComponent extends StatComponent implements Mergeable { - private int value; - - public IntegerComponent() { - } - - @Override - public void merge(IntegerComponent component) { - value += component.value; - } -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/LoreWrapper.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/LoreWrapper.java new file mode 100644 index 00000000..9c269bbb --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/LoreWrapper.java @@ -0,0 +1,27 @@ +package net.Indyuce.mmoitems.stat.component; + +import org.bukkit.ChatColor; + +import java.util.List; + +public class LoreWrapper { + private final List lore; + private final String prefix = String.valueOf(ChatColor.GRAY); + + public LoreWrapper(List lore) { + this.lore = lore; + } + + @Deprecated + public void addLines(String... lines) { + for (String line : lines) addLine(line); + } + + public void addLine(String line) { + lore.add(prefix + ChatColor.translateAlternateColorCodes('&', line)); + } + + public void addLines(Iterable lines) { + for (String line : lines) addLine(line); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java index dd002ad1..7b8b96df 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java @@ -1,8 +1,10 @@ package net.Indyuce.mmoitems.stat.component; import io.lumine.mythic.lib.util.annotation.NotUsed; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; -public interface Mergeable { +@NotUsed +public interface Mergeable, T extends StatComponent> { - public void merge(T t); + public void merge(C componentType, T t); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/ObjectComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/ObjectComponent.java deleted file mode 100644 index 24a1b8af..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/ObjectComponent.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.Indyuce.mmoitems.stat.component; - -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - -public class ObjectComponent extends StatComponent { - private final Map components = new HashMap<>(); - - public ObjectComponent() { - - } - - @Nullable - public StatComponent getComponent(String path) { - return components.get(path); - } - - public void forEachComponent(Consumer action) { - for (StatComponent component : components.values()) - action.accept(component); - } - - public Set getComponentKeys() { - return components.keySet(); - } - - /* - @Nullable - public StatComponent findComponent(String path) { - String[] split = path.split("\\."); - - ObjectComponent current = this; - int n = split.length - 1; - for (int i = 0; i < n; i++) { - StatComponent next = getComponent(split[i]); - if (next == null || !(next instanceof ObjectComponent)) - return null; - - current = (ObjectComponent) next; - } - - return current.getComponent(split[n]); - } - */ -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java index 10866488..5c40e358 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java @@ -1,5 +1,30 @@ package net.Indyuce.mmoitems.stat.component; +import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponent; +import org.apache.commons.lang.Validate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + public abstract class StatComponent { + @Nullable + public StatComponent get(@NotNull String key) { + throw new RuntimeException("No subcomponent for " + getClass().getSimpleName()); + } + + @Nullable + @Deprecated + public StatComponent findComponent(String path) { + String[] split = path.split("\\."); + + ObjectComponent current = (ObjectComponent) this; + int n = split.length - 1; + for (int i = 0; i < n; i++) { + StatComponent next = current.get(split[i]); + Validate.notNull(next, "Could not find component " + path); + current = (ObjectComponent) next; + } + + return current.get(split[n]); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/AbilityComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/AbilityComponent.java new file mode 100644 index 00000000..4c1b7e6a --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/AbilityComponent.java @@ -0,0 +1,61 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.skill.RegisteredSkill; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.apache.commons.lang.NotImplementedException; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class AbilityComponent extends StatComponent implements Model { + private RegisteredSkill ability; + + @NotNull + public RegisteredSkill getValue() { + return ability; + } + + @NotNull + public static Type.Builder type() { + return new Type().new Builder(); + } + + @Override + public AbilityComponent randomizeComponent(MMOItemBuilder builder) { + return this; + } + + public static class Type extends ComponentType { + + @NotNull + @Override + public List editionUiFormat(AbilityComponent data) { + return Collections.singletonList(data.getValue().getName()); + /* + List format = new ArrayList<>(1 + data.getComponentKeys().size()); + format.add("Ability: " + data.getAbility().getName()); + data.forEachModifier((key, comp) -> format.add(key + ": " + comp.getValue())); + return format; + */ + } + + @Override + public AbilityComponent initialize(@NotNull Object object) { + throw new NotImplementedException(); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTagHint("ability"); + } + + public Type build() { + return (Type) super.build(); + } + } + } +} \ No newline at end of file diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ArrayComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ArrayComponent.java new file mode 100644 index 00000000..9fb9351a --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ArrayComponent.java @@ -0,0 +1,28 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + +import net.Indyuce.mmoitems.stat.component.StatComponent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class ArrayComponent extends StatComponent { + private final List components = new ArrayList<>(); + + @Nullable + public C getComponent(int index) { + return components.get(index); + } + + public void forEachComponent(Consumer action) { + for (C component : components) + action.accept(component); + } + + @NotNull + public List getComponents() { + return components; + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/BooleanComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/BooleanComponent.java new file mode 100644 index 00000000..1fb227e0 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/BooleanComponent.java @@ -0,0 +1,37 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + + +import net.Indyuce.mmoitems.stat.component.Mergeable; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.type.builtin.BooleanComponentType; + +public class BooleanComponent extends StatComponent implements Mergeable { + private boolean value; + + public BooleanComponent(boolean value) { + this.value = value; + } + + public boolean getValue() { + return value; + } + + public void setValue(boolean value) { + this.value = value; + } + + @Override + public void merge(BooleanComponentType componentType, BooleanComponent component) { + switch (componentType.mergeMecanism) { + case OR: + value |= component.value; + break; + case AND: + value &= component.value; + break; + case XOR: + value ^= component.value; + break; + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/DoubleComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/DoubleComponent.java new file mode 100644 index 00000000..80eaa823 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/DoubleComponent.java @@ -0,0 +1,28 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + + +import net.Indyuce.mmoitems.stat.component.Mergeable; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType; + +public class DoubleComponent extends StatComponent implements Mergeable { + private double value; + + public DoubleComponent(double value) { + this.value = value; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } + + @Override + public void merge(DoubleComponentType componentType, DoubleComponent component) { + value += component.value; + // TODO merge mecanisms + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/IntegerComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/IntegerComponent.java new file mode 100644 index 00000000..a383f40c --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/IntegerComponent.java @@ -0,0 +1,33 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + + +import net.Indyuce.mmoitems.stat.component.Mergeable; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.type.builtin.IntegerComponentType; + +public class IntegerComponent extends StatComponent implements Mergeable { + private int value; + + public IntegerComponent(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + @Override + public void merge(IntegerComponentType componentType, IntegerComponent component) { + switch (componentType.mergeMecanism) { + case SUM: + value += component.value; + break; + case HIGHEST: + value = Math.max(value, component.value); + break; + case LOWEST: + value = Math.min(value, component.value); + break; + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ItemAbilityComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ItemAbilityComponent.java new file mode 100644 index 00000000..ba6e6fcf --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ItemAbilityComponent.java @@ -0,0 +1,225 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + +import io.lumine.mythic.lib.util.annotation.NotUsed; +import net.Indyuce.mmoitems.skill.RegisteredSkill; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; + +@NotUsed +@Deprecated +public class ItemAbilityComponent extends ObjectComponent { + private AbilityComponent ability; + private Map modifiers; + + /* + public NewAbilityData(@NotNull JsonObject object) { + super(MMOUtils.backwardsCompatibleTriggerType(object.get("CastMode").getAsString())); + + ability = MMOItems.plugin.getSkills().getSkill(object.get("Id").getAsString()); + + JsonObject modifiers = object.getAsJsonObject("Modifiers"); + modifiers.entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble())); + } + + public NewAbilityData(@NotNull ConfigurationSection config) { + super(MMOUtils.backwardsCompatibleTriggerType(UtilityMethods.enumName(Objects.requireNonNull(config.getString("mode"), "Ability is missing mode")))); + + Validate.isTrue(config.contains("type"), "Ability is missing type"); + + String abilityFormat = UtilityMethods.enumName(config.getString("type")); + Validate.isTrue(MMOItems.plugin.getSkills().hasSkill(abilityFormat), "Could not find ability called '" + abilityFormat + "'"); + ability = MMOItems.plugin.getSkills().getSkill(abilityFormat); + + for (String key : config.getKeys(false)) + if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getHandler().getModifiers().contains(key)) + modifiers.put(key, config.getDouble(key)); + } + + public NewAbilityData(RegisteredSkill ability, TriggerType triggerType) { + super(triggerType); + + this.ability = ability; + } + */ + + @NotNull + public RegisteredSkill getAbility() { + return ability.getValue(); + } + + @NotNull + public Set getModifiers() { + return modifiers.keySet(); + } + + public void forEachModifier(BiConsumer action) { + modifiers.forEach(action); + } + + public void setModifier(String modifier, double value) { + modifiers.put(modifier, new DoubleComponent(value)); + } + + public boolean hasModifier(String modifier) { + return modifiers.containsKey(modifier); + } + + @Override + public void set(@NotNull String key, @NotNull StatComponent component) { + + } + + @Nullable + @Override + public StatComponent get(@NotNull String key) { + return null; + } + + @Override + public void forEachComponent(@NotNull BiConsumer action) { + + } + + @NotNull + @Override + public Collection getComponentKeys() { + return Arrays.asList("ability", "modifiers"); + } + + + /* + @Override + public boolean getResult(SkillMetadata meta) { + + PlayerData playerData = PlayerData.get(meta.getCaster().getPlayer()); + RPGPlayer rpgPlayer = playerData.getRPG(); + Player player = meta.getCaster().getPlayer(); + + // Check for cooldown + if (meta.getCaster().getData().getCooldownMap().isOnCooldown(this)) { + CooldownInfo info = playerData.getMMOPlayerData().getCooldownMap().getInfo(this); + if (!getTrigger().isSilent()) { + StringBuilder progressBar = new StringBuilder(ChatColor.YELLOW + ""); + double progress = (double) (info.getInitialCooldown() - info.getRemaining()) / info.getInitialCooldown() * 10; + String barChar = MMOItems.plugin.getConfig().getString("cooldown-progress-bar-char"); + for (int j = 0; j < 10; j++) + progressBar.append(progress >= j ? ChatColor.GREEN : ChatColor.WHITE).append(barChar); + Message.SPELL_ON_COOLDOWN.format(ChatColor.RED, "#left#", MythicLib.plugin.getMMOConfig().decimal.format(info.getRemaining() / 1000d), "#progress#", progressBar.toString(), "#s#", (info.getRemaining() > 1999 ? "s" : "")).send(player); + } + return false; + } + + // Check for permission + if (MMOItems.plugin.getConfig().getBoolean("permissions.abilities") && !player.hasPermission("mmoitems.ability." + getHandler().getLowerCaseId()) && !player.hasPermission("mmoitems.bypass.ability")) + return false; + + // Check for mana cost + if (hasModifier("mana") && rpgPlayer.getMana() < meta.getParameter("mana")) { + Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(player); + return false; + } + + // Check for stamina cost + if (hasModifier("stamina") && rpgPlayer.getStamina() < meta.getParameter("stamina")) { + Message.NOT_ENOUGH_STAMINA.format(ChatColor.RED).send(player); + return false; + } + + return true; + } + + @Override + public void whenCast(SkillMetadata meta) { + PlayerData playerData = PlayerData.get(meta.getCaster().getPlayer()); + RPGPlayer rpgPlayer = playerData.getRPG(); + + // Apply mana cost + if (hasModifier("mana")) rpgPlayer.giveMana(-meta.getParameter("mana")); + + // Apply stamina cost + if (hasModifier("stamina")) rpgPlayer.giveStamina(-meta.getParameter("stamina")); + + // Apply cooldown + double cooldown = meta.getParameter("cooldown") * (1 - Math.min(.8, meta.getCaster().getStat("COOLDOWN_REDUCTION") / 100)); + if (cooldown > 0) meta.getCaster().getData().getCooldownMap().applyCooldown(this, cooldown); + } + + + @Override + public SkillHandler getHandler() { + return ability.getHandler(); + } + + @Override + public double getParameter(String path) { + return modifiers.getOrDefault(path, ability.getDefaultModifier(path)); + } + + + public JsonObject toJson() { + JsonObject object = new JsonObject(); + object.addProperty("Id", ability.getHandler().getId()); + object.addProperty("CastMode", getTrigger().name()); + + JsonObject modifiers = new JsonObject(); + this.modifiers.keySet().forEach(modifier -> modifiers.addProperty(modifier, getParameter(modifier))); + object.add("Modifiers", modifiers); + + return object; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AbilityDataImpl that = (AbilityDataImpl) o; + return ability.equals(that.ability) && getTrigger().equals(that.getTrigger()) && modifiers.equals(that.modifiers); + } + + @Override + public String toString() { + return "AbilityData{" + + "ability=" + ability + + ", modifiers=" + modifiers + + '}'; + } + + @Override + public int hashCode() { + return Objects.hash(ability, modifiers); + } + + @NotNull + public static Type.Builder type() { + return new Type().new Builder(); + } + + public static class Type extends ComponentType { + + @NotNull + @Override + public List editionUiFormat(ItemAbilityComponent data) { + List format = new ArrayList<>(1 + data.getComponentKeys().size()); + format.add("Ability: " + data.getAbility().getName()); + data.forEachModifier((key, comp) -> format.add(key + ": " + comp.getValue())); + return format; + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTagHint("ability"); + } + + public Type build() { + return (Type) super.build(); + } + } + }*/ +} \ No newline at end of file diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/MaterialComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/MaterialComponent.java new file mode 100644 index 00000000..6208b94d --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/MaterialComponent.java @@ -0,0 +1,68 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + + +import io.lumine.mythic.lib.UtilityMethods; +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.bukkit.Material; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; + +public class MaterialComponent extends StatComponent implements Model { + private Material mat; + + public MaterialComponent(@Nullable Material mat) { + this.mat = mat; + } + + public Material getMaterial() { + return mat; + } + + @Override + public MaterialComponent randomizeComponent(MMOItemBuilder builder) { + return this; + } + + /* + @Override + public void merge(MaterialComponent component) { + value += component.value; + } + */ + + public static class Type extends ComponentType { + + @NotNull + @Override + public List editionUiFormat(MaterialComponent data) { + return Collections.singletonList(data.getMaterial().name()); + } + + @Override + public MaterialComponent initialize(@NotNull Object object) { + return new MaterialComponent(Material.valueOf(UtilityMethods.enumName(object.toString()))); + } + + @NotNull + public static Builder init() { + return new Type().new Builder(); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTags("Left click to edit this material.", "Right click to remove this option."); + setTerminal(true); + } + + public Type build() { + return (Type) super.build(); + } + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponent.java new file mode 100644 index 00000000..f3cd21d1 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponent.java @@ -0,0 +1,38 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.function.BiConsumer; + +/** + * Allows both implementations of abstract objects for user-end + * fully customizable stat components, and builtin hard-coded + * implementations of components like abilities, elements for + * performance. + *

+ * Components for built-in stats like abilities or elements + * have specific implementations for performance to avoid the + * abstraction overhead. + */ +public abstract class ObjectComponent extends StatComponent implements Model { + + public abstract void set(@NotNull String key, @NotNull StatComponent component); + + @Nullable + public abstract StatComponent get(@NotNull String key); + + public abstract void forEachComponent(@NotNull BiConsumer action); + + @NotNull + public abstract Collection getComponentKeys(); + + @Override + public ObjectComponent randomizeComponent(MMOItemBuilder builder) { + return this; + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponentImpl.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponentImpl.java new file mode 100644 index 00000000..7792f578 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/ObjectComponentImpl.java @@ -0,0 +1,36 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + +import net.Indyuce.mmoitems.stat.component.StatComponent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; + +public class ObjectComponentImpl extends ObjectComponent { + private final Map components = new HashMap<>(); + + @Override + public void set(@NotNull String key, @NotNull StatComponent component) { + components.put(key, component); + } + + @Nullable + @Override + public StatComponent get(@NotNull String key) { + return components.get(key); + } + + @Override + public void forEachComponent(@NotNull BiConsumer action) { + components.forEach(action); + } + + @NotNull + @Override + public Set getComponentKeys() { + return components.keySet(); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/StringComponent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/StringComponent.java new file mode 100644 index 00000000..bba3cf63 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/builtin/StringComponent.java @@ -0,0 +1,32 @@ +package net.Indyuce.mmoitems.stat.component.builtin; + + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import org.jetbrains.annotations.Nullable; + +public class StringComponent extends StatComponent implements Model { + private String value; + + public StringComponent(@Nullable String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public StringComponent randomizeComponent(MMOItemBuilder builder) { + return this; + } + + /* + @Override + public void merge(StringComponent component) { + // By default, mere replacement, but can depend on options configured in the config section!! + value = component.value; + } + */ +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/Model.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/Model.java new file mode 100644 index 00000000..79b3600d --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/Model.java @@ -0,0 +1,23 @@ +package net.Indyuce.mmoitems.stat.component.model; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.annotation.TerminalComponentException; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface Model { + + /** + * @param builder The builder of the random item being generated + * @return A random stat data instance which will then be merged onto the + * base item template + */ + C randomizeComponent(MMOItemBuilder builder); + + // TODO change name + @Nullable + default Model getModel(@NotNull String key) { + throw new TerminalComponentException(); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ArrayModel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ArrayModel.java new file mode 100644 index 00000000..babfd24a --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ArrayModel.java @@ -0,0 +1,24 @@ +package net.Indyuce.mmoitems.stat.component.model.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.builtin.ArrayComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import org.apache.commons.lang.NotImplementedException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +// TODO merge with component? +public class ArrayModel implements Model> { + + @Override + public ArrayComponent randomizeComponent(MMOItemBuilder builder) { + throw new NotImplementedException(); + } + + @Nullable + @Override + public Model getModel(@NotNull String key) { + throw new NotImplementedException(); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/BooleanModel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/BooleanModel.java new file mode 100644 index 00000000..b73cde0d --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/BooleanModel.java @@ -0,0 +1,49 @@ +package net.Indyuce.mmoitems.stat.component.model.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.builtin.BooleanComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import org.apache.commons.lang.Validate; + +import java.util.Random; + +public class BooleanModel implements Model { + + private final double chance; + private final Boolean value; + // TODO add string expression + + private static final Random RANDOM = new Random(); + + public BooleanModel(Object object) { + + // Boolean value + if (object instanceof Boolean) { + this.value = (boolean) object; + this.chance = 0; + } + + // Flat nb + else if (object instanceof Number) { + this.value = null; + this.chance = Double.parseDouble(object.toString()); + Validate.isTrue(chance >= 0 && chance <= 1, "Chance must be between 0 and 1"); + } + + throw new IllegalArgumentException("Must be a number or boolean value"); + } + + public double getChance() { + return chance; + } + + public Boolean getValue() { + return value; + } + + @Override + public BooleanComponent randomizeComponent(MMOItemBuilder builder) { + boolean value = this.value != null ? this.value : chance < RANDOM.nextDouble(); + return new BooleanComponent(value); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/DoubleModel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/DoubleModel.java new file mode 100644 index 00000000..176e4666 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/DoubleModel.java @@ -0,0 +1,27 @@ +package net.Indyuce.mmoitems.stat.component.model.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.stat.annotation.TerminalComponentException; +import net.Indyuce.mmoitems.stat.component.builtin.DoubleComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class DoubleModel implements Model { + private final NumericStatFormula formula; + // TODO add string expression + + public DoubleModel(NumericStatFormula formula) { + this.formula = formula; + } + + public NumericStatFormula getFormula() { + return formula; + } + + @Override + public DoubleComponent randomizeComponent(MMOItemBuilder builder) { + return new DoubleComponent(formula.calculate(builder.getLevel())); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/IntegerModel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/IntegerModel.java new file mode 100644 index 00000000..4ab8f080 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/IntegerModel.java @@ -0,0 +1,25 @@ +package net.Indyuce.mmoitems.stat.component.model.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.stat.component.builtin.IntegerComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; + +public class IntegerModel implements Model { + private final NumericStatFormula formula; + + public IntegerModel(NumericStatFormula formula) { + this.formula = formula; + } + + public NumericStatFormula getFormula() { + return formula; + } + + @Override + public IntegerComponent randomizeComponent(MMOItemBuilder builder) { + // TODO add rule for round/ceil/floor? + // TODO make this function require a componentType as argument. cannot save it inside of models/components! + return new IntegerComponent((int) Math.round(formula.calculate(builder.getLevel()))); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ObjectModel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ObjectModel.java new file mode 100644 index 00000000..c673940c --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/model/builtin/ObjectModel.java @@ -0,0 +1,36 @@ +package net.Indyuce.mmoitems.stat.component.model.builtin; + +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponent; +import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponentImpl; +import net.Indyuce.mmoitems.stat.component.model.Model; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +// TODO merge with component? +public class ObjectModel implements Model { + private final Map> components = new HashMap<>(); + + public Map> getComponents() { + return components; + } + + @Override + public ObjectComponent randomizeComponent(MMOItemBuilder builder) { + ObjectComponentImpl comp = new ObjectComponentImpl(); + + for (Map.Entry> entry : this.components.entrySet()) + comp.set(entry.getKey(), entry.getValue().randomizeComponent(builder)); + + return comp; + } + + @Nullable + @Override + public Model getModel(@NotNull String key) { + return components.get(key); + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ComponentType.java index 0ba2e362..4c46c08b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ComponentType.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ComponentType.java @@ -1,4 +1,197 @@ package net.Indyuce.mmoitems.stat.component.type; -public class ComponentType { +import net.Indyuce.mmoitems.stat.component.LoreWrapper; +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import net.Indyuce.mmoitems.util.MMOUtils; +import net.Indyuce.mmoitems.util.Pair; +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +public abstract class ComponentType, C extends StatComponent> { + + /** + * A terminal component type is the type for a component + * which holds a terminal value like a string, integer, + * double, boolean, or even custom object types like abilities, + * ... + *

+ * Such terminal components can be directly edited by the player + * by clicking on that component in the editor UI. No further sub-UI + * can be opened to access its subcomponents. + */ + private boolean terminal; + private Function icon; + private Function name; + private Function> description; + + private List actionLoreTags = Arrays.asList("Left click to change this value.", "Right click to reset this value."); + + public boolean isTerminal() { + return terminal; + } + + @NotNull + public ItemStack provideIcon(@Nullable M model) { + return icon.apply(model); + } + + public String provideName(@Nullable M model) { + return name.apply(model); + } + + @Nullable + public List provideDescription(@Nullable M model) { + return description == null ? null : description.apply(model); + } + + public List getActionLoreTags() { + return actionLoreTags; + } + + /* + public void flatten(@NotNull List, StatComponent>> list, @Nullable S statComponent) { + Validate.isTrue(terminal, "Basic impl for terminal components"); + list.add(Pair.of(this, statComponent)); + } + */ + + /** + * @deprecated TODO adapt to arrays + */ + @NotNull + @Deprecated + public List>> getSubcomponents() { + throw new NotImplementedException(); + } + + public static final String NO_VALUE = ChatColor.RED + "---"; + public static final String CURRENT_VALUE = "Current Value: "; + + public void editionUiDisplay(LoreWrapper lore, @Nullable M model) { + + // Display nothing + if (model == null) { + lore.addLine(CURRENT_VALUE + NO_VALUE); + return; + } + + // Error handling + List disp; + try { + disp = editionUiFormat(model); + } catch (Exception exception) { + lore.addLine(CURRENT_VALUE + NO_VALUE); + // TODO improve error handling lore.addLine(ChatColor.RED + "Error: " + exception.getMessage()); + return; + } + + // Display it + if (disp.size() == 1) lore.addLine("Current Value: " + ChatColor.GREEN + disp.getFirst()); + else { + lore.addLine("Current Value:"); + lore.addLines(disp); + } + } + + // TODO remove overhead of using intermediate List + @NotNull + public abstract List editionUiFormat(M model); + + public abstract M initialize(@NotNull Object object); + + public class Builder { + public Builder setTerminal(boolean terminal) { + ComponentType.this.terminal = terminal; + return this; + } + + public Builder setIcon(@NotNull Material material) { + return setIcon(ignored -> new ItemStack(material)); + } + + public Builder setIcon(@NotNull ItemStack icon) { + return setIcon(ignored -> icon); + } + + public Builder setIcon(@NotNull Function material) { + ComponentType.this.icon = material; + return this; + } + + public Builder setActionLoreTags(@NotNull String... tags) { + ComponentType.this.actionLoreTags = Arrays.asList(tags); + return this; + } + + public Builder setActionLoreTagHint(@NotNull String hint) { + return setActionLoreTags("Left click to edit this " + hint + ".", "Right click to remove this " + hint + "."); + } + + public Builder setName(@NotNull String name) { + return setName(ignored -> name); + } + + public Builder setName(@NotNull Function name) { + ComponentType.this.name = name; + return this; + } + + public Builder setLore(@NotNull String... lore) { + return setLore(Arrays.asList(lore)); + } + + public Builder setLore(@NotNull List lore) { + return setLore(ignored -> lore); + } + + public Builder setLore(@NotNull Function> lore) { + ComponentType.this.description = lore; + return this; + } + + public Builder fromConfig(@NotNull ConfigurationSection config) { + setName(config.getString("name", "{no_stat_name}")); + + Object lore = config.get("lore"); + if (lore == null) setLore(Collections.singletonList("{no_stat_description}")); + else if (lore instanceof String) trimLore(lore.toString()); + else if (lore instanceof List) setLore((List) lore); + + setIcon(MMOUtils.readIcon(config.getString("icon"))); + + // TODO + + return this; + } + + public Builder trimLore(@NotNull String lore) { + return setLore(MMOUtils.trimString(40, lore)); + } + + /** + * Should return an exception if one of the fields is not correct + * + * @return Built component type + */ + public ComponentType build() { + // TODO infer data instead of throwing an error + Validate.notNull(icon, "Icon cannot be null"); + Validate.notNull(name, "Name cannot be null"); + //Validate.notNull(description, "Lore cannot be null"); + //Validate.notNull(actionLoreTags, "Action lore tags cannot be null"); + return ComponentType.this; + } + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponentType.java deleted file mode 100644 index b454631e..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponentType.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.Indyuce.mmoitems.stat.component.type; - -public class DoubleComponentType extends ComponentType { - - /** - * Are higher values of this component better or worse? Debuff stats - * should set this to false, otherwise should be true by default for - * most stats. - */ - boolean moreIsBetter = true; -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/IntegerComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/IntegerComponentType.java deleted file mode 100644 index 6814e3d5..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/IntegerComponentType.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.Indyuce.mmoitems.stat.component.type; - -public class IntegerComponentType { - - /** - * Are higher values of this component better or worse? Debuff stats - * should set this to false, otherwise should be true by default for - * most stats. - */ - boolean moreIsBetter = true; - - /** - * Should components be displayed using roman integer format. - */ - boolean useRoman; -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponentType.java deleted file mode 100644 index 1b0ee032..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponentType.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.Indyuce.mmoitems.stat.component.type; - -public class ObjectComponentType { - - /** - * Are higher values of this component better or worse? Debuff stats - * should set this to false, otherwise should be true by default for - * most stats. - */ - boolean moreIsBetter = true; - - /** - * Should components be displayed using roman integer format. - */ - boolean useRoman; -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ArrayComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ArrayComponentType.java new file mode 100644 index 00000000..7f21558d --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ArrayComponentType.java @@ -0,0 +1,94 @@ +package net.Indyuce.mmoitems.stat.component.type.builtin; + +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.builtin.ArrayComponent; +import net.Indyuce.mmoitems.stat.component.model.Model; +import net.Indyuce.mmoitems.stat.component.model.builtin.ArrayModel; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang.Validate; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class ArrayComponentType + extends ComponentType, ArrayComponent> { + + /** + * The component type that you can find inside your array. + * This must be specified for MMOItems to parse tags containing + * arrays of arbitrary types into component objects. + */ + private ComponentType subtype; + + private boolean displayList; + + private String nbElementsFormat = "Element Count: %s"; + private String listElPrefix = ""; + private String listHeader = ComponentType.CURRENT_VALUE; + + @NotNull + @Override + public List editionUiFormat(ArrayModel data) { +/* + // Display all the elements + if (displayList) { + + // Empty list + List list = data.getComponents(); + if (list.isEmpty()) return Collections.singletonList(listElPrefix + ComponentType.NO_VALUE); + + // Display full list + List lore = new ArrayList<>(1 + list.size()); + lore.add(listHeader); + for (StatComponent comp : list) { + List el = ((ComponentType) subtype).editionUiFormat(comp); // Can throw casting errors + lore.add(listElPrefix + el.removeFirst()); + lore.addAll(el); + } + return lore; + } + + // Simply print number of elements + else return Collections.singletonList(String.format(nbElementsFormat, data.getComponents().size())); + */ + throw new NotImplementedException(); + } + + @NotNull + @SuppressWarnings("rawtypes") + public static ArrayComponentType.Builder array() { + return new ArrayComponentType<>().new Builder(); + } + + @Override + public ArrayModel initialize(@NotNull Object object) { + throw new NotImplementedException(); + } + + @NotNull + public static , T extends ComponentType, S extends StatComponent> ArrayComponentType.Builder arrayOf(T of) { + return new ArrayComponentType().new Builder().of(of); + } + + public class Builder extends ComponentType, ArrayComponent>.Builder { + public Builder() { + //setActionLoreTags("Left click to edit this material.", "Right click to remove this option."); + } + + public Builder of(@NotNull ComponentType subtype) { + ArrayComponentType.this.subtype = subtype; + return this; + } + + public Builder displayList(boolean val) { + ArrayComponentType.this.displayList = val; + return this; + } + + public ArrayComponentType build() { + Validate.notNull(subtype, "Subtype cannot be null"); + return (ArrayComponentType) super.build(); + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/BooleanComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/BooleanComponentType.java new file mode 100644 index 00000000..4aea32b4 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/BooleanComponentType.java @@ -0,0 +1,59 @@ +package net.Indyuce.mmoitems.stat.component.type.builtin; + +import io.lumine.mythic.lib.MythicLib; +import net.Indyuce.mmoitems.stat.component.builtin.BooleanComponent; +import net.Indyuce.mmoitems.stat.component.model.builtin.BooleanModel; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class BooleanComponentType extends ComponentType { + + public MergeMecanism mergeMecanism = MergeMecanism.OR; + + @NotNull + @Override + public List editionUiFormat(BooleanModel model) { + + if (model.getValue() != null) + return Collections.singletonList(model.getValue().toString()); + + // Format boolean + return Collections.singletonList(MythicLib.plugin.getMMOConfig().decimal.format(100 * model.getChance()) + "% Chance"); + } + + @Override + public BooleanModel initialize(@NotNull Object object) { + return new BooleanModel(object); + } + + @NotNull + public static Builder toggle() { + return new BooleanComponentType().new Builder(); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTags("Left click to switch this value.", "Right click to reset this option."); + setTerminal(true); + } + + public BooleanComponentType build() { + return (BooleanComponentType) super.build(); + } + } + + public static enum MergeMecanism { + + OR, + + AND, + + /** + * This could definitely be used in a fun way... + */ + XOR, + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/DoubleComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/DoubleComponentType.java new file mode 100644 index 00000000..363d1b2f --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/DoubleComponentType.java @@ -0,0 +1,79 @@ +package net.Indyuce.mmoitems.stat.component.type.builtin; + +import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.stat.component.builtin.DoubleComponent; +import net.Indyuce.mmoitems.stat.component.model.builtin.DoubleModel; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.jetbrains.annotations.NotNull; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DoubleComponentType extends ComponentType { + + /** + * Are higher values of this component better or worse? Debuff stats + * should set this to false, otherwise should be true by default for + * most stats. + */ + public boolean moreIsBetter = true; + + // TODO edit with config. if none specified, fetch from MythicLib + public DecimalFormat format = new DecimalFormat("0.####"); + + @NotNull + @Override + public List editionUiFormat(DoubleModel model) { + return editionUiFormat(format, model.getFormula()); + } + + public static List editionUiFormat(DecimalFormat decFormat, NumericStatFormula formula) { + + // Uniform distribution + if (formula.isUniform()) + return Collections.singletonList("Uniform: &a" + decFormat.format(formula.getMin()) + "&7 -> &a" + decFormat.format(formula.getMax())); + + String baseFormat = "&a" + decFormat.format(formula.getBase()) + + (formula.getScale() != 0 ? " &7(+&a" + decFormat.format(formula.getScale()) + "&7/Lvl)" : ""); + + boolean spread = formula.getSpread() > 0, min = formula.hasMin(), max = formula.hasMax(); + if (!spread && !min && !max) + return Collections.singletonList(baseFormat); + + // Gaussian distribution + List list = new ArrayList<>(4); + list.add("Base Value: " + baseFormat); + if (spread) list.add("Spread: &a" + decFormat.format(formula.getSpread())); + if (min) list.add("Min: &a" + decFormat.format(formula.getMin())); + if (max) list.add("Max: &a" + decFormat.format(formula.getMax())); + return list; + } + + @Override + public DoubleModel initialize(@NotNull Object configObject) { + return new DoubleModel(new NumericStatFormula(configObject)); + } + + @NotNull + public static Builder numeric() { + return new DoubleComponentType().new Builder(); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTags("Left click to edit this number.", "Right click to remove this option."); + setTerminal(true); + } + + public Builder moreIsBetter(boolean val) { + DoubleComponentType.this.moreIsBetter = val; + return this; + } + + public DoubleComponentType build() { + return (DoubleComponentType) super.build(); + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/IntegerComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/IntegerComponentType.java new file mode 100644 index 00000000..32fd5124 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/IntegerComponentType.java @@ -0,0 +1,82 @@ +package net.Indyuce.mmoitems.stat.component.type.builtin; + +import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.stat.component.builtin.IntegerComponent; +import net.Indyuce.mmoitems.stat.component.model.builtin.IntegerModel; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.jetbrains.annotations.NotNull; + +import java.text.DecimalFormat; +import java.util.List; + +// TODO merge with DoubleComponents? just add an option for whole numbers. +public class IntegerComponentType extends ComponentType { + + /** + * Are higher values of this component better or worse? Debuff stats + * should set this to false, otherwise should be true by default for + * most stats. + */ + public boolean moreIsBetter = true; + + /** + * Should components be displayed using roman integer format. + */ + public boolean useRoman = false; + + // TODO edit with config. if none specified, fetch from MythicLib + public DecimalFormat format = new DecimalFormat("0.####"); + + public MergeMecanism mergeMecanism = MergeMecanism.SUM; + + @NotNull + @Override + public List editionUiFormat(IntegerModel data) { + return DoubleComponentType.editionUiFormat(format, data.getFormula()); + } + + @Override + public IntegerModel initialize(@NotNull Object object) { + return new IntegerModel(new NumericStatFormula(object)); + } + + @NotNull + public static Builder numericInt() { + return new IntegerComponentType().new Builder(); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTags("Left click to edit this int.", "Right click to remove this option."); + setTerminal(true); + } + + public Builder moreIsBetter(boolean moreIsBetter) { + IntegerComponentType.this.moreIsBetter = moreIsBetter; + return this; + } + + public Builder useRoman(boolean moreIsBetter) { + IntegerComponentType.this.moreIsBetter = moreIsBetter; + return this; + } + + public Builder mergeMecanism(@NotNull MergeMecanism mergeMecanism) { + IntegerComponentType.this.mergeMecanism = mergeMecanism; + return this; + } + + public IntegerComponentType build() { + return (IntegerComponentType) super.build(); + } + } + + public static enum MergeMecanism { + + HIGHEST, + + LOWEST, + + SUM, + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ObjectComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ObjectComponentType.java new file mode 100644 index 00000000..96a2ecaf --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/ObjectComponentType.java @@ -0,0 +1,112 @@ +package net.Indyuce.mmoitems.stat.component.type.builtin; + +import net.Indyuce.mmoitems.stat.component.LoreWrapper; +import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponent; +import net.Indyuce.mmoitems.stat.component.model.builtin.ObjectModel; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import net.Indyuce.mmoitems.util.Pair; +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class ObjectComponentType extends ComponentType { + private final Map> fields = new LinkedHashMap<>(); + + /** + * Not a terminal component type, but this display all its subcomponents + * on the same page nonetheless. + *

+ * TODO + */ + private boolean flattened; + + @Override + public void editionUiDisplay(LoreWrapper lore, ObjectModel model) { + throw new NotImplementedException(); + } + + public Map> getFields() { + return fields; + } + + /* + @Override + @SuppressWarnings({"unchecked", "rawtypes"}) + public void flatten(@NotNull List, StatComponent>> list, @Nullable ObjectComponent statComponent) { + + // Do not collect this item, only collect its children + fields.forEach((key, type) -> { + StatComponent subcomponent = statComponent == null ? null : statComponent.get(key); + ((ComponentType) type).flatten(list, subcomponent); + }); + } + */ + + @Override + public List>> getSubcomponents() { + List>> subcomponents = new ArrayList<>(); + this.fields.forEach((key, comp) -> subcomponents.add(Pair.of(key, comp))); + return subcomponents; + } + + @Override + public ObjectModel initialize(@NotNull Object object) { + Validate.isTrue(object instanceof ConfigurationSection, "Must be a configuration section"); + ConfigurationSection section = (ConfigurationSection) object; + + ObjectModel comp = new ObjectModel(); + + for (Map.Entry> entry : fields.entrySet()) { + Object sub = section.get(entry.getKey()); + comp.getComponents().put(entry.getKey(), entry.getValue().initialize(sub)); + } + + return comp; + } + + @NotNull + @Override + public List editionUiFormat(ObjectModel data) { + throw new NotImplementedException(); + } + + @NotNull + public static ObjectComponentType.Builder object() { + return new ObjectComponentType().new Builder(); + } + + @NotNull + public static ObjectComponentType.Builder color() { + return new ObjectComponentType().new Builder().addField("red", IntegerComponentType.numericInt().setIcon(Material.RED_WOOL).setName("Red").build()).addField("green", IntegerComponentType.numericInt().setIcon(Material.GREEN_WOOL).setName("Green").build()).addField("blue", IntegerComponentType.numericInt().setIcon(Material.BLUE_WOOL).setName("Blue").build()); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + //setActionLoreTags("Left click to edit this material.", "Right click to remove this option."); + } + + @Deprecated // TODO + public Builder setFlattened(boolean flattened) { + ObjectComponentType.this.flattened = flattened; + return this; + } + + public Builder addField(String key, ComponentType componentType) { + fields.put(key, componentType); + return this; + } + + @NotNull + public ObjectComponentType build() { + // TODO rules + return (ObjectComponentType) super.build(); + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/StringComponentType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/StringComponentType.java new file mode 100644 index 00000000..edce8d56 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/component/type/builtin/StringComponentType.java @@ -0,0 +1,38 @@ +package net.Indyuce.mmoitems.stat.component.type.builtin; + +import net.Indyuce.mmoitems.stat.component.builtin.StringComponent; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class StringComponentType extends ComponentType { + + @NotNull + @Override + public List editionUiFormat(StringComponent data) { + return Collections.singletonList(data.getValue()); + } + + @Override + public StringComponent initialize(@NotNull Object object) { + return new StringComponent(object.toString()); + } + + @NotNull + public static StringComponentType.Builder init() { + return new StringComponentType().new Builder(); + } + + public class Builder extends ComponentType.Builder { + public Builder() { + setActionLoreTags("Left click to edit this string.", "Right click to remove this option."); + } + + @NotNull + public StringComponentType build() { + return (StringComponentType) super.build(); + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java index b6aced99..7e5b9470 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java @@ -31,6 +31,7 @@ import java.util.Set; * used utility class which defines the castable implementation * of the {@link Skill} interface for MMOItems. */ +@Deprecated public class AbilityData extends Skill { private final RegisteredSkill ability; @NotNull diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/DoubleData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/DoubleData.java index 75220a74..08b0b4b0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/DoubleData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/DoubleData.java @@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.stat.data; import net.Indyuce.mmoitems.stat.data.type.Mergeable; import net.Indyuce.mmoitems.stat.data.type.StatData; +@Deprecated public class DoubleData implements StatData, Mergeable { private double value; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/dynamic/DynamicStatData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/dynamic/DynamicStatData.java index 27942861..2fc456b0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/dynamic/DynamicStatData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/dynamic/DynamicStatData.java @@ -1,11 +1,15 @@ package net.Indyuce.mmoitems.stat.data.dynamic; +import io.lumine.mythic.lib.util.annotation.NotUsed; + +@Deprecated +@NotUsed public interface DynamicStatData { - /* - * dynamic stat data is used when all the mmoitems are in the player - * inventory and when MMOItems calculates all passive effects which the - * items must apply on the player - */ - // TODO + /* + * dynamic stat data is used when all the mmoitems are in the player + * inventory and when MMOItems calculates all passive effects which the + * items must apply on the player + */ + // TODO } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java index f39a251f..1d409fc7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java @@ -15,6 +15,10 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.data.AbilityData; +/** + * @deprecated TODO replace using RandomComponent's + */ +@Deprecated public class RandomAbilityData { private final RegisteredSkill ability; private final TriggerType triggerType; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityListData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityListData.java index 601cbeb8..d6ef1149 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityListData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityListData.java @@ -8,6 +8,10 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.stat.data.AbilityListData; import net.Indyuce.mmoitems.stat.data.type.StatData; +/** + * @deprecated TODO replace using RandomComponent's + */ +@Deprecated public class RandomAbilityListData implements RandomStatData { private final Set abilities = new LinkedHashSet<>(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomElementListData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomElementListData.java index e4d35cc5..3cf33986 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomElementListData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomElementListData.java @@ -17,6 +17,10 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +/** + * @deprecated TODO replace using RandomComponent's + */ +@Deprecated public class RandomElementListData implements RandomStatData, UpdatableRandomStatData { private final Map, NumericStatFormula> stats = new LinkedHashMap<>(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomEnchantListData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomEnchantListData.java index bf9f89c5..ac2f7289 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomEnchantListData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomEnchantListData.java @@ -13,6 +13,10 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +/** + * @deprecated TODO replace using RandomComponent's + */ +@Deprecated public class RandomEnchantListData implements RandomStatData { private final Map enchants = new HashMap<>(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java index 64a1d571..6cfd9593 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java @@ -9,6 +9,10 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.data.PotionEffectData; +/** + * @deprecated TODO replace using RandomComponent's + */ +@Deprecated public class RandomPotionEffectData { private final PotionEffectType type; private final NumericStatFormula duration, amplifier; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectListData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectListData.java index d877ff96..6ab93c60 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectListData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectListData.java @@ -15,6 +15,10 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.stat.data.PotionEffectListData; import org.bukkit.potion.PotionEffectType; +/** + * @deprecated TODO replace using RandomComponent's + */ +@Deprecated public class RandomPotionEffectListData implements RandomStatData { private final List effects = new ArrayList<>(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRequiredLevelData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRequiredLevelData.java index 3934505c..0c7dd414 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRequiredLevelData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRequiredLevelData.java @@ -8,7 +8,10 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; /** * Used by the item level restriction as well as attribute * and profession item requirements for MMOCore and AureliumSkills + * + * @deprecated TODO replace using RandomComponent's */ +@Deprecated public class RandomRequiredLevelData extends NumericStatFormula { public RandomRequiredLevelData(Object object) { super(object); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRestoreData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRestoreData.java index 1a78b0d8..bd1613f6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRestoreData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomRestoreData.java @@ -8,31 +8,34 @@ import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.data.RestoreData; import net.Indyuce.mmoitems.stat.data.type.StatData; +/** + * @deprecated TODO replace using RandomComponent's + */ public class RandomRestoreData implements RandomStatData { - private final NumericStatFormula health, food, saturation; + private final NumericStatFormula health, food, saturation; - public RandomRestoreData(ConfigurationSection config) { - Validate.notNull(config, "Could not load restore config"); + public RandomRestoreData(ConfigurationSection config) { + Validate.notNull(config, "Could not load restore config"); - health = config.contains("health") ? new NumericStatFormula(config) : NumericStatFormula.ZERO; - food = config.contains("food") ? new NumericStatFormula(config) : NumericStatFormula.ZERO; - saturation = config.contains("saturation") ? new NumericStatFormula(config) : NumericStatFormula.ZERO; - } + health = config.contains("health") ? new NumericStatFormula(config) : NumericStatFormula.ZERO; + food = config.contains("food") ? new NumericStatFormula(config) : NumericStatFormula.ZERO; + saturation = config.contains("saturation") ? new NumericStatFormula(config) : NumericStatFormula.ZERO; + } - public NumericStatFormula getHealth() { - return health; - } + public NumericStatFormula getHealth() { + return health; + } - public NumericStatFormula getFood() { - return food; - } + public NumericStatFormula getFood() { + return food; + } - public NumericStatFormula getSaturation() { - return saturation; - } + public NumericStatFormula getSaturation() { + return saturation; + } - @Override - public RestoreData randomize(MMOItemBuilder builder) { - return new RestoreData(health.calculate(builder.getLevel()), food.calculate(builder.getLevel()), saturation.calculate(builder.getLevel())); - } + @Override + public RestoreData randomize(MMOItemBuilder builder) { + return new RestoreData(health.calculate(builder.getLevel()), food.calculate(builder.getLevel()), saturation.calculate(builder.getLevel())); + } } \ No newline at end of file diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java index 92234740..c9c06cba 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomStatData.java @@ -8,13 +8,14 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; * are the first instances called when loading gen templates from config files. * * @author cympe + * @deprecated TODO replace using RandomComponent's */ public interface RandomStatData { /** * @param builder The builder of the random item being generated * @return A random stat data instance which will then be merged onto the - * base item template + * base item template */ S randomize(MMOItemBuilder builder); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java index a85dc5a7..95006f44 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java @@ -1,157 +1,166 @@ package net.Indyuce.mmoitems.stat.type; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; +import io.lumine.mythic.lib.api.util.AltChar; +import net.Indyuce.mmoitems.MMOItems; +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.component.type.builtin.BooleanComponentType; +import net.Indyuce.mmoitems.stat.data.BooleanData; +import net.Indyuce.mmoitems.stat.data.random.RandomBooleanData; +import net.Indyuce.mmoitems.util.MMOUtils; 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.util.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.BooleanData; -import net.Indyuce.mmoitems.stat.data.random.RandomBooleanData; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.util.AltChar; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + public class BooleanStat extends ItemStat { - public BooleanStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { - super(id, mat, name, lore, types, materials); - } + @Deprecated + public BooleanStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { + this(id, mat, name, MMOUtils.append(lore), types, materials); + } - @Override - public RandomBooleanData whenInitialized(Object object) { + public BooleanStat(String id, Material mat, String name, String lore, String[] types, Material... materials) { + super(id, types, materials); - if (object instanceof Boolean) - return new RandomBooleanData((boolean) object); + setComponentType(BooleanComponentType.toggle() + .setName(name) + .setIcon(mat) + .trimLore(lore) + .build()); + } - if (object instanceof Number) - return new RandomBooleanData(Double.parseDouble(object.toString())); + @Override + public RandomBooleanData whenInitialized(Object object) { - throw new IllegalArgumentException("Must specify a number (chance) or true/false"); - } + if (object instanceof Boolean) + return new RandomBooleanData((boolean) object); - @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) { + if (object instanceof Number) + return new RandomBooleanData(Double.parseDouble(object.toString())); - // Only if enabled yo - if (data.isEnabled()) { + throw new IllegalArgumentException("Must specify a number (chance) or true/false"); + } - // Add those - item.addItemTag(getAppliedNBT(data)); + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) { - // Show in lore - item.getLore().insert(getPath(), getGeneralStatFormat()); - } - } + // Only if enabled yo + if (data.isEnabled()) { - @NotNull - @Override - public ArrayList getAppliedNBT(@NotNull BooleanData data) { + // Add those + item.addItemTag(getAppliedNBT(data)); - // Create Fresh - ArrayList ret = new ArrayList<>(); + // Show in lore + item.getLore().insert(getPath(), getGeneralStatFormat()); + } + } - if (data.isEnabled()) { + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull BooleanData data) { - // Add sole tag - ret.add(new ItemTag(getNBTPath(), true)); - } + // Create Fresh + ArrayList ret = new ArrayList<>(); - // Return thay - return ret; - } + if (data.isEnabled()) { - @Override - public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { - if (event.getAction() == InventoryAction.PICKUP_ALL) { - inv.getEditedSection().set(getPath(), inv.getEditedSection().getBoolean(getPath()) ? null : true); - inv.registerTemplateEdition(); - } + // Add sole tag + ret.add(new ItemTag(getNBTPath(), true)); + } - else if (event.getAction() == InventoryAction.PICKUP_HALF) - new StatEdition(inv, this).enable("Write in the chat the probability you want (a percentage)"); - } + // Return thay + return ret; + } - @Override - public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { + @Override + public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { + if (event.getAction() == InventoryAction.PICKUP_ALL) { + inv.getEditedSection().set(getPath(), inv.getEditedSection().getBoolean(getPath()) ? null : true); + inv.registerTemplateEdition(); + } else if (event.getAction() == InventoryAction.PICKUP_HALF) + new StatEdition(inv, this).enable("Write in the chat the probability you want (a percentage)"); + } - double probability = MMOUtils.parseDouble(message); - Validate.isTrue(probability >= 0 && probability <= 100, "Chance must be between 0 and 100"); + @Override + public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { - inv.getEditedSection().set(getPath(), probability / 100); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + ChatColor.GREEN - + MythicLib.plugin.getMMOConfig().decimal.format(probability) + "% Chance" + ChatColor.GRAY + "."); - } + double probability = MMOUtils.parseDouble(message); + Validate.isTrue(probability >= 0 && probability <= 100, "Chance must be between 0 and 100"); - @Override - public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + inv.getEditedSection().set(getPath(), probability / 100); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + ChatColor.GREEN + + MythicLib.plugin.getMMOConfig().decimal.format(probability) + "% Chance" + ChatColor.GRAY + "."); + } - // Find the useful tags - ArrayList relevantTags = new ArrayList<>(); + @Override + public void whenLoaded(@NotNull ReadMMOItem mmoitem) { - // That one is useful - if (mmoitem.getNBT().hasTag(getNBTPath())) - relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.BOOLEAN)); + // Find the useful tags + ArrayList relevantTags = new ArrayList<>(); - BooleanData data = (BooleanData) getLoadedNBT(relevantTags); + // That one is useful + if (mmoitem.getNBT().hasTag(getNBTPath())) + relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.BOOLEAN)); - // Success? - if (data != null) { + BooleanData data = (BooleanData) getLoadedNBT(relevantTags); - // Set the data if it was successful - mmoitem.setData(this, data); - } - } + // Success? + if (data != null) { - @Nullable - @Override - public BooleanData getLoadedNBT(@NotNull ArrayList storedTags) { + // Set the data if it was successful + mmoitem.setData(this, data); + } + } - // Find relevant tag - ItemTag encoded = ItemTag.getTagAtPath(getNBTPath(), storedTags); + @Nullable + @Override + public BooleanData getLoadedNBT(@NotNull ArrayList storedTags) { - // Found it? - if (encoded != null) { + // Find relevant tag + ItemTag encoded = ItemTag.getTagAtPath(getNBTPath(), storedTags); - // Well read it! - return new BooleanData((Boolean) encoded.getValue()); - } + // Found it? + if (encoded != null) { - return null; - } + // Well read it! + return new BooleanData((Boolean) encoded.getValue()); + } - @Override - public void whenDisplayed(List lore, Optional statData) { + return null; + } - if (statData.isPresent()) { - final double chance = statData.get().getChance(); - lore.add(ChatColor.GRAY + "Current Value: " + (chance >= 1 ? ChatColor.GREEN + "True" - : chance <= 0 ? ChatColor.RED + "False" : ChatColor.GREEN + MythicLib.plugin.getMMOConfig().decimal.format(chance * 100) + "% Chance")); + @Override + public void whenDisplayed(List lore, Optional statData) { - } else - lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "False"); + if (statData.isPresent()) { + final double chance = statData.get().getChance(); + lore.add(ChatColor.GRAY + "Current Value: " + (chance >= 1 ? ChatColor.GREEN + "True" + : chance <= 0 ? ChatColor.RED + "False" : ChatColor.GREEN + MythicLib.plugin.getMMOConfig().decimal.format(chance * 100) + "% Chance")); - lore.add(""); - lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to switch this value."); - lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to choose a probability to have this option."); - } + } else + lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "False"); - @NotNull - @Override - public BooleanData getClearStatData() { - return new BooleanData(false); - } + lore.add(""); + lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to switch this value."); + lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to choose a probability to have this option."); + } + + @NotNull + @Override + public BooleanData getClearStatData() { + return new BooleanData(false); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java index 9301d71b..3608647c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java @@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.gui.edition.EditionInventory; +import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo; @@ -37,26 +38,36 @@ import java.util.Optional; public class DoubleStat extends ItemStat implements Upgradable, Previewable { - private final boolean moreIsBetter; - private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.####"); + public DoubleStat(String id, Material mat, String name, String lore) { + this(id, mat, name, lore, new String[]{"!miscellaneous", "!block", "all"}, true); + } + + public DoubleStat(String id, Material mat, String name, String lore, String[] types, boolean moreIsBetter, Material... materials) { + super(id, types, materials); + + setComponentType(DoubleComponentType.numeric() + .moreIsBetter(moreIsBetter) + .setName(name) + .setIcon(mat) + .trimLore(lore) + .build()); + } + + @Deprecated public DoubleStat(String id, Material mat, String name, String[] lore) { this(id, mat, name, lore, new String[]{"!miscellaneous", "!block", "all"}, true); } - public DoubleStat(String id, Material mat, String name, String lore) { - this(id, mat, name, MMOUtils.trimString(LORE_LINE_WIDTH, lore), new String[]{"!miscellaneous", "!block", "all"}, true); - } - + @Deprecated public DoubleStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { this(id, mat, name, lore, types, true, materials); } + @Deprecated public DoubleStat(String id, Material mat, String name, String[] lore, String[] types, boolean moreIsBetter, Material... materials) { - super(id, mat, name, lore, types, materials); - - this.moreIsBetter = moreIsBetter; + this(id, mat, name, MMOUtils.append(lore), types, moreIsBetter, materials); } /** @@ -78,8 +89,9 @@ public class DoubleStat extends ItemStat impleme *

* However, it's not impossible for a stat to be evil instead, who knows? */ + @Deprecated public boolean moreIsBetter() { - return moreIsBetter; + return ((DoubleComponentType) getComponentType()).moreIsBetter; } @Override @@ -126,7 +138,7 @@ public class DoubleStat extends ItemStat impleme // Display in lore if (value != 0 || upgradeShift != 0) { - String loreInsert = formatPath(getId(), getGeneralStatFormat(), moreIsBetter, value * multiplyWhenDisplaying()); + String loreInsert = formatPath(getId(), getGeneralStatFormat(), moreIsBetter(), value * multiplyWhenDisplaying()); if (upgradeShift != 0) loreInsert += UpgradeTemplate.getUpgradeChangeSuffix(plus(true, upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying())); item.getLore().insert(getPath(), loreInsert); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FakeElementalStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FakeElementalStat.java index 7f0cfd99..56d1be09 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FakeElementalStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FakeElementalStat.java @@ -7,6 +7,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.HasCategory; +import net.Indyuce.mmoitems.stat.behaviour.InternalStat; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.util.ElementStatType; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemRestriction.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemRestriction.java deleted file mode 100644 index 883cfbde..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemRestriction.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.Indyuce.mmoitems.stat.type; - -import net.Indyuce.mmoitems.api.player.RPGPlayer; -import io.lumine.mythic.lib.api.item.NBTItem; - -/** - * Stats which implement an item restriction. They are automatically collected - * in a list when registered in the StatManager. Lets other plugins implement - * stats which rely on item restrictions without having to use Bukkit events! - * - * @author cympe - * - */ -public interface ItemRestriction { - - /** - * @param player Player trying to use an item - * @param item The item being checked - * @param message Difference between an active and a passive check: if the - * check is active (message boolean set to true), the plugin - * should send a message to the player if he can't use the - * item for eg when he tries to equip the item. If the check - * is passive, no message needs to be sent (when the plugin - * internally needs some similar check) - * @return False if the item cannot be used - */ - boolean canUse(RPGPlayer player, NBTItem item, boolean message); - - /** - * Usually, item restrictions are checked when equipping - * an item, and prevent the item being equipped if they fail that moment. - *

- * Setting this to true will allow items equip anyway - * and check with every use that the conditions for their usage - * are met. - */ - default boolean isDynamic() { return false; } -} 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 e7fcee9e..24fc83d6 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 @@ -10,9 +10,9 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.annotation.VersionDependant; import net.Indyuce.mmoitems.stat.category.StatCategory; +import net.Indyuce.mmoitems.stat.component.type.ComponentType; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.inventory.InventoryClickEvent; @@ -23,6 +23,10 @@ import org.jetbrains.annotations.Nullable; import java.util.*; public abstract class ItemStat, S extends StatData> { + + private ComponentType componentType; + + @NotNull private final String id, name, configPath, nbtPath; @NotNull @@ -56,7 +60,13 @@ public abstract class ItemStat, S extends StatData> * @param types Compatible types. See {@link #isCompatible(Type)} * @param materials Materials compatible with the item stat (e.g Shield Pattern), any if empty */ - public ItemStat(@NotNull String id, @NotNull Material material, @NotNull String name, @Nullable String[] lore, @Nullable String[] types, @Nullable Material... materials) { + @Deprecated + public ItemStat(@NotNull String id, + @NotNull Material material, + @NotNull String name, + @Nullable String[] lore, + @Nullable String[] types, + @Nullable Material... materials) { this.id = id; this.material = material; this.lore = lore == null ? new String[0] : lore; @@ -72,12 +82,34 @@ public abstract class ItemStat, S extends StatData> final VersionDependant implVersion = getClass().getAnnotation(VersionDependant.class); if (MythicLib.plugin.getVersion().isUnder(implVersion.version())) disable(); } + } - // Backwards compatibility - if (getClass().isAnnotationPresent(net.Indyuce.mmoitems.util.VersionDependant.class)) { - final net.Indyuce.mmoitems.util.VersionDependant implVersion = getClass().getAnnotation(net.Indyuce.mmoitems.util.VersionDependant.class); + public ItemStat(@NotNull String id, @Nullable String[] types, @Nullable Material... materials) { + this.id = id; + this.compatibleTypes = types == null ? new ArrayList<>() : Arrays.asList(types); + this.compatibleMaterials = materials == null ? new ArrayList<>() : Arrays.asList(materials); + + this.configPath = id.toLowerCase().replace("_", "-"); + this.nbtPath = "MMOITEMS_" + id; + + // Version dependency + if (getClass().isAnnotationPresent(VersionDependant.class)) { + final VersionDependant implVersion = getClass().getAnnotation(VersionDependant.class); if (MythicLib.plugin.getVersion().isUnder(implVersion.version())) disable(); } + + // Backwards comp + this.lore = new String[]{"Lorem ipsum dolor sit amet", "this lore is no longer used"}; + this.material = Material.BARRIER; + this.name = "Awesome Stat"; + } + + public void setComponentType(ComponentType componentType) { + this.componentType = componentType; + } + + public ComponentType getComponentType() { + return componentType; } /** @@ -175,7 +207,6 @@ public abstract class ItemStat, S extends StatData> protected String generalStatFormat; public void readTranslationFile(@NotNull ConfigurationSection translationFile) { - Bukkit.broadcastMessage("reading translation for " + getPath()); String path = getPath(); Object obj = translationFile.get(path); if (obj == null) obj = translationFile.get(getLegacyTranslationPath()); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/RequiredLevelStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/RequiredLevelStat.java index 923c511a..bcb875a8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/RequiredLevelStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/RequiredLevelStat.java @@ -6,6 +6,8 @@ import io.lumine.mythic.lib.util.annotation.BackwardsCompatibility; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.data.RequiredLevelData; import net.Indyuce.mmoitems.stat.data.random.RandomRequiredLevelData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java index 1560a462..90e33068 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StringStat.java @@ -9,7 +9,9 @@ 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.component.type.builtin.StringComponentType; import net.Indyuce.mmoitems.stat.data.StringData; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryAction; @@ -22,8 +24,20 @@ import java.util.List; import java.util.Optional; public class StringStat extends ItemStat { + + @Deprecated public StringStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { - super(id, mat, name, lore, types, materials); + this(id, mat, name, MMOUtils.append(lore), types, materials); + } + + public StringStat(String id, Material mat, String name, String lore, String[] types, Material... materials) { + super(id, types, materials); + + setComponentType(StringComponentType.init() + .setIcon(mat) + .setName(name) + .trimLore(lore) + .build()); } @Override diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java index c111f3f2..ead2aaaa 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java @@ -49,24 +49,43 @@ public class MMOUtils { continue; } - StringBuilder currentLine = new StringBuilder(); + StringBuilder currLine = new StringBuilder(); + int currLength = 0; for (String word : input.split(" ")) { - if (!currentLine.isEmpty()) currentLine.append(" "); - currentLine.append(word); - if (currentLine.length() > charactersPerLine || word.endsWith("\n")) { - list.add(currentLine.toString()); // Return line - currentLine.setLength(0); // Empty current line + if (currLength > 0) currLine.append(" "); + + // Append + currLine.append(word); + currLength += word.length(); + + if (currLength > charactersPerLine || word.endsWith("\n")) { + String finalLine = currLine.toString(); + String lastColors = ChatColor.getLastColors(finalLine); + + list.add(finalLine); // Return line + currLine.setLength(0); // Empty current line + currLength = 0; // Reset counter + currLine.append(lastColors); // Remember color } } // Add last line (sometimes not necessary) - if (!currentLine.isEmpty()) list.add(currentLine.toString()); + if (currLength > 0) list.add(currLine.toString()); } return list.toArray(new String[0]); } + public static String append(String... strings) { + StringBuilder builder = new StringBuilder(); + for (String str : strings) { + if (!builder.isEmpty()) builder.append(" "); + builder.append(str); + } + return builder.toString(); + } + @NotNull public static ItemStack readIcon(@NotNull String stringInput) { Validate.notNull(stringInput, "Input must not be null"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/Pair.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/Pair.java index f9ac317b..c922558b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/Pair.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/Pair.java @@ -1,6 +1,6 @@ package net.Indyuce.mmoitems.util; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -8,13 +8,13 @@ public class Pair { private final K key; private final V value; - public Pair(@NotNull K var1, @NotNull V var2) { + public Pair(@Nullable K var1, @Nullable V var2) { this.key = var1; this.value = var2; } - public static Pair of(@NotNull K var0, @NotNull V var1) { - return new Pair(var0, var1); + public static Pair of(@Nullable K var0, @Nullable V var1) { + return new Pair<>(var0, var1); } public K getKey() { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/VersionDependant.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/VersionDependant.java deleted file mode 100644 index 7067314b..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/VersionDependant.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.Indyuce.mmoitems.util; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * @see net.Indyuce.mmoitems.stat.annotation.VersionDependant - * @deprecated Moved to another class - */ -@Deprecated -@Retention(RetentionPolicy.RUNTIME) -public @interface VersionDependant { - - public int[] version(); -} diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepGems.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepGems.java index cee3ada5..97698e13 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepGems.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepGems.java @@ -13,7 +13,7 @@ import net.Indyuce.mmoitems.stat.data.GemSocketsData; import net.Indyuce.mmoitems.stat.data.GemstoneData; import net.Indyuce.mmoitems.stat.data.type.Mergeable; import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.GemStoneStat; +import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.StatHistory; import org.bukkit.event.EventHandler; diff --git a/pom.xml b/pom.xml index 82887d44..1e3fd1eb 100644 --- a/pom.xml +++ b/pom.xml @@ -108,6 +108,8 @@ annotations 23.0.0 provided + true +