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

View File

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

View File

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