Allow loading of different numbers to BigDecimal (Fixes #225)

Also catch wrong types when loading the config better without completely disabling the plugin and revert "Make sure special parsers are setup" and register the parsers static again.
This commit is contained in:
Phoenix616 2019-05-03 21:08:56 +01:00
parent da1dd94705
commit 4769ae2cf7
3 changed files with 6 additions and 5 deletions

View File

@ -63,9 +63,7 @@ public class Configuration {
writer.write(FieldParser.parse(field));
writer.newLine();
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (IllegalArgumentException | IllegalAccessException | IOException e) {
e.printStackTrace();
}
}

View File

@ -146,7 +146,6 @@ public class ChestShop extends JavaPlugin {
}
public void loadConfig() {
Properties.setup();
Configuration.pairFileAndClass(loadFile("config.yml"), Properties.class);
Configuration.pairFileAndClass(loadFile("local.yml"), Messages.class);

View File

@ -21,7 +21,7 @@ import java.util.logging.Level;
*/
public class Properties {
public static void setup() {
static {
Configuration.registerParser("StringSet", new ValueParser(){
public Object parseToJava(Object object) {
if (object instanceof Collection) {
@ -62,6 +62,10 @@ public class Properties {
public Object parseToJava(Object object) {
if (object instanceof Double) {
return BigDecimal.valueOf((Double) object);
} else if (object instanceof Long) {
return BigDecimal.valueOf((Long) object);
} else if (object instanceof Integer) {
return BigDecimal.valueOf((Integer) object);
}
return object;
}