Skip to content

Commit

Permalink
Fix Bukkit data not being loaded while offline
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
Jikoo committed May 26, 2021
1 parent bd207e9 commit 9e0ca47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down

0 comments on commit 9e0ca47

Please sign in to comment.