mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Add more unit tests
This commit is contained in:
8 files changed
+368
-18
No files matched your search
@@ -55,7 +55,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
|
||||
warp.getMeta().setName(optionalName.get());
|
||||
plugin.fireEvent(plugin.getWarpEditEvent(warp, executor), (event) -> {
|
||||
try {
|
||||
plugin.getManager().warps().renameWarp(warp, warp.getName());
|
||||
plugin.getManager().warps().setWarpName(warp, warp.getName());
|
||||
} catch (ValidationException e) {
|
||||
e.dispatchWarpError(executor, plugin, warp.getName());
|
||||
return;
|
||||
|
||||
@@ -170,7 +170,7 @@ public abstract class Node implements Executable {
|
||||
}
|
||||
|
||||
|
||||
protected Optional<Teleportable> resolveTeleportable(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
protected Optional<Teleportable> resolveTeleporter(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
return parseStringArg(args, 0).map(Teleportable::username)
|
||||
.or(() -> executor instanceof Teleportable ? Optional.of((Teleportable) executor) : Optional.empty());
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SpawnCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<Teleportable> optionalTeleporter = resolveTeleportable(executor, args);
|
||||
final Optional<Teleportable> optionalTeleporter = resolveTeleporter(executor, args);
|
||||
if (optionalTeleporter.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", getUsage())
|
||||
.ifPresent(executor::sendMessage);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
|
||||
}
|
||||
}
|
||||
|
||||
final Optional<Teleportable> optionalTeleporter = resolveTeleportable(executor, args);
|
||||
final Optional<Teleportable> optionalTeleporter = resolveTeleporter(executor, args);
|
||||
if (optionalTeleporter.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", getUsage())
|
||||
.ifPresent(executor::sendMessage);
|
||||
|
||||
@@ -35,10 +35,12 @@ public class Manager {
|
||||
|
||||
// Update caches on all servers
|
||||
protected void propagateCacheUpdate() {
|
||||
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
|
||||
.type(Message.Type.UPDATE_CACHES)
|
||||
.scope(Message.Scope.SERVER)
|
||||
.target(Message.TARGET_ALL)
|
||||
.build().send(plugin.getMessenger(), user));
|
||||
if (plugin.getSettings().isCrossServer()) {
|
||||
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
|
||||
.type(Message.Type.UPDATE_CACHES)
|
||||
.scope(Message.Scope.SERVER)
|
||||
.target(Message.TARGET_ALL)
|
||||
.build().send(plugin.getMessenger(), user));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,16 +137,16 @@ public class WarpsManager {
|
||||
this.cacheWarp(warp, true);
|
||||
}
|
||||
|
||||
public void renameWarp(@NotNull String name, @NotNull String newName) throws ValidationException {
|
||||
public void setWarpName(@NotNull String name, @NotNull String newName) throws ValidationException {
|
||||
final Optional<Warp> optionalWarp = plugin.getDatabase().getWarp(name);
|
||||
if (optionalWarp.isEmpty()) {
|
||||
throw new ValidationException(ValidationException.Type.NOT_FOUND);
|
||||
}
|
||||
|
||||
this.renameWarp(optionalWarp.get(), newName);
|
||||
this.setWarpName(optionalWarp.get(), newName);
|
||||
}
|
||||
|
||||
public void renameWarp(@NotNull Warp warp, @NotNull String newName) throws ValidationException {
|
||||
public void setWarpName(@NotNull Warp warp, @NotNull String newName) throws ValidationException {
|
||||
if (!plugin.getValidator().isValidName(newName)) {
|
||||
throw new ValidationException(ValidationException.Type.NAME_INVALID);
|
||||
}
|
||||
|
||||
@@ -31,17 +31,17 @@ public class Validator {
|
||||
/**
|
||||
* Validate home and warp descriptions
|
||||
*
|
||||
* @param meta The meta to validate
|
||||
* @param description 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;
|
||||
public boolean isValidDescription(@NotNull String description) {
|
||||
return (isAsciiOnly(description) || plugin.getSettings().isAllowUnicodeDescriptions())
|
||||
&& description.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");
|
||||
return string.matches("\\A\\p{ASCII}*\\z") && !string.contains("\u0000");
|
||||
}
|
||||
|
||||
// Check if a string contains whitespace
|
||||
|
||||
Reference in new issue
Block a user