diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index d8bc53377..4e1c4253f 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -199,12 +199,9 @@ public class PermissionsManager { */ public void onPluginEnable(String pluginName) { // Check if any known permissions system is enabling - for (PermissionsSystemType permissionsSystemType : PermissionsSystemType.values()) { - if (permissionsSystemType.isPermissionSystem(pluginName)) { - ConsoleLogger.info(pluginName + " plugin enabled, dynamically updating permissions hooks!"); - setup(); - break; - } + if (PermissionsSystemType.isPermissionSystem(pluginName)) { + ConsoleLogger.info(pluginName + " plugin enabled, dynamically updating permissions hooks!"); + setup(); } } @@ -215,12 +212,9 @@ public class PermissionsManager { */ public void onPluginDisable(String pluginName) { // Check if any known permission system is being disabled - for (PermissionsSystemType permissionsSystemType : PermissionsSystemType.values()) { - if (permissionsSystemType.isPermissionSystem(pluginName)) { - ConsoleLogger.info(pluginName + " plugin disabled, updating hooks!"); - setup(); - break; - } + if (PermissionsSystemType.isPermissionSystem(pluginName)) { + ConsoleLogger.info(pluginName + " plugin disabled, updating hooks!"); + setup(); } } diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java b/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java index a65ac50cf..88b09d193 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java @@ -90,7 +90,12 @@ public enum PermissionsSystemType { * @param name The name of the plugin to check. * @return If the plugin is a valid permissions system. */ - public boolean isPermissionSystem(String name) { - return name.equals(pluginName); + public static boolean isPermissionSystem(String name) { + for (PermissionsSystemType permissionsSystemType : values()) { + if (permissionsSystemType.pluginName.equals(name)) { + return true; + } + } + return false; } } diff --git a/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java b/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java new file mode 100644 index 000000000..809014ada --- /dev/null +++ b/src/test/java/fr/xephi/authme/permission/PermissionsSystemTypeTest.java @@ -0,0 +1,45 @@ +package fr.xephi.authme.permission; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +/** + * Test for {@link PermissionsSystemType}. + */ +public class PermissionsSystemTypeTest { + + @Test + public void shouldHaveDefinedAndUniqueNames() { + // given / when / then + List names = new ArrayList<>(PermissionsSystemType.values().length); + List pluginNames = new ArrayList<>(PermissionsSystemType.values().length); + + for (PermissionsSystemType system : PermissionsSystemType.values()) { + assertThat("Name for enum entry '" + system + "' is not null", + system.getName(), not(nullValue())); + assertThat("Plugin name for enum entry '" + system + "' is not null", + system.getPluginName(), not(nullValue())); + assertThat("Only one enum entry has name '" + system.getName() + "'", + names, not(hasItem(system.getName()))); + assertThat("Only one enum entry has plugin name '" + system.getPluginName() + "'", + pluginNames, not(hasItem(system.getPluginName()))); + names.add(system.getName()); + pluginNames.add(system.getPluginName()); + } + } + + @Test + public void shouldRecognizePermissionSystemType() { + assertThat(PermissionsSystemType.isPermissionSystem("bogus"), equalTo(false)); + assertThat(PermissionsSystemType.isPermissionSystem("PermissionsBukkit"), equalTo(true)); + } + +}