Fixed bug for ressources + class based ressource system

This commit is contained in:
Ka0rX 2023-03-09 17:22:58 +01:00
parent 825473c8c6
commit e338c0fd25
7 changed files with 100 additions and 5 deletions

View File

@ -948,14 +948,22 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
stellium = Math.max(0, Math.min(stellium + event.getAmount(), max));
}
@Override
public double getHealth() {
return getPlayer().getHealth();
}
@Override
public double getMana() {
return mana;
}
@Override
public double getStamina() {
return stamina;
}
@Override
public double getStellium() {
return stellium;
}

View File

@ -10,6 +10,7 @@ import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import java.util.*;
@ -17,7 +18,7 @@ import java.util.Map.Entry;
public class SavedClassInformation {
private final int level, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints;
private final double experience;
private final double experience, health, mana, stellium, stamina;
private final Map<String, Integer> attributeLevels = new HashMap<>();
private final Map<String, Integer> skillLevels = new HashMap<>();
private final Map<String, Integer> skillTreePoints = new HashMap<>();
@ -36,6 +37,10 @@ public class SavedClassInformation {
attributeReallocationPoints = config.getInt("attribute-realloc-points");
skillReallocationPoints = config.getInt("skill-reallocation-points");
skillTreeReallocationPoints = config.getInt("skill-tree-reallocation-points");
health = config.getInt("health", 20);
mana = config.getInt("mana", 0);
stamina = config.getInt("stamina", 0);
stellium = config.getInt("stellium", 0);
if (config.contains("attribute"))
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributeLevels.put(key, config.getInt("attribute." + key)));
if (config.contains("skill"))
@ -61,6 +66,10 @@ public class SavedClassInformation {
attributeReallocationPoints = json.get("attribute-realloc-points").getAsInt();
skillReallocationPoints = json.get("skill-reallocation-points").getAsInt();
skillTreeReallocationPoints = json.get("skill-tree-reallocation-points").getAsInt();
health = json.has("health") ? json.get("health").getAsDouble() : 20;
mana = json.has("mana") ? json.get("mana").getAsDouble() : 0;
stamina = json.has("stamina") ? json.get("stamina").getAsDouble() : 0;
stellium = json.has("stellium") ? json.get("stellium").getAsDouble() : 0;
if (json.has("attribute"))
for (Entry<String, JsonElement> entry : json.getAsJsonObject("attribute").entrySet())
attributeLevels.put(entry.getKey(), entry.getValue().getAsInt());
@ -88,7 +97,10 @@ public class SavedClassInformation {
this.skillTreeReallocationPoints = data.getSkillTreeReallocationPoints();
this.skillReallocationPoints = data.getSkillReallocationPoints();
this.experience = data.getExperience();
this.health = data.getHealth();
this.mana = data.getMana();
this.stellium = data.getStellium();
this.stamina = data.getStamina();
data.mapAttributeLevels().forEach((key, val) -> this.attributeLevels.put(key, val));
data.mapSkillLevels().forEach((key, val) -> skillLevels.put(key, val));
data.mapSkillTreePoints().forEach((key, val) -> skillTreePoints.put(key, val));
@ -163,6 +175,22 @@ public class SavedClassInformation {
return skillTreePoints.get(skillTreeId);
}
public double getHealth() {
return health;
}
public double getMana() {
return mana;
}
public double getStellium() {
return stellium;
}
public double getStamina() {
return stamina;
}
public Set<String> getAttributeKeys() {
return attributeLevels.keySet();
}
@ -265,6 +293,11 @@ public class SavedClassInformation {
player.setClass(profess);
player.unloadClassInfo(profess);
//This needs to be done at the end to make sure the MAX_HEALTH,MAX_MANA,MAX_STELLIUM... stats are loaded.
player.getPlayer().setHealth(Math.min(health,player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
player.setMana(mana);
player.setStellium(stellium);
player.setStamina(stamina);
// Updates level on exp bar
player.refreshVanillaExp();
}

View File

@ -89,6 +89,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
classinfo.addProperty("attribute-realloc-points", info.getAttributeReallocationPoints());
classinfo.addProperty("skill-reallocation-points", info.getSkillReallocationPoints());
classinfo.addProperty("skill-tree-reallocation-points", info.getSkillTreeReallocationPoints());
classinfo.addProperty("health", info.getHealth());
classinfo.addProperty("mana", info.getMana());
classinfo.addProperty("stamina", info.getStamina());
classinfo.addProperty("stellium", info.getStellium());
JsonObject skillinfo = new JsonObject();
for (String skill : info.getSkillKeys())

View File

@ -177,6 +177,10 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
config.set("class-info." + key + ".attribute-realloc-points", info.getAttributeReallocationPoints());
config.set("class-info." + key + ".skill-tree-reallocation-points", info.getSkillTreeReallocationPoints());
config.set("class-info." + key + ".skill-reallocation-points", info.getSkillReallocationPoints());
config.set("class-info." + key + ".health", info.getHealth());
config.set("class-info." + key + ".mana", info.getMana());
config.set("class-info." + key + ".stamina", info.getStamina());
config.set("class-info." + key + ".stellium", info.getStellium());
info.getSkillKeys().forEach(skill -> config.set("class-info." + key + ".skill." + skill, info.getSkillLevel(skill)));
info.getAttributeKeys().forEach(attribute -> config.set("class-info." + key + ".attribute." + attribute, info.getAttributeLevel(attribute)));
info.getNodeKeys().forEach(node -> config.set("class-info." + key + ".node-levels." + node, info.getNodeLevel(node)));

View File

@ -29,6 +29,14 @@ public interface ClassDataContainer {
int getSkillTreeReallocationPoints();
double getHealth();
double getMana();
double getStamina();
double getStellium();
Map<String, Integer> mapAttributeLevels();
Map<String, Integer> mapSkillLevels();

View File

@ -4,6 +4,7 @@ import io.lumine.mythic.lib.player.skill.PassiveSkill;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList;
@ -13,8 +14,8 @@ import java.util.Map;
public class DefaultPlayerData implements ClassDataContainer {
private final int level, classPoints, skillPoints, attributePoints, attrReallocPoints, skillReallocPoints, skillTreeReallocPoints;
public static final DefaultPlayerData DEFAULT = new DefaultPlayerData(1, 0, 0, 0, 0, 0, 0);
private final double health, mana, stamina, stellium;
public static final DefaultPlayerData DEFAULT = new DefaultPlayerData(1, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0);
public DefaultPlayerData(ConfigurationSection config) {
level = config.getInt("level", 1);
@ -24,9 +25,13 @@ public class DefaultPlayerData implements ClassDataContainer {
attrReallocPoints = config.getInt("attribute-realloc-points");
skillReallocPoints = config.getInt("skill-realloc-points", 0);
skillTreeReallocPoints = config.getInt("skill-tree-realloc-points", 0);
health = config.getDouble("health");
mana = config.getDouble("mana");
stellium = config.getDouble("stellium");
stamina = config.getDouble("stamina");
}
public DefaultPlayerData(int level, int classPoints, int skillPoints, int attributePoints, int attrReallocPoints, int skillReallocPoints, int skillTreeReallocPoints) {
public DefaultPlayerData(int level, int classPoints, int skillPoints, int attributePoints, int attrReallocPoints, int skillReallocPoints, int skillTreeReallocPoints, double health, double mana, double stamina, double stellium) {
this.level = level;
this.classPoints = classPoints;
this.skillPoints = skillPoints;
@ -34,6 +39,10 @@ public class DefaultPlayerData implements ClassDataContainer {
this.attrReallocPoints = attrReallocPoints;
this.skillReallocPoints = skillReallocPoints;
this.skillTreeReallocPoints = skillTreeReallocPoints;
this.health = health;
this.mana = mana;
this.stamina = stamina;
this.stellium = stellium;
}
public int getLevel() {
@ -74,6 +83,26 @@ public class DefaultPlayerData implements ClassDataContainer {
return skillTreeReallocPoints;
}
@Override
public double getHealth() {
return health;
}
@Override
public double getMana() {
return mana;
}
@Override
public double getStamina() {
return stamina;
}
@Override
public double getStellium() {
return stellium;
}
@Override
public Map<String, Integer> mapSkillLevels() {
return new HashMap<>();
@ -117,5 +146,9 @@ public class DefaultPlayerData implements ClassDataContainer {
player.setAttributeReallocationPoints(attrReallocPoints);
player.setSkillTreeReallocationPoints(skillTreeReallocPoints);
player.setSkillReallocationPoints(skillReallocPoints);
player.getPlayer().setHealth(Math.min(health,player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
player.setMana(mana);
player.setStamina(stamina);
player.setStellium(stellium);
}
}

View File

@ -30,6 +30,11 @@ default-playerdata:
skill-realloc-points: 0
attribute-points: 0
attribute-realloc-points: 0
health: 20
mana: 0
stellium: 0
stamina: 0
# The list of all conditions which must be met for the
# BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to