Refactor: 'SettingLoadException' -> 'ValueLoadException'.

master
blablubbabc 2020-11-28 20:58:57 +01:00
parent 55ed27979e
commit 37c39a9671
15 changed files with 48 additions and 48 deletions

View File

@ -13,7 +13,7 @@ import com.nisovin.shopkeepers.config.Config;
import com.nisovin.shopkeepers.config.ConfigLoadException;
import com.nisovin.shopkeepers.config.annotation.WithDefaultValueType;
import com.nisovin.shopkeepers.config.annotation.WithValueTypeProvider;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.types.ColoredStringListValue;
import com.nisovin.shopkeepers.config.value.types.ColoredStringValue;
import com.nisovin.shopkeepers.text.Text;
@ -405,12 +405,12 @@ public class Messages extends Config {
}
@Override
protected String msgSettingLoadException(String configKey, SettingLoadException e) {
protected String msgValueLoadException(String configKey, ValueLoadException e) {
return this.getLogPrefix() + "Could not load message '" + configKey + "': " + e.getMessage();
}
@Override
protected String msgDefaultSettingLoadException(String configKey, SettingLoadException e) {
protected String msgDefaultValueLoadException(String configKey, ValueLoadException e) {
return this.getLogPrefix() + "Could not load default value for message '" + configKey + "': " + e.getMessage();
}

View File

@ -20,7 +20,7 @@ import com.nisovin.shopkeepers.config.annotation.WithDefaultValueType;
import com.nisovin.shopkeepers.config.annotation.WithValueType;
import com.nisovin.shopkeepers.config.annotation.WithValueTypeProvider;
import com.nisovin.shopkeepers.config.value.DefaultValueTypes;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.UnknownMaterialException;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.config.value.ValueTypeProvider;
@ -324,8 +324,8 @@ public abstract class Config {
if (value != null) {
this.setSetting(field, value);
} // Else: Retain previous value.
} catch (SettingLoadException e) {
this.onSettingLoadException(field, config, e);
} catch (ValueLoadException e) {
this.onValueLoadException(field, config, e);
}
}
@ -346,23 +346,23 @@ public abstract class Config {
return this.getLogPrefix() + "Using default value for missing config entry: " + configKey;
}
protected <T> void onSettingLoadException(Field field, ConfigurationSection config, SettingLoadException e) throws ConfigLoadException {
protected <T> void onValueLoadException(Field field, ConfigurationSection config, ValueLoadException e) throws ConfigLoadException {
String configKey = this.getConfigKey(field);
Log.warning(this.msgSettingLoadException(configKey, e));
Log.warning(this.msgValueLoadException(configKey, e));
if (e instanceof UnknownMaterialException) {
Log.warning(this.getLogPrefix() + "All valid material names can be found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html");
}
}
protected String msgSettingLoadException(String configKey, SettingLoadException e) {
protected String msgValueLoadException(String configKey, ValueLoadException e) {
return this.getLogPrefix() + "Could not load setting '" + configKey + "': " + e.getMessage();
}
protected void setSetting(Field field, Object value) throws SettingLoadException {
protected void setSetting(Field field, Object value) throws ValueLoadException {
if (value != null) {
Class<?> fieldType = field.getType();
if (!Utils.isAssignableFrom(fieldType, value.getClass())) {
throw new SettingLoadException("Value is of wrong type: Got " + value.getClass().getName() + ", expected " + fieldType.getName());
throw new ValueLoadException("Value is of wrong type: Got " + value.getClass().getName() + ", expected " + fieldType.getName());
}
}
@ -375,7 +375,7 @@ public abstract class Config {
// Note: The config instance is ignored if the field is static.
field.set(this, value);
} catch (Exception e) {
throw new SettingLoadException(e.getMessage(), e);
throw new ValueLoadException(e.getMessage(), e);
} finally {
// Restore previous accessible state:
try {
@ -418,13 +418,13 @@ public abstract class Config {
try {
// Note: This can return null if the default config does not contain a default value for this setting.
return (T) valueType.load(defaults, configKey);
} catch (SettingLoadException e) {
Log.warning(this.msgDefaultSettingLoadException(configKey, e));
} catch (ValueLoadException e) {
Log.warning(this.msgDefaultValueLoadException(configKey, e));
return null;
}
}
protected String msgDefaultSettingLoadException(String configKey, SettingLoadException e) {
protected String msgDefaultValueLoadException(String configKey, ValueLoadException e) {
return this.getLogPrefix() + "Could not load default value for setting '" + configKey + "': " + e.getMessage();
}

View File

@ -5,7 +5,7 @@ import org.bukkit.Material;
/**
* This exception is issued by {@link ValueType#load(Object)} when an unknown {@link Material} is encountered.
*/
public class UnknownMaterialException extends SettingLoadException {
public class UnknownMaterialException extends ValueLoadException {
private static final long serialVersionUID = 1653518607452366268L;

View File

@ -1,14 +1,14 @@
package com.nisovin.shopkeepers.config.value;
public class SettingLoadException extends Exception {
public class ValueLoadException extends Exception {
private static final long serialVersionUID = -3068903999888105245L;
public SettingLoadException(String message) {
public ValueLoadException(String message) {
super(message);
}
public SettingLoadException(String message, Throwable cause) {
public ValueLoadException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -19,7 +19,7 @@ public abstract class ValueType<T> {
public ValueType() {
}
public T load(ConfigurationSection config, String key) throws SettingLoadException {
public T load(ConfigurationSection config, String key) throws ValueLoadException {
Object configValue = config.get(key);
return this.load(configValue);
}
@ -28,7 +28,7 @@ public abstract class ValueType<T> {
T value = null;
try {
value = this.load(config, key);
} catch (SettingLoadException e) {
} catch (ValueLoadException e) {
}
if (value == null) {
return defaultValue;
@ -38,7 +38,7 @@ public abstract class ValueType<T> {
}
// Null indicates the absence of a value and should only be used if the input has been null.
public abstract T load(Object configValue) throws SettingLoadException;
public abstract T load(Object configValue) throws ValueLoadException;
// A value of null will clear the config entry.
public void save(ConfigurationSection config, String key, T value) {

View File

@ -1,7 +1,7 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.util.ConversionUtils;
public class BooleanValue extends ValueType<Boolean> {
@ -12,11 +12,11 @@ public class BooleanValue extends ValueType<Boolean> {
}
@Override
public Boolean load(Object configValue) throws SettingLoadException {
public Boolean load(Object configValue) throws ValueLoadException {
if (configValue == null) return null;
Boolean value = ConversionUtils.toBoolean(configValue);
if (value == null) {
throw new SettingLoadException("Invalid boolean value: " + configValue);
throw new ValueLoadException("Invalid boolean value: " + configValue);
}
return value;
}

View File

@ -1,6 +1,6 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.util.TextUtils;
public class ColoredStringValue extends StringValue {
@ -11,7 +11,7 @@ public class ColoredStringValue extends StringValue {
}
@Override
public String load(Object configValue) throws SettingLoadException {
public String load(Object configValue) throws ValueLoadException {
return TextUtils.colorize(super.load(configValue));
}

View File

@ -1,7 +1,7 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.util.ConversionUtils;
public class DoubleValue extends ValueType<Double> {
@ -12,11 +12,11 @@ public class DoubleValue extends ValueType<Double> {
}
@Override
public Double load(Object configValue) throws SettingLoadException {
public Double load(Object configValue) throws ValueLoadException {
if (configValue == null) return null;
Double value = ConversionUtils.toDouble(configValue);
if (value == null) {
throw new SettingLoadException("Invalid double value: " + configValue);
throw new ValueLoadException("Invalid double value: " + configValue);
}
return value;
}

View File

@ -1,7 +1,7 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.util.ConversionUtils;
public class IntegerValue extends ValueType<Integer> {
@ -12,11 +12,11 @@ public class IntegerValue extends ValueType<Integer> {
}
@Override
public Integer load(Object configValue) throws SettingLoadException {
public Integer load(Object configValue) throws ValueLoadException {
if (configValue == null) return null;
Integer value = ConversionUtils.toInteger(configValue);
if (value == null) {
throw new SettingLoadException("Invalid integer value: " + configValue);
throw new ValueLoadException("Invalid integer value: " + configValue);
}
return value;
}

View File

@ -1,6 +1,6 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.UnknownMaterialException;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.util.ItemData;
@ -15,14 +15,14 @@ public class ItemDataValue extends ValueType<ItemData> {
}
@Override
public ItemData load(Object configValue) throws SettingLoadException {
public ItemData load(Object configValue) throws ValueLoadException {
try {
// Returns null if the config value is null.
return ItemData.deserialize(configValue);
} catch (UnknownItemTypeException e) {
throw new UnknownMaterialException(e.getMessage(), e);
} catch (ItemDataDeserializeException e) {
throw new SettingLoadException(e.getMessage(), e);
throw new ValueLoadException(e.getMessage(), e);
}
}

View File

@ -3,7 +3,7 @@ package com.nisovin.shopkeepers.config.value.types;
import java.util.ArrayList;
import java.util.List;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.util.Validate;
@ -17,10 +17,10 @@ public class ListValue<E> extends ValueType<List<E>> {
}
@Override
public List<E> load(Object configValue) throws SettingLoadException {
public List<E> load(Object configValue) throws ValueLoadException {
if (configValue == null) return null;
if (!(configValue instanceof List<?>)) {
throw new SettingLoadException("Expecting a list of values, but got " + configValue.getClass().getName());
throw new ValueLoadException("Expecting a list of values, but got " + configValue.getClass().getName());
}
List<?> configValues = (List<?>) configValue;
List<E> values = new ArrayList<>(configValues.size());

View File

@ -1,7 +1,7 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.util.ConversionUtils;
public class LongValue extends ValueType<Long> {
@ -12,11 +12,11 @@ public class LongValue extends ValueType<Long> {
}
@Override
public Long load(Object configValue) throws SettingLoadException {
public Long load(Object configValue) throws ValueLoadException {
if (configValue == null) return null;
Long value = ConversionUtils.toLong(configValue);
if (value == null) {
throw new SettingLoadException("Invalid long value: " + configValue);
throw new ValueLoadException("Invalid long value: " + configValue);
}
return value;
}

View File

@ -2,7 +2,7 @@ package com.nisovin.shopkeepers.config.value.types;
import org.bukkit.Material;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.UnknownMaterialException;
import com.nisovin.shopkeepers.config.value.ValueType;
@ -16,7 +16,7 @@ public class MaterialValue extends ValueType<Material> {
}
@Override
public Material load(Object configValue) throws SettingLoadException {
public Material load(Object configValue) throws ValueLoadException {
String materialName = stringValue.load(configValue);
if (materialName == null) return null;
// This assumes that legacy item conversion has already been performed:

View File

@ -1,6 +1,6 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.ValueType;
public class StringValue extends ValueType<String> {
@ -11,7 +11,7 @@ public class StringValue extends ValueType<String> {
}
@Override
public String load(Object configValue) throws SettingLoadException {
public String load(Object configValue) throws ValueLoadException {
if (configValue == null) return null;
return configValue.toString();
}

View File

@ -1,6 +1,6 @@
package com.nisovin.shopkeepers.config.value.types;
import com.nisovin.shopkeepers.config.value.SettingLoadException;
import com.nisovin.shopkeepers.config.value.ValueLoadException;
import com.nisovin.shopkeepers.config.value.ValueType;
import com.nisovin.shopkeepers.text.Text;
@ -14,7 +14,7 @@ public class TextValue extends ValueType<Text> {
}
@Override
public Text load(Object configValue) throws SettingLoadException {
public Text load(Object configValue) throws ValueLoadException {
return Text.parse(coloredStringValue.load(configValue));
}