Skip to content

Commit 50da051

Browse files
cryptobenchclaude
andcommitted
Fix trusted players not rendering on map overlay
The map tiles were not being refreshed when trust was added/removed, causing cached images without the trusted player names to persist. - Add refreshPlayerClaimChunks() to refresh all claim tiles for a player - Call map refresh in trust/untrust commands and settings GUI Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 174b9da commit 50da051

3 files changed

Lines changed: 81 additions & 2 deletions

File tree

src/main/java/com/easyclaims/EasyClaims.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,64 @@ private void onPlayerDisconnect(PlayerDisconnectEvent event) {
325325
}
326326
}
327327

328+
/**
329+
* Refreshes all claim chunks for a specific player.
330+
* Called when trust is added/removed to update the trusted player names on the map.
331+
*
332+
* @param playerId The UUID of the claim owner
333+
*/
334+
public void refreshPlayerClaimChunks(java.util.UUID playerId) {
335+
var playerClaims = claimStorage.getPlayerClaims(playerId);
336+
if (playerClaims == null) {
337+
return;
338+
}
339+
340+
// Group claims by world for efficient refresh
341+
Map<String, java.util.List<int[]>> claimsByWorld = new HashMap<>();
342+
for (var claim : playerClaims.getClaims()) {
343+
claimsByWorld.computeIfAbsent(claim.getWorld(), k -> new java.util.ArrayList<>())
344+
.add(new int[]{claim.getChunkX(), claim.getChunkZ()});
345+
}
346+
347+
// Refresh each world's chunks
348+
for (var entry : claimsByWorld.entrySet()) {
349+
String worldName = entry.getKey();
350+
World world = WORLDS.get(worldName);
351+
if (world == null) {
352+
continue;
353+
}
354+
355+
try {
356+
LongSet chunksToRefresh = new LongOpenHashSet();
357+
for (int[] coords : entry.getValue()) {
358+
// Add the claim chunk and its neighbors for border updates
359+
for (int dx = -1; dx <= 1; dx++) {
360+
for (int dz = -1; dz <= 1; dz++) {
361+
chunksToRefresh.add(ChunkUtil.indexChunk(coords[0] + dx, coords[1] + dz));
362+
}
363+
}
364+
}
365+
366+
// Clear server-side cached images
367+
world.getWorldMapManager().clearImagesInChunks(chunksToRefresh);
368+
369+
// Clear each player's client-side cache
370+
for (Player player : world.getPlayers()) {
371+
try {
372+
player.getWorldMapTracker().clearChunks(chunksToRefresh);
373+
} catch (Exception e) {
374+
getLogger().atFine().withCause(e).log("[Map] Error clearing chunks for player");
375+
}
376+
}
377+
378+
getLogger().atFine().log("[Map] Refreshed %d claim chunks for player %s in world %s",
379+
entry.getValue().size(), playerId, worldName);
380+
} catch (Exception e) {
381+
getLogger().atWarning().withCause(e).log("[Map] Error refreshing claims for player %s", playerId);
382+
}
383+
}
384+
}
385+
328386
/**
329387
* Gets the map overlay provider for external access.
330388
*/

src/main/java/com/easyclaims/commands/EasyClaimsCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ private void handleSettings(PlayerRef playerData, Store<EntityStore> store, Ref<
238238
new ClaimSettingsGui(
239239
playerData,
240240
plugin.getClaimManager(),
241-
plugin.getPlaytimeManager()
241+
plugin.getPlaytimeManager(),
242+
(playerId) -> plugin.refreshPlayerClaimChunks(playerId)
242243
)
243244
);
244245
});
@@ -382,6 +383,9 @@ private void handleTrust(PlayerRef playerData, String playerInput, String levelI
382383

383384
plugin.getClaimManager().addTrust(playerData.getUuid(), targetId, targetName, level);
384385
playerData.sendMessage(Message.raw("Trusted " + targetName + " with " + level.getDescription()).color(GREEN));
386+
387+
// Refresh map to show updated trusted player names
388+
plugin.refreshPlayerClaimChunks(playerData.getUuid());
385389
}
386390

387391
// ===== UNTRUST =====
@@ -428,6 +432,9 @@ private void handleUntrust(PlayerRef playerData, String playerInput) {
428432

429433
plugin.getClaimManager().removeTrust(playerData.getUuid(), targetId);
430434
playerData.sendMessage(Message.raw("Removed trust from " + targetName).color(GREEN));
435+
436+
// Refresh map to update trusted player names
437+
plugin.refreshPlayerClaimChunks(playerData.getUuid());
431438
}
432439

433440
// ===== TRUST LIST =====

src/main/java/com/easyclaims/gui/ClaimSettingsGui.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Map;
2828
import java.util.UUID;
29+
import java.util.function.Consumer;
2930

3031
/**
3132
* GUI for viewing and managing claim settings and trusted players.
@@ -34,16 +35,19 @@ public class ClaimSettingsGui extends InteractiveCustomUIPage<ClaimSettingsGui.S
3435

3536
private final ClaimManager claimManager;
3637
private final PlaytimeManager playtimeManager;
38+
private final Consumer<UUID> onTrustChanged;
3739
private String playerNameInput = "";
3840
private String statusMessage = "";
3941
private boolean statusIsError = true;
4042
private int requestingConfirmation = -1;
4143
private TrustLevel selectedTrustLevel = TrustLevel.BUILD;
4244

43-
public ClaimSettingsGui(@Nonnull PlayerRef playerRef, ClaimManager claimManager, PlaytimeManager playtimeManager) {
45+
public ClaimSettingsGui(@Nonnull PlayerRef playerRef, ClaimManager claimManager, PlaytimeManager playtimeManager,
46+
Consumer<UUID> onTrustChanged) {
4447
super(playerRef, CustomPageLifetime.CanDismiss, SettingsData.CODEC);
4548
this.claimManager = claimManager;
4649
this.playtimeManager = playtimeManager;
50+
this.onTrustChanged = onTrustChanged;
4751
}
4852

4953
@Override
@@ -119,6 +123,11 @@ public void handleDataEvent(@Nonnull Ref<EntityStore> ref, @Nonnull Store<Entity
119123
claimManager.removeTrust(playerId, targetId);
120124
statusMessage = "Removed " + targetName;
121125
statusIsError = false;
126+
127+
// Refresh map to update trusted player names
128+
if (onTrustChanged != null) {
129+
onTrustChanged.accept(playerId);
130+
}
122131
}
123132
this.requestingConfirmation = -1;
124133
}
@@ -174,6 +183,11 @@ private void addTrustedPlayer(UUID ownerId, String targetName, TrustLevel level)
174183
}
175184

176185
playerNameInput = "";
186+
187+
// Refresh map to show updated trusted player names
188+
if (onTrustChanged != null) {
189+
onTrustChanged.accept(ownerId);
190+
}
177191
}
178192

179193
@Override

0 commit comments

Comments
 (0)