From 9e0ca479a5d69014b48d5ea714b22195d1fa3f6f Mon Sep 17 00:00:00 2001 From: Jikoo Date: Wed, 26 May 2021 08:16:25 -0400 Subject: [PATCH] Fix Bukkit data not being loaded while offline Closes #16 --- .../lishid/openinv/internal/v1_16_R3/OpenPlayer.java | 11 ++++++++++- .../openinv/internal/v1_16_R3/PlayerDataManager.java | 6 ++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/OpenPlayer.java b/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/OpenPlayer.java index def3f960..ec87e3be 100644 --- a/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/OpenPlayer.java +++ b/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/OpenPlayer.java @@ -32,15 +32,24 @@ public OpenPlayer(CraftServer server, EntityPlayer entity) { super(server, entity); } + @Override + public void loadData() { + // See CraftPlayer#loadData + NBTTagCompound loaded = this.server.getHandle().playerFileData.load(this.getHandle()); + if (loaded != null) { + readExtraData(loaded); + } + } + @Override public void saveData() { - super.saveData(); EntityPlayer player = this.getHandle(); // See net.minecraft.server.WorldNBTStorage#save(EntityPlayer) try { WorldNBTStorage worldNBTStorage = player.server.getPlayerList().playerFileData; NBTTagCompound playerData = player.save(new NBTTagCompound()); + setExtraData(playerData); if (!isOnline()) { // Special case: save old vehicle data diff --git a/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/PlayerDataManager.java b/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/PlayerDataManager.java index 5a29ceb5..35cae336 100644 --- a/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/PlayerDataManager.java +++ b/internal/v1_16_R3/src/main/java/com/lishid/openinv/internal/v1_16_R3/PlayerDataManager.java @@ -57,8 +57,7 @@ public PlayerDataManager() { } } - @NotNull - public static EntityPlayer getHandle(final Player player) { + public static @NotNull EntityPlayer getHandle(final Player player) { if (player instanceof CraftPlayer) { return ((CraftPlayer) player).getHandle(); } @@ -78,9 +77,8 @@ public static EntityPlayer getHandle(final Player player) { return nmsPlayer; } - @Nullable @Override - public Player loadPlayer(@NotNull final OfflinePlayer offline) { + public @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline) { // Ensure player has data if (!offline.hasPlayedBefore()) { return null;