diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java index ebe98084..81e4d533 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java @@ -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) { diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java index fbf949b0..46317d6f 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java @@ -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); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java b/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java index c371e0f8..3bce6953 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java @@ -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 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))); diff --git a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java index d7ed9396..02748fc8 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java @@ -33,11 +33,14 @@ public class SkillManager { if (skills.isEmpty()) try { + JarFile jarFile = new JarFile(MMOCore.plugin.getJarFile()); JarEntry entry; - for (Enumeration 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 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 :(");