Don't trigger Vault primary thread checks whilst the server is starting up
This commit is contained in:
parent
9fd2028d9f
commit
51b7bb93e2
@ -85,6 +85,7 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
|
|||||||
// load/enable latches
|
// load/enable latches
|
||||||
private final CountDownLatch loadLatch = new CountDownLatch(1);
|
private final CountDownLatch loadLatch = new CountDownLatch(1);
|
||||||
private final CountDownLatch enableLatch = new CountDownLatch(1);
|
private final CountDownLatch enableLatch = new CountDownLatch(1);
|
||||||
|
private boolean serverStarting = true;
|
||||||
|
|
||||||
// if the plugin has been loaded on an incompatible version
|
// if the plugin has been loaded on an incompatible version
|
||||||
private boolean incompatibleVersion = false;
|
private boolean incompatibleVersion = false;
|
||||||
@ -150,6 +151,9 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
|
|||||||
this.startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
this.plugin.enable();
|
this.plugin.enable();
|
||||||
|
|
||||||
|
// schedule a task to update the 'serverStarting' flag
|
||||||
|
getServer().getScheduler().runTask(this, () -> this.serverStarting = false);
|
||||||
} finally {
|
} finally {
|
||||||
this.enableLatch.countDown();
|
this.enableLatch.countDown();
|
||||||
}
|
}
|
||||||
@ -162,6 +166,7 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.plugin.disable();
|
this.plugin.disable();
|
||||||
|
this.serverStarting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -174,6 +179,10 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
|
|||||||
return this.loadLatch;
|
return this.loadLatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isServerStarting() {
|
||||||
|
return this.serverStarting;
|
||||||
|
}
|
||||||
|
|
||||||
// provide information about the plugin
|
// provide information about the plugin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,15 +95,15 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// are we on the main thread?
|
// 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(
|
throw new RuntimeException(
|
||||||
"Unable to lookup a UUID for '" + player + "'. \n" +
|
"The operation to lookup a UUID for '" + player + "' was cancelled by LuckPerms. This is NOT a bug. \n" +
|
||||||
"This request was made on the main server thread. \n" +
|
"The lookup request was made on the main server thread. It is not safe to execute a request to \n" +
|
||||||
"It is not safe to execute a request to load username data from the database in this context. \n" +
|
"load username data from the database in this context. \n" +
|
||||||
"If you are a plugin author, please either make your request asynchronously, \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" +
|
"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" +
|
"Alternatively, server admins can disable this catch by setting 'vault-unsafe-lookups' to true \n" +
|
||||||
"but should consider the consequences (lag) before doing so."
|
"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?
|
// 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(
|
throw new RuntimeException(
|
||||||
"Unable to obtain user data for '" + uuid + "'. \n" +
|
"The operation to load user data for '" + uuid + "' was cancelled by LuckPerms. This is NOT a bug. \n" +
|
||||||
"This request was made on the main server thread. \n" +
|
"The lookup request was made on the main server thread. It is not safe to execute a request to \n" +
|
||||||
"It is not safe to execute a request to load user data from the database in this context. \n" +
|
"load username data from the database in this context. \n" +
|
||||||
"If you are a plugin author, please consider making your request asynchronously. \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" +
|
"Alternatively, server admins can disable this catch by setting 'vault-unsafe-lookups' to true \n" +
|
||||||
"but should consider the consequences (lag) before doing so."
|
"in the LP config, but should consider the consequences (lag) before doing so."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user