mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Further refactoring, move away from using future thread pool
This commit is contained in:
1 parent
4c90e5498c
commit
39e0b25d46
56 files changed
+737
-1713
No files matched your search
@@ -1,65 +0,0 @@
|
||||
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
|
||||
*/
|
||||
public final class RegexUtil {
|
||||
|
||||
/**
|
||||
* Pattern for checking home and warp {@link PositionMeta} description fields
|
||||
*/
|
||||
public static final Pattern DESCRIPTION_PATTERN = Pattern.compile("[a-zA-Z\\d\\-_\\s]*");
|
||||
|
||||
/**
|
||||
* Pattern for checking home and warp {@link PositionMeta} name fields
|
||||
*/
|
||||
public static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z\\d_\\-]+");
|
||||
|
||||
/**
|
||||
* Pattern for checking home input fields disambiguated by the owner's name
|
||||
* <p>
|
||||
* e.g. {@code ownerName.homeName}
|
||||
*/
|
||||
private static final Pattern OWNER_DISAMBIGUATED_HOME_IDENTIFIER_PATTERN = Pattern.compile("\\w+\\.[^.]{1,16}$");
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,9 +7,11 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface TaskRunner {
|
||||
void runAsync(@NotNull Runnable runnable);
|
||||
int runAsync(@NotNull Runnable runnable);
|
||||
<T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier);
|
||||
void runSync(@NotNull Runnable runnable);
|
||||
int runSync(@NotNull Runnable runnable);
|
||||
int runAsyncRepeating(@NotNull Runnable runnable, long delay);
|
||||
void cancelTask(int taskId);
|
||||
@NotNull
|
||||
HuskHomes getPlugin();
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ValidationException extends IllegalArgumentException {
|
||||
|
||||
public ValidationException(@NotNull ValidationException.Type error) {
|
||||
super("Error validating position: " + error.name());
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
NOT_FOUND,
|
||||
NAME_TAKEN,
|
||||
NAME_INVALID,
|
||||
DESCRIPTION_INVALID
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.william278.huskhomes.util;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public class Validator {
|
||||
|
||||
public static final int MAX_NAME_LENGTH = 16;
|
||||
|
||||
Reference in new issue
Block a user