diff --git a/src/main/java/net/Indyuce/mmoitems/ItemStats.java b/src/main/java/net/Indyuce/mmoitems/ItemStats.java index ed5056d8..8eb59bf4 100644 --- a/src/main/java/net/Indyuce/mmoitems/ItemStats.java +++ b/src/main/java/net/Indyuce/mmoitems/ItemStats.java @@ -172,7 +172,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[] { "piercing", "slashing", "blunt", "offhand", "range", "tool", "armor", "consumable", "accessory" }), 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[] { "piercing", "slashing", "blunt", "offhand", "range", "tool", "armor", "consumable", "accessory" }), - DOWNGRADE_ON_DEATH_CHANCE = new EvilDoubleStat("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[]{"!miscellaneous", "!block", "all"}), + 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[]{"!miscellaneous", "!block", "all"}, false), // Unique Item Stats SKULL_TEXTURE = new SkullTextureStat(), diff --git a/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java b/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java new file mode 100644 index 00000000..d4d8f6a2 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/component/Mergeable.java @@ -0,0 +1,6 @@ +package net.Indyuce.mmoitems.stat.component; + +public interface Mergeable { + + public void merge(T t); +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java b/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java new file mode 100644 index 00000000..983967f9 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/component/StatComponent.java @@ -0,0 +1,13 @@ +package net.Indyuce.mmoitems.stat.component; + +public abstract class StatComponent { + private final String path; + + public StatComponent(String path) { + this.path = path; + } + + public String getPath() { + return path; + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/component/Upgradable.java b/src/main/java/net/Indyuce/mmoitems/stat/component/Upgradable.java new file mode 100644 index 00000000..44108fbf --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/component/Upgradable.java @@ -0,0 +1,4 @@ +package net.Indyuce.mmoitems.stat.component; + +public interface Upgradable { +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/component/type/AbstractObjectComponent.java b/src/main/java/net/Indyuce/mmoitems/stat/component/type/AbstractObjectComponent.java new file mode 100644 index 00000000..0d8b920c --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/component/type/AbstractObjectComponent.java @@ -0,0 +1,32 @@ +package net.Indyuce.mmoitems.stat.component.type; + +import net.Indyuce.mmoitems.stat.component.StatComponent; +import org.jetbrains.annotations.Nullable; + +public abstract class AbstractObjectComponent extends StatComponent { + public AbstractObjectComponent(String path) { + super(path); + } + + @Nullable + public StatComponent findComponent(String path) { + String[] split = path.split("\\."); + + AbstractObjectComponent current = this; + int n = split.length - 1; + for (int i = 0; i < n; i++) { + StatComponent next = getComponent(split[i]); + if (next == null || !(next instanceof AbstractObjectComponent)) + return null; + + current = (AbstractObjectComponent) next; + } + + return current.getComponent(split[n]); + } + + @Nullable + public abstract StatComponent getComponent(String path); + + +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponent.java b/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponent.java new file mode 100644 index 00000000..1f5c9360 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/component/type/DoubleComponent.java @@ -0,0 +1,17 @@ +package net.Indyuce.mmoitems.stat.component.type; + +import net.Indyuce.mmoitems.stat.component.Mergeable; +import net.Indyuce.mmoitems.stat.component.StatComponent; + +public class DoubleComponent extends StatComponent implements Mergeable { + private double value; + + public DoubleComponent(String path) { + super(path); + } + + @Override + public void merge(DoubleComponent component) { + value += component.value; + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponent.java b/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponent.java new file mode 100644 index 00000000..945e9e7e --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/stat/component/type/ObjectComponent.java @@ -0,0 +1,33 @@ +package net.Indyuce.mmoitems.stat.component.type; + +import net.Indyuce.mmoitems.stat.component.StatComponent; +import net.Indyuce.mmoitems.stat.component.Upgradable; +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 AbstractObjectComponent implements Upgradable { + private final Map components = new HashMap<>(); + + public ObjectComponent(String path) { + super(path); + } + + @Override + @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(); + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java index d48b4b91..33c1142e 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java @@ -39,15 +39,23 @@ import java.util.regex.Pattern; public class DoubleStat extends ItemStat implements Upgradable, Previewable { - private static final DecimalFormat digit = new DecimalFormat("0.####"); + private final boolean moreIsBetter; - public DoubleStat(String id, Material mat, String name, String[] lore) { - super(id, mat, name, lore, new String[] { "!miscellaneous", "!block", "all" }); - } + private static final DecimalFormat digit = new DecimalFormat("0.####"); - public DoubleStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { - super(id, mat, name, lore, types, materials); - } + 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, Material... materials) { + this(id, mat, name, lore, types, true, materials); + } + + 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; + } /** * @return If this stat supports negatives stat values @@ -67,7 +75,7 @@ public class DoubleStat extends ItemStat implements Upgradable, Previewable { * Usually, a greater magnitude of stat benefits the player (more health, more attack damage). *

However, its not impossible for a stat to be evil instead, who knows? */ - public boolean moreIsBetter() { return true; } + public boolean moreIsBetter() { return moreIsBetter; } @Override public RandomStatData whenInitialized(Object object) { @@ -109,7 +117,7 @@ public class DoubleStat extends ItemStat implements Upgradable, Previewable { // Display in lore if (value != 0 || upgradeShift != 0) { - String loreInsert = formatPath(MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter(), value * multiplyWhenDisplaying()); + String loreInsert = formatPath(MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter, value * multiplyWhenDisplaying()); if (upgradeShift != 0) loreInsert += MythicLib.plugin.parseColors(UpgradeTemplate.getUpgradeChangeSuffix(plus(upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying()))); item.getLore().insert(getPath(), loreInsert); diff --git a/src/main/java/net/Indyuce/mmoitems/stat/type/EvilDoubleStat.java b/src/main/java/net/Indyuce/mmoitems/stat/type/EvilDoubleStat.java deleted file mode 100644 index ce8bd89f..00000000 --- a/src/main/java/net/Indyuce/mmoitems/stat/type/EvilDoubleStat.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.Indyuce.mmoitems.stat.type; - -import org.bukkit.Material; - -public class EvilDoubleStat extends DoubleStat { - - public EvilDoubleStat(String id, Material mat, String name, String[] lore) { super(id, mat, name, lore); } - public EvilDoubleStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) { super(id, mat, name, lore, types, materials); } - - @Override public boolean moreIsBetter() { return false; } -}