Created it's own listener for the Permissions Manager

This commit is contained in:
Tim Vis'ee 2016-03-11 11:41:41 +01:00
parent ae9cd626a5
commit 44d50b1c59
3 changed files with 112 additions and 7 deletions

View File

@ -55,9 +55,6 @@ public class AuthMeServerListener implements Listener {
return;
}
// Call the onPluginDisable method in the permissions manager
this.plugin.getPermissionsManager().onPluginDisable(event);
String pluginName = pluginInstance.getName();
if (pluginName.equalsIgnoreCase("Essentials")) {
plugin.ess = null;
@ -89,9 +86,6 @@ public class AuthMeServerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPluginEnable(PluginEnableEvent event) {
// Call the onPluginEnable method in the permissions manager
this.plugin.getPermissionsManager().onPluginEnable(event);
String pluginName = event.getPlugin().getName();
if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) {
plugin.checkEssentials();

View File

@ -57,6 +57,10 @@ public class PermissionsManager implements PermissionsService {
* Logger instance.
*/
private Logger log;
/**
* The permissions manager Bukkit listener instance.
*/
private PermissionsManagerBukkitListener bukkitListener;
/**
* Type of permissions system that is currently used.
* Null if no permissions system is hooked and/or used.
@ -82,6 +86,21 @@ public class PermissionsManager implements PermissionsService {
this.server = server;
this.plugin = plugin;
this.log = log;
// Create and register the Bukkit listener on the server if it's valid
if(this.server != null) {
// Create the Bukkit listener
this.bukkitListener = new PermissionsManagerBukkitListener(this);
// Get the plugin manager instance
PluginManager pluginManager = this.server.getPluginManager();
// Register the Bukkit listener
pluginManager.registerEvents(this.bukkitListener, this.plugin);
// Show a status message.
//this.log.info("Started permission plugins state listener!");
}
}
/**
@ -263,7 +282,14 @@ public class PermissionsManager implements PermissionsService {
}
}
/**
* Get the permissions manager Bukkit listener instance.
*
* @return Listener instance.
*/
public PermissionsManagerBukkitListener getListener() {
return this.bukkitListener;
}
/**
* Check if the command sender has permission for the given permissions node. If no permissions system is used or

View File

@ -0,0 +1,85 @@
package fr.xephi.authme.permission;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
public class PermissionsManagerBukkitListener implements Listener {
/**
* The permissions manager instance.
*/
private PermissionsManager permissionsManager;
/**
* Whether the listener is enabled or not.
*/
private boolean enabled = true;
/**
* Constructor.\
*
* @param permissionsManager Permissions manager instance.
*/
public PermissionsManagerBukkitListener(PermissionsManager permissionsManager) {
this.permissionsManager = permissionsManager;
}
/**
* Check whether the listener is enabled.
*
* @return True if the listener is enabled.
*/
public boolean isEnabled() {
return this.enabled;
}
/**
* Set whether the listener is enabled.
* Disabling the listener will stop the event handling until it's enabled again.
*
* @param enabled True if enabled, false if disabled.
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Called when a plugin is enabled.
*
* @param event Event reference.
*/
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
// Make sure the listener is enabled
if(!isEnabled())
return;
// Make sure the permissions manager is set
if(this.permissionsManager == null)
return;
// Call the onPluginEnable method in the permissions manager
permissionsManager.onPluginEnable(event);
}
/**
* Called when a plugin is disabled.
*
* @param event Event reference.
*/
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
// Make sure the listener is enabled
if(!isEnabled())
return;
// Make sure the permissions manager is set
if(this.permissionsManager == null)
return;
// Call the onPluginDisable method in the permissions manager
permissionsManager.onPluginDisable(event);
}
}