mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +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
@@ -144,7 +144,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
this.requestManager = new RequestManager(this);
|
this.requestManager = new RequestManager(this);
|
||||||
|
|
||||||
// Prepare the home and warp position manager
|
// Prepare the home and warp position manager
|
||||||
this.savedPositionManager = new SavedPositionManager(database, cache);
|
this.savedPositionManager = new SavedPositionManager(database, cache,
|
||||||
|
settings.allowUnicodeNames, settings.allowUnicodeDescriptions);
|
||||||
|
|
||||||
// Initialize the RTP engine with the default normal distribution engine
|
// Initialize the RTP engine with the default normal distribution engine
|
||||||
this.rtpEngine = new NormalDistributionEngine(this);
|
this.rtpEngine = new NormalDistributionEngine(this);
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
final String warpName = args[0];
|
final String warpName = args[0];
|
||||||
plugin.getSavedPositionManager().deleteWarp(warpName).thenAccept(deleted -> {
|
plugin.getSavedPositionManager().deleteWarp(warpName).thenAccept(deleted -> {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
plugin.getLocales().getLocale("warp_deleted").ifPresent(onlineUser::sendMessage);
|
plugin.getLocales().getLocale("warp_deleted", warpName)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
} else {
|
} else {
|
||||||
plugin.getLocales().getLocale("error_warp_invalid", warpName).ifPresent(onlineUser::sendMessage);
|
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken");
|
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken");
|
||||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_home_name_length");
|
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_home_name_length");
|
||||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_home_name_characters");
|
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_home_name_characters");
|
||||||
default -> Optional.of(new MineDown(""));
|
default -> plugin.getLocales().getLocale("error_home_description_characters");
|
||||||
}).ifPresent(editor::sendMessage));
|
}).ifPresent(editor::sendMessage));
|
||||||
}
|
}
|
||||||
case "description" -> {
|
case "description" -> {
|
||||||
@@ -161,7 +161,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
plugin.getLocales().getLocale("error_home_description_length");
|
plugin.getLocales().getLocale("error_home_description_length");
|
||||||
case FAILED_DESCRIPTION_CHARACTERS ->
|
case FAILED_DESCRIPTION_CHARACTERS ->
|
||||||
plugin.getLocales().getLocale("error_home_description_characters");
|
plugin.getLocales().getLocale("error_home_description_characters");
|
||||||
default -> Optional.of(new MineDown(""));
|
default -> plugin.getLocales().getLocale("error_home_name_characters");
|
||||||
}).ifPresent(editor::sendMessage));
|
}).ifPresent(editor::sendMessage));
|
||||||
}
|
}
|
||||||
case "relocate" ->
|
case "relocate" ->
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class EditWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken");
|
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken");
|
||||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
||||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
||||||
default -> Optional.of(new MineDown(""));
|
default -> plugin.getLocales().getLocale("error_warp_description_characters");
|
||||||
}).ifPresent(editor::sendMessage));
|
}).ifPresent(editor::sendMessage));
|
||||||
}
|
}
|
||||||
case "description" -> {
|
case "description" -> {
|
||||||
@@ -111,7 +111,7 @@ public class EditWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
plugin.getLocales().getLocale("error_warp_description_length");
|
plugin.getLocales().getLocale("error_warp_description_length");
|
||||||
case FAILED_DESCRIPTION_CHARACTERS ->
|
case FAILED_DESCRIPTION_CHARACTERS ->
|
||||||
plugin.getLocales().getLocale("error_warp_description_characters");
|
plugin.getLocales().getLocale("error_warp_description_characters");
|
||||||
default -> Optional.of(new MineDown(""));
|
default -> plugin.getLocales().getLocale("error_warp_name_characters");
|
||||||
}).ifPresent(editor::sendMessage));
|
}).ifPresent(editor::sendMessage));
|
||||||
}
|
}
|
||||||
case "relocate" ->
|
case "relocate" ->
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class SetHomeCommand extends CommandBase {
|
|||||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken");
|
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken");
|
||||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_home_name_length");
|
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_home_name_length");
|
||||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_home_name_characters");
|
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_home_name_characters");
|
||||||
default -> Optional.of(new MineDown(""));
|
default -> plugin.getLocales().getLocale("error_home_description_characters");
|
||||||
}).ifPresent(onlineUser::sendMessage);
|
}).ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package net.william278.huskhomes.command;
|
package net.william278.huskhomes.command;
|
||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.position.PositionMeta;
|
import net.william278.huskhomes.position.PositionMeta;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class SetWarpCommand extends CommandBase {
|
public class SetWarpCommand extends CommandBase {
|
||||||
|
|
||||||
protected SetWarpCommand(@NotNull HuskHomes implementor) {
|
protected SetWarpCommand(@NotNull HuskHomes implementor) {
|
||||||
@@ -37,7 +34,7 @@ public class SetWarpCommand extends CommandBase {
|
|||||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken");
|
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken");
|
||||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
||||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
||||||
default -> Optional.of(new MineDown(""));
|
default -> plugin.getLocales().getLocale("error_warp_description_characters");
|
||||||
}).ifPresent(onlineUser::sendMessage));
|
}).ifPresent(onlineUser::sendMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cross-platform manager for validating homes and warps and updating them as neccessary
|
* Cross-platform manager for validating homes and warps and updating them as neccessary
|
||||||
@@ -25,9 +26,22 @@ public class SavedPositionManager {
|
|||||||
*/
|
*/
|
||||||
private final Cache cache;
|
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.database = database;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
|
this.allowUnicodeNames = allowUnicodeNames;
|
||||||
|
this.allowUnicodeDescriptions = allowUnicodeDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,18 +350,21 @@ public class SavedPositionManager {
|
|||||||
* identifying which constraint is violated by the metadata
|
* identifying which constraint is violated by the metadata
|
||||||
*/
|
*/
|
||||||
private Optional<SaveResult.ResultType> validateMeta(@NotNull PositionMeta positionMeta) {
|
private Optional<SaveResult.ResultType> validateMeta(@NotNull PositionMeta positionMeta) {
|
||||||
//todo options for allowing unicode names / descriptions
|
|
||||||
if (positionMeta.name.length() > 16) {
|
if (positionMeta.name.length() > 16) {
|
||||||
return Optional.of(SaveResult.ResultType.FAILED_NAME_LENGTH);
|
return Optional.of(SaveResult.ResultType.FAILED_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.NAME_PATTERN.matcher(positionMeta.name).matches()) {
|
if (!allowUnicodeNames || positionMeta.name.contains(Pattern.quote("."))) {
|
||||||
return Optional.of(SaveResult.ResultType.FAILED_NAME_CHARACTERS);
|
if (!RegexUtil.NAME_PATTERN.matcher(positionMeta.name).matches()) {
|
||||||
|
return Optional.of(SaveResult.ResultType.FAILED_NAME_CHARACTERS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (positionMeta.description.length() > 255) {
|
if (positionMeta.description.length() > 255) {
|
||||||
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_LENGTH);
|
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_LENGTH);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(positionMeta.name).matches()) {
|
if (!allowUnicodeDescriptions) {
|
||||||
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_CHARACTERS);
|
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(positionMeta.description).matches()) {
|
||||||
|
return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_CHARACTERS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public final class RegexUtil {
|
|||||||
/**
|
/**
|
||||||
* Pattern for checking home and warp {@link PositionMeta} description fields
|
* Pattern for checking home and warp {@link PositionMeta} description fields
|
||||||
*/
|
*/
|
||||||
public static final Pattern DESCRIPTION_PATTERN = Pattern.compile("[a-zA-Z\\d\\-_\\s]+");
|
public static final Pattern DESCRIPTION_PATTERN = Pattern.compile("[a-zA-Z\\d\\-_\\s]*");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pattern for checking home and warp {@link PositionMeta} name fields
|
* Pattern for checking home and warp {@link PositionMeta} name fields
|
||||||
|
|||||||
Reference in new issue
Block a user