1111
1212import com .google .common .base .Strings ;
1313import java .util .Objects ;
14- import java .util .regex .Pattern ;
1514import net .kyori .adventure .key .Key ;
1615import org .checkerframework .checker .nullness .qual .Nullable ;
1716
2120 */
2221public final class MinecraftChannelIdentifier implements ChannelIdentifier {
2322
24- private static final Pattern VALID_IDENTIFIER_REGEX = Pattern .compile ("[a-z0-9/\\ -_]*" );
25-
2623 private final String namespace ;
2724 private final String name ;
2825
@@ -39,7 +36,7 @@ private MinecraftChannelIdentifier(String namespace, String name) {
3936 * @return a new channel identifier
4037 */
4138 public static MinecraftChannelIdentifier forDefaultNamespace (String name ) {
42- return new MinecraftChannelIdentifier ("minecraft" , name );
39+ return new MinecraftChannelIdentifier (Key . MINECRAFT_NAMESPACE , name );
4340 }
4441
4542 /**
@@ -52,14 +49,10 @@ public static MinecraftChannelIdentifier forDefaultNamespace(String name) {
5249 public static MinecraftChannelIdentifier create (String namespace , String name ) {
5350 checkArgument (!Strings .isNullOrEmpty (namespace ), "namespace is null or empty" );
5451 checkArgument (name != null , "namespace is null or empty" );
55- checkArgument (VALID_IDENTIFIER_REGEX .matcher (namespace ).matches (),
56- "namespace is not valid, must match: %s got %s" ,
57- VALID_IDENTIFIER_REGEX .toString (),
58- namespace );
59- checkArgument (VALID_IDENTIFIER_REGEX .matcher (name ).matches (),
60- "name is not valid, must match: %s got %s" ,
61- VALID_IDENTIFIER_REGEX .toString (),
62- name );
52+ checkArgument (Key .parseableNamespace (namespace ),
53+ "namespace is not valid, must match: [a-z0-9_.-] got %s" , namespace );
54+ checkArgument (Key .parseableValue (name ),
55+ "name is not valid, must match: [a-z0-9/._-] got %s" , name );
6356 return new MinecraftChannelIdentifier (namespace , name );
6457 }
6558
@@ -72,10 +65,9 @@ public static MinecraftChannelIdentifier create(String namespace, String name) {
7265 public static MinecraftChannelIdentifier from (String identifier ) {
7366 int colonPos = identifier .indexOf (':' );
7467 if (colonPos == -1 ) {
75- throw new IllegalArgumentException ("Identifier does not contain a colon." );
76- }
77- if (colonPos + 1 == identifier .length ()) {
78- throw new IllegalArgumentException ("Identifier is empty." );
68+ return create (Key .MINECRAFT_NAMESPACE , identifier );
69+ } else if (colonPos == 0 ) {
70+ return create (Key .MINECRAFT_NAMESPACE , identifier .substring (1 ));
7971 }
8072 String namespace = identifier .substring (0 , colonPos );
8173 String name = identifier .substring (colonPos + 1 );
0 commit comments