From 55bb77c2dd4b8e28d2a3cdb4c961040bb4367b1d Mon Sep 17 00:00:00 2001 From: ImproperIssues Date: Sat, 15 Apr 2023 01:22:55 -0700 Subject: [PATCH] config command --- .../commands/commands/ConfigCommand.java | 15 ++++++++---- .../ogredupealias/data/ConfigDataType.java | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/ConfigCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/ConfigCommand.java index 39ff77a..bb7778c 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/ConfigCommand.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/ConfigCommand.java @@ -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] + ","); } diff --git a/src/main/java/io/github/itzispyder/ogredupealias/data/ConfigDataType.java b/src/main/java/io/github/itzispyder/ogredupealias/data/ConfigDataType.java index ec66171..6f6afbe 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/data/ConfigDataType.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/data/ConfigDataType.java @@ -24,6 +24,9 @@ public class ConfigDataType { public static final ConfigDataType LOCATION = register(Location.class); public static final ConfigDataType STRING_LIST = register(String[].class); public static final ConfigDataType BYTE_LIST = register(Byte[].class); + public static final ConfigDataType INTEGER_LIST = register(Integer[].class); + public static final ConfigDataType FLOAT_LIST = register(Float[].class); + public static final ConfigDataType DOUBLE_LIST = register(Double[].class); public static final ConfigDataType NULL = register(Null.class); private static ConfigDataType register(Class type) { @@ -59,7 +62,12 @@ public class ConfigDataType { return name; } + public boolean isList() { + return name.contains("[]"); + } + public static T parseConfig(String path, ConfigDataType 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 { for (String s : value.split(",")) list.add(Byte.parseByte(s)); returnable = list; } + case "INTEGER[]" -> { + List list = new ArrayList<>(); + for (String s : value.split(",")) list.add(Integer.parseInt(s)); + returnable = list; + } + case "FLOAT[]" -> { + List list = new ArrayList<>(); + for (String s : value.split(",")) list.add(Double.parseDouble(s)); + returnable = list; + } + case "DOUBLE[]" -> { + List 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]);