From c61b0a21b8da46bf1bc5a5d55ec73fa7dd2de163 Mon Sep 17 00:00:00 2001 From: William Date: Tue, 5 Nov 2024 22:29:15 +0000 Subject: [PATCH] feat: default server.yml value to server dir name --- .../william278/huskhomes/config/Server.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/huskhomes/config/Server.java b/common/src/main/java/net/william278/huskhomes/config/Server.java index 79dbd375..92132423 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Server.java +++ b/common/src/main/java/net/william278/huskhomes/config/Server.java @@ -26,6 +26,8 @@ import lombok.NoArgsConstructor; import org.jetbrains.annotations.NotNull; +import java.nio.file.Path; + @Getter @Configuration @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -41,11 +43,29 @@ public class Server { ┣╸ If you join it using /server alpha, then set it to 'alpha' (case-sensitive) ┗╸ You only need to touch this if you're using cross-server mode."""; - private String name = "server"; + private String name = getDefault(); @NotNull public static Server of(@NotNull String name) { return new Server(name); } + /** + * Find a sensible default name for the server name property + */ + @NotNull + private static String getDefault() { + final String serverFolder = System.getProperty("user.dir"); + return serverFolder == null ? "server" : Path.of(serverFolder).getFileName().toString().trim(); + } + + @Override + public boolean equals(@NotNull Object other) { + // If the name of this server matches another, the servers are the same. + if (other instanceof Server server) { + return server.getName().equalsIgnoreCase(this.getName()); + } + return super.equals(other); + } + } \ No newline at end of file