Fix StartupQuery to run properly on dedicated server.. Closes #5649

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-03-30 14:46:30 -04:00
parent 37016ca77f
commit e0361047f7
No known key found for this signature in database
GPG Key ID: 8EB3DF749553B1B7
5 changed files with 27 additions and 23 deletions

View File

@ -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;

View File

@ -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())

View File

@ -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;

View File

@ -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) -> {

View File

@ -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;