From deea1f7655ddeb1b091e6d3642598c440484f05b Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sun, 4 Dec 2011 19:06:41 -0800 Subject: [PATCH] Moved PermissionsResolverServerListener into PermissionsResolverManager and got rid of some unnecessary methods. --- .../wepif/PermissionsResolverManager.java | 49 +++++++++--- .../PermissionsResolverServerListener.java | 80 ------------------- .../sk89q/wepif/WEPIFRuntimeException.java | 2 +- 3 files changed, 38 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/com/sk89q/wepif/PermissionsResolverServerListener.java diff --git a/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java b/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java index b87bf845e..abbb5ccbd 100644 --- a/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java +++ b/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java @@ -24,6 +24,9 @@ import com.sk89q.util.yaml.YAMLFormat; import com.sk89q.util.yaml.YAMLProcessor; import org.bukkit.OfflinePlayer; import org.bukkit.Server; +import org.bukkit.event.Event; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; import java.io.File; @@ -76,7 +79,6 @@ public class PermissionsResolverManager implements PermissionsResolver { private Server server; private PermissionsResolver permissionResolver; - private PermissionsResolverServerListener listener; private YAMLProcessor config; private Logger logger = Logger.getLogger(getClass().getCanonicalName()); private List> enabledResolvers = new ArrayList>(); @@ -93,7 +95,7 @@ public class PermissionsResolverManager implements PermissionsResolver { protected PermissionsResolverManager(Plugin plugin) { this.server = plugin.getServer(); - this.listener = new PermissionsResolverServerListener(this, plugin); + (new ServerListener()).register(plugin); // Register the events loadConfig(new File("wepif.yml")); findResolver(); @@ -168,6 +170,10 @@ public class PermissionsResolverManager implements PermissionsResolver { return permissionResolver.getGroups(player); } + public String getDetectionMessage() { + return "Using WEPIF for permissions"; + } + private boolean loadConfig(File file) { boolean isUpdated = false; if (!file.exists()) { @@ -253,20 +259,39 @@ public class PermissionsResolverManager implements PermissionsResolver { return isUpdated; } - boolean hasServerListener() { - return listener != null; - } - - void setServerListener(PermissionsResolverServerListener listener) { - this.listener = listener; - } - public static class MissingPluginException extends Exception { private static final long serialVersionUID = 7044832912491608706L; } - public String getDetectionMessage() { - return "Using WEPIF for permissions"; + class ServerListener extends org.bukkit.event.server.ServerListener { + + @Override + public void onPluginEnable(PluginEnableEvent event) { + Plugin plugin = event.getPlugin(); + String name = plugin.getDescription().getName(); + if (plugin instanceof PermissionsProvider) { + setPluginPermissionsResolver(plugin); + } else if ("Permissions".equals(name) || "PermissionsEx".equals(name)) { + load(); + } + } + + @Override + public void onPluginDisable(PluginDisableEvent event) { + String name = event.getPlugin().getDescription().getName(); + + if (event.getPlugin() instanceof PermissionsProvider + || "Permissions".equals(name) || "PermissionsEx".equals(name)) { + load(); + } + } + + void register(Plugin plugin) { + plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, + this, Event.Priority.Normal, plugin); + plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE, + this, Event.Priority.Normal, plugin); + } } } diff --git a/src/main/java/com/sk89q/wepif/PermissionsResolverServerListener.java b/src/main/java/com/sk89q/wepif/PermissionsResolverServerListener.java deleted file mode 100644 index e9bf935a7..000000000 --- a/src/main/java/com/sk89q/wepif/PermissionsResolverServerListener.java +++ /dev/null @@ -1,80 +0,0 @@ -// $Id$ -/* - * WorldEdit - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sk89q.wepif; - -import org.bukkit.event.Event; -import org.bukkit.event.Event.Priority; -import org.bukkit.event.server.PluginDisableEvent; -import org.bukkit.event.server.PluginEnableEvent; -import org.bukkit.event.server.ServerListener; -import org.bukkit.plugin.Plugin; - -public class PermissionsResolverServerListener extends ServerListener { - private PermissionsResolverManager manager; - - public PermissionsResolverServerListener(PermissionsResolverManager manager, Plugin plugin) { - this.manager = manager; - if (!manager.hasServerListener()) { - register(plugin); - } - } - - /** - * Called when a plugin is enabled - * - * @param event Relevant event details - */ - @Override - public void onPluginEnable(PluginEnableEvent event) { - Plugin plugin = event.getPlugin(); - String name = plugin.getDescription().getName(); - if (plugin instanceof PermissionsProvider) { - manager.setPluginPermissionsResolver(plugin); - } else if ("Permissions".equals(name) || "PermissionsEx".equals(name)) { - manager.findResolver(); - manager.load(); - } - } - - /** - * Called when a plugin is disabled - * - * @param event Relevant event details - */ - @Override - public void onPluginDisable(PluginDisableEvent event) { - Plugin plugin = event.getPlugin(); - String name = plugin.getDescription().getName(); - - if (plugin instanceof PermissionsProvider || "Permissions".equals(name) || "PermissionsEx".equals(name)) { - manager.findResolver(); - manager.load(); - } - } - - public void register(Plugin plugin) { - plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, - this, Priority.Normal, plugin); - plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE, - this, Priority.Normal, plugin); - manager.setServerListener(this); - } - -} diff --git a/src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java b/src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java index da15b98e0..954b938ec 100644 --- a/src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java +++ b/src/main/java/com/sk89q/wepif/WEPIFRuntimeException.java @@ -4,7 +4,7 @@ package com.sk89q.wepif; * @author zml2008 */ public class WEPIFRuntimeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 5092745960439109699L; public WEPIFRuntimeException(String message) { super(message);