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 f3ce33d7..3bb5a1c3 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 @@ -738,9 +738,13 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD public void setLevel(int level, @NotNull PlayerLevelChangeEvent.Reason reason) { + // Compute effective new level final var oldLevel = getLevel(); var newLevel = Math.max(1, level); if (getProfess().hasMaxLevel()) newLevel = Math.min(getProfess().getMaxLevel(), newLevel); + + if (oldLevel == newLevel) return; // Safeguard when changing class + this.level = newLevel; if (reason != PlayerLevelChangeEvent.Reason.CHOOSE_PROFILE) // No event, data is loaded async 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 bd940af3..ead1daf6 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 @@ -316,32 +316,25 @@ public class SavedClassInformation implements ClassDataContainer { // Patch player data /////////////////////////////////////////////// - final int targetLevel, - targetSkillPoints, - targetAttributePoints, - targetSkillReallocationPoints, - targetAttributeReallocationPoints; - final double targetExp; - - // Fetch info from last class - if (lastClassPlayed != null) { - targetLevel = lastClassPlayed.level; - targetExp = lastClassPlayed.experience; - targetSkillPoints = lastClassPlayed.skillPoints + lastClassPlayed.countSpentSkillPoints() - this.countSpentSkillPoints(); - targetAttributePoints = lastClassPlayed.attributePoints + lastClassPlayed.countSpentAttributePoints() - this.countSpentAttributePoints(); - targetSkillReallocationPoints = lastClassPlayed.skillReallocationPoints; - targetAttributeReallocationPoints = lastClassPlayed.attributeReallocationPoints; - } - - // Fetch info from saved class info - else { - targetLevel = level; - targetExp = experience; - targetSkillPoints = this.skillPoints; - targetAttributePoints = this.attributePoints; - targetSkillReallocationPoints = this.skillReallocationPoints; - targetAttributeReallocationPoints = this.attributeReallocationPoints; - } + final var conf = MMOCore.plugin.configManager; + final var targetLevel = lastClassPlayed != null && conf.shareExp + ? lastClassPlayed.level + : level; + final var targetExp = lastClassPlayed != null && conf.shareExp + ? lastClassPlayed.experience + : experience; + final var targetSkillPoints = lastClassPlayed != null && conf.shareSkillPts + ? lastClassPlayed.skillPoints + lastClassPlayed.countSpentSkillPoints() - this.countSpentSkillPoints() + : this.skillPoints; + final var targetAttributePoints = lastClassPlayed != null && conf.shareAttributePts + ? lastClassPlayed.attributePoints + lastClassPlayed.countSpentAttributePoints() - this.countSpentAttributePoints() + : this.attributePoints; + final var targetSkillReallocationPoints = lastClassPlayed != null && conf.shareSkillReallocPts + ? lastClassPlayed.skillReallocationPoints + : this.skillReallocationPoints; + final var targetAttributeReallocationPoints = lastClassPlayed != null && conf.shareAttributeReallocPts + ? lastClassPlayed.attributeReallocationPoints + : this.attributeReallocationPoints; /////////////////////////////////////////////// // Apply player data diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index c8572d22..923d5702 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -25,7 +25,8 @@ import java.util.logging.Level; public class ConfigManager { public boolean overrideVanillaExp, canCreativeCast, passiveSkillsNeedBinding, cobbleGeneratorXP, saveDefaultClassInfo, splitMainExp, splitProfessionExp, disableQuestBossBar, pvpModeEnabled, pvpModeInvulnerabilityCanDamage, forceClassSelection, - enableGlobalSkillTreeGUI, enableSpecificSkillTreeGUI, waypointAutoPathCalculation, waypointLinkReciprocity; + enableGlobalSkillTreeGUI, enableSpecificSkillTreeGUI, waypointAutoPathCalculation, waypointLinkReciprocity, + shareExp, shareSkillPts, shareAttributePts, shareSkillReallocPts, shareAttributeReallocPts; public String partyChatPrefix, noSkillBoundPlaceholder; public ChatColor staminaFull, staminaHalf, staminaEmpty; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; @@ -171,6 +172,13 @@ public class ConfigManager { cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info"); overrideVanillaExp = MMOCore.plugin.getConfig().getBoolean("override-vanilla-exp"); + + // Data share across classes + shareExp = MMOCore.plugin.getConfig().getBoolean("share_across_classes.experience"); + shareSkillPts = MMOCore.plugin.getConfig().getBoolean("share_across_classes.skill_points"); + shareAttributePts = MMOCore.plugin.getConfig().getBoolean("share_across_classes.attribute_points"); + shareSkillReallocPts = MMOCore.plugin.getConfig().getBoolean("share_across_classes.skill_reallocation_points"); + shareAttributeReallocPts = MMOCore.plugin.getConfig().getBoolean("share_across_classes.attribute_reallocation_points"); } @NotNull diff --git a/MMOCore-Dist/src/main/resources/config.yml b/MMOCore-Dist/src/main/resources/config.yml index a1026055..22dcc900 100644 --- a/MMOCore-Dist/src/main/resources/config.yml +++ b/MMOCore-Dist/src/main/resources/config.yml @@ -329,6 +329,20 @@ resource-bar-colors: stamina-half: 'DARK_GREEN' stamina-empty: 'WHITE' +# Define what data you want to be passed along new +# classes when a player changes class. +share_across_classes: + + # When toggling on this, all classes of the player + # will share experience and level. This only makes + # sense if all classes share the same exp curves! + experience: false + + skill_points: false + attribute_points: false + skill_reallocation_points: false + attribute_reallocation_points: false + # Requires WorldGuard to work. Do NOT enable unless # you have WG to avoid weird interact rule issues! #