Allow Server#getDefaultGameMode before worlds are initialized (#12490)

This commit is contained in:
David 2025-04-28 17:36:46 +02:00 committed by GitHub
parent 1db3785307
commit d1810f241c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,6 +40,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import net.minecraft.Optionull;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -2261,7 +2262,11 @@ public final class CraftServer implements Server {
@Override
public GameMode getDefaultGameMode() {
return GameMode.getByValue(this.console.getLevel(net.minecraft.world.level.Level.OVERWORLD).serverLevelData.getGameType().getId());
return GameMode.getByValue(Optionull.mapOrDefault(
this.console.getLevel(net.minecraft.world.level.Level.OVERWORLD),
l -> l.serverLevelData.getGameType(),
this.console.getProperties().gamemode
).getId());
}
@Override