Fixes a few issues

Fixes problems when setting a non-string value
Fixes values for some option data types not being available for tab completion
This commit is contained in:
2022-05-30 16:45:04 +02:00
parent 1bfa91a98b
commit a14e3b4d9d
2 changed files with 24 additions and 14 deletions

View File

@@ -88,19 +88,28 @@ public class CommandConfig implements CommandExecutor {
} }
} }
OptionDataType optionDataType = selectedOption.getDataType(); OptionDataType optionDataType = selectedOption.getDataType();
Object typeCastedValue;
//Validate the input based on the data type //Validate the input based on the data type
switch (optionDataType) { switch (optionDataType) {
case INTEGER -> { case INTEGER -> {
if (getInteger(commandSender, selectedOption, value) == null) { Integer intValue = getInteger(commandSender, selectedOption, value);
if (intValue == null) {
return; return;
} else {
typeCastedValue = intValue;
} }
} }
case DOUBLE -> { case DOUBLE -> {
if (getDouble(commandSender, selectedOption, value) == null) { Double doubleValue = getDouble(commandSender, selectedOption, value);
if (doubleValue == null) {
return; return;
} else {
typeCastedValue = doubleValue;
} }
} }
case BOOLEAN -> typeCastedValue = Boolean.parseBoolean(value);
default -> typeCastedValue = value;
} }
/* Test any option data type with a defined set of values. /* Test any option data type with a defined set of values.
@@ -112,7 +121,7 @@ public class CommandConfig implements CommandExecutor {
} }
} }
configurationAPI.setConfigurationOptionValue(selectedOption, value); configurationAPI.setConfigurationOptionValue(selectedOption, typeCastedValue);
saveAndReload(commandSender); saveAndReload(commandSender);
} }

View File

@@ -85,17 +85,18 @@ public class ConfigTabCompleter implements TabCompleter {
* @return <p>Some or all of the valid values for the option</p> * @return <p>Some or all of the valid values for the option</p>
*/ */
private List<String> getPossibleOptionValues(ConfigurationOption selectedOption, String typedText) { private List<String> getPossibleOptionValues(ConfigurationOption selectedOption, String typedText) {
switch (selectedOption) { String[] availableValues = selectedOption.getDataType().getValues();
case LANGUAGE: if (availableValues != null && availableValues.length > 0) {
//Return available languages return filterMatching(List.of(availableValues), typedText);
return filterMatching(List.of(OptionDataType.LANGUAGE.getValues()), typedText); }
case DEFAULT_NETWORK:
//Just return the default value as most values should be possible //Just return the default value as most values should be possible
if (typedText.trim().isEmpty()) { if (selectedOption == ConfigurationOption.DEFAULT_NETWORK) {
return putStringInList((String) selectedOption.getDefaultValue()); if (typedText.trim().isEmpty()) {
} else { return putStringInList((String) selectedOption.getDefaultValue());
return new ArrayList<>(); } else {
} return new ArrayList<>();
}
} }
if (selectedOption.getDataType() == OptionDataType.COLOR) { if (selectedOption.getDataType() == OptionDataType.COLOR) {