Change use of String permissions to the permission enums

This commit is contained in:
ljacqu 2015-11-28 21:59:29 +01:00
parent e519906dc5
commit 364583e7db
18 changed files with 108 additions and 257 deletions

View File

@ -1,5 +1,6 @@
package fr.xephi.authme;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
@ -72,7 +73,7 @@ public class AntiBot {
if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) {
return;
}
if (plugin.getPermissionsManager().hasPermission(player, "authme.bypassantibot")) {
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_ANTIBOT)) {
return;
}

View File

@ -18,6 +18,7 @@ import fr.xephi.authme.hooks.EssSpawn;
import fr.xephi.authme.listener.*;
import fr.xephi.authme.modules.ModuleManager;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.*;
import fr.xephi.authme.util.GeoLiteAPI;
@ -725,7 +726,7 @@ public class AuthMe extends JavaPlugin {
public Player generateKickPlayer(Collection<? extends Player> collection) {
Player player = null;
for (Player p : collection) {
if (!getPermissionsManager().hasPermission(p, "authme.vip")) {
if (!getPermissionsManager().hasPermission(p, UserPermission.IS_VIP)) {
player = p;
break;
}

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.command;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.command.CommandSender;
@ -921,7 +922,7 @@ public class CommandDescription {
* @param permissionNode The permission node required.
* @param defaultPermission The default permission.
*/
public void setCommandPermissions(String permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
public void setCommandPermissions(PermissionNode permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
}

View File

@ -9,6 +9,8 @@ import fr.xephi.authme.command.executable.email.ChangeEmailCommand;
import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
import fr.xephi.authme.command.executable.login.LoginCommand;
import fr.xephi.authme.command.executable.logout.LogoutCommand;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.UserPermission;
import java.util.ArrayList;
import java.util.List;
@ -72,14 +74,14 @@ public class CommandManager {
add("r");
}
}, "Register a player", "Register the specified player with the specified password.", authMeBaseCommand);
registerCommand.setCommandPermissions("authme.admin.register", CommandPermissions.DefaultPermission.OP_ONLY);
registerCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.OP_ONLY);
registerCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
// Register the unregister command
CommandDescription unregisterCommand = new CommandDescription(new UnregisterCommand(), helpCommandLabels,
"Unregister a player", "Unregister the specified player.", authMeBaseCommand);
unregisterCommand.setCommandPermissions("authme.admin.unregister", CommandPermissions.DefaultPermission.OP_ONLY);
unregisterCommand.setCommandPermissions(UserPermission.UNREGISTER, CommandPermissions.DefaultPermission.OP_ONLY);
unregisterCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
// Register the forcelogin command
@ -90,7 +92,7 @@ public class CommandManager {
add("login");
}
}, "Enforce login player", "Enforce the specified player to login.", authMeBaseCommand);
forceLoginCommand.setCommandPermissions("authme.admin.forcelogin", CommandPermissions.DefaultPermission.OP_ONLY);
forceLoginCommand.setCommandPermissions(UserPermission.CAN_LOGIN_BE_FORCED, CommandPermissions.DefaultPermission.OP_ONLY);
forceLoginCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
// Register the changepassword command
@ -103,7 +105,7 @@ public class CommandManager {
add("cp");
}
}, "Change player's password", "Change the password of a player.", authMeBaseCommand);
changePasswordCommand.setCommandPermissions("authme.admin.changepassword", CommandPermissions.DefaultPermission.OP_ONLY);
changePasswordCommand.setCommandPermissions(AdminPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.OP_ONLY);
changePasswordCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
changePasswordCommand.addArgument(new CommandArgumentDescription("pwd", "New password", false));
@ -115,7 +117,7 @@ public class CommandManager {
add("ll");
}
}, "Player's last login", "View the date of the specified players last login", authMeBaseCommand);
lastLoginCommand.setCommandPermissions("authme.admin.lastlogin", CommandPermissions.DefaultPermission.OP_ONLY);
lastLoginCommand.setCommandPermissions(AdminPermission.LAST_LOGIN, CommandPermissions.DefaultPermission.OP_ONLY);
lastLoginCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
// Register the accounts command
@ -126,7 +128,7 @@ public class CommandManager {
add("account");
}
}, "Display player accounts", "Display all accounts of a player by it's player name or IP.", authMeBaseCommand);
accountsCommand.setCommandPermissions("authme.admin.accounts", CommandPermissions.DefaultPermission.OP_ONLY);
accountsCommand.setCommandPermissions(AdminPermission.ACCOUNTS, CommandPermissions.DefaultPermission.OP_ONLY);
accountsCommand.addArgument(new CommandArgumentDescription("player", "Player name or IP", true));
// Register the getemail command
@ -139,7 +141,7 @@ public class CommandManager {
add("mail");
}
}, "Display player's email", "Display the email address of the specified player if set.", authMeBaseCommand);
getEmailCommand.setCommandPermissions("authme.admin.getemail", CommandPermissions.DefaultPermission.OP_ONLY);
getEmailCommand.setCommandPermissions(AdminPermission.GET_EMAIL, CommandPermissions.DefaultPermission.OP_ONLY);
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
// Register the setemail command
@ -152,7 +154,7 @@ public class CommandManager {
add("setmail");
}
}, "Change player's email", "Change the email address of the specified player.", authMeBaseCommand);
setEmailCommand.setCommandPermissions("authme.admin.chgemail", CommandPermissions.DefaultPermission.OP_ONLY);
setEmailCommand.setCommandPermissions(AdminPermission.CHANGE_EMAIL, CommandPermissions.DefaultPermission.OP_ONLY);
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
@ -164,7 +166,7 @@ public class CommandManager {
add("ip");
}
}, "Get player's IP", "Get the IP address of the specified online player.", authMeBaseCommand);
getIpCommand.setCommandPermissions("authme.admin.getip", CommandPermissions.DefaultPermission.OP_ONLY);
getIpCommand.setCommandPermissions(AdminPermission.GET_IP, CommandPermissions.DefaultPermission.OP_ONLY);
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
// Register the spawn command
@ -175,7 +177,7 @@ public class CommandManager {
add("home");
}
}, "Teleport to spawn", "Teleport to the spawn.", authMeBaseCommand);
spawnCommand.setCommandPermissions("authme.admin.spawn", CommandPermissions.DefaultPermission.OP_ONLY);
spawnCommand.setCommandPermissions(AdminPermission.SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
// Register the setspawn command
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
@ -185,7 +187,7 @@ public class CommandManager {
add("chgspawn");
}
}, "Change the spawn", "Change the player's spawn to your current position.", authMeBaseCommand);
setSpawnCommand.setCommandPermissions("authme.admin.setspawn", CommandPermissions.DefaultPermission.OP_ONLY);
setSpawnCommand.setCommandPermissions(AdminPermission.SET_SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
// Register the firstspawn command
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
@ -195,7 +197,7 @@ public class CommandManager {
add("firsthome");
}
}, "Teleport to first spawn", "Teleport to the first spawn.", authMeBaseCommand);
firstSpawnCommand.setCommandPermissions("authme.admin.firstspawn", CommandPermissions.DefaultPermission.OP_ONLY);
firstSpawnCommand.setCommandPermissions(AdminPermission.FIRST_SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
// Register the setfirstspawn command
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
@ -205,7 +207,7 @@ public class CommandManager {
add("chgfirstspawn");
}
}, "Change the first spawn", "Change the first player's spawn to your current position.", authMeBaseCommand);
setFirstSpawnCommand.setCommandPermissions("authme.admin.setfirstspawn", CommandPermissions.DefaultPermission.OP_ONLY);
setFirstSpawnCommand.setCommandPermissions(AdminPermission.SET_FIRST_SPAWN, CommandPermissions.DefaultPermission.OP_ONLY);
// Register the purge command
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
@ -215,7 +217,7 @@ public class CommandManager {
add("delete");
}
}, "Purge old data", "Purge old AuthMeReloaded data longer than the specified amount of days ago.", authMeBaseCommand);
purgeCommand.setCommandPermissions("authme.admin.purge", CommandPermissions.DefaultPermission.OP_ONLY);
purgeCommand.setCommandPermissions(AdminPermission.PURGE, CommandPermissions.DefaultPermission.OP_ONLY);
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
// Register the purgelastposition command
@ -230,7 +232,7 @@ public class CommandManager {
add("resetlastpos");
}
}, "Purge player's last position", "Purge the last know position of the specified player.", authMeBaseCommand);
purgeLastPositionCommand.setCommandPermissions("authme.admin.purgelastpos", CommandPermissions.DefaultPermission.OP_ONLY);
purgeLastPositionCommand.setCommandPermissions(AdminPermission.PURGE_LAST_POSITION, CommandPermissions.DefaultPermission.OP_ONLY);
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
// Register the purgebannedplayers command
@ -243,7 +245,7 @@ public class CommandManager {
add("deletebannedplayer");
}
}, "Purge banned palyers data", "Purge all AuthMeReloaded data for banned players.", authMeBaseCommand);
purgeBannedPlayersCommand.setCommandPermissions("authme.admin.purgebannedplayers", CommandPermissions.DefaultPermission.OP_ONLY);
purgeBannedPlayersCommand.setCommandPermissions(AdminPermission.PURGE_BANNED_PLAYERS, CommandPermissions.DefaultPermission.OP_ONLY);
// Register the switchantibot command
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
@ -254,7 +256,7 @@ public class CommandManager {
add("antibot");
}
}, "Switch AntiBot mode", "Switch or toggle the AntiBot mode to the specified state.", authMeBaseCommand);
switchAntiBotCommand.setCommandPermissions("authme.admin.switchantibot", CommandPermissions.DefaultPermission.OP_ONLY);
switchAntiBotCommand.setCommandPermissions(AdminPermission.SWITCH_ANTIBOT, CommandPermissions.DefaultPermission.OP_ONLY);
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
// // Register the resetname command
@ -278,14 +280,14 @@ public class CommandManager {
add("rld");
}
}, "Reload plugin", "Reload the AuthMeReloaded plugin.", authMeBaseCommand);
reloadCommand.setCommandPermissions("authme.admin.reload", CommandPermissions.DefaultPermission.OP_ONLY);
reloadCommand.setCommandPermissions(AdminPermission.RELOAD, CommandPermissions.DefaultPermission.OP_ONLY);
// Register the version command
CommandDescription versionCommand = new CommandDescription(new VersionCommand(), helpCommandLabels,
"Version info", "Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.", authMeBaseCommand);
versionCommand.setMaximumArguments(false);
// Register the base Dungeon Maze command
// Register the base login command
CommandDescription loginBaseCommand = new CommandDescription(new LoginCommand(), new ArrayList<String>() {
{
@ -293,7 +295,7 @@ public class CommandManager {
add("l");
}
}, "Login command", "Command to login using AuthMeReloaded.", null);
loginBaseCommand.setCommandPermissions("authme.login", CommandPermissions.DefaultPermission.ALLOWED);
loginBaseCommand.setCommandPermissions(UserPermission.LOGIN, CommandPermissions.DefaultPermission.ALLOWED);
loginBaseCommand.addArgument(new CommandArgumentDescription("password", "Login password", false));
// Register the help command
@ -309,7 +311,7 @@ public class CommandManager {
add("logout");
}
}, "Logout command", "Command to logout using AuthMeReloaded.", null);
logoutBaseCommand.setCommandPermissions("authme.logout", CommandPermissions.DefaultPermission.ALLOWED);
logoutBaseCommand.setCommandPermissions(UserPermission.LOGOUT, CommandPermissions.DefaultPermission.ALLOWED);
// Register the help command
CommandDescription logoutHelpCommand = new CommandDescription(new HelpCommand(), helpCommandLabels,
@ -325,7 +327,7 @@ public class CommandManager {
add("reg");
}
}, "Registration command", "Command to register using AuthMeReloaded.", null);
registerBaseCommand.setCommandPermissions("authme.register", CommandPermissions.DefaultPermission.ALLOWED);
registerBaseCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.ALLOWED);
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
registerBaseCommand.setMaximumArguments(false);
@ -344,7 +346,7 @@ public class CommandManager {
add("unreg");
}
}, "Unregistration command", "Command to unregister using AuthMeReloaded.", null);
unregisterBaseCommand.setCommandPermissions("authme.unregister", CommandPermissions.DefaultPermission.ALLOWED);
unregisterBaseCommand.setCommandPermissions(UserPermission.UNREGISTER, CommandPermissions.DefaultPermission.ALLOWED);
unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
// Register the help command
@ -360,7 +362,7 @@ public class CommandManager {
add("changepass");
}
}, "Change password command", "Command to change your password using AuthMeReloaded.", null);
changePasswordBaseCommand.setCommandPermissions("authme.changepassword", CommandPermissions.DefaultPermission.ALLOWED);
changePasswordBaseCommand.setCommandPermissions(UserPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.ALLOWED);
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
changePasswordBaseCommand.setMaximumArguments(false);
@ -395,7 +397,7 @@ public class CommandManager {
add("addmail");
}
}, "Add E-mail", "Add an new E-Mail address to your account.", emailBaseCommand);
addEmailCommand.setCommandPermissions("authme.email.add", CommandPermissions.DefaultPermission.ALLOWED);
addEmailCommand.setCommandPermissions(UserPermission.ADD_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
@ -408,7 +410,7 @@ public class CommandManager {
add("changemail");
}
}, "Change E-mail", "Change an E-Mail address of your account.", emailBaseCommand);
changeEmailCommand.setCommandPermissions("authme.email.change", CommandPermissions.DefaultPermission.ALLOWED);
changeEmailCommand.setCommandPermissions(UserPermission.CHANGE_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
@ -422,7 +424,7 @@ public class CommandManager {
add("recovermail");
}
}, "Recover using E-mail", "Recover your account using an E-mail address.", emailBaseCommand);
recoverEmailCommand.setCommandPermissions("authme.email.recover", CommandPermissions.DefaultPermission.ALLOWED);
recoverEmailCommand.setCommandPermissions(UserPermission.RECOVER_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
// Register the base captcha command
@ -433,7 +435,7 @@ public class CommandManager {
add("capt");
}
}, "Captcha command", "Captcha command for AuthMeReloaded.", null);
captchaBaseCommand.setCommandPermissions("authme.captcha", CommandPermissions.DefaultPermission.ALLOWED);
captchaBaseCommand.setCommandPermissions(UserPermission.CAPTCHA, CommandPermissions.DefaultPermission.ALLOWED);
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
captchaBaseCommand.setMaximumArguments(false);
@ -452,7 +454,7 @@ public class CommandManager {
add("conv");
}
}, "Convert command", "Convert command for AuthMeReloaded.", null);
converterBaseCommand.setCommandPermissions("authme.converter", CommandPermissions.DefaultPermission.OP_ONLY);
converterBaseCommand.setCommandPermissions(UserPermission.CONVERTER, CommandPermissions.DefaultPermission.OP_ONLY);
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
converterBaseCommand.setMaximumArguments(false);

