forked from git-mirrors/GeyserConnect
Update for latest Geyser changes
This commit is contained in:
parent
d8ce39636b
commit
79ce0a146d
2 changed files with 31 additions and 2 deletions
|
@ -42,11 +42,14 @@ import org.geysermc.geyser.network.MinecraftProtocol;
|
||||||
import org.geysermc.geyser.util.FileUtils;
|
import org.geysermc.geyser.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MasterServer {
|
public class MasterServer {
|
||||||
|
@ -86,7 +89,7 @@ public class MasterServer {
|
||||||
logger = new Logger();
|
logger = new Logger();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File configFile = FileUtils.fileOrCopiedFromResource(new File("config.yml"), "config.yml", (x) -> x);
|
File configFile = fileOrCopiedFromResource(new File("config.yml"), "config.yml", (x) -> x);
|
||||||
this.geyserConnectConfig = FileUtils.loadConfig(configFile, GeyserConnectConfig.class);
|
this.geyserConnectConfig = FileUtils.loadConfig(configFile, GeyserConnectConfig.class);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||||
|
@ -120,7 +123,7 @@ public class MasterServer {
|
||||||
|
|
||||||
// Create the base welcome.txt file
|
// Create the base welcome.txt file
|
||||||
try {
|
try {
|
||||||
FileUtils.fileOrCopiedFromResource(new File(getGeyserConnectConfig().getWelcomeFile()), "welcome.txt", (x) -> x);
|
fileOrCopiedFromResource(new File(getGeyserConnectConfig().getWelcomeFile()), "welcome.txt", (x) -> x);
|
||||||
} catch (IOException ignored) { }
|
} catch (IOException ignored) { }
|
||||||
|
|
||||||
start(geyserConnectConfig.getPort());
|
start(geyserConnectConfig.getPort());
|
||||||
|
@ -208,4 +211,27 @@ public class MasterServer {
|
||||||
public List<Server> getServers(ServerCategory serverCategory) {
|
public List<Server> getServers(ServerCategory serverCategory) {
|
||||||
return getGeyserConnectConfig().getServers().stream().filter(server -> server.getCategory() == serverCategory).collect(Collectors.toList());
|
return getGeyserConnectConfig().getServers().stream().filter(server -> server.getCategory() == serverCategory).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File fileOrCopiedFromResource(File file, String name, Function<String, String> format) throws IOException {
|
||||||
|
if (!file.exists()) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
file.createNewFile();
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||||
|
try (InputStream input = MasterServer.class.getClassLoader().getResourceAsStream(name)) {
|
||||||
|
byte[] bytes = new byte[input.available()];
|
||||||
|
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
input.read(bytes);
|
||||||
|
|
||||||
|
for(char c : format.apply(new String(bytes)).toCharArray()) {
|
||||||
|
fos.write(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
fos.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.geysermc.geyser.configuration.GeyserConfiguration;
|
||||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||||
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
||||||
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
||||||
|
import org.geysermc.geyser.text.GeyserLocale;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -58,6 +59,8 @@ public class GeyserProxyBootstrap implements GeyserBootstrap {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
GeyserLocale.init(this);
|
||||||
|
|
||||||
// Setup a logger
|
// Setup a logger
|
||||||
geyserLogger = new GeyserProxyLogger();
|
geyserLogger = new GeyserProxyLogger();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue