mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-03 21:15:28 +02:00
Fix bug with levels up commands reporting incorrect level
This commit is contained in:
@@ -1123,7 +1123,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
||||
*/
|
||||
public static int getXpNeededToLevel(int level) {
|
||||
return mcMMO.getFormulaManager().getXPtoNextLevel(level, ExperienceConfig.getInstance().getFormulaType());
|
||||
return mcMMO.p.getFormulaManager().getXPtoNextLevel(level, ExperienceConfig.getInstance().getFormulaType());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1137,7 +1137,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
||||
*/
|
||||
public static int getXpNeededToLevel(int level, String formulaType) {
|
||||
return mcMMO.getFormulaManager().getXPtoNextLevel(level, getFormulaType(formulaType));
|
||||
return mcMMO.p.getFormulaManager().getXPtoNextLevel(level, getFormulaType(formulaType));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,7 +18,7 @@ public class ConvertExperienceCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 2) {
|
||||
FormulaType previousType = mcMMO.getFormulaManager().getPreviousFormulaType();
|
||||
FormulaType previousType = mcMMO.p.getFormulaManager().getPreviousFormulaType();
|
||||
FormulaType newType = FormulaType.getFormulaType(args[1].toUpperCase(Locale.ENGLISH));
|
||||
|
||||
if (newType == FormulaType.UNKNOWN) {
|
||||
|
@@ -199,7 +199,7 @@ public class ExperienceConfig extends BukkitConfig {
|
||||
|
||||
/* Curve settings */
|
||||
public FormulaType getFormulaType() {
|
||||
return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve"));
|
||||
return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve", "LINEAR"));
|
||||
}
|
||||
|
||||
public boolean getCumulativeCurveEnabled() {
|
||||
@@ -208,11 +208,13 @@ public class ExperienceConfig extends BukkitConfig {
|
||||
|
||||
/* Curve values */
|
||||
public double getMultiplier(FormulaType type) {
|
||||
return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.multiplier");
|
||||
double def = type == FormulaType.LINEAR ? 20D : 0.1D;
|
||||
return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.multiplier", def);
|
||||
}
|
||||
|
||||
public int getBase(FormulaType type) {
|
||||
return config.getInt("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.base");
|
||||
int def = type == FormulaType.LINEAR ? 1020 : 2000;
|
||||
return config.getInt("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.base", def);
|
||||
}
|
||||
|
||||
public double getExponent(FormulaType type) {
|
||||
|
@@ -203,7 +203,7 @@ public class Party {
|
||||
|
||||
public int getXpToLevel() {
|
||||
FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType();
|
||||
return (mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType)) * (getOnlineMembers().size() + mcMMO.p.getGeneralConfig().getPartyXpCurveMultiplier());
|
||||
return (mcMMO.p.getFormulaManager().getXPtoNextLevel(level, formulaType)) * (getOnlineMembers().size() + mcMMO.p.getGeneralConfig().getPartyXpCurveMultiplier());
|
||||
}
|
||||
|
||||
public String getXpToLevelPercentage() {
|
||||
|
@@ -663,7 +663,7 @@ public class McMMOPlayer implements Identified {
|
||||
}
|
||||
|
||||
final McMMOPlayerPreXpGainEvent mcMMOPlayerPreXpGainEvent = new McMMOPlayerPreXpGainEvent(player, primarySkillType, xp, xpGainReason);
|
||||
Bukkit.getPluginManager().callEvent(mcMMOPlayerPreXpGainEvent);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(mcMMOPlayerPreXpGainEvent);
|
||||
xp = mcMMOPlayerPreXpGainEvent.getXpGained();
|
||||
|
||||
if (SkillTools.isChildSkill(primarySkillType)) {
|
||||
|
@@ -428,7 +428,7 @@ public class PlayerProfile {
|
||||
int level = (ExperienceConfig.getInstance().getCumulativeCurveEnabled()) ? UserManager.getPlayer(playerName).getPowerLevel() : skills.get(primarySkillType);
|
||||
FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType();
|
||||
|
||||
return mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType);
|
||||
return mcMMO.p.getFormulaManager().getXPtoNextLevel(level, formulaType);
|
||||
}
|
||||
|
||||
private int getChildSkillLevel(PrimarySkillType primarySkillType) {
|
||||
|
@@ -60,9 +60,9 @@ public class SelfListener implements Listener {
|
||||
}
|
||||
|
||||
final Set<Integer> levelsAchieved = new LinkedHashSet<>();
|
||||
for(int i = 1; i <= event.getLevelsGained(); i++)
|
||||
{
|
||||
levelsAchieved.add(event.getSkillLevel() + i);
|
||||
int startingLevel = event.getSkillLevel() - event.getLevelsGained();
|
||||
for (int i = 0; i < event.getLevelsGained(); i++) {
|
||||
levelsAchieved.add(startingLevel + (i + 1));
|
||||
}
|
||||
plugin.getLevelUpCommandManager().apply(mcMMOPlayer, skill, levelsAchieved);
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private static SalvageableManager salvageableManager;
|
||||
private static ModManager modManager;
|
||||
private static DatabaseManager databaseManager;
|
||||
private static FormulaManager formulaManager;
|
||||
private FormulaManager formulaManager;
|
||||
private static UpgradeManager upgradeManager;
|
||||
private static LevelUpCommandManager levelUpCommandManager;
|
||||
private static MaterialMapStore materialMapStore;
|
||||
@@ -428,7 +428,7 @@ public class mcMMO extends JavaPlugin {
|
||||
xpEventEnabled = !xpEventEnabled;
|
||||
}
|
||||
|
||||
public static FormulaManager getFormulaManager() {
|
||||
public FormulaManager getFormulaManager() {
|
||||
return formulaManager;
|
||||
}
|
||||
|
||||
|
@@ -52,7 +52,7 @@ public class FormulaConversionTask extends BukkitRunnable {
|
||||
convertedUsers++;
|
||||
Misc.printProgress(convertedUsers, DatabaseManager.progressInterval, startMillis);
|
||||
}
|
||||
mcMMO.getFormulaManager().setPreviousFormulaType(formulaType);
|
||||
mcMMO.p.getFormulaManager().setPreviousFormulaType(formulaType);
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Finish", formulaType.toString()));
|
||||
}
|
||||
@@ -63,13 +63,13 @@ public class FormulaConversionTask extends BukkitRunnable {
|
||||
for (PrimarySkillType primarySkillType : SkillTools.NON_CHILD_SKILLS) {
|
||||
int oldLevel = profile.getSkillLevel(primarySkillType);
|
||||
int oldXPLevel = profile.getSkillXpLevel(primarySkillType);
|
||||
int totalOldXP = mcMMO.getFormulaManager().calculateTotalExperience(oldLevel, oldXPLevel);
|
||||
int totalOldXP = mcMMO.p.getFormulaManager().calculateTotalExperience(oldLevel, oldXPLevel);
|
||||
|
||||
if (totalOldXP == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(primarySkillType, (int) Math.floor(totalOldXP / ExperienceConfig.getInstance().getExpModifier()), formulaType);
|
||||
int[] newExperienceValues = mcMMO.p.getFormulaManager().calculateNewLevel(primarySkillType, (int) Math.floor(totalOldXP / ExperienceConfig.getInstance().getExpModifier()), formulaType);
|
||||
int newLevel = newExperienceValues[0];
|
||||
int newXPlevel = newExperienceValues[1];
|
||||
|
||||
|
@@ -263,7 +263,6 @@ public final class EventUtils {
|
||||
if (isLevelUp) {
|
||||
NotificationManager.processLevelUpBroadcasting(mmoPlayer, skill, mmoPlayer.getSkillLevel(skill));
|
||||
NotificationManager.processPowerLevelUpBroadcasting(mmoPlayer, mmoPlayer.getPowerLevel());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.LogUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@@ -25,7 +26,19 @@ public class FormulaManager {
|
||||
public FormulaManager() {
|
||||
/* Setting for Classic Mode (Scales a lot of stuff up by * 10) */
|
||||
initExperienceNeededMaps();
|
||||
loadFormula();
|
||||
if (!formulaFile.exists()) {
|
||||
previousFormula = FormulaType.UNKNOWN;
|
||||
return;
|
||||
}
|
||||
|
||||
previousFormula = FormulaType.getFormulaType(YamlConfiguration.loadConfiguration(formulaFile).getString("Previous_Formula", "UNKNOWN"));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public FormulaManager(FormulaType previousFormulaType) {
|
||||
/* Setting for Classic Mode (Scales a lot of stuff up by * 10) */
|
||||
initExperienceNeededMaps();
|
||||
this.previousFormula = previousFormulaType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +135,7 @@ public class FormulaManager {
|
||||
*/
|
||||
|
||||
//TODO: When the heck is Unknown used?
|
||||
if (formulaType == FormulaType.UNKNOWN) {
|
||||
if (formulaType == null || formulaType == FormulaType.UNKNOWN) {
|
||||
formulaType = FormulaType.LINEAR;
|
||||
}
|
||||
|
||||
@@ -209,18 +222,6 @@ public class FormulaManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load formula file.
|
||||
*/
|
||||
public void loadFormula() {
|
||||
if (!formulaFile.exists()) {
|
||||
previousFormula = FormulaType.UNKNOWN;
|
||||
return;
|
||||
}
|
||||
|
||||
previousFormula = FormulaType.getFormulaType(YamlConfiguration.loadConfiguration(formulaFile).getString("Previous_Formula", "UNKNOWN"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save formula file.
|
||||
*/
|
||||
|
@@ -139,7 +139,7 @@ public class NotificationManager {
|
||||
notificationType, message, destination, mcMMO.p.getAdvancedConfig().doesNotificationSendCopyToChat(notificationType));
|
||||
|
||||
//Call event
|
||||
Bukkit.getServer().getPluginManager().callEvent(customEvent);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(customEvent);
|
||||
return customEvent;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user