1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-09-03 11:22:33 +02:00

Refactor VaultHookManager

This commit is contained in:
Luck
2019-04-22 10:27:29 +01:00
parent 2fd2f4fedb
commit b81e8a40a4
3 changed files with 41 additions and 34 deletions

View File

@@ -218,8 +218,8 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
try {
if (force || this.bootstrap.getServer().getPluginManager().isPluginEnabled("Vault")) {
this.vaultHookManager = new VaultHookManager();
this.vaultHookManager.hook(this);
this.vaultHookManager = new VaultHookManager(this);
this.vaultHookManager.hook();
getLogger().info("Registered Vault permission & chat hook.");
}
} catch (Exception e) {
@@ -323,29 +323,29 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
// unhook vault
if (this.vaultHookManager != null) {
this.vaultHookManager.unhook(this);
this.vaultHookManager.unhook();
}
}
public void refreshAutoOp(Player player, boolean callerIsSync) {
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) {
if (callerIsSync) {
player.setOp(false);
} else {
this.bootstrap.getScheduler().executeSync(() -> player.setOp(false));
}
return;
}
if (!getConfiguration().get(ConfigKeys.AUTO_OP)) {
return;
}
User user = getUserManager().getIfLoaded(player.getUniqueId());
boolean value;
if (user != null) {
Map<String, Boolean> permData = user.getCachedData().getPermissionData(this.contextManager.getApplicableContexts(player)).getImmutableBacking();
boolean value = permData.getOrDefault("luckperms.autoop", false);
if (callerIsSync) {
player.setOp(value);
} else {
this.bootstrap.getScheduler().executeSync(() -> player.setOp(value));
}
value = permData.getOrDefault("luckperms.autoop", false);
} else {
value = false;
}
if (callerIsSync) {
player.setOp(value);
} else {
this.bootstrap.getScheduler().executeSync(() -> player.setOp(value));
}
}

View File

@@ -37,16 +37,20 @@ import org.bukkit.plugin.ServicesManager;
* Handles hooking with the Vault API
*/
public class VaultHookManager {
private final LPBukkitPlugin plugin;
private LuckPermsVaultChat chat = null;
private LuckPermsVaultPermission permission = null;
public VaultHookManager(LPBukkitPlugin plugin) {
this.plugin = plugin;
}
/**
* Registers the LuckPerms implementation of {@link Permission} and {@link Chat} with
* the service manager.
*
* @param plugin the plugin
*/
public void hook(LPBukkitPlugin plugin) {
public void hook() {
try {
if (this.permission == null) {
this.permission = new LuckPermsVaultPermission(plugin);
@@ -67,10 +71,8 @@ public class VaultHookManager {
/**
* Unregisters the LuckPerms Vault hooks, if present.
*
* @param plugin the plugin
*/
public void unhook(LPBukkitPlugin plugin) {
public void unhook() {
final ServicesManager sm = plugin.getBootstrap().getServer().getServicesManager();
if (this.permission != null) {