Skip to content

Commit

Permalink
add async load on logic option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 7, 2020
1 parent fe73b7a commit e1b7998
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Expand Up @@ -429,6 +429,7 @@ public void run() {
if (!PlayerFlagHandler.dataFolder.exists()) {
PlayerFlagHandler.dataFolder.mkdir();
}
Bukkit.getPluginManager().registerEvents(new PlayerFlagHandler(), this);
new BukkitRunnable() {
@Override
public void run() {
Expand Down
Expand Up @@ -86,6 +86,7 @@ public static void refillCache() {
cache_warningRate = config.getLong("Tags.Warning rate", 10000);
cache_packetInterception = config.getBoolean("Packets.Interception", true);
PlayerFlagHandler.cacheTimeoutSeconds = config.getLong("Saves.Offline player cache timeout", 300);
PlayerFlagHandler.asyncPreload = config.getBoolean("Saves.Load async on login", true);
}

private static boolean cache_showDebug = true, cache_overrideHelp, cache_useDefaultScriptPath,
Expand Down
Expand Up @@ -218,5 +218,26 @@ public static void saveFlags(UUID id, String flagData) {
Debug.echoError(ex);
}
}

@EventHandler
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
if (!asyncPreload) {
return;
}
UUID id = event.getUniqueId();
if (!Bukkit.isPrimaryThread()) {
Future<Future> future = Bukkit.getScheduler().callSyncMethod(Denizen.getInstance(), () -> {
return loadAsync(id);
});
try {
Future newFuture = future.get(15, TimeUnit.SECONDS);
if (newFuture != null) {
newFuture.get(15, TimeUnit.SECONDS);
}
}
catch (Throwable ex) {
Debug.echoError(ex);
}
}
}
}
2 changes: 2 additions & 0 deletions plugin/src/main/resources/config.yml
Expand Up @@ -182,6 +182,8 @@ Saves:
# How long (in seconds) before the offline player flag cache times out.
# Set to -1 to keep offline player flags loaded perpetually, or to 0 to never cache.
Offline player cache timeout: 300
# When set to 'true', player data will be loaded offthread during the login sequence, to avoid adding load to the server while players join.
Load async on login: true

Packets:
# Whether to allow Denizen to intercept packets from and to player clients.
Expand Down

0 comments on commit e1b7998

Please sign in to comment.