Moves some methods from EconomyConfig to EconomyHelper and tries to simplify EconomyConfig

This commit is contained in:
2021-11-23 07:20:48 +01:00
parent ab9a118d49
commit 22bb75d4df
8 changed files with 165 additions and 182 deletions

@ -68,11 +68,11 @@ public class CommandConfig implements CommandExecutor {
switch (selectedOption.getDataType()) {
case BOOLEAN -> configuration.set(selectedOption.getConfigNode(), Boolean.parseBoolean(value));
case INTEGER -> {
try {
configuration.set(selectedOption.getConfigNode(), Integer.parseInt(value));
} catch (NumberFormatException exception) {
commandSender.sendMessage(ChatColor.RED + "Invalid number given");
Integer intValue = getInteger(commandSender, selectedOption, value);
if (intValue == null) {
return;
} else {
configuration.set(selectedOption.getConfigNode(), intValue);
}
}
case STRING -> {
@ -93,6 +93,30 @@ public class CommandConfig implements CommandExecutor {
reloadIfNecessary(commandSender);
}
/**
* Gets an integer from a string
*
* @param commandSender <p>The command sender that sent the config command</p>
* @param selectedOption <p>The option the command sender is trying to change</p>
* @param value <p>The value given</p>
* @return <p>An integer, or null if it was invalid</p>
*/
private Integer getInteger(CommandSender commandSender, ConfigOption selectedOption, String value) {
try {
int intValue = Integer.parseInt(value);
if ((selectedOption == ConfigOption.USE_COST || selectedOption == ConfigOption.CREATE_COST) && intValue < 0) {
commandSender.sendMessage(ChatColor.RED + "This config option cannot be negative.");
return null;
}
return intValue;
} catch (NumberFormatException exception) {
commandSender.sendMessage(ChatColor.RED + "Invalid number given");
return null;
}
}
/**
* Reloads the config if necessary
*