diff --git a/src/main/java/me/skymc/taboolib/commands/TabooLibExecuteCommand.java b/src/main/java/me/skymc/taboolib/commands/TabooLibExecuteCommand.java index f75ea8c..e380cde 100644 --- a/src/main/java/me/skymc/taboolib/commands/TabooLibExecuteCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/TabooLibExecuteCommand.java @@ -97,6 +97,47 @@ public class TabooLibExecuteCommand extends BaseMainCommand { } }; + @CommandRegister(priority = 2) + BaseSubCommand commandAsOp = new BaseSubCommand() { + @Override + public String getLabel() { + return "commandAsOp"; + } + + @Override + public String getDescription() { + return TLocale.asString("COMMANDS.TEXECUTE.COMMAND-AS-OP.DESCRIPTION"); + } + + @Override + public CommandArgument[] getArguments() { + return new CommandArgument[] { + new CommandArgument(TLocale.asString("COMMANDS.TEXECUTE.COMMAND-AS-OP.ARGUMENTS.0")), + new CommandArgument(TLocale.asString("COMMANDS.TEXECUTE.COMMAND-AS-OP.ARGUMENTS.1")) + }; + } + + @Override + public void onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args[0].equalsIgnoreCase("console")) { + dispatchCommand(Bukkit.getConsoleSender(), ArrayUtils.arrayJoin(args, 1)); + return; + } + Player player = Bukkit.getPlayerExact(args[0]); + if (player == null) { + TLocale.sendTo(sender, "INVALID-TARGET-NOT-FOUND", args[0]); + return; + } + boolean isOp = player.isOp(); + player.setOp(true); + try { + dispatchCommand(player, ArrayUtils.arrayJoin(args, 1)); + } catch (Exception ignored) { + } + player.setOp(isOp); + } + }; + public static boolean dispatchCommand(CommandSender sender, String command) { try { if ((sender instanceof Player)) { diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index 2684f3a..41defa2 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -533,7 +533,13 @@ COMMANDS: 1: '内容' INVALID-PLAYER-OFFLINE: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线.' COMMAND: - DESCRIPTION: '使目标输入执行指令' + DESCRIPTION: '使目标执行指令' + ARGUMENTS: + 0: '目标' + 1: '内容' + INVALID-TARGET-NOT-FOUND: '&8[&3&lTabooLib&8] &4目标 &c{0} &4不存在.' + COMMAND-AS-OP: + DESCRIPTION: '使目标以管理员身份执行指令' ARGUMENTS: 0: '目标' 1: '内容'