Skip to content

Determining a Valid Region ID

Patrick Miller edited this page Jun 24, 2024 · 2 revisions

WorldGuard has restrictions on what can and can't be in a region name (also referred to as "region ID"). Currently, only the following characters may be in a region name:

  • Letters
  • Numbers
  • Underscores
  • Commas
  • Single Quotation Marks
  • Dashes
  • Pluses
  • Forward Slashes

That means characters like percentage signs, parentheses, and colons aren't valid.

What if you wanted to make a custom command that lets users create a new region? While you could give access to WorldGuard's built in command, you could have far greater control by using Skript. If a user is going to be naming a region, you'll want to provide an error message if the name they give isn't valid. You could just check against these requirements yourself, but what if they changed in the future? You'd have to make sure your script is always up to date.

While this probably isn't a situation many people are going to have, it's still useful to provide a utility for those that will. That's why skript-worldguard offers a condition to check if a string is a valid region name (or ID). The syntax for this condition is:

%strings% (is|are) [a] valid [worldguard] region id
%strings% (isn't|is not|aren't|are not) [a] valid [worldguard] region id

If you wanted to use this in a command, it could look something like:

command /createregion <text>:
  trigger:
    if arg-1 is not a valid region id:
      send "<red>Region IDs may only contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, forward slashes." to player

So, if the user entered an invalid region ID, they would get an error message telling them what characters are allowed in a region ID. Even if the characters allowed in a region ID changed in the future, only the message would be incorrect. The command would still prevent users from entering an invalid region ID.

If you were to enter an invalid region ID, here's what it would look like in-game:

image

Clone this wiki locally