Merge remote-tracking branch 'origin/unit-tests' into unit-tests

Conflicts:
	src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java
	src/test/java/fr/xephi/authme/AuthMeMockUtil.java
This commit is contained in:
ljacqu 2015-11-21 19:36:48 +01:00
commit f06f7d8c77
5 changed files with 431 additions and 198 deletions

View File

@ -606,7 +606,7 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- jUnit Testing Library --> <!-- Unit Testing Libraries -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -60,6 +60,7 @@ import net.milkbowl.vault.permission.Permission;
import net.minelink.ctplus.CombatTagPlus; import net.minelink.ctplus.CombatTagPlus;
/** /**
* The AuthMe main class.
*/ */
public class AuthMe extends JavaPlugin { public class AuthMe extends JavaPlugin {
@ -506,8 +507,8 @@ public class AuthMe extends JavaPlugin {
/** /**
* Get the permissions manager instance. * Get the permissions manager instance.
* *
* @return Permissions Manager instance.
* @return Permissions Manager instance. */ */
public PermissionsManager getPermissionsManager() { public PermissionsManager getPermissionsManager() {
return this.permsMan; return this.permsMan;
} }
@ -649,10 +650,6 @@ public class AuthMe extends JavaPlugin {
} }
// Save Player Data // Save Player Data
/**
* Method savePlayer.
* @param player Player
*/
public void savePlayer(Player player) { public void savePlayer(Player player) {
if ((Utils.isNPC(player)) || (Utils.isUnrestricted(player))) { if ((Utils.isNPC(player)) || (Utils.isUnrestricted(player))) {
return; return;
@ -681,11 +678,6 @@ public class AuthMe extends JavaPlugin {
} }
// Select the player to kick when a vip player join the server when full // 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) { public Player generateKickPlayer(Collection<? extends Player> collection) {
Player player = null; Player player = null;
for (Player p : collection) { for (Player p : collection) {
@ -730,11 +722,6 @@ public class AuthMe extends JavaPlugin {
} }
// Return the spawn location of a player // Return the spawn location of a player
/**
* Method getSpawnLocation.
* @param player Player
* @return Location */
public Location getSpawnLocation(Player player) { public Location getSpawnLocation(Player player) {
World world = player.getWorld(); World world = player.getWorld();
String[] spawnPriority = Settings.spawnPriority.split(","); String[] spawnPriority = Settings.spawnPriority.split(",");
@ -757,21 +744,11 @@ public class AuthMe extends JavaPlugin {
} }
// Return the default spawnpoint of a world // Return the default spawnpoint of a world
/**
* Method getDefaultSpawn.
* @param world World
* @return Location */
private Location getDefaultSpawn(World world) { private Location getDefaultSpawn(World world) {
return world.getSpawnLocation(); return world.getSpawnLocation();
} }
// Return the multiverse spawnpoint of a world // Return the multiverse spawnpoint of a world
/**
* Method getMultiverseSpawn.
* @param world World
* @return Location */
private Location getMultiverseSpawn(World world) { private Location getMultiverseSpawn(World world) {
if (multiverse != null && Settings.multiverse) { if (multiverse != null && Settings.multiverse) {
try { try {
@ -784,10 +761,6 @@ public class AuthMe extends JavaPlugin {
} }
// Return the essentials spawnpoint // Return the essentials spawnpoint
/**
* Method getEssentialsSpawn.
* @return Location */
private Location getEssentialsSpawn() { private Location getEssentialsSpawn() {
if (essentialsSpawn != null) { if (essentialsSpawn != null) {
return essentialsSpawn; return essentialsSpawn;
@ -796,11 +769,6 @@ public class AuthMe extends JavaPlugin {
} }
// Return the authme soawnpoint // Return the authme soawnpoint
/**
* Method getAuthMeSpawn.
* @param player Player
* @return Location */
private Location getAuthMeSpawn(Player player) { private Location getAuthMeSpawn(Player player) {
if ((!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) && (Spawn.getInstance().getFirstSpawn() != null)) { if ((!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) && (Spawn.getInstance().getFirstSpawn() != null)) {
return Spawn.getInstance().getFirstSpawn(); return Spawn.getInstance().getFirstSpawn();
@ -811,19 +779,11 @@ public class AuthMe extends JavaPlugin {
return player.getWorld().getSpawnLocation(); return player.getWorld().getSpawnLocation();
} }
/**
* Method switchAntiBotMod.
* @param mode boolean
*/
public void switchAntiBotMod(boolean mode) { public void switchAntiBotMod(boolean mode) {
this.antibotMod = mode; this.antibotMod = mode;
Settings.switchAntiBotMod(mode); Settings.switchAntiBotMod(mode);
} }
/**
* Method getAntiBotModMode.
* @return boolean */
public boolean getAntiBotModMode() { public boolean getAntiBotModMode() {
return this.antibotMod; return this.antibotMod;
} }
@ -850,12 +810,7 @@ public class AuthMe extends JavaPlugin {
}, 1, 1200 * Settings.delayRecall); }, 1, 1200 * Settings.delayRecall);
} }
/**
* Method replaceAllInfos.
* @param message String
* @param player Player
* @return String */
public String replaceAllInfos(String message, Player player) { public String replaceAllInfos(String message, Player player) {
int playersOnline = Utils.getOnlinePlayers().size(); int playersOnline = Utils.getOnlinePlayers().size();
message = message.replace("&", "\u00a7"); message = message.replace("&", "\u00a7");
@ -871,11 +826,7 @@ public class AuthMe extends JavaPlugin {
return message; return message;
} }
/**
* Method getIP.
* @param player Player
* @return String */
public String getIP(Player player) { public String getIP(Player player) {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
String ip = player.getAddress().getAddress().getHostAddress(); String ip = player.getAddress().getAddress().getHostAddress();
@ -889,12 +840,7 @@ public class AuthMe extends JavaPlugin {
return ip; return ip;
} }
/**
* Method isLoggedIp.
* @param name String
* @param ip String
* @return boolean */
public boolean isLoggedIp(String name, String ip) { public boolean isLoggedIp(String name, String ip) {
int count = 0; int count = 0;
for (Player player : Utils.getOnlinePlayers()) { for (Player player : Utils.getOnlinePlayers()) {
@ -904,12 +850,7 @@ public class AuthMe extends JavaPlugin {
return count >= Settings.getMaxLoginPerIp; return count >= Settings.getMaxLoginPerIp;
} }
/**
* Method hasJoinedIp.
* @param name String
* @param ip String
* @return boolean */
public boolean hasJoinedIp(String name, String ip) { public boolean hasJoinedIp(String name, String ip) {
int count = 0; int count = 0;
for (Player player : Utils.getOnlinePlayers()) { for (Player player : Utils.getOnlinePlayers()) {
@ -919,21 +860,18 @@ public class AuthMe extends JavaPlugin {
return count >= Settings.getMaxJoinPerIp; return count >= Settings.getMaxJoinPerIp;
} }
/**
* Method getModuleManager.
* @return ModuleManager */
public ModuleManager getModuleManager() { public ModuleManager getModuleManager() {
return moduleManager; return moduleManager;
} }
/** /**
* Get Player real IP through VeryGames method * Gets a player's real IP through VeryGames method.
* *
* @param player * @param player the player to process
* player *
* @return the real IP of the player
* @return String */ */
@Deprecated @Deprecated
public String getVeryGamesIP(Player player) { public String getVeryGamesIP(Player player) {
String realIP = player.getAddress().getAddress().getHostAddress(); String realIP = player.getAddress().getAddress().getHostAddress();
@ -952,31 +890,19 @@ public class AuthMe extends JavaPlugin {
return realIP; return realIP;
} }
/**
* Method getCountryCode.
* @param ip String
* @return String */
@Deprecated @Deprecated
public String getCountryCode(String ip) { public String getCountryCode(String ip) {
return Utils.getCountryCode(ip); return Utils.getCountryCode(ip);
} }
/**
* Method getCountryName.
* @param ip String
* @return String */
@Deprecated @Deprecated
public String getCountryName(String ip) { public String getCountryName(String ip) {
return Utils.getCountryName(ip); return Utils.getCountryName(ip);
} }
/**
* Get the command handler instance.
*
* @return Command handler. */
public CommandHandler getCommandHandler() { public CommandHandler getCommandHandler() {
return this.commandHandler; return this.commandHandler;
} }
@ -993,9 +919,7 @@ public class AuthMe extends JavaPlugin {
* @param args * @param args
* The command arguments (Bukkit). * The command arguments (Bukkit).
* *
* @return True if the command was executed, false otherwise.
* @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[])
*/ */
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, public boolean onCommand(CommandSender sender, Command cmd,
@ -1012,9 +936,9 @@ public class AuthMe extends JavaPlugin {
/** /**
* Get the current installed AuthMeReloaded version name. * Get the current installed AuthMeReloaded version name.
* *
* @return The version name of the currently installed AuthMeReloaded * @return The version name of the currently installed AuthMeReloaded
* instance. */ * instance.
*/
public static String getVersionName() { public static String getVersionName() {
return PLUGIN_VERSION_NAME; return PLUGIN_VERSION_NAME;
} }
@ -1022,9 +946,9 @@ public class AuthMe extends JavaPlugin {
/** /**
* Get the current installed AuthMeReloaded version code. * Get the current installed AuthMeReloaded version code.
* *
* @return The version code of the currently installed AuthMeReloaded * @return The version code of the currently installed AuthMeReloaded
* instance. */ * instance.
*/
public static int getVersionCode() { public static int getVersionCode() {
return PLUGIN_VERSION_CODE; return PLUGIN_VERSION_CODE;
} }

View File

@ -24,12 +24,6 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
public Log4JFilter() { public Log4JFilter() {
} }
/**
* Method filter.
* @param record LogEvent
* @return Result * @see org.apache.logging.log4j.core.Filter#filter(LogEvent) */
@Override @Override
public Result filter(LogEvent record) { public Result filter(LogEvent record) {
if (record == null) { if (record == null) {
@ -38,32 +32,12 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
return validateMessage(record.getMessage()); 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 @Override
public Result filter(Logger arg0, Level arg1, Marker arg2, String message, public Result filter(Logger arg0, Level arg1, Marker arg2, String message,
Object... arg4) { Object... arg4) {
return validateMessage(message); 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 @Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Object message, public Result filter(Logger arg0, Level arg1, Marker arg2, Object message,
Throwable arg4) { Throwable arg4) {
@ -73,37 +47,17 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
return validateMessage(message.toString()); 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 @Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Message message, public Result filter(Logger arg0, Level arg1, Marker arg2, Message message,
Throwable arg4) { Throwable arg4) {
return validateMessage(message); return validateMessage(message);
} }
/**
* Method getOnMatch.
* @return Result * @see org.apache.logging.log4j.core.Filter#getOnMatch() */
@Override @Override
public Result getOnMatch() { public Result getOnMatch() {
return Result.NEUTRAL; return Result.NEUTRAL;
} }
/**
* Method getOnMismatch.
* @return Result * @see org.apache.logging.log4j.core.Filter#getOnMismatch() */
@Override @Override
public Result getOnMismatch() { public Result getOnMismatch() {
return Result.NEUTRAL; return Result.NEUTRAL;
@ -115,8 +69,9 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
* data. * data.
* *
* @param message the Message object to verify * @param message the Message object to verify
*
* @return the Result value */ * @return the Result value
*/
private static Result validateMessage(Message message) { private static Result validateMessage(Message message) {
if (message == null) { if (message == null) {
return Result.NEUTRAL; 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. * depending on whether the message contains sensitive AuthMe data.
* *
* @param message the message to verify * @param message the message to verify
*
* @return the Result value */ * @return the Result value
*/
private static Result validateMessage(String message) { private static Result validateMessage(String message) {
if (message == null) { if (message == null) {
return Result.NEUTRAL; return Result.NEUTRAL;

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.permission; package fr.xephi.authme.permission;
import com.nijiko.permissions.Group;
import com.nijiko.permissions.PermissionHandler; import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.bukkit.Permissions.Permissions;
import de.bananaco.bpermissions.api.ApiLayer; import de.bananaco.bpermissions.api.ApiLayer;
@ -339,8 +340,8 @@ public class PermissionsManager {
* @return True if the player has permission. * @return True if the player has permission.
*/ */
public boolean hasPermission(Player player, String permsNode, boolean def) { public boolean hasPermission(Player player, String permsNode, boolean def) {
// If no permissions system is used, return the default value
if(!isEnabled()) if(!isEnabled())
// No permissions system is used, return default
return def; return def;
switch(this.permsType) { 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. * Get the permission groups of a player, if available.
* *
* @param player The player. * @param player The player.
* *
* @return Permission groups. * @return Permission groups, or an empty list if this feature is not supported.
*/ */
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
public List<String> getGroups(Player player) { public List<String> getGroups(Player player) {
// If no permissions system is used, return an empty list
if(!isEnabled()) if(!isEnabled())
// No permissions system is used, return an empty list
return new ArrayList<>(); return new ArrayList<>();
switch(this.permsType) { switch(this.permsType) {
@ -410,12 +449,12 @@ public class PermissionsManager {
case PERMISSIONS_BUKKIT: case PERMISSIONS_BUKKIT:
// Permissions Bukkit // Permissions Bukkit
// Permissions Bukkit doesn't support group, return an empty list // FIXME: Add support for this!
return new ArrayList<>(); return new ArrayList<>();
case B_PERMISSIONS: case B_PERMISSIONS:
// bPermissions // 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: case ESSENTIALS_GROUP_MANAGER:
// Essentials Group Manager // Essentials Group Manager
@ -432,6 +471,18 @@ public class PermissionsManager {
// Vault // Vault
return Arrays.asList(vaultPerms.getPlayerGroups(player)); return Arrays.asList(vaultPerms.getPlayerGroups(player));
case PERMISSIONS:
// Permissions
// Create a list to put the groups in
List<String> 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: case NONE:
// Not hooked into any permissions system, return an empty list // Not hooked into any permissions system, return an empty list
return new ArrayList<>(); 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<String> 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 player The player
* @param groupName The name of the group. * @param groupName The name of the group.
* *
* @return True if succeed, false otherwise. * @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<String> 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<String> 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"}) @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
public boolean setGroup(Player player, String groupName) { public boolean setGroup(Player player, String groupName) {
// If no permissions system is used, return false
if(!isEnabled()) if(!isEnabled())
// No permissions system is used, return false
return false; return false;
// Create a list of group names // Create a list of group names
@ -470,8 +757,8 @@ public class PermissionsManager {
case PERMISSIONS_BUKKIT: case PERMISSIONS_BUKKIT:
// Permissions Bukkit // Permissions Bukkit
// Permissions Bukkit doesn't support groups, return false // Set the user's group using a command
return false; return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player setgroup " + player.getName() + " " + groupName);
case B_PERMISSIONS: case B_PERMISSIONS:
// bPermissions // bPermissions
@ -480,23 +767,27 @@ public class PermissionsManager {
case ESSENTIALS_GROUP_MANAGER: case ESSENTIALS_GROUP_MANAGER:
// Essentials Group Manager // Essentials Group Manager
final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player); // Clear the list of groups, add the player to the specified group afterwards using a command
if(handler == null) removeAllGroups(player);
return false; return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player.getName() + " " + groupName);
// TODO: Write proper code here!
//return Arrays.asList(handler.getGroups(player.getName()));
case Z_PERMISSIONS: case Z_PERMISSIONS:
//zPermissions //zPermissions
// TODO: Write proper code here! // Set the players group through the plugin commands
//return new ArrayList(zPermissionsService.getPlayerGroups(player.getName())); return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " setgroup " + groupName);
case VAULT: case VAULT:
// 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); vaultPerms.playerAddGroup(player, groupName);
return true; return true;
case PERMISSIONS:
// Permissions
// FIXME: Add this method!
//return this.defaultPerms.group
case NONE: case NONE:
// Not hooked into any permissions system, return false // Not hooked into any permissions system, return false
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<String> 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<String> groupNames = getGroups(player);
// Remove each group
return removeGroups(player, groupNames);
}
public enum PermissionsSystemType { public enum PermissionsSystemType {
NONE("None"), NONE("None"),
PERMISSIONS_EX("PermissionsEx"), PERMISSIONS_EX("PermissionsEx"),

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,53 @@ 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; // Get the permissions manager, and make sure it's valid
String currentGroup; PermissionsManager permsMan = plugin.getPermissionsManager();
try { if(permsMan == null)
currentGroup = plugin.vaultGroupManagement.getPrimaryGroup(player); ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
} catch (UnsupportedOperationException e) { assert permsMan != null;
ConsoleLogger.showError("Your permission plugin (" + plugin.vaultGroupManagement.getName() + ") doesn't support the Group system... unhook!");
plugin.vaultGroupManagement = null; // Make sure group support is available
return; if(!permsMan.hasGroupSupport())
} ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
switch (group) {
case UNREGISTERED: { switch(group) {
plugin.vaultGroupManagement.playerRemoveGroup(player, currentGroup); case UNREGISTERED:
plugin.vaultGroupManagement.playerAddGroup(player, Settings.unRegisteredGroup); // 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; 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.