Improved class skill loading

This commit is contained in:
Indyuce 2022-04-03 01:36:10 +02:00
parent 966ef01b36
commit 83a6af7ad1
3 changed files with 8 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.player.profess;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject; import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.version.VersionMaterial; import io.lumine.mythic.lib.version.VersionMaterial;
@ -133,8 +134,8 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
if (config.contains("skills")) if (config.contains("skills"))
for (String key : config.getConfigurationSection("skills").getKeys(false)) for (String key : config.getConfigurationSection("skills").getKeys(false))
try { try {
Validate.isTrue(MMOCore.plugin.skillManager.hasSkill(key), "Could not find skill " + key); RegisteredSkill registered = MMOCore.plugin.skillManager.getSkillOrThrow(UtilityMethods.enumName(key));
skills.put(key, new ClassSkill(MMOCore.plugin.skillManager.getSkill(key), config.getConfigurationSection("skills." + key))); skills.put(registered.getHandler().getId(), new ClassSkill(registered, config.getConfigurationSection("skills." + key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill info '" + key + "' from class '" MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill info '" + key + "' from class '"
+ id + "': " + exception.getMessage()); + id + "': " + exception.getMessage());

View File

@ -15,6 +15,9 @@ public class Placeholders {
public String apply(Player player, String str) { public String apply(Player player, String str) {
// Remove conditions first
str = removeCondition(str);
// Internal placeholders // Internal placeholders
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) { while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}")); String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
@ -22,7 +25,7 @@ public class Placeholders {
} }
// External placeholders // External placeholders
return MMOCore.plugin.placeholderParser.parse(player, removeCondition(str)); return MMOCore.plugin.placeholderParser.parse(player, str);
} }
private String removeCondition(String str) { private String removeCondition(String str) {

View File

@ -33,11 +33,7 @@ public class SkillManager implements MMOCoreManager {
@NotNull @NotNull
public RegisteredSkill getSkillOrThrow(String id) { public RegisteredSkill getSkillOrThrow(String id) {
return Objects.requireNonNull(skills.get(id.toUpperCase()), "Could not find skill with ID '" + id + "'"); return Objects.requireNonNull(skills.get(id), "Could not find skill with ID '" + id + "'");
}
public boolean hasSkill(String id) {
return skills.containsKey(id.toUpperCase());
} }
public Collection<RegisteredSkill> getAll() { public Collection<RegisteredSkill> getAll() {