From 5dd1e2534e5c62d927dc224eb77373f8df9fa503 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 22 Jan 2022 14:34:34 +0100 Subject: [PATCH] Fixed issue with custom mining --- .../mmocore/experience/PlayerProfessions.java | 4 ++-- .../mmocore/experience/Profession.java | 13 +++++++----- .../manager/profession/ProfessionManager.java | 20 +++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index 36614288..5a257b20 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -47,7 +47,7 @@ public class PlayerProfessions { if (config.contains("times-claimed")) // Watch out for the deep section lookup for (String key : config.getConfigurationSection("times-claimed").getKeys(true)) - playerData.setProfessionExpItemClaims(key, config.getInt("times-claimed." + key)); + playerData.getItemClaims().put("profession." + key, config.getInt("times-claimed." + key)); return this; } @@ -95,7 +95,7 @@ public class PlayerProfessions { // Load times claimed if (obj.has("timesClaimed")) for (Entry entry : obj.getAsJsonObject("timesClaimed").entrySet()) - playerData.setProfessionExpItemClaims(entry.getKey(), entry.getValue().getAsInt()); + playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt()); } public PlayerData getPlayerData() { diff --git a/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/experience/Profession.java index 12e10f5d..8058b847 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.Objects; import java.util.logging.Level; -public class Profession implements ExperienceObject { +public class Profession extends PostLoadObject implements ExperienceObject { private final String id, name; private final int maxLevel; private final Map options = new HashMap<>(); @@ -30,6 +30,8 @@ public class Profession implements ExperienceObject { private final LinearValue experience; public Profession(String id, FileConfiguration config) { + super(config); + this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); this.name = config.getString("name"); Validate.notNull(name, "Could not load name"); @@ -70,11 +72,12 @@ public class Profession implements ExperienceObject { "Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage()); } } - - MMOCore.plugin.professionManager.loadProfessionConfigurations(this, config); } - + @Override + protected void whenPostLoaded(ConfigurationSection configurationSection) { + MMOCore.plugin.professionManager.loadProfessionConfigurations(this, configurationSection); + } public boolean getOption(ProfessionOption option) { return options.getOrDefault(option, option.getDefault()); @@ -89,7 +92,7 @@ public class Profession implements ExperienceObject { } @Override - public String geyKey() { + public String getKey() { return "profession." + getId(); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java index 419d6961..c29a4e99 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java @@ -16,11 +16,6 @@ public class ProfessionManager implements MMOCoreManager { private final Map professions = new HashMap<>(); private final Set professionManagers = new HashSet<>(); - /** - * If it has been loaded at least once - */ - private boolean loadedOnce; - public void register(Profession profession) { professions.put(profession.getId(), profession); } @@ -63,17 +58,18 @@ public class ProfessionManager implements MMOCoreManager { if (clearBefore) professions.clear(); - // Load default profession managers (can't be done on constructor because MMOCore.plugin is null) - if (!loadedOnce) { + // Load default profession managers (can't be done on constructor because MMOCore.plugin is null) + else { registerProfessionManager(MMOCore.plugin.alchemyManager); + registerProfessionManager(MMOCore.plugin.mineManager); registerProfessionManager(MMOCore.plugin.enchantManager); registerProfessionManager(MMOCore.plugin.fishingManager); registerProfessionManager(MMOCore.plugin.smithingManager); - loadedOnce = true; } professionManagers.forEach(manager -> manager.initialize(clearBefore)); + // Register professions for (File file : new File(MMOCore.plugin.getDataFolder() + "/professions").listFiles()) try { String id = file.getName().substring(0, file.getName().length() - 4); @@ -81,5 +77,13 @@ public class ProfessionManager implements MMOCoreManager { } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession " + file.getName() + ": " + exception.getMessage()); } + + // Load profession-specific configurations + for (Profession profession : professions.values()) + try { + profession.postLoad(); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not postload profession " + profession.getId() + ": " + exception.getMessage()); + } } }