Refactor VaultHookManager

This commit is contained in:
Luck 2019-04-22 10:27:29 +01:00
parent 2fd2f4fedb
commit b81e8a40a4
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 41 additions and 34 deletions

View File

@ -218,8 +218,8 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
try { try {
if (force || this.bootstrap.getServer().getPluginManager().isPluginEnabled("Vault")) { if (force || this.bootstrap.getServer().getPluginManager().isPluginEnabled("Vault")) {
this.vaultHookManager = new VaultHookManager(); this.vaultHookManager = new VaultHookManager(this);
this.vaultHookManager.hook(this); this.vaultHookManager.hook();
getLogger().info("Registered Vault permission & chat hook."); getLogger().info("Registered Vault permission & chat hook.");
} }
} catch (Exception e) { } catch (Exception e) {
@ -323,29 +323,29 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
// unhook vault // unhook vault
if (this.vaultHookManager != null) { if (this.vaultHookManager != null) {
this.vaultHookManager.unhook(this); this.vaultHookManager.unhook();
} }
} }
public void refreshAutoOp(Player player, boolean callerIsSync) { public void refreshAutoOp(Player player, boolean callerIsSync) {
if (getConfiguration().get(ConfigKeys.AUTO_OP)) { if (!getConfiguration().get(ConfigKeys.AUTO_OP)) {
User user = getUserManager().getIfLoaded(player.getUniqueId()); return;
if (user == null) { }
if (callerIsSync) {
player.setOp(false);
} else {
this.bootstrap.getScheduler().executeSync(() -> player.setOp(false));
}
return;
}
User user = getUserManager().getIfLoaded(player.getUniqueId());
boolean value;
if (user != null) {
Map<String, Boolean> permData = user.getCachedData().getPermissionData(this.contextManager.getApplicableContexts(player)).getImmutableBacking(); Map<String, Boolean> permData = user.getCachedData().getPermissionData(this.contextManager.getApplicableContexts(player)).getImmutableBacking();
boolean value = permData.getOrDefault("luckperms.autoop", false); value = permData.getOrDefault("luckperms.autoop", false);
if (callerIsSync) { } else {
player.setOp(value); value = false;
} else { }
this.bootstrap.getScheduler().executeSync(() -> player.setOp(value));
} 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 * Handles hooking with the Vault API
*/ */
public class VaultHookManager { public class VaultHookManager {
private final LPBukkitPlugin plugin;
private LuckPermsVaultChat chat = null; private LuckPermsVaultChat chat = null;
private LuckPermsVaultPermission permission = null; private LuckPermsVaultPermission permission = null;
public VaultHookManager(LPBukkitPlugin plugin) {
this.plugin = plugin;
}
/** /**
* Registers the LuckPerms implementation of {@link Permission} and {@link Chat} with * Registers the LuckPerms implementation of {@link Permission} and {@link Chat} with
* the service manager. * the service manager.
*
* @param plugin the plugin
*/ */
public void hook(LPBukkitPlugin plugin) { public void hook() {
try { try {
if (this.permission == null) { if (this.permission == null) {
this.permission = new LuckPermsVaultPermission(plugin); this.permission = new LuckPermsVaultPermission(plugin);
@ -67,10 +71,8 @@ public class VaultHookManager {
/** /**
* Unregisters the LuckPerms Vault hooks, if present. * 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(); final ServicesManager sm = plugin.getBootstrap().getServer().getServicesManager();
if (this.permission != null) { if (this.permission != null) {

View File

@ -270,16 +270,21 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
} }
public void refreshAutoOp(Player player) { public void refreshAutoOp(Player player) {
if (getConfiguration().get(ConfigKeys.AUTO_OP)) { if (!getConfiguration().get(ConfigKeys.AUTO_OP)) {
User user = getUserManager().getIfLoaded(player.getUniqueId()); return;
if (user == null) {
player.setOp(false);
return;
}
Map<String, Boolean> permData = user.getCachedData().getPermissionData(this.contextManager.getApplicableContexts(player)).getImmutableBacking();
player.setOp(permData.getOrDefault("luckperms.autoop", false));
} }
User user = getUserManager().getIfLoaded(player.getUniqueId());
boolean value;
if (user != null) {
Map<String, Boolean> permData = user.getCachedData().getPermissionData(this.contextManager.getApplicableContexts(player)).getImmutableBacking();
value = permData.getOrDefault("luckperms.autoop", false);
} else {
value = false;
}
player.setOp(value);
} }
private File resolveConfig() { private File resolveConfig() {