Improved console error warnings

This commit is contained in:
Indyuce 2020-05-01 19:07:00 +02:00
parent 1ce01d7be0
commit dc97cbeac9
14 changed files with 89 additions and 112 deletions

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.block;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
@ -12,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.DropTable;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
@ -48,8 +48,9 @@ public class BlockInfo {
for (String key : list)
try {
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key)));
} catch (MMOLoadException exception) {
exception.printConsole("BlockRegen", "trigger");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load trigger '" + key + "' from block info '" + block.generateKey() + "': " + exception.getMessage());
}
}

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.droptable;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
@ -10,48 +11,54 @@ import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.load.PostLoadObject;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.mmogroup.mmolib.api.MMOLineConfig;
public class DropTable {
public class DropTable extends PostLoadObject {
private final String id;
private final Set<DropItem> drops = new LinkedHashSet<>();
/*
* cached in order to load other items.
*/
private ConfigurationSection loaded;
public DropTable(ConfigurationSection config) {
super(config);
public DropTable(ConfigurationSection section) {
id = section.getName();
loaded = section;
id = config.getName();
}
public DropTable(String id) {
super(null);
this.id = id;
}
/*
* must be loaded after since drop tables must be initialized first
* otherwise no reference for drop table drop items.
*/
public DropTable load() {
List<String> list = loaded.getStringList("items");
@Override
protected void whenPostLoaded(ConfigurationSection config) {
List<String> list = config.getStringList("items");
Validate.notNull(list, "Could not find drop item list");
for (String key : list)
try {
drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key)));
} catch (MMOLoadException exception) {
exception.printConsole("DropTables", "drop item");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load drop item '" + key + "' from table '" + id + "': " + exception.getMessage());
}
loaded = null;
return this;
}
public String getId() {
return id;
}
public void registerDropItem(DropItem item) {
Validate.notNull(item);
drops.add(item);
}
public List<ItemStack> collect(LootBuilder builder) {
for (DropItem item : drops)

View File

@ -4,18 +4,19 @@ import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.potion.PotionType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.load.PostLoadObject;
import net.Indyuce.mmocore.api.player.ExpCurve;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.MMOLineConfig;
public class Profession {
public class Profession extends PostLoadObject {
private final String id, name;
private final ExpCurve expCurve;
@ -25,15 +26,10 @@ public class Profession {
*/
private final LinearValue experience;
/*
* removed when loaded
*/
private FileConfiguration config;
public Profession(String id, FileConfiguration config) {
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.config = config;
super(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = config.getString("name");
Validate.notNull(name, "Could not load name");
@ -46,15 +42,17 @@ public class Profession {
for (String key : config.getStringList("exp-sources"))
try {
MMOCore.plugin.professionManager.registerExpSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this));
} catch (MMOLoadException exception) {
exception.printConsole("PlayerProfessions", "exp source");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage());
}
}
/*
* drop tables must be loaded after professions are initialized
*/
public void loadOptions() {
@Override
protected void whenPostLoaded(ConfigurationSection config) {
if (config.contains("on-fish"))
MMOCore.plugin.fishingManager.loadDropTables(config.getConfigurationSection("on-fish"));
@ -103,11 +101,10 @@ public class Profession {
// MMOCore.plugin.alchemyManager.registerEffectWeight(PotionEffectType.getByName(key.toUpperCase().replace("-",
// "_").replace(" ", "_")), config.getDouble("effect-weight." + key));
// } catch (IllegalArgumentException exception) {
// MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read
// MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not
// read
// potion effect type from " + key);
// }
config = null;
}
public String getId() {

View File

@ -1,30 +0,0 @@
package net.Indyuce.mmocore.api.load;
import java.util.logging.Level;
import net.Indyuce.mmocore.MMOCore;
import net.mmogroup.mmolib.api.MMOLineConfig;
public class MMOLoadException extends IllegalArgumentException {
private static final long serialVersionUID = -8839506644440697800L;
private MMOLineConfig config;
public MMOLoadException(String message) {
super(message);
}
public MMOLoadException(MMOLineConfig config, Exception exception) {
super(exception.getMessage());
this.config = config;
}
public boolean hasConfig() {
return config != null;
}
public void printConsole(String prefix, String obj) {
MMOCore.plugin.getLogger().log(Level.WARNING, "[" + prefix + "] " + (hasConfig() ? "Could not load " + obj + " '" + config.toString() + "': " : "") + getMessage());
}
}

View File

@ -25,7 +25,6 @@ import com.mojang.authlib.properties.Property;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.load.PostLoadObject;
import net.Indyuce.mmocore.api.player.ExpCurve;
import net.Indyuce.mmocore.api.player.profess.event.EventTrigger;
@ -98,7 +97,8 @@ public class PlayerClass extends PostLoadObject {
stats.put(StatType.valueOf(key.toUpperCase().replace("-", "_")),
new LinearValue(config.getConfigurationSection("attributes." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load stat info '" + key + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load stat info '" + key + "' from class '" + id + "': " + exception.getMessage());
}
if (config.contains("skills"))
@ -107,7 +107,8 @@ public class PlayerClass extends PostLoadObject {
Validate.isTrue(MMOCore.plugin.skillManager.has(key), "Could not find skill " + key);
skills.put(key.toUpperCase(), MMOCore.plugin.skillManager.get(key).newSkillInfo(config.getConfigurationSection("skills." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load skill info '" + key + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load skill info '" + key + "' from class '" + id + "': " + exception.getMessage());
}
castParticle = config.contains("cast-particle") ? new CastingParticle(config.getConfigurationSection("cast-particle"))
@ -118,7 +119,8 @@ public class PlayerClass extends PostLoadObject {
try {
setOption(ClassOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")), config.getBoolean("options." + key));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not read class option from '" + key + "'");
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load option '" + key + "' from class '" + key + "': " + exception.getMessage());
}
if (config.contains("main-exp-sources"))
@ -127,8 +129,9 @@ public class PlayerClass extends PostLoadObject {
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), null);
source.setClass(this);
MMOCore.plugin.professionManager.registerExpSource(source);
} catch (MMOLoadException exception) {
exception.printConsole("PlayerClasses:" + id, "exp source");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load exp source '" + key + "' from class '" + id + "': " + exception.getMessage());
}
if (config.contains("triggers"))

View File

@ -3,11 +3,11 @@ package net.Indyuce.mmocore.api.player.profess.event;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.mmogroup.mmolib.api.MMOLineConfig;
@ -17,17 +17,18 @@ public class EventTrigger {
public EventTrigger(String event, List<String> list) {
Validate.notNull(list, "Could not load trigger list");
this.event = event;
for (String format : list)
try {
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format)));
} catch (MMOLoadException exception) {
exception.printConsole("EventTrigger:" + event, "trigger");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load trigger '" + format + "' from event trigger '" + event + "': " + exception.getMessage());
}
}
public String getEvent() {
return event;
}

View File

@ -13,7 +13,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.load.PostLoadObject;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.objective.Objective;
@ -64,8 +63,9 @@ public class Quest extends PostLoadObject {
Validate.notNull(format, "Objective is missing format");
objectives.add(MMOCore.plugin.loadManager.loadObjective(new MMOLineConfig(format), section));
} catch (MMOLoadException exception) {
exception.printConsole("Quests:" + id, "objective");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load objective '" + key + "' from quest '" + id + "': " + exception.getMessage());
}
}

View File

@ -2,13 +2,13 @@ package net.Indyuce.mmocore.api.quest.objective;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.boss.BarColor;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
import net.Indyuce.mmocore.api.quest.QuestProgress;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
@ -17,7 +17,7 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
public abstract class Objective {
private final String id, lore;
private BarColor barColor;
private final BarColor barColor;
private final List<Trigger> triggers = new ArrayList<>();
public Objective(ConfigurationSection config) {
@ -27,19 +27,15 @@ public abstract class Objective {
Validate.notNull(lore, "Could not find objective lore");
Validate.notNull(config.getStringList("triggers"), "Could not load trigger list");
try {
String format = config.getString("bar-color");
Validate.notNull(format);
barColor = BarColor.valueOf(format.toUpperCase().replace("-", "_").replace(" ", "_"));
} catch (IllegalArgumentException exeption) {
barColor = BarColor.PURPLE;
}
String format = config.getString("bar-color", "PURPLE");
barColor = BarColor.valueOf(format.toUpperCase().replace("-", "_").replace(" ", "_"));
for (String key : config.getStringList("triggers"))
try {
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key)));
} catch (MMOLoadException exception) {
exception.printConsole("Objectives:" + id, "trigger");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load trigger '" + key + "' from objective '" + id + "': " + exception.getMessage());
}
}

View File

@ -10,14 +10,14 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.util.item.ConfigItem;
public class ConfigItemManager {
private Map<String, ConfigItem> map = new HashMap<>();
private final Map<String, ConfigItem> map = new HashMap<>();
public ConfigItemManager(FileConfiguration config) {
for (String key : config.getKeys(false))
try {
register(new ConfigItem(config.getConfigurationSection(key)));
} catch (NullPointerException | IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.INFO, "Could not load config item " + key);
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load config item " + key);
}
}

View File

@ -24,7 +24,6 @@ import net.Indyuce.mmocore.api.block.SkullBlockType;
import net.Indyuce.mmocore.api.block.VanillaBlockType;
import net.Indyuce.mmocore.api.droptable.condition.Condition;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.mmogroup.mmolib.api.MMOLineConfig;
@ -126,8 +125,8 @@ public class CustomBlockManager extends MMOManager {
for (String key : MMOCore.plugin.getConfig().getStringList("custom-mine-conditions"))
try {
customMineConditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
} catch (MMOLoadException exception) {
exception.printConsole("CustomMine", "condition");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage());
}
}

View File

@ -47,8 +47,11 @@ public class DropTableManager extends MMOManager {
if (obj instanceof String)
return get((String) obj);
if (obj instanceof ConfigurationSection)
return new DropTable((ConfigurationSection) obj).load();
if (obj instanceof ConfigurationSection) {
DropTable table = new DropTable((ConfigurationSection) obj);
table.postLoad();
return table;
}
throw new IllegalArgumentException("Could not parse drop table.");
}
@ -70,7 +73,7 @@ public class DropTableManager extends MMOManager {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load drop table file '" + file.getName() + "': " + exception.getMessage());
}
map.values().forEach(table -> table.load());
map.values().forEach(table -> table.postLoad());
}
@Override

View File

@ -15,7 +15,6 @@ import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.load.DefaultMMOLoader;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.load.MMOLoader;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
@ -67,10 +66,11 @@ public class MMOLoadManager {
if (found != null)
return found;
} catch (IllegalArgumentException | JsonParseException | IndexOutOfBoundsException exception) {
throw new MMOLoadException("Could not load '" + config.toString() + "': " + exception.getMessage());
throw new IllegalArgumentException("Could not load '" + config.toString() + "': " + exception.getMessage());
}
}
throw new MMOLoadException("Could not load '" + config.toString() + "': Could not find corresponding " + c.getSimpleName() + " in database");
throw new IllegalArgumentException(
"Could not load '" + config.toString() + "': Could not find corresponding " + c.getSimpleName() + " in database");
}
}

View File

@ -16,7 +16,6 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.condition.Condition;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.manager.MMOManager;
import net.mmogroup.mmolib.api.MMOLineConfig;
@ -50,7 +49,7 @@ public class FishingManager extends MMOManager {
private final Set<Condition> conditions = new HashSet<>();
private final List<FishingDropItem> items = new ArrayList<>();
private int maxWeight = 0;
public FishingDropTable(ConfigurationSection section) {
Validate.notNull(section, "Could not load config");
this.id = section.getName();
@ -62,8 +61,9 @@ public class FishingManager extends MMOManager {
for (String str : list)
try {
conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(str)));
} catch (MMOLoadException exception) {
exception.printConsole("FishDropTables", "fish drop item");
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load condition '" + str + "' from fishing drop table '" + id + "': " + exception.getMessage());
}
}
@ -75,10 +75,9 @@ public class FishingManager extends MMOManager {
FishingDropItem dropItem = new FishingDropItem(str);
maxWeight += dropItem.getWeight();
items.add(dropItem);
} catch (MMOLoadException exception) {
exception.printConsole("FishDropTables:" + id, "drop item");
} catch (IllegalArgumentException | IndexOutOfBoundsException exception) {
MMOCore.log(Level.WARNING, "[FishDropTables:" + id + "] Could not load item '" + str + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load item '" + str + "' from fishing drop table '" + id + "': " + exception.getMessage());
}
Validate.notEmpty(list, "The item list must not be empty.");
@ -100,8 +99,9 @@ public class FishingManager extends MMOManager {
for (FishingDropItem item : items) {
weight -= item.getWeight();
if(weight <= 0) return item;
if (weight <= 0)
return item;
}
throw new NullPointerException("Could not find item in drop table");

View File

@ -34,7 +34,7 @@ public class ProfessionManager extends MMOManager {
@SuppressWarnings("unchecked")
public <T extends ExperienceSource<?>> void registerExpSource(T source) {
Class<T> path = (Class<T>) source.getClass();
if (!managers.containsKey(path))
managers.put(path, source.newManager());
getManager(path).register(source);
@ -66,7 +66,7 @@ public class ProfessionManager extends MMOManager {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession " + file.getName() + ": " + exception.getMessage());
}
getAll().forEach(profession -> profession.loadOptions());
getAll().forEach(profession -> profession.postLoad());
}
@Override