mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 06:28:49 +00:00
Cut down jar size, adjust shadings, fix message formatting, adjust home pattern matching
This commit is contained in:
1 parent
ff2465ac85
commit
979d57e7b2
22 files changed
+160
-107
No files matched your search
@@ -1,8 +1,10 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.william278.huskhomes.position.PositionMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Provides a number of utility regular expressions for checking home name patterns
|
||||
@@ -20,9 +22,44 @@ public final class RegexUtil {
|
||||
public static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z\\d_\\-]+");
|
||||
|
||||
/**
|
||||
* Pattern for checking public home input fields
|
||||
* Pattern for checking home input fields disambiguated by the owner's name
|
||||
* <p>
|
||||
* e.g. {@code ownerName.homeName}
|
||||
*/
|
||||
public static final Pattern OWNER_NAME_PATTERN = Pattern.compile("\\w+\\.[A-Za-z\\d_\\-]+");
|
||||
private static final Pattern OWNER_DISAMBIGUATED_HOME_IDENTIFIER_PATTERN = Pattern.compile("\\w+\\.[A-Za-z\\d_\\-]+");
|
||||
|
||||
/**
|
||||
* Match pattern for checking home input fields disambiguated by the owner's name
|
||||
*
|
||||
* @param input input string to match
|
||||
* @return An optional containing the {@link DisambiguatedHomeIdentifier} if matched, otherwise empty if not
|
||||
*/
|
||||
public static Optional<DisambiguatedHomeIdentifier> matchDisambiguatedHomeIdentifier(@NotNull String input) {
|
||||
if (OWNER_DISAMBIGUATED_HOME_IDENTIFIER_PATTERN.matcher(input).matches()) {
|
||||
final String[] separatedInput = input.split(Pattern.quote("."));
|
||||
return Optional.of(new DisambiguatedHomeIdentifier(separatedInput[0], separatedInput[1]));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an identifier for a home or warp {@link PositionMeta} that is disambiguated by the owner's name
|
||||
*
|
||||
* @param ownerName the username of a home's owner
|
||||
* @param homeName the name of a home
|
||||
*/
|
||||
public record DisambiguatedHomeIdentifier(String ownerName, String homeName) {
|
||||
|
||||
|
||||
/**
|
||||
* Get the period-separated formatted disambiguated home identifier
|
||||
*
|
||||
* @return the formatted disambiguated home identifier (e.g. {@code ownerName.homeName})
|
||||
*/
|
||||
public String toString() {
|
||||
return ownerName + "." + homeName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user