diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java index fb171884..d68e7132 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/AttributeModifier.java @@ -1,36 +1,30 @@ package net.Indyuce.mmocore.api.player.attribute; -import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.api.player.MMOPlayerData; -import io.lumine.mythic.lib.api.stat.modifier.StatModifier; +import io.lumine.mythic.lib.api.stat.api.InstanceModifier; import io.lumine.mythic.lib.player.modifier.ModifierSource; import io.lumine.mythic.lib.player.modifier.ModifierType; -import io.lumine.mythic.lib.player.modifier.PlayerModifier; import io.lumine.mythic.lib.util.configobject.ConfigObject; import net.Indyuce.mmocore.api.player.PlayerData; -import org.apache.commons.lang.Validate; -import java.text.DecimalFormat; -import java.util.Objects; +import java.util.UUID; -public class AttributeModifier extends PlayerModifier { +public class AttributeModifier extends InstanceModifier { private final String attribute; - private final double value; - private final ModifierType type; - - private static final DecimalFormat oneDigit = MythicLib.plugin.getMMOConfig().newDecimalFormat("0.#"); /** * Flat attribute modifier (simplest modifier you can think about) */ public AttributeModifier(String key, String attribute, double value) { - this(key, attribute, value, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER); + super(key, value); + + this.attribute = attribute; } /** - * Attribute modifier given by an external mecanic, like a party buff, item set bonuses, - * skills or abilities... Anything apart from items and armor. + * Attribute modifier given by an external mechanic, like a party buff, item + * set bonuses, skills or abilities... Anything apart from items and armor. */ public AttributeModifier(String key, String attribute, double value, ModifierType type) { this(key, attribute, value, type, EquipmentSlot.OTHER, ModifierSource.OTHER); @@ -47,11 +41,23 @@ public class AttributeModifier extends PlayerModifier { * @param source Type of the item granting the stat modifier */ public AttributeModifier(String key, String attribute, double value, ModifierType type, EquipmentSlot slot, ModifierSource source) { - super(key, slot, source); + this(UUID.randomUUID(), key, attribute, value, type, slot, source); + } + + /** + * Attribute modifier given by an item, either a weapon or an armor piece. + * + * @param key Player modifier key + * @param attribute Attribute being modified + * @param value Value of stat modifier + * @param type Is the modifier flat or multiplicative + * @param slot Slot of the item granting the stat modifier + * @param source Type of the item granting the stat modifier + */ + public AttributeModifier(UUID uniqueId, String key, String attribute, double value, ModifierType type, EquipmentSlot slot, ModifierSource source) { + super(uniqueId, key, slot, source, value, type); this.attribute = attribute; - this.value = value; - this.type = type; } /** @@ -62,22 +68,14 @@ public class AttributeModifier extends PlayerModifier { * @param str The string to be parsed */ public AttributeModifier(String key, String attribute, String str) { - super(key, EquipmentSlot.OTHER, ModifierSource.OTHER); + super(key, EquipmentSlot.OTHER, ModifierSource.OTHER, str); - Validate.notNull(str, "String cannot be null"); - Validate.notEmpty(str, "String cannot be empty"); - - type = str.toCharArray()[str.length() - 1] == '%' ? ModifierType.RELATIVE : ModifierType.FLAT; - value = Double.parseDouble(type == ModifierType.RELATIVE ? str.substring(0, str.length() - 1) : str); this.attribute = attribute; } public AttributeModifier(ConfigObject object) { - super(object.getString("key"), EquipmentSlot.OTHER, ModifierSource.OTHER); + super(object); - String str = Objects.requireNonNull(object.getString("value")); - type = str.toCharArray()[str.length() - 1] == '%' ? ModifierType.RELATIVE : ModifierType.FLAT; - value = Double.parseDouble(type == ModifierType.RELATIVE ? str.substring(0, str.length() - 1) : str); this.attribute = object.getString("attribute"); } @@ -85,14 +83,6 @@ public class AttributeModifier extends PlayerModifier { return attribute; } - public ModifierType getType() { - return type; - } - - public double getValue() { - return value; - } - /** * Used to multiply some existing stat modifier by a constant, usually an * integer, for instance when MMOCore party modifiers scale with the @@ -101,8 +91,8 @@ public class AttributeModifier extends PlayerModifier { * @param coef The multiplicative constant * @return A new instance of StatModifier with modified value */ - public StatModifier multiply(double coef) { - return new StatModifier(getKey(), attribute, value * coef, type, getSlot(), getSource()); + public AttributeModifier multiply(double coef) { + return new AttributeModifier(getUniqueId(), getKey(), attribute, value * coef, type, getSlot(), getSource()); } @Override @@ -116,9 +106,4 @@ public class AttributeModifier extends PlayerModifier { PlayerData playerData = PlayerData.get(mmoPlayerData); playerData.getAttributes().getInstance(attribute).removeModifier(getKey()); } - - @Override - public String toString() { - return oneDigit.format(value) + (type == io.lumine.mythic.lib.player.modifier.ModifierType.RELATIVE ? "%" : ""); - } } \ No newline at end of file diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java index 53738674..d3ce3d3d 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java @@ -113,6 +113,7 @@ public class PlayerAttributes { return n; } + // TODO have it extend ModifiedInstance public class AttributeInstance { private int spent; @@ -223,10 +224,9 @@ public class PlayerAttributes { } } + @Deprecated public void setBaseAttribute(String id, int value) { - getInstances().forEach(ins -> { - if (ins.getId().equals(id)) - ins.setBase(value); - }); + AttributeInstance ins = instances.get(id); + if (ins != null) ins.setBase(value); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index ef4436b8..5a07f44c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -5,6 +5,7 @@ import io.lumine.mythic.lib.gson.JsonObject; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; +import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.player.ClassDataContainer; import net.Indyuce.mmocore.skill.RegisteredSkill; @@ -327,7 +328,10 @@ public class SavedClassInformation implements ClassDataContainer { player.bindSkill(slot, profess.getSkill(boundSkills.get(slot))); skillLevels.forEach(player::setSkillLevel); - attributeLevels.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts)); + attributeLevels.forEach((id, pts) -> { + final PlayerAttributes.AttributeInstance ins = player.getAttributes().getInstance(id); + if (ins != null) ins.setBase(pts); + }); // Careful, the global points must not be forgotten. player.setSkillTreePoints("global", skillTreePoints.getOrDefault("global", 0)); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java index b6e6439a..970ae7f7 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java @@ -109,7 +109,7 @@ public class AttributeView extends EditableInventory { playerData.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); playerData.giveAttributePoints(spent); playerData.giveAttributeReallocationPoints(-1); - MMOCore.plugin.configManager.getSimpleMessage("attribute-points-reallocated", "points", "" + playerData.getAttributePoints()).send(player); + MMOCore.plugin.configManager.getSimpleMessage("attribute-points-reallocated", "points", String.valueOf(playerData.getAttributePoints())).send(player); MMOCore.plugin.soundManager.getSound(SoundEvent.RESET_ATTRIBUTES).playTo(getPlayer()); open(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index a5855bf7..420427b5 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -207,7 +207,7 @@ public class ConfigManager { } /** - * Merge with {@link net.Indyuce.mmocore.api.ConfigMessage} + * @deprecated TODO Merge with {@link net.Indyuce.mmocore.api.ConfigMessage} */ @Deprecated public SimpleMessage getSimpleMessage(String key, String... placeholders) { @@ -218,7 +218,7 @@ public class ConfigManager { } /** - * Merge with {@link net.Indyuce.mmocore.api.ConfigMessage} + * @deprecated TODO Merge with {@link net.Indyuce.mmocore.api.ConfigMessage} */ @Deprecated public static class SimpleMessage { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java index c711c590..6b5405d8 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java @@ -8,8 +8,6 @@ import java.util.Set; /** * All the class-specific information i.e information being saved * in {@link SavedClassInformation} when a player changes its current class. - * - * TODO move {@link SavedClassInformation} method to ClassDataContainer */ public interface ClassDataContainer { diff --git a/MMOCore-Dist/src/main/resources/default/gui/attribute-view.yml b/MMOCore-Dist/src/main/resources/default/gui/attribute-view.yml index 4722590d..71286aa6 100644 --- a/MMOCore-Dist/src/main/resources/default/gui/attribute-view.yml +++ b/MMOCore-Dist/src/main/resources/default/gui/attribute-view.yml @@ -32,7 +32,7 @@ items: - '' - '&8When Leveled Up:' - '&7 +{buff_weapon_damage}% Weapon Damage (&a+{total_weapon_damage}%&7)' - - '&7 +{buff_max_health} Max Health (&a+{total_max_health}&7)' + - '&7 +{buff_max_health}% Max Health (&a+{total_max_health}%&7)' - '' - '&eClick to level up for 1 attribute point.' - '&e◆ Current Attribute Points: {attribute_points}' @@ -50,7 +50,7 @@ items: - '&8When Leveled Up:' - '&7 +{buff_physical_damage}% Physical Damage (&a+{total_physical_damage}%&7)' - '&7 +{buff_projectile_damage}% Projectile Damage (&a+{total_projectile_damage}%&7)' - - '&7 +{buff_attack_speed} Attack Speed (&a+{total_attack_speed}&7)' + - '&7 +{buff_attack_speed}% Attack Speed (&a+{total_attack_speed}%&7)' - '' - '&eClick to level up for 1 attribute point.' - '&e◆ Current Attribute Points: {attribute_points}'