Improved setGroup method in Utils class, to replace legacy permissions code

This commit is contained in:
Tim Visée 2015-11-21 16:03:00 +01:00
parent 973c683c90
commit 69d6518b30

View File

@ -7,6 +7,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -125,49 +126,51 @@ public class Utils {
* @param group GroupType * @param group GroupType
*/ */
public static void setGroup(Player player, GroupType group) { public static void setGroup(Player player, GroupType group) {
if (!Settings.isPermissionCheckEnabled) if(!Settings.isPermissionCheckEnabled)
return; return;
if (plugin.vaultGroupManagement == null)
return; // TODO: Make sure a groups system is used!
String currentGroup;
try { // Get the permissions manager, and make sure it's valid
currentGroup = plugin.vaultGroupManagement.getPrimaryGroup(player); PermissionsManager permsMan = plugin.getPermissionsManager();
} catch (UnsupportedOperationException e) { if(permsMan == null)
ConsoleLogger.showError("Your permission plugin (" + plugin.vaultGroupManagement.getName() + ") doesn't support the Group system... unhook!"); ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
plugin.vaultGroupManagement = null; assert permsMan != null;
return;
} switch(group) {
switch (group) { case UNREGISTERED:
case UNREGISTERED: { // Remove the other group type groups, set the current group
plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); permsMan.removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
plugin.vaultGroupManagement.playerAddGroup(player, Settings.unRegisteredGroup); permsMan.addGroup(player, Settings.unRegisteredGroup);
break; break;
}
case REGISTERED: { case REGISTERED:
plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); // Remove the other group type groups, set the current group
plugin.vaultGroupManagement.playerAddGroup(player, Settings.getRegisteredGroup); permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup));
permsMan.addGroup(player, Settings.getRegisteredGroup);
break; break;
}
case NOTLOGGEDIN: { case NOTLOGGEDIN:
if (!useGroupSystem()) // Remove the other group type groups, set the current group
break; permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup));
plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); permsMan.addGroup(player, Settings.getUnloggedinGroup);
plugin.vaultGroupManagement.playerAddGroup(player, Settings.getUnloggedinGroup);
break;
}
case LOGGEDIN: {
if (!useGroupSystem())
break; break;
case LOGGEDIN:
// Get the limbo player data
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
if (limbo == null) if(limbo == null)
break; break;
// Get the players group
String realGroup = limbo.getGroup(); 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; break;
} }
} }
}
/** /**
* Method addNormal. * Method addNormal.