View File

@ -2,6 +2,7 @@ package fr.xephi.authme.command;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PermissionNode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -18,7 +19,7 @@ public class CommandPermissions {
/**
* Defines the permission nodes required to have permission to execute this command.
*/
private List<String> permissionNodes = new ArrayList<>();
private List<PermissionNode> permissionNodes = new ArrayList<>();
/**
* Defines the default permission if the permission nodes couldn't be used.
*/
@ -36,7 +37,7 @@ public class CommandPermissions {
* @param permissionNode The permission node required to execute a command.
* @param defaultPermission The default permission if the permission nodes couldn't be used.
*/
public CommandPermissions(String permissionNode, DefaultPermission defaultPermission) {
public CommandPermissions(PermissionNode permissionNode, DefaultPermission defaultPermission) {
this.permissionNodes.add(permissionNode);
this.defaultPermission = defaultPermission;
}
@ -47,7 +48,7 @@ public class CommandPermissions {
* @param permissionNodes The permission nodes required to execute a command.
* @param defaultPermission The default permission if the permission nodes couldn't be used.
*/
public CommandPermissions(List<String> permissionNodes, DefaultPermission defaultPermission) {
public CommandPermissions(List<PermissionNode> permissionNodes, DefaultPermission defaultPermission) {
this.permissionNodes.addAll(permissionNodes);
}
@ -58,14 +59,7 @@ public class CommandPermissions {
*
* @return True on success, false on failure.
*/
public boolean addPermissionNode(String permissionNode) {
// Trim the permission node
permissionNode = permissionNode.trim();
// Make sure the permission node is valid
if (permissionNode.length() == 0)
return false;
public boolean addPermissionNode(PermissionNode permissionNode) {
// Make sure this permission node hasn't been added already
if (hasPermissionNode(permissionNode))
return true;
@ -81,7 +75,7 @@ public class CommandPermissions {
*
* @return True if this permission node is required, false if not.
*/
public boolean hasPermissionNode(String permissionNode) {
public boolean hasPermissionNode(PermissionNode permissionNode) {
return this.permissionNodes.contains(permissionNode);
}
@ -90,7 +84,7 @@ public class CommandPermissions {
*
* @return The permission nodes required to execute this command.
*/
public List<String> getPermissionNodes() {
public List<PermissionNode> getPermissionNodes() {
return this.permissionNodes;
}
@ -99,7 +93,7 @@ public class CommandPermissions {
*
* @param permissionNodes The permission nodes required to execute this command.
*/
public void setPermissionNodes(List<String> permissionNodes) {
public void setPermissionNodes(List<PermissionNode> permissionNodes) {
this.permissionNodes = permissionNodes;
}
@ -140,9 +134,11 @@ public class CommandPermissions {
return false;
// Check whether the player has permission, return the result
for (String node : this.permissionNodes)
if (!permissionsManager.hasPermission(player, node, defaultPermission))
for (PermissionNode node : this.permissionNodes) {
if (!permissionsManager.hasPermission(player, node, defaultPermission)) {
return false;
}
}
return true;
}

View File

@ -3,6 +3,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.permission.UserPermission;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -29,7 +30,7 @@ public class ForceLoginCommand extends ExecutableCommand {
sender.sendMessage("Player needs to be online!");
return true;
}
if (!plugin.getPermissionsManager().hasPermission(player, "authme.canbeforced")) {
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.CAN_LOGIN_BE_FORCED)) {
sender.sendMessage("You cannot force login for the player " + playerName + "!");
return true;
}

View File

@ -5,6 +5,7 @@ import fr.xephi.authme.command.CommandArgumentDescription;
import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.CommandPermissions;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -103,7 +104,7 @@ public class HelpPrinter {
sender.sendMessage(ChatColor.GOLD + "Permissions:");
// Print each node
for (String node : permissions.getPermissionNodes()) {
for (PermissionNode node : permissions.getPermissionNodes()) {
boolean nodePermission = true;
if (sender instanceof Player)
nodePermission = AuthMe.getInstance().getPermissionsManager().hasPermission((Player) sender, node);

View File

@ -10,6 +10,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.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
@ -41,21 +42,11 @@ public class AuthMePlayerListener implements Listener {
public final AuthMe plugin;
private final Messages m;
/**
* Constructor for AuthMePlayerListener.
*
* @param plugin AuthMe
*/
public AuthMePlayerListener(AuthMe plugin) {
this.m = plugin.getMessages();
this.plugin = plugin;
}
/**
* Method handleChat.
*
* @param event AsyncPlayerChatEvent
*/
private void handleChat(AsyncPlayerChatEvent event) {
if (Settings.isChatAllowed) {
return;
@ -89,11 +80,6 @@ public class AuthMePlayerListener implements Listener {
});
}
/**
* Method onPlayerCommandPreprocess.
*
* @param event PlayerCommandPreprocessEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String cmd = event.getMessage().split(" ")[0].toLowerCase();
@ -109,71 +95,36 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerNormalChat.
*
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerNormalChat(AsyncPlayerChatEvent event) {
handleChat(event);
}
/**
* Method onPlayerHighChat.
*
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerHighChat(AsyncPlayerChatEvent event) {
handleChat(event);
}
/**
* Method onPlayerChat.
*
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) {
handleChat(event);
}
/**
* Method onPlayerHighestChat.
*
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerHighestChat(AsyncPlayerChatEvent event) {
handleChat(event);
}
/**
* Method onPlayerEarlyChat.
*
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerEarlyChat(AsyncPlayerChatEvent event) {
handleChat(event);
}
/**
* Method onPlayerLowChat.
*
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerLowChat(AsyncPlayerChatEvent event) {
handleChat(event);
}
/**
* Method onPlayerMove.
*
* @param event PlayerMoveEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent event) {
if (Settings.isMovementAllowed && Settings.getMovementRadius <= 0) {
@ -216,11 +167,6 @@ public class AuthMePlayerListener implements Listener {
}
}
/**
* Method onPlayerJoin.
*
* @param event PlayerJoinEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer() == null || Utils.isNPC(event.getPlayer())) {
@ -250,11 +196,6 @@ public class AuthMePlayerListener implements Listener {
});
}
/**
* Method onPreLogin.
*
* @param event AsyncPlayerPreLoginEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
final String name = event.getName().toLowerCase();
@ -282,11 +223,6 @@ public class AuthMePlayerListener implements Listener {
}
}
/**
* Method onPlayerLogin.
*
* @param event PlayerLoginEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) {
if (event.getPlayer() == null) {
@ -318,7 +254,7 @@ public class AuthMePlayerListener implements Listener {
PermissionsManager permsMan = plugin.getPermissionsManager();
final Player player = event.getPlayer();
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, "authme.vip")) {
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, UserPermission.IS_VIP)) {
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return;
@ -331,7 +267,7 @@ public class AuthMePlayerListener implements Listener {
final String name = player.getName().toLowerCase();
boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, UserPermission.BYPASS_ANTIBOT)) {
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (Settings.countriesBlacklist.contains(code)) {
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
@ -340,7 +276,7 @@ public class AuthMePlayerListener implements Listener {
}
}
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, UserPermission.BYPASS_ANTIBOT)) {
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (!Settings.countries.contains(code)) {
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
@ -383,11 +319,6 @@ public class AuthMePlayerListener implements Listener {
}
}
/**
* Method onPlayerQuit.
*
* @param event PlayerQuitEvent
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
if (event.getPlayer() == null) {
@ -403,11 +334,6 @@ public class AuthMePlayerListener implements Listener {
plugin.management.performQuit(player, false);
}
/**
* Method onPlayerKick.
*
* @param event PlayerKickEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
if (event.getPlayer() == null) {
@ -423,11 +349,6 @@ public class AuthMePlayerListener implements Listener {
plugin.management.performQuit(player, true);
}
/**
* Method onPlayerPickupItem.
*
* @param event PlayerPickupItemEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (Utils.checkAuth(event.getPlayer()))
@ -435,11 +356,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerInteract.
*
* @param event PlayerInteractEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
@ -448,11 +364,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerConsumeItem.
*
* @param event PlayerItemConsumeEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerConsumeItem(PlayerItemConsumeEvent event) {
if (Utils.checkAuth(event.getPlayer()))
@ -460,11 +371,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerInventoryOpen.
*
* @param event InventoryOpenEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
final Player player = (Player) event.getPlayer();
@ -485,11 +391,6 @@ public class AuthMePlayerListener implements Listener {
}, 1);
}
/**
* Method onPlayerInventoryClick.
*
* @param event InventoryClickEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInventoryClick(InventoryClickEvent event) {
if (event.getWhoClicked() == null)
@ -501,11 +402,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method playerHitPlayerEvent.
*
* @param event EntityDamageByEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void playerHitPlayerEvent(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
@ -518,11 +414,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerInteractEntity.
*
* @param event PlayerInteractEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
@ -531,11 +422,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerDropItem.
*
* @param event PlayerDropItemEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (Utils.checkAuth(event.getPlayer()))
@ -543,11 +429,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerBedEnter.
*
* @param event PlayerBedEnterEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (Utils.checkAuth(event.getPlayer()))
@ -555,11 +436,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onSignChange.
*
* @param event SignChangeEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onSignChange(SignChangeEvent event) {
if (Utils.checkAuth(event.getPlayer()))
@ -567,11 +443,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerRespawn.
*
* @param event PlayerRespawnEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
@ -588,17 +459,12 @@ public class AuthMePlayerListener implements Listener {
}
}
/**
* Method onPlayerGameModeChange.
*
* @param event PlayerGameModeChangeEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
Player player = event.getPlayer();
if (player == null)
return;
if (plugin.getPermissionsManager().hasPermission(player, "authme.bypassforcesurvival"))
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL))
return;
if (Utils.checkAuth(player))
return;
@ -611,11 +477,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerShear.
*
* @param event PlayerShearEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerShear(PlayerShearEntityEvent event) {
Player player = event.getPlayer();
@ -624,11 +485,6 @@ public class AuthMePlayerListener implements Listener {
event.setCancelled(true);
}
/**
* Method onPlayerFish.
*
* @param event PlayerFishEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerFish(PlayerFishEvent event) {
Player player = event.getPlayer();

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission;
/**
* AuthMe admin permissions.
*/
public enum AdminPermission implements PermissionsNode {
public enum AdminPermission implements PermissionNode {
REGISTER("authme.admin.register"),

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission;
/**
* Common interface for AuthMe permission nodes.
*/
public interface PermissionsNode {
public interface PermissionNode {
/** Return the node of the permission, e.g. "authme.unregister". */
String getNode();

View File

@ -98,10 +98,10 @@ public class PermissionsManager {
/**
* Return the permissions system where the permissions manager is currently hooked into.
*
* @return Permissions system type.
* @return The name of the permissions system used.
*/
public PermissionsSystemType getUsedPermissionsSystemType() {
return this.permsType;
public String getUsedPermissionsSystemType() {
return this.permsType.getName();
}
/**
@ -330,12 +330,16 @@ public class PermissionsManager {
* the player has to be OP in order to have the permission.
*
* @param player The player.
* @param permissionsNode The permissions node to verify.
* @param permissionNode The permissions node to verify.
*
* @return True if the player has the permission, false otherwise.
*/
public boolean hasPermission(Player player, PermissionsNode permissionsNode) {
return hasPermission(player, permissionsNode.getNode(), player.isOp());
public boolean hasPermission(Player player, PermissionNode permissionNode) {
return hasPermission(player, permissionNode, player.isOp());
}
public boolean hasPermission(Player player, PermissionNode permissionNode, boolean def) {
return hasPermission(player, permissionNode.getNode(), def);
}
/**
@ -910,7 +914,7 @@ public class PermissionsManager {
return removeGroups(player, groupNames);
}
public enum PermissionsSystemType {
private enum PermissionsSystemType {
NONE("None"),
PERMISSIONS_EX("PermissionsEx"),
PERMISSIONS_BUKKIT("Permissions Bukkit"),

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission;
/**
* AuthMe user permission nodes.
*/
public enum UserPermission implements PermissionsNode {
public enum UserPermission implements PermissionNode {
BYPASS_ANTIBOT("authme.bypassantibot"),

View File

@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
@ -38,7 +39,7 @@ public class AsyncChangeEmail {
String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts")
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;

View File

@ -10,6 +10,7 @@ import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
@ -93,7 +94,10 @@ public class AsynchronousJoin {
});
return;
}
if (Settings.getMaxJoinPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost")) {
if (Settings.getMaxJoinPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& !ip.equalsIgnoreCase("127.0.0.1")
&& !ip.equalsIgnoreCase("localhost")) {
if (plugin.hasJoinedIp(player.getName(), ip)) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() {

View File

@ -8,6 +8,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.MessageKey;
@ -119,7 +120,7 @@ public class AsynchronousLogin {
}
return null;
}
if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) {
if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) {
if (plugin.isLoggedIp(name, getIP())) {
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return null;
@ -267,7 +268,7 @@ public class AsynchronousLogin {
* uuidaccounts + "."; } }
*/
for (Player player : Utils.getOnlinePlayers()) {
if (plugin.getPermissionsManager().hasPermission(player, "authme.seeOtherAccounts")) {
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.SEE_OTHER_ACCOUNTS)) {
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
player.sendMessage(message.toString());
// player.sendMessage(uuidaccounts.replace("%size%",

View File

@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
@ -26,15 +27,6 @@ public class AsyncRegister {
private final DataSource database;
private final Messages m;
/**
* Constructor for AsyncRegister.
*
* @param player Player
* @param password String
* @param email String
* @param plugin AuthMe
* @param data DataSource
*/
public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data) {
this.m = plugin.getMessages();
this.player = player;
@ -45,20 +37,10 @@ public class AsyncRegister {
this.database = data;
}
/**
* Method getIp.
*
* @return String
*/
protected String getIp() {
return plugin.getIP(player);
}
/**
* Method preRegisterCheck.
*
* @return boolean * @throws Exception
*/
protected boolean preRegisterCheck() throws Exception {
String passLow = password.toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(name)) {
@ -82,25 +64,28 @@ public class AsyncRegister {
} else if (database.isAuthAvailable(name)) {
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
return false;
} else if (Settings.getmaxRegPerIp > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return false;
}
} else if (Settings.getmaxRegPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp
&& !getIp().equalsIgnoreCase("127.0.0.1")
&& !getIp().equalsIgnoreCase("localhost")) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return false;
}
return true;
}
public void process() {
try {
if (!preRegisterCheck())
if (!preRegisterCheck()) {
return;
}
if (!email.isEmpty() && !email.equals("")) {
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
emailRegister();
return;
@ -113,17 +98,12 @@ public class AsyncRegister {
}
}
/**
* Method emailRegister.
*
* @throws Exception
*/
protected void emailRegister() throws Exception {
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
PlayerAuth auth;
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);

View File

@ -7,6 +7,7 @@ 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.permission.UserPermission;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -200,7 +201,7 @@ public final class Utils {
* @param player the player to modify.
*/
public static void forceGM(Player player) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.bypassforcesurvival")) {
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)) {
player.setGameMode(GameMode.SURVIVAL);
}
}

View File

@ -3,6 +3,7 @@ package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.settings.Settings;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@ -53,7 +54,7 @@ public class UtilsTest {
public void shouldForceSurvivalGameMode() {
// given
Player player = mock(Player.class);
given(permissionsManagerMock.hasPermission(player, "authme.bypassforcesurvival")).willReturn(false);
given(permissionsManagerMock.hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)).willReturn(false);
// when
Utils.forceGM(player);
@ -67,14 +68,14 @@ public class UtilsTest {
public void shouldNotForceGameModeForUserWithBypassPermission() {
// given
Player player = mock(Player.class);
given(permissionsManagerMock.hasPermission(player, "authme.bypassforcesurvival")).willReturn(true);
given(permissionsManagerMock.hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)).willReturn(true);
// when
Utils.forceGM(player);
// then
verify(authMeMock).getPermissionsManager();
verify(permissionsManagerMock).hasPermission(player, "authme.bypassforcesurvival");
verify(permissionsManagerMock).hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL);
verify(player, never()).setGameMode(any(GameMode.class));
}