Skip to content

Commit

Permalink
Fix race condition and exception when registering check permissions d…
Browse files Browse the repository at this point in the history
…uring rapid consecutive player joins on server start
  • Loading branch information
crimilo authored and Axionize committed Nov 22, 2024
1 parent e389e4b commit 2b50164
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/ac/grim/grimac/manager/CheckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;

import java.util.concurrent.atomic.AtomicBoolean;

public class CheckManager {
private static boolean inited;
private static final AtomicBoolean initedAtomic = new AtomicBoolean(false);

ClassToInstanceMap<PacketCheck> packetChecks;
ClassToInstanceMap<PositionCheck> positionCheck;
Expand Down Expand Up @@ -364,7 +367,12 @@ public <T extends PostPredictionCheck> T getPostPredictionCheck(Class<T> check)
}

private void init() {
// Fast non-thread safe check
if (inited) return;
// Slow thread safe check
if (!initedAtomic.compareAndSet(false, true)) return;
inited = true;

for (AbstractCheck check : allChecks.values()) {
if (check.getCheckName() != null) {
String permissionName = "grim.exempt." + check.getCheckName().toLowerCase();
Expand All @@ -377,7 +385,5 @@ private void init() {
}
}
}

inited = true;
}
}

0 comments on commit 2b50164

Please sign in to comment.