diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java index e016bfc9..12edc13a 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java @@ -40,8 +40,8 @@ public class PublicHomeCommand extends HomeCommand implements TabCompletable { public void execute(@NotNull CommandUser executor, @NotNull String[] args) { // Display the public home list if no arguments are provided if (args.length == 0) { - plugin.getCommand(PublicHomeListCommand.class) - .ifPresent(command -> command.showPublicHomeList(executor, null, 1)); + plugin.getCommand(PublicHomeListCommand.class).ifPresent(cmd -> cmd + .showPublicHomeList(executor, null, 1)); return; } super.execute(executor, args); @@ -51,7 +51,7 @@ public class PublicHomeCommand extends HomeCommand implements TabCompletable { @NotNull public List suggest(@NotNull CommandUser executor, @NotNull String[] args) { if (args.length <= 2) { - if (args.length >= 1 && args[0].contains(Home.IDENTIFIER_DELIMITER)) { + if (args.length >= 1 && args[0].contains(Home.getDelimiter())) { return plugin.getManager().homes().getPublicHomeIdentifierNames(); } return plugin.getManager().homes().getPublicHomeNames(); diff --git a/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java b/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java index d8a66c91..30f85f5e 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java @@ -77,7 +77,7 @@ public abstract class SavedPositionCommand extends Comm public abstract void execute(@NotNull CommandUser executor, @NotNull T position, @NotNull String[] arguments); private Optional resolveHome(@NotNull CommandUser executor, @NotNull String homeName) { - if (homeName.contains(Home.IDENTIFIER_DELIMITER)) { + if (homeName.contains(Home.getDelimiter())) { return resolveDelimitedHome(executor, homeName); } else if (positionType == PositionCommandType.PUBLIC_HOME) { return resolvePublicHome(executor, homeName); @@ -90,8 +90,8 @@ public abstract class SavedPositionCommand extends Comm } private Optional resolveDelimitedHome(@NotNull CommandUser executor, @NotNull String homeName) { - final String ownerUsername = homeName.substring(0, homeName.indexOf(Home.IDENTIFIER_DELIMITER)); - final String ownerHome = homeName.substring(homeName.indexOf(Home.IDENTIFIER_DELIMITER) + 1); + final String ownerUsername = homeName.substring(0, homeName.indexOf(Home.getDelimiter())); + final String ownerHome = homeName.substring(homeName.indexOf(Home.getDelimiter()) + 1); if (ownerUsername.isBlank() || ownerHome.isBlank()) { plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) .ifPresent(executor::sendMessage); @@ -238,7 +238,7 @@ public abstract class SavedPositionCommand extends Comm private List suggestHome(@NotNull CommandUser executor, @NotNull String[] args) { return switch (args.length) { case 0, 1 -> { - if (args.length == 1 && args[0].contains(Home.IDENTIFIER_DELIMITER) + if (args.length == 1 && args[0].contains(Home.getDelimiter()) && executor.hasPermission(getOtherPermission())) { yield plugin.getManager().homes().getUserHomeIdentifiers(); } diff --git a/common/src/main/java/net/william278/huskhomes/config/ConfigProvider.java b/common/src/main/java/net/william278/huskhomes/config/ConfigProvider.java index a2cf8663..365761de 100644 --- a/common/src/main/java/net/william278/huskhomes/config/ConfigProvider.java +++ b/common/src/main/java/net/william278/huskhomes/config/ConfigProvider.java @@ -21,6 +21,7 @@ package net.william278.huskhomes.config; import de.exlll.configlib.*; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.position.Home; import net.william278.huskhomes.position.Location; import net.william278.huskhomes.util.UnsafeBlocks; import org.jetbrains.annotations.NotNull; @@ -71,6 +72,7 @@ public interface ConfigProvider { Settings.class, YAML_CONFIGURATION_PROPERTIES.header(Settings.CONFIG_HEADER).build() )); + Home.setDelimiter(getSettings().getGeneral().getHomeDelimiter()); } /** diff --git a/common/src/main/java/net/william278/huskhomes/config/Settings.java b/common/src/main/java/net/william278/huskhomes/config/Settings.java index 2ecca1df..5ec7537d 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Settings.java +++ b/common/src/main/java/net/william278/huskhomes/config/Settings.java @@ -127,6 +127,10 @@ public final class Settings { + "Override with the huskhomes.max_public_homes. permission.") private int maxPublicHomes = 10; + @Comment({"What character to use between owner usernames and home names when specifying a home or public home.", + "(e.g. the '.' in: /phome username.home_name). Change if you're using '.' as the Bedrock user prefix."}) + private String homeDelimiter = "."; + @Comment("Whether permission limits (i.e. huskhomes.max_homes.) should stack " + "if the user inherits multiple nodes.") private boolean stackPermissionLimits = false; diff --git a/common/src/main/java/net/william278/huskhomes/position/Home.java b/common/src/main/java/net/william278/huskhomes/position/Home.java index d6e8ff43..47568ecf 100644 --- a/common/src/main/java/net/william278/huskhomes/position/Home.java +++ b/common/src/main/java/net/william278/huskhomes/position/Home.java @@ -20,6 +20,7 @@ package net.william278.huskhomes.position; import net.william278.huskhomes.user.User; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -29,10 +30,9 @@ import java.util.UUID; */ public class Home extends SavedPosition { - /** - * The delimiter used to separate the owner's name from the home name in the home identifier. - */ - public static final String IDENTIFIER_DELIMITER = "."; + // The delimiter used to separate the owner's name from the home name in the home identifier. + private static String delimiter = "."; + private final User owner; private boolean isPublic; @@ -49,6 +49,17 @@ public class Home extends SavedPosition { this.setPublic(false); } + @ApiStatus.Internal + public static void setDelimiter(@NotNull String delimiter) { + Home.delimiter = delimiter; + } + + @NotNull + @ApiStatus.Internal + public static String getDelimiter() { + return delimiter; + } + /** * Creates a new {@link Home} from a series of coordinates, a viewing angle, a {@link World}, a server name, a * {@link PositionMeta}, a {@link UUID}, a {@link User} and a boolean representing whether the home is public. @@ -134,7 +145,7 @@ public class Home extends SavedPosition { @NotNull @Override public String getSafeIdentifier() { - return getOwner().getName() + IDENTIFIER_DELIMITER + super.getSafeIdentifier(); + return getOwner().getName() + getDelimiter() + super.getSafeIdentifier(); } /** @@ -148,7 +159,7 @@ public class Home extends SavedPosition { @NotNull @Override public String getIdentifier() { - return getOwner().getName() + IDENTIFIER_DELIMITER + super.getIdentifier(); + return getOwner().getName() + getDelimiter() + super.getIdentifier(); } } diff --git a/common/src/main/java/net/william278/huskhomes/util/TextValidator.java b/common/src/main/java/net/william278/huskhomes/util/TextValidator.java index e3871dde..e9f2108a 100644 --- a/common/src/main/java/net/william278/huskhomes/util/TextValidator.java +++ b/common/src/main/java/net/william278/huskhomes/util/TextValidator.java @@ -55,7 +55,7 @@ public interface TextValidator { return (name.matches(config.getRegex()) || !config.isRestrict()) && !name.contains("\u0000") && !containsWhitespace(name) - && !name.contains(Home.IDENTIFIER_DELIMITER); + && !name.contains(Home.getDelimiter()); } // Check a home/warp name is of a valid length diff --git a/common/src/test/java/net/william278/huskhomes/position/SavedPositionTests.java b/common/src/test/java/net/william278/huskhomes/position/SavedPositionTests.java index 70007464..ca2a4ca8 100644 --- a/common/src/test/java/net/william278/huskhomes/position/SavedPositionTests.java +++ b/common/src/test/java/net/william278/huskhomes/position/SavedPositionTests.java @@ -53,12 +53,12 @@ public class SavedPositionTests { public void testHomeIdentifiers(@NotNull Home home, @NotNull String name, boolean isUnsafeName) { Assertions.assertEquals( home.getIdentifier(), - home.getOwner().getName() + Home.IDENTIFIER_DELIMITER + home.getName() + home.getOwner().getName() + Home.getDelimiter() + home.getName() ); Assertions.assertEquals( home.getSafeIdentifier(), isUnsafeName - ? home.getOwner().getName() + Home.IDENTIFIER_DELIMITER + home.getUuid() + ? home.getOwner().getName() + Home.getDelimiter() + home.getUuid() : home.getIdentifier() ); }