From 57fe9f1f1b170f33efbf72477fe65cd1be235af7 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 19 Mar 2023 13:15:45 +0100 Subject: [PATCH 1/6] Blocks MMOCore party commands when another Module has been loaded. --- .../main/java/net/Indyuce/mmocore/command/PartyCommand.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java index d36ac5b2..d9f02a10 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java @@ -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"); From ae9c396c252c426b44b6f9e7833036ccfd5e293a Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 19 Mar 2023 13:33:13 +0100 Subject: [PATCH 2/6] Fixed Multiple Servers Skill Tree Bug --- .../mmocore/api/player/PlayerData.java | 33 ++++++++++--------- .../mmocore/experience/PlayerProfessions.java | 13 +++----- .../data/mysql/MMOCoreDataSynchronizer.java | 3 ++ .../data/yaml/YAMLPlayerDataManager.java | 3 ++ 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 3705daeb..bad06b81 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -183,11 +183,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 +232,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 iter = instance.getModifiers().iterator(); + while (iter.hasNext()) { + StatModifier modifier = iter.next(); if (modifier.getKey().startsWith(StatTrigger.TRIGGER_PREFIX)) - return true; - return false; + modifier.unregister(mmoData); + } + } } + public Map getNodeLevels() { return new HashMap<>(nodeLevels); } @@ -748,9 +751,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); @@ -1199,7 +1202,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() { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index 2540845b..ef8e6f89 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -101,15 +101,12 @@ public class PlayerProfessions { for (Entry 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()); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java index 84229919..15923c17 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java @@ -37,6 +37,9 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer { @Override public void loadData(ResultSet result) throws SQLException { + //Reset stats linked to triggers + data.resetTriggerStats(); + // Initialize custom resources data.setMana(result.getFloat("mana")); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index eabe5e83..a06eb434 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -33,6 +33,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())); From 6c89e78f543c46c1f754b54f79162bfae89d3370 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 19 Mar 2023 17:56:23 +0100 Subject: [PATCH 3/6] Bug Fix --- .../main/java/net/Indyuce/mmocore/api/player/PlayerData.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index bad06b81..37bfc58a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -233,7 +233,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public void resetTriggerStats() { - for (StatInstance instance : mmoData.getStatMap().getInstances()) { + Iterator stat_ite=mmoData.getStatMap().getInstances().iterator(); + while(stat_ite.hasNext()) { + StatInstance instance=stat_ite.next(); Iterator iter = instance.getModifiers().iterator(); while (iter.hasNext()) { StatModifier modifier = iter.next(); From 0f16c987f048b5f11c9d6ba9488d641044ae654c Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 19 Mar 2023 18:20:56 +0100 Subject: [PATCH 4/6] Bug Fix --- .../java/net/Indyuce/mmocore/api/player/PlayerData.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 37bfc58a..9224c564 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -233,14 +233,12 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public void resetTriggerStats() { - Iterator stat_ite=mmoData.getStatMap().getInstances().iterator(); - while(stat_ite.hasNext()) { - StatInstance instance=stat_ite.next(); + for(StatInstance instance:mmoData.getStatMap().getInstances()) { Iterator iter = instance.getModifiers().iterator(); while (iter.hasNext()) { StatModifier modifier = iter.next(); if (modifier.getKey().startsWith(StatTrigger.TRIGGER_PREFIX)) - modifier.unregister(mmoData); + iter.remove(); } } } From 4d89fa8fd9d193dadb7227366f7ee8ee2342154f Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 19 Mar 2023 22:23:33 +0100 Subject: [PATCH 5/6] Class based Ressources that are also saved/set when quitting & connecting to the server. --- .../mmocore/api/player/PlayerData.java | 11 +++++- .../player/profess/SavedClassInformation.java | 38 ++++++++++++++++++- .../data/mysql/MMOCoreDataSynchronizer.java | 10 +++++ .../manager/data/mysql/MySQLDataProvider.java | 11 ++++-- .../data/mysql/MySQLPlayerDataManager.java | 1 + .../data/yaml/YAMLPlayerDataManager.java | 6 ++- .../mmocore/player/ClassDataContainer.java | 8 ++++ .../mmocore/player/DefaultPlayerData.java | 34 +++++++++++++++-- 8 files changed, 110 insertions(+), 9 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 9224c564..f51527f1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -233,7 +233,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public void resetTriggerStats() { - for(StatInstance instance:mmoData.getStatMap().getInstances()) { + for (StatInstance instance : mmoData.getStatMap().getInstances()) { Iterator iter = instance.getModifiers().iterator(); while (iter.hasNext()) { StatModifier modifier = iter.next(); @@ -939,18 +939,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 getPlayer().getHealth(); + } + + @Override public double getStamina() { return stamina; } + @Override public double getStellium() { return stellium; } + public PlayerStats getStats() { return playerStats; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index 76eafa7e..31ac030c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -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 attributeLevels = new HashMap<>(); private final Map skillLevels = new HashMap<>(); private final Map 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 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 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(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java index 15923c17..afa1f397 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java @@ -16,6 +16,7 @@ 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.attribute.Attribute; import org.jetbrains.annotations.Nullable; import java.sql.ResultSet; @@ -121,6 +122,15 @@ 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 = 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(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java index 7a631b47..652714cb 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java @@ -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));"); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 1b994b11..e6f8ca30 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -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.getPlayer().getHealth()); updater.addData("mana", data.getMana()); updater.addData("stellium", data.getStellium()); updater.addData("stamina", data.getStamina()); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index a06eb434..40926977 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -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; @@ -120,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(); } @@ -145,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()); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java index 9ac8f2b1..90e8367d 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java @@ -29,6 +29,14 @@ public interface ClassDataContainer { int getSkillTreeReallocationPoints(); + double getHealth(); + + double getMana(); + + double getStamina(); + + double getStellium(); + Map mapAttributeLevels(); Map mapSkillLevels(); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java index f6b16547..62f1695a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java @@ -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; From 6b91315b576a262b6351979c1cfabb73850140f2 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Mon, 20 Mar 2023 16:55:13 +0100 Subject: [PATCH 6/6] Class based Ressources that are also saved/set when quitting & connecting to the server. --- .../src/main/java/net/Indyuce/mmocore/MMOCore.java | 2 ++ .../net/Indyuce/mmocore/api/player/PlayerData.java | 10 +++++++++- .../manager/data/mysql/MMOCoreDataSynchronizer.java | 9 +++------ .../manager/data/mysql/MySQLPlayerDataManager.java | 2 +- .../net/Indyuce/mmocore/listener/PlayerListener.java | 4 ++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java index 71d465c4..8f3e5f00 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -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); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index f51527f1..94c06980 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -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; @@ -946,7 +950,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc @Override public double getHealth() { - return getPlayer().getHealth(); + return health; } @Override @@ -972,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"))); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java index afa1f397..1364026b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java @@ -16,7 +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; @@ -41,12 +43,6 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer { //Reset stats linked to triggers data.resetTriggerStats(); - - // Initialize custom resources - data.setMana(result.getFloat("mana")); - data.setStellium(result.getFloat("stellium")); - data.setStamina(result.getFloat("stamina")); - data.setClassPoints(result.getInt("class_points")); data.setSkillPoints(result.getInt("skill_points")); data.setSkillReallocationPoints(result.getInt("skill_reallocation_points")); @@ -127,6 +123,7 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer { 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); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index e6f8ca30..8763cce3 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -44,7 +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.getPlayer().getHealth()); + updater.addData("health",data.getHealth()); updater.addData("mana", data.getMana()); updater.addData("stellium", data.getStellium()); updater.addData("stamina", data.getStamina()); diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index e2f663c7..66bae5bb 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -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); }