Skip to content

Commit

Permalink
Fix /geyser reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Dec 29, 2021
1 parent b246d5b commit b23275f
Showing 1 changed file with 63 additions and 43 deletions.
106 changes: 63 additions & 43 deletions core/src/main/java/org/geysermc/geyser/GeyserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,46 +112,39 @@ public class GeyserImpl implements GeyserApi {

private FloodgateCipher cipher;
private FloodgateSkinUploader skinUploader;
private final NewsHandler newsHandler;
private NewsHandler newsHandler;

private volatile boolean shuttingDown = false;

private final ScheduledExecutorService scheduledThread;
private ScheduledExecutorService scheduledThread;

private final BedrockServer bedrockServer;
private BedrockServer bedrockServer;
private final PlatformType platformType;
private final GeyserBootstrap bootstrap;

private final Metrics metrics;
private Metrics metrics;

private static GeyserImpl instance;

private GeyserImpl(PlatformType platformType, GeyserBootstrap bootstrap) {
long startupTime = System.currentTimeMillis();

this.bootstrap = bootstrap;

instance = this;

Geyser.set(this);

GeyserLogger logger = bootstrap.getGeyserLogger();
GeyserConfiguration config = bootstrap.getGeyserConfig();

this.platformType = platformType;
this.bootstrap = bootstrap;

long startupTime = System.currentTimeMillis();

GeyserLocale.finalizeDefaultLocale(this);
GeyserLogger logger = bootstrap.getGeyserLogger();

logger.info("******************************************");
logger.info("");
logger.info(GeyserLocale.getLocaleStringLog("geyser.core.load", NAME, VERSION));
logger.info("");
logger.info("******************************************");

this.scheduledThread = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("Geyser Scheduled Thread"));

logger.setDebug(config.isDebugMode());

/* Initialize translators and registries */
BlockRegistries.init();
Registries.init();
Expand All @@ -160,6 +153,46 @@ private GeyserImpl(PlatformType platformType, GeyserBootstrap bootstrap) {
ItemTranslator.init();
MessageTranslator.init();
MinecraftLocale.init();

start();

GeyserConfiguration config = bootstrap.getGeyserConfig();

boolean isGui = false;
// This will check if we are in standalone and get the 'useGui' variable from there
if (platformType == PlatformType.STANDALONE) {
try {
Class<?> cls = Class.forName("org.geysermc.geyser.platform.standalone.GeyserStandaloneBootstrap");
isGui = (boolean) cls.getMethod("isUseGui").invoke(cls.cast(bootstrap));
} catch (Exception e) {
logger.debug("Failed detecting if standalone is using a GUI; if this is a GeyserConnect instance this can be safely ignored.");
}
}

double completeTime = (System.currentTimeMillis() - startupTime) / 1000D;
String message = GeyserLocale.getLocaleStringLog("geyser.core.finish.done", new DecimalFormat("#.###").format(completeTime)) + " ";
if (isGui) {
message += GeyserLocale.getLocaleStringLog("geyser.core.finish.gui");
} else {
message += GeyserLocale.getLocaleStringLog("geyser.core.finish.console");
}

logger.info(message);

if (platformType == PlatformType.STANDALONE) {
logger.warning(GeyserLocale.getLocaleStringLog("geyser.core.movement_warn"));
} else if (config.getRemote().getAuthType() == AuthType.FLOODGATE) {
VersionCheckUtils.checkForOutdatedFloodgate(logger);
}
}

private void start() {
this.scheduledThread = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("Geyser Scheduled Thread"));

GeyserLogger logger = bootstrap.getGeyserLogger();
GeyserConfiguration config = bootstrap.getGeyserConfig();
logger.setDebug(config.isDebugMode());

ScoreboardUpdater.init();

ResourcePack.loadPacks();
Expand Down Expand Up @@ -231,7 +264,8 @@ private GeyserImpl(PlatformType platformType, GeyserBootstrap bootstrap) {
} else {
logger.debug("Not getting git properties for the news handler as we are in a development environment.");
}
newsHandler = new NewsHandler(branch, buildNumber);

this.newsHandler = new NewsHandler(branch, buildNumber);

CooldownUtils.setDefaultShowCooldown(config.getShowCooldown());
DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
Expand Down Expand Up @@ -367,32 +401,6 @@ private GeyserImpl(PlatformType platformType, GeyserBootstrap bootstrap) {
metrics = null;
}

boolean isGui = false;
// This will check if we are in standalone and get the 'useGui' variable from there
if (platformType == PlatformType.STANDALONE) {
try {
Class<?> cls = Class.forName("org.geysermc.geyser.platform.standalone.GeyserStandaloneBootstrap");
isGui = (boolean) cls.getMethod("isUseGui").invoke(cls.cast(bootstrap));
} catch (Exception e) {
logger.debug("Failed detecting if standalone is using a GUI; if this is a GeyserConnect instance this can be safely ignored.");
}
}

double completeTime = (System.currentTimeMillis() - startupTime) / 1000D;
String message = GeyserLocale.getLocaleStringLog("geyser.core.finish.done", new DecimalFormat("#.###").format(completeTime)) + " ";
if (isGui) {
message += GeyserLocale.getLocaleStringLog("geyser.core.finish.gui");
} else {
message += GeyserLocale.getLocaleStringLog("geyser.core.finish.console");
}
logger.info(message);

if (platformType == PlatformType.STANDALONE) {
logger.warning(GeyserLocale.getLocaleStringLog("geyser.core.movement_warn"));
} else if (config.getRemote().getAuthType() == AuthType.FLOODGATE) {
VersionCheckUtils.checkForOutdatedFloodgate(logger);
}

newsHandler.handleNews(null, NewsItemAction.ON_SERVER_STARTED);
}

Expand Down Expand Up @@ -447,6 +455,8 @@ public void shutdown() {
newsHandler.shutdown();
this.getCommandManager().getCommands().clear();

ResourcePack.PACKS.clear();

bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done"));
}

Expand All @@ -469,7 +479,17 @@ public boolean productionEnvironment() {
}

public static GeyserImpl start(PlatformType platformType, GeyserBootstrap bootstrap) {
return new GeyserImpl(platformType, bootstrap);
if (instance == null) {
return new GeyserImpl(platformType, bootstrap);
}

// We've been reloaded
if (instance.isShuttingDown()) {
instance.shuttingDown = false;
instance.start();
}

return instance;
}

public GeyserLogger getLogger() {
Expand Down

0 comments on commit b23275f

Please sign in to comment.