From 6bb361d78146faaf7ee9babf09a7b7a79d62da70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 3 Sep 2018 19:23:09 +0800 Subject: [PATCH] =?UTF-8?q?+=20=E5=A2=9E=E5=8A=A0=20/tlocale=20commandAsOp?= =?UTF-8?q?=20=E5=91=BD=E4=BB=A4=E4=BB=A5=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=89=A7=E8=A1=8C=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/TabooLibExecuteCommand.java | 41 +++++++++++++++++++ src/main/resources/lang/zh_CN.yml | 8 +++- 2 files changed, 48 insertions(+), 1 deletion(-) 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: '内容'