mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
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. Fixes GH-1701
This commit is contained in:
parent
35e52a42ab
commit
de644b9b87
1 changed files with 63 additions and 0 deletions
|
@ -0,0 +1,63 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Zach Brown <1254957+zachbr@users.noreply.github.com>
|
||||
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 698cfb918..fbdb2df27 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ 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() {
|
||||
@@ -0,0 +0,0 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
}
|
||||
|
||||
private File getDataFile() {
|
||||
- return new File(storage.getPlayerDir(), getUniqueId() + ".dat");
|
||||
+ return new File(getStorageLazy().getPlayerDir(), getUniqueId() + ".dat");
|
||||
}
|
||||
|
||||
public long getFirstPlayed() {
|
||||
--
|
Loading…
Reference in a new issue