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 committed Nov 20, 2024
1 parent 187d70d commit 67a25de
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 @@ -47,8 +47,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 @@ -336,7 +339,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 @@ -349,7 +357,5 @@ private void init() {
}
}
}

inited = true;
}
}

0 comments on commit 67a25de

Please sign in to comment.