Skip to main content

Overview

The Valid class provides methods for:
  • Validating objects and conditions
  • Type checking (integers, decimals, UUIDs)
  • Collection validation
  • Range validation
  • Equality comparisons
  • List matching operations
All check methods throw FoException on failure, which is automatically logged.

Null checks

checkNotNull

Throws an exception if the object is null.
object
Object
required
The object to check
message
String
Error message if null
Valid.checkNotNull(player);
Valid.checkNotNull(config, "Configuration cannot be null!");

checkNotEmpty

Throws an exception if collection or string is null or empty.
value
Collection|Map|String
required
The value to check
message
String
required
Error message if empty
Valid.checkNotEmpty(playerList, "Player list cannot be empty");
Valid.checkNotEmpty(command, "Command cannot be empty");
Valid.checkNotEmpty(settings, "Settings map is required");

Boolean checks

checkBoolean

Throws an exception if the expression is false.
expression
boolean
required
The condition to check
message
String
Error message if false
replacements
Object...
Format replacements for the message
Valid.checkBoolean(player.hasPermission("admin"), "No permission!");
Valid.checkBoolean(amount > 0, "Amount must be positive, got %s", amount);

Type validation

isInteger

Checks if a string is a valid integer.
value
String
required
The string to check
returns
boolean
True if the string is a valid integer
if (Valid.isInteger(args[0])) {
    int amount = Integer.parseInt(args[0]);
}

checkInteger

Throws exception if string is not a valid integer.
value
String
required
The string to check
message
String
required
Error message if invalid
Valid.checkInteger(input, "Expected a number, got: " + input);
int number = Integer.parseInt(input);

isDecimal

Checks if a string is a valid decimal number.
value
String
required
The string to check
returns
boolean
True if valid decimal
if (Valid.isDecimal("3.14")) {
    double pi = Double.parseDouble("3.14");
}

isNumber

Checks if string is a valid Java number (including hex, scientific notation, etc.).
value
String
required
The string to check
returns
boolean
True if valid number
boolean valid1 = Valid.isNumber("123");      // true
boolean valid2 = Valid.isNumber("3.14");     // true
boolean valid3 = Valid.isNumber("0xFF");     // true (hex)
boolean valid4 = Valid.isNumber("1.5e10");   // true (scientific)

isUUID

Checks if object is a valid UUID.
object
Object
required
The object to check
returns
boolean
True if valid UUID or UUID string
if (Valid.isUUID(args[0])) {
    UUID uuid = UUID.fromString(args[0]);
}

Empty checks

isNullOrEmpty

Checks if value is null or empty.
value
String|Collection|Object[]
required
The value to check
returns
boolean
True if null or empty
if (!Valid.isNullOrEmpty(playerName)) {
    // Process name
}

if (Valid.isNullOrEmpty(items)) {
    return; // No items to process
}

Range validation

isInRange

Checks if a value is within bounds (inclusive).
value
double|long
required
The value to check
min
double|long
required
Minimum value (inclusive)
max
double|long
required
Maximum value (inclusive)
returns
boolean
True if value is between min and max
int level = player.getLevel();
if (Valid.isInRange(level, 1, 100)) {
    // Valid level
}

double damage = 15.5;
Valid.checkBoolean(
    Valid.isInRange(damage, 0.0, 20.0),
    "Damage must be between 0 and 20"
);

isFinite

Checks if all vector coordinates are finite numbers.
vector
Vector
required
The vector to check
returns
boolean
True if all coordinates are finite
Vector velocity = entity.getVelocity();
if (Valid.isFinite(velocity)) {
    entity.setVelocity(velocity.multiply(2));
}

Equality checks

locationEquals

Compares two locations by world and block coordinates.
first
Location
required
First location
second
Location
required
Second location
returns
boolean
True if same world and block position
Location spawn = world.getSpawnLocation();
if (Valid.locationEquals(player.getLocation(), spawn)) {
    player.sendMessage("You are at spawn!");
}

listEquals

Compares two lists (strips colors from strings before comparison).
first
List<T>
required
First list
second
List<T>
required
Second list
returns
boolean
True if lists are equal
List<String> list1 = Arrays.asList("&aHello", "&bWorld");
List<String> list2 = Arrays.asList("&cHello", "&dWorld");

