Improve startup on forge to be more stable with other mods

This commit is contained in:
Blue (Lukas Rieger) 2020-10-06 16:05:39 +02:00
parent e071ed83fa
commit 86b8deb3f3
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
3 changed files with 33 additions and 21 deletions

View File

@ -37,6 +37,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import org.apache.logging.log4j.LogManager;
import com.github.benmanes.caffeine.cache.Caffeine;
@ -97,20 +98,23 @@ public ForgeMod() {
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
this.worldUUIDs.clear();
//save worlds to generate level.dat files
event.getServer().save(false, true, true);
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
this.serverInstance = event.getServer();
//register commands
new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource));
}
@SubscribeEvent
public void onServerStarted(FMLServerStartedEvent event) {
//save worlds to generate level.dat files
serverInstance.save(false, true, true);
new Thread(() -> {
Logger.global.logInfo("Loading...");
try {
pluginInstance.load();
if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!");
@ -119,7 +123,7 @@ public void onServerStarting(FMLServerStartingEvent event) {
pluginInstance.unload();
}
}).start();
}
}
@SubscribeEvent
public void onServerStopping(FMLServerStoppingEvent event) {

View File

@ -37,6 +37,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import org.apache.logging.log4j.LogManager;
import com.github.benmanes.caffeine.cache.Caffeine;
@ -100,17 +101,20 @@ public ForgeMod() {
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
this.worldUUIDs.clear();
//save worlds to generate level.dat files
event.getServer().save(false, true, true);
this.serverInstance = event.getServer();
//register commands
new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource));
}
@SubscribeEvent
public void onServerStarted(FMLServerStartedEvent event) {
//save worlds to generate level.dat files
serverInstance.save(false, true, true);
new Thread(() -> {
Logger.global.logInfo("Loading...");
try {
pluginInstance.load();
if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!");
@ -119,7 +123,7 @@ public void onServerStarting(FMLServerStartingEvent event) {
pluginInstance.unload();
}
}).start();
}
}
@SubscribeEvent
public void onServerStopping(FMLServerStoppingEvent event) {

View File

@ -37,6 +37,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import org.apache.logging.log4j.LogManager;
import com.github.benmanes.caffeine.cache.Caffeine;
@ -101,20 +102,23 @@ public ForgeMod() {
}
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
public void onServerStarting(FMLServerStartingEvent event) {
this.serverInstance = event.getServer();
//register commands
new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource));
}
@SubscribeEvent
public void onServerStarted(FMLServerStartedEvent event) {
//save worlds to generate level.dat files
serverInstance.save(false, true, true);
new Thread(() -> {
Logger.global.logInfo("Loading...");
try {
pluginInstance.load();
if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!");
@ -123,7 +127,7 @@ public void onServerStarting(FMLServerStartingEvent event) {
pluginInstance.unload();
}
}).start();
}
}
@SubscribeEvent
public void onServerStopping(FMLServerStoppingEvent event) {