From 69d6518b30a8950e0f490e16652c0f724ecf1d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sat, 21 Nov 2015 16:03:00 +0100 Subject: [PATCH] Improved setGroup method in Utils class, to replace legacy permissions code --- src/main/java/fr/xephi/authme/util/Utils.java | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 330e8d8e7..af15b8e5d 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -7,6 +7,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.events.AuthMeTeleportEvent; +import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -125,47 +126,49 @@ public class Utils { * @param group GroupType */ public static void setGroup(Player player, GroupType group) { - if (!Settings.isPermissionCheckEnabled) + if(!Settings.isPermissionCheckEnabled) return; - if (plugin.vaultGroupManagement == null) - return; - String currentGroup; - try { - currentGroup = plugin.vaultGroupManagement.getPrimaryGroup(player); - } catch (UnsupportedOperationException e) { - ConsoleLogger.showError("Your permission plugin (" + plugin.vaultGroupManagement.getName() + ") doesn't support the Group system... unhook!"); - plugin.vaultGroupManagement = null; - return; - } - switch (group) { - case UNREGISTERED: { - plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); - plugin.vaultGroupManagement.playerAddGroup(player, Settings.unRegisteredGroup); + + // TODO: Make sure a groups system is used! + + // Get the permissions manager, and make sure it's valid + PermissionsManager permsMan = plugin.getPermissionsManager(); + if(permsMan == null) + ConsoleLogger.showError("Failed to access permissions manager instance, shutting down."); + assert permsMan != null; + + switch(group) { + case UNREGISTERED: + // Remove the other group type groups, set the current group + permsMan.removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup)); + permsMan.addGroup(player, Settings.unRegisteredGroup); break; - } - case REGISTERED: { - plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); - plugin.vaultGroupManagement.playerAddGroup(player, Settings.getRegisteredGroup); + + case REGISTERED: + // Remove the other group type groups, set the current group + permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup)); + permsMan.addGroup(player, Settings.getRegisteredGroup); break; - } - case NOTLOGGEDIN: { - if (!useGroupSystem()) - break; - plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); - plugin.vaultGroupManagement.playerAddGroup(player, Settings.getUnloggedinGroup); + + case NOTLOGGEDIN: + // Remove the other group type groups, set the current group + permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup)); + permsMan.addGroup(player, Settings.getUnloggedinGroup); break; - } - case LOGGEDIN: { - if (!useGroupSystem()) - break; + + case LOGGEDIN: + // Get the limbo player data LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); - if (limbo == null) + if(limbo == null) break; + + // Get the players group String realGroup = limbo.getGroup(); - plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); - plugin.vaultGroupManagement.playerAddGroup(player, realGroup); + + // Remove the other group types groups, set the real group + permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup)); + permsMan.addGroup(player, realGroup); break; - } } }