package com.xfestudio.xfeservermanager.api.command;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.Locale;
import java.util.Map;
/** Canonicalizes command roots without depending on a particular command dispatcher. */
public final class CommandNames {
private static final Map<String, String> VANILLA_ALIASES = Map.of(
"tp", "teleport"
);
private CommandNames() {
}
public static String canonicalize(String commandId) {
String value = ApiChecks.notBlank(commandId, "commandId").toLowerCase(Locale.ROOT);
while (value.startsWith("/")) {
value = value.substring(1);
}
int space = value.indexOf(' ');
if (space >= 0) {
value = value.substring(0, space);
}
int separator = value.indexOf(':');
String namespace = separator >= 0 ? value.substring(0, separator) : "minecraft";
String path = separator >= 0 ? value.substring(separator + 1) : value;
if (namespace.equals("minecraft")) {
path = VANILLA_ALIASES.getOrDefault(path, path);
}
if (namespace.isBlank() || path.isBlank()) {
throw new IllegalArgumentException("commandId must contain a valid namespace and path");
}
return namespace + ':' + path;
}
}
package com.xfestudio.xfeservermanager.api.command;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.Locale;
import java.util.Map;
/** Canonicalizes command roots without depending on a particular command dispatcher. */
public final class CommandNames {
private static final Map<String, String> VANILLA_ALIASES = Map.of(
"tp", "teleport"
);
private CommandNames() {
}
public static String canonicalize(String commandId) {
String value = ApiChecks.notBlank(commandId, "commandId").toLowerCase(Locale.ROOT);
while (value.startsWith("/")) {
value = value.substring(1);
}
int space = value.indexOf(' ');
if (space >= 0) {
value = value.substring(0, space);
}
int separator = value.indexOf(':');
String namespace = separator >= 0 ? value.substring(0, separator) : "minecraft";
String path = separator >= 0 ? value.substring(separator + 1) : value;
if (namespace.equals("minecraft")) {
path = VANILLA_ALIASES.getOrDefault(path, path);
}
if (namespace.isBlank() || path.isBlank()) {
throw new IllegalArgumentException("commandId must contain a valid namespace and path");
}
return namespace + ':' + path;
}
}