forked from Upstream/mmocore
Fixed stats
This commit is contained in:
parent
4a94dbd269
commit
83ab7ef523
@ -300,12 +300,12 @@ public class MMOCore extends JavaPlugin {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize player data from all online players. This is very important to do
|
* 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
|
* recognize what profess the player has and professes will be lost
|
||||||
*/
|
*/
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player.getUniqueId()));
|
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();
|
dataProvider.getGuildManager().load();
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
|
@ -380,6 +380,10 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
|
|||||||
return skills.values();
|
return skills.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getStats() {
|
||||||
|
return stats.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LinearValue getStatInfo(String stat) {
|
private LinearValue getStatInfo(String stat) {
|
||||||
LinearValue found = stats.get(stat);
|
LinearValue found = stats.get(stat);
|
||||||
|
@ -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.api.stat.modifier.StatModifier;
|
||||||
import io.lumine.mythic.lib.player.modifier.ModifierSource;
|
import io.lumine.mythic.lib.player.modifier.ModifierSource;
|
||||||
import io.lumine.mythic.lib.player.modifier.ModifierType;
|
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.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.experience.Profession;
|
import net.Indyuce.mmocore.experience.Profession;
|
||||||
import net.Indyuce.mmocore.player.stats.StatInfo;
|
import net.Indyuce.mmocore.player.stats.StatInfo;
|
||||||
|
import net.Indyuce.mmocore.skill.ClassSkill;
|
||||||
|
|
||||||
public class PlayerStats {
|
public class PlayerStats {
|
||||||
private final PlayerData data;
|
private final PlayerData data;
|
||||||
@ -70,14 +71,15 @@ public class PlayerStats {
|
|||||||
* see {@link PlayerData#update()} for more info
|
* see {@link PlayerData#update()} for more info
|
||||||
*/
|
*/
|
||||||
public synchronized void updateStats() {
|
public synchronized void updateStats() {
|
||||||
for (StatInstance instance : getMap().getInstances()) {
|
for (String stat : MMOCore.plugin.statManager.getRegistered()) {
|
||||||
StatInstance.ModifierPacket packet = instance.newPacket();
|
final StatInstance instance = getMap().getInstance(stat);
|
||||||
|
final StatInstance.ModifierPacket packet = instance.newPacket();
|
||||||
|
|
||||||
// Remove old stat modifiers
|
// Remove old stat modifier
|
||||||
packet.removeIf(str -> str.equals("mmocoreClass"));
|
packet.remove("mmocoreClass");
|
||||||
|
|
||||||
// Add newest one
|
// Add newest one
|
||||||
double total = getBase(instance.getStat()) - instance.getBase();
|
final double total = getBase(instance.getStat()) - instance.getBase();
|
||||||
if (total != 0)
|
if (total != 0)
|
||||||
packet.addModifier(new StatModifier("mmocoreClass", instance.getStat(), total, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER));
|
packet.addModifier(new StatModifier("mmocoreClass", instance.getStat(), total, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER));
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
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.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.EventTriggerHandler;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.*;
|
import net.Indyuce.mmocore.api.player.profess.event.trigger.*;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
@ -46,6 +46,7 @@ public class ClassManager implements MMOCoreManager {
|
|||||||
|
|
||||||
public void register(PlayerClass playerClass) {
|
public void register(PlayerClass playerClass) {
|
||||||
map.put(playerClass.getId(), playerClass);
|
map.put(playerClass.getId(), playerClass);
|
||||||
|
MMOCore.plugin.statManager.getRegistered().addAll(playerClass.getStats());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean has(String id) {
|
public boolean has(String id) {
|
||||||
@ -75,8 +76,8 @@ public class ClassManager implements MMOCoreManager {
|
|||||||
map.clear();
|
map.clear();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do not clear the list of trigger listeners, since it's only setup
|
* Does not clear the list of trigger listeners, since it's
|
||||||
* once the server loads and it is never modified.
|
* only setup once the server loads and it is never modified.
|
||||||
*/
|
*/
|
||||||
triggerHandlers.forEach(HandlerList::unregisterAll);
|
triggerHandlers.forEach(HandlerList::unregisterAll);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,38 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.ConfigFile;
|
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.api.util.math.formula.LinearValue;
|
||||||
import net.Indyuce.mmocore.experience.Profession;
|
import net.Indyuce.mmocore.experience.Profession;
|
||||||
|
import net.Indyuce.mmocore.player.stats.StatInfo;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class StatManager implements MMOCoreManager {
|
public class StatManager implements MMOCoreManager {
|
||||||
private final Map<String, StatInfo> loaded = new HashMap<>();
|
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
|
@Override
|
||||||
public void initialize(boolean clearBefore) {
|
public void initialize(boolean clearBefore) {
|
||||||
if (clearBefore)
|
if (clearBefore) {
|
||||||
loaded.clear();
|
loaded.clear();
|
||||||
|
usedStats.clear();
|
||||||
FileConfiguration config = new ConfigFile("stats").getConfig();
|
}
|
||||||
|
|
||||||
// Read default formulas
|
// Read default formulas
|
||||||
|
FileConfiguration config = new ConfigFile("stats").getConfig();
|
||||||
for (String key : config.getConfigurationSection("default").getKeys(false))
|
for (String key : config.getConfigurationSection("default").getKeys(false))
|
||||||
registerDefaultFormula(key, new LinearValue(config.getConfigurationSection("default." + key)));
|
registerDefaultFormula(key, new LinearValue(config.getConfigurationSection("default." + key)));
|
||||||
}
|
}
|
||||||
@ -31,6 +41,21 @@ public class StatManager implements MMOCoreManager {
|
|||||||
return loaded.values();
|
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
|
@Nullable
|
||||||
public StatInfo getInfo(String stat) {
|
public StatInfo getInfo(String stat) {
|
||||||
return loaded.get(stat);
|
return loaded.get(stat);
|
||||||
@ -42,20 +67,15 @@ public class StatManager implements MMOCoreManager {
|
|||||||
|
|
||||||
public void registerDefaultFormula(String stat, LinearValue defaultFormula) {
|
public void registerDefaultFormula(String stat, LinearValue defaultFormula) {
|
||||||
compute(stat).defaultInfo = defaultFormula;
|
compute(stat).defaultInfo = defaultFormula;
|
||||||
|
usedStats.add(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A stat info for the specified stat. If it doesn't
|
* @return A stat info for the specified stat. If it doesn't exist
|
||||||
* exist when method is called, it is registered into the map
|
* when method is called, it is registered into the map
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
private StatInfo compute(String stat) {
|
private StatInfo compute(String stat) {
|
||||||
StatInfo found = loaded.get(stat);
|
return loaded.computeIfAbsent(stat, StatInfo::new);
|
||||||
if (found != null)
|
|
||||||
return found;
|
|
||||||
|
|
||||||
StatInfo newInfo = new StatInfo(stat);
|
|
||||||
loaded.put(stat, newInfo);
|
|
||||||
return newInfo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ items:
|
|||||||
- ''
|
- ''
|
||||||
- '✤ Knockback Resistance: &f{knockback_resistance} &7(&f{knockback_resistance_base} &7+ &f{knockback_resistance_extra}&7)'
|
- '✤ 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)'
|
- '✤ 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:
|
int:
|
||||||
slots: [34]
|
slots: [34]
|
||||||
function: stats
|
function: stats
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# Caution, these are very case sensitive!
|
||||||
default:
|
default:
|
||||||
ATTACK_DAMAGE:
|
ATTACK_DAMAGE:
|
||||||
base: 1
|
base: 1
|
||||||
@ -26,7 +27,7 @@ default:
|
|||||||
HEALTH_REGENERATION:
|
HEALTH_REGENERATION:
|
||||||
base: .1
|
base: .1
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Max Resource
|
# Max Resource
|
||||||
MAX_MANA:
|
MAX_MANA:
|
||||||
base: 20
|
base: 20
|
||||||
@ -37,7 +38,7 @@ default:
|
|||||||
MAX_STELLIUM:
|
MAX_STELLIUM:
|
||||||
base: 20
|
base: 20
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Resource Regeneration
|
# Resource Regeneration
|
||||||
MANA_REGENERATION:
|
MANA_REGENERATION:
|
||||||
base: .166
|
base: .166
|
||||||
@ -48,12 +49,12 @@ default:
|
|||||||
STELLIUM_REGENERATION:
|
STELLIUM_REGENERATION:
|
||||||
base: .01
|
base: .01
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Increases main class experience earned.
|
# Increases main class experience earned.
|
||||||
ADDITIONAL_EXPERIENCE:
|
ADDITIONAL_EXPERIENCE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Reduces skill cooldowns by X%
|
# Reduces skill cooldowns by X%
|
||||||
COOLDOWN_REDUCTION:
|
COOLDOWN_REDUCTION:
|
||||||
base: 0
|
base: 0
|
||||||
@ -63,32 +64,32 @@ default:
|
|||||||
CHANCE:
|
CHANCE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Dealt by skills
|
# Dealt by skills
|
||||||
SKILL_DAMAGE:
|
SKILL_DAMAGE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Physical skill damage
|
# Physical skill damage
|
||||||
PHYSICAL_DAMAGE:
|
PHYSICAL_DAMAGE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Magic skill damage
|
# Magic skill damage
|
||||||
MAGIC_DAMAGE:
|
MAGIC_DAMAGE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Dealt by any weapon
|
# Dealt by any weapon
|
||||||
WEAPON_DAMAGE:
|
WEAPON_DAMAGE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Dealt by projectile skills or weapons
|
# Dealt by projectile skills or weapons
|
||||||
PROJECTILE_DAMAGE:
|
PROJECTILE_DAMAGE:
|
||||||
base: 0
|
base: 0
|
||||||
per-level: 0
|
per-level: 0
|
||||||
|
|
||||||
# Reduces the amount of tugs needed to fish fishes.
|
# Reduces the amount of tugs needed to fish fishes.
|
||||||
# (When set to 30, 30% of the tugs will be removed).
|
# (When set to 30, 30% of the tugs will be removed).
|
||||||
FISHING_STRENGTH:
|
FISHING_STRENGTH:
|
||||||
@ -96,14 +97,14 @@ default:
|
|||||||
per-level: 0.3
|
per-level: 0.3
|
||||||
min: 0
|
min: 0
|
||||||
max: 40
|
max: 40
|
||||||
|
|
||||||
# Chance of instantly fishing.
|
# Chance of instantly fishing.
|
||||||
CRITICAL_FISHING_CHANCE:
|
CRITICAL_FISHING_CHANCE:
|
||||||
base: 5
|
base: 5
|
||||||
per-level: 0
|
per-level: 0
|
||||||
min: 0
|
min: 0
|
||||||
max: 70
|
max: 70
|
||||||
|
|
||||||
# Chance of being dragged in the waters
|
# Chance of being dragged in the waters
|
||||||
# by the fish when trying to catch it,
|
# by the fish when trying to catch it,
|
||||||
# once the player has NOT successfully
|
# once the player has NOT successfully
|
||||||
|
Loading…
Reference in New Issue
Block a user