mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 06:28:49 +00:00
Start refactor work
This commit is contained in:
1 parent
6a8851a446
commit
3e1ec09487
51 files changed
+2397
-2474
No files matched your search
@@ -0,0 +1,16 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface TaskRunner {
|
||||
void runAsync(@NotNull Runnable runnable);
|
||||
<T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier);
|
||||
void runSync(@NotNull Runnable runnable);
|
||||
@NotNull
|
||||
HuskHomes getPlugin();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Validator {
|
||||
|
||||
public static final int MAX_NAME_LENGTH = 16;
|
||||
public static final int MIN_NAME_LENGTH = 1;
|
||||
public static final int MAX_DESCRIPTION_LENGTH = 256;
|
||||
|
||||
private final HuskHomes plugin;
|
||||
|
||||
public Validator(@NotNull HuskHomes plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a name is valid
|
||||
*
|
||||
* @param name The name to check
|
||||
* @return True if the name is valid as per the plugin settings, false otherwise
|
||||
*/
|
||||
public boolean isValidName(@NotNull String name) {
|
||||
return (isAsciiOnly(name) || plugin.getSettings().isAllowUnicodeNames())
|
||||
&& !containsWhitespace(name)
|
||||
&& name.length() <= MAX_NAME_LENGTH && name.length() >= MIN_NAME_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate home and warp descriptions
|
||||
*
|
||||
* @param meta The meta to validate
|
||||
* @return Whether the meta is valid against the plugin settings
|
||||
*/
|
||||
public boolean isValidDescription(@NotNull String meta) {
|
||||
return (isAsciiOnly(meta) || plugin.getSettings().isAllowUnicodeDescriptions())
|
||||
&& meta.length() <= MAX_DESCRIPTION_LENGTH;
|
||||
}
|
||||
|
||||
// Check if a string contains only ASCII characters
|
||||
private static boolean isAsciiOnly(@NotNull String string) {
|
||||
return string.matches("\\A\\p{ASCII}*\\z");
|
||||
}
|
||||
|
||||
// Check if a string contains whitespace
|
||||
private static boolean containsWhitespace(@NotNull String string) {
|
||||
return string.matches(".*\\s.*");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user