From 178396607196b059bb51d0b5a34e71690fba27fc Mon Sep 17 00:00:00 2001 From: Wodor <17339354+wode490390@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:13:00 +0800 Subject: [PATCH 1/4] Cleanup command params --- .../cn/nukkit/command/data/CommandEnum.java | 28 +++++++++ .../nukkit/command/data/CommandParameter.java | 14 +++++ .../nukkit/command/defaults/BanIpCommand.java | 4 ++ .../command/defaults/BanListCommand.java | 4 +- .../command/defaults/DebugPasteCommand.java | 1 + .../defaults/DefaultGamemodeCommand.java | 6 +- .../command/defaults/DifficultyCommand.java | 6 +- .../command/defaults/EffectCommand.java | 23 ++++++-- .../command/defaults/EnchantCommand.java | 10 +++- .../command/defaults/GamemodeCommand.java | 6 +- .../command/defaults/GameruleCommand.java | 58 +++++++++++++++++-- .../nukkit/command/defaults/GiveCommand.java | 15 ++--- .../nukkit/command/defaults/KickCommand.java | 2 +- .../cn/nukkit/command/defaults/MeCommand.java | 2 +- .../command/defaults/PardonIpCommand.java | 3 +- .../command/defaults/ParticleCommand.java | 9 ++- .../nukkit/command/defaults/SayCommand.java | 3 +- .../defaults/SetWorldSpawnCommand.java | 2 +- .../command/defaults/SpawnpointCommand.java | 3 +- .../command/defaults/TeleportCommand.java | 16 +++-- .../nukkit/command/defaults/TellCommand.java | 2 +- .../nukkit/command/defaults/TimeCommand.java | 20 ++++--- .../command/defaults/TimingsCommand.java | 6 +- .../nukkit/command/defaults/TitleCommand.java | 24 +++----- .../command/defaults/VersionCommand.java | 5 ++ .../command/defaults/WeatherCommand.java | 8 +-- .../command/defaults/WhitelistCommand.java | 7 ++- .../cn/nukkit/command/defaults/XpCommand.java | 6 +- 28 files changed, 217 insertions(+), 76 deletions(-) diff --git a/src/main/java/cn/nukkit/command/data/CommandEnum.java b/src/main/java/cn/nukkit/command/data/CommandEnum.java index 20f482c0de3..b9137426f62 100644 --- a/src/main/java/cn/nukkit/command/data/CommandEnum.java +++ b/src/main/java/cn/nukkit/command/data/CommandEnum.java @@ -1,5 +1,12 @@ package cn.nukkit.command.data; +import cn.nukkit.block.BlockID; +import cn.nukkit.item.ItemID; +import com.google.common.collect.ImmutableList; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -7,6 +14,27 @@ */ public class CommandEnum { + public static final CommandEnum ENUM_BOOLEAN = new CommandEnum("Boolean", ImmutableList.of("true", "false")); + public static final CommandEnum ENUM_GAMEMODE = new CommandEnum("GameMode", + ImmutableList.of("survival", "creative", "s", "c", "adventure", "a", "spectator", "view", "v", "spc")); + public static final CommandEnum ENUM_BLOCK; + public static final CommandEnum ENUM_ITEM; + + static { + List blocks = new ArrayList<>(); + for (Field field : BlockID.class.getDeclaredFields()) { + blocks.add(field.getName().toLowerCase()); + } + ENUM_BLOCK = new CommandEnum("Block", Collections.unmodifiableList(blocks)); + + List items = new ArrayList<>(); + for (Field field : ItemID.class.getDeclaredFields()) { + items.add(field.getName().toLowerCase()); + } + items.addAll(blocks); + ENUM_ITEM = new CommandEnum("Item", Collections.unmodifiableList(items)); + } + private String name; private List values; diff --git a/src/main/java/cn/nukkit/command/data/CommandParameter.java b/src/main/java/cn/nukkit/command/data/CommandParameter.java index befe39246ab..e3a19a64abb 100644 --- a/src/main/java/cn/nukkit/command/data/CommandParameter.java +++ b/src/main/java/cn/nukkit/command/data/CommandParameter.java @@ -64,6 +64,20 @@ public CommandParameter(String name, boolean optional, String[] enumValues) { this.enumData = new CommandEnum(name + "Enums", Arrays.asList(enumValues)); } + public CommandParameter(String name, boolean optional, CommandEnum enumData) { + this.name = name; + this.type = CommandParamType.RAWTEXT; + this.optional = optional; + this.enumData = enumData; + } + + public CommandParameter(boolean optional, String name, String postFix) { + this.name = name; + this.type = CommandParamType.RAWTEXT; + this.optional = optional; + this.postFix = postFix; + } + public CommandParameter(String name, String enumType) { this(name, false, enumType); } diff --git a/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java b/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java index 3ce50c08016..1c3b2506bdb 100644 --- a/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java @@ -33,6 +33,10 @@ public BanIpCommand(String name) { new CommandParameter("player", CommandParamType.TARGET, false), new CommandParameter("reason", CommandParamType.STRING, true) }); + this.commandParameters.put("byIp", new CommandParameter[]{ + new CommandParameter("ip", CommandParamType.STRING, false), + new CommandParameter("reason", CommandParamType.STRING, true) + }); } @Override diff --git a/src/main/java/cn/nukkit/command/defaults/BanListCommand.java b/src/main/java/cn/nukkit/command/defaults/BanListCommand.java index 2ba24980801..14f25c938f7 100644 --- a/src/main/java/cn/nukkit/command/defaults/BanListCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/BanListCommand.java @@ -1,10 +1,12 @@ package cn.nukkit.command.defaults; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.permission.BanEntry; import cn.nukkit.permission.BanList; +import com.google.common.collect.ImmutableList; import java.util.Iterator; @@ -18,7 +20,7 @@ public BanListCommand(String name) { this.setPermission("nukkit.command.ban.list"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("ips|players", true) + new CommandParameter("type", true, new CommandEnum("BanListType", ImmutableList.of("ips", "players"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/DebugPasteCommand.java b/src/main/java/cn/nukkit/command/defaults/DebugPasteCommand.java index 1617db80816..57e765d08bb 100644 --- a/src/main/java/cn/nukkit/command/defaults/DebugPasteCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DebugPasteCommand.java @@ -18,6 +18,7 @@ public class DebugPasteCommand extends VanillaCommand { public DebugPasteCommand(String name) { super(name, "%nukkit.command.debug.description", "%nukkit.command.debug.usage"); this.setPermission("nukkit.command.debug.perform"); + this.commandParameters.clear(); } @Override diff --git a/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java b/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java index 8594186b679..b414c75ce8c 100644 --- a/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java @@ -2,6 +2,7 @@ import cn.nukkit.Server; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; @@ -17,11 +18,10 @@ public DefaultGamemodeCommand(String name) { this.setPermission("nukkit.command.defaultgamemode"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("mode", CommandParamType.INT, false) + new CommandParameter("gameMode", CommandParamType.INT, false) }); this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("mode", new String[]{"survival", "creative", "s", "c", - "adventure", "a", "spectator", "view", "v"}) + new CommandParameter("gameMode", false, CommandEnum.ENUM_GAMEMODE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java b/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java index 081312233df..02b74189c22 100644 --- a/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java @@ -3,10 +3,12 @@ import cn.nukkit.Server; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.network.protocol.SetDifficultyPacket; +import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -24,8 +26,8 @@ public DifficultyCommand(String name) { new CommandParameter("difficulty", CommandParamType.INT, false) }); this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("difficulty", new String[]{"peaceful", "p", "easy", "e", - "normal", "n", "hard", "h"}) + new CommandParameter("difficulty", false, new CommandEnum("Difficulty", + ImmutableList.of("peaceful", "p", "easy", "e", "normal", "n", "hard", "h"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/EffectCommand.java b/src/main/java/cn/nukkit/command/defaults/EffectCommand.java index 78dbfe90849..e873ad71710 100644 --- a/src/main/java/cn/nukkit/command/defaults/EffectCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/EffectCommand.java @@ -3,6 +3,7 @@ import cn.nukkit.Player; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; @@ -10,6 +11,12 @@ import cn.nukkit.potion.InstantEffect; import cn.nukkit.utils.ServerException; import cn.nukkit.utils.TextFormat; +import com.google.common.collect.ImmutableList; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; /** * Created by Snake1999 and Pub4Game on 2016/1/23. @@ -20,16 +27,24 @@ public EffectCommand(String name) { super(name, "%nukkit.command.effect.description", "%commands.effect.usage"); this.setPermission("nukkit.command.effect"); this.commandParameters.clear(); + + List effects = new ArrayList<>(); + for (Field field : Effect.class.getDeclaredFields()) { + if (field.getType() == int.class && field.getModifiers() == (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL)) { + effects.add(field.getName().toLowerCase()); + } + } + this.commandParameters.put("default", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("effect", CommandParamType.STRING, false), //Do not use Enum here because of buggy behavior + new CommandParameter("effect", false, new CommandEnum("Effect", effects)), new CommandParameter("seconds", CommandParamType.INT, true), - new CommandParameter("amplifier", true), - new CommandParameter("hideParticle", true, new String[]{"true", "false"}) + new CommandParameter("amplifier", CommandParamType.INT, true), + new CommandParameter("hideParticle", true, CommandEnum.ENUM_BOOLEAN) }); this.commandParameters.put("clear", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("clear", new String[]{"clear"}) + new CommandParameter("clear", false, new CommandEnum("ClearEffects", ImmutableList.of("clear"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java b/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java index 5fe9bf8f123..da311635513 100644 --- a/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java @@ -3,12 +3,14 @@ import cn.nukkit.Player; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.item.Item; import cn.nukkit.item.enchantment.Enchantment; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; +import com.google.common.collect.ImmutableList; /** * Created by Pub4Game on 23.01.2016. @@ -21,12 +23,16 @@ public EnchantCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("enchantment ID", CommandParamType.INT, false), + new CommandParameter("enchantmentId", CommandParamType.INT, false), new CommandParameter("level", CommandParamType.INT, true) }); this.commandParameters.put("byName", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("id", false, CommandParameter.ENUM_TYPE_ENCHANTMENT_LIST), + new CommandParameter("enchantmentName", false, new CommandEnum("Enchant", + ImmutableList.of("protection", "fire_protection", "feather_falling", "blast_protection", "projectile_projection", "thorns", "respiration", + "aqua_affinity", "depth_strider", "sharpness", "smite", "bane_of_arthropods", "knockback", "fire_aspect", "looting", "efficiency", + "silk_touch", "durability", "fortune", "power", "punch", "flame", "infinity", "luck_of_the_sea", "lure", "frost_walker", "mending", + "binding_curse", "vanishing_curse", "impaling", "loyality", "riptide", "channeling"))), new CommandParameter("level", CommandParamType.INT, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java b/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java index 3dd8a1891e5..55d17dd64f1 100644 --- a/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java @@ -4,6 +4,7 @@ import cn.nukkit.Server; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; @@ -25,12 +26,11 @@ public GamemodeCommand(String name) { "nukkit.command.gamemode.other"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("mode", CommandParamType.INT, false), + new CommandParameter("gameMode", CommandParamType.INT, false), new CommandParameter("player", CommandParamType.TARGET, true) }); this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("mode", new String[]{"survival", "s", "creative", "c", - "adventure", "a", "spectator", "spc", "view", "v"}), + new CommandParameter("gameMode", false, CommandEnum.ENUM_GAMEMODE), new CommandParameter("player", CommandParamType.TARGET, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java b/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java index 26a7d180633..f9e6b294d37 100644 --- a/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java @@ -2,13 +2,16 @@ import cn.nukkit.Player; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.level.GameRule; import cn.nukkit.level.GameRules; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Optional; import java.util.StringJoiner; @@ -18,10 +21,55 @@ public GameruleCommand(String name) { super(name, "%nukkit.command.gamerule.description", "%nukkit.command.gamerule.usage"); this.setPermission("nukkit.command.gamerule"); this.commandParameters.clear(); - this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("gamerule", true , GameRule.getNames()), - new CommandParameter("value", CommandParamType.STRING, true) + + GameRules rules = GameRules.getDefault(); + List boolGameRules = new ArrayList<>(); + List intGameRules = new ArrayList<>(); + List floatGameRules = new ArrayList<>(); + List unknownGameRules = new ArrayList<>(); + + rules.getGameRules().forEach((rule, value) -> { + switch (value.getType()) { + case BOOLEAN: + boolGameRules.add(rule.getName().toLowerCase()); + break; + case INTEGER: + intGameRules.add(rule.getName().toLowerCase()); + break; + case FLOAT: + floatGameRules.add(rule.getName().toLowerCase()); + break; + case UNKNOWN: + default: + unknownGameRules.add(rule.getName().toLowerCase()); + break; + } }); + + if (!boolGameRules.isEmpty()) { + this.commandParameters.put("boolGameRules", new CommandParameter[]{ + new CommandParameter("rule", false , new CommandEnum("BoolGameRule", boolGameRules)), + new CommandParameter("value", true, CommandEnum.ENUM_BOOLEAN) + }); + } + if (!intGameRules.isEmpty()) { + this.commandParameters.put("intGameRules", new CommandParameter[]{ + new CommandParameter("rule", false , new CommandEnum("IntGameRule", intGameRules)), + new CommandParameter("value", CommandParamType.INT, true) + }); + } + if (!floatGameRules.isEmpty()) { + this.commandParameters.put("floatGameRules", new CommandParameter[]{ + new CommandParameter("rule", false , new CommandEnum("FloatGameRule", floatGameRules)), + new CommandParameter("value", CommandParamType.FLOAT, true) + }); + } + if (!unknownGameRules.isEmpty()) { + this.commandParameters.put("unknownGameRules", new CommandParameter[]{ + new CommandParameter("rule", false , new CommandEnum("UnknownGameRule", unknownGameRules)), + new CommandParameter("value", CommandParamType.STRING, true) + }); + } } @Override @@ -51,7 +99,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args) return true; } - sender.sendMessage(gameRule.get().getName() + " = " + rules.getString(gameRule.get())); + sender.sendMessage(gameRule.get().getName() .toLowerCase()+ " = " + rules.getString(gameRule.get())); return true; default: Optional optionalRule = GameRule.parseString(args[0]); @@ -64,7 +112,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args) try { rules.setGameRules(optionalRule.get(), args[1]); - sender.sendMessage(new TranslationContainer("commands.gamerule.success", optionalRule.get().getName(), args[1])); + sender.sendMessage(new TranslationContainer("commands.gamerule.success", optionalRule.get().getName().toLowerCase(), args[1])); } catch (IllegalArgumentException e) { sender.sendMessage(new TranslationContainer("commands.generic.syntax", "/gamerule " + args[0] + " ", args[1], " " + String.join(" ", Arrays.copyOfRange(args, 2, args.length)))); } diff --git a/src/main/java/cn/nukkit/command/defaults/GiveCommand.java b/src/main/java/cn/nukkit/command/defaults/GiveCommand.java index e3ca0b16209..b44c511c623 100644 --- a/src/main/java/cn/nukkit/command/defaults/GiveCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/GiveCommand.java @@ -3,6 +3,7 @@ import cn.nukkit.Player; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.item.Item; @@ -20,22 +21,22 @@ public GiveCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("item", false, CommandParameter.ENUM_TYPE_ITEM_LIST), + new CommandParameter("itemName", false, CommandEnum.ENUM_ITEM), new CommandParameter("amount", CommandParamType.INT, true), - new CommandParameter("meta", CommandParamType.INT, true), - new CommandParameter("tags...", CommandParamType.RAWTEXT, true) + //new CommandParameter("data", CommandParamType.INT, true), + new CommandParameter("tags", CommandParamType.RAWTEXT, true) }); this.commandParameters.put("toPlayerById", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("item ID", CommandParamType.INT, false), + new CommandParameter("itemId", CommandParamType.INT, false), new CommandParameter("amount", CommandParamType.INT, true), - new CommandParameter("tags...", CommandParamType.RAWTEXT, true) + new CommandParameter("tags", CommandParamType.RAWTEXT, true) }); this.commandParameters.put("toPlayerByIdMeta", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("item ID:meta", CommandParamType.RAWTEXT, false), + new CommandParameter("itemAndData", CommandParamType.STRING, false), new CommandParameter("amount", CommandParamType.INT, true), - new CommandParameter("tags...", CommandParamType.RAWTEXT, true) + new CommandParameter("tags", CommandParamType.RAWTEXT, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/KickCommand.java b/src/main/java/cn/nukkit/command/defaults/KickCommand.java index 01045116f8b..5946d0d8eab 100644 --- a/src/main/java/cn/nukkit/command/defaults/KickCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/KickCommand.java @@ -21,7 +21,7 @@ public KickCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("reason", true) + new CommandParameter("reason", CommandParamType.MESSAGE, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/MeCommand.java b/src/main/java/cn/nukkit/command/defaults/MeCommand.java index fb701d91d5d..b3fd04c8818 100644 --- a/src/main/java/cn/nukkit/command/defaults/MeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/MeCommand.java @@ -18,7 +18,7 @@ public MeCommand(String name) { this.setPermission("nukkit.command.me"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("action ...", CommandParamType.RAWTEXT, false) + new CommandParameter("message", CommandParamType.MESSAGE, false) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java b/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java index bc61968664f..78d8e9a6440 100644 --- a/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java @@ -2,6 +2,7 @@ import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; @@ -21,7 +22,7 @@ public PardonIpCommand(String name) { this.setAliases(new String[]{"unbanip", "unban-ip", "pardonip"}); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("ip") + new CommandParameter("ip", CommandParamType.STRING, false) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java b/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java index d4812d7b117..e4956c53523 100644 --- a/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java @@ -3,6 +3,7 @@ import cn.nukkit.Player; import cn.nukkit.block.Block; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.item.Item; @@ -11,7 +12,9 @@ import cn.nukkit.level.particle.*; import cn.nukkit.math.Vector3; +import java.util.Arrays; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * Created on 2015/11/12 by xtypr. @@ -27,10 +30,10 @@ public ParticleCommand(String name) { this.setPermission("nukkit.command.particle"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("name", false, ENUM_VALUES), + new CommandParameter("effect", false, new CommandEnum("Particle", Arrays.asList(ENUM_VALUES))), new CommandParameter("position", CommandParamType.POSITION, false), new CommandParameter("count", CommandParamType.INT, true), - new CommandParameter("data", true) + new CommandParameter("data", CommandParamType.INT, true) }); } @@ -98,7 +101,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args) sender.sendMessage(new TranslationContainer("commands.particle.success", name, String.valueOf(count))); - Random random = new Random(System.currentTimeMillis()); + Random random = ThreadLocalRandom.current(); for (int i = 0; i < count; i++) { particle.setComponents( diff --git a/src/main/java/cn/nukkit/command/defaults/SayCommand.java b/src/main/java/cn/nukkit/command/defaults/SayCommand.java index 738bbac5bf1..5eebc91d77c 100644 --- a/src/main/java/cn/nukkit/command/defaults/SayCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/SayCommand.java @@ -3,6 +3,7 @@ import cn.nukkit.Player; import cn.nukkit.command.CommandSender; import cn.nukkit.command.ConsoleCommandSender; +import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; @@ -18,7 +19,7 @@ public SayCommand(String name) { this.setPermission("nukkit.command.say"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("message") + new CommandParameter("message", CommandParamType.MESSAGE, false) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java b/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java index 83720b6a3d7..e063a6a72da 100644 --- a/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java @@ -21,7 +21,7 @@ public SetWorldSpawnCommand(String name) { this.setPermission("nukkit.command.setworldspawn"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("blockPos", CommandParamType.POSITION, true) + new CommandParameter("spawnPoint", CommandParamType.POSITION, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java b/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java index 8b98b7ab06e..d2954d3bf55 100644 --- a/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java @@ -22,7 +22,8 @@ public SpawnpointCommand(String name) { this.setPermission("nukkit.command.spawnpoint"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("blockPos", CommandParamType.POSITION, true), + new CommandParameter("player", CommandParamType.TARGET, true), + new CommandParameter("spawnPos", CommandParamType.POSITION, true), }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java b/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java index 364e9f46963..773393c6741 100644 --- a/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java @@ -21,18 +21,22 @@ public TeleportCommand(String name) { this.setPermission("nukkit.command.teleport"); this.commandParameters.clear(); this.commandParameters.put("->Player", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), + new CommandParameter("destination", CommandParamType.TARGET, false), }); this.commandParameters.put("Player->Player", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("target", CommandParamType.TARGET, false), + new CommandParameter("victim", CommandParamType.TARGET, false), + new CommandParameter("destination", CommandParamType.TARGET, false) }); this.commandParameters.put("Player->Pos", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("blockPos", CommandParamType.POSITION, false), + new CommandParameter("victim", CommandParamType.TARGET, false), + new CommandParameter("destination", CommandParamType.POSITION, false), + new CommandParameter("yRot", CommandParamType.VALUE, true), + new CommandParameter("xRot", CommandParamType.VALUE, true) }); this.commandParameters.put("->Pos", new CommandParameter[]{ - new CommandParameter("blockPos", CommandParamType.POSITION, false), + new CommandParameter("destination", CommandParamType.POSITION, false), + new CommandParameter("yRot", CommandParamType.VALUE, true), + new CommandParameter("xRot", CommandParamType.VALUE, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TellCommand.java b/src/main/java/cn/nukkit/command/defaults/TellCommand.java index fa5640bfe9e..6a2538e47a8 100644 --- a/src/main/java/cn/nukkit/command/defaults/TellCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TellCommand.java @@ -21,7 +21,7 @@ public TellCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("message") + new CommandParameter("message", CommandParamType.MESSAGE, false) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TimeCommand.java b/src/main/java/cn/nukkit/command/defaults/TimeCommand.java index b0816b164e8..ff27bab3c68 100644 --- a/src/main/java/cn/nukkit/command/defaults/TimeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TimeCommand.java @@ -3,11 +3,13 @@ import cn.nukkit.Player; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.level.Level; import cn.nukkit.utils.TextFormat; +import com.google.common.collect.ImmutableList; /** * Created on 2015/11/11 by xtypr. @@ -23,15 +25,19 @@ public TimeCommand(String name) { "nukkit.command.time.stop"); this.commandParameters.clear(); this.commandParameters.put("1arg", new CommandParameter[]{ - new CommandParameter("start|stop", CommandParamType.STRING, false) + new CommandParameter("mode", false, new CommandEnum("TimeMode", ImmutableList.of("query", "start", "stop"))) }); - this.commandParameters.put("2args", new CommandParameter[]{ - new CommandParameter("add|set", CommandParamType.STRING, false), - new CommandParameter("value", CommandParamType.INT, false) + this.commandParameters.put("add", new CommandParameter[]{ + new CommandParameter("mode", false, new CommandEnum("TimeModeAdd", ImmutableList.of("add"))), + new CommandParameter("amount", CommandParamType.INT, false) }); - this.commandParameters.put("2args_", new CommandParameter[]{ - new CommandParameter("add|set", CommandParamType.STRING, false), - new CommandParameter("value", CommandParamType.STRING, false) + this.commandParameters.put("setAmount", new CommandParameter[]{ + new CommandParameter("mode", false, new CommandEnum("TimeModeSet", ImmutableList.of("set"))), + new CommandParameter("amount", CommandParamType.INT, false) + }); + this.commandParameters.put("setTime", new CommandParameter[]{ + new CommandParameter("mode", false, new CommandEnum("TimeModeSet", ImmutableList.of("set"))), + new CommandParameter("time", false, new CommandEnum("TimeSpec", ImmutableList.of("day", "night", "midnight", "noon", "sunrise", "sunset"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java b/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java index e9b81c64f58..85c66c314de 100644 --- a/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java @@ -1,10 +1,12 @@ package cn.nukkit.command.defaults; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import co.aikar.timings.Timings; import co.aikar.timings.TimingsExport; +import com.google.common.collect.ImmutableList; /** * @author fromgate @@ -17,7 +19,8 @@ public TimingsCommand(String name) { this.setPermission("nukkit.command.timings"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("on|off|paste") + new CommandParameter("action", false, new CommandEnum("TimingsAction", + ImmutableList.of("on", "off", "paste", "verbon", "verboff", "reset", "report"))) }); } @@ -71,4 +74,3 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args) return true; } } - diff --git a/src/main/java/cn/nukkit/command/defaults/TitleCommand.java b/src/main/java/cn/nukkit/command/defaults/TitleCommand.java index 09e0fa7d870..3398f5d91a6 100644 --- a/src/main/java/cn/nukkit/command/defaults/TitleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TitleCommand.java @@ -3,10 +3,12 @@ import cn.nukkit.Player; import cn.nukkit.Server; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; +import com.google.common.collect.ImmutableList; /** * @author Tee7even @@ -19,30 +21,20 @@ public TitleCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("clear", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("clear", new String[]{"clear"}) + new CommandParameter("clear", false, new CommandEnum("TitleClear", ImmutableList.of("clear"))) }); this.commandParameters.put("reset", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("reset", new String[]{"reset"}) + new CommandParameter("reset", false, new CommandEnum("TitleReset", ImmutableList.of("reset"))) }); - this.commandParameters.put("title", new CommandParameter[]{ + this.commandParameters.put("set", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("title", new String[]{"title"}), - new CommandParameter("titleText", CommandParamType.STRING, false) - }); - this.commandParameters.put("subtitle", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("subtitle", new String[]{"subtitle"}), - new CommandParameter("titleText", CommandParamType.STRING, false) - }); - this.commandParameters.put("actionbar", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("actionbar", new String[]{"actionbar"}), - new CommandParameter("titleText", CommandParamType.STRING, false) + new CommandParameter("titleLocation", false, new CommandEnum("TitleSet", ImmutableList.of("title", "subtitle", "actionbar"))), + new CommandParameter("titleText", CommandParamType.MESSAGE, false) }); this.commandParameters.put("times", new CommandParameter[]{ new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("times", new String[]{"times"}), + new CommandParameter("times", false, new CommandEnum("TitleTimes", ImmutableList.of("times"))), new CommandParameter("fadeIn", CommandParamType.INT, false), new CommandParameter("stay", CommandParamType.INT, false), new CommandParameter("fadeOut", CommandParamType.INT, false) diff --git a/src/main/java/cn/nukkit/command/defaults/VersionCommand.java b/src/main/java/cn/nukkit/command/defaults/VersionCommand.java index 17d439c77fe..650147685ec 100644 --- a/src/main/java/cn/nukkit/command/defaults/VersionCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/VersionCommand.java @@ -1,6 +1,8 @@ package cn.nukkit.command.defaults; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandParamType; +import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.network.protocol.ProtocolInfo; import cn.nukkit.plugin.Plugin; @@ -23,6 +25,9 @@ public VersionCommand(String name) { ); this.setPermission("nukkit.command.version"); this.commandParameters.clear(); + this.commandParameters.put("default", new CommandParameter[]{ + new CommandParameter("pluginName", CommandParamType.STRING, true) + }); } @Override diff --git a/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java b/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java index 24069cc7b3d..1b9dd358fc8 100644 --- a/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java @@ -3,10 +3,12 @@ import cn.nukkit.Player; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.level.Level; +import com.google.common.collect.ImmutableList; /** * author: Angelic47 @@ -14,15 +16,13 @@ */ public class WeatherCommand extends VanillaCommand { - private java.util.Random rand = new java.util.Random(); - public WeatherCommand(String name) { super(name, "%nukkit.command.weather.description", "%commands.weather.usage"); this.setPermission("nukkit.command.weather"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("clear|rain|thunder", CommandParamType.STRING, false), - new CommandParameter("duration in seconds", CommandParamType.INT, true) + new CommandParameter("type", false, new CommandEnum("WeatherType", ImmutableList.of("clear", "rain", "thunder"))), + new CommandParameter("duration", CommandParamType.INT, true) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java b/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java index 0e30f93987d..5774c5d1d25 100644 --- a/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java @@ -2,10 +2,12 @@ import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import cn.nukkit.command.data.CommandEnum; import cn.nukkit.command.data.CommandParamType; import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; +import com.google.common.collect.ImmutableList; /** * Created on 2015/11/12 by xtypr. @@ -25,15 +27,14 @@ public WhitelistCommand(String name) { ); this.commandParameters.clear(); this.commandParameters.put("1arg", new CommandParameter[]{ - new CommandParameter("on|off|list|reload", CommandParamType.STRING, false) + new CommandParameter("action", false, new CommandEnum("WhitelistAction", ImmutableList.of("on", "off", "list", "reload"))) }); this.commandParameters.put("2args", new CommandParameter[]{ - new CommandParameter("add|remove", CommandParamType.STRING, false), + new CommandParameter("action", false, new CommandEnum("WhitelistPlayerAction", ImmutableList.of("add", "remove"))), new CommandParameter("player", CommandParamType.TARGET, false) }); } - @Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { diff --git a/src/main/java/cn/nukkit/command/defaults/XpCommand.java b/src/main/java/cn/nukkit/command/defaults/XpCommand.java index 31ac7f49414..430b147eb59 100644 --- a/src/main/java/cn/nukkit/command/defaults/XpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/XpCommand.java @@ -18,7 +18,11 @@ public XpCommand(String name) { this.setPermission("nukkit.command.xp"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("amount|level", CommandParamType.INT, false), + new CommandParameter("amount", CommandParamType.INT, false), + new CommandParameter("player", CommandParamType.TARGET, true) + }); + this.commandParameters.put("level", new CommandParameter[]{ + new CommandParameter(false, "amount", "l"), new CommandParameter("player", CommandParamType.TARGET, true) }); } From ab7fa941185489ddc20804ea7be17b15d7528dce Mon Sep 17 00:00:00 2001 From: Wodor <17339354+wode490390@users.noreply.github.com> Date: Mon, 12 Oct 2020 05:31:23 +0800 Subject: [PATCH 2/4] Remove deprecated constructor --- .../nukkit/command/data/CommandParameter.java | 51 ++----------------- .../cn/nukkit/command/defaults/XpCommand.java | 2 +- 2 files changed, 6 insertions(+), 47 deletions(-) diff --git a/src/main/java/cn/nukkit/command/data/CommandParameter.java b/src/main/java/cn/nukkit/command/data/CommandParameter.java index e3a19a64abb..ede0f07d378 100644 --- a/src/main/java/cn/nukkit/command/data/CommandParameter.java +++ b/src/main/java/cn/nukkit/command/data/CommandParameter.java @@ -1,28 +1,10 @@ package cn.nukkit.command.data; - import java.util.ArrayList; import java.util.Arrays; public class CommandParameter { - public final static String ARG_TYPE_STRING = "string"; - public final static String ARG_TYPE_STRING_ENUM = "stringenum"; - public final static String ARG_TYPE_BOOL = "bool"; - public final static String ARG_TYPE_TARGET = "target"; - public final static String ARG_TYPE_PLAYER = "target"; - public final static String ARG_TYPE_BLOCK_POS = "blockpos"; - public final static String ARG_TYPE_RAW_TEXT = "rawtext"; - public final static String ARG_TYPE_INT = "int"; - - public static final String ENUM_TYPE_ITEM_LIST = "itemType"; - public static final String ENUM_TYPE_BLOCK_LIST = "blockType"; - public static final String ENUM_TYPE_COMMAND_LIST = "commandName"; - public static final String ENUM_TYPE_ENCHANTMENT_LIST = "enchantmentType"; - public static final String ENUM_TYPE_ENTITY_LIST = "entityType"; - public static final String ENUM_TYPE_EFFECT_LIST = "effectType"; - public static final String ENUM_TYPE_PARTICLE_LIST = "particleType"; - public String name; public CommandParamType type; public boolean optional; @@ -31,9 +13,11 @@ public class CommandParameter { public CommandEnum enumData; public String postFix; - @Deprecated - public CommandParameter(String name, String type, boolean optional) { - this(name, fromString(type), optional); + public CommandParameter(String name, String postFix, boolean optional) { + this.name = name; + this.type = CommandParamType.RAWTEXT; + this.optional = optional; + this.postFix = postFix; } public CommandParameter(String name, CommandParamType type, boolean optional) { @@ -71,13 +55,6 @@ public CommandParameter(String name, boolean optional, CommandEnum enumData) { this.enumData = enumData; } - public CommandParameter(boolean optional, String name, String postFix) { - this.name = name; - this.type = CommandParamType.RAWTEXT; - this.optional = optional; - this.postFix = postFix; - } - public CommandParameter(String name, String enumType) { this(name, false, enumType); } @@ -85,22 +62,4 @@ public CommandParameter(String name, String enumType) { public CommandParameter(String name, String[] enumValues) { this(name, false, enumValues); } - - protected static CommandParamType fromString(String param) { - switch (param) { - case "string": - case "stringenum": - return CommandParamType.STRING; - case "target": - return CommandParamType.TARGET; - case "blockpos": - return CommandParamType.POSITION; - case "rawtext": - return CommandParamType.RAWTEXT; - case "int": - return CommandParamType.INT; - } - - return CommandParamType.RAWTEXT; - } } diff --git a/src/main/java/cn/nukkit/command/defaults/XpCommand.java b/src/main/java/cn/nukkit/command/defaults/XpCommand.java index 430b147eb59..647aea6eafc 100644 --- a/src/main/java/cn/nukkit/command/defaults/XpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/XpCommand.java @@ -22,7 +22,7 @@ public XpCommand(String name) { new CommandParameter("player", CommandParamType.TARGET, true) }); this.commandParameters.put("level", new CommandParameter[]{ - new CommandParameter(false, "amount", "l"), + new CommandParameter("amount", "l", false), new CommandParameter("player", CommandParamType.TARGET, true) }); } From 5356a1efc0b77b50f02a6b28774aa5c6bcc9afc4 Mon Sep 17 00:00:00 2001 From: Wodor <17339354+wode490390@users.noreply.github.com> Date: Mon, 12 Oct 2020 21:17:36 +0800 Subject: [PATCH 3/4] deprecate old constructors --- src/main/java/cn/nukkit/command/Command.java | 2 +- .../cn/nukkit/command/SimpleCommandMap.java | 2 +- .../nukkit/command/data/CommandParameter.java | 110 ++++++++++++++++-- .../nukkit/command/defaults/BanCommand.java | 4 +- .../nukkit/command/defaults/BanIpCommand.java | 8 +- .../command/defaults/BanListCommand.java | 2 +- .../defaults/DefaultGamemodeCommand.java | 4 +- .../nukkit/command/defaults/DeopCommand.java | 2 +- .../command/defaults/DifficultyCommand.java | 4 +- .../command/defaults/EffectCommand.java | 14 +-- .../command/defaults/EnchantCommand.java | 12 +- .../command/defaults/GamemodeCommand.java | 8 +- .../command/defaults/GameruleCommand.java | 16 +-- .../nukkit/command/defaults/GiveCommand.java | 25 ++-- .../nukkit/command/defaults/HelpCommand.java | 2 +- .../nukkit/command/defaults/KickCommand.java | 4 +- .../nukkit/command/defaults/KillCommand.java | 2 +- .../cn/nukkit/command/defaults/MeCommand.java | 2 +- .../cn/nukkit/command/defaults/OpCommand.java | 2 +- .../command/defaults/PardonCommand.java | 2 +- .../command/defaults/PardonIpCommand.java | 2 +- .../command/defaults/ParticleCommand.java | 8 +- .../nukkit/command/defaults/SayCommand.java | 2 +- .../defaults/SetWorldSpawnCommand.java | 2 +- .../command/defaults/SpawnpointCommand.java | 4 +- .../command/defaults/TeleportCommand.java | 20 ++-- .../nukkit/command/defaults/TellCommand.java | 4 +- .../nukkit/command/defaults/TimeCommand.java | 14 +-- .../command/defaults/TimingsCommand.java | 2 +- .../nukkit/command/defaults/TitleCommand.java | 24 ++-- .../command/defaults/VersionCommand.java | 2 +- .../command/defaults/WeatherCommand.java | 4 +- .../command/defaults/WhitelistCommand.java | 6 +- .../cn/nukkit/command/defaults/XpCommand.java | 8 +- 34 files changed, 208 insertions(+), 121 deletions(-) diff --git a/src/main/java/cn/nukkit/command/Command.java b/src/main/java/cn/nukkit/command/Command.java index 6b6e6897413..fbbd4954eb7 100644 --- a/src/main/java/cn/nukkit/command/Command.java +++ b/src/main/java/cn/nukkit/command/Command.java @@ -68,7 +68,7 @@ public Command(String name, String description, String usageMessage, String[] al this.aliases = aliases; this.activeAliases = aliases; this.timing = Timings.getCommandTiming(this); - this.commandParameters.put("default", new CommandParameter[]{new CommandParameter("args", CommandParamType.RAWTEXT, true)}); + this.commandParameters.put("default", new CommandParameter[]{CommandParameter.newType("args", true, CommandParamType.RAWTEXT)}); } /** diff --git a/src/main/java/cn/nukkit/command/SimpleCommandMap.java b/src/main/java/cn/nukkit/command/SimpleCommandMap.java index c4d8fe06194..366dfb16933 100644 --- a/src/main/java/cn/nukkit/command/SimpleCommandMap.java +++ b/src/main/java/cn/nukkit/command/SimpleCommandMap.java @@ -144,7 +144,7 @@ public void registerSimpleCommands(Object object) { if (commandParameters != null) { Map map = Arrays.stream(commandParameters.parameters()) .collect(Collectors.toMap(Parameters::name, parameters -> Arrays.stream(parameters.parameters()) - .map(parameter -> new CommandParameter(parameter.name(), parameter.type(), parameter.optional())) + .map(parameter -> CommandParameter.newType(parameter.name(), parameter.optional(), parameter.type())) .distinct() .toArray(CommandParameter[]::new))); diff --git a/src/main/java/cn/nukkit/command/data/CommandParameter.java b/src/main/java/cn/nukkit/command/data/CommandParameter.java index ede0f07d378..95926cbe122 100644 --- a/src/main/java/cn/nukkit/command/data/CommandParameter.java +++ b/src/main/java/cn/nukkit/command/data/CommandParameter.java @@ -13,27 +13,44 @@ public class CommandParameter { public CommandEnum enumData; public String postFix; - public CommandParameter(String name, String postFix, boolean optional) { - this.name = name; - this.type = CommandParamType.RAWTEXT; - this.optional = optional; - this.postFix = postFix; + /** + * @deprecated use {@link #newType(String, boolean, CommandParamType)} instead + */ + @Deprecated + public CommandParameter(String name, String type, boolean optional) { + this(name, fromString(type), optional); } + /** + * @deprecated use {@link #newType(String, boolean, CommandParamType)} instead + */ + @Deprecated public CommandParameter(String name, CommandParamType type, boolean optional) { this.name = name; this.type = type; this.optional = optional; } + /** + * @deprecated use {@link #newType(String, boolean, CommandParamType)} instead + */ + @Deprecated public CommandParameter(String name, boolean optional) { this(name, CommandParamType.RAWTEXT, optional); } + /** + * @deprecated use {@link #newType(String, CommandParamType)} instead + */ + @Deprecated public CommandParameter(String name) { this(name, false); } + /** + * @deprecated use {@link #newEnum(String, boolean, String)} instead + */ + @Deprecated public CommandParameter(String name, boolean optional, String enumType) { this.name = name; this.type = CommandParamType.RAWTEXT; @@ -41,6 +58,10 @@ public CommandParameter(String name, boolean optional, String enumType) { this.enumData = new CommandEnum(enumType, new ArrayList<>()); } + /** + * @deprecated use {@link #newEnum(String, boolean, String[])} instead + */ + @Deprecated public CommandParameter(String name, boolean optional, String[] enumValues) { this.name = name; this.type = CommandParamType.RAWTEXT; @@ -48,18 +69,85 @@ public CommandParameter(String name, boolean optional, String[] enumValues) { this.enumData = new CommandEnum(name + "Enums", Arrays.asList(enumValues)); } - public CommandParameter(String name, boolean optional, CommandEnum enumData) { + /** + * @deprecated use {@link #newEnum(String, String)} instead + */ + @Deprecated + public CommandParameter(String name, String enumType) { + this(name, false, enumType); + } + + /** + * @deprecated use {@link #newEnum(String, String[])} instead + */ + @Deprecated + public CommandParameter(String name, String[] enumValues) { + this(name, false, enumValues); + } + + private CommandParameter(String name, boolean optional, CommandParamType type, CommandEnum enumData, String postFix) { this.name = name; - this.type = CommandParamType.RAWTEXT; this.optional = optional; + this.type = type; this.enumData = enumData; + this.postFix = postFix; } - public CommandParameter(String name, String enumType) { - this(name, false, enumType); + public static CommandParameter newType(String name, CommandParamType type) { + return newType(name, false, type); } - public CommandParameter(String name, String[] enumValues) { - this(name, false, enumValues); + public static CommandParameter newType(String name, boolean optional, CommandParamType type) { + return new CommandParameter(name, optional, type, null, null); + } + + public static CommandParameter newEnum(String name, String[] values) { + return newEnum(name, false, values); + } + + public static CommandParameter newEnum(String name, boolean optional, String[] values) { + return newEnum(name, optional, new CommandEnum(name + "Enums", Arrays.asList(values))); + } + + public static CommandParameter newEnum(String name, String type) { + return newEnum(name, false, type); + } + + public static CommandParameter newEnum(String name, boolean optional, String type) { + return newEnum(name, optional, new CommandEnum(type, new ArrayList<>())); + } + + public static CommandParameter newEnum(String name, CommandEnum data) { + return newEnum(name, false, data); + } + + public static CommandParameter newEnum(String name, boolean optional, CommandEnum data) { + return new CommandParameter(name, optional, CommandParamType.RAWTEXT, data, null); + } + + public static CommandParameter newPostfix(String name, String postfix) { + return newPostfix(name, false, postfix); + } + + public static CommandParameter newPostfix(String name, boolean optional, String postfix) { + return new CommandParameter(name, optional, CommandParamType.RAWTEXT, null, postfix); + } + + protected static CommandParamType fromString(String param) { + switch (param) { + case "string": + case "stringenum": + return CommandParamType.STRING; + case "target": + return CommandParamType.TARGET; + case "blockpos": + return CommandParamType.POSITION; + case "rawtext": + return CommandParamType.RAWTEXT; + case "int": + return CommandParamType.INT; + } + + return CommandParamType.RAWTEXT; } } diff --git a/src/main/java/cn/nukkit/command/defaults/BanCommand.java b/src/main/java/cn/nukkit/command/defaults/BanCommand.java index 9ae05584693..ca437e55712 100644 --- a/src/main/java/cn/nukkit/command/defaults/BanCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/BanCommand.java @@ -20,8 +20,8 @@ public BanCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("reason", CommandParamType.STRING, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("reason", true, CommandParamType.STRING) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java b/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java index 1c3b2506bdb..7a1b48bb89e 100644 --- a/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/BanIpCommand.java @@ -30,12 +30,12 @@ public BanIpCommand(String name) { this.setAliases(new String[]{"banip"}); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("reason", CommandParamType.STRING, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("reason", true, CommandParamType.STRING) }); this.commandParameters.put("byIp", new CommandParameter[]{ - new CommandParameter("ip", CommandParamType.STRING, false), - new CommandParameter("reason", CommandParamType.STRING, true) + CommandParameter.newType("ip", CommandParamType.STRING), + CommandParameter.newType("reason", true, CommandParamType.STRING) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/BanListCommand.java b/src/main/java/cn/nukkit/command/defaults/BanListCommand.java index 14f25c938f7..d074c6f797a 100644 --- a/src/main/java/cn/nukkit/command/defaults/BanListCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/BanListCommand.java @@ -20,7 +20,7 @@ public BanListCommand(String name) { this.setPermission("nukkit.command.ban.list"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("type", true, new CommandEnum("BanListType", ImmutableList.of("ips", "players"))) + CommandParameter.newEnum("type", true, new CommandEnum("BanListType", ImmutableList.of("ips", "players"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java b/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java index b414c75ce8c..73604ce3cd3 100644 --- a/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DefaultGamemodeCommand.java @@ -18,10 +18,10 @@ public DefaultGamemodeCommand(String name) { this.setPermission("nukkit.command.defaultgamemode"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("gameMode", CommandParamType.INT, false) + CommandParameter.newType("gameMode", CommandParamType.INT) }); this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("gameMode", false, CommandEnum.ENUM_GAMEMODE) + CommandParameter.newEnum("gameMode", CommandEnum.ENUM_GAMEMODE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/DeopCommand.java b/src/main/java/cn/nukkit/command/defaults/DeopCommand.java index 358599f3786..4934da84e69 100644 --- a/src/main/java/cn/nukkit/command/defaults/DeopCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DeopCommand.java @@ -18,7 +18,7 @@ public DeopCommand(String name) { super(name, "%nukkit.command.deop.description", "%commands.deop.description"); this.setPermission("nukkit.command.op.take"); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false) + CommandParameter.newType("player", CommandParamType.TARGET) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java b/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java index 02b74189c22..ab24c6811eb 100644 --- a/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java @@ -23,10 +23,10 @@ public DifficultyCommand(String name) { this.setPermission("nukkit.command.difficulty"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("difficulty", CommandParamType.INT, false) + CommandParameter.newType("difficulty", CommandParamType.INT) }); this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("difficulty", false, new CommandEnum("Difficulty", + CommandParameter.newEnum("difficulty", new CommandEnum("Difficulty", ImmutableList.of("peaceful", "p", "easy", "e", "normal", "n", "hard", "h"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/EffectCommand.java b/src/main/java/cn/nukkit/command/defaults/EffectCommand.java index e873ad71710..fe73cd6df2e 100644 --- a/src/main/java/cn/nukkit/command/defaults/EffectCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/EffectCommand.java @@ -36,15 +36,15 @@ public EffectCommand(String name) { } this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("effect", false, new CommandEnum("Effect", effects)), - new CommandParameter("seconds", CommandParamType.INT, true), - new CommandParameter("amplifier", CommandParamType.INT, true), - new CommandParameter("hideParticle", true, CommandEnum.ENUM_BOOLEAN) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("effect", new CommandEnum("Effect", effects)), + CommandParameter.newType("seconds", true, CommandParamType.INT), + CommandParameter.newType("amplifier", true, CommandParamType.INT), + CommandParameter.newEnum("hideParticle", true, CommandEnum.ENUM_BOOLEAN) }); this.commandParameters.put("clear", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("clear", false, new CommandEnum("ClearEffects", ImmutableList.of("clear"))) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("clear", new CommandEnum("ClearEffects", ImmutableList.of("clear"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java b/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java index da311635513..bff2ed4aef4 100644 --- a/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java @@ -22,18 +22,18 @@ public EnchantCommand(String name) { this.setPermission("nukkit.command.enchant"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("enchantmentId", CommandParamType.INT, false), - new CommandParameter("level", CommandParamType.INT, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("enchantmentId", CommandParamType.INT), + CommandParameter.newType("level", true, CommandParamType.INT) }); this.commandParameters.put("byName", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("enchantmentName", false, new CommandEnum("Enchant", + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("enchantmentName", new CommandEnum("Enchant", ImmutableList.of("protection", "fire_protection", "feather_falling", "blast_protection", "projectile_projection", "thorns", "respiration", "aqua_affinity", "depth_strider", "sharpness", "smite", "bane_of_arthropods", "knockback", "fire_aspect", "looting", "efficiency", "silk_touch", "durability", "fortune", "power", "punch", "flame", "infinity", "luck_of_the_sea", "lure", "frost_walker", "mending", "binding_curse", "vanishing_curse", "impaling", "loyality", "riptide", "channeling"))), - new CommandParameter("level", CommandParamType.INT, true) + CommandParameter.newType("level", true, CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java b/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java index 55d17dd64f1..417c473e4a4 100644 --- a/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/GamemodeCommand.java @@ -26,12 +26,12 @@ public GamemodeCommand(String name) { "nukkit.command.gamemode.other"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("gameMode", CommandParamType.INT, false), - new CommandParameter("player", CommandParamType.TARGET, true) + CommandParameter.newType("gameMode", CommandParamType.INT), + CommandParameter.newType("player", true, CommandParamType.TARGET) }); this.commandParameters.put("byString", new CommandParameter[]{ - new CommandParameter("gameMode", false, CommandEnum.ENUM_GAMEMODE), - new CommandParameter("player", CommandParamType.TARGET, true) + CommandParameter.newEnum("gameMode", CommandEnum.ENUM_GAMEMODE), + CommandParameter.newType("player", true, CommandParamType.TARGET) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java b/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java index f9e6b294d37..1015a4cc662 100644 --- a/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/GameruleCommand.java @@ -48,26 +48,26 @@ public GameruleCommand(String name) { if (!boolGameRules.isEmpty()) { this.commandParameters.put("boolGameRules", new CommandParameter[]{ - new CommandParameter("rule", false , new CommandEnum("BoolGameRule", boolGameRules)), - new CommandParameter("value", true, CommandEnum.ENUM_BOOLEAN) + CommandParameter.newEnum("rule", new CommandEnum("BoolGameRule", boolGameRules)), + CommandParameter.newEnum("value", true, CommandEnum.ENUM_BOOLEAN) }); } if (!intGameRules.isEmpty()) { this.commandParameters.put("intGameRules", new CommandParameter[]{ - new CommandParameter("rule", false , new CommandEnum("IntGameRule", intGameRules)), - new CommandParameter("value", CommandParamType.INT, true) + CommandParameter.newEnum("rule", new CommandEnum("IntGameRule", intGameRules)), + CommandParameter.newType("value", true, CommandParamType.INT) }); } if (!floatGameRules.isEmpty()) { this.commandParameters.put("floatGameRules", new CommandParameter[]{ - new CommandParameter("rule", false , new CommandEnum("FloatGameRule", floatGameRules)), - new CommandParameter("value", CommandParamType.FLOAT, true) + CommandParameter.newEnum("rule", new CommandEnum("FloatGameRule", floatGameRules)), + CommandParameter.newType("value", true, CommandParamType.FLOAT) }); } if (!unknownGameRules.isEmpty()) { this.commandParameters.put("unknownGameRules", new CommandParameter[]{ - new CommandParameter("rule", false , new CommandEnum("UnknownGameRule", unknownGameRules)), - new CommandParameter("value", CommandParamType.STRING, true) + CommandParameter.newEnum("rule", new CommandEnum("UnknownGameRule", unknownGameRules)), + CommandParameter.newType("value", true, CommandParamType.STRING) }); } } diff --git a/src/main/java/cn/nukkit/command/defaults/GiveCommand.java b/src/main/java/cn/nukkit/command/defaults/GiveCommand.java index b44c511c623..d3cef0469d9 100644 --- a/src/main/java/cn/nukkit/command/defaults/GiveCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/GiveCommand.java @@ -20,23 +20,22 @@ public GiveCommand(String name) { this.setPermission("nukkit.command.give"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("itemName", false, CommandEnum.ENUM_ITEM), - new CommandParameter("amount", CommandParamType.INT, true), - //new CommandParameter("data", CommandParamType.INT, true), - new CommandParameter("tags", CommandParamType.RAWTEXT, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("itemName", CommandEnum.ENUM_ITEM), + CommandParameter.newType("amount", true, CommandParamType.INT), + CommandParameter.newType("tags", true, CommandParamType.RAWTEXT) }); this.commandParameters.put("toPlayerById", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("itemId", CommandParamType.INT, false), - new CommandParameter("amount", CommandParamType.INT, true), - new CommandParameter("tags", CommandParamType.RAWTEXT, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("itemId", CommandParamType.INT), + CommandParameter.newType("amount", true, CommandParamType.INT), + CommandParameter.newType("tags", true, CommandParamType.RAWTEXT) }); this.commandParameters.put("toPlayerByIdMeta", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("itemAndData", CommandParamType.STRING, false), - new CommandParameter("amount", CommandParamType.INT, true), - new CommandParameter("tags", CommandParamType.RAWTEXT, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("itemAndData", CommandParamType.STRING), + CommandParameter.newType("amount", true, CommandParamType.INT), + CommandParameter.newType("tags", true, CommandParamType.RAWTEXT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/HelpCommand.java b/src/main/java/cn/nukkit/command/defaults/HelpCommand.java index 5c8f7b718ee..124c35b46f1 100644 --- a/src/main/java/cn/nukkit/command/defaults/HelpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/HelpCommand.java @@ -22,7 +22,7 @@ public HelpCommand(String name) { this.setPermission("nukkit.command.help"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("page", CommandParamType.INT, true) + CommandParameter.newType("page", true, CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/KickCommand.java b/src/main/java/cn/nukkit/command/defaults/KickCommand.java index 5946d0d8eab..1caf85ac982 100644 --- a/src/main/java/cn/nukkit/command/defaults/KickCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/KickCommand.java @@ -20,8 +20,8 @@ public KickCommand(String name) { this.setPermission("nukkit.command.kick"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("reason", CommandParamType.MESSAGE, true) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("reason", true, CommandParamType.MESSAGE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/KillCommand.java b/src/main/java/cn/nukkit/command/defaults/KillCommand.java index 2f35f45dc2d..a6fa78e8563 100644 --- a/src/main/java/cn/nukkit/command/defaults/KillCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/KillCommand.java @@ -27,7 +27,7 @@ public KillCommand(String name) { + "nukkit.command.kill.other"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, true) + CommandParameter.newType("player", true, CommandParamType.TARGET) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/MeCommand.java b/src/main/java/cn/nukkit/command/defaults/MeCommand.java index b3fd04c8818..57a35cfc010 100644 --- a/src/main/java/cn/nukkit/command/defaults/MeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/MeCommand.java @@ -18,7 +18,7 @@ public MeCommand(String name) { this.setPermission("nukkit.command.me"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("message", CommandParamType.MESSAGE, false) + CommandParameter.newType("message", CommandParamType.MESSAGE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/OpCommand.java b/src/main/java/cn/nukkit/command/defaults/OpCommand.java index 2c8493340c3..6afc9fdcc6c 100644 --- a/src/main/java/cn/nukkit/command/defaults/OpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/OpCommand.java @@ -20,7 +20,7 @@ public OpCommand(String name) { this.setPermission("nukkit.command.op.give"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false) + CommandParameter.newType("player", CommandParamType.TARGET) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/PardonCommand.java b/src/main/java/cn/nukkit/command/defaults/PardonCommand.java index d97dd30d0ca..0ffd5296b72 100644 --- a/src/main/java/cn/nukkit/command/defaults/PardonCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/PardonCommand.java @@ -18,7 +18,7 @@ public PardonCommand(String name) { this.setAliases(new String[]{"unban"}); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false) + CommandParameter.newType("player", CommandParamType.TARGET) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java b/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java index 78d8e9a6440..d3ae0695a85 100644 --- a/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/PardonIpCommand.java @@ -22,7 +22,7 @@ public PardonIpCommand(String name) { this.setAliases(new String[]{"unbanip", "unban-ip", "pardonip"}); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("ip", CommandParamType.STRING, false) + CommandParameter.newType("ip", CommandParamType.STRING) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java b/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java index e4956c53523..291bfb977b8 100644 --- a/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java @@ -30,10 +30,10 @@ public ParticleCommand(String name) { this.setPermission("nukkit.command.particle"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("effect", false, new CommandEnum("Particle", Arrays.asList(ENUM_VALUES))), - new CommandParameter("position", CommandParamType.POSITION, false), - new CommandParameter("count", CommandParamType.INT, true), - new CommandParameter("data", CommandParamType.INT, true) + CommandParameter.newEnum("effect", new CommandEnum("Particle", Arrays.asList(ENUM_VALUES))), + CommandParameter.newType("position", CommandParamType.POSITION), + CommandParameter.newType("count", true, CommandParamType.INT), + CommandParameter.newType("data", true, CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/SayCommand.java b/src/main/java/cn/nukkit/command/defaults/SayCommand.java index 5eebc91d77c..a55d3c459cf 100644 --- a/src/main/java/cn/nukkit/command/defaults/SayCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/SayCommand.java @@ -19,7 +19,7 @@ public SayCommand(String name) { this.setPermission("nukkit.command.say"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("message", CommandParamType.MESSAGE, false) + CommandParameter.newType("message", CommandParamType.MESSAGE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java b/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java index e063a6a72da..fcb93688eb2 100644 --- a/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/SetWorldSpawnCommand.java @@ -21,7 +21,7 @@ public SetWorldSpawnCommand(String name) { this.setPermission("nukkit.command.setworldspawn"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("spawnPoint", CommandParamType.POSITION, true) + CommandParameter.newType("spawnPoint", true, CommandParamType.POSITION) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java b/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java index d2954d3bf55..bf10543d072 100644 --- a/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/SpawnpointCommand.java @@ -22,8 +22,8 @@ public SpawnpointCommand(String name) { this.setPermission("nukkit.command.spawnpoint"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, true), - new CommandParameter("spawnPos", CommandParamType.POSITION, true), + CommandParameter.newType("player", true, CommandParamType.TARGET), + CommandParameter.newType("spawnPos", true, CommandParamType.POSITION), }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java b/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java index 773393c6741..e69aa948808 100644 --- a/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TeleportCommand.java @@ -21,22 +21,22 @@ public TeleportCommand(String name) { this.setPermission("nukkit.command.teleport"); this.commandParameters.clear(); this.commandParameters.put("->Player", new CommandParameter[]{ - new CommandParameter("destination", CommandParamType.TARGET, false), + CommandParameter.newType("destination", CommandParamType.TARGET), }); this.commandParameters.put("Player->Player", new CommandParameter[]{ - new CommandParameter("victim", CommandParamType.TARGET, false), - new CommandParameter("destination", CommandParamType.TARGET, false) + CommandParameter.newType("victim", CommandParamType.TARGET), + CommandParameter.newType("destination", CommandParamType.TARGET) }); this.commandParameters.put("Player->Pos", new CommandParameter[]{ - new CommandParameter("victim", CommandParamType.TARGET, false), - new CommandParameter("destination", CommandParamType.POSITION, false), - new CommandParameter("yRot", CommandParamType.VALUE, true), - new CommandParameter("xRot", CommandParamType.VALUE, true) + CommandParameter.newType("victim", CommandParamType.TARGET), + CommandParameter.newType("destination", CommandParamType.POSITION), + CommandParameter.newType("yRot", true, CommandParamType.VALUE), + CommandParameter.newType("xRot", true, CommandParamType.VALUE) }); this.commandParameters.put("->Pos", new CommandParameter[]{ - new CommandParameter("destination", CommandParamType.POSITION, false), - new CommandParameter("yRot", CommandParamType.VALUE, true), - new CommandParameter("xRot", CommandParamType.VALUE, true) + CommandParameter.newType("destination", CommandParamType.POSITION), + CommandParameter.newType("yRot", true, CommandParamType.VALUE), + CommandParameter.newType("xRot", true, CommandParamType.VALUE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TellCommand.java b/src/main/java/cn/nukkit/command/defaults/TellCommand.java index 6a2538e47a8..37dc1426bd7 100644 --- a/src/main/java/cn/nukkit/command/defaults/TellCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TellCommand.java @@ -20,8 +20,8 @@ public TellCommand(String name) { this.setPermission("nukkit.command.tell"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("message", CommandParamType.MESSAGE, false) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newType("message", CommandParamType.MESSAGE) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TimeCommand.java b/src/main/java/cn/nukkit/command/defaults/TimeCommand.java index ff27bab3c68..23d8e68e6d7 100644 --- a/src/main/java/cn/nukkit/command/defaults/TimeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TimeCommand.java @@ -25,19 +25,19 @@ public TimeCommand(String name) { "nukkit.command.time.stop"); this.commandParameters.clear(); this.commandParameters.put("1arg", new CommandParameter[]{ - new CommandParameter("mode", false, new CommandEnum("TimeMode", ImmutableList.of("query", "start", "stop"))) + CommandParameter.newEnum("mode", new CommandEnum("TimeMode", ImmutableList.of("query", "start", "stop"))) }); this.commandParameters.put("add", new CommandParameter[]{ - new CommandParameter("mode", false, new CommandEnum("TimeModeAdd", ImmutableList.of("add"))), - new CommandParameter("amount", CommandParamType.INT, false) + CommandParameter.newEnum("mode", new CommandEnum("TimeModeAdd", ImmutableList.of("add"))), + CommandParameter.newType("amount", CommandParamType.INT) }); this.commandParameters.put("setAmount", new CommandParameter[]{ - new CommandParameter("mode", false, new CommandEnum("TimeModeSet", ImmutableList.of("set"))), - new CommandParameter("amount", CommandParamType.INT, false) + CommandParameter.newEnum("mode", false, new CommandEnum("TimeModeSet", ImmutableList.of("set"))), + CommandParameter.newType("amount", CommandParamType.INT) }); this.commandParameters.put("setTime", new CommandParameter[]{ - new CommandParameter("mode", false, new CommandEnum("TimeModeSet", ImmutableList.of("set"))), - new CommandParameter("time", false, new CommandEnum("TimeSpec", ImmutableList.of("day", "night", "midnight", "noon", "sunrise", "sunset"))) + CommandParameter.newEnum("mode", new CommandEnum("TimeModeSet", ImmutableList.of("set"))), + CommandParameter.newEnum("time", new CommandEnum("TimeSpec", ImmutableList.of("day", "night", "midnight", "noon", "sunrise", "sunset"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java b/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java index 85c66c314de..a406cb0ed28 100644 --- a/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java @@ -19,7 +19,7 @@ public TimingsCommand(String name) { this.setPermission("nukkit.command.timings"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("action", false, new CommandEnum("TimingsAction", + CommandParameter.newEnum("action", new CommandEnum("TimingsAction", ImmutableList.of("on", "off", "paste", "verbon", "verboff", "reset", "report"))) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TitleCommand.java b/src/main/java/cn/nukkit/command/defaults/TitleCommand.java index 3398f5d91a6..d17f47552ef 100644 --- a/src/main/java/cn/nukkit/command/defaults/TitleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TitleCommand.java @@ -20,24 +20,24 @@ public TitleCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("clear", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("clear", false, new CommandEnum("TitleClear", ImmutableList.of("clear"))) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("clear", new CommandEnum("TitleClear", ImmutableList.of("clear"))) }); this.commandParameters.put("reset", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("reset", false, new CommandEnum("TitleReset", ImmutableList.of("reset"))) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("reset", new CommandEnum("TitleReset", ImmutableList.of("reset"))) }); this.commandParameters.put("set", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("titleLocation", false, new CommandEnum("TitleSet", ImmutableList.of("title", "subtitle", "actionbar"))), - new CommandParameter("titleText", CommandParamType.MESSAGE, false) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("titleLocation", new CommandEnum("TitleSet", ImmutableList.of("title", "subtitle", "actionbar"))), + CommandParameter.newType("titleText", CommandParamType.MESSAGE) }); this.commandParameters.put("times", new CommandParameter[]{ - new CommandParameter("player", CommandParamType.TARGET, false), - new CommandParameter("times", false, new CommandEnum("TitleTimes", ImmutableList.of("times"))), - new CommandParameter("fadeIn", CommandParamType.INT, false), - new CommandParameter("stay", CommandParamType.INT, false), - new CommandParameter("fadeOut", CommandParamType.INT, false) + CommandParameter.newType("player", CommandParamType.TARGET), + CommandParameter.newEnum("times", new CommandEnum("TitleTimes", ImmutableList.of("times"))), + CommandParameter.newType("fadeIn", CommandParamType.INT), + CommandParameter.newType("stay", CommandParamType.INT), + CommandParameter.newType("fadeOut", CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/VersionCommand.java b/src/main/java/cn/nukkit/command/defaults/VersionCommand.java index 650147685ec..0fbfe8a6949 100644 --- a/src/main/java/cn/nukkit/command/defaults/VersionCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/VersionCommand.java @@ -26,7 +26,7 @@ public VersionCommand(String name) { this.setPermission("nukkit.command.version"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("pluginName", CommandParamType.STRING, true) + CommandParameter.newType("pluginName", true, CommandParamType.STRING) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java b/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java index 1b9dd358fc8..006418ada64 100644 --- a/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java @@ -21,8 +21,8 @@ public WeatherCommand(String name) { this.setPermission("nukkit.command.weather"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("type", false, new CommandEnum("WeatherType", ImmutableList.of("clear", "rain", "thunder"))), - new CommandParameter("duration", CommandParamType.INT, true) + CommandParameter.newEnum("type", new CommandEnum("WeatherType", ImmutableList.of("clear", "rain", "thunder"))), + CommandParameter.newType("duration", true, CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java b/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java index 5774c5d1d25..525bc59fe8c 100644 --- a/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java @@ -27,11 +27,11 @@ public WhitelistCommand(String name) { ); this.commandParameters.clear(); this.commandParameters.put("1arg", new CommandParameter[]{ - new CommandParameter("action", false, new CommandEnum("WhitelistAction", ImmutableList.of("on", "off", "list", "reload"))) + CommandParameter.newEnum("action", new CommandEnum("WhitelistAction", ImmutableList.of("on", "off", "list", "reload"))) }); this.commandParameters.put("2args", new CommandParameter[]{ - new CommandParameter("action", false, new CommandEnum("WhitelistPlayerAction", ImmutableList.of("add", "remove"))), - new CommandParameter("player", CommandParamType.TARGET, false) + CommandParameter.newEnum("action", new CommandEnum("WhitelistPlayerAction", ImmutableList.of("add", "remove"))), + CommandParameter.newType("player", CommandParamType.TARGET) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/XpCommand.java b/src/main/java/cn/nukkit/command/defaults/XpCommand.java index 647aea6eafc..26a5a5f9323 100644 --- a/src/main/java/cn/nukkit/command/defaults/XpCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/XpCommand.java @@ -18,12 +18,12 @@ public XpCommand(String name) { this.setPermission("nukkit.command.xp"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - new CommandParameter("amount", CommandParamType.INT, false), - new CommandParameter("player", CommandParamType.TARGET, true) + CommandParameter.newType("amount", CommandParamType.INT), + CommandParameter.newType("player", true, CommandParamType.TARGET) }); this.commandParameters.put("level", new CommandParameter[]{ - new CommandParameter("amount", "l", false), - new CommandParameter("player", CommandParamType.TARGET, true) + CommandParameter.newPostfix("amount", "l"), + CommandParameter.newType("player", true, CommandParamType.TARGET) }); } From 3ce8a9fdd1e78609543289b224b0ff875f06eae3 Mon Sep 17 00:00:00 2001 From: Wodor <17339354+wode490390@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:55:40 +0800 Subject: [PATCH 4/4] CommandEnum(String, String...) --- .../cn/nukkit/command/data/CommandEnum.java | 17 ++++++++++------- .../nukkit/command/data/CommandParameter.java | 5 ++--- .../nukkit/command/defaults/BanListCommand.java | 3 +-- .../command/defaults/DifficultyCommand.java | 4 +--- .../nukkit/command/defaults/EffectCommand.java | 3 +-- .../nukkit/command/defaults/EnchantCommand.java | 9 ++++----- .../command/defaults/ParticleCommand.java | 3 +-- .../cn/nukkit/command/defaults/TimeCommand.java | 11 +++++------ .../nukkit/command/defaults/TimingsCommand.java | 4 +--- .../nukkit/command/defaults/TitleCommand.java | 9 ++++----- .../nukkit/command/defaults/WeatherCommand.java | 3 +-- .../command/defaults/WhitelistCommand.java | 5 ++--- 12 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/main/java/cn/nukkit/command/data/CommandEnum.java b/src/main/java/cn/nukkit/command/data/CommandEnum.java index b9137426f62..6e18e36039b 100644 --- a/src/main/java/cn/nukkit/command/data/CommandEnum.java +++ b/src/main/java/cn/nukkit/command/data/CommandEnum.java @@ -5,8 +5,7 @@ import com.google.common.collect.ImmutableList; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collections; +import java.util.Arrays; import java.util.List; /** @@ -21,23 +20,27 @@ public class CommandEnum { public static final CommandEnum ENUM_ITEM; static { - List blocks = new ArrayList<>(); + ImmutableList.Builder blocks = ImmutableList.builder(); for (Field field : BlockID.class.getDeclaredFields()) { blocks.add(field.getName().toLowerCase()); } - ENUM_BLOCK = new CommandEnum("Block", Collections.unmodifiableList(blocks)); + ENUM_BLOCK = new CommandEnum("Block", blocks.build()); - List items = new ArrayList<>(); + ImmutableList.Builder items = ImmutableList.builder(); for (Field field : ItemID.class.getDeclaredFields()) { items.add(field.getName().toLowerCase()); } - items.addAll(blocks); - ENUM_ITEM = new CommandEnum("Item", Collections.unmodifiableList(items)); + items.addAll(ENUM_BLOCK.getValues()); + ENUM_ITEM = new CommandEnum("Item", items.build()); } private String name; private List values; + public CommandEnum(String name, String... values) { + this(name, Arrays.asList(values)); + } + public CommandEnum(String name, List values) { this.name = name; this.values = values; diff --git a/src/main/java/cn/nukkit/command/data/CommandParameter.java b/src/main/java/cn/nukkit/command/data/CommandParameter.java index 95926cbe122..a657455d1b0 100644 --- a/src/main/java/cn/nukkit/command/data/CommandParameter.java +++ b/src/main/java/cn/nukkit/command/data/CommandParameter.java @@ -1,7 +1,6 @@ package cn.nukkit.command.data; import java.util.ArrayList; -import java.util.Arrays; public class CommandParameter { @@ -66,7 +65,7 @@ public CommandParameter(String name, boolean optional, String[] enumValues) { this.name = name; this.type = CommandParamType.RAWTEXT; this.optional = optional; - this.enumData = new CommandEnum(name + "Enums", Arrays.asList(enumValues)); + this.enumData = new CommandEnum(name + "Enums", enumValues); } /** @@ -106,7 +105,7 @@ public static CommandParameter newEnum(String name, String[] values) { } public static CommandParameter newEnum(String name, boolean optional, String[] values) { - return newEnum(name, optional, new CommandEnum(name + "Enums", Arrays.asList(values))); + return newEnum(name, optional, new CommandEnum(name + "Enums", values)); } public static CommandParameter newEnum(String name, String type) { diff --git a/src/main/java/cn/nukkit/command/defaults/BanListCommand.java b/src/main/java/cn/nukkit/command/defaults/BanListCommand.java index d074c6f797a..0ca654c4e88 100644 --- a/src/main/java/cn/nukkit/command/defaults/BanListCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/BanListCommand.java @@ -6,7 +6,6 @@ import cn.nukkit.lang.TranslationContainer; import cn.nukkit.permission.BanEntry; import cn.nukkit.permission.BanList; -import com.google.common.collect.ImmutableList; import java.util.Iterator; @@ -20,7 +19,7 @@ public BanListCommand(String name) { this.setPermission("nukkit.command.ban.list"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - CommandParameter.newEnum("type", true, new CommandEnum("BanListType", ImmutableList.of("ips", "players"))) + CommandParameter.newEnum("type", true, new CommandEnum("BanListType", "ips", "players")) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java b/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java index ab24c6811eb..4fad9e3b8fc 100644 --- a/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/DifficultyCommand.java @@ -8,7 +8,6 @@ import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.network.protocol.SetDifficultyPacket; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -26,8 +25,7 @@ public DifficultyCommand(String name) { CommandParameter.newType("difficulty", CommandParamType.INT) }); this.commandParameters.put("byString", new CommandParameter[]{ - CommandParameter.newEnum("difficulty", new CommandEnum("Difficulty", - ImmutableList.of("peaceful", "p", "easy", "e", "normal", "n", "hard", "h"))) + CommandParameter.newEnum("difficulty", new CommandEnum("Difficulty", "peaceful", "p", "easy", "e", "normal", "n", "hard", "h")) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/EffectCommand.java b/src/main/java/cn/nukkit/command/defaults/EffectCommand.java index fe73cd6df2e..760db564e36 100644 --- a/src/main/java/cn/nukkit/command/defaults/EffectCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/EffectCommand.java @@ -11,7 +11,6 @@ import cn.nukkit.potion.InstantEffect; import cn.nukkit.utils.ServerException; import cn.nukkit.utils.TextFormat; -import com.google.common.collect.ImmutableList; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -44,7 +43,7 @@ public EffectCommand(String name) { }); this.commandParameters.put("clear", new CommandParameter[]{ CommandParameter.newType("player", CommandParamType.TARGET), - CommandParameter.newEnum("clear", new CommandEnum("ClearEffects", ImmutableList.of("clear"))) + CommandParameter.newEnum("clear", new CommandEnum("ClearEffects", "clear")) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java b/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java index bff2ed4aef4..861e92ff5ca 100644 --- a/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/EnchantCommand.java @@ -10,7 +10,6 @@ import cn.nukkit.item.enchantment.Enchantment; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; -import com.google.common.collect.ImmutableList; /** * Created by Pub4Game on 23.01.2016. @@ -29,10 +28,10 @@ public EnchantCommand(String name) { this.commandParameters.put("byName", new CommandParameter[]{ CommandParameter.newType("player", CommandParamType.TARGET), CommandParameter.newEnum("enchantmentName", new CommandEnum("Enchant", - ImmutableList.of("protection", "fire_protection", "feather_falling", "blast_protection", "projectile_projection", "thorns", "respiration", - "aqua_affinity", "depth_strider", "sharpness", "smite", "bane_of_arthropods", "knockback", "fire_aspect", "looting", "efficiency", - "silk_touch", "durability", "fortune", "power", "punch", "flame", "infinity", "luck_of_the_sea", "lure", "frost_walker", "mending", - "binding_curse", "vanishing_curse", "impaling", "loyality", "riptide", "channeling"))), + "protection", "fire_protection", "feather_falling", "blast_protection", "projectile_projection", "thorns", "respiration", + "aqua_affinity", "depth_strider", "sharpness", "smite", "bane_of_arthropods", "knockback", "fire_aspect", "looting", "efficiency", + "silk_touch", "durability", "fortune", "power", "punch", "flame", "infinity", "luck_of_the_sea", "lure", "frost_walker", "mending", + "binding_curse", "vanishing_curse", "impaling", "loyality", "riptide", "channeling")), CommandParameter.newType("level", true, CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java b/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java index 291bfb977b8..aea1e78c51e 100644 --- a/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/ParticleCommand.java @@ -12,7 +12,6 @@ import cn.nukkit.level.particle.*; import cn.nukkit.math.Vector3; -import java.util.Arrays; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -30,7 +29,7 @@ public ParticleCommand(String name) { this.setPermission("nukkit.command.particle"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - CommandParameter.newEnum("effect", new CommandEnum("Particle", Arrays.asList(ENUM_VALUES))), + CommandParameter.newEnum("effect", new CommandEnum("Particle", ENUM_VALUES)), CommandParameter.newType("position", CommandParamType.POSITION), CommandParameter.newType("count", true, CommandParamType.INT), CommandParameter.newType("data", true, CommandParamType.INT) diff --git a/src/main/java/cn/nukkit/command/defaults/TimeCommand.java b/src/main/java/cn/nukkit/command/defaults/TimeCommand.java index 23d8e68e6d7..5d6f39ad95d 100644 --- a/src/main/java/cn/nukkit/command/defaults/TimeCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TimeCommand.java @@ -9,7 +9,6 @@ import cn.nukkit.lang.TranslationContainer; import cn.nukkit.level.Level; import cn.nukkit.utils.TextFormat; -import com.google.common.collect.ImmutableList; /** * Created on 2015/11/11 by xtypr. @@ -25,19 +24,19 @@ public TimeCommand(String name) { "nukkit.command.time.stop"); this.commandParameters.clear(); this.commandParameters.put("1arg", new CommandParameter[]{ - CommandParameter.newEnum("mode", new CommandEnum("TimeMode", ImmutableList.of("query", "start", "stop"))) + CommandParameter.newEnum("mode", new CommandEnum("TimeMode", "query", "start", "stop")) }); this.commandParameters.put("add", new CommandParameter[]{ - CommandParameter.newEnum("mode", new CommandEnum("TimeModeAdd", ImmutableList.of("add"))), + CommandParameter.newEnum("mode", new CommandEnum("TimeModeAdd", "add")), CommandParameter.newType("amount", CommandParamType.INT) }); this.commandParameters.put("setAmount", new CommandParameter[]{ - CommandParameter.newEnum("mode", false, new CommandEnum("TimeModeSet", ImmutableList.of("set"))), + CommandParameter.newEnum("mode", false, new CommandEnum("TimeModeSet", "set")), CommandParameter.newType("amount", CommandParamType.INT) }); this.commandParameters.put("setTime", new CommandParameter[]{ - CommandParameter.newEnum("mode", new CommandEnum("TimeModeSet", ImmutableList.of("set"))), - CommandParameter.newEnum("time", new CommandEnum("TimeSpec", ImmutableList.of("day", "night", "midnight", "noon", "sunrise", "sunset"))) + CommandParameter.newEnum("mode", new CommandEnum("TimeModeSet", "set")), + CommandParameter.newEnum("time", new CommandEnum("TimeSpec", "day", "night", "midnight", "noon", "sunrise", "sunset")) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java b/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java index a406cb0ed28..beb9354e2ba 100644 --- a/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TimingsCommand.java @@ -6,7 +6,6 @@ import cn.nukkit.lang.TranslationContainer; import co.aikar.timings.Timings; import co.aikar.timings.TimingsExport; -import com.google.common.collect.ImmutableList; /** * @author fromgate @@ -19,8 +18,7 @@ public TimingsCommand(String name) { this.setPermission("nukkit.command.timings"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - CommandParameter.newEnum("action", new CommandEnum("TimingsAction", - ImmutableList.of("on", "off", "paste", "verbon", "verboff", "reset", "report"))) + CommandParameter.newEnum("action", new CommandEnum("TimingsAction", "on", "off", "paste", "verbon", "verboff", "reset", "report")) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/TitleCommand.java b/src/main/java/cn/nukkit/command/defaults/TitleCommand.java index d17f47552ef..2bdf150c741 100644 --- a/src/main/java/cn/nukkit/command/defaults/TitleCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/TitleCommand.java @@ -8,7 +8,6 @@ import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; -import com.google.common.collect.ImmutableList; /** * @author Tee7even @@ -21,20 +20,20 @@ public TitleCommand(String name) { this.commandParameters.clear(); this.commandParameters.put("clear", new CommandParameter[]{ CommandParameter.newType("player", CommandParamType.TARGET), - CommandParameter.newEnum("clear", new CommandEnum("TitleClear", ImmutableList.of("clear"))) + CommandParameter.newEnum("clear", new CommandEnum("TitleClear", "clear")) }); this.commandParameters.put("reset", new CommandParameter[]{ CommandParameter.newType("player", CommandParamType.TARGET), - CommandParameter.newEnum("reset", new CommandEnum("TitleReset", ImmutableList.of("reset"))) + CommandParameter.newEnum("reset", new CommandEnum("TitleReset", "reset")) }); this.commandParameters.put("set", new CommandParameter[]{ CommandParameter.newType("player", CommandParamType.TARGET), - CommandParameter.newEnum("titleLocation", new CommandEnum("TitleSet", ImmutableList.of("title", "subtitle", "actionbar"))), + CommandParameter.newEnum("titleLocation", new CommandEnum("TitleSet", "title", "subtitle", "actionbar")), CommandParameter.newType("titleText", CommandParamType.MESSAGE) }); this.commandParameters.put("times", new CommandParameter[]{ CommandParameter.newType("player", CommandParamType.TARGET), - CommandParameter.newEnum("times", new CommandEnum("TitleTimes", ImmutableList.of("times"))), + CommandParameter.newEnum("times", new CommandEnum("TitleTimes", "times")), CommandParameter.newType("fadeIn", CommandParamType.INT), CommandParameter.newType("stay", CommandParamType.INT), CommandParameter.newType("fadeOut", CommandParamType.INT) diff --git a/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java b/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java index 006418ada64..f85de3c6d19 100644 --- a/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/WeatherCommand.java @@ -8,7 +8,6 @@ import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.level.Level; -import com.google.common.collect.ImmutableList; /** * author: Angelic47 @@ -21,7 +20,7 @@ public WeatherCommand(String name) { this.setPermission("nukkit.command.weather"); this.commandParameters.clear(); this.commandParameters.put("default", new CommandParameter[]{ - CommandParameter.newEnum("type", new CommandEnum("WeatherType", ImmutableList.of("clear", "rain", "thunder"))), + CommandParameter.newEnum("type", new CommandEnum("WeatherType", "clear", "rain", "thunder")), CommandParameter.newType("duration", true, CommandParamType.INT) }); } diff --git a/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java b/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java index 525bc59fe8c..d04aaa3b85e 100644 --- a/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java +++ b/src/main/java/cn/nukkit/command/defaults/WhitelistCommand.java @@ -7,7 +7,6 @@ import cn.nukkit.command.data.CommandParameter; import cn.nukkit.lang.TranslationContainer; import cn.nukkit.utils.TextFormat; -import com.google.common.collect.ImmutableList; /** * Created on 2015/11/12 by xtypr. @@ -27,10 +26,10 @@ public WhitelistCommand(String name) { ); this.commandParameters.clear(); this.commandParameters.put("1arg", new CommandParameter[]{ - CommandParameter.newEnum("action", new CommandEnum("WhitelistAction", ImmutableList.of("on", "off", "list", "reload"))) + CommandParameter.newEnum("action", new CommandEnum("WhitelistAction", "on", "off", "list", "reload")) }); this.commandParameters.put("2args", new CommandParameter[]{ - CommandParameter.newEnum("action", new CommandEnum("WhitelistPlayerAction", ImmutableList.of("add", "remove"))), + CommandParameter.newEnum("action", new CommandEnum("WhitelistPlayerAction", "add", "remove")), CommandParameter.newType("player", CommandParamType.TARGET) }); }