|
9 | 9 |
|
10 | 10 | import java.util.HashMap; |
11 | 11 | import java.util.Map; |
| 12 | +import java.util.regex.Matcher; |
| 13 | +import java.util.regex.Pattern; |
12 | 14 |
|
13 | 15 | import static com.mojang.brigadier.arguments.StringArgumentType.word; |
14 | 16 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; |
15 | 17 |
|
16 | 18 | public class CommandNode extends Command { |
17 | 19 |
|
18 | 20 | private static final Map<String, String> NODE_MAP = new HashMap<>(); |
| 21 | + private static final Pattern PRIVATE_NODE_PATTERN = Pattern.compile("^p(\\d+)$"); |
19 | 22 |
|
20 | 23 | public void loadNodes() { |
21 | 24 | NODE_MAP.clear(); |
@@ -61,7 +64,18 @@ public LiteralArgumentBuilder<FabricClientCommandSource> create(LiteralArgumentB |
61 | 64 | String key = context.getArgument("node", String.class); |
62 | 65 | if (CodeClient.MC.getNetworkHandler() == null) return -1; |
63 | 66 |
|
64 | | - CodeClient.MC.getNetworkHandler().sendCommand("server " + NODE_MAP.getOrDefault(key, key)); |
| 67 | + String serverId = NODE_MAP.getOrDefault(key, key); |
| 68 | + |
| 69 | + // If the server ID is not found, as a last resort, |
| 70 | + // try to process "pX" syntax as a private node shorthand. |
| 71 | + if (serverId.equals(key)) { |
| 72 | + Matcher privateNodeMatcher = PRIVATE_NODE_PATTERN.matcher(key.trim()); |
| 73 | + if (privateNodeMatcher.find()) { |
| 74 | + serverId = "private" + privateNodeMatcher.group(1); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + CodeClient.MC.getNetworkHandler().sendCommand("server " + serverId); |
65 | 79 | return 0; |
66 | 80 | })); |
67 | 81 | } |
|
0 commit comments