Skip to content

Commit a28f8f7

Browse files
committed
fix(redis): publish INVALIDATE_PROFILE on transferClaimProfile for cross-server sync
The previous merge-branch security fix (aaad3bc) updated the local cache + spatial index but didn't propagate the change to other Redis-connected server instances. On a multi-server network, a market sale on node A was invisible to node B until the next periodic cache flush, so players on B would see the old owner. Add INVALIDATE_PROFILE publishes for both branches: - merge branch (buyer already has a profile): invalidate the source owner's profile id AND the buyer's profile id - re-key branch (no profile yet): invalidate the old and new owner ids A small publishInvalidate() helper makes the null check + redis call a one-liner. unclaimAllById doesn't need this — it delegates to abandonProfile which already publishes INVALIDATE_PROFILE.
1 parent 69485f5 commit a28f8f7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/main/java/org/ayosynk/landClaimPlugin/managers/ClaimManager.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,25 +722,39 @@ public boolean transferClaimProfile(UUID profileId, UUID newOwnerId) {
722722
}
723723
// Drop the now-empty source profile from the profile cache
724724
// (it's keyed by owner UUID).
725-
plugin.getCacheManager().getProfileCache().invalidate(source.getOwnerId());
725+
UUID sourceOwner = source.getOwnerId();
726+
plugin.getCacheManager().getProfileCache().invalidate(sourceOwner);
726727
// Refresh the buyer entry so subsequent lookups see the new chunks.
727728
plugin.getCacheManager().getProfileCache().put(buyerProfile.getOwnerId(), buyerProfile);
728729
plugin.getDatabaseManager().getProfileDao().saveProfile(buyerProfile);
729-
plugin.getDatabaseManager().getProfileDao().deleteProfile(source.getOwnerId());
730+
plugin.getDatabaseManager().getProfileDao().deleteProfile(sourceOwner);
731+
// Cross-server: invalidate both profiles on remote nodes so a
732+
// /claimmarket sale on node A is visible immediately on node B.
733+
publishInvalidate(sourceOwner);
734+
publishInvalidate(buyerProfile.getOwnerId());
730735
} else {
731736
// Re-key: change ownerId in place, move cache entry.
732737
UUID oldOwnerId = source.getOwnerId();
733738
plugin.getCacheManager().getProfileCache().invalidate(oldOwnerId);
734739
source.setOwnerId(newOwnerId);
735740
plugin.getCacheManager().getProfileCache().put(newOwnerId, source);
736741
plugin.getDatabaseManager().getProfileDao().saveProfile(source);
742+
// Cross-server: invalidate on both old and new owner IDs.
743+
publishInvalidate(oldOwnerId);
744+
publishInvalidate(newOwnerId);
737745
}
738746

739747
plugin.getVisualizationManager().invalidateCache(newOwnerId);
740748
plugin.getHookManager().refreshMapHooks();
741749
return true;
742750
}
743751

752+
private void publishInvalidate(UUID ownerId) {
753+
if (plugin.getRedisManager() != null && ownerId != null) {
754+
plugin.getRedisManager().publishUpdate("INVALIDATE_PROFILE", ownerId);
755+
}
756+
}
757+
744758
/**
745759
* Fully unclaim every chunk in a profile by its profile ID. Used
746760
* by addons (e.g. tax auto-unclaim) that need to wipe a claim

0 commit comments

Comments
 (0)