Skip to content

Commit

Permalink
experimental player flag handler reliability patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 2, 2021
1 parent ff520e2 commit eba02f6
Showing 1 changed file with 24 additions and 8 deletions.
Expand Up @@ -136,8 +136,12 @@ public void run() {
}

public static void loadFlags(UUID id, CachedPlayerFlag cache) {
cache.tracker = SavableMapFlagTracker.loadFlagFile(new File(dataFolder, id.toString()).getPath());
cache.loadingNow = false;
try {
cache.tracker = SavableMapFlagTracker.loadFlagFile(new File(dataFolder, id.toString()).getPath());
}
finally {
cache.loadingNow = false;
}
}

public static AbstractFlagTracker getTrackerFor(UUID id) {
Expand Down Expand Up @@ -166,12 +170,24 @@ public static AbstractFlagTracker getTrackerFor(UUID id) {
loadFlags(id, cache);
}
else {
while (cache.loadingNow) {
try {
Thread.sleep(1);
}
catch (InterruptedException ex) {
Debug.echoError(ex);
if (cache.loadingNow) {
long start = System.currentTimeMillis();
while (cache.loadingNow) {
if (System.currentTimeMillis() - start > 15 * 1000) {
Debug.echoError("Flag loading timeout, errors may follow");
cache = playerFlagTrackerCache.remove(id);
if (cache != null && !cache.loadingNow) {
return cache.tracker;
}
return null;
}
try {
Thread.sleep(1);
}
catch (InterruptedException ex) {
Debug.echoError(ex);
return cache.tracker;
}
}
}
}
Expand Down

0 comments on commit eba02f6

Please sign in to comment.