mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-18 05:21:57 +01:00
Fix null and empty world name checking
This commit is contained in:
parent
b7d067123c
commit
30e8b93786
@ -4,6 +4,7 @@ import java.io.File;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import io.vavr.control.Option;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -45,13 +46,18 @@ public class WorldNameChecker {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public NameStatus checkName(@Nullable String worldName) {
|
public NameStatus checkName(@Nullable String worldName) {
|
||||||
if (BLACKLIST_NAMES.contains(worldName)) {
|
return Option.of(worldName).map(name -> {
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return NameStatus.EMPTY;
|
||||||
|
}
|
||||||
|
if (BLACKLIST_NAMES.contains(name)) {
|
||||||
return NameStatus.BLACKLISTED;
|
return NameStatus.BLACKLISTED;
|
||||||
}
|
}
|
||||||
if (worldName == null || !WORLD_NAME_PATTERN.matcher(worldName).matches()) {
|
if (!WORLD_NAME_PATTERN.matcher(name).matches()) {
|
||||||
return NameStatus.INVALID_CHARS;
|
return NameStatus.INVALID_CHARS;
|
||||||
}
|
}
|
||||||
return NameStatus.VALID;
|
return NameStatus.VALID;
|
||||||
|
}).getOrElse(NameStatus.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,6 +148,11 @@ public class WorldNameChecker {
|
|||||||
*/
|
*/
|
||||||
INVALID_CHARS,
|
INVALID_CHARS,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name string that is null or length 0.
|
||||||
|
*/
|
||||||
|
EMPTY,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name not valid as it is deemed blacklisted.
|
* Name not valid as it is deemed blacklisted.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user