mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Add checks for unicode in home/description names if enabled
This commit is contained in:
1 parent
e90fc481a9
commit
1c6902fc9e
8 files changed
+36
-19
No files matched your search
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Cross-platform manager for validating homes and warps and updating them as neccessary
|
||||
@@ -25,9 +26,22 @@ public class SavedPositionManager {
|
||||
*/
|
||||
private final Cache cache;
|
||||
|
||||
public SavedPositionManager(@NotNull Database database, @NotNull Cache cache) {
|
||||
/**
|
||||
* Whether to allow unicode characters in SavedPosition names
|
||||
*/
|
||||
private final boolean allowUnicodeNames;
|
||||
|
||||
/**
|
||||
* Whether to allow unicode characters in SavedPosition descriptions
|
||||
*/
|
||||
private final boolean allowUnicodeDescriptions;
|
||||
|
||||
public SavedPositionManager(@NotNull Database database, @NotNull Cache cache,
|
||||
boolean allowUnicodeNames, boolean allowUnicodeDescriptions) {
|
||||
this.database = database;
|
||||
this.cache = cache;
|
||||
this.allowUnicodeNames = allowUnicodeNames;
|
||||
this.allowUnicodeDescriptions = allowUnicodeDescriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,18 +350,21 @@ public class SavedPositionManager {
|
||||
* identifying which constraint is violated by the metadata
|
||||
*/
|
||||
private Optional<SaveResult.ResultType> validateMeta(@NotNull PositionMeta positionMeta) {
|
||||
//todo options for allowing unicode names / descriptions
|
||||
if (positionMeta.name.length() > 16) {
|
||||
return Optional.of(SaveResult.ResultType.FAILED_NAME_LENGTH);
|
||||
}
|
||||
if (!RegexUtil.NAME_PATTERN.matcher(positionMeta.name).matches()) {
|
||||
return Optional.of(SaveResult.ResultType.FAILED_NAME_CHARACTERS);
|
||||
if (!allowUnicodeNames || positionMeta.name.contains(Pattern.quote("."))) {
|
||||
if (!RegexUtil.NAME_PATTERN.matcher(positionMeta.name).matches()) {
|
||||
return Optional.of(SaveResult.ResultType.FAILED_NAME_CHARACTERS);
|
||||
}
|
||||
}
|
||||
if (positionMeta.description.length() > 255) {
|
||||
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_LENGTH);
|
||||
}
|
||||
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(positionMeta.name).matches()) {
|
||||
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_CHARACTERS);
|
||||
if (!allowUnicodeDescriptions) {
|
||||
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(positionMeta.description).matches()) {
|
||||
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_CHARACTERS);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user