mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Small refactor on stat histories preparing MI7
This commit is contained in:
parent
d2033b8030
commit
152518532c
@ -57,14 +57,10 @@ public class MMOItemBuilder extends Buildable<MMOItem> {
|
||||
this.tier = tier;
|
||||
|
||||
// Either use provided tier or look into the template base data
|
||||
tier = tier != null ? tier
|
||||
: template.getBaseItemData().containsKey(ItemStats.TIER) ? MMOItems.plugin.getTiers().get(template.getBaseItemData().get(ItemStats.TIER).toString())
|
||||
: null;
|
||||
tier = tier != null ? tier : template.getBaseItemData().containsKey(ItemStats.TIER) ? MMOItems.plugin.getTiers().get(template.getBaseItemData().get(ItemStats.TIER).toString()) : null;
|
||||
|
||||
// Capacity is not final as it keeps lowering as modifiers are selected
|
||||
capacity = (template.hasModifierCapacity() ? template.getModifierCapacity() :
|
||||
tier != null && tier.hasCapacity() ? tier.getModifierCapacity() :
|
||||
MMOItems.plugin.getLanguage().defaultItemCapacity).calculate(level);
|
||||
capacity = (template.hasModifierCapacity() ? template.getModifierCapacity() : tier != null && tier.hasCapacity() ? tier.getModifierCapacity() : MMOItems.plugin.getLanguage().defaultItemCapacity).calculate(level);
|
||||
mmoitem = new MMOItem(template.getType(), template.getId());
|
||||
|
||||
// Apply base item data
|
||||
@ -118,8 +114,7 @@ public class MMOItemBuilder extends Buildable<MMOItem> {
|
||||
|
||||
// Get name data
|
||||
StatHistory hist = StatHistory.from(mmoitem, ItemStats.NAME);
|
||||
if (!mmoitem.hasData(ItemStats.NAME))
|
||||
mmoitem.setData(ItemStats.NAME, new NameData("Item"));
|
||||
if (!mmoitem.hasData(ItemStats.NAME)) mmoitem.setData(ItemStats.NAME, new NameData("Item"));
|
||||
|
||||
nameModifiers.forEach((obs, mod) -> {
|
||||
|
||||
@ -148,18 +143,10 @@ public class MMOItemBuilder extends Buildable<MMOItem> {
|
||||
* @param stat Stat owning the data
|
||||
* @param data StatData to apply
|
||||
*/
|
||||
public void applyData(ItemStat stat, StatData data) {
|
||||
|
||||
// Is the data mergeable? Apply as External SH
|
||||
if (mmoitem.hasData(stat) && data instanceof Mergeable) {
|
||||
|
||||
((Mergeable) mmoitem.getData(stat)).merge(data);
|
||||
|
||||
} else {
|
||||
|
||||
// Set, there is no more.
|
||||
mmoitem.setData(stat, data);
|
||||
}
|
||||
public void applyData(@NotNull ItemStat stat, @NotNull StatData data) {
|
||||
final StatData found = mmoitem.getData(stat);
|
||||
if (found != null && found instanceof Mergeable) ((Mergeable) found).mergeWith(data);
|
||||
else mmoitem.setData(stat, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,8 +158,7 @@ public class MMOItemBuilder extends Buildable<MMOItem> {
|
||||
public void addModifierData(@NotNull ItemStat stat, @NotNull StatData data, @NotNull UUID uuid) {
|
||||
if (stat.getClearStatData() instanceof Mergeable)
|
||||
StatHistory.from(mmoitem, stat).registerModifierBonus(uuid, data);
|
||||
else
|
||||
mmoitem.setData(stat, data);
|
||||
else mmoitem.setData(stat, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,8 +192,7 @@ public class MMOItemBuilder extends Buildable<MMOItem> {
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static Collection<TemplateModifier> rollModifiers(@NotNull MMOItemTemplate template) {
|
||||
if (!template.hasOption(TemplateOption.ROLL_MODIFIER_CHECK_ORDER))
|
||||
return template.getModifiers().values();
|
||||
if (!template.hasOption(TemplateOption.ROLL_MODIFIER_CHECK_ORDER)) return template.getModifiers().values();
|
||||
|
||||
List<TemplateModifier> modifiers = new ArrayList<>(template.getModifiers().values());
|
||||
Collections.shuffle(modifiers);
|
||||
|
@ -378,7 +378,7 @@ public class NumericStatFormula implements RandomStatData<DoubleData>, Updatable
|
||||
//UPGRD//MMOItems.log("\u00a7a +\u00a77 Acceptable Range --- kept");
|
||||
|
||||
// Just clone I guess
|
||||
return original.cloneData();
|
||||
return original.clone();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,4 +15,9 @@ public class CrazyEnchantsData implements StatData {
|
||||
public Map<CEnchantment, Integer> getEnchants() {
|
||||
return enchants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return enchants.isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -8,4 +8,9 @@ import java.util.Map;
|
||||
|
||||
public class AdvancedEnchantMap implements StatData {
|
||||
public final Map<String, Integer> enchants = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return enchants.isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package net.Indyuce.mmoitems.stat.component;
|
||||
|
||||
/**
|
||||
* @deprecated Not used yet
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Mergeable<T extends StatComponent> {
|
||||
|
||||
public void merge(T t);
|
||||
|
@ -1,5 +1,9 @@
|
||||
package net.Indyuce.mmoitems.stat.component;
|
||||
|
||||
/**
|
||||
* @deprecated Not used yet
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class StatComponent {
|
||||
private final String path;
|
||||
|
||||
|
@ -1,4 +1,8 @@
|
||||
package net.Indyuce.mmoitems.stat.component;
|
||||
|
||||
/**
|
||||
* @deprecated Not used yet
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Upgradable {
|
||||
}
|
||||
|
@ -3,6 +3,10 @@ package net.Indyuce.mmoitems.stat.component.type;
|
||||
import net.Indyuce.mmoitems.stat.component.StatComponent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @deprecated Not used yet
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractObjectComponent extends StatComponent {
|
||||
public AbstractObjectComponent(String path) {
|
||||
super(path);
|
||||
|
@ -2,7 +2,10 @@ package net.Indyuce.mmoitems.stat.component.type;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.component.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.component.StatComponent;
|
||||
|
||||
/**
|
||||
* @deprecated Not used yet
|
||||
*/
|
||||
@Deprecated
|
||||
public class DoubleComponent extends StatComponent implements Mergeable<DoubleComponent> {
|
||||
private double value;
|
||||
|
||||
|
@ -9,6 +9,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @deprecated Not used yet
|
||||
*/
|
||||
@Deprecated
|
||||
public class ObjectComponent extends AbstractObjectComponent implements Upgradable {
|
||||
private final Map<String, StatComponent> components = new HashMap<>();
|
||||
|
||||
|
@ -1,64 +1,83 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AbilityListData implements StatData, Mergeable<AbilityListData> {
|
||||
@NotNull private final Set<AbilityData> abilities = new LinkedHashSet<>();
|
||||
private final List<AbilityData> abilities = new ArrayList<>();
|
||||
|
||||
public AbilityListData(@NotNull AbilityData... abilities) {
|
||||
add(abilities);
|
||||
}
|
||||
public AbilityListData(@NotNull AbilityData... abilities) {
|
||||
add(abilities);
|
||||
}
|
||||
|
||||
public AbilityListData(@NotNull Set<AbilityData> abilit) { add(abilit); }
|
||||
public AbilityListData(@NotNull Collection<AbilityData> abilities) {
|
||||
add(abilities);
|
||||
}
|
||||
|
||||
public void add(@NotNull AbilityData... abilities) {
|
||||
this.abilities.addAll(Arrays.asList(abilities));
|
||||
}
|
||||
public void add(@NotNull AbilityData... abilities) {
|
||||
this.abilities.addAll(Arrays.asList(abilities));
|
||||
}
|
||||
|
||||
public void add(@NotNull Set<AbilityData> abilit) { abilities.addAll(abilit); }
|
||||
public void add(@NotNull Collection<AbilityData> abilit) {
|
||||
abilities.addAll(abilit);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<AbilityData> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
@NotNull
|
||||
public Set<AbilityData> getAbilities() {
|
||||
return new HashSet<>(abilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(@NotNull AbilityListData data) {
|
||||
abilities.addAll(data.abilities);
|
||||
}
|
||||
@Override
|
||||
public void mergeWith(@NotNull AbilityListData targetData) {
|
||||
abilities.addAll(targetData.abilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AbilityListData)) { return false; }
|
||||
@NotNull
|
||||
@Override
|
||||
public AbilityListData clone() {
|
||||
return new AbilityListData();
|
||||
}
|
||||
|
||||
// Different number of abilities? Not equal
|
||||
if (getAbilities().size() != ((AbilityListData) obj).getAbilities().size()) { return false; }
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AbilityListData)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Examine each
|
||||
for (AbilityData ab : ((AbilityListData) obj).getAbilities()) {
|
||||
// Different number of abilities? Not equal
|
||||
if (getAbilities().size() != ((AbilityListData) obj).getAbilities().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ab == null) { continue; }
|
||||
// Examine each
|
||||
for (AbilityData ab : ((AbilityListData) obj).getAbilities()) {
|
||||
|
||||
boolean unmatched = true;
|
||||
for (AbilityData thi : getAbilities()) { if (ab.equals(thi)) { unmatched = false; break; } }
|
||||
if (ab == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extraneous ability found, not equal.
|
||||
if (unmatched) { return false; }
|
||||
}
|
||||
boolean unmatched = true;
|
||||
for (AbilityData thi : getAbilities()) {
|
||||
if (ab.equals(thi)) {
|
||||
unmatched = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true; }
|
||||
// Extraneous ability found, not equal.
|
||||
if (unmatched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull AbilityListData cloneData() { return new AbilityListData(getAbilities()); }
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return abilities.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return abilities.isEmpty();
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import org.bukkit.Particle;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class ArrowParticlesData implements StatData, RandomStatData<ArrowParticlesData> {
|
||||
private final Particle particle;
|
||||
|
@ -1,32 +1,33 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandListData implements StatData, Mergeable, RandomStatData<CommandListData> {
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandListData implements StatData, Mergeable<CommandListData>, RandomStatData<CommandListData> {
|
||||
@NotNull
|
||||
private final List<CommandData> commands;
|
||||
private final List<CommandData> commands = new ArrayList<>();
|
||||
|
||||
public CommandListData(@NotNull List<CommandData> commands) {
|
||||
this.commands = commands;
|
||||
add(commands);
|
||||
}
|
||||
|
||||
public CommandListData(CommandData... commands) {
|
||||
this(new ArrayList<>());
|
||||
|
||||
add(commands);
|
||||
}
|
||||
|
||||
public void add(CommandData... commands) {
|
||||
for (CommandData data : commands)
|
||||
this.commands.add(data);
|
||||
for (CommandData data : commands) this.commands.add(data);
|
||||
}
|
||||
|
||||
public void add(Collection<CommandData> commands) {
|
||||
this.commands.addAll(commands);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -43,13 +44,13 @@ public class CommandListData implements StatData, Mergeable, RandomStatData<Comm
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof CommandListData, "Cannot merge two different stat data types");
|
||||
commands.addAll(((CommandListData) data).commands);
|
||||
public void mergeWith(CommandListData data) {
|
||||
commands.addAll(data.commands);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public @NotNull StatData cloneData() {
|
||||
public CommandListData clone() {
|
||||
return new CommandListData(commands);
|
||||
}
|
||||
|
||||
@ -60,6 +61,6 @@ public class CommandListData implements StatData, Mergeable, RandomStatData<Comm
|
||||
|
||||
@Override
|
||||
public CommandListData randomize(MMOItemBuilder builder) {
|
||||
return new CommandListData(new ArrayList<>(commands));
|
||||
return clone();
|
||||
}
|
||||
}
|
@ -27,12 +27,12 @@ public class DoubleData implements StatData, Mergeable<DoubleData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(DoubleData data) {
|
||||
public void mergeWith(DoubleData data) {
|
||||
value += data.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleData cloneData() { return new DoubleData(getValue()); }
|
||||
public DoubleData clone() { return new DoubleData(value); }
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
@ -42,8 +42,9 @@ public class DoubleData implements StatData, Mergeable<DoubleData> {
|
||||
@Override
|
||||
public String toString() { return String.valueOf(getValue()); }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof DoubleData)) { return false; }
|
||||
return ((DoubleData) obj).getValue() == getValue(); }
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof DoubleData)) return false;
|
||||
return ((DoubleData) obj).getValue() == getValue();
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.util.ElementStatType;
|
||||
import net.Indyuce.mmoitems.util.Pair;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@ -13,7 +12,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ElementListData implements Mergeable {
|
||||
public class ElementListData implements StatData, Mergeable<ElementListData> {
|
||||
private final Map<Pair<Element, ElementStatType>, Double> stats = new LinkedHashMap<>();
|
||||
|
||||
public double getStat(Element element, ElementStatType statType) {
|
||||
@ -30,16 +29,14 @@ public class ElementListData implements Mergeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof ElementListData, "Cannot merge two different stat data types");
|
||||
ElementListData extra = (ElementListData) data;
|
||||
public void mergeWith(@NotNull ElementListData targetData) {
|
||||
//Includes old values if any, fixes stacking of element double values I believe - Kilo
|
||||
extra.stats.forEach((key, value) -> stats.put(key, value + stats.getOrDefault(key,0.0)));
|
||||
targetData.stats.forEach((key, value) -> stats.put(key, value + stats.getOrDefault(key,0.0)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StatData cloneData() {
|
||||
public ElementListData clone() {
|
||||
ElementListData ret = new ElementListData();
|
||||
for (Map.Entry<Pair<Element, ElementStatType>, Double> entry : stats.entrySet()) {
|
||||
Pair<Element, ElementStatType> key = entry.getKey();
|
||||
|
@ -13,157 +13,188 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class EnchantListData implements StatData, Mergeable {
|
||||
private final Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
public class EnchantListData implements StatData, Mergeable<EnchantListData> {
|
||||
private final Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
|
||||
public Set<Enchantment> getEnchants() {
|
||||
return enchants.keySet();
|
||||
}
|
||||
@NotNull
|
||||
public Set<Enchantment> getEnchants() {
|
||||
return enchants.keySet();
|
||||
}
|
||||
|
||||
public int getLevel(@NotNull Enchantment enchant) {
|
||||
@Nullable Integer found = enchants.get(enchant);
|
||||
return found == null ? 0 : found;
|
||||
}
|
||||
public int getLevel(@NotNull Enchantment enchant) {
|
||||
@Nullable Integer found = enchants.get(enchant);
|
||||
return found == null ? 0 : found;
|
||||
}
|
||||
|
||||
public void addEnchant(Enchantment enchant, int level) {
|
||||
|
||||
// Ignore lvl 0 enchants :wazowskibruhmoment:
|
||||
if (level <= 0) { enchants.remove(enchant); } else { enchants.put(enchant, level);}
|
||||
// Ignore lvl 0 enchants :wazowskibruhmoment:
|
||||
if (level <= 0) {
|
||||
enchants.remove(enchant);
|
||||
} else {
|
||||
enchants.put(enchant, level);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() { enchants.clear(); }
|
||||
public void clear() {
|
||||
enchants.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof EnchantListData)) { return false; }
|
||||
if (((EnchantListData) obj).enchants.size() != enchants.size()) { return false; }
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof EnchantListData)) {
|
||||
return false;
|
||||
}
|
||||
if (((EnchantListData) obj).enchants.size() != enchants.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Enchantment e : getEnchants()) {
|
||||
for (Enchantment e : getEnchants()) {
|
||||
|
||||
// Compare
|
||||
if (getLevel(e) != ((EnchantListData) obj).getLevel(e)) { return false; } }
|
||||
return true;
|
||||
}
|
||||
// Compare
|
||||
if (getLevel(e) != ((EnchantListData) obj).getLevel(e)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof EnchantListData, "Cannot merge two different stat data types");
|
||||
@Override
|
||||
public void mergeWith(@NotNull EnchantListData targetData) {
|
||||
for (Enchantment enchant : targetData.getEnchants())
|
||||
addEnchant(enchant, Math.max(enchants.getOrDefault(enchant, 0), targetData.getLevel(enchant)));
|
||||
}
|
||||
|
||||
final EnchantListData enchantList = (EnchantListData) data;
|
||||
for (Enchantment enchant : enchantList.getEnchants())
|
||||
addEnchant(enchant, Math.max(enchants.getOrDefault(enchant, 0), enchantList.getLevel(enchant)));
|
||||
}
|
||||
@Override
|
||||
@NotNull
|
||||
public EnchantListData clone() {
|
||||
|
||||
@Override
|
||||
public @NotNull StatData cloneData() {
|
||||
// Start Fresh
|
||||
EnchantListData ret = new EnchantListData();
|
||||
|
||||
// Start Fresh
|
||||
EnchantListData ret = new EnchantListData();
|
||||
// Enchant
|
||||
for (Enchantment enchant : enchants.keySet()) {
|
||||
ret.addEnchant(enchant, enchants.getOrDefault(enchant, 0));
|
||||
}
|
||||
|
||||
// Enchant
|
||||
for (Enchantment enchant : enchants.keySet()) { ret.addEnchant(enchant, enchants.getOrDefault(enchant, 0)); }
|
||||
// Thats it
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Thats it
|
||||
return ret;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("EnchantList{");
|
||||
final AtomicBoolean check = new AtomicBoolean();
|
||||
enchants.forEach((enchant, lvl) -> {
|
||||
if (check.get()) builder.append(",");
|
||||
builder.append(enchant + "=" + lvl);
|
||||
check.set(true);
|
||||
});
|
||||
builder.append("}");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (int level : enchants.values())
|
||||
if (level > 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (int level : enchants.values())
|
||||
if (level > 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo We cannot yet assume (for a few months) that the Original Enchantment Data
|
||||
* registered into the Stat History is actually true to the template (since it may
|
||||
* be the enchantments of an old-enchanted item, put by the player).
|
||||
* <br><br>
|
||||
* Thus this block of code checks the enchantment data of the newly generated
|
||||
* MMOItem and follows the following logic to give our best guess if the Original
|
||||
* stats are actually Original:
|
||||
* <br><br>
|
||||
* 1: Is the item unenchantable and unrepairable? Then they must be original
|
||||
* <br><br>
|
||||
* 2: Does the template have no enchantments? Then they must be external
|
||||
* <br><br>
|
||||
* 3: Does the template have this enchantment at an unobtainable level? Then it must be original
|
||||
* <br><br>
|
||||
* 4: Does the template have this enchantment at a lesser level? Then it must be external (player upgraded it)
|
||||
* <br><br>
|
||||
* Original: Included within the template at first creation
|
||||
* External: Enchanted manually by a player
|
||||
*
|
||||
* @param mmoItem The item, to provide context for adequate guessing.
|
||||
*
|
||||
*/
|
||||
public void identifyTrueOriginalEnchantments(@NotNull MMOItem mmoItem) {
|
||||
/**
|
||||
* todo We cannot yet assume (for a few months) that the Original Enchantment Data
|
||||
* registered into the Stat History is actually true to the template (since it may
|
||||
* be the enchantments of an old-enchanted item, put by the player).
|
||||
* <br><br>
|
||||
* Thus this block of code checks the enchantment data of the newly generated
|
||||
* MMOItem and follows the following logic to give our best guess if the Original
|
||||
* stats are actually Original:
|
||||
* <br><br>
|
||||
* 1: Is the item unenchantable and unrepairable? Then they must be original
|
||||
* <br><br>
|
||||
* 2: Does the template have no enchantments? Then they must be external
|
||||
* <br><br>
|
||||
* 3: Does the template have this enchantment at an unobtainable level? Then it must be original
|
||||
* <br><br>
|
||||
* 4: Does the template have this enchantment at a lesser level? Then it must be external (player upgraded it)
|
||||
* <br><br>
|
||||
* Original: Included within the template at first creation
|
||||
* External: Enchanted manually by a player
|
||||
*
|
||||
* @param mmoItem The item, to provide context for adequate guessing.
|
||||
*/
|
||||
public void identifyTrueOriginalEnchantments(@NotNull MMOItem mmoItem) {
|
||||
|
||||
//RFG//MMOItems.log(" \u00a7b> \u00a77Original Enchantments Upkeep");
|
||||
//RFG//MMOItems.log(" \u00a7b> \u00a77Original Enchantments Upkeep");
|
||||
|
||||
// 1: The item is unenchantable and unrepairable? Cancel this operation, the cached are Original
|
||||
if (mmoItem.hasData(ItemStats.DISABLE_ENCHANTING) && mmoItem.hasData(ItemStats.DISABLE_REPAIRING)) {
|
||||
//RFG//MMOItems.log(" \u00a7bType-1 \u00a77Original Identification ~ no transfer");
|
||||
// 1: The item is unenchantable and unrepairable? Cancel this operation, the cached are Original
|
||||
if (mmoItem.hasData(ItemStats.DISABLE_ENCHANTING) && mmoItem.hasData(ItemStats.DISABLE_REPAIRING)) {
|
||||
//RFG//MMOItems.log(" \u00a7bType-1 \u00a77Original Identification ~ no transfer");
|
||||
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mmoItem.hasData(ItemStats.ENCHANTS)) { mmoItem.setData(ItemStats.ENCHANTS, new EnchantListData());}
|
||||
if (!mmoItem.hasData(ItemStats.ENCHANTS)) {
|
||||
mmoItem.setData(ItemStats.ENCHANTS, new EnchantListData());
|
||||
}
|
||||
|
||||
EnchantListData mmoData = (EnchantListData) mmoItem.getData(ItemStats.ENCHANTS);
|
||||
EnchantListData mmoData = (EnchantListData) mmoItem.getData(ItemStats.ENCHANTS);
|
||||
|
||||
// 2: If it has data (It always has) and the amount of enchants is zero, the cached are Extraneous
|
||||
if (mmoData.getEnchants().size() == 0) {
|
||||
//RFG//MMOItems.log(" \u00a73Type-2 \u00a77Extraneous Identification ~ all transferred");
|
||||
// 2: If it has data (It always has) and the amount of enchants is zero, the cached are Extraneous
|
||||
if (mmoData.getEnchants().size() == 0) {
|
||||
//RFG//MMOItems.log(" \u00a73Type-2 \u00a77Extraneous Identification ~ all transferred");
|
||||
|
||||
// All right, lets add those to cached enchantments
|
||||
mmoItem.mergeData(ItemStats.ENCHANTS,this, null);
|
||||
return;
|
||||
}
|
||||
// All right, lets add those to cached enchantments
|
||||
mmoItem.mergeData(ItemStats.ENCHANTS, this, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Which enchantments are deemed external, after all?
|
||||
EnchantListData processed = new EnchantListData();
|
||||
// Which enchantments are deemed external, after all?
|
||||
EnchantListData processed = new EnchantListData();
|
||||
|
||||
// Identify material
|
||||
mmoItem.hasData(ItemStats.MATERIAL); MaterialData mData = (MaterialData) mmoItem.getData(ItemStats.MATERIAL); Material mat = mData.getMaterial();
|
||||
// Identify material
|
||||
mmoItem.hasData(ItemStats.MATERIAL);
|
||||
MaterialData mData = (MaterialData) mmoItem.getData(ItemStats.MATERIAL);
|
||||
Material mat = mData.getMaterial();
|
||||
|
||||
// 3 & 4: Lets examine every stat
|
||||
for (Enchantment e : getEnchants()) {
|
||||
//RFG//MMOItems.log(" \u00a7b = \u00a77Per Enchant - \u00a7f" + e.getName());
|
||||
// 3 & 4: Lets examine every stat
|
||||
for (Enchantment e : getEnchants()) {
|
||||
//RFG//MMOItems.log(" \u00a7b = \u00a77Per Enchant - \u00a7f" + e.getName());
|
||||
|
||||
// Lets see hmm
|
||||
int current = getLevel(e);
|
||||
int updated = mmoData.getLevel(e);
|
||||
//RFG//MMOItems.log(" \u00a73 <=: \u00a77Current \u00a7f" + current);
|
||||
//RFG//MMOItems.log(" \u00a73 <=: \u00a77Updated \u00a7f" + updated);
|
||||
// Lets see hmm
|
||||
int current = getLevel(e);
|
||||
int updated = mmoData.getLevel(e);
|
||||
//RFG//MMOItems.log(" \u00a73 <=: \u00a77Current \u00a7f" + current);
|
||||
//RFG//MMOItems.log(" \u00a73 <=: \u00a77Updated \u00a7f" + updated);
|
||||
|
||||
// 3: Is it at an unobtainable level? Then its Original
|
||||
if (updated > e.getMaxLevel() || !e.getItemTarget().includes(mat)) {
|
||||
//RFG//MMOItems.log(" \u00a7bType-3 \u00a77Original Identification ~ Impossible through vanilla");
|
||||
// 3: Is it at an unobtainable level? Then its Original
|
||||
if (updated > e.getMaxLevel() || !e.getItemTarget().includes(mat)) {
|
||||
//RFG//MMOItems.log(" \u00a7bType-3 \u00a77Original Identification ~ Impossible through vanilla");
|
||||
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 4: Is it at a lesser level? Player must have enchanted, take them as External
|
||||
if (updated < current) {
|
||||
//RFG//MMOItems.log(" \u00a73Type-4 \u00a77Extraneous Identification ~ Improvement from the Template");
|
||||
processed.addEnchant(e, current);
|
||||
// 4: Is it at a lesser level? Player must have enchanted, take them as External
|
||||
if (updated < current) {
|
||||
//RFG//MMOItems.log(" \u00a73Type-4 \u00a77Extraneous Identification ~ Improvement from the Template");
|
||||
processed.addEnchant(e, current);
|
||||
|
||||
//noinspection UnnecessaryContinue
|
||||
continue;
|
||||
}
|
||||
//noinspection UnnecessaryContinue
|
||||
continue;
|
||||
}
|
||||
|
||||
//RFG//MMOItems.log(" \u00a73Type-5 \u00a77Original Identification ~ Not improved from the template");
|
||||
}
|
||||
//RFG//MMOItems.log(" \u00a73Type-5 \u00a77Original Identification ~ Not improved from the template");
|
||||
}
|
||||
|
||||
// Finish merge
|
||||
if (!processed.isClear()) {
|
||||
// Finish merge
|
||||
if (!processed.isEmpty()) {
|
||||
|
||||
// As Extraneosu
|
||||
mmoItem.mergeData(ItemStats.ENCHANTS, processed, null);
|
||||
}
|
||||
}
|
||||
// As Extraneosu
|
||||
mmoItem.mergeData(ItemStats.ENCHANTS, processed, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -126,7 +126,7 @@ public class GemSocketsData implements StatData, Mergeable<GemSocketsData>, Rand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(GemSocketsData data) {
|
||||
public void mergeWith(GemSocketsData data) {
|
||||
|
||||
// Combine both actual gems, and empty slots
|
||||
emptySlots.addAll(data.emptySlots);
|
||||
@ -134,7 +134,7 @@ public class GemSocketsData implements StatData, Mergeable<GemSocketsData>, Rand
|
||||
}
|
||||
|
||||
@Override
|
||||
public GemSocketsData cloneData() {
|
||||
public GemSocketsData clone() {
|
||||
|
||||
// Clone empty slots
|
||||
GemSocketsData ret = new GemSocketsData(new ArrayList<>(emptySlots));
|
||||
|
@ -1,15 +1,13 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class PotionEffectListData implements StatData, Mergeable<PotionEffectListData> {
|
||||
private final List<PotionEffectData> effects = new ArrayList<>();
|
||||
|
||||
@ -20,6 +18,41 @@ public class PotionEffectListData implements StatData, Mergeable<PotionEffectLis
|
||||
// PotionEffectData(config.getConfigurationSection(key)));
|
||||
// }
|
||||
|
||||
public PotionEffectListData(PotionEffectData... effects) {
|
||||
add(effects);
|
||||
}
|
||||
|
||||
public PotionEffectListData(Collection<PotionEffectData> effects) {
|
||||
add(effects);
|
||||
}
|
||||
|
||||
public void add(PotionEffectData... effects) {
|
||||
for (PotionEffectData el : effects) this.effects.add(el);
|
||||
}
|
||||
|
||||
public void add(Collection<PotionEffectData> effects) {
|
||||
this.effects.addAll(effects);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<PotionEffectData> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return effects.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeWith(PotionEffectListData data) {
|
||||
effects.addAll(data.effects);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PotionEffectListData clone() { return new PotionEffectListData(effects); }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof PotionEffectListData)) { return false; }
|
||||
@ -41,29 +74,4 @@ public class PotionEffectListData implements StatData, Mergeable<PotionEffectLis
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public PotionEffectListData(PotionEffectData... effects) {
|
||||
add(effects);
|
||||
}
|
||||
|
||||
public void add(PotionEffectData... effects) {
|
||||
this.effects.addAll(Arrays.asList(effects));
|
||||
}
|
||||
|
||||
public List<PotionEffectData> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return effects.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(PotionEffectListData data) {
|
||||
effects.addAll(data.effects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PotionEffectListData cloneData() { return new PotionEffectListData(getEffects().toArray(new PotionEffectData[0])); }
|
||||
}
|
||||
|
@ -77,6 +77,11 @@ public class ProjectileParticlesData implements StatData, RandomStatData<Project
|
||||
return blue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isColorable(Particle particle) {
|
||||
return particle == Particle.REDSTONE || particle == Particle.SPELL_MOB || particle == Particle.SPELL_MOB_AMBIENT || particle == Particle.NOTE;
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ public class RequiredLevelData extends DoubleData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(DoubleData data) {
|
||||
public void mergeWith(DoubleData data) {
|
||||
final boolean additiveMerge = MMOItems.plugin.getConfig().getBoolean("stat-merging.additive-levels", false);
|
||||
setValue(additiveMerge ? data.getValue() + getValue() : Math.max(data.getValue(), getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleData cloneData() {
|
||||
public DoubleData clone() {
|
||||
return new RequiredLevelData(getValue());
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RestoreData implements StatData, Mergeable {
|
||||
public class RestoreData implements StatData, Mergeable<RestoreData> {
|
||||
private double health, food, saturation;
|
||||
|
||||
public RestoreData(double health, double food, double saturation) {
|
||||
@ -44,17 +44,16 @@ public class RestoreData implements StatData, Mergeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof RestoreData, "Cannot merge two different stat data types");
|
||||
health += ((RestoreData) data).health;
|
||||
food += ((RestoreData) data).food;
|
||||
saturation += ((RestoreData) data).saturation;
|
||||
public void mergeWith(@NotNull RestoreData targetData) {
|
||||
health += targetData.health;
|
||||
food += targetData.food;
|
||||
saturation += targetData.saturation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull
|
||||
StatData cloneData() {
|
||||
return new RestoreData(getHealth(), getFood(), getSaturation());
|
||||
@NotNull
|
||||
public RestoreData clone() {
|
||||
return new RestoreData(health, food, saturation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,43 +1,62 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
public class ShieldPatternData implements StatData, RandomStatData<ShieldPatternData> {
|
||||
private final DyeColor base;
|
||||
private final List<Pattern> patterns = new ArrayList<>();
|
||||
private DyeColor base;
|
||||
private final List<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
public ShieldPatternData(DyeColor base, Pattern... patterns) {
|
||||
this.base = base;
|
||||
this.patterns.addAll(Arrays.asList(patterns));
|
||||
}
|
||||
public ShieldPatternData(DyeColor base, Pattern... patterns) {
|
||||
this.base = base;
|
||||
this.patterns.addAll(Arrays.asList(patterns));
|
||||
}
|
||||
|
||||
public DyeColor getBaseColor() {
|
||||
return base;
|
||||
}
|
||||
public void setBase(@Nullable DyeColor base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public List<Pattern> getPatterns() {
|
||||
return patterns;
|
||||
}
|
||||
@Nullable
|
||||
public DyeColor getBaseColor() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public void add(Pattern pattern) {
|
||||
patterns.add(pattern);
|
||||
}
|
||||
@NotNull
|
||||
public List<Pattern> getPatterns() {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public void addAll(List<Pattern> patterns) {
|
||||
this.patterns.addAll(patterns);
|
||||
}
|
||||
public void add(Pattern pattern) {
|
||||
patterns.add(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShieldPatternData randomize(MMOItemBuilder builder) {
|
||||
return this;
|
||||
}
|
||||
public void addAll(List<Pattern> patterns) {
|
||||
this.patterns.addAll(patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShieldPatternData clone() {
|
||||
final ShieldPatternData clone = new ShieldPatternData(base);
|
||||
clone.patterns.addAll(patterns);
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return base == null && patterns.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShieldPatternData randomize(MMOItemBuilder builder) {
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,24 +1,41 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SkullTextureData implements StatData, RandomStatData<SkullTextureData> {
|
||||
private final GameProfile profile;
|
||||
private GameProfile profile;
|
||||
|
||||
public SkullTextureData(GameProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
public SkullTextureData(GameProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public GameProfile getGameProfile() {
|
||||
return profile;
|
||||
}
|
||||
@Nullable
|
||||
public GameProfile getGameProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkullTextureData randomize(MMOItemBuilder builder) {
|
||||
return this;
|
||||
}
|
||||
public void setGameProfile(@Nullable GameProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SkullTextureData clone() {
|
||||
return new SkullTextureData(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return profile == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkullTextureData randomize(MMOItemBuilder builder) {
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,51 +1,61 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
public class SoulboundData implements StatData {
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final int level;
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final int level;
|
||||
|
||||
public SoulboundData(Player player, int level) {
|
||||
this(player.getUniqueId(), player.getName(), level);
|
||||
}
|
||||
public SoulboundData(Player player, int level) {
|
||||
this(player.getUniqueId(), player.getName(), level);
|
||||
}
|
||||
|
||||
public SoulboundData(UUID uuid, String name, int level) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
}
|
||||
public SoulboundData(UUID uuid, String name, int level) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public SoulboundData(JsonObject object) {
|
||||
uuid = UUID.fromString(object.get("UUID").getAsString());
|
||||
name = object.get("Name").getAsString();
|
||||
level = object.get("Level").getAsInt();
|
||||
}
|
||||
public SoulboundData(JsonObject object) {
|
||||
uuid = UUID.fromString(object.get("UUID").getAsString());
|
||||
name = object.get("Name").getAsString();
|
||||
level = object.get("Level").getAsInt();
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public JsonObject toJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("Level", level);
|
||||
object.addProperty("Name", name);
|
||||
object.addProperty("UUID", uuid.toString());
|
||||
return object;
|
||||
}
|
||||
public JsonObject toJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("Level", level);
|
||||
object.addProperty("Name", name);
|
||||
object.addProperty("UUID", uuid.toString());
|
||||
return object;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StatData clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -5,83 +5,93 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class SoundListData implements StatData, Mergeable, RandomStatData<SoundListData> {
|
||||
private final Map<CustomSound, SoundData> sounds;
|
||||
public class SoundListData implements StatData, Mergeable<SoundListData>, RandomStatData<SoundListData> {
|
||||
private final Map<CustomSound, SoundData> sounds = new LinkedHashMap<>();
|
||||
|
||||
public SoundListData() {
|
||||
this(new HashMap<>());
|
||||
}
|
||||
public SoundListData() {
|
||||
}
|
||||
|
||||
public SoundListData(Map<CustomSound, SoundData> sounds) {
|
||||
this.sounds = sounds;
|
||||
}
|
||||
public SoundListData(@NotNull Map<CustomSound, SoundData> sounds) {
|
||||
sounds.forEach(this.sounds::put);
|
||||
}
|
||||
|
||||
public Set<CustomSound> getCustomSounds() {
|
||||
return sounds.keySet();
|
||||
}
|
||||
public Set<CustomSound> getCustomSounds() {
|
||||
return sounds.keySet();
|
||||
}
|
||||
|
||||
public Map<CustomSound, SoundData> mapData() {
|
||||
return sounds;
|
||||
}
|
||||
public Map<CustomSound, SoundData> mapData() {
|
||||
return sounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Sound used, or null if none
|
||||
*/
|
||||
@Nullable
|
||||
public SoundData get(CustomSound sound) {
|
||||
return sounds.getOrDefault(sound, null);
|
||||
}
|
||||
/**
|
||||
* @return Sound used, or null if none
|
||||
*/
|
||||
@Nullable
|
||||
public SoundData get(CustomSound sound) {
|
||||
return sounds.getOrDefault(sound, null);
|
||||
}
|
||||
|
||||
public void set(CustomSound type, SoundData data) {
|
||||
this.sounds.put(type, data);
|
||||
}
|
||||
public void set(CustomSound type, SoundData data) {
|
||||
this.sounds.put(type, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SoundListData)) { return false; }
|
||||
if (((SoundListData) obj).getCustomSounds().size() != getCustomSounds().size()) { return false; }
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SoundListData)) {
|
||||
return false;
|
||||
}
|
||||
if (((SoundListData) obj).getCustomSounds().size() != getCustomSounds().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CustomSound sound : ((SoundListData) obj).getCustomSounds()) {
|
||||
for (CustomSound sound : ((SoundListData) obj).getCustomSounds()) {
|
||||
|
||||
if (sound == null) { continue; }
|
||||
if (sound == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean unmatched = true;
|
||||
for (CustomSound thi : getCustomSounds()) {
|
||||
boolean unmatched = true;
|
||||
for (CustomSound thi : getCustomSounds()) {
|
||||
|
||||
if (sound.equals(thi)) {
|
||||
unmatched = false;
|
||||
break; } }
|
||||
if (unmatched) { return false; }
|
||||
}
|
||||
if (sound.equals(thi)) {
|
||||
unmatched = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unmatched) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof SoundListData, "Cannot merge two different stat data types");
|
||||
SoundListData cast = (SoundListData) data;
|
||||
cast.sounds.forEach(sounds::put);
|
||||
}
|
||||
@Override
|
||||
public void mergeWith(SoundListData targetData) {
|
||||
targetData.sounds.forEach(sounds::put);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull StatData cloneData() { return new SoundListData(mapData()); }
|
||||
@Override
|
||||
@NotNull
|
||||
public SoundListData clone() {
|
||||
return new SoundListData(mapData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return sounds.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return sounds.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundListData randomize(MMOItemBuilder builder) {
|
||||
return new SoundListData(new HashMap<>(sounds));
|
||||
}
|
||||
@Override
|
||||
public SoundListData randomize(MMOItemBuilder builder) {
|
||||
return new SoundListData(new HashMap<>(sounds));
|
||||
}
|
||||
}
|
@ -110,12 +110,12 @@ public class StoredTagsData implements StatData, Mergeable<StoredTagsData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StoredTagsData data) {
|
||||
public void mergeWith(StoredTagsData data) {
|
||||
tags.addAll(data.tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoredTagsData cloneData() {
|
||||
public StoredTagsData clone() {
|
||||
return new StoredTagsData(getTags());
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,11 @@ package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class StringData implements StatData, RandomStatData<StringData>, Mergeable<StringData> {
|
||||
public class StringData implements StatData, RandomStatData<StringData> {
|
||||
@Nullable
|
||||
private String value;
|
||||
|
||||
@ -39,16 +38,9 @@ public class StringData implements StatData, RandomStatData<StringData>, Mergeab
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(@Nullable StringData data) {
|
||||
|
||||
// Overwrite
|
||||
value = data.getString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StringData cloneData() {
|
||||
public StringData clone() {
|
||||
return new StringData(value);
|
||||
}
|
||||
}
|
@ -1,13 +1,7 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
@ -15,8 +9,11 @@ import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class StringListData implements StatData, RandomStatData<StringListData>, Mergeable<StringListData> {
|
||||
@NotNull private final List<String> list;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StringListData implements StatData, Mergeable<StringListData>, RandomStatData<StringListData> {
|
||||
@NotNull private final List<String> list = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@ -26,21 +23,18 @@ public class StringListData implements StatData, RandomStatData<StringListData>,
|
||||
}
|
||||
|
||||
public StringListData() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
public StringListData(@NotNull String[] array) {
|
||||
this(Arrays.asList(array));
|
||||
for (String str : array) this.list.add(str);
|
||||
}
|
||||
|
||||
public StringListData(@NotNull JsonArray array) {
|
||||
this();
|
||||
|
||||
array.forEach(str -> list.add(str.getAsString()));
|
||||
}
|
||||
|
||||
public StringListData(@NotNull List<String> list) {
|
||||
this.list = list;
|
||||
this.list.addAll(list);
|
||||
}
|
||||
|
||||
@NotNull public List<String> getList() {
|
||||
@ -53,13 +47,13 @@ public class StringListData implements StatData, RandomStatData<StringListData>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StringListData data) {
|
||||
public void mergeWith(StringListData data) {
|
||||
list.addAll(data.list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public StringListData cloneData() { return new StringListData(new ArrayList<>(getList())); }
|
||||
public StringListData clone() { return new StringListData(list); }
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() { return list.isEmpty(); }
|
||||
|
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <p> • Chance of successful upgrade
|
||||
* </p> • May it get destroyed if unsucessful upgrade?
|
||||
*/
|
||||
public class UpgradeData implements StatData, RandomStatData<UpgradeData>, Cloneable {
|
||||
public class UpgradeData implements StatData, RandomStatData<UpgradeData> {
|
||||
|
||||
/**
|
||||
* @return The String a consumable must match to Upgrade this Item
|
||||
@ -149,6 +149,11 @@ public class UpgradeData implements StatData, RandomStatData<UpgradeData>, Clone
|
||||
return reference == null || data.reference == null || reference.isEmpty() || data.reference.isEmpty() || reference.equals(data.reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade this MMOItem by 1 Level
|
||||
*/
|
||||
@ -197,7 +202,6 @@ public class UpgradeData implements StatData, RandomStatData<UpgradeData>, Clone
|
||||
|
||||
@Override
|
||||
public UpgradeData clone() {
|
||||
try { super.clone(); } catch (CloneNotSupportedException ignored) { }
|
||||
|
||||
return new UpgradeData(reference, template, workbench, destroy, max, min, success); }
|
||||
return new UpgradeData(reference, template, workbench, destroy, max, min, success);
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package net.Indyuce.mmoitems.stat.data.random;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -32,7 +31,7 @@ public interface UpdatableRandomStatData<S extends StatData> {
|
||||
* @param determinedItemLevel The level of the item
|
||||
* @return The rerolled StatData if the original is unreasonable.
|
||||
* <br><br>
|
||||
* If the original is reasonable, a clone of it, probably using {@link Mergeable#cloneData()}
|
||||
* If the original is reasonable, a clone of it, probably using {@link StatData#clone()}
|
||||
*/
|
||||
@NotNull
|
||||
S reroll(@NotNull ItemStat stat, @NotNull S original, int determinedItemLevel);
|
||||
|
@ -6,38 +6,30 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Most intuitive use is for ItemStats to not completely replace each other
|
||||
* when used through Gem Stones. However, this serves a crucial internal
|
||||
* role in determining which stats generate {@link StatHistory}'s, which in
|
||||
* turn allows them to be {@link Upgradable}.
|
||||
* when used through Gem Stones. This could happen for very complex options
|
||||
* like arrow particles, where only the while stat component makes sense (and
|
||||
* those behaviours are hardcoded for simplicity), but most of the time they
|
||||
* add up and get merged.
|
||||
* <p>
|
||||
* This serves a crucial internal role in determining which stats generate
|
||||
* {@link StatHistory}'s, which in turn allows them to be {@link Upgradable}.
|
||||
* <p></p>
|
||||
* <b>Strongly encouraged to override the <code>equals</code> method
|
||||
* to something fitting here as Mergeable stats should support comparisons.</b>
|
||||
*
|
||||
* @deprecated All stat datas should be mergeable. Refactor planned for MI7
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Mergeable<S extends StatData> extends StatData {
|
||||
|
||||
/**
|
||||
* Merging two stat data is used when either applying a gem stone to an item
|
||||
* which already has this type of item data, or when generating an item
|
||||
* randomly so that the item benefits from all modifiers
|
||||
* Merging two stat datas is required when an item benefits from
|
||||
* a buff in a stat, given by
|
||||
* - the base item data + 1 modifier
|
||||
* - at least 2 modifiers
|
||||
*/
|
||||
void merge(S data);
|
||||
void mergeWith(S data);
|
||||
|
||||
/**
|
||||
* Returns a Data with the same values as this, but that is not this.
|
||||
*/
|
||||
@NotNull
|
||||
S cloneData();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> If this is the default state of the StatData, like an enchantment
|
||||
* list data having 0 enchantments, or a percent bonus double stat having a value of 0.
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean isClear() {
|
||||
// Backwards compatibility
|
||||
return isEmpty();
|
||||
}
|
||||
S clone();
|
||||
}
|
||||
|
@ -5,6 +5,13 @@ package net.Indyuce.mmoitems.stat.data.type;
|
||||
* <p>
|
||||
* These are paired with an <code>ItemStat</code> to mean something,
|
||||
* they then become the value of such <code>ItemStat</code>.
|
||||
* <p>
|
||||
* A stat data is enough to calculate the effects of a given item onto a
|
||||
* player but it not sufficient to take into accoun the full history of
|
||||
* an item.
|
||||
*
|
||||
* @author jules
|
||||
* @see {@link net.Indyuce.mmoitems.stat.type.StatHistory}
|
||||
*/
|
||||
public interface StatData {
|
||||
|
||||
@ -12,8 +19,5 @@ public interface StatData {
|
||||
* @return <code>true</code> If this is the default state of the StatData, like an enchantment
|
||||
* list data having 0 enchantments, or a percent bonus double stat having a value of 0.
|
||||
*/
|
||||
default boolean isEmpty() {
|
||||
// Backwards compatibility
|
||||
return this instanceof Mergeable && ((Mergeable) this).isClear();
|
||||
}
|
||||
public boolean isEmpty();
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.Indyuce.mmoitems.stat.data.type;
|
||||
|
||||
/**
|
||||
* Parsed from the configs into providing a StatData all the changes each upgrade will give it.
|
||||
* Parsed from the configs into providing a StatData
|
||||
* all the changes each upgrade will give it.
|
||||
*/
|
||||
public interface UpgradeInfo { }
|
||||
public interface UpgradeInfo {
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package net.Indyuce.mmoitems.stat.type;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.stat.data.StringData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -13,7 +11,7 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* Data that stores what an item is originally named like and prefixes or whatever.
|
||||
*/
|
||||
public class NameData extends StringData implements Mergeable<StringData> {
|
||||
public class NameData extends StringData implements Mergeable<NameData> {
|
||||
public NameData(@NotNull String str) {
|
||||
super(str);
|
||||
}
|
||||
@ -109,29 +107,20 @@ public class NameData extends StringData implements Mergeable<StringData> {
|
||||
@NotNull public ArrayList<String> getSuffixes() { return suffixes; }
|
||||
|
||||
@Override
|
||||
public void merge(StringData data) {
|
||||
|
||||
// Assimilate
|
||||
if (data instanceof NameData) {
|
||||
|
||||
// Replace name if not empty
|
||||
if (!((NameData) data).getMainName().isEmpty()) { setString(((NameData) data).getMainName()); }
|
||||
|
||||
// Assimilate
|
||||
for (String p : ((NameData) data).getPrefixes()) { addPrefix(p);}
|
||||
for (String p : ((NameData) data).getSuffixes()) { addSuffix(p);}
|
||||
|
||||
} else if (data instanceof StringData) {
|
||||
|
||||
public void mergeWith(NameData data) {
|
||||
if (!data.getMainName().isEmpty()) setString(data.getMainName());
|
||||
for (String p : data.getPrefixes()) addPrefix(p);
|
||||
for (String p : data.getSuffixes()) addSuffix(p);
|
||||
/* } else if (data instanceof StringData) {
|
||||
// Replace name if not empty
|
||||
if (data.toString().isEmpty()) { return; }
|
||||
setString(data.toString());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StringData cloneData() {
|
||||
public NameData clone() {
|
||||
|
||||
NameData c = new NameData(getMainName());
|
||||
for (String p : getPrefixes()) { c.addPrefix(p);}
|
||||
|
@ -257,20 +257,13 @@ public class StatHistory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapses all ExSH stat data into one.
|
||||
* Collapses all external stat datas into only one.
|
||||
*/
|
||||
public void consolidateEXSH() {
|
||||
|
||||
// Create Clear
|
||||
StatData theEXSH = getItemStat().getClearStatData();
|
||||
|
||||
// Merge All
|
||||
for (StatData ex : getExternalData()) {
|
||||
if (ex == null) {
|
||||
continue;
|
||||
}
|
||||
((Mergeable) theEXSH).merge(ex);
|
||||
}
|
||||
for (StatData ex : getExternalData()) if (ex != null) ((Mergeable) theEXSH).mergeWith(ex);
|
||||
|
||||
// Clear and Register
|
||||
getExternalData().clear();
|
||||
@ -353,7 +346,7 @@ public class StatHistory {
|
||||
//UPGRD//MMOItems.log("\u00a7e +\u00a77 Item didnt have this stat, original set as blanc.");
|
||||
|
||||
} else {
|
||||
original = ((Mergeable) original).cloneData();
|
||||
original = ((Mergeable) original).clone();
|
||||
//UPGRD//MMOItems.log("\u00a7a +\u00a77 Found original data\u00a7f " + original);
|
||||
}
|
||||
//LVL//MMOItems.log(" \u00a7d*\u00a77-\u00a7a-\u00a763? \u00a77Lvl: \u00a7b" + ofItem.getUpgradeLevel() + "\u00a7d-\u00a77-\u00a7a-\u00a7d-\u00a77-\u00a7a-");
|
||||
@ -548,7 +541,7 @@ public class StatHistory {
|
||||
}
|
||||
|
||||
// Clone original
|
||||
StatData ogCloned = ((Mergeable) originalData).cloneData();
|
||||
StatData ogCloned = ((Mergeable) originalData).clone();
|
||||
//DBL//if (ogCloned instanceof DoubleData) MMOItems.log("\u00a76 >\u00a77 Original Base: \u00a7e" + ((DoubleData) ogCloned).getValue() + "\u00a78 {Original:\u00a77 " + ((DoubleData) getOriginalData()).getValue() + "\u00a78}");
|
||||
|
||||
// Add Modifiers (who are affected by upgrades as if they was the base item data
|
||||
@ -556,7 +549,7 @@ public class StatHistory {
|
||||
|
||||
//DBL//if (getModifiersBonus() instanceof DoubleData) MMOItems.log("\u00a76 >\u00a7c> \u00a77 Modifier Base: \u00a7e" + ((DoubleData) getModifiersBonus()).getValue());
|
||||
// Just merge ig
|
||||
((Mergeable) ogCloned).merge(((Mergeable) getModifiersBonus(d)).cloneData());
|
||||
((Mergeable) ogCloned).mergeWith(((Mergeable) getModifiersBonus(d)).clone());
|
||||
}
|
||||
|
||||
// Level up
|
||||
@ -602,11 +595,11 @@ public class StatHistory {
|
||||
//DBL//if (getGemstoneData(d) instanceof DoubleData) MMOItems.log("\u00a76 \u00a7b|>\u00a77 Gemstone Base: \u00a7e" + ((DoubleData) getGemstoneData(d)).getValue());
|
||||
// Apply upgrades
|
||||
//noinspection ConstantConditions
|
||||
StatData gRet = ((Upgradable) getItemStat()).apply(((Mergeable) getGemstoneData(d)).cloneData(), inf, gLevel);
|
||||
StatData gRet = ((Upgradable) getItemStat()).apply(((Mergeable) getGemstoneData(d)).clone(), inf, gLevel);
|
||||
//DBL//if (gRet instanceof DoubleData) MMOItems.log("\u00a76 \u00a7b|>\u00a77 Leveled Base: \u00a7e" + ((DoubleData) gRet).getValue());
|
||||
|
||||
// Merge
|
||||
((Mergeable) ret).merge(((Mergeable) gRet).cloneData());
|
||||
((Mergeable) ret).mergeWith(((Mergeable) gRet).clone());
|
||||
}
|
||||
|
||||
// Add up externals (who dont suffer upgrades
|
||||
@ -614,7 +607,7 @@ public class StatHistory {
|
||||
|
||||
//DBL//if (d instanceof DoubleData) MMOItems.log("\u00a76 >\u00a7c> \u00a77 Extraneous Base: \u00a7e" + ((DoubleData) d).getValue());
|
||||
// Just merge ig
|
||||
((Mergeable) ret).merge(((Mergeable) d).cloneData());
|
||||
((Mergeable) ret).mergeWith(((Mergeable) d).clone());
|
||||
}
|
||||
|
||||
// Return result
|
||||
@ -635,7 +628,7 @@ public class StatHistory {
|
||||
//RECALCULATE//MMOItems.log("\u00a73|||\u00a77 Calculating \u00a7f" + getItemStat().getNBTPath() + "\u00a77 as Mergeable");
|
||||
|
||||
// Just clone bro
|
||||
StatData ret = ((Mergeable) getOriginalData()).cloneData();
|
||||
StatData ret = ((Mergeable) getOriginalData()).clone();
|
||||
|
||||
//DBL//if (ret instanceof DoubleData) MMOItems.log("\u00a73 > \u00a77 Original Base: \u00a7e" + ((DoubleData) ret).getValue());
|
||||
|
||||
@ -643,19 +636,19 @@ public class StatHistory {
|
||||
for (StatData d : perModifierBonus.values()) {
|
||||
//DBL//if (getModifiersBonus() instanceof DoubleData) MMOItems.log("\u00a73 >\u00a7c> \u00a77 Modifier Base: \u00a7e" + ((DoubleData) getModifiersBonus()).getValue());
|
||||
// Just merge ig
|
||||
((Mergeable) ret).merge(((Mergeable) d).cloneData());
|
||||
((Mergeable) ret).mergeWith(((Mergeable) d).clone());
|
||||
}
|
||||
|
||||
// Add up gemstones
|
||||
for (StatData d : perGemstoneData.values()) {
|
||||
//DBL//if (d instanceof DoubleData) MMOItems.log("\u00a73 >\u00a7b> \u00a77 Gemstone Base: \u00a7e" + ((DoubleData) d).getValue());
|
||||
((Mergeable) ret).merge(((Mergeable) d).cloneData());
|
||||
((Mergeable) ret).mergeWith(((Mergeable) d).clone());
|
||||
}
|
||||
|
||||
// Add up externals
|
||||
for (StatData d : getExternalData()) {
|
||||
//DBL//if (d instanceof DoubleData) MMOItems.log("\u00a73 >\u00a7c> \u00a77 Extraneous Base: \u00a7e" + ((DoubleData) d).getValue());
|
||||
((Mergeable) ret).merge(((Mergeable) d).cloneData());
|
||||
((Mergeable) ret).mergeWith(((Mergeable) d).clone());
|
||||
}
|
||||
|
||||
// Return result
|
||||
@ -689,7 +682,7 @@ public class StatHistory {
|
||||
* And allows net.Indyuce.mmoitems.stat.Enchants.whenLoaded() to correctly initialize the
|
||||
* StatHistory of these items.
|
||||
*/
|
||||
if (!((Mergeable) getOriginalData()).isClear() || getItemStat() == ItemStats.ENCHANTS) {
|
||||
if (!getOriginalData().isEmpty() || getItemStat() == ItemStats.ENCHANTS) {
|
||||
object.add(enc_OGS, ItemTag.compressTags(getItemStat().getAppliedNBT(getOriginalData())));
|
||||
}
|
||||
|
||||
@ -726,7 +719,7 @@ public class StatHistory {
|
||||
for (StatData ex : getExternalData()) {
|
||||
|
||||
// Skip clear
|
||||
if (((Mergeable) ex).isClear()) {
|
||||
if (ex.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1078,7 +1071,7 @@ public class StatHistory {
|
||||
public StatHistory clone(@NotNull MMOItem clonedMMOItem) {
|
||||
|
||||
// Clone
|
||||
StatHistory res = new StatHistory(clonedMMOItem, getItemStat(), ((Mergeable) getOriginalData()).cloneData());
|
||||
StatHistory res = new StatHistory(clonedMMOItem, getItemStat(), ((Mergeable) getOriginalData()).clone());
|
||||
|
||||
// Add all
|
||||
for (UUID uid : getAllGemstones()) {
|
||||
@ -1092,7 +1085,7 @@ public class StatHistory {
|
||||
}
|
||||
|
||||
// Clone
|
||||
res.registerGemstoneData(uid, ((Mergeable) gem).cloneData());
|
||||
res.registerGemstoneData(uid, ((Mergeable) gem).clone());
|
||||
}
|
||||
|
||||
// Add all
|
||||
@ -1102,7 +1095,7 @@ public class StatHistory {
|
||||
}
|
||||
|
||||
// Clone
|
||||
res.registerExternalData(((Mergeable) ex).cloneData());
|
||||
res.registerExternalData(((Mergeable) ex).clone());
|
||||
}
|
||||
|
||||
// Clone
|
||||
@ -1118,7 +1111,7 @@ public class StatHistory {
|
||||
}
|
||||
|
||||
// Clone
|
||||
res.registerModifierBonus(uid, ((Mergeable) mod).cloneData());
|
||||
res.registerModifierBonus(uid, ((Mergeable) mod).clone());
|
||||
}
|
||||
|
||||
// Thats it
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.Indyuce.mmoitems.stat.type;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -10,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* The methods required for this ItemStat to be Upgradeable. <p></p>
|
||||
* <b>It makes sense then that the <code>StatData</code> this uses
|
||||
* implements {@link Mergeable}</b> and it is even assumed so.
|
||||
* implements {@link StatData}</b> and it is even assumed so.
|
||||
*
|
||||
* An upgradable stat can be used in an upgrade template to be upgraded
|
||||
*
|
||||
|
@ -11,7 +11,9 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -7,7 +7,6 @@ import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.stat.Enchants;
|
||||
import net.Indyuce.mmoitems.stat.data.EnchantListData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.StatHistory;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -15,8 +14,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Transfers enchantments from the old MMOItem to the new one.
|
||||
*
|
||||
@ -47,7 +44,7 @@ public class RFGKeepEnchantments implements Listener {
|
||||
|
||||
// Gather
|
||||
StatHistory hist = StatHistory.from(operable, ItemStats.ENCHANTS);
|
||||
EnchantListData maybeOriginalEnchs = (EnchantListData) ((Mergeable) hist.getOriginalData()).cloneData();
|
||||
EnchantListData maybeOriginalEnchs = ((EnchantListData) hist.getOriginalData()).clone();
|
||||
|
||||
//RFG//MMOItems.log(" \u00a7b*** \u00a77Enchantments in old item:");
|
||||
//RFG//hist.log();
|
||||
|
@ -141,7 +141,7 @@ public class RFGKeepGems implements Listener {
|
||||
if (data instanceof Mergeable) {
|
||||
|
||||
// Just ignore that lol
|
||||
if (data instanceof EnchantListData && ((Mergeable) data).isClear()) { continue; }
|
||||
if (data instanceof EnchantListData && data.isEmpty()) { continue; }
|
||||
|
||||
//RFG//MMOItems.log("\u00a79>>> \u00a77Gem-Merging \u00a7c" + stat.getNBTPath() + "\u00a7e" + data.toString() + "\u00a78 " + reforgedGemData.getHistoricUUID().toString());
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class RFGKeepModifications implements Listener {
|
||||
if (modData == null) { continue; }
|
||||
|
||||
// Apply it
|
||||
newHist.registerModifierBonus(mod, ((Mergeable) modData).cloneData());
|
||||
newHist.registerModifierBonus(mod, ((Mergeable) modData).clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user