Now uses _ for space, and \_ for underscore in descriptions

This commit is contained in:
2022-08-05 12:41:25 +02:00
parent c9d0907b2f
commit fee287f884
2 changed files with 21 additions and 5 deletions

View File

@ -57,7 +57,7 @@ public class CreateCommand implements CommandExecutor {
*/
private PermissionSign parseSign(@NotNull CommandSender sender, @NotNull String[] args) {
String name = args[0];
String description = args[1].replaceAll("\\\\_", " ");
String description = replaceUnderscoresWithSpaces(args[1]);
String[] permissions = args[2].replaceAll("\\?", " ").split(",");
for (String permission : permissions) {
if (permission.contains(":")) {
@ -93,4 +93,20 @@ public class CreateCommand implements CommandExecutor {
return new PermissionSign(name, description, List.of(permissions), duration, cost);
}
/**
* Replaces underscores with spaces in the given description
*
* <p>This basically replaces all underscores with spaces, but keeps escaped underscores (\_) as underscores.</p>
*
* @param description <p>The description to replace underscores in</p>
* @return <p>The string with underscores replaced</p>
*/
private String replaceUnderscoresWithSpaces(String description) {
String temporaryString = "\\|ESCAPED-UNDERSCORE\\|";
description = description.replaceAll("\\\\_", temporaryString);
description = description.replaceAll("_", " ");
description = description.replaceAll(temporaryString, "_");
return description;
}
}