mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-03-10 22:03:57 +01:00
Refactor VaultHookManager
This commit is contained in:
parent
2fd2f4fedb
commit
b81e8a40a4
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user