4040import java .util .Objects ;
4141import java .util .UUID ;
4242import java .util .concurrent .atomic .AtomicReference ;
43+ import java .util .regex .Pattern ;
4344
4445/**
4546 * Handles {@code /realty create leasehold <name> <price> <period> <maxextensions>}
@@ -54,6 +55,7 @@ public record CreateCommand(@NotNull RealtyPaperApi api,
5455 @ NotNull MessageContainer messages ) implements CustomCommandBean {
5556
5657 private static final CloudKey <String > NAME = CloudKey .of ("name" , String .class );
58+ private static final Pattern VALID_NAME_PATTERN = Pattern .compile ("^[A-Za-z0-9]+$" );
5759 private static final CloudKey <Double > PRICE = CloudKey .of ("price" , Double .class );
5860 private static final CloudKey <Duration > PERIOD = CloudKey .of ("period" , Duration .class );
5961 private static final CloudKey <Integer > MAX_EXTENSIONS = CloudKey .of ("maxextensions" , Integer .class );
@@ -110,6 +112,11 @@ private void executeLeasehold(@NotNull CommandContext<Source> ctx) {
110112 return ;
111113 }
112114 String name = ctx .get (NAME );
115+ if (!VALID_NAME_PATTERN .matcher (name ).matches ()) {
116+ player .sendMessage (messages .messageFor (MessageKeys .CREATE_INVALID_NAME ,
117+ Placeholder .unparsed ("region" , name )));
118+ return ;
119+ }
113120 double price = ctx .get (PRICE );
114121 Duration period = ctx .get (PERIOD );
115122 int maxExtensions = ctx .get (MAX_EXTENSIONS );
@@ -168,6 +175,11 @@ private void executeFreehold(@NotNull CommandContext<Source> ctx) {
168175 return ;
169176 }
170177 String name = ctx .get (NAME );
178+ if (!VALID_NAME_PATTERN .matcher (name ).matches ()) {
179+ player .sendMessage (messages .messageFor (MessageKeys .CREATE_INVALID_NAME ,
180+ Placeholder .unparsed ("region" , name )));
181+ return ;
182+ }
171183 Double price = ctx .flags ().getValue (PRICE_FLAG , null );
172184 UUID authority = ctx .flags ()
173185 .getValue (AUTHORITY_FLAG , settings .get ().defaultFreeholdAuthority ());
0 commit comments