Add some missing convenience APIs to MinecraftChannelIdentifier
This commit is contained in:
@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import net.kyori.minecraft.Key;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,35 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
||||
return new MinecraftChannelIdentifier(namespace, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an channel identifier from the specified Minecraft identifier.
|
||||
*
|
||||
* @param identifier the Minecraft identifier
|
||||
* @return a new channel identifier
|
||||
*/
|
||||
public static MinecraftChannelIdentifier from(String identifier) {
|
||||
int colonPos = identifier.indexOf(':');
|
||||
if (colonPos == -1) {
|
||||
throw new IllegalArgumentException("Identifier does not contain a colon.");
|
||||
}
|
||||
if (colonPos + 1 == identifier.length()) {
|
||||
throw new IllegalArgumentException("Identifier is empty.");
|
||||
}
|
||||
String namespace = identifier.substring(0, colonPos);
|
||||
String name = identifier.substring(colonPos + 1);
|
||||
return create(namespace, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an channel identifier from the specified Minecraft identifier.
|
||||
*
|
||||
* @param key the Minecraft key to use
|
||||
* @return a new channel identifier
|
||||
*/
|
||||
public static MinecraftChannelIdentifier from(Key key) {
|
||||
return create(key.namespace(), key.value());
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
@@ -58,6 +88,10 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Key asKey() {
|
||||
return Key.of(namespace, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return namespace + ":" + name + " (modern)";
|
||||
|
||||
Reference in New Issue
Block a user