Typo's and formatting

This commit is contained in:
ElgarL 2011-10-31 09:14:58 +00:00
parent 0f67d42c99
commit 0731de53b4
3 changed files with 2868 additions and 2846 deletions

View file

@ -58,7 +58,8 @@ public class GlobalGroups {
} }
/** /**
* @param haveGroupsChanged the haveGroupsChanged to set * @param haveGroupsChanged
* the haveGroupsChanged to set
*/ */
public void setGroupsChanged(boolean haveGroupsChanged) { public void setGroupsChanged(boolean haveGroupsChanged) {
this.haveGroupsChanged = haveGroupsChanged; this.haveGroupsChanged = haveGroupsChanged;
@ -71,14 +72,12 @@ public class GlobalGroups {
groups = new HashMap<String, Group>(); groups = new HashMap<String, Group>();
// READ globalGroups FILE // READ globalGroups FILE
File GlobalGroupsFile = new File(plugin.getDataFolder(), File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
"globalgroups.yml");
if (!GlobalGroupsFile.exists()) { if (!GlobalGroupsFile.exists()) {
try { try {
// Create a new file if it doesn't exist. // Create a new file if it doesn't exist.
Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), GlobalGroupsFile);
GlobalGroupsFile);
} catch (IOException ex) { } catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex); GroupManager.logger.log(Level.SEVERE, null, ex);
} }
@ -87,21 +86,17 @@ public class GlobalGroups {
try { try {
GGroups.load(GlobalGroupsFile); GGroups.load(GlobalGroupsFile);
} catch (Exception ex) { } catch (Exception ex) {
throw new IllegalArgumentException( throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + GlobalGroupsFile.getPath(), ex);
"The following file couldn't pass on Parser.\n"
+ GlobalGroupsFile.getPath(), ex);
} }
// Read all global groups // Read all global groups
Map<String, Object> allGroups = (Map<String, Object>) GGroups Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
.getConfigurationSection("groups").getValues(false);
// Load each groups permissions list. // Load each groups permissions list.
if (allGroups != null) if (allGroups != null)
for (String groupName : allGroups.keySet()) { for (String groupName : allGroups.keySet()) {
Group newGroup = new Group(groupName.toLowerCase()); Group newGroup = new Group(groupName.toLowerCase());
Object permissions = GGroups.get("groups." + groupName Object permissions = GGroups.get("groups." + groupName + ".permissions");
+ ".permissions");
if (permissions instanceof List) { if (permissions instanceof List) {
for (String permission : (List<String>) permissions) { for (String permission : (List<String>) permissions) {
@ -120,15 +115,12 @@ public class GlobalGroups {
} }
/** /**
* Write a dataHolder in a specified file * Write the globalgroups.yml file
* @param ph
* @param groupsFile
*/ */
public void writeGroups() { public void writeGroups() {
File GlobalGroupsFile = new File(plugin.getDataFolder(), File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
"globalgroups.yml");
Map<String, Object> root = new HashMap<String, Object>(); Map<String, Object> root = new HashMap<String, Object>();
@ -186,7 +178,6 @@ public class GlobalGroups {
return false; return false;
} }
/** /**
* Returns true if the Global Group exists in the globalgroups.yml * Returns true if the Global Group exists in the globalgroups.yml
* *
@ -209,8 +200,7 @@ public class GlobalGroups {
if (!hasGroup(groupName.toLowerCase())) if (!hasGroup(groupName.toLowerCase()))
return false; return false;
return groups.get(groupName.toLowerCase()).hasSamePermissionNode( return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode);
permissionNode);
} }
@ -222,8 +212,7 @@ public class GlobalGroups {
* @param permissionNode * @param permissionNode
* @return * @return
*/ */
public PermissionCheckResult checkPermission(String groupName, public PermissionCheckResult checkPermission(String groupName, String permissionNode) {
String permissionNode) {
PermissionCheckResult result = new PermissionCheckResult(); PermissionCheckResult result = new PermissionCheckResult();
result.askedPermission = permissionNode; result.askedPermission = permissionNode;

View file

@ -82,7 +82,8 @@ public class GroupManager extends JavaPlugin {
WorldEvents = null; WorldEvents = null;
BukkitPermissions = null; BukkitPermissions = null;
// EXAMPLE: Custom code, here we just output some info so we can check all is well // EXAMPLE: Custom code, here we just output some info so we can check
// all is well
PluginDescriptionFile pdfFile = this.getDescription(); PluginDescriptionFile pdfFile = this.getDescription();
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!"); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
GroupManager.logger.removeHandler(ch); GroupManager.logger.removeHandler(ch);
@ -111,15 +112,16 @@ public class GroupManager extends JavaPlugin {
throw new IllegalStateException("An error ocurred while loading GroupManager"); throw new IllegalStateException("An error ocurred while loading GroupManager");
} }
// Initialize the world listener and bukkit permissions to handle events. // Initialize the world listener and bukkit permissions to handle
// events.
WorldEvents = new GMWorldListener(this); WorldEvents = new GMWorldListener(this);
BukkitPermissions = new BukkitPermissions(this); BukkitPermissions = new BukkitPermissions(this);
enableScheduler(); enableScheduler();
/* /*
* Schedule a Bukiit Permissions update for 1 tick later. * Schedule a Bukiit Permissions update for 1 tick later. All plugins
* All plugins will be loaded by then * will be loaded by then
*/ */
if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) {
@ -130,8 +132,6 @@ public class GroupManager extends JavaPlugin {
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
} }
public static boolean isLoaded() { public static boolean isLoaded() {
return isLoaded; return isLoaded;
} }
@ -188,8 +188,7 @@ public class GroupManager extends JavaPlugin {
} }
/** /**
* Use the WorldsHolder saveChanges directly instead * Use the WorldsHolder saveChanges directly instead Saves the data on file
* Saves the data on file
*/ */
@Deprecated @Deprecated
public void commit() { public void commit() {
@ -199,8 +198,7 @@ public class GroupManager extends JavaPlugin {
} }
/** /**
* Use worlds holder to reload a specific world * Use worlds holder to reload a specific world Reloads the data
* Reloads the data
*/ */
@Deprecated @Deprecated
public void reload() { public void reload() {
@ -213,6 +211,7 @@ public class GroupManager extends JavaPlugin {
/** /**
* The handler in the interface created by AnjoCaido * The handler in the interface created by AnjoCaido
*
* @return * @return
*/ */
@Deprecated @Deprecated
@ -223,6 +222,7 @@ public class GroupManager extends JavaPlugin {
/** /**
* A simple interface, for ones that don't want to mess with overloading. * A simple interface, for ones that don't want to mess with overloading.
* Yet it is affected by overloading. But seamless. * Yet it is affected by overloading. But seamless.
*
* @return the dataholder with all information * @return the dataholder with all information
*/ */
@Deprecated @Deprecated
@ -232,6 +232,7 @@ public class GroupManager extends JavaPlugin {
/** /**
* Use this if you want to play with overloading. * Use this if you want to play with overloading.
*
* @return a dataholder with overloading interface * @return a dataholder with overloading interface
*/ */
@Deprecated @Deprecated
@ -241,6 +242,7 @@ public class GroupManager extends JavaPlugin {
/** /**
* Called when a command registered by this plugin is received. * Called when a command registered by this plugin is received.
*
* @param sender * @param sender
* @param cmd * @param cmd
* @param args * @param args
@ -255,7 +257,6 @@ public class GroupManager extends JavaPlugin {
User senderUser = null; User senderUser = null;
boolean isOpOverride = config.isOpOverride(); boolean isOpOverride = config.isOpOverride();
// DETERMINING PLAYER INFORMATION // DETERMINING PLAYER INFORMATION
if (sender instanceof Player) { if (sender instanceof Player) {
senderPlayer = (Player) sender; senderPlayer = (Player) sender;
@ -290,7 +291,6 @@ public class GroupManager extends JavaPlugin {
// VARIABLES USED IN COMMANDS // VARIABLES USED IN COMMANDS
int count; int count;
PermissionCheckResult permissionResult = null; PermissionCheckResult permissionResult = null;
ArrayList<User> removeList = null; ArrayList<User> removeList = null;
@ -381,7 +381,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'."); sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
// break; // break;
@ -418,7 +419,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' to default settings."); sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' to default settings.");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
case manuaddsub: case manuaddsub:
@ -462,7 +464,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'."); sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
case manudelsub: case manudelsub:
@ -504,7 +507,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list."); sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list.");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
case mangadd: case mangadd:
@ -580,8 +584,7 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
|| permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have."); sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
return false; return false;
} }
@ -615,7 +618,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to player '" + auxUser.getName() + "' permissions."); sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to player '" + auxUser.getName() + "' permissions.");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
// break; // break;
@ -648,8 +652,7 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
|| permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have."); sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
return false; return false;
} }
@ -669,7 +672,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from player '" + auxUser.getName() + "' permissions."); sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from player '" + auxUser.getName() + "' permissions.");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
// break; // break;
@ -739,7 +743,6 @@ public class GroupManager extends JavaPlugin {
} }
} }
return true; return true;
case manucheckp: case manucheckp:
// VALIDANDO ESTADO DO SENDER // VALIDANDO ESTADO DO SENDER
@ -774,7 +777,8 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
// PARECE OK // PARECE OK
//auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]); // auxString =
// permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
if (permissionResult.owner instanceof User) { if (permissionResult.owner instanceof User) {
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) { if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
sender.sendMessage(ChatColor.RED + "The user has directly a negation node for that permission."); sender.sendMessage(ChatColor.RED + "The user has directly a negation node for that permission.");
@ -796,7 +800,6 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1])); sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]));
} }
return true; return true;
case mangaddp: case mangaddp:
// VALIDANDO ESTADO DO SENDER // VALIDANDO ESTADO DO SENDER
@ -816,8 +819,7 @@ public class GroupManager extends JavaPlugin {
} }
// VALIDANDO SUA PERMISSAO // VALIDANDO SUA PERMISSAO
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
|| permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have."); sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
return false; return false;
} }
@ -871,8 +873,7 @@ public class GroupManager extends JavaPlugin {
} }
// VALIDANDO SUA PERMISSAO // VALIDANDO SUA PERMISSAO
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
|| permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have."); sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
return false; return false;
} }
@ -965,7 +966,8 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
// PARECE OK // PARECE OK
//auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]); // auxString =
// permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
if (permissionResult.owner instanceof Group) { if (permissionResult.owner instanceof Group) {
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) { if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName()); sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName());
@ -1607,7 +1609,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
// break; // break;
@ -1666,7 +1669,8 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
targetPlayer = this.getServer().getPlayer(auxUser.getName()); targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer); if (targetPlayer != null)
BukkitPermissions.updatePermissions(targetPlayer);
return true; return true;
// break; // break;
@ -1769,11 +1773,9 @@ public class GroupManager extends JavaPlugin {
} }
/** /**
* Send confirmation of a group change. * Send confirmation of a group change. using permission nodes...
* using permission nodes...
* *
* groupmanager.notify.self * groupmanager.notify.self groupmanager.notify.other
* groupmanager.notify.other
* *
* @param name * @param name
* @param msg * @param msg
@ -1786,8 +1788,7 @@ public class GroupManager extends JavaPlugin {
if (!test.equals(player)) { if (!test.equals(player)) {
if (test.hasPermission("groupmanager.notify.other")) if (test.hasPermission("groupmanager.notify.other"))
test.sendMessage(ChatColor.YELLOW + name + " was" + msg); test.sendMessage(ChatColor.YELLOW + name + " was" + msg);
} else } else if ((player != null) && ((player.hasPermission("groupmanager.notify.self")) || (player.hasPermission("groupmanager.notify.other"))))
if ((player != null) && ((player.hasPermission("groupmanager.notify.self")) || (player.hasPermission("groupmanager.notify.other"))))
player.sendMessage(ChatColor.YELLOW + "You were" + msg); player.sendMessage(ChatColor.YELLOW + "You were" + msg);
} }

View file

@ -34,6 +34,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* It needs a WorldDataHolder to work with. * It needs a WorldDataHolder to work with.
*
* @param holder * @param holder
*/ */
public AnjoPermissionsHandler(WorldDataHolder holder) { public AnjoPermissionsHandler(WorldDataHolder holder) {
@ -42,6 +43,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* A short name method, for permission method. * A short name method, for permission method.
*
* @param player * @param player
* @param permission * @param permission
* @return * @return
@ -53,6 +55,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Checks if a player can use that permission node. * Checks if a player can use that permission node.
*
* @param player * @param player
* @param permission * @param permission
* @return * @return
@ -64,6 +67,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Checks if a player can use that permission node. * Checks if a player can use that permission node.
*
* @param playerName * @param playerName
* @param permission * @param permission
* @return * @return
@ -74,6 +78,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the name of the group of that player name. * Returns the name of the group of that player name.
*
* @param userName * @param userName
* @return * @return
*/ */
@ -83,7 +88,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns All permissions (including inheritance and sub groups) for the player. * Returns All permissions (including inheritance and sub groups) for the
* player.
* *
* @param userName * @param userName
* @return * @return
@ -133,16 +139,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Verify if player is in suck group. * Verify if player is in suck group. It will check it's groups inheritance.
* It will check it's groups inheritance.
* *
* So if you have a group Admin > Moderator * So if you have a group Admin > Moderator
* *
* And verify the player 'MyAdmin', which is Admin, it will return true for both * And verify the player 'MyAdmin', which is Admin, it will return true for
* Admin or Moderator groups. * both Admin or Moderator groups.
* *
* Mas if you have a player 'MyModerator', which is Moderator, * Mas if you have a player 'MyModerator', which is Moderator, it will give
* it will give false if you pass Admin in group parameter. * false if you pass Admin in group parameter.
* *
* @param name * @param name
* @param group * @param group
@ -162,11 +167,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Gets the appropriate prefix for the user. * Gets the appropriate prefix for the user. This method is a utility method
* This method is a utility method for chat plugins to get the user's prefix * for chat plugins to get the user's prefix without having to look at every
* without having to look at every one of the user's ancestors. * one of the user's ancestors. Returns an empty string if user has no
* Returns an empty string if user has no parent groups. * parent groups.
* @param user Player's name *
* @param user
* Player's name
* @return Player's prefix * @return Player's prefix
*/ */
@Override @Override
@ -181,11 +188,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Gets the appropriate prefix for the user. * Gets the appropriate prefix for the user. This method is a utility method
* This method is a utility method for chat plugins to get the user's prefix * for chat plugins to get the user's prefix without having to look at every
* without having to look at every one of the user's ancestors. * one of the user's ancestors. Returns an empty string if user has no
* Returns an empty string if user has no parent groups. * parent groups.
* @param user Player's name *
* @param user
* Player's name
* @return Player's prefix * @return Player's prefix
*/ */
@Override @Override
@ -201,10 +210,12 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Gets name of the primary group of the user. * Gets name of the primary group of the user. Returns the name of the
* Returns the name of the default group if user has no parent groups, * default group if user has no parent groups, or "Default" if there is no
* or "Default" if there is no default group for that world. * default group for that world.
* @param user Player's name *
* @param user
* Player's name
* @return Name of player's primary group * @return Name of player's primary group
*/ */
public String getPrimaryGroup(String user) { public String getPrimaryGroup(String user) {
@ -215,8 +226,11 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Check if user can build. * Check if user can build.
* @param world Player's world *
* @param user Player's name * @param world
* Player's world
* @param user
* Player's name
* @return Whether the user can build * @return Whether the user can build
*/ */
public boolean canUserBuild(String user) { public boolean canUserBuild(String user) {
@ -232,6 +246,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the String prefix for the given group * Returns the String prefix for the given group
*
* @param groupName * @param groupName
* @return empty string if found none. * @return empty string if found none.
*/ */
@ -246,6 +261,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Return the suffix for the given group name * Return the suffix for the given group name
*
* @param groupName * @param groupName
* @return * @return
*/ */
@ -273,8 +289,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* It returns a string variable value, set in the INFO node of the group. * It returns a string variable value, set in the INFO node of the group. It
* It will harvest inheritance for value. * will harvest inheritance for value.
*
* @param groupName * @param groupName
* @param variable * @param variable
* @return null if no group with that variable is found. * @return null if no group with that variable is found.
@ -293,8 +310,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* It returns a Integer variable value * It returns a Integer variable value It will harvest inheritance for
* It will harvest inheritance for value. * value.
*
* @param groupName * @param groupName
* @param variable * @param variable
* @return -1 if none found or not parseable. * @return -1 if none found or not parseable.
@ -313,8 +331,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns a boolean for given variable in INFO node. * Returns a boolean for given variable in INFO node. It will harvest
* It will harvest inheritance for value. * inheritance for value.
*
* @param group * @param group
* @param variable * @param variable
* @return false if not found/not parseable. * @return false if not found/not parseable.
@ -333,8 +352,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns a double value for the given variable name in INFO node. * Returns a double value for the given variable name in INFO node. It will
* It will harvest inheritance for value. * harvest inheritance for value.
*
* @param group * @param group
* @param variable * @param variable
* @return -1 if not found / not parseable. * @return -1 if not found / not parseable.
@ -354,6 +374,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -369,6 +390,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -384,6 +406,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -399,6 +422,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node.
*
* @param user * @param user
* @param variable * @param variable
* @return * @return
@ -413,9 +437,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return empty string if not found * @return empty string if not found
@ -442,9 +466,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return -1 if not found * @return -1 if not found
@ -471,9 +495,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return false if not found or not parseable to true. * @return false if not found or not parseable to true.
@ -500,9 +524,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the variable value of the user, in INFO node. * Returns the variable value of the user, in INFO node. If not found, it
* If not found, it will search for his Group variables. * will search for his Group variables. It will harvest the inheritance.
* It will harvest the inheritance. *
* @param user * @param user
* @param variable * @param variable
* @return -1 if not found. * @return -1 if not found.
@ -530,6 +554,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Does not include User's group permission * Does not include User's group permission
*
* @param user * @param user
* @param permission * @param permission
* @return * @return
@ -557,8 +582,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Returns the node responsible for that permission. * Returns the node responsible for that permission. Does not include User's
* Does not include User's group permission. * group permission.
*
* @param group * @param group
* @param permission * @param permission
* @return the node if permission is found. if not found, return null * @return the node if permission is found. if not found, return null
@ -587,14 +613,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Check permissions, including it's group and inheritance. * Check permissions, including it's group and inheritance.
*
* @param user * @param user
* @param permission * @param permission
* @return true if permission was found. false if not, or was negated. * @return true if permission was found. false if not, or was negated.
*/ */
public boolean checkUserPermission(User user, String permission) { public boolean checkUserPermission(User user, String permission) {
PermissionCheckResult result = checkFullUserPermission(user, permission); PermissionCheckResult result = checkFullUserPermission(user, permission);
if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
|| result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
return true; return true;
} }
if (Bukkit.getPlayer(user.getName()).hasPermission(permission)) if (Bukkit.getPlayer(user.getName()).hasPermission(permission))
@ -604,7 +630,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* Do what checkUserPermission did before. But now returning a PermissionCheckResult. * Do what checkUserPermission did before. But now returning a
* PermissionCheckResult.
*
* @param user * @param user
* @param targetPermission * @param targetPermission
* @return * @return
@ -657,7 +685,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* @param variable * @param variable
* @param alreadyChecked * @param alreadyChecked
* @return returns the closest inherited group with the variable. * @return returns the closest inherited group with the variable.
* @deprecated use now nextGroupWithVariable(Group start, String targetVariable) * @deprecated use now nextGroupWithVariable(Group start, String
* targetVariable)
*/ */
@Deprecated @Deprecated
public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) { public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) {
@ -670,8 +699,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* *
* It does Breadth-first search * It does Breadth-first search
* *
* @param start the starting group to look for * @param start
* @param targetVariable the variable name * the starting group to look for
* @param targetVariable
* the variable name
* @return The group if found. Null if not. * @return The group if found. Null if not.
*/ */
public Group nextGroupWithVariable(Group start, String targetVariable) { public Group nextGroupWithVariable(Group start, String targetVariable) {
@ -704,11 +735,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* redirected to the other method. this is deprecated now. and will be gone * redirected to the other method. this is deprecated now. and will be gone
* in the future releases. * in the future releases.
* *
* @param start The group to start the search. * @param start
* @param askedGroup Name of the group you're looking for * The group to start the search.
* @param alreadyChecked groups to ignore(pass null on it, please) * @param askedGroup
* Name of the group you're looking for
* @param alreadyChecked
* groups to ignore(pass null on it, please)
* @return true if it inherits the group. * @return true if it inherits the group.
* @deprecated prefer using hasGroupInInheritance(Group start, String askedGroup) * @deprecated prefer using hasGroupInInheritance(Group start, String
* askedGroup)
*/ */
@Deprecated @Deprecated
public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) { public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) {
@ -720,8 +755,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* *
* It does Breadth-first search * It does Breadth-first search
* *
* @param start The group to start the search. * @param start
* @param askedGroup Name of the group you're looking for * The group to start the search.
* @param askedGroup
* Name of the group you're looking for
* @return true if it inherits the group. * @return true if it inherits the group.
*/ */
public boolean hasGroupInInheritance(Group start, String askedGroup) { public boolean hasGroupInInheritance(Group start, String askedGroup) {
@ -750,30 +787,30 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Check if the group has given permission. Including it's inheritance * Check if the group has given permission. Including it's inheritance
*
* @param start * @param start
* @param permission * @param permission
* @param alreadyChecked * @param alreadyChecked
* @return true if PermissionCheckResult is EXCEPTION or FOUND * @return true if PermissionCheckResult is EXCEPTION or FOUND
* @deprecated use the other checkGroupPermissionWithInheritance for everything * @deprecated use the other checkGroupPermissionWithInheritance for
* everything
*/ */
@Deprecated @Deprecated
public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) { public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) {
PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
if (result.resultType.equals(Type.EXCEPTION) if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
|| result.resultType.equals(Type.FOUND)) {
return true; return true;
} }
return false; return false;
} }
/** /**
* Returns the result of permission check. Including inheritance. * Returns the result of permission check. Including inheritance. If found
* If found anything, the PermissionCheckResult that retuns will * anything, the PermissionCheckResult that retuns will include the Group
* include the Group name, and the result type. * name, and the result type. Result types will be EXCEPTION, NEGATION,
* Result types will be EXCEPTION, NEGATION, FOUND. * FOUND.
* *
* If returned type NOTFOUND, the owner will be null, * If returned type NOTFOUND, the owner will be null, and ownerType too.
* and ownerType too.
* *
* It does Breadth-first search * It does Breadth-first search
* *
@ -810,8 +847,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
/** /**
* It uses checkGroupPermissionWithInheritance * It uses checkGroupPermissionWithInheritance and cast the owner to Group
* and cast the owner to Group type if result type was EXCEPTION or FOUND. * type if result type was EXCEPTION or FOUND.
* *
* @param start * @param start
* @param permission * @param permission
@ -822,8 +859,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
@Deprecated @Deprecated
public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) { public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) {
PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
if (result.resultType.equals(Type.EXCEPTION) if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
|| result.resultType.equals(Type.FOUND)) {
return (Group) checkGroupPermissionWithInheritance(start, permission).owner; return (Group) checkGroupPermissionWithInheritance(start, permission).owner;
} }
return null; return null;
@ -833,8 +869,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* Return whole list of names of groups in a inheritance chain. Including a * Return whole list of names of groups in a inheritance chain. Including a
* starting group. * starting group.
* *
* it now redirects to the other method. but get away from this one, * it now redirects to the other method. but get away from this one, it will
* it will disappear in a future release. * disappear in a future release.
* *
* @param start * @param start
* @param alreadyChecked * @param alreadyChecked
@ -878,17 +914,17 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* Compare a user permission like 'myplugin.*' against a full plugin * Compare a user permission like 'myplugin.*' against a full plugin
* permission name, like 'myplugin.dosomething'. * permission name, like 'myplugin.dosomething'. As the example above, will
* As the example above, will return true. * return true.
* *
* Please sort permissions before sending them here. So negative tokens * Please sort permissions before sending them here. So negative tokens get
* get priority. * priority.
* *
* You must test if it start with negative outside this method. It will * You must test if it start with negative outside this method. It will only
* only tell if the nodes are matching or not. * tell if the nodes are matching or not.
* *
* Every '-' or '+' in the beginning is ignored. It will match only * Every '-' or '+' in the beginning is ignored. It will match only node
* node names. * names.
* *
* @param userAcessLevel * @param userAcessLevel
* @param fullPermissionName * @param fullPermissionName
@ -912,7 +948,6 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
fullPermissionName = fullPermissionName.substring(1); fullPermissionName = fullPermissionName.substring(1);
} }
StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, "."); StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, ".");
StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, "."); StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, ".");
while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) { while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) {
@ -944,6 +979,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* Returns a list of all groups. * Returns a list of all groups.
* *
* Including subgroups. * Including subgroups.
*
* @param userName * @param userName
* @return * @return
*/ */
@ -961,8 +997,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/** /**
* A Breadth-first search thru inheritance model. * A Breadth-first search thru inheritance model.
* *
* Just a model to copy and paste. * Just a model to copy and paste. This will guarantee the closer groups
* This will guarantee the closer groups will be checked first. * will be checked first.
*
* @param start * @param start
* @param targerPermission * @param targerPermission
* @return * @return
@ -979,8 +1016,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
Group now = stack.pop(); Group now = stack.pop();
PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targerPermission); PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targerPermission);
if (resultNow.resultType.equals(PermissionCheckResult.Type.EXCEPTION) if (resultNow.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || resultNow.resultType.equals(PermissionCheckResult.Type.FOUND)) {
|| resultNow.resultType.equals(PermissionCheckResult.Type.FOUND)) {
return now; return now;
} }
if (resultNow.resultType.equals(PermissionCheckResult.Type.NEGATION)) { if (resultNow.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
@ -1003,8 +1039,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public String getInfoString(String entryName, String path, public String getInfoString(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {
@ -1021,8 +1056,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public int getInfoInteger(String entryName, String path, public int getInfoInteger(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {
@ -1039,8 +1073,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public double getInfoDouble(String entryName, String path, public double getInfoDouble(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {
@ -1058,8 +1091,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
@Override @Override
public boolean getInfoBoolean(String entryName, String path, public boolean getInfoBoolean(String entryName, String path, boolean isGroup) {
boolean isGroup) {
if (isGroup) { if (isGroup) {
Group data = ph.getGroup(entryName); Group data = ph.getGroup(entryName);
if (data == null) { if (data == null) {