Skip to content

Commit

Permalink
feat: default server.yml value to server dir name
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Nov 5, 2024
1 parent bece27a commit c61b0a2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion common/src/main/java/net/william278/huskhomes/config/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;

@Getter
@Configuration
@NoArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -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);
}

}

0 comments on commit c61b0a2

Please sign in to comment.