Quests appear sorted alphabetically (file name)

This commit is contained in:
Jules 2020-05-21 14:01:08 +02:00
parent 5ffbb37acd
commit ec1500fc28
4 changed files with 32 additions and 20 deletions

View File

@ -114,7 +114,7 @@ public class PlayerProfessions {
}
public boolean hasReachedMaxLevel(Profession profession) {
return profession.getMaxLevel() > 0 && getLevel(profession) >= profession.getMaxLevel();
return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel();
}
public void giveExperience(Profession profession, int value, Location loc) {

View File

@ -35,21 +35,21 @@ public class Profession extends PostLoadObject {
Validate.notNull(name, "Could not load name");
expCurve = config.contains("exp-curve")
? MMOCore.plugin.experience.getOrThrow(config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
? MMOCore.plugin.experience.getOrThrow(
config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
: ExpCurve.DEFAULT;
experience = new LinearValue(config.getConfigurationSection("experience"));
maxLevel = config.contains("max-level")
? config.getInt("max-level")
: -1;
maxLevel = config.getInt("max-level");
if (config.contains("exp-sources"))
for (String key : config.getStringList("exp-sources"))
try {
MMOCore.plugin.professionManager.registerExpSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this));
MMOCore.plugin.professionManager.registerExpSource(
MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not register exp source '" + key
+ "' from profession '" + id + "': " + exception.getMessage());
}
}
@ -68,14 +68,16 @@ public class Profession extends PostLoadObject {
if (config.contains("alchemy-experience")) {
MMOCore.plugin.alchemyManager.splash = 1 + config.getDouble("alchemy-experience.special.splash") / 100;
MMOCore.plugin.alchemyManager.lingering = 1 + config.getDouble("alchemy-experience.special.lingering") / 100;
MMOCore.plugin.alchemyManager.lingering = 1
+ config.getDouble("alchemy-experience.special.lingering") / 100;
MMOCore.plugin.alchemyManager.extend = 1 + config.getDouble("alchemy-experience.special.extend") / 100;
MMOCore.plugin.alchemyManager.upgrade = 1 + config.getDouble("alchemy-experience.special.upgrade") / 100;
for (String key : config.getConfigurationSection("alchemy-experience.effects").getKeys(false))
try {
PotionType type = PotionType.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_"));
MMOCore.plugin.alchemyManager.registerBaseExperience(type, config.getDouble("alchemy-experience.effects." + key));
MMOCore.plugin.alchemyManager.registerBaseExperience(type,
config.getDouble("alchemy-experience.effects." + key));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read potion type from " + key);
}
@ -84,8 +86,10 @@ public class Profession extends PostLoadObject {
if (config.contains("base-enchant-exp"))
for (String key : config.getConfigurationSection("base-enchant-exp").getKeys(false))
try {
Enchantment enchant = MMOLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_"));
MMOCore.plugin.enchantManager.registerBaseExperience(enchant, config.getDouble("base-enchant-exp." + key));
Enchantment enchant = MMOLib.plugin.getVersion().getWrapper()
.getEnchantmentFromString(key.toLowerCase().replace("-", "_"));
MMOCore.plugin.enchantManager.registerBaseExperience(enchant,
config.getDouble("base-enchant-exp." + key));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read enchant from " + key);
}
@ -94,7 +98,8 @@ public class Profession extends PostLoadObject {
for (String key : config.getConfigurationSection("repair-exp").getKeys(false))
try {
Material material = Material.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_"));
MMOCore.plugin.smithingManager.registerBaseExperience(material, config.getDouble("repair-exp." + key));
MMOCore.plugin.smithingManager.registerBaseExperience(material,
config.getDouble("repair-exp." + key));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read material from " + key);
}
@ -128,6 +133,10 @@ public class Profession extends PostLoadObject {
return maxLevel;
}
public boolean hasMaxLevel() {
return maxLevel > 0;
}
public int calculateExperience(int x) {
return (int) experience.calculate(x);
}

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.manager;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
@ -14,11 +15,10 @@ import net.Indyuce.mmocore.api.quest.Quest;
public class QuestManager extends MMOManager {
private final Map<String, Quest> quests = new LinkedHashMap<>();
public void load(File file) {
if (file.isDirectory())
for (File subfile : file.listFiles())
load(subfile);
Arrays.asList(file.listFiles()).stream().sorted().forEach(subfile -> load(subfile));
else
try {
register(new Quest(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)));

View File

@ -33,11 +33,14 @@ public class SkillManager {
if (skills.isEmpty())
try {
JarFile jarFile = new JarFile(MMOCore.plugin.getJarFile());
JarEntry entry;
for (Enumeration<JarEntry> en = new JarFile(MMOCore.plugin.getJarFile()).entries(); en.hasMoreElements();)
if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/") && !entry.isDirectory()
&& !entry.getName().contains("$"))
register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", "")).newInstance());
for (Enumeration<JarEntry> en = jarFile.entries(); en.hasMoreElements();)
if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/")
&& !entry.isDirectory() && !entry.getName().contains("$"))
register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", ""))
.newInstance());
jarFile.close();
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException exception) {
exception.printStackTrace();
MMOCore.log(Level.WARNING, "Could not load skills! Careful with player data :(");