Fixed issue with custom mining

This commit is contained in:
Indyuce 2022-01-22 14:34:34 +01:00
parent 9d34d4d655
commit 5dd1e2534e
3 changed files with 22 additions and 15 deletions

View File

@ -47,7 +47,7 @@ public class PlayerProfessions {
if (config.contains("times-claimed")) if (config.contains("times-claimed"))
// Watch out for the deep section lookup // Watch out for the deep section lookup
for (String key : config.getConfigurationSection("times-claimed").getKeys(true)) 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; return this;
} }
@ -95,7 +95,7 @@ public class PlayerProfessions {
// Load times claimed // Load times claimed
if (obj.has("timesClaimed")) if (obj.has("timesClaimed"))
for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet()) for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet())
playerData.setProfessionExpItemClaims(entry.getKey(), entry.getValue().getAsInt()); playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt());
} }
public PlayerData getPlayerData() { public PlayerData getPlayerData() {

View File

@ -16,7 +16,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
public class Profession implements ExperienceObject { public class Profession extends PostLoadObject implements ExperienceObject {
private final String id, name; private final String id, name;
private final int maxLevel; private final int maxLevel;
private final Map<ProfessionOption, Boolean> options = new HashMap<>(); private final Map<ProfessionOption, Boolean> options = new HashMap<>();
@ -30,6 +30,8 @@ public class Profession implements ExperienceObject {
private final LinearValue experience; private final LinearValue experience;
public Profession(String id, FileConfiguration config) { public Profession(String id, FileConfiguration config) {
super(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = config.getString("name"); this.name = config.getString("name");
Validate.notNull(name, "Could not load 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()); "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) { public boolean getOption(ProfessionOption option) {
return options.getOrDefault(option, option.getDefault()); return options.getOrDefault(option, option.getDefault());
@ -89,7 +92,7 @@ public class Profession implements ExperienceObject {
} }
@Override @Override
public String geyKey() { public String getKey() {
return "profession." + getId(); return "profession." + getId();
} }

View File

@ -16,11 +16,6 @@ public class ProfessionManager implements MMOCoreManager {
private final Map<String, Profession> professions = new HashMap<>(); private final Map<String, Profession> professions = new HashMap<>();
private final Set<SpecificProfessionManager> professionManagers = new HashSet<>(); private final Set<SpecificProfessionManager> professionManagers = new HashSet<>();
/**
* If it has been loaded at least once
*/
private boolean loadedOnce;
public void register(Profession profession) { public void register(Profession profession) {
professions.put(profession.getId(), profession); professions.put(profession.getId(), profession);
} }
@ -63,17 +58,18 @@ public class ProfessionManager implements MMOCoreManager {
if (clearBefore) if (clearBefore)
professions.clear(); professions.clear();
// Load default profession managers (can't be done on constructor because MMOCore.plugin is null) // Load default profession managers (can't be done on constructor because MMOCore.plugin is null)
if (!loadedOnce) { else {
registerProfessionManager(MMOCore.plugin.alchemyManager); registerProfessionManager(MMOCore.plugin.alchemyManager);
registerProfessionManager(MMOCore.plugin.mineManager);
registerProfessionManager(MMOCore.plugin.enchantManager); registerProfessionManager(MMOCore.plugin.enchantManager);
registerProfessionManager(MMOCore.plugin.fishingManager); registerProfessionManager(MMOCore.plugin.fishingManager);
registerProfessionManager(MMOCore.plugin.smithingManager); registerProfessionManager(MMOCore.plugin.smithingManager);
loadedOnce = true;
} }
professionManagers.forEach(manager -> manager.initialize(clearBefore)); professionManagers.forEach(manager -> manager.initialize(clearBefore));
// Register professions
for (File file : new File(MMOCore.plugin.getDataFolder() + "/professions").listFiles()) for (File file : new File(MMOCore.plugin.getDataFolder() + "/professions").listFiles())
try { try {
String id = file.getName().substring(0, file.getName().length() - 4); String id = file.getName().substring(0, file.getName().length() - 4);
@ -81,5 +77,13 @@ public class ProfessionManager implements MMOCoreManager {
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession " + file.getName() + ": " + exception.getMessage()); 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());
}
} }
} }