Improved some config error messages

This commit is contained in:
Jules 2024-05-24 19:41:49 -07:00
parent daa052cabd
commit 7edd17962c
10 changed files with 19 additions and 23 deletions

View File

@ -85,7 +85,7 @@ public class PlayerAttribute implements ExperienceObject {
@NotNull
@Override
public ExperienceTable getExperienceTable() {
return Objects.requireNonNull(expTable);
return Objects.requireNonNull(expTable, "Attribute has no exp table");
}
@Override

View File

@ -8,7 +8,6 @@ import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import javax.annotation.Nullable;
import java.util.Objects;
public class BindSkillTrigger extends Trigger implements Removable {
private final RegisteredSkill skill;
@ -19,14 +18,13 @@ public class BindSkillTrigger extends Trigger implements Removable {
config.validateKeys("skill", "slot");
slot = config.getInt("slot");
skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(config.getString("skill")));
skill = MMOCore.plugin.skillManager.getSkillOrThrow(config.getString("skill"));
}
@Override
public void apply(PlayerData playerData) {
final @Nullable ClassSkill found = playerData.getProfess().getSkill(skill);
if (found != null)
playerData.bindSkill(slot, found);
if (found != null) playerData.bindSkill(slot, found);
}
@Override

View File

@ -8,7 +8,6 @@ import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import javax.annotation.Nullable;
import java.util.Objects;
public class UnlockSkillTrigger extends Trigger implements Removable {
private final RegisteredSkill skill;
@ -17,7 +16,7 @@ public class UnlockSkillTrigger extends Trigger implements Removable {
super(config);
config.validateKeys("skill");
skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(config.getString("skill")));
skill = MMOCore.plugin.skillManager.getSkillOrThrow(config.getString("skill"));
}
@Override

View File

@ -15,7 +15,6 @@ import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.skill.CastableSkill;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.binding.BoundSkillInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@ -73,7 +72,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
else if (identifier.startsWith("skill_level_")) {
String id = identifier.substring(12);
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(id), "Could not find skill with ID '" + id + "'");
RegisteredSkill skill = MMOCore.plugin.skillManager.getSkillOrThrow(id);
return String.valueOf(playerData.getSkillLevel(skill));
}

View File

@ -29,7 +29,6 @@ import org.bukkit.persistence.PersistentDataType;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ClassSelect extends EditableInventory {
public ClassSelect() {
@ -59,7 +58,7 @@ public class ClassSelect extends EditableInventory {
Validate.isTrue(config.getString("function").length() > 6, "Couldn't find the class associated to: " + config.getString("function"));
String classId = UtilityMethods.enumName(config.getString("function").substring(6));
this.playerClass = Objects.requireNonNull(MMOCore.plugin.classManager.get(classId), classId + " does not correspond to any classId.");
this.playerClass = MMOCore.plugin.classManager.getOrThrow(classId);
this.name = config.getString("name");
this.lore = config.getStringList("lore");
}

View File

@ -3,17 +3,17 @@ package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -25,7 +25,6 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class SubclassSelect extends EditableInventory {
public SubclassSelect() {
@ -50,7 +49,7 @@ public class SubclassSelect extends EditableInventory {
super(config.contains("item") ? Material.valueOf(UtilityMethods.enumName(config.getString("item"))) : Material.BARRIER, config);
Validate.isTrue(config.getString("function").length() > 10, "Couldn't find the class associated to: " + config.getString("function"));
String classId = UtilityMethods.enumName(config.getString("function").substring(10));
this.playerClass = Objects.requireNonNull(MMOCore.plugin.classManager.get(classId), classId + " does not correspond to any classId.");
this.playerClass = MMOCore.plugin.classManager.getOrThrow(classId);
this.name = config.getString("name");
this.lore = config.getStringList("lore");
}

View File

@ -22,8 +22,8 @@ public class Icon {
}
public Icon(ConfigurationSection config) {
this(Material.valueOf(Objects.requireNonNull(UtilityMethods.enumName(
config.getString("item")))), config.contains("custom-model-data") ? config.getInt("custom-model-data") : 0);
this(Material.valueOf(UtilityMethods.enumName(
config.getString("item", "DIRT"))), config.contains("custom-model-data") ? config.getInt("custom-model-data") : 0);
}
public Icon(Material material, int customModelData) {

View File

@ -58,8 +58,9 @@ public class ClassManager implements MMOCoreManager {
}
public PlayerClass getOrThrow(String id) {
Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'");
return map.get(id);
final PlayerClass found = map.get(id);
Validate.notNull(found, "Could not find class with ID '" + id + "'");
return found;
}
public Collection<PlayerClass> getAll() {

View File

@ -216,7 +216,7 @@ public class SkillTreeNode implements ExperienceObject {
@Override
@NotNull
public ExperienceTable getExperienceTable() {
return Objects.requireNonNull(experienceTable);
return Objects.requireNonNull(experienceTable, "Skill tree has no exp table");
}
@Override

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.skilltree.tree;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
@ -32,7 +33,7 @@ import java.util.*;
* @author Ka0rX
* @see {@link SkillTreeNode}
*/
public abstract class SkillTree extends PostLoadObject implements RegisteredObject {
public abstract class SkillTree extends PostLoadObject implements RegisteredObject, PreloadedObject {
private final String id, name;
private final List<String> lore = new ArrayList<>();
private final Material item;
@ -64,7 +65,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
this.id = Objects.requireNonNull(config.getString("id"), "Could not find skill tree id");
this.name = MythicLib.plugin.parseColors(Objects.requireNonNull(config.getString("name"), "Could not find skill tree name"));
Objects.requireNonNull(config.getStringList("lore"), "Could not find skill tree lore").forEach(str -> lore.add(MythicLib.plugin.parseColors(str)));
this.item = Material.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("item"))));
this.item = Material.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("item"), "Could not find item")));
this.customModelData = config.getInt("custom-model-data", 0);
Validate.isTrue(config.isConfigurationSection("nodes"), "Could not find any nodes in the tree");
this.maxPointSpent = config.getInt("max-point-spent", Integer.MAX_VALUE);