mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Simplify server logic
This commit is contained in:
1 parent
eb4652d6ff
commit
c1b499f7b2
2 files changed
+20
-7
No files matched your search
@@ -467,14 +467,17 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<World> getWorlds() {
|
||||
return getServer().getWorlds().stream().filter(world -> BukkitAdapter.adaptWorld(world).isPresent()).map(world -> BukkitAdapter.adaptWorld(world).orElse(null)).collect(Collectors.toList());
|
||||
return getServer().getWorlds().stream()
|
||||
.filter(world -> BukkitAdapter.adaptWorld(world).isPresent())
|
||||
.map(world -> BukkitAdapter.adaptWorld(world).orElse(null))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
try {
|
||||
// Load settings
|
||||
this.settings = Annotaml.create(new File(getDataFolder(), "config.yml"), new Settings()).get();
|
||||
this.settings = Annotaml.create(new File(getDataFolder(), "config.yml"), Settings.class).get();
|
||||
|
||||
// Load locales from language preset default
|
||||
final Locales languagePresets = Annotaml.create(Locales.class, Objects.requireNonNull(getResource("locales/" + settings.language + ".yml"))).get();
|
||||
@@ -482,9 +485,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
||||
|
||||
// Load server from file
|
||||
if (settings.crossServer) {
|
||||
this.server = Annotaml.create(new File(getDataFolder(), "server.yml"), Server.DEFAULT).get();
|
||||
this.server = Annotaml.create(new File(getDataFolder(), "server.yml"), Server.class).get();
|
||||
} else {
|
||||
this.server = Server.DEFAULT;
|
||||
this.server = Server.getDefault();
|
||||
}
|
||||
|
||||
// Load spawn location from file
|
||||
|
||||
@@ -4,6 +4,8 @@ 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
|
||||
*/
|
||||
@@ -17,19 +19,27 @@ public class Server {
|
||||
/**
|
||||
* Default (unknown) server identifier
|
||||
*/
|
||||
public static final Server DEFAULT = new Server();
|
||||
public static Server getDefault() {
|
||||
final Server server = new Server();
|
||||
try {
|
||||
final Path serverDirectory = Path.of(System.getProperty("user.dir"));
|
||||
server.name = serverDirectory.getFileName().toString().trim();
|
||||
} catch (Exception e) {
|
||||
server.name = "server";
|
||||
}
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy-defined name of this server
|
||||
*/
|
||||
@YamlKey("server_name")
|
||||
public String name = "server";
|
||||
public String name = getDefault().name;
|
||||
|
||||
public Server(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Server() {
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user