Skip to content

Commit 53403df

Browse files
committed
feat: /node p<num> for private nodes
/node p1, /node p2, etc.
1 parent 2a38e09 commit 53403df

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/main/java/dev/dfonline/codeclient/command/impl/CommandNode.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
import java.util.HashMap;
1111
import java.util.Map;
12+
import java.util.regex.Matcher;
13+
import java.util.regex.Pattern;
1214

1315
import static com.mojang.brigadier.arguments.StringArgumentType.word;
1416
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
1517

1618
public class CommandNode extends Command {
1719

1820
private static final Map<String, String> NODE_MAP = new HashMap<>();
21+
private static final Pattern PRIVATE_NODE_PATTERN = Pattern.compile("^p(\\d+)$");
1922

2023
public void loadNodes() {
2124
NODE_MAP.clear();
@@ -61,7 +64,18 @@ public LiteralArgumentBuilder<FabricClientCommandSource> create(LiteralArgumentB
6164
String key = context.getArgument("node", String.class);
6265
if (CodeClient.MC.getNetworkHandler() == null) return -1;
6366

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);
6579
return 0;
6680
}));
6781
}

0 commit comments

Comments
 (0)