Skip to content

Commit

Permalink
Fix: look up from trackers map with correct type, resolves trackers n…
Browse files Browse the repository at this point in the history
…ot being updated when invalidated
  • Loading branch information
Gegy committed Nov 16, 2024
1 parent d4de925 commit 33a8623
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class ProtectionPlayerTracker {
@SubscribeEvent(priority = EventPriority.HIGH)
public static void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) {
if (event.getEntity() instanceof final ServerPlayer player) {
INSTANCE.clearTracker(player, player.getUUID());
INSTANCE.clearTracker(player);
}
}

Expand All @@ -53,7 +53,7 @@ public void invalidate() {
}

private void onPlayerChangeDimension(ServerPlayer player) {
final Tracker tracker = trackers.get(player);
final Tracker tracker = trackers.get(player.getUUID());
if (tracker != null) {
updateTracker(player, tracker);
}
Expand All @@ -62,15 +62,15 @@ private void onPlayerChangeDimension(ServerPlayer player) {
private void tickPlayer(final ServerPlayer player) {
final UUID playerId = player.getUUID();
if (queuedReset.remove(playerId)) {
final Tracker tracker = trackers.get(player);
final Tracker tracker = trackers.get(playerId);
if (tracker != null) {
updateTracker(player, tracker);
// We already updated the tracker state for this tick, so we don't need to check it again
return;
}
}

final Tracker tracker = getOrInitializeTracker(player, playerId);
final Tracker tracker = getOrInitializeTracker(player);

final long blockPos = player.blockPosition().asLong();
if (blockPos != tracker.lastBlockPos) {
Expand All @@ -79,12 +79,13 @@ private void tickPlayer(final ServerPlayer player) {
}
}

private Tracker getOrInitializeTracker(ServerPlayer player, UUID uuid) {
Tracker tracker = trackers.get(uuid);
private Tracker getOrInitializeTracker(ServerPlayer player) {
UUID playerId = player.getUUID();
Tracker tracker = trackers.get(playerId);
if (tracker == null) {
tracker = new Tracker();
updateTracker(player, tracker);
trackers.put(uuid, tracker);
trackers.put(playerId, tracker);
}
return tracker;
}
Expand Down Expand Up @@ -124,8 +125,8 @@ private void updateTracker(final ServerPlayer player, final Tracker tracker) {
}
}

private void clearTracker(ServerPlayer player, UUID uuid) {
Tracker tracker = trackers.remove(uuid);
private void clearTracker(ServerPlayer player) {
Tracker tracker = trackers.remove(player.getUUID());
if (tracker != null) {
for (AuthorityBehavior behavior : tracker.behaviors) {
behavior.onPlayerExit(player);
Expand Down

0 comments on commit 33a8623

Please sign in to comment.