Fix StartupQuery to run properly on dedicated server.. Closes #5649
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
37016ca77f
commit
e0361047f7
5 changed files with 27 additions and 23 deletions
|
@ -53,6 +53,7 @@ import net.minecraft.world.WorldServerMulti;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import net.minecraftforge.event.world.RegisterDimensionsEvent;
|
import net.minecraftforge.event.world.RegisterDimensionsEvent;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
import net.minecraftforge.fml.StartupQuery;
|
||||||
import net.minecraftforge.registries.ClearableRegistry;
|
import net.minecraftforge.registries.ClearableRegistry;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
|
@ -151,6 +152,11 @@ public class DimensionManager
|
||||||
Validate.notNull(server, "Must provide server when creating world");
|
Validate.notNull(server, "Must provide server when creating world");
|
||||||
Validate.notNull(dim, "Dimension type must not be null");
|
Validate.notNull(dim, "Dimension type must not be null");
|
||||||
|
|
||||||
|
// If we're in the early stages of loading, we need to return null so CommandSource can work properly for command function
|
||||||
|
if (StartupQuery.pendingQuery()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (resetUnloadDelay && unloadQueue.contains(dim.getId()))
|
if (resetUnloadDelay && unloadQueue.contains(dim.getId()))
|
||||||
getData(dim).ticksWaited = 0;
|
getData(dim).ticksWaited = 0;
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,9 @@ public final class FMLWorldPersistenceHook implements WorldPersistenceHooks.Worl
|
||||||
{
|
{
|
||||||
NBTTagCompound mod = modList.getCompound(i);
|
NBTTagCompound mod = modList.getCompound(i);
|
||||||
String modId = mod.getString("ModId");
|
String modId = mod.getString("ModId");
|
||||||
|
if (Objects.equals("minecraft", modId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String modVersion = mod.getString("ModVersion");
|
String modVersion = mod.getString("ModVersion");
|
||||||
Optional<? extends ModContainer> container = ModList.get().getModContainerById(modId);
|
Optional<? extends ModContainer> container = ModList.get().getModContainerById(modId);
|
||||||
if (!container.isPresent())
|
if (!container.isPresent())
|
||||||
|
|
|
@ -48,8 +48,8 @@ public enum SidedProvider
|
||||||
()-> str->str),
|
()-> str->str),
|
||||||
@SuppressWarnings("Convert2MethodRef") // need to not be methodrefs to avoid classloading all of StartupQuery's data (supplier is coming from StartupQuery)
|
@SuppressWarnings("Convert2MethodRef") // need to not be methodrefs to avoid classloading all of StartupQuery's data (supplier is coming from StartupQuery)
|
||||||
STARTUPQUERY(
|
STARTUPQUERY(
|
||||||
c->StartupQuery.QueryWrapper.clientQuery(c),
|
c->StartupQuery.QueryWrapperClient.clientQuery(c),
|
||||||
s->StartupQuery.QueryWrapper.dedicatedServerQuery(s),
|
s->StartupQuery.QueryWrapperServer.dedicatedServerQuery(s),
|
||||||
()-> { throw new UnsupportedOperationException(); });
|
()-> { throw new UnsupportedOperationException(); });
|
||||||
|
|
||||||
private static Supplier<Minecraft> client;
|
private static Supplier<Minecraft> client;
|
||||||
|
|
|
@ -70,7 +70,9 @@ public class StartupQuery {
|
||||||
throw new AbortedException(); // to halt the server
|
throw new AbortedException(); // to halt the server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean pendingQuery() {
|
||||||
|
return pending != null;
|
||||||
|
}
|
||||||
public static void reset()
|
public static void reset()
|
||||||
{
|
{
|
||||||
pending = null;
|
pending = null;
|
||||||
|
@ -89,6 +91,7 @@ public class StartupQuery {
|
||||||
}
|
}
|
||||||
catch (RuntimeException e)
|
catch (RuntimeException e)
|
||||||
{
|
{
|
||||||
|
LOGGER.error(SQ,"An exception occurred during startup query handling", e);
|
||||||
}
|
}
|
||||||
pending.throwException();
|
pending.throwException();
|
||||||
}
|
}
|
||||||
|
@ -212,44 +215,35 @@ public class StartupQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class QueryWrapper
|
public static class QueryWrapperClient {
|
||||||
{
|
public static Consumer<StartupQuery> clientQuery(Supplier<Minecraft> clientSupplier) {
|
||||||
public static Consumer<StartupQuery> clientQuery(Supplier<Minecraft> clientSupplier)
|
|
||||||
{
|
|
||||||
return (query) -> {
|
return (query) -> {
|
||||||
Minecraft client = clientSupplier.get();
|
Minecraft client = clientSupplier.get();
|
||||||
if (query.getResult() == null)
|
if (query.getResult() == null) {
|
||||||
{
|
|
||||||
client.displayGuiScreen(new GuiNotification(query));
|
client.displayGuiScreen(new GuiNotification(query));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
client.displayGuiScreen(new GuiConfirmation(query));
|
client.displayGuiScreen(new GuiConfirmation(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.isSynchronous())
|
if (query.isSynchronous()) {
|
||||||
{
|
while (client.currentScreen instanceof GuiNotification) {
|
||||||
while (client.currentScreen instanceof GuiNotification)
|
if (Thread.interrupted()) {
|
||||||
{
|
|
||||||
if (Thread.interrupted())
|
|
||||||
{
|
|
||||||
query.exception = new InterruptedException();
|
query.exception = new InterruptedException();
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
}
|
} catch (InterruptedException ie) {
|
||||||
catch (InterruptedException ie)
|
|
||||||
{
|
|
||||||
query.exception = ie;
|
query.exception = ie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class QueryWrapperServer {
|
||||||
public static Consumer<StartupQuery> dedicatedServerQuery(Supplier<DedicatedServer> serverSupplier)
|
public static Consumer<StartupQuery> dedicatedServerQuery(Supplier<DedicatedServer> serverSupplier)
|
||||||
{
|
{
|
||||||
return (query) -> {
|
return (query) -> {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package net.minecraftforge.server.console;
|
package net.minecraftforge.server.console;
|
||||||
|
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
|
import net.minecraftforge.fml.StartupQuery;
|
||||||
import net.minecrell.terminalconsole.TerminalConsoleAppender;
|
import net.minecrell.terminalconsole.TerminalConsoleAppender;
|
||||||
import org.jline.reader.EndOfFileException;
|
import org.jline.reader.EndOfFileException;
|
||||||
import org.jline.reader.LineReader;
|
import org.jline.reader.LineReader;
|
||||||
|
|
Loading…
Reference in a new issue