Merge branch 'Bug_Fix' into 'master'

Bug fixing

See merge request phoenix-dvpmt/mmocore!19
This commit is contained in:
Jules 2023-03-21 14:07:07 +00:00
commit d02418ea12
12 changed files with 158 additions and 36 deletions

View File

@ -291,6 +291,8 @@ public class MMOCore extends JavaPlugin {
for (PlayerData data : PlayerData.getAll())
if (data.isFullyLoaded()) {
data.close();
//Saves player health before saveData as the player will be considered offline into it if it is async.
data.setHealth(data.getPlayer().getHealth());
dataProvider.getDataManager().saveData(data, true);
}

View File

@ -82,6 +82,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
private int level, classPoints, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints;
private double experience;
private double mana, stamina, stellium;
/**
* Health is stored in playerData because when saving the playerData we can't access the player health anymore as the payer is Offline.
*/
private double health;
private Guild guild;
private SkillCastingHandler skillCasting;
private final PlayerQuests questData;
@ -183,11 +187,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
skillTree.setupNodeStates(this);
// Stat triggers setup
if (!areStatsLoaded()) {
for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll())
for (SkillTreeNode node : skillTree.getNodes())
node.getExperienceTable().claimStatTriggers(this, node);
}
for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll())
for (SkillTreeNode node : skillTree.getNodes())
node.getExperienceTable().claimStatTriggers(this, node);
}
public int getPointSpent(SkillTree skillTree) {
@ -232,15 +236,18 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return nodeLevelsString.entrySet();
}
public boolean areStatsLoaded() {
// Used to see if the triggers need to be applied
for (StatInstance instance : mmoData.getStatMap().getInstances())
for (StatModifier modifier : instance.getModifiers())
public void resetTriggerStats() {
for (StatInstance instance : mmoData.getStatMap().getInstances()) {
Iterator<StatModifier> iter = instance.getModifiers().iterator();
while (iter.hasNext()) {
StatModifier modifier = iter.next();
if (modifier.getKey().startsWith(StatTrigger.TRIGGER_PREFIX))
return true;
return false;
iter.remove();
}
}
}
public Map<SkillTreeNode, Integer> getNodeLevels() {
return new HashMap<>(nodeLevels);
}
@ -748,9 +755,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
final double r = Math.sin((double) t / warpTime * Math.PI);
for (double j = 0; j < Math.PI * 2; j += Math.PI / 4)
getPlayer().getLocation().getWorld().spawnParticle(Particle.REDSTONE, getPlayer().getLocation().add(
Math.cos((double) 5 * t / warpTime + j) * r,
(double) 2 * t / warpTime,
Math.sin((double) 5 * t / warpTime + j) * r),
Math.cos((double) 5 * t / warpTime + j) * r,
(double) 2 * t / warpTime,
Math.sin((double) 5 * t / warpTime + j) * r),
1, new Particle.DustOptions(Color.PURPLE, 1.25f));
}
}.runTaskTimer(MMOCore.plugin, 0, 1);
@ -936,18 +943,27 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
stellium = Math.max(0, Math.min(stellium + event.getAmount(), max));
}
@Override
public double getMana() {
return mana;
}
@Override
public double getHealth() {
return health;
}
@Override
public double getStamina() {
return stamina;
}
@Override
public double getStellium() {
return stellium;
}
public PlayerStats getStats() {
return playerStats;
}
@ -960,6 +976,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
mana = Math.max(0, Math.min(amount, getStats().getStat("MAX_MANA")));
}
public void setHealth(double amount) {
this.health = amount;
}
public void setStamina(double amount) {
stamina = Math.max(0, Math.min(amount, getStats().getStat("MAX_STAMINA")));
}
@ -1199,7 +1219,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
* checks if they could potentially upgrade to one of these
*
* @return If the player can change its current class to
* a subclass
* a subclass
*/
@Deprecated
public boolean canChooseSubclass() {

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.getDouble("health", 20);
mana = config.getDouble("mana", 0);
stamina = config.getDouble("stamina", 0);
stellium = config.getDouble("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,11 @@ 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,6 +98,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));
@ -119,6 +133,22 @@ public class SavedClassInformation {
return attributeReallocationPoints;
}
public double getHealth() {
return health;
}
public double getMana() {
return mana;
}
public double getStellium() {
return stellium;
}
public double getStamina() {
return stamina;
}
public Set<String> getSkillKeys() {
return skillLevels.keySet();
}
@ -265,6 +295,12 @@ public class SavedClassInformation {
player.setClass(profess);
player.unloadClassInfo(profess);
//These should be loaded after to make sure that the MAX_MANA, MAX_STAMINA & MAX_STELLIUM stats are already loaded.
player.setMana(mana);
player.setStellium(stellium);
player.setStamina(stamina);
player.getPlayer().setHealth(Math.min(health,player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
// Updates level on exp bar
player.refreshVanillaExp();
}

View File

@ -31,6 +31,10 @@ public class PartyCommand extends RegisteredCommand {
sender.sendMessage(ChatColor.RED + "This command is for players only.");
return true;
}
if(!(MMOCore.plugin.partyModule instanceof MMOCorePartyModule)){
sender.sendMessage(ChatColor.RED+"You can't use MMOCore party system as you delegated the party system to another plugin.");
return true;
}
PlayerData data = PlayerData.get((OfflinePlayer) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "party");

View File

@ -101,15 +101,12 @@ public class PlayerProfessions {
for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet())
playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt());
if (!playerData.areStatsLoaded()) {
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
if (profession.hasExperienceTable())
profession.getExperienceTable().claimStatTriggers(playerData, profession);
}
if (playerData.getProfess().hasExperienceTable())
playerData.getProfess().getExperienceTable().claimStatTriggers(playerData, playerData.getProfess());
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
if (profession.hasExperienceTable())
profession.getExperienceTable().claimStatTriggers(playerData, profession);
}
if (playerData.getProfess().hasExperienceTable())
playerData.getProfess().getExperienceTable().claimStatTriggers(playerData, playerData.getProfess());
}

View File

@ -16,6 +16,9 @@ import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.Nullable;
import java.sql.ResultSet;
@ -37,11 +40,8 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer {
@Override
public void loadData(ResultSet result) throws SQLException {
// Initialize custom resources
data.setMana(result.getFloat("mana"));
data.setStellium(result.getFloat("stellium"));
data.setStamina(result.getFloat("stamina"));
//Reset stats linked to triggers
data.resetTriggerStats();
data.setClassPoints(result.getInt("class_points"));
data.setSkillPoints(result.getInt("skill_points"));
@ -118,6 +118,16 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer {
}
}
//These should be loaded after to make sure that the MAX_MANA, MAX_STAMINA & MAX_STELLIUM stats are already loaded.
data.setMana(result.getDouble("mana"));
data.setStamina(result.getDouble("stamina"));
data.setStellium(result.getDouble("stamina"));
double health = result.getDouble("health");
health = health == 0 ? 20 : health;
health = Math.min(health, data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
data.getPlayer().setHealth(health);
UtilityMethods.debug(MMOCore.plugin, "SQL", String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
data.setFullyLoaded();
}

View File

@ -21,9 +21,10 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider {
"skill_tree_reallocation_points", "INT(11)",
"skill_tree_points", "LONGTEXT",
"skill_tree_levels", "LONGTEXT",
"mana","FLOAT",
"stamina","FLOAT",
"stellium","FLOAT"};
"health", "FLOAT",
"mana", "FLOAT",
"stamina", "FLOAT",
"stellium", "FLOAT"};
public MySQLDataProvider(FileConfiguration config) {
super(MMOCore.plugin);
@ -56,6 +57,10 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider {
"friends LONGTEXT," +
"skills LONGTEXT," +
"bound_skills LONGTEXT," +
"health FLOAT," +
"mana FLOAT," +
"stamina FLOAT," +
"stellium FLOAT," +
"class_info LONGTEXT," +
"is_saved TINYINT," +
"PRIMARY KEY (uuid));");

View File

@ -44,6 +44,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
updater.addData("attribute_realloc_points", data.getAttributeReallocationPoints());
updater.addJSONArray("waypoints", data.getWaypoints());
updater.addData("skill_tree_reallocation_points", data.getSkillTreeReallocationPoints());
updater.addData("health",data.getHealth());
updater.addData("mana", data.getMana());
updater.addData("stellium", data.getStellium());
updater.addData("stamina", data.getStamina());

View File

@ -12,6 +12,7 @@ import net.Indyuce.mmocore.manager.data.PlayerDataManager;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import org.apache.commons.lang.Validate;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
@ -33,6 +34,9 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
public void loadData(PlayerData data) {
FileConfiguration config = new ConfigFile(data.getUniqueId()).getConfig();
//Reset stats linked to triggers.
data.resetTriggerStats();
data.setClassPoints(config.getInt("class-points", getDefaultData().getClassPoints()));
data.setSkillPoints(config.getInt("skill-points", getDefaultData().getSkillPoints()));
data.setSkillReallocationPoints(config.getInt("skill-reallocation-points", getDefaultData().getSkillReallocationPoints()));
@ -117,7 +121,9 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
double health=config.contains("health") ? config.getDouble("health") : data.getStats().getStat("MAX_HEALTH");
health=Math.min(health,data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
data.getPlayer().setHealth(health);
data.setFullyLoaded();
}
@ -142,6 +148,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
data.mapSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value));
config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints());
config.set("skill", null);
config.set("health",data.getHealth());
config.set("mana", data.getMana());
config.set("stellium", data.getStellium());
config.set("stamina", data.getStamina());

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

@ -13,8 +13,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 +24,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",20);
mana=config.getDouble("mana",20);
stamina=config.getDouble("stamina",20);
stellium=config.getDouble("stellium",20);
}
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 +38,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() {
@ -45,6 +53,26 @@ public class DefaultPlayerData implements ClassDataContainer {
return 0;
}
@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 int getSkillPoints() {
return skillPoints;

View File

@ -73,6 +73,10 @@ public class PlayerListener implements Listener {
@EventHandler
public void saveDataOnQuit(PlayerQuitEvent event) {
PlayerData playerData = PlayerData.get(event.getPlayer());
/**
* We save player health as it won't be accessible anymore when saving the player data (player will be offline).
*/
playerData.setHealth(event.getPlayer().getHealth());
MMOCore.plugin.dataProvider.getDataManager().unregisterSafe(playerData);
}