From a746153db0ec01d6ff063857119ed4b38abe87de Mon Sep 17 00:00:00 2001 From: Maru32768 Date: Sun, 1 Jan 2023 01:15:48 +0900 Subject: [PATCH] =?UTF-8?q?modify=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=AE=E5=88=A9=E4=BE=BF=E6=80=A7=E5=90=91=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab/configlib/ConfigModifyCommand.java | 44 ++++++++++++++++++- .../kunmc/lab/configlib/ModifySetCommand.java | 43 ------------------ bukkit/test_plugin/server/server.properties | 10 ++--- .../lab/configlib/ConfigModifyCommand.java | 42 +++++++++++++++++- .../kunmc/lab/configlib/ModifySetCommand.java | 43 ------------------ 5 files changed, 88 insertions(+), 94 deletions(-) delete mode 100644 bukkit/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java delete mode 100644 forge/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java diff --git a/bukkit/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java b/bukkit/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java index 0d0c8f8..b1bd430 100644 --- a/bukkit/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java +++ b/bukkit/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java @@ -2,9 +2,11 @@ import net.kunmc.lab.commandlib.Command; import net.kunmc.lab.configlib.util.ConfigUtil; +import org.bukkit.command.CommandSender; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.List; import java.util.Set; class ConfigModifyCommand extends Command { @@ -28,7 +30,7 @@ public ConfigModifyCommand(Set configSet) { } } - private void init(BaseConfig config, Command command) { + private static void init(BaseConfig config, Command command) { for (Field field : ConfigUtil.getSingleValueFields(config)) { if (Modifier.isStatic(field.getModifiers())) { continue; @@ -49,7 +51,13 @@ private void init(BaseConfig config, Command command) { } command.addChildren(new Command(field.getName()) {{ - addChildren(new ModifySetCommand(field, v, config)); + execute(ctx -> { + v.sendListMessage(ctx, field.getName()); + }); + applySet(this, field, v, config); + addChildren(new Command("set") {{ + applySet(this, field, v, config); + }}); if (v instanceof NumericValue) { addChildren(new ModifyIncCommand(field, ((NumericValue) v), config)); @@ -108,4 +116,36 @@ private void init(BaseConfig config, Command command) { }}); } } + + private static void applySet(Command command, Field field, SingleValue value, BaseConfig config) { + command.argument(builder -> { + value.appendArgument(builder); + + builder.execute(ctx -> { + String entryName = field.getName(); + + List argument = ctx.getParsedArgs(); + CommandSender sender = ctx.getSender(); + if (!value.isCorrectArgument(entryName, argument, sender)) { + ctx.sendFailure(value.incorrectArgumentMessage(entryName, argument, sender)); + return; + } + + Object newValue = value.argumentToValue(argument, sender); + if (!value.validateOnSet(entryName, newValue, sender)) { + ctx.sendFailure(value.invalidValueMessage(entryName, newValue, sender)); + return; + } + + if (value.onModifyValue(newValue, ctx)) { + return; + } + + value.value(newValue); + ctx.sendSuccess(value.succeedModifyMessage(entryName)); + + config.saveConfigIfPresent(); + }); + }); + } } diff --git a/bukkit/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java b/bukkit/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java deleted file mode 100644 index a8691ce..0000000 --- a/bukkit/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.kunmc.lab.configlib; - -import net.kunmc.lab.commandlib.Command; -import org.bukkit.command.CommandSender; - -import java.lang.reflect.Field; -import java.util.List; - -class ModifySetCommand extends Command { - public ModifySetCommand(Field field, SingleValue value, BaseConfig config) { - super("set"); - - argument(builder -> { - value.appendArgument(builder); - - builder.execute(ctx -> { - String entryName = field.getName(); - - List argument = ctx.getParsedArgs(); - CommandSender sender = ctx.getSender(); - if (!value.isCorrectArgument(entryName, argument, sender)) { - ctx.sendFailure(value.incorrectArgumentMessage(entryName, argument, sender)); - return; - } - - Object newValue = value.argumentToValue(argument, sender); - if (!value.validateOnSet(entryName, newValue, sender)) { - ctx.sendFailure(value.invalidValueMessage(entryName, newValue, sender)); - return; - } - - if (value.onModifyValue(newValue, ctx)) { - return; - } - - value.value(newValue); - ctx.sendSuccess(value.succeedModifyMessage(entryName)); - - config.saveConfigIfPresent(); - }); - }); - } -} diff --git a/bukkit/test_plugin/server/server.properties b/bukkit/test_plugin/server/server.properties index 14acd40..4a1179a 100644 --- a/bukkit/test_plugin/server/server.properties +++ b/bukkit/test_plugin/server/server.properties @@ -1,5 +1,5 @@ #Minecraft server properties -#Sun Jan 01 00:39:18 JST 2023 +#Sun Jan 01 01:00:09 JST 2023 spawn-protection=16 max-tick-time=-1 query.port=25565 @@ -42,12 +42,12 @@ spawn-animals=true white-list=false rcon.password= generate-structures=true -online-mode=false max-build-height=256 +online-mode=false level-seed= -prevent-proxy-connections=false use-native-transport=true +prevent-proxy-connections=false enable-jmx-monitoring=false -rate-limit=0 -motd=A Minecraft Server enable-rcon=false +motd=A Minecraft Server +rate-limit=0 diff --git a/forge/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java b/forge/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java index 0d0c8f8..7057cd5 100644 --- a/forge/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java +++ b/forge/src/main/java/net/kunmc/lab/configlib/ConfigModifyCommand.java @@ -2,9 +2,11 @@ import net.kunmc.lab.commandlib.Command; import net.kunmc.lab.configlib.util.ConfigUtil; +import net.minecraft.command.CommandSource; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.List; import java.util.Set; class ConfigModifyCommand extends Command { @@ -49,7 +51,13 @@ private void init(BaseConfig config, Command command) { } command.addChildren(new Command(field.getName()) {{ - addChildren(new ModifySetCommand(field, v, config)); + execute(ctx -> { + v.sendListMessage(ctx, field.getName()); + }); + applySet(this, field, v, config); + addChildren(new Command("set") {{ + applySet(this, field, v, config); + }}); if (v instanceof NumericValue) { addChildren(new ModifyIncCommand(field, ((NumericValue) v), config)); @@ -108,4 +116,36 @@ private void init(BaseConfig config, Command command) { }}); } } + + private static void applySet(Command command, Field field, SingleValue value, BaseConfig config) { + command.argument(builder -> { + value.appendArgument(builder); + + builder.execute(ctx -> { + String entryName = field.getName(); + + List argument = ctx.getParsedArgs(); + CommandSource sender = ctx.getSender(); + if (!value.isCorrectArgument(entryName, argument, sender)) { + ctx.sendFailure(value.incorrectArgumentMessage(entryName, argument, sender)); + return; + } + + Object newValue = value.argumentToValue(argument, sender); + if (!value.validateOnSet(entryName, newValue, sender)) { + ctx.sendFailure(value.invalidValueMessage(entryName, newValue, sender)); + return; + } + + if (value.onModifyValue(newValue, ctx)) { + return; + } + + value.value(newValue); + ctx.sendSuccess(value.succeedModifyMessage(entryName)); + + config.saveConfigIfPresent(); + }); + }); + } } diff --git a/forge/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java b/forge/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java deleted file mode 100644 index de1d543..0000000 --- a/forge/src/main/java/net/kunmc/lab/configlib/ModifySetCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.kunmc.lab.configlib; - -import net.kunmc.lab.commandlib.Command; -import net.minecraft.command.CommandSource; - -import java.lang.reflect.Field; -import java.util.List; - -class ModifySetCommand extends Command { - public ModifySetCommand(Field field, SingleValue value, BaseConfig config) { - super("set"); - - argument(builder -> { - value.appendArgument(builder); - - builder.execute(ctx -> { - String entryName = field.getName(); - - List argument = ctx.getParsedArgs(); - CommandSource sender = ctx.getSender(); - if (!value.isCorrectArgument(entryName, argument, sender)) { - ctx.sendFailure(value.incorrectArgumentMessage(entryName, argument, sender)); - return; - } - - Object newValue = value.argumentToValue(argument, sender); - if (!value.validateOnSet(entryName, newValue, sender)) { - ctx.sendFailure(value.invalidValueMessage(entryName, newValue, sender)); - return; - } - - if (value.onModifyValue(newValue, ctx)) { - return; - } - - value.value(newValue); - ctx.sendSuccess(value.succeedModifyMessage(entryName)); - - config.saveConfigIfPresent(); - }); - }); - } -}