mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
* Remove instance getters, improve command logic, register APi * Publish multiple fabric builds, enforce checkstyle * Bump guava * Bump to 4.4.2
83 lines
2.6 KiB
Java
83 lines
2.6 KiB
Java
/*
|
|
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
|
*
|
|
* Copyright (c) William278 <[email protected]>
|
|
* Copyright (c) contributors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package net.william278.huskhomes.config;
|
|
|
|
import net.william278.annotaml.YamlFile;
|
|
import net.william278.annotaml.YamlKey;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
/**
|
|
* Represents a server on a proxied network.
|
|
*/
|
|
@YamlFile(header = """
|
|
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
┃ HuskHomes Server ID config ┃
|
|
┃ Developed by William278 ┃
|
|
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
┣╸ This file should contain the ID of this server as defined in your proxy config.
|
|
┣╸ 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.""")
|
|
public class Server {
|
|
|
|
/**
|
|
* Default server identifier.
|
|
*/
|
|
@NotNull
|
|
public static String getDefaultServerName() {
|
|
try {
|
|
final Path serverDirectory = Path.of(System.getProperty("user.dir"));
|
|
return serverDirectory.getFileName().toString().trim();
|
|
} catch (Exception e) {
|
|
return "server";
|
|
}
|
|
}
|
|
|
|
@YamlKey("name")
|
|
private String serverName = getDefaultServerName();
|
|
|
|
public Server(@NotNull String serverName) {
|
|
this.serverName = serverName;
|
|
}
|
|
|
|
@SuppressWarnings("unused")
|
|
private Server() {
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
/**
|
|
* Proxy-defined name of this server.
|
|
*/
|
|
@NotNull
|
|
public String getName() {
|
|
return serverName;
|
|
}
|
|
|
|
}
|