mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-09-08 05:10:55 +02:00
Avoid calls to the Bukkit singleton
This commit is contained in:
@@ -189,9 +189,9 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
||||
protected void setupPlatformHooks() {
|
||||
// inject our own custom permission maps
|
||||
Runnable[] injectors = new Runnable[]{
|
||||
new InjectorSubscriptionMap(this),
|
||||
new InjectorPermissionMap(this),
|
||||
new InjectorDefaultsMap(this),
|
||||
new InjectorSubscriptionMap(this)::inject,
|
||||
new InjectorPermissionMap(this)::inject,
|
||||
new InjectorDefaultsMap(this)::inject,
|
||||
new PermissibleMonitoringInjector(this, PermissibleMonitoringInjector.Mode.INJECT)
|
||||
};
|
||||
|
||||
@@ -317,9 +317,9 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
||||
}
|
||||
|
||||
// uninject custom maps
|
||||
InjectorSubscriptionMap.uninject();
|
||||
InjectorPermissionMap.uninject();
|
||||
InjectorDefaultsMap.uninject();
|
||||
new InjectorSubscriptionMap(this).uninject();
|
||||
new InjectorPermissionMap(this).uninject();
|
||||
new InjectorDefaultsMap(this).uninject();
|
||||
new PermissibleMonitoringInjector(this, PermissibleMonitoringInjector.Mode.UNINJECT).run();
|
||||
|
||||
// unhook vault
|
||||
|
@@ -27,7 +27,6 @@ package me.lucko.luckperms.bukkit.inject.server;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
@@ -41,7 +40,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Injects a {@link LuckPermsDefaultsMap} info the {@link PluginManager}.
|
||||
*/
|
||||
public class InjectorDefaultsMap implements Runnable {
|
||||
public class InjectorDefaultsMap {
|
||||
private static final Field DEFAULT_PERMISSIONS_FIELD;
|
||||
|
||||
static {
|
||||
@@ -61,10 +60,9 @@ public class InjectorDefaultsMap implements Runnable {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void inject() {
|
||||
try {
|
||||
LuckPermsDefaultsMap defaultsMap = inject();
|
||||
LuckPermsDefaultsMap defaultsMap = tryInject();
|
||||
if (defaultsMap != null) {
|
||||
this.plugin.setDefaultPermissionMap(defaultsMap);
|
||||
}
|
||||
@@ -74,7 +72,7 @@ public class InjectorDefaultsMap implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private LuckPermsDefaultsMap inject() throws Exception {
|
||||
private LuckPermsDefaultsMap tryInject() throws Exception {
|
||||
Objects.requireNonNull(DEFAULT_PERMISSIONS_FIELD, "DEFAULT_PERMISSIONS_FIELD");
|
||||
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
|
||||
|
||||
@@ -98,11 +96,11 @@ public class InjectorDefaultsMap implements Runnable {
|
||||
return newMap;
|
||||
}
|
||||
|
||||
public static void uninject() {
|
||||
public void uninject() {
|
||||
try {
|
||||
Objects.requireNonNull(DEFAULT_PERMISSIONS_FIELD, "DEFAULT_PERMISSIONS_FIELD");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
return;
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ package me.lucko.luckperms.bukkit.inject.server;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
@@ -40,7 +39,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* Injects a {@link LuckPermsPermissionMap} into the {@link PluginManager}.
|
||||
*/
|
||||
public class InjectorPermissionMap implements Runnable {
|
||||
public class InjectorPermissionMap {
|
||||
private static final Field PERMISSIONS_FIELD;
|
||||
|
||||
static {
|
||||
@@ -60,10 +59,9 @@ public class InjectorPermissionMap implements Runnable {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void inject() {
|
||||
try {
|
||||
LuckPermsPermissionMap permissionMap = inject();
|
||||
LuckPermsPermissionMap permissionMap = tryInject();
|
||||
if (permissionMap != null) {
|
||||
this.plugin.setPermissionMap(permissionMap);
|
||||
}
|
||||
@@ -73,7 +71,7 @@ public class InjectorPermissionMap implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private LuckPermsPermissionMap inject() throws Exception {
|
||||
private LuckPermsPermissionMap tryInject() throws Exception {
|
||||
Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
|
||||
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
|
||||
|
||||
@@ -97,11 +95,11 @@ public class InjectorPermissionMap implements Runnable {
|
||||
return newMap;
|
||||
}
|
||||
|
||||
public static void uninject() {
|
||||
public void uninject() {
|
||||
try {
|
||||
Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
return;
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ package me.lucko.luckperms.bukkit.inject.server;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
@@ -39,7 +38,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* Injects a {@link LuckPermsSubscriptionMap} into the {@link PluginManager}.
|
||||
*/
|
||||
public class InjectorSubscriptionMap implements Runnable {
|
||||
public class InjectorSubscriptionMap {
|
||||
private static final Field PERM_SUBS_FIELD;
|
||||
|
||||
static {
|
||||
@@ -59,10 +58,9 @@ public class InjectorSubscriptionMap implements Runnable {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void inject() {
|
||||
try {
|
||||
LuckPermsSubscriptionMap subscriptionMap = inject();
|
||||
LuckPermsSubscriptionMap subscriptionMap = tryInject();
|
||||
if (subscriptionMap != null) {
|
||||
this.plugin.setSubscriptionMap(subscriptionMap);
|
||||
}
|
||||
@@ -72,7 +70,7 @@ public class InjectorSubscriptionMap implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private LuckPermsSubscriptionMap inject() throws Exception {
|
||||
private LuckPermsSubscriptionMap tryInject() throws Exception {
|
||||
Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
|
||||
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
|
||||
|
||||
@@ -100,11 +98,11 @@ public class InjectorSubscriptionMap implements Runnable {
|
||||
return newMap;
|
||||
}
|
||||
|
||||
public static void uninject() {
|
||||
public void uninject() {
|
||||
try {
|
||||
Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
return;
|
||||
}
|
||||
|
@@ -55,7 +55,6 @@ import net.luckperms.api.query.Flag;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -100,7 +99,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
|
||||
Objects.requireNonNull(player, "player");
|
||||
|
||||
// are they online?
|
||||
Player onlinePlayer = Bukkit.getPlayerExact(player);
|
||||
Player onlinePlayer = this.plugin.getBootstrap().getServer().getPlayerExact(player);
|
||||
if (onlinePlayer != null) {
|
||||
return onlinePlayer.getUniqueId();
|
||||
}
|
||||
@@ -112,7 +111,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
|
||||
}
|
||||
|
||||
// are we on the main thread?
|
||||
if (!this.plugin.getBootstrap().isServerStarting() && Bukkit.isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
|
||||
if (!this.plugin.getBootstrap().isServerStarting() && this.plugin.getBootstrap().getServer().isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
|
||||
throw new RuntimeException(
|
||||
"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" +
|
||||
@@ -163,7 +162,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
|
||||
}
|
||||
|
||||
// are we on the main thread?
|
||||
if (!this.plugin.getBootstrap().isServerStarting() && Bukkit.isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
|
||||
if (!this.plugin.getBootstrap().isServerStarting() && this.plugin.getBootstrap().getServer().isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
|
||||
throw new RuntimeException(
|
||||
"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" +
|
||||
|
@@ -82,18 +82,13 @@ public class StorageFactory {
|
||||
} else {
|
||||
StorageType type = this.plugin.getConfiguration().get(ConfigKeys.STORAGE_METHOD);
|
||||
this.plugin.getLogger().info("Loading storage provider... [" + type.name() + "]");
|
||||
storage = makeInstance(type);
|
||||
storage = new Storage(this.plugin, createNewImplementation(type));
|
||||
}
|
||||
|
||||
storage.init();
|
||||
return storage;
|
||||
}
|
||||
|
||||
private Storage makeInstance(StorageType type) {
|
||||
// make a base implementation
|
||||
return new Storage(this.plugin, createNewImplementation(type));
|
||||
}
|
||||
|
||||
private StorageImplementation createNewImplementation(StorageType method) {
|
||||
switch (method) {
|
||||
case CUSTOM:
|
||||
|
Reference in New Issue
Block a user