config command
This commit is contained in:
@@ -12,10 +12,9 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.itzispyder.ogredupealias.OgreDupeAlias.prefix;
|
||||
|
||||
public class ConfigCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
@@ -33,10 +32,16 @@ public class ConfigCommand implements TabExecutor {
|
||||
FileConfiguration config = Config.get();
|
||||
config.set(path,ConfigDataType.parse(value,type));
|
||||
Config.save(config);
|
||||
sender.sendMessage(Text.builder("&3Config path '&b" + path + "&3' has updated: \n&3Value: &7" + ConfigDataType.parse(value,type)).color().prefix().build());
|
||||
sender.sendMessage(Text.builder("&3Config path '&b" + path + "&3' has updated: \n&3Value: &7" + ConfigDataType.parse(value,type))
|
||||
.color()
|
||||
.prefix()
|
||||
.build());
|
||||
}
|
||||
case "get" -> {
|
||||
sender.sendMessage(Text.builder("&3Config path '&b" + path + "&3' has the following data: \n&3Value: &7" + ConfigDataType.parseConfig(path,type)).color().prefix().build());
|
||||
sender.sendMessage(Text.builder("&3Config path '&b" + path + "&3' has the following data: \n&3Value: &7" + (type.isList() ? Arrays.stream((Object[]) ConfigDataType.parseConfig(path,type)).toList() : ConfigDataType.parseConfig(path,type)))
|
||||
.color()
|
||||
.prefix()
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +77,7 @@ public class ConfigCommand implements TabExecutor {
|
||||
list.add(args[3] + ",");
|
||||
}
|
||||
}
|
||||
case "byte[]", "string[]" -> {
|
||||
case "byte[]", "string[]", "integer[]", "float[]", "double[]" -> {
|
||||
if (args[3].length() >= 1 && args[3].charAt(args[3].length() - 1) != ',') {
|
||||
list.add(args[3] + ",");
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ public class ConfigDataType<T> {
|
||||
public static final ConfigDataType<Location> LOCATION = register(Location.class);
|
||||
public static final ConfigDataType<String[]> STRING_LIST = register(String[].class);
|
||||
public static final ConfigDataType<Byte[]> BYTE_LIST = register(Byte[].class);
|
||||
public static final ConfigDataType<Integer[]> INTEGER_LIST = register(Integer[].class);
|
||||
public static final ConfigDataType<Float[]> FLOAT_LIST = register(Float[].class);
|
||||
public static final ConfigDataType<Double[]> DOUBLE_LIST = register(Double[].class);
|
||||
public static final ConfigDataType<Null> NULL = register(Null.class);
|
||||
|
||||
private static <T> ConfigDataType<T> register(Class<T> type) {
|
||||
@@ -59,7 +62,12 @@ public class ConfigDataType<T> {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isList() {
|
||||
return name.contains("[]");
|
||||
}
|
||||
|
||||
public static <T> T parseConfig(String path, ConfigDataType<T> type) {
|
||||
if (type.isList()) return (T) Config.get().getList(path).toArray();
|
||||
return Config.get().getObject(path,type.getClassType());
|
||||
}
|
||||
|
||||
@@ -85,6 +93,21 @@ public class ConfigDataType<T> {
|
||||
for (String s : value.split(",")) list.add(Byte.parseByte(s));
|
||||
returnable = list;
|
||||
}
|
||||
case "INTEGER[]" -> {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (String s : value.split(",")) list.add(Integer.parseInt(s));
|
||||
returnable = list;
|
||||
}
|
||||
case "FLOAT[]" -> {
|
||||
List<Double> list = new ArrayList<>();
|
||||
for (String s : value.split(",")) list.add(Double.parseDouble(s));
|
||||
returnable = list;
|
||||
}
|
||||
case "DOUBLE[]" -> {
|
||||
List<Float> list = new ArrayList<>();
|
||||
for (String s : value.split(",")) list.add(Float.parseFloat(s));
|
||||
returnable = list;
|
||||
}
|
||||
case "LOCATION" -> {
|
||||
String[] parts = value.split(",");
|
||||
World world = Bukkit.getWorld(parts[0]);
|
||||
|
||||
Reference in New Issue
Block a user