mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Implement proper logger, shutdown, and IP checking
This commit is contained in:
parent
e7c00d897f
commit
be07a47f9f
2 changed files with 25 additions and 9 deletions
|
@ -25,10 +25,14 @@
|
||||||
|
|
||||||
package org.geysermc.platform.fabric;
|
package org.geysermc.platform.fabric;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.geysermc.connector.GeyserLogger;
|
import org.geysermc.connector.GeyserLogger;
|
||||||
|
|
||||||
public class GeyserFabricLogger implements GeyserLogger {
|
public class GeyserFabricLogger implements GeyserLogger {
|
||||||
|
|
||||||
|
private final Logger logger = LogManager.getLogger("geyser-fabric");
|
||||||
|
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
|
|
||||||
public GeyserFabricLogger(boolean isDebug) {
|
public GeyserFabricLogger(boolean isDebug) {
|
||||||
|
@ -37,38 +41,38 @@ public class GeyserFabricLogger implements GeyserLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void severe(String message) {
|
public void severe(String message) {
|
||||||
System.out.println(message);
|
logger.fatal(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void severe(String message, Throwable error) {
|
public void severe(String message, Throwable error) {
|
||||||
System.out.println(message);
|
logger.fatal(message, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message) {
|
public void error(String message) {
|
||||||
System.out.println(message);
|
logger.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message, Throwable error) {
|
public void error(String message, Throwable error) {
|
||||||
System.out.println(message);
|
logger.error(message, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warning(String message) {
|
public void warning(String message) {
|
||||||
System.out.println(message);
|
logger.warn(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void info(String message) {
|
public void info(String message) {
|
||||||
System.out.println(message);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
info(message);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,9 @@ package org.geysermc.platform.fabric;
|
||||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.GeyserLogger;
|
import org.geysermc.connector.GeyserLogger;
|
||||||
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
||||||
|
@ -76,7 +77,7 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
|
||||||
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
||||||
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserFabricConfiguration.class);
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserFabricConfiguration.class);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.out.println(LanguageUtils.getLocaleStringLog("geyser.config.failed"));
|
LogManager.getLogger("geyser-fabric").error(LanguageUtils.getLocaleStringLog("geyser.config.failed"), ex);
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +87,14 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
|
||||||
|
|
||||||
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
|
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
|
||||||
this.geyserConfig.setAutoconfiguredRemote(true);
|
this.geyserConfig.setAutoconfiguredRemote(true);
|
||||||
|
ServerLifecycleEvents.SERVER_STARTING.register((server) -> {
|
||||||
|
String ip = server.getServerIp();
|
||||||
|
int port = server.getServerPort();
|
||||||
|
if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
|
||||||
|
this.geyserConfig.getRemote().setAddress(ip);
|
||||||
|
}
|
||||||
|
this.geyserConfig.getRemote().setPort(port);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geyserConfig.getBedrock().isCloneRemotePort()) {
|
if (geyserConfig.getBedrock().isCloneRemotePort()) {
|
||||||
|
@ -94,6 +103,9 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
|
||||||
|
|
||||||
this.connector = GeyserConnector.start(PlatformType.ANDROID, this);
|
this.connector = GeyserConnector.start(PlatformType.ANDROID, this);
|
||||||
|
|
||||||
|
// Register onDisable so players are properly kicked
|
||||||
|
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
|
||||||
|
|
||||||
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
||||||
|
|
||||||
this.geyserCommandManager = new GeyserFabricCommandManager(connector);
|
this.geyserCommandManager = new GeyserFabricCommandManager(connector);
|
||||||
|
|
Loading…
Reference in a new issue