Paper/Spigot-Server-Patches/0094-remove-null-possibility-for-getServer-singleton.patch

37 lines
2.4 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 28 Apr 2016 00:57:27 -0400
Subject: [PATCH] remove null possibility for getServer singleton
to stop IDE complaining about potential NPE
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 026ddfba26439a00685f3962084aa6194086c9b7..f990f242a8d812a93b454b065a17fd4e8170355a 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2021-03-16 23:50:45 +08:00
@@ -180,6 +180,7 @@ import org.spigotmc.SlackActivityAccountant; // Spigot
2020-06-25 19:00:35 +08:00
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable {
+ private static MinecraftServer SERVER; // Paper
public static final Logger LOGGER = LogManager.getLogger();
2019-04-27 11:05:36 +08:00
public static final File b = new File("usercache.json");
2020-06-25 19:00:35 +08:00
public static final WorldSettings c = new WorldSettings("Demo World", EnumGamemode.SURVIVAL, false, EnumDifficulty.NORMAL, false, new GameRules(), DataPackConfiguration.a);
2021-03-16 23:50:45 +08:00
@@ -286,6 +287,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2020-06-25 19:00:35 +08:00
public MinecraftServer(OptionSet options, DataPackConfiguration datapackconfiguration, Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, SaveData savedata, ResourcePackRepository resourcepackrepository, Proxy proxy, DataFixer datafixer, DataPackResources datapackresources, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
2019-04-27 11:05:36 +08:00
super("Server");
+ SERVER = this; // Paper - better singleton
this.m = new GameProfilerSwitcher(SystemUtils.a, this::ai);
2020-06-25 19:00:35 +08:00
this.methodProfiler = GameProfilerDisabled.a;
this.serverPing = new ServerPing();
@@ -2163,7 +2165,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-04-27 11:05:36 +08:00
@Deprecated
public static MinecraftServer getServer() {
- return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null;
2019-04-27 11:05:36 +08:00
+ return SERVER; // Paper
}
// CraftBukkit end
2020-06-25 19:00:35 +08:00