Move default permissions out of Commands and into PermissionNode - fixes #606

This commit is contained in:
EbonJaguar
2016-05-30 16:47:48 -04:00
parent 8a0655e333
commit 3ad00a45f9
13 changed files with 150 additions and 177 deletions
@@ -8,115 +8,121 @@ public enum AdminPermission implements PermissionNode {
/**
* Administrator command to register a new user.
*/
REGISTER("authme.admin.register"),
REGISTER("authme.admin.register", DefaultPermission.OP_ONLY),
/**
* Administrator command to unregister an existing user.
*/
UNREGISTER("authme.admin.unregister"),
UNREGISTER("authme.admin.unregister", DefaultPermission.OP_ONLY),
/**
* Administrator command to force-login an existing user.
*/
FORCE_LOGIN("authme.admin.forcelogin"),
FORCE_LOGIN("authme.admin.forcelogin", DefaultPermission.OP_ONLY),
/**
* Administrator command to change the password of a user.
*/
CHANGE_PASSWORD("authme.admin.changepassword"),
CHANGE_PASSWORD("authme.admin.changepassword", DefaultPermission.OP_ONLY),
/**
* Administrator command to see the last login date and time of a user.
*/
LAST_LOGIN("authme.admin.lastlogin"),
LAST_LOGIN("authme.admin.lastlogin", DefaultPermission.OP_ONLY),
/**
* Administrator command to see all accounts associated with a user.
*/
ACCOUNTS("authme.admin.accounts"),
ACCOUNTS("authme.admin.accounts", DefaultPermission.OP_ONLY),
/**
* Administrator command to get the email address of a user, if set.
*/
GET_EMAIL("authme.admin.getemail"),
GET_EMAIL("authme.admin.getemail", DefaultPermission.OP_ONLY),
/**
* Administrator command to set or change the email address of a user.
*/
CHANGE_EMAIL("authme.admin.changemail"),
CHANGE_EMAIL("authme.admin.changemail", DefaultPermission.OP_ONLY),
/**
* Administrator command to get the last known IP of a user.
*/
GET_IP("authme.admin.getip"),
GET_IP("authme.admin.getip", DefaultPermission.OP_ONLY),
/**
* Administrator command to teleport to the AuthMe spawn.
*/
SPAWN("authme.admin.spawn"),
SPAWN("authme.admin.spawn", DefaultPermission.OP_ONLY),
/**
* Administrator command to set the AuthMe spawn.
*/
SET_SPAWN("authme.admin.setspawn"),
SET_SPAWN("authme.admin.setspawn", DefaultPermission.OP_ONLY),
/**
* Administrator command to teleport to the first AuthMe spawn.
*/
FIRST_SPAWN("authme.admin.firstspawn"),
FIRST_SPAWN("authme.admin.firstspawn", DefaultPermission.OP_ONLY),
/**
* Administrator command to set the first AuthMe spawn.
*/
SET_FIRST_SPAWN("authme.admin.setfirstspawn"),
SET_FIRST_SPAWN("authme.admin.setfirstspawn", DefaultPermission.OP_ONLY),
/**
* Administrator command to purge old user data.
*/
PURGE("authme.admin.purge"),
PURGE("authme.admin.purge", DefaultPermission.OP_ONLY),
/**
* Administrator command to purge the last position of a user.
*/
PURGE_LAST_POSITION("authme.admin.purgelastpos"),
PURGE_LAST_POSITION("authme.admin.purgelastpos", DefaultPermission.OP_ONLY),
/**
* Administrator command to purge all data associated with banned players.
*/
PURGE_BANNED_PLAYERS("authme.admin.purgebannedplayers"),
PURGE_BANNED_PLAYERS("authme.admin.purgebannedplayers", DefaultPermission.OP_ONLY),
/**
* Administrator command to toggle the AntiBot protection status.
*/
SWITCH_ANTIBOT("authme.admin.switchantibot"),
SWITCH_ANTIBOT("authme.admin.switchantibot", DefaultPermission.OP_ONLY),
/**
* Administrator command to convert old or other data to AuthMe data.
*/
CONVERTER("authme.admin.converter"),
CONVERTER("authme.admin.converter", DefaultPermission.OP_ONLY),
/**
* Administrator command to reload the plugin configuration.
*/
RELOAD("authme.admin.reload"),
RELOAD("authme.admin.reload", DefaultPermission.OP_ONLY),
/**
* Permission to see the other accounts of the players that log in.
*/
SEE_OTHER_ACCOUNTS("authme.admin.seeotheraccounts");
SEE_OTHER_ACCOUNTS("authme.admin.seeotheraccounts", DefaultPermission.OP_ONLY);
/**
* The permission node.
*/
private String node;
/**
* The default permission level
*/
private DefaultPermission defaultPermission;
/**
* Constructor.
*
* @param node Permission node.
*/
AdminPermission(String node) {
AdminPermission(String node, DefaultPermission defaultPermission) {
this.node = node;
this.defaultPermission = defaultPermission;
}
@Override
@@ -124,4 +130,8 @@ public enum AdminPermission implements PermissionNode {
return node;
}
@Override
public DefaultPermission getDefaultPermission() {
return defaultPermission;
}
}
@@ -12,4 +12,10 @@ public interface PermissionNode {
*/
String getNode();
/**
* Return the default permission for this node, e.g. "OP_ONLY"
*
* @return The default level of permission
*/
DefaultPermission getDefaultPermission();
}
@@ -285,15 +285,14 @@ public class PermissionsManager implements PermissionsService {
}
public boolean hasPermission(CommandSender sender, CommandDescription command) {
if (command.getCommandPermissions() == null
|| CollectionUtils.isEmpty(command.getCommandPermissions().getPermissionNodes())) {
if (command.getPermission() == null) {
return true;
}
DefaultPermission defaultPermission = command.getCommandPermissions().getDefaultPermission();
DefaultPermission defaultPermission = command.getPermission().getDefaultPermission();
boolean def = evaluateDefaultPermission(defaultPermission, sender);
return (sender instanceof Player)
? hasPermission((Player) sender, command.getCommandPermissions().getPermissionNodes(), def)
? hasPermission((Player) sender, command.getPermission().getNode(), def)
: def;
}
@@ -8,70 +8,76 @@ public enum PlayerPermission implements PermissionNode {
/**
* Command permission to login.
*/
LOGIN("authme.player.login"),
LOGIN("authme.player.login", DefaultPermission.ALLOWED),
/**
* Command permission to logout.
*/
LOGOUT("authme.player.logout"),
LOGOUT("authme.player.logout", DefaultPermission.ALLOWED),
/**
* Command permission to register.
*/
REGISTER("authme.player.register"),
REGISTER("authme.player.register", DefaultPermission.ALLOWED),
/**
* Command permission to unregister.
*/
UNREGISTER("authme.player.unregister"),
UNREGISTER("authme.player.unregister", DefaultPermission.ALLOWED),
/**
* Command permission to change the password.
*/
CHANGE_PASSWORD("authme.player.changepassword"),
CHANGE_PASSWORD("authme.player.changepassword", DefaultPermission.ALLOWED),
/**
* Command permission to add an email address.
*/
ADD_EMAIL("authme.player.email.add"),
ADD_EMAIL("authme.player.email.add", DefaultPermission.ALLOWED),
/**
* Command permission to change the email address.
*/
CHANGE_EMAIL("authme.player.email.change"),
CHANGE_EMAIL("authme.player.email.change", DefaultPermission.ALLOWED),
/**
* Command permission to recover an account using it's email address.
*/
RECOVER_EMAIL("authme.player.email.recover"),
RECOVER_EMAIL("authme.player.email.recover", DefaultPermission.ALLOWED),
/**
* Command permission to use captcha.
*/
CAPTCHA("authme.player.captcha"),
CAPTCHA("authme.player.captcha", DefaultPermission.ALLOWED),
/**
* Permission for users a login can be forced to.
*/
CAN_LOGIN_BE_FORCED("authme.player.canbeforced"),
CAN_LOGIN_BE_FORCED("authme.player.canbeforced", DefaultPermission.ALLOWED),
/**
* Permission to use to see own other accounts.
*/
SEE_OWN_ACCOUNTS("authme.player.seeownaccounts");
SEE_OWN_ACCOUNTS("authme.player.seeownaccounts", DefaultPermission.ALLOWED);
/**
* The permission node.
*/
private String node;
/**
* The default permission level
*/
private DefaultPermission defaultPermission;
/**
* Constructor.
*
* @param node Permission node.
*/
PlayerPermission(String node) {
PlayerPermission(String node, DefaultPermission defaultPermission) {
this.node = node;
this.defaultPermission = defaultPermission;
}
@Override
@@ -79,4 +85,9 @@ public enum PlayerPermission implements PermissionNode {
return node;
}
@Override
public DefaultPermission getDefaultPermission() {
return defaultPermission;
}
}
@@ -9,39 +9,50 @@ public enum PlayerStatePermission implements PermissionNode {
/**
* Permission node to bypass AntiBot protection.
*/
BYPASS_ANTIBOT("authme.bypassantibot"),
BYPASS_ANTIBOT("authme.bypassantibot", DefaultPermission.OP_ONLY),
/**
* Permission for users to bypass force-survival mode.
*/
BYPASS_FORCE_SURVIVAL("authme.bypassforcesurvival"),
BYPASS_FORCE_SURVIVAL("authme.bypassforcesurvival", DefaultPermission.OP_ONLY),
/**
* Permission node to identify VIP users.
*/
IS_VIP("authme.vip"),
IS_VIP("authme.vip", DefaultPermission.OP_ONLY),
/**
* Permission to be able to register multiple accounts.
*/
ALLOW_MULTIPLE_ACCOUNTS("authme.allowmultipleaccounts");
ALLOW_MULTIPLE_ACCOUNTS("authme.allowmultipleaccounts", DefaultPermission.OP_ONLY);
/**
* The permission node.
*/
private String node;
/**
* The default permission level
*/
private DefaultPermission defaultPermission;
/**
* Constructor.
*
* @param node Permission node.
*/
PlayerStatePermission(String node) {
PlayerStatePermission(String node, DefaultPermission defaultPermission) {
this.node = node;
this.defaultPermission = defaultPermission;
}
@Override
public String getNode() {
return node;
}
@Override
public DefaultPermission getDefaultPermission() {
return defaultPermission;
}
}