Fixed attributes not reseting with /mmocore reload

This commit is contained in:
Jules 2023-11-26 17:42:45 +01:00
parent f6d094fb6e
commit 947637127e
8 changed files with 35 additions and 80 deletions

View File

@ -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()));
}

View File

@ -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

View File

@ -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);

View File

@ -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()));
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;