if (Valid.listEquals(list1, list2)) {
    // Content is the same (colors ignored)
}

colorlessEquals

Compares strings ignoring color codes.
first
String|List|String[]
required
First value
second
String|List|String[]
required
Second value
returns
boolean
True if equal after stripping colors
boolean same = Valid.colorlessEquals("&aHello", "&cHello");
// Returns: true

List<String> a = Arrays.asList("&aTest");
List<String> b = Arrays.asList("&bTest");
boolean listsEqual = Valid.colorlessEquals(a, b);
// Returns: true

List matching

isInList

Checks if element is in list (case-insensitive).
element
String
required
The element to find
list
Iterable<String>
required
The list to search
returns
boolean
True if found
List<String> commands = Arrays.asList("help", "info", "stats");
if (Valid.isInList(userInput, commands)) {
    // Valid command
}

isInListStartsWith

Checks if any list element starts with the given string.
element
String
required
The string to match
list
Iterable<String>
required
The list to search
List<String> prefixes = Arrays.asList("admin_", "mod_", "helper_");
if (Valid.isInListStartsWith("admin_Steve", prefixes)) {
    // Matches "admin_" prefix
}

isInListRegex

Checks if element matches any regex pattern in list.
element
String
required
The string to test
list
Iterable<String>
required
List of regex patterns
List<String> patterns = Arrays.asList(
    "player_.*",
    "mob_[0-9]+",
    "custom_.+"
);

if (Valid.isInListRegex("player_steve", patterns)) {
    // Matches "player_.*" pattern
}

isInListEnum

Checks if string matches any enum constant name.
element
String
required
The string to match
enumeration
Enum<?>[]
required
The enum constants
if (Valid.isInListEnum("DIAMOND", Material.values())) {
    Material mat = Material.valueOf("DIAMOND");
}

Thread validation

checkSync

Throws exception if not on main thread.
errorMessage
String
required
Error message if async
public void modifyBlock(Block block) {
    Valid.checkSync("Cannot modify blocks asynchronously!");
    block.setType(Material.AIR);
}

checkAsync

Throws exception if on main thread.
errorMessage
String
required
Error message if sync
public void queryDatabase() {
    Valid.checkAsync("Cannot query database on main thread!");
    // Database operations
}

Permission checks

checkPermission

Checks if sender has permission, sends message if not.
sender
CommandSender
required
The command sender
permission
String
required
The permission node
returns
boolean
True if has permission
if (!Valid.checkPermission(player, "myplugin.admin")) {
    return; // Message already sent
}

// Continue with admin action

Examples

Command argument validation

public void onCommand(CommandSender sender, String[] args) {
    Valid.checkBoolean(args.length >= 2, "Usage: /command <player> <amount>");
    
    String playerName = args[0];
    Valid.checkNotEmpty(playerName, "Player name cannot be empty");
    
    String amountStr = args[1];
    Valid.checkInteger(amountStr, "Amount must be a number: " + amountStr);
    
    int amount = Integer.parseInt(amountStr);
    Valid.checkBoolean(
        Valid.isInRange(amount, 1, 64),
        "Amount must be between 1 and 64"
    );
    
    Player target = Bukkit.getPlayer(playerName);
    Valid.checkNotNull(target, "Player not found: " + playerName);
    
    // Execute command
}

Configuration validation

public void loadConfig() {
    String message = config.getString("welcome-message");
    Valid.checkNotEmpty(message, "Welcome message is required!");
    
    int maxPlayers = config.getInt("max-players");
    Valid.checkBoolean(
        Valid.isInRange(maxPlayers, 1, 1000),
        "Max players must be between 1 and 1000, got: " + maxPlayers
    );
    
    List<String> commands = config.getStringList("startup-commands");
    Valid.checkNotEmpty(commands, "Startup commands list cannot be empty");
}

Safe null handling

public void teleportPlayer(Player player, Location location) {
    Valid.checkNotNull(player, "Player cannot be null");
    Valid.checkNotNull(location, "Location cannot be null");
    Valid.checkNotNull(location.getWorld(), "World cannot be null");
    Valid.checkBoolean(Valid.isFinite(location.toVector()), "Invalid coordinates");
    
    Valid.checkSync("Cannot teleport player asynchronously");
    player.teleport(location);
}

Build docs developers (and LLMs) love