diff --git a/pom.xml b/pom.xml
index 93fdb5f2e..1a9a64396 100644
--- a/pom.xml
+++ b/pom.xml
@@ -606,7 +606,7 @@
true
-
+
junit
junit
diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java
index 3b8d9f142..69112ea20 100644
--- a/src/main/java/fr/xephi/authme/AuthMe.java
+++ b/src/main/java/fr/xephi/authme/AuthMe.java
@@ -60,6 +60,7 @@ import net.milkbowl.vault.permission.Permission;
import net.minelink.ctplus.CombatTagPlus;
/**
+ * The AuthMe main class.
*/
public class AuthMe extends JavaPlugin {
@@ -506,8 +507,8 @@ public class AuthMe extends JavaPlugin {
/**
* Get the permissions manager instance.
*
-
- * @return Permissions Manager instance. */
+ * @return Permissions Manager instance.
+ */
public PermissionsManager getPermissionsManager() {
return this.permsMan;
}
@@ -649,10 +650,6 @@ public class AuthMe extends JavaPlugin {
}
// Save Player Data
- /**
- * Method savePlayer.
- * @param player Player
- */
public void savePlayer(Player player) {
if ((Utils.isNPC(player)) || (Utils.isUnrestricted(player))) {
return;
@@ -681,11 +678,6 @@ public class AuthMe extends JavaPlugin {
}
// Select the player to kick when a vip player join the server when full
- /**
- * Method generateKickPlayer.
- * @param collection Collection extends Player>
-
- * @return Player */
public Player generateKickPlayer(Collection extends Player> collection) {
Player player = null;
for (Player p : collection) {
@@ -730,11 +722,6 @@ public class AuthMe extends JavaPlugin {
}
// Return the spawn location of a player
- /**
- * Method getSpawnLocation.
- * @param player Player
-
- * @return Location */
public Location getSpawnLocation(Player player) {
World world = player.getWorld();
String[] spawnPriority = Settings.spawnPriority.split(",");
@@ -757,21 +744,11 @@ public class AuthMe extends JavaPlugin {
}
// Return the default spawnpoint of a world
- /**
- * Method getDefaultSpawn.
- * @param world World
-
- * @return Location */
private Location getDefaultSpawn(World world) {
return world.getSpawnLocation();
}
// Return the multiverse spawnpoint of a world
- /**
- * Method getMultiverseSpawn.
- * @param world World
-
- * @return Location */
private Location getMultiverseSpawn(World world) {
if (multiverse != null && Settings.multiverse) {
try {
@@ -784,10 +761,6 @@ public class AuthMe extends JavaPlugin {
}
// Return the essentials spawnpoint
- /**
- * Method getEssentialsSpawn.
-
- * @return Location */
private Location getEssentialsSpawn() {
if (essentialsSpawn != null) {
return essentialsSpawn;
@@ -796,11 +769,6 @@ public class AuthMe extends JavaPlugin {
}
// Return the authme soawnpoint
- /**
- * Method getAuthMeSpawn.
- * @param player Player
-
- * @return Location */
private Location getAuthMeSpawn(Player player) {
if ((!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) && (Spawn.getInstance().getFirstSpawn() != null)) {
return Spawn.getInstance().getFirstSpawn();
@@ -811,19 +779,11 @@ public class AuthMe extends JavaPlugin {
return player.getWorld().getSpawnLocation();
}
- /**
- * Method switchAntiBotMod.
- * @param mode boolean
- */
public void switchAntiBotMod(boolean mode) {
this.antibotMod = mode;
Settings.switchAntiBotMod(mode);
}
- /**
- * Method getAntiBotModMode.
-
- * @return boolean */
public boolean getAntiBotModMode() {
return this.antibotMod;
}
@@ -850,12 +810,7 @@ public class AuthMe extends JavaPlugin {
}, 1, 1200 * Settings.delayRecall);
}
- /**
- * Method replaceAllInfos.
- * @param message String
- * @param player Player
-
- * @return String */
+
public String replaceAllInfos(String message, Player player) {
int playersOnline = Utils.getOnlinePlayers().size();
message = message.replace("&", "\u00a7");
@@ -871,11 +826,7 @@ public class AuthMe extends JavaPlugin {
return message;
}
- /**
- * Method getIP.
- * @param player Player
-
- * @return String */
+
public String getIP(Player player) {
String name = player.getName().toLowerCase();
String ip = player.getAddress().getAddress().getHostAddress();
@@ -889,12 +840,7 @@ public class AuthMe extends JavaPlugin {
return ip;
}
- /**
- * Method isLoggedIp.
- * @param name String
- * @param ip String
-
- * @return boolean */
+
public boolean isLoggedIp(String name, String ip) {
int count = 0;
for (Player player : Utils.getOnlinePlayers()) {
@@ -904,12 +850,7 @@ public class AuthMe extends JavaPlugin {
return count >= Settings.getMaxLoginPerIp;
}
- /**
- * Method hasJoinedIp.
- * @param name String
- * @param ip String
-
- * @return boolean */
+
public boolean hasJoinedIp(String name, String ip) {
int count = 0;
for (Player player : Utils.getOnlinePlayers()) {
@@ -919,21 +860,18 @@ public class AuthMe extends JavaPlugin {
return count >= Settings.getMaxJoinPerIp;
}
- /**
- * Method getModuleManager.
-
- * @return ModuleManager */
+
public ModuleManager getModuleManager() {
return moduleManager;
}
/**
- * Get Player real IP through VeryGames method
+ * Gets a player's real IP through VeryGames method.
*
- * @param player
- * player
-
- * @return String */
+ * @param player the player to process
+ *
+ * @return the real IP of the player
+ */
@Deprecated
public String getVeryGamesIP(Player player) {
String realIP = player.getAddress().getAddress().getHostAddress();
@@ -952,31 +890,19 @@ public class AuthMe extends JavaPlugin {
return realIP;
}
- /**
- * Method getCountryCode.
- * @param ip String
-
- * @return String */
+
@Deprecated
public String getCountryCode(String ip) {
return Utils.getCountryCode(ip);
}
- /**
- * Method getCountryName.
- * @param ip String
-
- * @return String */
+
@Deprecated
public String getCountryName(String ip) {
return Utils.getCountryName(ip);
}
- /**
- * Get the command handler instance.
- *
-
- * @return Command handler. */
+
public CommandHandler getCommandHandler() {
return this.commandHandler;
}
@@ -993,9 +919,7 @@ public class AuthMe extends JavaPlugin {
* @param args
* The command arguments (Bukkit).
*
-
-
- * @return True if the command was executed, false otherwise. * @see org.bukkit.command.CommandExecutor#onCommand(CommandSender, Command, String, String[]) * @see org.bukkit.command.CommandExecutor#onCommand(CommandSender, Command, String, String[])
+ * @return True if the command was executed, false otherwise.
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd,
@@ -1012,9 +936,9 @@ public class AuthMe extends JavaPlugin {
/**
* Get the current installed AuthMeReloaded version name.
*
-
* @return The version name of the currently installed AuthMeReloaded
- * instance. */
+ * instance.
+ */
public static String getVersionName() {
return PLUGIN_VERSION_NAME;
}
@@ -1022,9 +946,9 @@ public class AuthMe extends JavaPlugin {
/**
* Get the current installed AuthMeReloaded version code.
*
-
* @return The version code of the currently installed AuthMeReloaded
- * instance. */
+ * instance.
+ */
public static int getVersionCode() {
return PLUGIN_VERSION_CODE;
}
diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java
index 5eebc7cb7..917a75369 100644
--- a/src/main/java/fr/xephi/authme/Log4JFilter.java
+++ b/src/main/java/fr/xephi/authme/Log4JFilter.java
@@ -24,12 +24,6 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
public Log4JFilter() {
}
- /**
- * Method filter.
- * @param record LogEvent
-
-
- * @return Result * @see org.apache.logging.log4j.core.Filter#filter(LogEvent) */
@Override
public Result filter(LogEvent record) {
if (record == null) {
@@ -38,32 +32,12 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
return validateMessage(record.getMessage());
}
- /**
- * Method filter.
- * @param arg0 Logger
- * @param arg1 Level
- * @param arg2 Marker
- * @param message String
- * @param arg4 Object[]
-
-
- * @return Result * @see org.apache.logging.log4j.core.Filter#filter(Logger, Level, Marker, String, Object[]) */
@Override
public Result filter(Logger arg0, Level arg1, Marker arg2, String message,
Object... arg4) {
return validateMessage(message);
}
- /**
- * Method filter.
- * @param arg0 Logger
- * @param arg1 Level
- * @param arg2 Marker
- * @param message Object
- * @param arg4 Throwable
-
-
- * @return Result * @see org.apache.logging.log4j.core.Filter#filter(Logger, Level, Marker, Object, Throwable) */
@Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Object message,
Throwable arg4) {
@@ -73,37 +47,17 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
return validateMessage(message.toString());
}
- /**
- * Method filter.
- * @param arg0 Logger
- * @param arg1 Level
- * @param arg2 Marker
- * @param message Message
- * @param arg4 Throwable
-
-
- * @return Result * @see org.apache.logging.log4j.core.Filter#filter(Logger, Level, Marker, Message, Throwable) */
@Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Message message,
Throwable arg4) {
return validateMessage(message);
}
- /**
- * Method getOnMatch.
-
-
- * @return Result * @see org.apache.logging.log4j.core.Filter#getOnMatch() */
@Override
public Result getOnMatch() {
return Result.NEUTRAL;
}
- /**
- * Method getOnMismatch.
-
-
- * @return Result * @see org.apache.logging.log4j.core.Filter#getOnMismatch() */
@Override
public Result getOnMismatch() {
return Result.NEUTRAL;
@@ -115,8 +69,9 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
* data.
*
* @param message the Message object to verify
-
- * @return the Result value */
+ *
+ * @return the Result value
+ */
private static Result validateMessage(Message message) {
if (message == null) {
return Result.NEUTRAL;
@@ -129,8 +84,9 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
* depending on whether the message contains sensitive AuthMe data.
*
* @param message the message to verify
-
- * @return the Result value */
+ *
+ * @return the Result value
+ */
private static Result validateMessage(String message) {
if (message == null) {
return Result.NEUTRAL;
diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
index 104a986c1..8640d3e13 100644
--- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
+++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
@@ -1,5 +1,6 @@
package fr.xephi.authme.permission;
+import com.nijiko.permissions.Group;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import de.bananaco.bpermissions.api.ApiLayer;
@@ -339,8 +340,8 @@ public class PermissionsManager {
* @return True if the player has permission.
*/
public boolean hasPermission(Player player, String permsNode, boolean def) {
+ // If no permissions system is used, return the default value
if(!isEnabled())
- // No permissions system is used, return default
return def;
switch(this.permsType) {
@@ -389,17 +390,55 @@ public class PermissionsManager {
}
}
+ /**
+ * Check whether the current permissions system has group support.
+ * If no permissions system is hooked, false will be returned.
+ *
+ * @return True if the current permissions system supports groups, false otherwise.
+ */
+ public boolean hasGroupSupport() {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ switch(this.permsType) {
+ case PERMISSIONS_EX:
+ case PERMISSIONS_BUKKIT:
+ case B_PERMISSIONS:
+ case ESSENTIALS_GROUP_MANAGER:
+ case Z_PERMISSIONS:
+ return true;
+
+ case VAULT:
+ // Vault
+ return vaultPerms.hasGroupSupport();
+
+ case PERMISSIONS:
+ // Legacy permissions
+ // FIXME: Supported by plugin, but addGroup and removeGroup haven't been implemented correctly yet!
+ return false;
+
+ case NONE:
+ // Not hooked into any permissions system, return false
+ return false;
+
+ default:
+ // Something went wrong, return false to prevent problems
+ return false;
+ }
+ }
+
/**
* Get the permission groups of a player, if available.
*
* @param player The player.
*
- * @return Permission groups.
+ * @return Permission groups, or an empty list if this feature is not supported.
*/
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
public List getGroups(Player player) {
+ // If no permissions system is used, return an empty list
if(!isEnabled())
- // No permissions system is used, return an empty list
return new ArrayList<>();
switch(this.permsType) {
@@ -410,12 +449,12 @@ public class PermissionsManager {
case PERMISSIONS_BUKKIT:
// Permissions Bukkit
- // Permissions Bukkit doesn't support group, return an empty list
+ // FIXME: Add support for this!
return new ArrayList<>();
case B_PERMISSIONS:
// bPermissions
- return Arrays.asList(ApiLayer.getGroups(player.getName(), CalculableType.USER, player.getName()));
+ return Arrays.asList(ApiLayer.getGroups(player.getWorld().getName(), CalculableType.USER, player.getName()));
case ESSENTIALS_GROUP_MANAGER:
// Essentials Group Manager
@@ -432,6 +471,18 @@ public class PermissionsManager {
// Vault
return Arrays.asList(vaultPerms.getPlayerGroups(player));
+ case PERMISSIONS:
+ // Permissions
+ // Create a list to put the groups in
+ List groups = new ArrayList<>();
+
+ // Get the groups and add each to the list
+ for(Group group : this.defaultPerms.getGroups(player.getName()))
+ groups.add(group.getName());
+
+ // Return the groups
+ return groups;
+
case NONE:
// Not hooked into any permissions system, return an empty list
return new ArrayList<>();
@@ -443,17 +494,253 @@ public class PermissionsManager {
}
/**
- * Set the permission group of a player, if supported.
+ * Check whether the player is in the specified group.
+ *
+ * @param player The player.
+ * @param groupName The group name.
+ *
+ * @return True if the player is in the specified group, false otherwise.
+ * False is also returned if groups aren't supported by the used permissions system.
+ */
+ public boolean inGroup(Player player, String groupName) {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ switch(this.permsType) {
+ case PERMISSIONS_EX:
+ // Permissions Ex
+ PermissionUser user = PermissionsEx.getUser(player);
+ return user.inGroup(groupName);
+
+ case PERMISSIONS_BUKKIT:
+ case Z_PERMISSIONS:
+ // Get the current list of groups
+ List groupNames = getGroups(player);
+
+ // Check whether the list contains the group name, return the result
+ for(String entry : groupNames)
+ if(entry.equals(groupName))
+ return true;
+ return false;
+
+ case B_PERMISSIONS:
+ // bPermissions
+ return ApiLayer.hasGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
+
+ case ESSENTIALS_GROUP_MANAGER:
+ // Essentials Group Manager
+ final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
+ return handler != null && handler.inGroup(player.getName(), groupName);
+
+ case VAULT:
+ // Vault
+ return vaultPerms.playerInGroup(player, groupName);
+
+ case PERMISSIONS:
+ // Permissions
+ return this.defaultPerms.inGroup(player.getWorld().getName(), player.getName(), groupName);
+
+ case NONE:
+ // Not hooked into any permissions system, return an empty list
+ return false;
+
+ default:
+ // Something went wrong, return an empty list to prevent problems
+ return false;
+ }
+ }
+
+ /**
+ * Add the permission group of a player, if supported.
*
* @param player The player
* @param groupName The name of the group.
*
* @return True if succeed, false otherwise.
+ * False is also returned if this feature isn't supported for the current permissions system.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+ public boolean addGroup(Player player, String groupName) {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ // Set the group the proper way
+ switch(this.permsType) {
+ case PERMISSIONS_EX:
+ // Permissions Ex
+ PermissionUser user = PermissionsEx.getUser(player);
+ user.addGroup(groupName);
+ return true;
+
+ case PERMISSIONS_BUKKIT:
+ // Permissions Bukkit
+ // Add the group to the user using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player addgroup " + player.getName() + " " + groupName);
+
+ case B_PERMISSIONS:
+ // bPermissions
+ ApiLayer.addGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
+ return true;
+
+ case ESSENTIALS_GROUP_MANAGER:
+ // Essentials Group Manager
+ // Add the group to the user using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddsub " + player.getName() + " " + groupName);
+
+ case Z_PERMISSIONS:
+ // zPermissions
+ // Add the group to the user using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " addgroup " + groupName);
+
+ case VAULT:
+ // Vault
+ vaultPerms.playerAddGroup(player, groupName);
+ return true;
+
+ case PERMISSIONS:
+ // Permissions
+ // FIXME: Add this method!
+ //return this.defaultPerms.group
+
+ case NONE:
+ // Not hooked into any permissions system, return false
+ return false;
+
+ default:
+ // Something went wrong, return false
+ return false;
+ }
+ }
+
+ /**
+ * Add the permission groups of a player, if supported.
+ *
+ * @param player The player
+ * @param groupNames The name of the groups to add.
+ *
+ * @return True if succeed, false otherwise.
+ * False is also returned if this feature isn't supported for the current permissions system.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+ public boolean addGroups(Player player, List groupNames) {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ // Add each group to the user
+ boolean result = true;
+ for(String groupName : groupNames)
+ if(!addGroup(player, groupName))
+ result = false;
+
+ // Return the result
+ return result;
+ }
+
+ /**
+ * Remove the permission group of a player, if supported.
+ *
+ * @param player The player
+ * @param groupName The name of the group.
+ *
+ * @return True if succeed, false otherwise.
+ * False is also returned if this feature isn't supported for the current permissions system.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+ public boolean removeGroup(Player player, String groupName) {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ // Set the group the proper way
+ switch(this.permsType) {
+ case PERMISSIONS_EX:
+ // Permissions Ex
+ PermissionUser user = PermissionsEx.getUser(player);
+ user.removeGroup(groupName);
+ return true;
+
+ case PERMISSIONS_BUKKIT:
+ // Permissions Bukkit
+ // Remove the group to the user using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player removegroup " + player.getName() + " " + groupName);
+
+ case B_PERMISSIONS:
+ // bPermissions
+ ApiLayer.removeGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
+ return true;
+
+ case ESSENTIALS_GROUP_MANAGER:
+ // Essentials Group Manager
+ // Remove the group to the user using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manudelsub " + player.getName() + " " + groupName);
+
+ case Z_PERMISSIONS:
+ // zPermissions
+ // Remove the group to the user using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " removegroup " + groupName);
+
+ case VAULT:
+ // Vault
+ vaultPerms.playerRemoveGroup(player, groupName);
+ return true;
+
+ case PERMISSIONS:
+ // Permissions
+ // FIXME: Add this method!
+ //return this.defaultPerms.group
+
+ case NONE:
+ // Not hooked into any permissions system, return false
+ return false;
+
+ default:
+ // Something went wrong, return false
+ return false;
+ }
+ }
+
+ /**
+ * Remove the permission groups of a player, if supported.
+ *
+ * @param player The player
+ * @param groupNames The name of the groups to add.
+ *
+ * @return True if succeed, false otherwise.
+ * False is also returned if this feature isn't supported for the current permissions system.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+ public boolean removeGroups(Player player, List groupNames) {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ // Add each group to the user
+ boolean result = true;
+ for(String groupName : groupNames)
+ if(!removeGroup(player, groupName))
+ result = false;
+
+ // Return the result
+ return result;
+ }
+
+ /**
+ * Set the permission group of a player, if supported.
+ * This clears the current groups of the player.
+ *
+ * @param player The player
+ * @param groupName The name of the group.
+ *
+ * @return True if succeed, false otherwise.
+ * False is also returned if this feature isn't supported for the current permissions system.
*/
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
public boolean setGroup(Player player, String groupName) {
+ // If no permissions system is used, return false
if(!isEnabled())
- // No permissions system is used, return false
return false;
// Create a list of group names
@@ -470,8 +757,8 @@ public class PermissionsManager {
case PERMISSIONS_BUKKIT:
// Permissions Bukkit
- // Permissions Bukkit doesn't support groups, return false
- return false;
+ // Set the user's group using a command
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player setgroup " + player.getName() + " " + groupName);
case B_PERMISSIONS:
// bPermissions
@@ -480,23 +767,27 @@ public class PermissionsManager {
case ESSENTIALS_GROUP_MANAGER:
// Essentials Group Manager
- final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
- if(handler == null)
- return false;
- // TODO: Write proper code here!
- //return Arrays.asList(handler.getGroups(player.getName()));
+ // Clear the list of groups, add the player to the specified group afterwards using a command
+ removeAllGroups(player);
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player.getName() + " " + groupName);
case Z_PERMISSIONS:
//zPermissions
- // TODO: Write proper code here!
- //return new ArrayList(zPermissionsService.getPlayerGroups(player.getName()));
+ // Set the players group through the plugin commands
+ return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " setgroup " + groupName);
case VAULT:
// Vault
- // TODO: Clear the current list of groups?
+ // Remove all current groups, add the player to the specified group afterwards
+ removeAllGroups(player);
vaultPerms.playerAddGroup(player, groupName);
return true;
+ case PERMISSIONS:
+ // Permissions
+ // FIXME: Add this method!
+ //return this.defaultPerms.group
+
case NONE:
// Not hooked into any permissions system, return false
return false;
@@ -507,6 +798,63 @@ public class PermissionsManager {
}
}
+ /**
+ * Set the permission groups of a player, if supported.
+ * This clears the current groups of the player.
+ *
+ * @param player The player
+ * @param groupNames The name of the groups to set.
+ *
+ * @return True if succeed, false otherwise.
+ * False is also returned if this feature isn't supported for the current permissions system.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+ public boolean setGroups(Player player, List groupNames) {
+ // If no permissions system is used or if there's no group supplied, return false
+ if(!isEnabled() || groupNames.size() <= 0)
+ return false;
+
+ // Set the main group
+ if(!setGroup(player, groupNames.get(0)))
+ return false;
+
+ // Add the rest of the groups
+ boolean result = true;
+ for(int i = 1; i < groupNames.size(); i++) {
+ // Get the group name
+ String groupName = groupNames.get(0);
+
+ // Add this group
+ if(!addGroup(player, groupName))
+ result = false;
+ }
+
+ // Return the result
+ return result;
+ }
+
+ /**
+ * Remove all groups of the specified player, if supported.
+ * Systems like Essentials GroupManager don't allow all groups to be removed from a player, thus the user will stay
+ * in it's primary group. All the subgroups are removed just fine.
+ *
+ * @param player The player to remove all groups from.
+ *
+ * @return True if succeed, false otherwise.
+ * False will also be returned if this feature isn't supported for the used permissions system.
+ */
+ public boolean removeAllGroups(Player player) {
+ // If no permissions system is used, return false
+ if(!isEnabled())
+ return false;
+
+ // Get a list of current groups
+ List groupNames = getGroups(player);
+
+ // Remove each group
+ return removeGroups(player, groupNames);
+ }
+
public enum PermissionsSystemType {
NONE("None"),
PERMISSIONS_EX("PermissionsEx"),
diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java
index 330e8d8e7..278cf41af 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,51 @@ 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);
+
+ // 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;
+
+ // Make sure group support is available
+ if(!permsMan.hasGroupSupport())
+ ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
+
+ 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;
- }
}
}