mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
feat: add ability to customise the home delimiter
This commit is contained in:
7 files changed
+33
-16
No files matched your search
@@ -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<String> 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();
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
|
||||
public abstract void execute(@NotNull CommandUser executor, @NotNull T position, @NotNull String[] arguments);
|
||||
|
||||
private Optional<Home> 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<T extends SavedPosition> extends Comm
|
||||
}
|
||||
|
||||
private Optional<Home> 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<T extends SavedPosition> extends Comm
|
||||
private List<String> 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();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -127,6 +127,10 @@ public final class Settings {
|
||||
+ "Override with the huskhomes.max_public_homes.<number> 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.<number>) should stack "
|
||||
+ "if the user inherits multiple nodes.")
|
||||
private boolean stackPermissionLimits = false;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user