feat: 添加管理员指令
This commit is contained in:
@@ -257,11 +257,10 @@ public abstract class BallAPI {
|
||||
*/
|
||||
public void dispatchConsoleCommand(@Nullable BallServerType type, @Nullable String serverID, @NotNull String command) {
|
||||
sendBallMessage(BALL_CHANNEL, new BallMessage(
|
||||
getLocalServerId(), null, BallServerType.GAME,
|
||||
getLocalServerId(), null, type,
|
||||
BallActions.DispatchConsoleCommand.name(),
|
||||
CoreAPI.getInstance().getGson().toJsonTree(new DispatchConsoleCommandEvent(type, serverID, command))
|
||||
CoreAPI.getInstance().getGson().toJsonTree(new DispatchConsoleCommandEvent(serverID, command))
|
||||
), false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,9 +272,9 @@ public abstract class BallAPI {
|
||||
*/
|
||||
public void dispatchPlayerCommand(@Nullable BallServerType type, @Nullable UUID uuid, @NotNull String command) {
|
||||
sendBallMessage(BALL_CHANNEL, new BallMessage(
|
||||
getLocalServerId(), null, BallServerType.GAME,
|
||||
getLocalServerId(), null, type,
|
||||
BallActions.DispatchPlayerCommand.name(),
|
||||
CoreAPI.getInstance().getGson().toJsonTree(new DispatchPlayerCommandEvent(type, uuid, command))
|
||||
CoreAPI.getInstance().getGson().toJsonTree(new DispatchPlayerCommandEvent(uuid, command))
|
||||
), false);
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,16 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.command;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.AdaptCommandSender;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SudoAllConsoleCommand extends ChildCommand {
|
||||
public static final SudoAllConsoleCommand INSTANCE = new SudoAllConsoleCommand();
|
||||
@@ -22,7 +25,7 @@ public class SudoAllConsoleCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull String getUsage() {
|
||||
return "sudo-all-console <服务器ID> <命令内容>";
|
||||
return "sudo-all-console <服务器类型> <命令内容>";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,22 +40,36 @@ public class SudoAllConsoleCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull AdaptCommandSender sender, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(BallCommand.INSTANCE.getUsage() + " " + getUsage());
|
||||
return true;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(args[0]);
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
BallServerType serverType;
|
||||
try {
|
||||
serverType = BallServerType.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage("§c未知的服务器类型: " + args[0]);
|
||||
return true;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(args[1]);
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
builder.append(" ").append(args[i]);
|
||||
}
|
||||
String command = builder.toString();
|
||||
BallAPI.getInstance().dispatchConsoleCommand(null, null, command);
|
||||
BallAPI.getInstance().dispatchConsoleCommand(serverType, null, command);
|
||||
sender.sendMessage("§a已强制所有服务器控制台执行命令: §e/" + command);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull AdaptCommandSender sender, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.stream(BallServerType.values())
|
||||
.map(Enum::name)
|
||||
.filter(o -> o.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@@ -3,11 +3,14 @@ package cn.hamster3.mc.plugin.ball.common.command;
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.AdaptCommandSender;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SudoAllPlayerCommand extends ChildCommand {
|
||||
public static final SudoAllPlayerCommand INSTANCE = new SudoAllPlayerCommand();
|
||||
@@ -22,7 +25,7 @@ public class SudoAllPlayerCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull String getUsage() {
|
||||
return "sudo-all-player <命令内容>";
|
||||
return "sudo-all-player <服务器类型> <命令内容>";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,22 +40,36 @@ public class SudoAllPlayerCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull AdaptCommandSender sender, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(BallCommand.INSTANCE.getUsage() + " " + getUsage());
|
||||
return true;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(args[0]);
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
BallServerType serverType;
|
||||
try {
|
||||
serverType = BallServerType.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage("§c未知的服务器类型: " + args[0]);
|
||||
return true;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(args[1]);
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
builder.append(" ").append(args[i]);
|
||||
}
|
||||
String command = builder.toString();
|
||||
BallAPI.getInstance().dispatchPlayerCommand(null, null, command);
|
||||
BallAPI.getInstance().dispatchPlayerCommand(serverType, null, command);
|
||||
sender.sendMessage("§a已强制所有玩家执行命令: §e/" + command);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull AdaptCommandSender sender, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.stream(BallServerType.values())
|
||||
.map(Enum::name)
|
||||
.filter(o -> o.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.command;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.AdaptCommandSender;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@@ -1,12 +1,14 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.command;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.AdaptCommandSender;
|
||||
import cn.hamster3.mc.plugin.ball.common.command.adapt.ChildCommand;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -25,7 +27,7 @@ public class SudoPlayerCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull String getUsage() {
|
||||
return "sudo-player <玩家名|UUID> <命令内容>";
|
||||
return "sudo-player <服务器类型> <玩家名|UUID> <命令内容>";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,43 +42,59 @@ public class SudoPlayerCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull AdaptCommandSender sender, @NotNull String[] args) {
|
||||
if (args.length < 2) {
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(BallCommand.INSTANCE.getUsage() + " " + getUsage());
|
||||
return true;
|
||||
}
|
||||
BallServerType serverType;
|
||||
try {
|
||||
serverType = BallServerType.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage("§c未知的服务器类型: " + args[0]);
|
||||
return true;
|
||||
}
|
||||
BallPlayerInfo info;
|
||||
try {
|
||||
UUID uuid = UUID.fromString(args[0]);
|
||||
UUID uuid = UUID.fromString(args[1]);
|
||||
info = BallAPI.getInstance().getPlayerInfo(uuid);
|
||||
} catch (Exception e) {
|
||||
info = BallAPI.getInstance().getPlayerInfo(args[0]);
|
||||
info = BallAPI.getInstance().getPlayerInfo(args[1]);
|
||||
}
|
||||
if (info == null) {
|
||||
sender.sendMessage("§c未找到玩家 " + args[0]);
|
||||
sender.sendMessage("§c未找到玩家 " + args[1]);
|
||||
return true;
|
||||
}
|
||||
if (!info.isOnline()) {
|
||||
sender.sendMessage("§c玩家 " + args[0] + " 不在线");
|
||||
sender.sendMessage("§c玩家 " + args[1] + " 不在线");
|
||||
return true;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(args[1]);
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
StringBuilder builder = new StringBuilder(args[2]);
|
||||
for (int i = 3; i < args.length; i++) {
|
||||
builder.append(" ").append(args[i]);
|
||||
}
|
||||
String command = builder.toString();
|
||||
BallAPI.getInstance().dispatchPlayerCommand(null, info.getUuid(), command);
|
||||
BallAPI.getInstance().dispatchPlayerCommand(serverType, info.getUuid(), command);
|
||||
sender.sendMessage("§a已强制玩家 " + info.getName() + " 执行命令: §e/" + command);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull AdaptCommandSender sender, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
return BallAPI.getInstance().getAllPlayerInfo().values().stream()
|
||||
.map(BallPlayerInfo::getName)
|
||||
.filter(o -> o.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
return Arrays.stream(BallServerType.values())
|
||||
.map(Enum::name)
|
||||
.filter(o -> o.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
case 2: {
|
||||
return BallAPI.getInstance().getAllPlayerInfo().values().stream()
|
||||
.map(BallPlayerInfo::getName)
|
||||
.filter(o -> o.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -9,8 +8,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DispatchConsoleCommandEvent {
|
||||
@Nullable
|
||||
private final BallServerType type;
|
||||
@Nullable
|
||||
private final String serverID;
|
||||
@NotNull
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -11,8 +10,6 @@ import java.util.UUID;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DispatchPlayerCommandEvent {
|
||||
@Nullable
|
||||
private final BallServerType type;
|
||||
@Nullable
|
||||
private final UUID uuid;
|
||||
@NotNull
|
||||
|
Reference in New Issue
Block a user