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
|
@ -53,6 +53,7 @@ import net.minecraft.world.WorldServerMulti;
|
|||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.event.world.RegisterDimensionsEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.StartupQuery;
|
||||
import net.minecraftforge.registries.ClearableRegistry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
|
@ -151,6 +152,11 @@ public class DimensionManager
|
|||
Validate.notNull(server, "Must provide server when creating world");
|
||||
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()))
|
||||
getData(dim).ticksWaited = 0;
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ public final class FMLWorldPersistenceHook implements WorldPersistenceHooks.Worl
|
|||
{
|
||||
NBTTagCompound mod = modList.getCompound(i);
|
||||
String modId = mod.getString("ModId");
|
||||
if (Objects.equals("minecraft", modId)) {
|
||||
continue;
|
||||
}
|
||||
String modVersion = mod.getString("ModVersion");
|
||||
Optional<? extends ModContainer> container = ModList.get().getModContainerById(modId);
|
||||
if (!container.isPresent())
|
||||
|
|
|
@ -48,8 +48,8 @@ public enum SidedProvider
|
|||
()-> str->str),
|
||||
@SuppressWarnings("Convert2MethodRef") // need to not be methodrefs to avoid classloading all of StartupQuery's data (supplier is coming from StartupQuery)
|
||||
STARTUPQUERY(
|
||||
c->StartupQuery.QueryWrapper.clientQuery(c),
|
||||
s->StartupQuery.QueryWrapper.dedicatedServerQuery(s),
|
||||
c->StartupQuery.QueryWrapperClient.clientQuery(c),
|
||||
s->StartupQuery.QueryWrapperServer.dedicatedServerQuery(s),
|
||||
()-> { throw new UnsupportedOperationException(); });
|
||||
|
||||
private static Supplier<Minecraft> client;
|
||||
|
|
|
@ -70,7 +70,9 @@ public class StartupQuery {
|
|||
throw new AbortedException(); // to halt the server
|
||||
}
|
||||
|
||||
|
||||
public static boolean pendingQuery() {
|
||||
return pending != null;
|
||||
}
|
||||
public static void reset()
|
||||
{
|
||||
pending = null;
|
||||
|
@ -89,6 +91,7 @@ public class StartupQuery {
|
|||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
LOGGER.error(SQ,"An exception occurred during startup query handling", e);
|
||||
}
|
||||
pending.throwException();
|
||||
}
|
||||
|
@ -212,44 +215,35 @@ public class StartupQuery {
|
|||
}
|
||||
|
||||
|
||||
public static class QueryWrapper
|
||||
{
|
||||
public static Consumer<StartupQuery> clientQuery(Supplier<Minecraft> clientSupplier)
|
||||
{
|
||||
public static class QueryWrapperClient {
|
||||
public static Consumer<StartupQuery> clientQuery(Supplier<Minecraft> clientSupplier) {
|
||||
return (query) -> {
|
||||
Minecraft client = clientSupplier.get();
|
||||
if (query.getResult() == null)
|
||||
{
|
||||
if (query.getResult() == null) {
|
||||
client.displayGuiScreen(new GuiNotification(query));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
client.displayGuiScreen(new GuiConfirmation(query));
|
||||
}
|
||||
|
||||
if (query.isSynchronous())
|
||||
{
|
||||
while (client.currentScreen instanceof GuiNotification)
|
||||
{
|
||||
if (Thread.interrupted())
|
||||
{
|
||||
if (query.isSynchronous()) {
|
||||
while (client.currentScreen instanceof GuiNotification) {
|
||||
if (Thread.interrupted()) {
|
||||
query.exception = new InterruptedException();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
} catch (InterruptedException ie) {
|
||||
query.exception = ie;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class QueryWrapperServer {
|
||||
public static Consumer<StartupQuery> dedicatedServerQuery(Supplier<DedicatedServer> serverSupplier)
|
||||
{
|
||||
return (query) -> {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package net.minecraftforge.server.console;
|
||||
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraftforge.fml.StartupQuery;
|
||||
import net.minecrell.terminalconsole.TerminalConsoleAppender;
|
||||
import org.jline.reader.EndOfFileException;
|
||||
import org.jline.reader.LineReader;
|
||||
|
|
Loading…
Reference in New Issue