Paper/Spigot-Server-Patches/0350-Lazy-init-world-storage-in-CraftOfflinePlayer.patch
Zach Brown 70ce6ce831
Move version command update checking to the implementation
This makes it easier for downstream projects (forks) to replace the
version fetching system with their own. It is as simple as implementing
an interface and overriding the default implementation of
org.bukkit.UnsafeValues#getVersionFetcher()

It also makes it easier for us to organize things like the version
history feature.

Lastly I have updated the paper implementation to check against the site
API rather than against jenkins.
2019-05-27 04:13:41 -05:00

66 lines
2.6 KiB
Diff

From 7a8de00ab10ca0a140ab7adc0460553932af3942 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach@zachbr.io>
Date: Tue, 11 Dec 2018 22:25:07 -0500
Subject: [PATCH] Lazy init world storage in CraftOfflinePlayer
Allows access to some offline player properties even when there are no
worlds loaded. This is typically a rare occurrence but probably one that
should be covered as best we can.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index 6a448c02e..c1ef1c950 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
@@ -25,12 +25,12 @@ import org.bukkit.plugin.Plugin;
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
private final GameProfile profile;
private final CraftServer server;
- private final WorldNBTStorage storage;
+ private WorldNBTStorage storage; // Paper - lazy init
protected CraftOfflinePlayer(CraftServer server, GameProfile profile) {
this.server = server;
this.profile = profile;
- this.storage = (WorldNBTStorage) (server.console.getWorldServer(DimensionManager.OVERWORLD).getDataManager());
+ //this.storage = (WorldNBTStorage) (server.console.getWorldServer(DimensionManager.OVERWORLD).getDataManager()); // Paper - lazy init
}
@@ -177,8 +177,23 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return hash;
}
+ // Paper - lazy
+ private WorldNBTStorage getStorageLazy() {
+ if (this.storage == null) {
+ net.minecraft.server.WorldServer worldServer = server.console.getWorldServer(DimensionManager.OVERWORLD);
+ if (worldServer == null) {
+ throw new IllegalStateException("Cannot get world storage when there are no worlds loaded!");
+ } else {
+ this.storage = (WorldNBTStorage) worldServer.getDataManager();
+ }
+ }
+
+ return this.storage;
+ }
+ // Paper end
+
private NBTTagCompound getData() {
- return storage.getPlayerData(getUniqueId().toString());
+ return getStorageLazy().getPlayerData(getUniqueId().toString());
}
private NBTTagCompound getBukkitData() {
@@ -195,7 +210,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
}
private File getDataFile() {
- return new File(storage.getPlayerDir(), getUniqueId() + ".dat");
+ return new File(getStorageLazy().getPlayerDir(), getUniqueId() + ".dat");
}
@Override
--
2.21.0