Simplified SettingLoadExcpetion by removing the multi-line error handling.
parent
cf07e1efa4
commit
cb843307da
|
@ -348,9 +348,6 @@ public abstract class Config {
|
|||
protected <T> void onSettingLoadException(Field field, ConfigurationSection config, SettingLoadException e) throws ConfigLoadException {
|
||||
String configKey = this.getConfigKey(field);
|
||||
Log.warning(this.msgSettingLoadException(configKey, e));
|
||||
for (String extraMessage : e.getExtraMessages()) {
|
||||
Log.warning(this.getLogPrefix() + extraMessage);
|
||||
}
|
||||
}
|
||||
|
||||
protected String msgSettingLoadException(String configKey, SettingLoadException e) {
|
||||
|
@ -419,9 +416,6 @@ public abstract class Config {
|
|||
return (T) valueType.load(defaults, configKey);
|
||||
} catch (SettingLoadException e) {
|
||||
Log.warning(this.msgDefaultSettingLoadException(configKey, e));
|
||||
for (String extraMessage : e.getExtraMessages()) {
|
||||
Log.warning(this.getLogPrefix() + extraMessage);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,14 @@
|
|||
package com.nisovin.shopkeepers.config.value;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SettingLoadException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3068903999888105245L;
|
||||
|
||||
private final List<String> extraMessages;
|
||||
|
||||
public SettingLoadException(String message) {
|
||||
this(message, Collections.emptyList());
|
||||
}
|
||||
|
||||
public SettingLoadException(String message, List<String> extraMessages) {
|
||||
super(message);
|
||||
this.extraMessages = extraMessages;
|
||||
}
|
||||
|
||||
public SettingLoadException(String message, Throwable cause) {
|
||||
this(message, Collections.emptyList(), cause);
|
||||
}
|
||||
|
||||
public SettingLoadException(String message, List<String> extraMessages, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.extraMessages = extraMessages;
|
||||
}
|
||||
|
||||
public List<String> getExtraMessages() {
|
||||
return extraMessages;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package com.nisovin.shopkeepers.config.value.types;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.nisovin.shopkeepers.config.value.SettingLoadException;
|
||||
import com.nisovin.shopkeepers.config.value.ValueType;
|
||||
import com.nisovin.shopkeepers.util.ItemData;
|
||||
|
@ -22,15 +18,13 @@ public class ItemDataValue extends ValueType<ItemData> {
|
|||
// Returns null if the config value is null. Otherwise triggers a warning, which we translate into an
|
||||
// exception.
|
||||
itemData = ItemData.deserialize(configValue, (warning) -> {
|
||||
List<String> extraMessages = Collections.emptyList();
|
||||
String errorMsg = warning;
|
||||
if (warning.contains("Unknown item type")) { // TODO this is ugly
|
||||
extraMessages = Arrays.asList(
|
||||
"All valid material names can be found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html"
|
||||
);
|
||||
errorMsg = warning + " (All valid material names can be found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html)";
|
||||
}
|
||||
// We can only throw unchecked exceptions here, so we wrap the exception here and unwrap it again
|
||||
// outside:
|
||||
throw new RuntimeException(new SettingLoadException(warning, extraMessages));
|
||||
throw new RuntimeException(new SettingLoadException(errorMsg));
|
||||
});
|
||||
} catch (RuntimeException e) {
|
||||
if (e.getCause() instanceof SettingLoadException) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.nisovin.shopkeepers.config.value.types;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.nisovin.shopkeepers.config.value.SettingLoadException;
|
||||
|
@ -23,9 +21,8 @@ public class MaterialValue extends ValueType<Material> {
|
|||
// This assumes that legacy item conversion has already been performed:
|
||||
Material material = Material.matchMaterial(materialName); // Can be null
|
||||
if (material == null) {
|
||||
throw new SettingLoadException("Unknown material: " + materialName, Arrays.asList(
|
||||
"All valid material names can be found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html"
|
||||
));
|
||||
throw new SettingLoadException("Unknown material: " + materialName
|
||||
+ " (All valid material names can be found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html)");
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue