Skip to content

Commit

Permalink
fix: null-check for player's chunk team data on logout
Browse files Browse the repository at this point in the history
Should not normally be null, but external factors could force a player
disconnect before they have an FTB team assigned.

FTBTeam/FTB-Mods-Issues#932
  • Loading branch information
desht committed Sep 13, 2023
1 parent 4396ac1 commit 368ae54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
20 changes: 13 additions & 7 deletions common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,19 @@ public void loggedOut(ServerPlayer player) {
}

ChunkTeamDataImpl data = ClaimedChunkManagerImpl.getInstance().getOrCreateData(player);
data.setForceLoadMember(player.getUUID(), FTBChunksWorldConfig.canPlayerOfflineForceload(player));
ClaimedChunkManagerImpl.getInstance().clearForceLoadedCache();
LongRangePlayerTracker.INSTANCE.stopTracking(player);

if (data.getTeam().getOnlineMembers().size() == 1 && !data.canDoOfflineForceLoading()) {
// last player on the team to log out; unforce chunks if the team can't do offline chunk-loading
data.updateChunkTickets(false);
// shouldn't normally be null here, but external problems could force a player logout before they have a team
// https://github.com/FTBTeam/FTB-Mods-Issues/issues/932
if (data != null) {
data.setForceLoadMember(player.getUUID(), FTBChunksWorldConfig.canPlayerOfflineForceload(player));
ClaimedChunkManagerImpl.getInstance().clearForceLoadedCache();
LongRangePlayerTracker.INSTANCE.stopTracking(player);

if (data.getTeam().getOnlineMembers().size() == 1 && !data.canDoOfflineForceLoading()) {
// last player on the team to log out; unforce chunks if the team can't do offline chunk-loading
data.updateChunkTickets(false);
}
} else {
FTBChunks.LOGGER.warn("on player disconnect: player '{}' has no team?", player.getGameProfile().getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public interface ClaimedChunkManager {
/**
* Get the FTB Chunks team data for the given player, creating a new instance if necessary. This will get the
* data for the party team the player is in, if applicable.
* <p>
* This should not normally return null, but it is a possibility if external problems cause the player to be
* disconnected before they are assigned an FTB Team. So the return value should be checked.
*
* @param player the player
* @return the FTB Chunks data for the team
* @return the FTB Chunks data for the team, or null if something went wrong
*/
ChunkTeamData getOrCreateData(ServerPlayer player);

Expand All @@ -44,7 +47,7 @@ public interface ClaimedChunkManager {
* for the player's personal team, even if they are currently in a party team.
*
* @param id a player UUID
* @return the FTB Chunks data for the player
* @return the FTB Chunks data for the player, or null if something went wrong
*/
ChunkTeamData getPersonalData(UUID id);

Expand Down

0 comments on commit 368ae54

Please sign in to comment.