+ 增加 /tlocale commandAsOp 命令以管理员权限执行命令

This commit is contained in:
坏黑 2018-09-03 19:23:09 +08:00
parent b4f06444ab
commit 6bb361d781
2 changed files with 48 additions and 1 deletions

View File

@ -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) { public static boolean dispatchCommand(CommandSender sender, String command) {
try { try {
if ((sender instanceof Player)) { if ((sender instanceof Player)) {

View File

@ -533,7 +533,13 @@ COMMANDS:
1: '内容' 1: '内容'
INVALID-PLAYER-OFFLINE: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线.' INVALID-PLAYER-OFFLINE: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线.'
COMMAND: COMMAND:
DESCRIPTION: '使目标输入执行指令' DESCRIPTION: '使目标执行指令'
ARGUMENTS:
0: '目标'
1: '内容'
INVALID-TARGET-NOT-FOUND: '&8[&3&lTabooLib&8] &4目标 &c{0} &4不存在.'
COMMAND-AS-OP:
DESCRIPTION: '使目标以管理员身份执行指令'
ARGUMENTS: ARGUMENTS:
0: '目标' 0: '目标'
1: '内容' 1: '内容'