Don't trigger Vault primary thread checks whilst the server is starting up

This commit is contained in:
Luck 2018-09-20 10:44:04 +01:00
parent 9fd2028d9f
commit 51b7bb93e2
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 21 additions and 12 deletions

View File

@ -85,6 +85,7 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
// load/enable latches
private final CountDownLatch loadLatch = new CountDownLatch(1);
private final CountDownLatch enableLatch = new CountDownLatch(1);
private boolean serverStarting = true;
// if the plugin has been loaded on an incompatible version
private boolean incompatibleVersion = false;
@ -150,6 +151,9 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
this.startTime = System.currentTimeMillis();
try {
this.plugin.enable();
// schedule a task to update the 'serverStarting' flag
getServer().getScheduler().runTask(this, () -> this.serverStarting = false);
} finally {
this.enableLatch.countDown();
}
@ -162,6 +166,7 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
}
this.plugin.disable();
this.serverStarting = true;
}
@Override
@ -174,6 +179,10 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
return this.loadLatch;
}
public boolean isServerStarting() {
return this.serverStarting;
}
// provide information about the plugin
@Override

View File

@ -95,15 +95,15 @@ public class VaultPermissionHook extends AbstractVaultPermission {
}
// are we on the main thread?
if (Bukkit.isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
if (!plugin.getBootstrap().isServerStarting() && Bukkit.isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
throw new RuntimeException(
"Unable to lookup a UUID for '" + player + "'. \n" +
"This request was made on the main server thread. \n" +
"It is not safe to execute a request to load username data from the database in this context. \n" +
"The operation to lookup a UUID for '" + player + "' was cancelled by LuckPerms. This is NOT a bug. \n" +
"The lookup request was made on the main server thread. It is not safe to execute a request to \n" +
"load username data from the database in this context. \n" +
"If you are a plugin author, please either make your request asynchronously, \n" +
"or provide an 'OfflinePlayer' object with the UUID already populated. \n" +
"Server admins can disable this catch by setting 'vault-unsafe-lookups' to true in the LP config, \n" +
"but should consider the consequences (lag) before doing so."
"Alternatively, server admins can disable this catch by setting 'vault-unsafe-lookups' to true \n" +
"in the LP config, but should consider the consequences (lag) before doing so."
);
}
@ -131,14 +131,14 @@ public class VaultPermissionHook extends AbstractVaultPermission {
}
// are we on the main thread?
if (Bukkit.isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
if (!plugin.getBootstrap().isServerStarting() && Bukkit.isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
throw new RuntimeException(
"Unable to obtain user data for '" + uuid + "'. \n" +
"This request was made on the main server thread. \n" +
"It is not safe to execute a request to load user data from the database in this context. \n" +
"The operation to load user data for '" + uuid + "' was cancelled by LuckPerms. This is NOT a bug. \n" +
"The lookup request was made on the main server thread. It is not safe to execute a request to \n" +
"load username data from the database in this context. \n" +
"If you are a plugin author, please consider making your request asynchronously. \n" +
"Server admins can disable this catch by setting 'vault-unsafe-lookups' to true in the LP config, \n" +
"but should consider the consequences (lag) before doing so."
"Alternatively, server admins can disable this catch by setting 'vault-unsafe-lookups' to true \n" +
"in the LP config, but should consider the consequences (lag) before doing so."
);
}