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 d3ce3d3d..55869799 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 @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.player.EquipmentSlot; +import io.lumine.mythic.lib.api.stat.StatInstance; import io.lumine.mythic.lib.player.modifier.Closeable; import io.lumine.mythic.lib.player.modifier.ModifierSource; import io.lumine.mythic.lib.player.modifier.ModifierType; @@ -216,6 +217,12 @@ public class PlayerAttributes { public void updateStats() { final PlayerAttribute attr = MMOCore.plugin.attributeManager.get(id); final int total = getTotal(); + + // Remove ALL stat modifiers + for (StatInstance ins : data.getMMOPlayerData().getStatMap().getInstances()) + ins.removeIf(str -> str.equals("attribute." + id)); + + // Register new stat modifiers attr.getBuffs().forEach(buff -> buff.multiply(total).register(data.getMMOPlayerData())); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java index 6fe25c60..6a60d3a4 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java @@ -28,12 +28,8 @@ public class StatTrigger extends Trigger implements Removable { @Override public void apply(PlayerData player) { StatModifier prevModifier = player.getMMOPlayerData().getStatMap().getInstance(stat).getModifier(modifier.getUniqueId()); - if (prevModifier == null) - modifier.register(player.getMMOPlayerData()); - else { - prevModifier.unregister(player.getMMOPlayerData()); - prevModifier.add(amount).register(player.getMMOPlayerData()); - } + if (prevModifier == null) modifier.register(player.getMMOPlayerData()); + else prevModifier.add(amount).register(player.getMMOPlayerData()); } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java index a2a68a02..d0591ecc 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java @@ -89,7 +89,7 @@ public class RPGPlaceholders extends PlaceholderExpansion { else if (identifier.startsWith("attribute_points_spent_")) { String attributeId = identifier.substring(31); PlayerAttributes.AttributeInstance attributeInstance = Objects.requireNonNull(playerData.getAttributes().getInstance(attributeId), "Could not find attribute with ID '" + attributeId + "'"); - return String.valueOf(attributeInstance.getSpent()); + return String.valueOf(attributeInstance.getBase()); } else if (identifier.equals("level_percent")) { double current = playerData.getExperience(), next = playerData.getLevelUpExperience(); return MythicLib.plugin.getMMOConfig().decimal.format(current / next * 100); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModule.java index 24faf048..314c1001 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModule.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.party; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import org.jetbrains.annotations.Nullable; @@ -7,4 +8,19 @@ public interface PartyModule { @Nullable public AbstractParty getParty(PlayerData playerData); + + + /** + * Applies party stat bonuses to a specific player + */ + default void applyStatBonuses(PlayerData player, int memberCount) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(memberCount - 1).register(player.getMMOPlayerData())); + } + + /** + * Clear party stat bonuses from a player + */ + default void clearStatBonuses(PlayerData player) { + MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); + } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java index 381ef5e7..9954b7d0 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsXLPartyModule.java @@ -1,7 +1,5 @@ package net.Indyuce.mmocore.party.compat; -import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostJoinEvent; -import com.alessiodp.parties.api.events.bukkit.player.BukkitPartiesPlayerPostLeaveEvent; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.event.group.GroupDisbandEvent; import de.erethon.dungeonsxl.api.event.group.GroupPlayerJoinEvent; @@ -54,20 +52,6 @@ public class DungeonsXLPartyModule implements PartyModule, Listener { event.getGroup().getMembers().getOnlinePlayers().forEach(p -> clearStatBonuses(PlayerData.get(p))); } - /** - * Applies party stat bonuses to a specific player - */ - private void applyStatBonuses(PlayerData player, int membersSize) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); - } - - /** - * Clear party stat bonuses from a player - */ - private void clearStatBonuses(PlayerData player) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); - } - class CustomParty implements AbstractParty { private final PlayerGroup group; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java index bbc16765..f429e8f5 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/McMMOPartyModule.java @@ -60,20 +60,6 @@ public class McMMOPartyModule implements PartyModule, Listener { } } - /** - * Applies party stat bonuses to a specific player - */ - private void applyStatBonuses(PlayerData player, int membersSize) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); - } - - /** - * Clear party stat bonuses from a player - */ - private void clearStatBonuses(PlayerData player) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); - } - class CustomParty implements AbstractParty { private final Party party; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java index 37a0fa16..cd966eae 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java @@ -50,20 +50,6 @@ public class PartiesPartyModule implements PartyModule, Listener { .forEach(p -> applyStatBonuses(PlayerData.get(p.getPlayerUUID()), membersSize)); } - /** - * Applies party stat bonuses to a specific player - */ - private void applyStatBonuses(PlayerData player, int membersSize) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(membersSize - 1).register(player.getMMOPlayerData())); - } - - /** - * Clear party stat bonuses from a player - */ - private void clearStatBonuses(PlayerData player) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); - } - class CustomParty implements AbstractParty { private final Party party; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/provided/Party.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/provided/Party.java index af023cda..81a32924 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/provided/Party.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/provided/Party.java @@ -1,13 +1,14 @@ package net.Indyuce.mmocore.party.provided; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.gui.api.PluginInventory; -import net.Indyuce.mmocore.gui.social.party.EditablePartyView; -import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.social.Request; +import net.Indyuce.mmocore.gui.api.PluginInventory; +import net.Indyuce.mmocore.gui.social.party.EditablePartyView; +import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.party.AbstractParty; +import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.Validate; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -29,18 +30,11 @@ public class Party implements AbstractParty { @NotNull private PlayerData owner; - /** - * If the difference between a player level and the party - * level is too high then players cannot join the party. - */ - private final int partyLevel; - private final MMOCorePartyModule module; public Party(MMOCorePartyModule module, PlayerData owner) { - this.owner = owner; this.module = module; - this.partyLevel = owner.getLevel(); + this.owner = owner; addMember(owner); } @@ -69,7 +63,7 @@ public class Party implements AbstractParty { } public int getLevel() { - return partyLevel; + return owner.getLevel(); } @Override @@ -113,8 +107,8 @@ public class Party implements AbstractParty { members.remove(data); module.setParty(data, null); - clearStatBonuses(data); - members.forEach(this::applyStatBonuses); + module.clearStatBonuses(data); + members.forEach(member -> module.applyStatBonuses(member, members.size())); updateOpenInventories(); // Disband the party if no member left @@ -138,7 +132,7 @@ public class Party implements AbstractParty { module.setParty(data, this); members.add(data); - members.forEach(this::applyStatBonuses); + members.forEach(member -> module.applyStatBonuses(member, members.size())); updateOpenInventories(); } @@ -175,20 +169,6 @@ public class Party implements AbstractParty { new ArrayList<>(members).forEach(action); } - /** - * Applies party stat bonuses to a specific player - */ - private void applyStatBonuses(PlayerData player) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.multiply(members.size() - 1).register(player.getMMOPlayerData())); - } - - /** - * Clear party stat bonuses from a player - */ - private void clearStatBonuses(PlayerData player) { - MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData())); - } - @Override public boolean equals(Object o) { if (this == o) return true;