Fixed stats

This commit is contained in:
Indyuce 2022-07-29 17:07:04 +02:00
parent 4a94dbd269
commit 83ab7ef523
7 changed files with 68 additions and 40 deletions

View File

@ -300,12 +300,12 @@ public class MMOCore extends JavaPlugin {
/*
* Initialize player data from all online players. This is very important to do
* that after registering all the professses otherwise the player datas can't
* that after registering all the classes otherwise the player datas can't
* recognize what profess the player has and professes will be lost
*/
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player.getUniqueId()));
// load guild data after loading player data
// Load guild data after loading player data
dataProvider.getGuildManager().load();
// Command

View File

@ -380,6 +380,10 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return skills.values();
}
public Set<String> getStats() {
return stats.keySet();
}
@NotNull
private LinearValue getStatInfo(String stat) {
LinearValue found = stats.get(stat);

View File

@ -6,10 +6,11 @@ import io.lumine.mythic.lib.api.stat.StatMap;
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
import io.lumine.mythic.lib.player.modifier.ModifierSource;
import io.lumine.mythic.lib.player.modifier.ModifierType;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.player.stats.StatInfo;
import net.Indyuce.mmocore.skill.ClassSkill;
public class PlayerStats {
private final PlayerData data;
@ -70,14 +71,15 @@ public class PlayerStats {
* see {@link PlayerData#update()} for more info
*/
public synchronized void updateStats() {
for (StatInstance instance : getMap().getInstances()) {
StatInstance.ModifierPacket packet = instance.newPacket();
for (String stat : MMOCore.plugin.statManager.getRegistered()) {
final StatInstance instance = getMap().getInstance(stat);
final StatInstance.ModifierPacket packet = instance.newPacket();
// Remove old stat modifiers
packet.removeIf(str -> str.equals("mmocoreClass"));
// Remove old stat modifier
packet.remove("mmocoreClass");
// Add newest one
double total = getBase(instance.getStat()) - instance.getBase();
final double total = getBase(instance.getStat()) - instance.getBase();
if (total != 0)
packet.addModifier(new StatModifier("mmocoreClass", instance.getStat(), total, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER));

View File

@ -1,8 +1,8 @@
package net.Indyuce.mmocore.manager;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler;
import net.Indyuce.mmocore.api.player.profess.event.trigger.*;
import org.apache.commons.lang.Validate;
@ -46,6 +46,7 @@ public class ClassManager implements MMOCoreManager {
public void register(PlayerClass playerClass) {
map.put(playerClass.getId(), playerClass);
MMOCore.plugin.statManager.getRegistered().addAll(playerClass.getStats());
}
public boolean has(String id) {
@ -75,8 +76,8 @@ public class ClassManager implements MMOCoreManager {
map.clear();
/*
* Do not clear the list of trigger listeners, since it's only setup
* once the server loads and it is never modified.
* Does not clear the list of trigger listeners, since it's
* only setup once the server loads and it is never modified.
*/
triggerHandlers.forEach(HandlerList::unregisterAll);
}

View File

@ -1,28 +1,38 @@
package net.Indyuce.mmocore.manager;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.player.stats.StatInfo;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.player.stats.StatInfo;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class StatManager implements MMOCoreManager {
private final Map<String, StatInfo> loaded = new HashMap<>();
/**
* Keeps track of all the item stats used so far in the plugin.
* It is not a constant since users can freely add or even create
* new stats.
* <p>
* These stats appear at least once:
* - in a class definition
* - in stats.yml which defines default stat formulas
*/
private final Set<String> usedStats = new HashSet<>();
@Override
public void initialize(boolean clearBefore) {
if (clearBefore)
if (clearBefore) {
loaded.clear();
FileConfiguration config = new ConfigFile("stats").getConfig();
usedStats.clear();
}
// Read default formulas
FileConfiguration config = new ConfigFile("stats").getConfig();
for (String key : config.getConfigurationSection("default").getKeys(false))
registerDefaultFormula(key, new LinearValue(config.getConfigurationSection("default." + key)));
}
@ -31,6 +41,21 @@ public class StatManager implements MMOCoreManager {
return loaded.values();
}
/**
* Keeps track of all the item stats used so far in the plugin.
* It is not a constant since users can freely add or even create
* new stats.
* <p>
* These stats appear at least once:
* - in a class definition
* - in stats.yml which defines default stat formulas
*
* @return A list of stats that must be taken into account in MMOCore
*/
public Set<String> getRegistered() {
return usedStats;
}
@Nullable
public StatInfo getInfo(String stat) {
return loaded.get(stat);
@ -42,20 +67,15 @@ public class StatManager implements MMOCoreManager {
public void registerDefaultFormula(String stat, LinearValue defaultFormula) {
compute(stat).defaultInfo = defaultFormula;
usedStats.add(stat);
}
/**
* @return A stat info for the specified stat. If it doesn't
* exist when method is called, it is registered into the map
* @return A stat info for the specified stat. If it doesn't exist
* when method is called, it is registered into the map
*/
@NotNull
private StatInfo compute(String stat) {
StatInfo found = loaded.get(stat);
if (found != null)
return found;
StatInfo newInfo = new StatInfo(stat);
loaded.put(stat, newInfo);
return newInfo;
return loaded.computeIfAbsent(stat, StatInfo::new);
}
}

View File

@ -221,7 +221,7 @@ items:
- ''
- '✤ Knockback Resistance: &f{knockback_resistance} &7(&f{knockback_resistance_base} &7+ &f{knockback_resistance_extra}&7)'
- '✤ Movement Speed: &f{movement_speed} &7(&f{movement_speed_base} &7+ &f{movement_speed_extra}&7)'
- '✤ Speed Malus Reduction: &f{speed_malus_reduction} &7(&f{speed_malus_reduction_base} &7+ &f{speed_malus_reduction_extra}&7)'
- '✤ Speed Malus Reduction: &f{speed_malus_reduction}% &7(&f{speed_malus_reduction_base} &7+ &f{speed_malus_reduction_extra}&7)'
int:
slots: [34]
function: stats

View File

@ -1,3 +1,4 @@
# Caution, these are very case sensitive!
default:
ATTACK_DAMAGE:
base: 1