Skip to content

Commit

Permalink
Merge pull request #1811 from crimilo/2.0
Browse files Browse the repository at this point in the history
Fix race condition and exception when registering check permissions during rapid consecutive player joins on server start
  • Loading branch information
AoElite authored Nov 21, 2024
2 parents 187d70d + 67a25de commit e5bd42c
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 e5bd42c

Please sign in to comment.