From c0df77153958bb3cbd3f07c5be305027440a773e Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 21 Feb 2012 18:38:08 +0000 Subject: Update for Bukkit R5 compatability. Removed some unused variables. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/events/GMGroupEvent.java | 1 - .../src/org/anjocaido/groupmanager/events/GMSystemEvent.java | 1 - .../src/org/anjocaido/groupmanager/events/GMUserEvent.java | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 31d40413f..0566ef676 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -141,4 +141,5 @@ v 1.9: - Change Service registration to register WorldsHolder instead of AnjoPermissionsHandler. This is the correct entry point for all data. - Depreciate PlayerTeleportEvent, PlayerRespawnEvent and PlayerPortalEvent as it's all handled in PlayerChangedWorldEvent. This also means we no longer update permissions before we change worlds. - - A command of '/manload' with no world arguments now performs a full reload of GM. \ No newline at end of file + - A command of '/manload' with no world arguments now performs a full reload of GM. + - Update for Bukkit R5 compatability. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java index f109cf4f7..fc9b8433b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java @@ -16,7 +16,6 @@ public class GMGroupEvent extends Event { /** * */ - private static final long serialVersionUID = -5294917600434510451L; private static final HandlerList handlers = new HandlerList(); @Override diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java index 6f4c0ea08..210960876 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java @@ -15,7 +15,6 @@ public class GMSystemEvent extends Event { /** * */ - private static final long serialVersionUID = -8786811924448821548L; private static final HandlerList handlers = new HandlerList(); @Override diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java index 543580f41..206de8c86 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java @@ -16,7 +16,6 @@ public class GMUserEvent extends Event { /** * */ - private static final long serialVersionUID = -5294917600434510451L; private static final HandlerList handlers = new HandlerList(); @Override -- cgit v1.2.3 From 9c68cbae727f84a7b4dfb2594c458c3353a739d3 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 21 Feb 2012 18:40:54 +0000 Subject: Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- EssentialsGroupManager/src/config.yml | 4 ---- .../src/org/anjocaido/groupmanager/GMConfiguration.java | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 0566ef676..cb14c4e6e 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -142,4 +142,5 @@ v 1.9: - Depreciate PlayerTeleportEvent, PlayerRespawnEvent and PlayerPortalEvent as it's all handled in PlayerChangedWorldEvent. This also means we no longer update permissions before we change worlds. - A command of '/manload' with no world arguments now performs a full reload of GM. - - Update for Bukkit R5 compatability. \ No newline at end of file + - Update for Bukkit R5 compatability. + - Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. \ No newline at end of file diff --git a/EssentialsGroupManager/src/config.yml b/EssentialsGroupManager/src/config.yml index 13b59d343..cc90bea6f 100644 --- a/EssentialsGroupManager/src/config.yml +++ b/EssentialsGroupManager/src/config.yml @@ -4,10 +4,6 @@ settings: # The user will be able to promote players to the same group or even above. opOverrides: true - # If enabled any bukkit permissiosn which default to true will be left enabled. - # If the player is op any permissions set to Op will follow suit. - bukkit_perms_override: true - # Default setting for 'mantoglevalidate' # true will cause GroupManager to attempt name matching by default. validate_toggle: true diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java index d830696e7..98ff075dd 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java @@ -57,9 +57,6 @@ public class GMConfiguration { public boolean isOpOverride() { return GMconfig.getBoolean("settings.config.opOverrides", true); } - public boolean isBukkitPermsOverride() { - return GMconfig.getBoolean("settings.config.bukkit_perms_override", false); - } public boolean isToggleValidate() { return GMconfig.getBoolean("settings.config.validate_toggle", true); } -- cgit v1.2.3 From fa49fc91d2454b2da193ed2b757356b2496d504c Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 25 Feb 2012 09:22:54 +0000 Subject: Prevent adding inheritances to globalgroups. These are permissions collections, not player groups. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GroupManager.java | 10 +++ .../src/org/anjocaido/groupmanager/data/Group.java | 73 +++++++++++++--------- 3 files changed, 56 insertions(+), 30 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index cb14c4e6e..bb5cbf550 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -143,4 +143,5 @@ v 1.9: This also means we no longer update permissions before we change worlds. - A command of '/manload' with no world arguments now performs a full reload of GM. - Update for Bukkit R5 compatability. - - Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. \ No newline at end of file + - Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. + - Prevent adding inheritances to globalgroups. These are permissions collections, not player groups. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index d8d151200..3c39c24d7 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -1019,6 +1019,11 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group 2 does not exists!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support inheritance."); + return false; + } + // VALIDANDO PERMISSAO if (permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " already inherits " + auxGroup2.getName() + " (might not be directly)"); @@ -1052,6 +1057,11 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group 2 does not exists!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support inheritance."); + return false; + } + // VALIDANDO PERMISSAO if (!permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + "."); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index 5a39600b6..396240ec6 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -48,6 +48,15 @@ public class Group extends DataUnit implements Cloneable { public Group(String name) { super(name); } + + /** + * Is this a GlobalGroup + * + * @return + */ + public boolean isGlobal() { + return (getDataSource() == null); + } /** * Clone this group @@ -57,7 +66,7 @@ public class Group extends DataUnit implements Cloneable { public Group clone() { Group clone; - if (getDataSource() == null) { + if (isGlobal()) { clone = new Group(this.getName()); } else { clone = new Group(getDataSource(), this.getName()); @@ -85,7 +94,7 @@ public class Group extends DataUnit implements Cloneable { Group clone = dataSource.createGroup(this.getName()); // Don't add inheritance for GlobalGroups - if (getDataSource() != null) { + if (!isGlobal()) { clone.inherits = new ArrayList(this.getInherits()); } for (String perm : this.getPermissionList()) { @@ -110,26 +119,30 @@ public class Group extends DataUnit implements Cloneable { * @param inherit the inherits to set */ public void addInherits(Group inherit) { - if (!this.getDataSource().groupExists(inherit.getName())) { - getDataSource().addGroup(inherit); - } - if (!inherits.contains(inherit.getName().toLowerCase())) { - inherits.add(inherit.getName().toLowerCase()); - } - flagAsChanged(); - if (GroupManager.isLoaded()) { - GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); - } + if (!isGlobal()) { + if (!this.getDataSource().groupExists(inherit.getName())) { + getDataSource().addGroup(inherit); + } + if (!inherits.contains(inherit.getName().toLowerCase())) { + inherits.add(inherit.getName().toLowerCase()); + } + flagAsChanged(); + if (GroupManager.isLoaded()) { + GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); + } + } } public boolean removeInherits(String inherit) { - if (this.inherits.contains(inherit.toLowerCase())) { - this.inherits.remove(inherit.toLowerCase()); - flagAsChanged(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); - return true; - } + if (!isGlobal()) { + if (this.inherits.contains(inherit.toLowerCase())) { + this.inherits.remove(inherit.toLowerCase()); + flagAsChanged(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); + return true; + } + } return false; } @@ -145,15 +158,17 @@ public class Group extends DataUnit implements Cloneable { * @param varList */ public void setVariables(Map varList) { - GroupVariables temp = new GroupVariables(this, varList); - variables.clearVars(); - for (String key : temp.getVarKeyList()) { - variables.addVar(key, temp.getVarObject(key)); - } - flagAsChanged(); - if (GroupManager.isLoaded()) { - GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED); - } + if (!isGlobal()) { + GroupVariables temp = new GroupVariables(this, varList); + variables.clearVars(); + for (String key : temp.getVarKeyList()) { + variables.addVar(key, temp.getVarObject(key)); + } + flagAsChanged(); + if (GroupManager.isLoaded()) { + GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED); + } + } } } -- cgit v1.2.3 From 50bd5869bf18421918c6ef9f5ffe0fa46ccfb894 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 25 Feb 2012 09:29:54 +0000 Subject: Prevent promoting players to, and demoting to GlobalGroups. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../org/anjocaido/groupmanager/GroupManager.java | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index bb5cbf550..1159607ed 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -144,4 +144,5 @@ v 1.9: - A command of '/manload' with no world arguments now performs a full reload of GM. - Update for Bukkit R5 compatability. - Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. - - Prevent adding inheritances to globalgroups. These are permissions collections, not player groups. \ No newline at end of file + - Prevent adding inheritances and info nodes to globalgroups. These are permissions collections, not player groups. + - Prevent promoting players to, and demoting to GlobalGroups. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 3c39c24d7..b0d46ca1a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -398,6 +398,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group not found!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "Players may not be members of GlobalGroups directly."); + return false; + } // VALIDANDO PERMISSAO if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { @@ -1232,6 +1236,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group does not exists!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); + return false; + } // VALIDANDO PERMISSAO // PARECE OK auxString = ""; @@ -1261,6 +1269,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group does not exists!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); + return false; + } // VALIDANDO PERMISSAO if (!auxGroup.getVariables().hasVar(args[1])) { sender.sendMessage(ChatColor.RED + "The group doesn't have directly that variable!"); @@ -1286,6 +1298,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group does not exists!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); + return false; + } // VALIDANDO PERMISSAO // PARECE OK auxString = ""; @@ -1323,6 +1339,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group does not exists!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); + return false; + } // VALIDANDO PERMISSAO auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1], null); if (auxGroup2 == null) { @@ -1588,6 +1608,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group not found!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "Players may not be members of GlobalGroups directly."); + return false; + } // VALIDANDO PERMISSAO if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); @@ -1644,6 +1668,10 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group not found!"); return false; } + if (auxGroup.isGlobal()) { + sender.sendMessage(ChatColor.RED + "Players may not be members of GlobalGroups directly."); + return false; + } // VALIDANDO PERMISSAO if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); -- cgit v1.2.3 From 3823e7a108eaff2ecc65cb9221ad344d36f8c9ef Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 28 Feb 2012 10:46:10 +0000 Subject: Make 'manload' reload the config correctly. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 1159607ed..9d7187690 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -145,4 +145,5 @@ v 1.9: - Update for Bukkit R5 compatability. - Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. - Prevent adding inheritances and info nodes to globalgroups. These are permissions collections, not player groups. - - Prevent promoting players to, and demoting to GlobalGroups. \ No newline at end of file + - Prevent promoting players to, and demoting to GlobalGroups. + - Make 'manload' reload the config correctly. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index b0d46ca1a..00c71a41e 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -121,15 +121,15 @@ public class GroupManager extends JavaPlugin { ch = new GMLoggerHandler(); GroupManager.logger.addHandler(ch); logger.setLevel(Level.ALL); - if (worldsHolder == null) { - // Create the backup folder, if it doesn't exist. - prepareFileFields(); - // Load the config.yml - prepareConfig(); - // Load the global groups - globalGroups = new GlobalGroups(this); - worldsHolder = new WorldsHolder(this); - } + + // Create the backup folder, if it doesn't exist. + prepareFileFields(); + // Load the config.yml + prepareConfig(); + // Load the global groups + globalGroups = new GlobalGroups(this); + worldsHolder = new WorldsHolder(this); + PluginDescriptionFile pdfFile = this.getDescription(); if (worldsHolder == null) { -- cgit v1.2.3 From d2d8d191dad6af966ee1bda365d72098a52b587b Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 3 Mar 2012 13:00:17 +0000 Subject: Minor optimization when checking bukkit permissions. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../groupmanager/permissions/AnjoPermissionsHandler.java | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 9d7187690..9ea8082c0 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -146,4 +146,5 @@ v 1.9: - Removed BukkitPermsOverride as this is now the default with bukkit handling child nodes. - Prevent adding inheritances and info nodes to globalgroups. These are permissions collections, not player groups. - Prevent promoting players to, and demoting to GlobalGroups. - - Make 'manload' reload the config correctly. \ No newline at end of file + - Make 'manload' reload the config correctly. + - Minor optimization when checking bukkit permissions. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index bd2829f38..b9315e849 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -17,9 +17,7 @@ import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.utils.PermissionCheckResult; import org.anjocaido.groupmanager.utils.PermissionCheckResult.Type; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; /** * Everything here maintains the model created by Nijikokun @@ -767,9 +765,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { // Check Bukkit perms to support plugins which add perms via code // (Heroes). final Player player = user.getBukkitPlayer(); - final Permission bukkitPerm = Bukkit.getPluginManager().getPermission(targetPermission); - if (player != null && bukkitPerm != null) { - result.resultType = player.hasPermission(bukkitPerm) ? PermissionCheckResult.Type.FOUND : PermissionCheckResult.Type.NEGATION; + //final Permission bukkitPerm = Bukkit.getPluginManager().getPermission(targetPermission); + if (player != null && player.hasPermission(targetPermission)) { + result.resultType = PermissionCheckResult.Type.FOUND; result.owner = user; return result; } -- cgit v1.2.3 From 6efd3eaa27a87fd41046d2ddc9bb96f6508d6851 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 3 Mar 2012 13:47:59 +0000 Subject: Fix a silly logic error when testing bukkit perms --- EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java | 2 +- .../org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index 396240ec6..56ef7e870 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -52,7 +52,7 @@ public class Group extends DataUnit implements Cloneable { /** * Is this a GlobalGroup * - * @return + * @return true if this is a global group */ public boolean isGlobal() { return (getDataSource() == null); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index b9315e849..6b6ae58ea 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -766,7 +766,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { // (Heroes). final Player player = user.getBukkitPlayer(); //final Permission bukkitPerm = Bukkit.getPluginManager().getPermission(targetPermission); - if (player != null && player.hasPermission(targetPermission)) { + if ((player != null) && player.hasPermission(targetPermission)) { result.resultType = PermissionCheckResult.Type.FOUND; result.owner = user; return result; -- cgit v1.2.3 From c33499797ebe490b44618014459ab6341cb964c1 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 3 Mar 2012 14:03:52 +0000 Subject: Minor change to globalgroups --- EssentialsGroupManager/src/globalgroups.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index f21034237..e199622ee 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -181,11 +181,13 @@ groups: - towny.nation.* - towny.chat.tc - towny.chat.nc - - towny.wild.block.6.* + - towny.wild.block.6.build + - towny.wild.block.6.destroy - towny.wild.block.14.destroy - towny.wild.block.15.destroy - towny.wild.block.16.destroy - - towny.wild.block.17.* + - towny.wild.block.17.build + - towny.wild.block.17.destroy - towny.wild.block.18.destroy - towny.wild.block.21.destroy - towny.wild.block.31.destroy -- cgit v1.2.3 From 7ba49afa0b3095e678f91412f991db4bf82a84b9 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 4 Mar 2012 10:39:39 +0000 Subject: Better reporting when a users.yml is failing to load. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 9ea8082c0..d28696f5f 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -147,4 +147,5 @@ v 1.9: - Prevent adding inheritances and info nodes to globalgroups. These are permissions collections, not player groups. - Prevent promoting players to, and demoting to GlobalGroups. - Make 'manload' reload the config correctly. - - Minor optimization when checking bukkit permissions. \ No newline at end of file + - Minor optimization when checking bukkit permissions. + - Better reporting when a users.yml is failing to load. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index e766b6c78..a01381fcd 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -602,7 +602,12 @@ public class WorldDataHolder { // Load users if the file is NOT empty if (allUsersNode != null) for (String usersKey : allUsersNode.keySet()) { - Map thisUserNode = (Map) allUsersNode.get(usersKey); + Map thisUserNode = null; + try { + thisUserNode = (Map) allUsersNode.get(usersKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); + } User thisUser = ph.createUser(usersKey); if (thisUser == null) { throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); -- cgit v1.2.3 From 1f761ee1cbd1b4be8583cf4b310e825a1247471e Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 6 Mar 2012 11:02:48 +0000 Subject: Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GroupManager.java | 86 ++++++++++++++-------- EssentialsGroupManager/src/plugin.yml | 2 +- 3 files changed, 57 insertions(+), 34 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index d28696f5f..b8b05c1b4 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -148,4 +148,5 @@ v 1.9: - Prevent promoting players to, and demoting to GlobalGroups. - Make 'manload' reload the config correctly. - Minor optimization when checking bukkit permissions. - - Better reporting when a users.yml is failing to load. \ No newline at end of file + - Better reporting when a users.yml is failing to load. + - Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 00c71a41e..739e5db6b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -374,16 +374,16 @@ public class GroupManager extends JavaPlugin { if (isConsole || playerCanDo) { switch (execCmd) { case manuadd: - // VALIDANDO ESTADO DO SENDER - if (dataHolder == null || permissionHandler == null) { - if (!setDefaultWorldHandler(sender)) - return true; - } + // VALIDANDO ARGUMENTOS - if (args.length != 2) { - sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); + if ((args.length != 2) && (args.length != 3)) { + sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional )"); return false; } + // Select the relevant world + dataHolder = worldsHolder.getWorldData((args.length == 3)? args[2]:Bukkit.getWorlds().get(0).getName()); + permissionHandler = dataHolder.getPermissionsHandler(); + if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { return false; } @@ -420,14 +420,10 @@ public class GroupManager extends JavaPlugin { // PARECE OK auxUser.setGroup(auxGroup); if (!sender.hasPermission("groupmanager.notify.other") || (isConsole)) - sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'."); - - //targetPlayer = this.getServer().getPlayer(auxUser.getName()); - //if (targetPlayer != null) - // BukkitPermissions.updatePermissions(targetPlayer); + sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "' in world '" + dataHolder.getName() + "'."); return true; - // break; + case manudel: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -463,6 +459,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updatePermissions(targetPlayer); return true; + case manuaddsub: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -502,11 +499,8 @@ public class GroupManager extends JavaPlugin { else sender.sendMessage(ChatColor.RED + "The subgroup '" + auxGroup.getName() + "' is already available to '" + auxUser.getName() + "'."); - //targetPlayer = this.getServer().getPlayer(auxUser.getName()); - //if (targetPlayer != null) - // BukkitPermissions.updatePermissions(targetPlayer); - return true; + case manudelsub: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -547,6 +541,7 @@ public class GroupManager extends JavaPlugin { // BukkitPermissions.updatePermissions(targetPlayer); return true; + case mangadd: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -568,6 +563,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You created a group named: " + auxGroup.getName()); return true; + case mangdel: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -591,6 +587,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; + case manuaddp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -655,7 +652,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updatePermissions(targetPlayer); return true; - // break; + case manudelp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -706,7 +703,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updatePermissions(targetPlayer); return true; - // break; + case manulistp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -771,6 +768,7 @@ public class GroupManager extends JavaPlugin { } return true; + case manucheckp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -825,6 +823,7 @@ public class GroupManager extends JavaPlugin { } return true; + case mangaddp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -879,6 +878,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; + case mangdelp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -919,6 +919,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; + case manglistp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -967,6 +968,7 @@ public class GroupManager extends JavaPlugin { } return true; + case mangcheckp: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1002,6 +1004,7 @@ public class GroupManager extends JavaPlugin { } return true; + case mangaddi: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1040,6 +1043,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; + case mangdeli: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1082,6 +1086,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; + case manuaddv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1113,7 +1118,9 @@ public class GroupManager extends JavaPlugin { } auxUser.getVariables().addVar(args[1], Variables.parseVariableValue(auxString)); sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the user " + auxUser.getName()); + return true; + case manudelv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1141,7 +1148,9 @@ public class GroupManager extends JavaPlugin { // PARECE OK auxUser.getVariables().removeVar(args[1]); sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the user " + ChatColor.GREEN + auxUser.getName()); + return true; + case manulistv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1174,7 +1183,9 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Variables of user " + auxUser.getName() + ": "); sender.sendMessage(auxString + "."); sender.sendMessage(ChatColor.YELLOW + "Plus all variables from group: " + auxUser.getGroupName()); + return true; + case manucheckv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1219,7 +1230,9 @@ public class GroupManager extends JavaPlugin { if (!auxGroup.equals(auxGroup2)) { sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName()); } + return true; + case mangaddv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1253,6 +1266,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the group " + auxGroup.getName()); return true; + case mangdelv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1282,6 +1296,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the group " + ChatColor.GREEN + auxGroup.getName()); return true; + case manglistv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1322,7 +1337,9 @@ public class GroupManager extends JavaPlugin { auxString = auxString.substring(0, auxString.lastIndexOf(",")); sender.sendMessage(ChatColor.YELLOW + "Plus all variables from groups: " + auxString); } + return true; + case mangcheckv: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1353,7 +1370,9 @@ public class GroupManager extends JavaPlugin { if (!auxGroup.equals(auxGroup2)) { sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName()); } + return true; + case manwhois: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1383,7 +1402,7 @@ public class GroupManager extends JavaPlugin { } // victim.permissions.add(args[1]); return true; - // break; + case tempadd: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1417,7 +1436,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Player overloaded!"); return true; - // break; + case tempdel: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1453,7 +1472,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You removed that player overload. He's back to normal!"); return true; - // break; + case templist: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1482,7 +1501,9 @@ public class GroupManager extends JavaPlugin { } overloadedUsers.get(dataHolder.getName().toLowerCase()).removeAll(removeList); sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode: " + ChatColor.WHITE + auxString); + return true; + case tempdelall: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1509,6 +1530,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode. Now they are normal again."); return true; + case mansave: boolean forced = false; @@ -1583,7 +1605,9 @@ public class GroupManager extends JavaPlugin { auxString = auxString.substring(0, auxString.lastIndexOf(",")); } sender.sendMessage(ChatColor.YELLOW + " Groups Available: " + ChatColor.WHITE + auxString); + return true; + case manpromote: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1638,12 +1662,8 @@ public class GroupManager extends JavaPlugin { if (!sender.hasPermission("groupmanager.notify.other") || (isConsole)) sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); - //targetPlayer = this.getServer().getPlayer(auxUser.getName()); - //if (targetPlayer != null) - // BukkitPermissions.updatePermissions(targetPlayer); - return true; - // break; + case mandemote: // VALIDANDO ESTADO DO SENDER if (dataHolder == null || permissionHandler == null) { @@ -1698,12 +1718,8 @@ public class GroupManager extends JavaPlugin { if (!sender.hasPermission("groupmanager.notify.other") || (isConsole)) sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); - //targetPlayer = this.getServer().getPlayer(auxUser.getName()); - //if (targetPlayer != null) - // BukkitPermissions.updatePermissions(targetPlayer); - return true; - // break; + case mantogglevalidate: validateOnlinePlayer = !validateOnlinePlayer; sender.sendMessage(ChatColor.YELLOW + "Validade if player is online, now set to: " + Boolean.toString(validateOnlinePlayer)); @@ -1734,7 +1750,9 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Your world now uses permissions of world name: '" + dataHolder.getName() + "' "); } } + return true; + case manselect: if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); @@ -1765,7 +1783,9 @@ public class GroupManager extends JavaPlugin { permissionHandler = dataHolder.getPermissionsHandler(); selectedWorlds.put(sender, dataHolder.getName()); sender.sendMessage(ChatColor.YELLOW + "You have selected world '" + dataHolder.getName() + "'."); + return true; + case manclear: if (args.length != 0) { sender.sendMessage(ChatColor.RED + "Review your arguments count!"); @@ -1773,7 +1793,9 @@ public class GroupManager extends JavaPlugin { } selectedWorlds.remove(sender); sender.sendMessage(ChatColor.YELLOW + "You have removed your world selection. Working with current world(if possible)."); + return true; + default: break; } diff --git a/EssentialsGroupManager/src/plugin.yml b/EssentialsGroupManager/src/plugin.yml index 65a5d4e95..6648ad7e8 100644 --- a/EssentialsGroupManager/src/plugin.yml +++ b/EssentialsGroupManager/src/plugin.yml @@ -10,7 +10,7 @@ authors: commands: manuadd: description: Move a player to desired group.(Adds to the file if not exists) - usage: / + usage: / | optional permissions: groupmanager.manuadd manudel: description: Remove any user specific configuration. Make him default group. -- cgit v1.2.3 From 19d233454ee7590e1f5221e23a77eb821b14548b Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 6 Mar 2012 16:23:57 +0000 Subject: change []<> for optional command components --- EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java | 2 +- EssentialsGroupManager/src/plugin.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 739e5db6b..eaa945f5d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -377,7 +377,7 @@ public class GroupManager extends JavaPlugin { // VALIDANDO ARGUMENTOS if ((args.length != 2) && (args.length != 3)) { - sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional )"); + sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional [world])"); return false; } // Select the relevant world diff --git a/EssentialsGroupManager/src/plugin.yml b/EssentialsGroupManager/src/plugin.yml index 6648ad7e8..bf42a08c3 100644 --- a/EssentialsGroupManager/src/plugin.yml +++ b/EssentialsGroupManager/src/plugin.yml @@ -10,7 +10,7 @@ authors: commands: manuadd: description: Move a player to desired group.(Adds to the file if not exists) - usage: / | optional + usage: / | optional [world] permissions: groupmanager.manuadd manudel: description: Remove any user specific configuration. Make him default group. -- cgit v1.2.3 From a8937f7bf0a97276443473d6bd83d8045e0a112f Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 12 Mar 2012 22:18:25 +0000 Subject: Fix a globalgroup inheritance in groups.yml --- EssentialsGroupManager/src/groups.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/groups.yml b/EssentialsGroupManager/src/groups.yml index e50054c9f..ec8b0422f 100644 --- a/EssentialsGroupManager/src/groups.yml +++ b/EssentialsGroupManager/src/groups.yml @@ -24,7 +24,7 @@ groups: inheritance: - default - g:essentials_builder - - g:towny_moderator + - g:towny_builder info: prefix: '&2' build: true -- cgit v1.2.3 From b72083fb186504b88aad84c9b4df4b5349602c77 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 17 Mar 2012 12:37:23 +0000 Subject: Removed some debug spam. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index b8b05c1b4..13cbf98c6 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -149,4 +149,5 @@ v 1.9: - Make 'manload' reload the config correctly. - Minor optimization when checking bukkit permissions. - Better reporting when a users.yml is failing to load. - - Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). \ No newline at end of file + - Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). + - Removed some debug spam. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 30fe3f709..217ab904e 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -243,7 +243,6 @@ public class User extends DataUnit implements Cloneable { //UserVariables temp = new UserVariables(this, varList); variables.clearVars(); for (String key : varList.keySet()) { - System.out.print("Adding variable - " + key); variables.addVar(key, varList.get(key)); } flagAsChanged(); -- cgit v1.2.3 From 6476158462650c9dea305c2e3892e976a258a529 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 17 Mar 2012 15:56:40 +0000 Subject: Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../dataholder/worlds/WorldsHolder.java | 26 +--------------------- .../permissions/BukkitPermissions.java | 12 ++-------- 3 files changed, 5 insertions(+), 36 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 13cbf98c6..6bedf7e90 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -150,4 +150,5 @@ v 1.9: - Minor optimization when checking bukkit permissions. - Better reporting when a users.yml is failing to load. - Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). - - Removed some debug spam. \ No newline at end of file + - Removed some debug spam. + - Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index e72118468..290a58388 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -347,32 +347,8 @@ public class WorldsHolder { String worldNameLowered = worldName.toLowerCase(); // Find this worlds data - if (worldsData.containsKey(worldNameLowered)) { - - String usersMirror = mirrorsUser.get(worldNameLowered); - String groupsMirror = mirrorsGroup.get(worldNameLowered); - - if (usersMirror != null) { - - // If both are mirrored - if (groupsMirror != null) { - - // if the data sources are the same, return the parent - if (usersMirror == groupsMirror) - return getUpdatedWorldData(usersMirror.toLowerCase()); - - // Both data sources are mirrors, but they are from different parents - // so we return the actual data object. - return getUpdatedWorldData(worldNameLowered); - } - - // Groups isn't a mirror so return this this worlds data source - return getUpdatedWorldData(worldNameLowered); - } - - // users isn't mirrored so we need to return this worlds data source + if (worldsData.containsKey(worldNameLowered)) return getUpdatedWorldData(worldNameLowered); - } // Oddly no data source was found for this world so return the default. GroupManager.logger.finest("Requested world " + worldName + " not found or badly mirrored. Returning default world..."); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 0b6148900..dc08168dc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import org.anjocaido.groupmanager.GroupManager; @@ -37,7 +38,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.permissions.Permission; @@ -54,7 +54,7 @@ import org.bukkit.plugin.PluginManager; */ public class BukkitPermissions { - protected Map attachments = new HashMap(); + protected WeakHashMap attachments = new WeakHashMap(); protected LinkedHashMap registeredPermissions = new LinkedHashMap(); protected GroupManager plugin; protected boolean dumpAllPermissions = true; @@ -368,14 +368,6 @@ public class BukkitPermissions { updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName()); } - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerQuit(PlayerQuitEvent event) { - if (!GroupManager.isLoaded()) - return; - - attachments.remove(event.getPlayer()); - } - @EventHandler(priority = EventPriority.LOWEST) public void onPlayerKick(PlayerKickEvent event) { attachments.remove(event.getPlayer()); -- cgit v1.2.3 From bcd4fd9bff3b6fcb3eda05e5cb79f2aeba5477f0 Mon Sep 17 00:00:00 2001 From: Michael Bonney Date: Wed, 21 Mar 2012 16:13:34 +0000 Subject: Removed Portuguese text, and added English replacements. Made more sense of the sentences, and also changed an incorrect message to it's proper form. --- .../org/anjocaido/groupmanager/GroupManager.java | 306 ++++++++++----------- 1 file changed, 153 insertions(+), 153 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index eaa945f5d..baa45a275 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -108,7 +108,7 @@ public class GroupManager extends JavaPlugin { WorldEvents = null; BukkitPermissions = null; - // EXAMPLE: Custom code, here we just output some info so we can check + // EXAMPLE: Custom code, here we just output some info so we can check that // all is well PluginDescriptionFile pdfFile = this.getDescription(); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!"); @@ -349,7 +349,7 @@ public class GroupManager extends JavaPlugin { GroupManager.logger.severe("==================================================="); GroupManager.logger.severe("= ERROR REPORT START ="); GroupManager.logger.severe("==================================================="); - GroupManager.logger.severe("= COPY AND PASTE THIS TO GROUPMANAGER DEVELOPER ="); + GroupManager.logger.severe("= COPY AND PASTE THIS TO A GROUPMANAGER DEVELOPER ="); GroupManager.logger.severe("==================================================="); GroupManager.logger.severe(this.getDescription().getName()); GroupManager.logger.severe(this.getDescription().getVersion()); @@ -375,7 +375,7 @@ public class GroupManager extends JavaPlugin { switch (execCmd) { case manuadd: - // VALIDANDO ARGUMENTOS + // Validating arguments if ((args.length != 2) && (args.length != 3)) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional [world])"); return false; @@ -403,9 +403,9 @@ public class GroupManager extends JavaPlugin { return false; } - // VALIDANDO PERMISSAO + // Validating permissions if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "Can't modify a player with the same permissions as you, or higher."); return false; } if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { @@ -413,11 +413,11 @@ public class GroupManager extends JavaPlugin { return false; } if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { - sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit."); + sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit."); return false; } - // PARECE OK + // Seems OK auxUser.setGroup(auxGroup); if (!sender.hasPermission("groupmanager.notify.other") || (isConsole)) sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "' in world '" + dataHolder.getName() + "'."); @@ -425,12 +425,12 @@ public class GroupManager extends JavaPlugin { return true; case manudel: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -444,12 +444,12 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher."); return false; } - // PARECE OK + // Seems OK dataHolder.removeUser(auxUser.getName()); sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' to default settings."); @@ -461,7 +461,7 @@ public class GroupManager extends JavaPlugin { return true; case manuaddsub: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) { sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. World selection is needed."); @@ -469,7 +469,7 @@ public class GroupManager extends JavaPlugin { return true; } } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -488,12 +488,12 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group not found!"); return false; } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher."); return false; } - // PARECE OK + // Seems OK if (auxUser.addSubGroup(auxGroup)) sender.sendMessage(ChatColor.YELLOW + "You added subgroup '" + auxGroup.getName() + "' to player '" + auxUser.getName() + "'."); else @@ -502,12 +502,12 @@ public class GroupManager extends JavaPlugin { return true; case manudelsub: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/manudelsub )"); return false; @@ -527,12 +527,12 @@ public class GroupManager extends JavaPlugin { return false; } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher."); return false; } - // PARECE OK + // Seems OK auxUser.removeSubGroup(auxGroup); sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list."); @@ -543,12 +543,12 @@ public class GroupManager extends JavaPlugin { return true; case mangadd: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -558,19 +558,19 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group already exists!"); return false; } - // PARECE OK + // Seems OK auxGroup = dataHolder.createGroup(args[0]); sender.sendMessage(ChatColor.YELLOW + "You created a group named: " + auxGroup.getName()); return true; case mangdel: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -580,7 +580,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group not exists!"); return false; } - // PARECE OK + // Seems OK dataHolder.removeGroup(auxGroup.getName()); sender.sendMessage(ChatColor.YELLOW + "You deleted a group named " + auxGroup.getName() + ", it's users are default group now."); @@ -589,12 +589,12 @@ public class GroupManager extends JavaPlugin { return true; case manuaddp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -608,17 +608,17 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO SUA PERMISSAO + // Validating your permissions if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher."); return false; } permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) { - sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have."); + sender.sendMessage(ChatColor.RED + "You can't add a permission you don't have."); return false; } - // VALIDANDO PERMISSAO DO DESTINO + // Validating permissions of user permissionResult = permissionHandler.checkUserOnlyPermission(auxUser, args[1]); if (args[1].startsWith("+")) { if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) { @@ -643,7 +643,7 @@ public class GroupManager extends JavaPlugin { return false; } } - // PARECE OK + // Seems OK auxUser.addPermission(args[1]); sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to player '" + auxUser.getName() + "' permissions."); @@ -654,12 +654,12 @@ public class GroupManager extends JavaPlugin { return true; case manudelp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -673,17 +673,17 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO SUA PERMISSAO + // Validating your permissions if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same group as you, or higher."); return false; } permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) { - sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have."); + sender.sendMessage(ChatColor.RED + "You can't remove a permission you don't have."); return false; } - // VALIDANDO PERMISSAO DO DESTINO + // Validating permissions of user permissionResult = permissionHandler.checkUserOnlyPermission(auxUser, args[1]); if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { sender.sendMessage(ChatColor.RED + "The user doesn't have direct access to that permission."); @@ -694,7 +694,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "But might match node: " + permissionResult.accessLevel); return false; } - // PARECE OK + // Seems OK auxUser.removePermission(args[1]); sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from player '" + auxUser.getName() + "' permissions."); @@ -705,12 +705,12 @@ public class GroupManager extends JavaPlugin { return true; case manulistp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if ((args.length == 0) || (args.length > 2)) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ (+))"); return false; @@ -725,8 +725,8 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO - // PARECE OK + // Validating permission + // Seems OK auxString = ""; for (String perm : auxUser.getPermissionList()) { auxString += perm + ", "; @@ -770,12 +770,12 @@ public class GroupManager extends JavaPlugin { return true; case manucheckp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -791,7 +791,7 @@ public class GroupManager extends JavaPlugin { auxUser = dataHolder.getUser(args[0]); } targetPlayer = this.getServer().getPlayer(auxUser.getName()); - // VALIDANDO PERMISSAO + // Validating permission permissionResult = permissionHandler.checkFullGMPermission(auxUser, args[1], false); if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { @@ -825,28 +825,28 @@ public class GroupManager extends JavaPlugin { return true; case mangaddp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } - // VALIDANDO SUA PERMISSAO + // Validating your permissions permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) { - sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have."); + sender.sendMessage(ChatColor.RED + "You can't add a permission you don't have."); return false; } - // VALIDANDO PERMISSAO DO DESTINO + // Validating permissions of user permissionResult = permissionHandler.checkGroupOnlyPermission(auxGroup, args[1]); if (args[1].startsWith("+")) { if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) { @@ -866,12 +866,12 @@ public class GroupManager extends JavaPlugin { } } else { if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND)) { - sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission."); + sender.sendMessage(ChatColor.RED + "The group already has direct access to that permission."); sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel); return false; } } - // PARECE OK + // Seems OK auxGroup.addPermission(args[1]); sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to group '" + auxGroup.getName() + "' permissions."); @@ -880,28 +880,28 @@ public class GroupManager extends JavaPlugin { return true; case mangdelp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } - // VALIDANDO SUA PERMISSAO + // Validating your permissions permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) { sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have."); return false; } - // VALIDANDO PERMISSAO DO DESTINO + // Validating permissions of user permissionResult = permissionHandler.checkGroupOnlyPermission(auxGroup, args[1]); if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { sender.sendMessage(ChatColor.RED + "The group doesn't have direct access to that permission."); @@ -912,7 +912,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "But might match node: " + permissionResult.accessLevel); return false; } - // PARECE OK + // Seems OK auxGroup.removePermission(args[1]); sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from group '" + auxGroup.getName() + "' permissions."); @@ -921,24 +921,24 @@ public class GroupManager extends JavaPlugin { return true; case manglistp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } - // VALIDANDO PERMISSAO + // Validating permission - // PARECE OK + // Seems OK auxString = ""; for (String perm : auxGroup.getPermissionList()) { auxString += perm + ", "; @@ -970,28 +970,28 @@ public class GroupManager extends JavaPlugin { return true; case mangcheckp: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } - // VALIDANDO PERMISSAO + // Validating permission permissionResult = permissionHandler.checkGroupPermissionWithInheritance(auxGroup, args[1]); if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { sender.sendMessage(ChatColor.RED + "The group doesn't have access to that permission"); return false; } - // PARECE OK + // Seems OK // auxString = // permissionHandler.checkUserOnlyPermission(auxUser, args[1]); if (permissionResult.owner instanceof Group) { @@ -1006,24 +1006,24 @@ public class GroupManager extends JavaPlugin { return true; case mangaddi: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group 1 does not exists!"); + sender.sendMessage(ChatColor.RED + "Group 1 does not exist!"); return false; } auxGroup2 = dataHolder.getGroup(args[1]); if (auxGroup2 == null) { - sender.sendMessage(ChatColor.RED + "Group 2 does not exists!"); + sender.sendMessage(ChatColor.RED + "Group 2 does not exist!"); return false; } if (auxGroup.isGlobal()) { @@ -1031,12 +1031,12 @@ public class GroupManager extends JavaPlugin { return false; } - // VALIDANDO PERMISSAO + // Validating permission if (permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " already inherits " + auxGroup2.getName() + " (might not be directly)"); return false; } - // PARECE OK + // Seems OK auxGroup.addInherits(auxGroup2); sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " is now in " + auxGroup.getName() + " inheritance list."); @@ -1045,24 +1045,24 @@ public class GroupManager extends JavaPlugin { return true; case mangdeli: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group 1 does not exists!"); + sender.sendMessage(ChatColor.RED + "Group 1 does not exist!"); return false; } auxGroup2 = dataHolder.getGroup(args[1]); if (auxGroup2 == null) { - sender.sendMessage(ChatColor.RED + "Group 2 does not exists!"); + sender.sendMessage(ChatColor.RED + "Group 2 does not exist!"); return false; } if (auxGroup.isGlobal()) { @@ -1070,7 +1070,7 @@ public class GroupManager extends JavaPlugin { return false; } - // VALIDANDO PERMISSAO + // Validating permission if (!permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + "."); return false; @@ -1079,7 +1079,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + " directly."); return false; } - // PARECE OK + // Seems OK auxGroup.removeInherits(auxGroup2.getName()); sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " was removed from " + auxGroup.getName() + " inheritance list."); @@ -1088,12 +1088,12 @@ public class GroupManager extends JavaPlugin { return true; case manuaddv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length < 3) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1107,8 +1107,8 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO - // PARECE OK + // Validating permission + // Seems OK auxString = ""; for (int i = 2; i < args.length; i++) { auxString += args[i]; @@ -1122,12 +1122,12 @@ public class GroupManager extends JavaPlugin { return true; case manudelv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1141,23 +1141,23 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO + // Validating permission if (!auxUser.getVariables().hasVar(args[1])) { sender.sendMessage(ChatColor.RED + "The user doesn't have directly that variable!"); } - // PARECE OK + // Seems OK auxUser.getVariables().removeVar(args[1]); sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the user " + ChatColor.GREEN + auxUser.getName()); return true; case manulistv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1170,8 +1170,8 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO - // PARECE OK + // Validating permission + // Seems OK auxString = ""; for (String varKey : auxUser.getVariables().getVarKeyList()) { Object o = auxUser.getVariables().getVarObject(varKey); @@ -1187,12 +1187,12 @@ public class GroupManager extends JavaPlugin { return true; case manucheckv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1205,7 +1205,7 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO + // Validating permission auxGroup = auxUser.getGroup(); auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1]); @@ -1221,7 +1221,7 @@ public class GroupManager extends JavaPlugin { return false; } } - // PARECE OK + // Seems OK if (auxUser.getVariables().hasVar(auxString)) { sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxUser.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'"); sender.sendMessage(ChatColor.YELLOW + "This user own directly the variable"); @@ -1234,27 +1234,27 @@ public class GroupManager extends JavaPlugin { return true; case mangaddv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length < 3) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } if (auxGroup.isGlobal()) { sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); return false; } - // VALIDANDO PERMISSAO - // PARECE OK + // Validating permission + // Seems OK auxString = ""; for (int i = 2; i < args.length; i++) { auxString += args[i]; @@ -1268,57 +1268,57 @@ public class GroupManager extends JavaPlugin { return true; case mangdelv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } if (auxGroup.isGlobal()) { sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); return false; } - // VALIDANDO PERMISSAO + // Validating permission if (!auxGroup.getVariables().hasVar(args[1])) { sender.sendMessage(ChatColor.RED + "The group doesn't have directly that variable!"); } - // PARECE OK + // Seems OK auxGroup.getVariables().removeVar(args[1]); sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the group " + ChatColor.GREEN + auxGroup.getName()); return true; case manglistv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } if (auxGroup.isGlobal()) { sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); return false; } - // VALIDANDO PERMISSAO - // PARECE OK + // Validating permission + // Seems OK auxString = ""; for (String varKey : auxGroup.getVariables().getVarKeyList()) { Object o = auxGroup.getVariables().getVarObject(varKey); @@ -1341,31 +1341,31 @@ public class GroupManager extends JavaPlugin { return true; case mangcheckv: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; } auxGroup = dataHolder.getGroup(args[0]); if (auxGroup == null) { - sender.sendMessage(ChatColor.RED + "Group does not exists!"); + sender.sendMessage(ChatColor.RED + "The specified group does not exist!"); return false; } if (auxGroup.isGlobal()) { sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support Info Nodes."); return false; } - // VALIDANDO PERMISSAO + // Validating permission auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1], null); if (auxGroup2 == null) { sender.sendMessage(ChatColor.RED + "The group doesn't have access to that variable!"); } - // PARECE OK + // Seems OK sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxGroup2.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'"); if (!auxGroup.equals(auxGroup2)) { sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName()); @@ -1374,12 +1374,12 @@ public class GroupManager extends JavaPlugin { return true; case manwhois: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1392,7 +1392,7 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // PARECE OK + // Seems OK sender.sendMessage(ChatColor.YELLOW + "Name: " + ChatColor.GREEN + auxUser.getName()); sender.sendMessage(ChatColor.YELLOW + "Group: " + ChatColor.GREEN + auxUser.getGroup().getName()); sender.sendMessage(ChatColor.YELLOW + "Overloaded: " + ChatColor.GREEN + dataHolder.isOverloaded(auxUser.getName())); @@ -1404,12 +1404,12 @@ public class GroupManager extends JavaPlugin { return true; case tempadd: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1422,12 +1422,12 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } - // PARECE OK + // Seems OK if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) { overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList()); } @@ -1438,12 +1438,12 @@ public class GroupManager extends JavaPlugin { return true; case tempdel: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1456,12 +1456,12 @@ public class GroupManager extends JavaPlugin { } else { auxUser = dataHolder.getUser(args[0]); } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher."); return false; } - // PARECE OK + // Seems OK if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) { overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList()); } @@ -1469,12 +1469,12 @@ public class GroupManager extends JavaPlugin { if (overloadedUsers.get(dataHolder.getName().toLowerCase()).contains(auxUser)) { overloadedUsers.get(dataHolder.getName().toLowerCase()).remove(auxUser); } - sender.sendMessage(ChatColor.YELLOW + "You removed that player overload. He's back to normal!"); + sender.sendMessage(ChatColor.YELLOW + "You removed that player's overload. He's back to normal!"); return true; case templist: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; @@ -1492,7 +1492,7 @@ public class GroupManager extends JavaPlugin { } } if (count == 0) { - sender.sendMessage(ChatColor.YELLOW + "There is no users in overload mode"); + sender.sendMessage(ChatColor.YELLOW + "There are no users in overload mode."); return true; } auxString = auxString.substring(0, auxString.lastIndexOf(",")); @@ -1505,7 +1505,7 @@ public class GroupManager extends JavaPlugin { return true; case tempdelall: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; @@ -1520,14 +1520,14 @@ public class GroupManager extends JavaPlugin { } } if (count == 0) { - sender.sendMessage(ChatColor.YELLOW + "There is no users in overload mode"); + sender.sendMessage(ChatColor.YELLOW + "There are no users in overload mode."); return true; } if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) { overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList()); } overloadedUsers.get(dataHolder.getName().toLowerCase()).clear(); - sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode. Now they are normal again."); + sender.sendMessage(ChatColor.YELLOW + " " + count + "All users in overload mode are now are normal again."); return true; @@ -1588,7 +1588,7 @@ public class GroupManager extends JavaPlugin { return true; case listgroups: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; @@ -1609,12 +1609,12 @@ public class GroupManager extends JavaPlugin { return true; case manpromote: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1636,9 +1636,9 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Players may not be members of GlobalGroups directly."); return false; } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher."); return false; } if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { @@ -1646,18 +1646,18 @@ public class GroupManager extends JavaPlugin { return false; } if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { - sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit."); + sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit."); return false; } if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { - sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line."); + sender.sendMessage(ChatColor.RED + "You can't modify a player using groups with different heritage line."); return false; } if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "The new group must be a higher rank."); return false; } - // PARECE OK + // Seems OK auxUser.setGroup(auxGroup); if (!sender.hasPermission("groupmanager.notify.other") || (isConsole)) sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); @@ -1665,12 +1665,12 @@ public class GroupManager extends JavaPlugin { return true; case mandemote: - // VALIDANDO ESTADO DO SENDER + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - // VALIDANDO ARGUMENTOS + // Validating arguments if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); return false; @@ -1692,9 +1692,9 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Players may not be members of GlobalGroups directly."); return false; } - // VALIDANDO PERMISSAO + // Validating permission if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { - sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); + sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher."); return false; } if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { @@ -1702,18 +1702,18 @@ public class GroupManager extends JavaPlugin { return false; } if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { - sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don' inherit."); + sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit."); return false; } if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { - sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line."); + sender.sendMessage(ChatColor.RED + "You can't modify a player using groups with different heritage line."); return false; } if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "The new group must be a lower rank."); return false; } - // PARECE OK + // Seems OK auxUser.setGroup(auxGroup); if (!sender.hasPermission("groupmanager.notify.other") || (isConsole)) sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); -- cgit v1.2.3 From 9570e5cfd9731e19420f33048c55d3fb7d58bc7d Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 22 Mar 2012 17:54:59 +0000 Subject: Correct Grammar --- EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index baa45a275..09ea3b247 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -1527,7 +1527,7 @@ public class GroupManager extends JavaPlugin { overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList()); } overloadedUsers.get(dataHolder.getName().toLowerCase()).clear(); - sender.sendMessage(ChatColor.YELLOW + " " + count + "All users in overload mode are now are normal again."); + sender.sendMessage(ChatColor.YELLOW + " " + count + "All users in overload mode are now normal again."); return true; -- cgit v1.2.3 From 50ea442bf0be605420befc97c715825b3eff9bfc Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 26 Mar 2012 19:18:19 +0100 Subject: Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../dataholder/worlds/WorldsHolder.java | 44 +++++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 6bedf7e90..5ee1a386e 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -151,4 +151,5 @@ v 1.9: - Better reporting when a users.yml is failing to load. - Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). - Removed some debug spam. - - Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. \ No newline at end of file + - Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. + - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index 290a58388..35e8794b5 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -362,9 +362,10 @@ public class WorldsHolder { * @return updated world holder */ private OverloadedWorldHolder getUpdatedWorldData(String worldName) { + String worldNameLowered = worldName.toLowerCase(); - if (worldsData.containsKey(worldName.toLowerCase())) { - OverloadedWorldHolder data = worldsData.get(worldName.toLowerCase()); + if (worldsData.containsKey(worldNameLowered)) { + OverloadedWorldHolder data = worldsData.get(worldNameLowered); data.updateDataSource(); return data; } @@ -444,17 +445,19 @@ public class WorldsHolder { } public void setupWorldFolder(String worldName) { + String worldNameLowered = worldName.toLowerCase(); + worldsFolder = new File(plugin.getDataFolder(), "worlds"); if (!worldsFolder.exists()) { worldsFolder.mkdirs(); } - File defaultWorldFolder = new File(worldsFolder, worldName); - if ((!defaultWorldFolder.exists()) && ((!mirrorsGroup.containsKey(worldName.toLowerCase()))) || (!mirrorsUser.containsKey(worldName.toLowerCase()))) { + File defaultWorldFolder = new File(worldsFolder, worldNameLowered); + if ((!defaultWorldFolder.exists()) && ((!mirrorsGroup.containsKey(worldNameLowered))) || (!mirrorsUser.containsKey(worldNameLowered))) { defaultWorldFolder.mkdirs(); } if (defaultWorldFolder.exists()) { - if (!mirrorsGroup.containsKey(worldName.toLowerCase())) { + if (!mirrorsGroup.containsKey(worldNameLowered)) { File groupsFile = new File(defaultWorldFolder, "groups.yml"); if (!groupsFile.exists() || groupsFile.length() == 0) { @@ -467,7 +470,7 @@ public class WorldsHolder { } } - if (!mirrorsUser.containsKey(worldName.toLowerCase())) { + if (!mirrorsUser.containsKey(worldNameLowered)) { File usersFile = new File(defaultWorldFolder, "users.yml"); if (!usersFile.exists() || usersFile.length() == 0) { @@ -485,13 +488,15 @@ public class WorldsHolder { /** * Copies the specified world data to another world + * * @param fromWorld * @param toWorld * @return true if successfully copied. */ public boolean cloneWorld(String fromWorld, String toWorld) { - File fromWorldFolder = new File(worldsFolder, fromWorld); - File toWorldFolder = new File(worldsFolder, toWorld); + + File fromWorldFolder = new File(worldsFolder, fromWorld.toLowerCase()); + File toWorldFolder = new File(worldsFolder, toWorld.toLowerCase()); if (toWorldFolder.exists() || !fromWorldFolder.exists()) { return false; } @@ -530,17 +535,20 @@ public class WorldsHolder { * @param worldName */ public void loadWorld(String worldName, Boolean isMirror) { - if (worldsData.containsKey(worldName.toLowerCase())) { - worldsData.get(worldName.toLowerCase()).reload(); + + String worldNameLowered = worldName.toLowerCase(); + + if (worldsData.containsKey(worldNameLowered)) { + worldsData.get(worldNameLowered).reload(); return; } GroupManager.logger.finest("Trying to load world " + worldName + "..."); - File thisWorldFolder = new File(worldsFolder, worldName); + File thisWorldFolder = new File(worldsFolder, worldNameLowered); if ((isMirror) || (thisWorldFolder.exists() && thisWorldFolder.isDirectory())) { // Setup file handles, if not mirrored - File groupsFile = (mirrorsGroup.containsKey(worldName.toLowerCase()))? null : new File(thisWorldFolder, "groups.yml"); - File usersFile = (mirrorsUser.containsKey(worldName.toLowerCase()))? null : new File(thisWorldFolder, "users.yml"); + File groupsFile = (mirrorsGroup.containsKey(worldNameLowered))? null : new File(thisWorldFolder, "groups.yml"); + File usersFile = (mirrorsUser.containsKey(worldNameLowered))? null : new File(thisWorldFolder, "users.yml"); if ((groupsFile != null) && (!groupsFile.exists())) { throw new IllegalArgumentException("Groups file for world '" + worldName + "' doesnt exist: " + groupsFile.getPath()); @@ -552,14 +560,14 @@ public class WorldsHolder { WorldDataHolder tempHolder = new WorldDataHolder(worldName); // Map the group object for any mirror - if (mirrorsGroup.containsKey(worldName.toLowerCase())) - tempHolder.setGroupsObject(this.getWorldData(mirrorsGroup.get(worldName.toLowerCase())).getGroupsObject()); + if (mirrorsGroup.containsKey(worldNameLowered)) + tempHolder.setGroupsObject(this.getWorldData(mirrorsGroup.get(worldNameLowered)).getGroupsObject()); else tempHolder.loadGroups(groupsFile); // Map the user object for any mirror - if (mirrorsUser.containsKey(worldName.toLowerCase())) - tempHolder.setUsersObject(this.getWorldData(mirrorsUser.get(worldName.toLowerCase())).getUsersObject()); + if (mirrorsUser.containsKey(worldNameLowered)) + tempHolder.setUsersObject(this.getWorldData(mirrorsUser.get(worldNameLowered)).getUsersObject()); else tempHolder.loadUsers(usersFile); @@ -573,7 +581,7 @@ public class WorldsHolder { if (thisWorldData != null) { GroupManager.logger.finest("Successful load of world " + worldName + "..."); - worldsData.put(worldName.toLowerCase(), thisWorldData); + worldsData.put(worldNameLowered, thisWorldData); return; } -- cgit v1.2.3 From fe7f479e63601097c245d296140bfce0f37448b0 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 26 Mar 2012 20:06:59 +0100 Subject: Auto rename all case sensitive world folders to lower case (if possible). --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../dataholder/worlds/WorldsHolder.java | 24 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 5ee1a386e..bbc8abe82 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -152,4 +152,5 @@ v 1.9: - Expanded '/manuadd'to accept an optional variable for the world (eg '/manuadd '). - Removed some debug spam. - Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. - - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). \ No newline at end of file + - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). + - Auto rename all case sensitive world folders to lower case (if possible). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index 35e8794b5..bfa7d5cd2 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -106,7 +106,12 @@ public class WorldsHolder { if (!worldsData.containsKey(folder.getName().toLowerCase()) && ((!mirrorsGroup.containsKey(folder.getName().toLowerCase())) || (!mirrorsUser.containsKey(folder.getName().toLowerCase())))) { - loadWorld(folder.getName()); + /* + * Call setupWorldFolder to check case sensitivity + * and convert to lower case, before we attempt to load this world. + */ + setupWorldFolder(folder.getName()); + loadWorld(folder.getName().toLowerCase()); } } @@ -454,7 +459,22 @@ public class WorldsHolder { File defaultWorldFolder = new File(worldsFolder, worldNameLowered); if ((!defaultWorldFolder.exists()) && ((!mirrorsGroup.containsKey(worldNameLowered))) || (!mirrorsUser.containsKey(worldNameLowered))) { - defaultWorldFolder.mkdirs(); + + /* + * check and convert all old case sensitive folders to lower case + */ + File casedWorldFolder = new File(worldsFolder, worldName); + if ((casedWorldFolder.exists()) && (casedWorldFolder.getName().toLowerCase().equals(worldNameLowered))) { + /* + * Rename the old folder to the new lower cased format + */ + casedWorldFolder.renameTo(new File(worldsFolder, worldNameLowered)); + } else { + /* + * Else we just create the folder + */ + defaultWorldFolder.mkdirs(); + } } if (defaultWorldFolder.exists()) { if (!mirrorsGroup.containsKey(worldNameLowered)) { -- cgit v1.2.3 From b8453ac7927ae83811d00448842c622d8adec5fa Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 27 Mar 2012 10:14:53 +0100 Subject: Update GlobalGroups.yml for new/changed Towny permission nodes. --- EssentialsGroupManager/src/Changelog.txt | 3 +- EssentialsGroupManager/src/globalgroups.yml | 70 ++++++++++++++--------------- 2 files changed, 37 insertions(+), 36 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index bbc8abe82..a9ebb72aa 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -153,4 +153,5 @@ v 1.9: - Removed some debug spam. - Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). - - Auto rename all case sensitive world folders to lower case (if possible). \ No newline at end of file + - Auto rename all case sensitive world folders to lower case (if possible). + - Update GlobalGroups.yml for new/changed Towny permission nodes. \ No newline at end of file diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index e199622ee..885c6675d 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -181,47 +181,47 @@ groups: - towny.nation.* - towny.chat.tc - towny.chat.nc - - towny.wild.block.6.build - - towny.wild.block.6.destroy - - towny.wild.block.14.destroy - - towny.wild.block.15.destroy - - towny.wild.block.16.destroy - - towny.wild.block.17.build - - towny.wild.block.17.destroy - - towny.wild.block.18.destroy - - towny.wild.block.21.destroy - - towny.wild.block.31.destroy - - towny.wild.block.37.destroy - - towny.wild.block.38.destroy - - towny.wild.block.39.destroy - - towny.wild.block.40.destroy - - towny.wild.block.50.destroy - - towny.wild.block.56.destroy - - towny.wild.block.73.destroy - - towny.wild.block.74.destroy - - towny.wild.block.78.destroy - - towny.wild.block.81.destroy - - towny.wild.block.82.destroy - - towny.wild.block.83.destroy - - towny.wild.block.86.destroy - - towny.wild.block.103.destroy - - towny.wild.block.106.destroy - - towny.wild.block.111.destroy - - towny.wild.block.115.destroy + - towny.wild.build.6 + - towny.wild.destroy.6 + - towny.wild.destroy.14 + - towny.wild.destroy.15 + - towny.wild.destroy.16 + - towny.wild.build.17 + - towny.wild.destroy.17 + - towny.wild.destroy.18 + - towny.wild.destroy.21 + - towny.wild.destroy.31 + - towny.wild.destroy.37 + - towny.wild.destroy.38 + - towny.wild.destroy.39 + - towny.wild.destroy.40 + - towny.wild.destroy.50 + - towny.wild.destroy.56 + - towny.wild.destroy.73 + - towny.wild.destroy.74 + - towny.wild.destroy.78 + - towny.wild.destroy.81 + - towny.wild.destroy.82 + - towny.wild.destroy.83 + - towny.wild.destroy.86 + - towny.wild.destroy.103 + - towny.wild.destroy.106 + - towny.wild.destroy.111 + - towny.wild.destroy.115 g:towny_moderator: permissions: - towny.chat.mod - - towny.wild.block.64.switch - - towny.wild.block.83.build - - towny.wild.block.86.build - - towny.wild.block.103.build - - towny.wild.block.111.build - - towny.wild.block.115.build + - towny.wild.switch.64 + - towny.wild.build.83 + - towny.wild.build.86 + - towny.wild.build.103 + - towny.wild.build.111 + - towny.wild.build.115 g:towny_admin: permissions: - towny.admin - - -towny.wild.block.119.destroy - - -towny.wild.block.120.destroy + - -towny.wild.destroy.119 + - -towny.wild.destroy.120 - towny.chat.admin \ No newline at end of file -- cgit v1.2.3 From 1ef8ab70d141e60a92b5fa152a5be61637fd84ba Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 29 Mar 2012 13:41:59 +0100 Subject: Stop attempting to push empty permissions when players edit the yml's incorrectly. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../groupmanager/dataholder/WorldDataHolder.java | 24 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index a9ebb72aa..4599cbcc0 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -154,4 +154,5 @@ v 1.9: - Don't remove an attachment on a player leaving as Bukkit never forgets it. This fixes non mirrored permissions being messed up if a player relogs. - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). - Auto rename all case sensitive world folders to lower case (if possible). - - Update GlobalGroups.yml for new/changed Towny permission nodes. \ No newline at end of file + - Update GlobalGroups.yml for new/changed Towny permission nodes. + - Stop attempting to push empty permissions when players edit the yml's incorrectly. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index a01381fcd..c4e27fa1e 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -485,14 +485,22 @@ public class WorldDataHolder { if (thisGroupNode.get("permissions") instanceof List) { for (Object o : ((List) thisGroupNode.get("permissions"))) { try { - thisGrp.addPermission(o.toString()); + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission(o.toString()); } catch (NullPointerException e) { // Ignore this entry as it's null. //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } } } else if (thisGroupNode.get("permissions") instanceof String) { - thisGrp.addPermission((String) thisGroupNode.get("permissions")); + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission((String) thisGroupNode.get("permissions")); } else { throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } @@ -617,11 +625,19 @@ public class WorldDataHolder { } else { if (thisUserNode.get("permissions") instanceof List) { for (Object o : ((List) thisUserNode.get("permissions"))) { - thisUser.addPermission(o.toString()); + /* + * Only add this permission if it's not empty + */ + if (!o.toString().isEmpty()) + thisUser.addPermission(o.toString()); } } else if (thisUserNode.get("permissions") instanceof String) { try { - thisUser.addPermission(thisUserNode.get("permissions").toString()); + /* + * Only add this permission if it's not empty + */ + if (!thisUserNode.get("permissions").toString().isEmpty()) + thisUser.addPermission(thisUserNode.get("permissions").toString()); } catch (NullPointerException e) { // Ignore this entry as it's null. //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath()); -- cgit v1.2.3 From 9dbeb1407c4d7fd3be5ab3a44bd80eb0e4936f5c Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 29 Mar 2012 14:02:53 +0100 Subject: Catch errors caused by bad indentation in yml's. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GlobalGroups.java | 74 ++--- .../groupmanager/dataholder/WorldDataHolder.java | 344 +++++++++++---------- 3 files changed, 217 insertions(+), 204 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 4599cbcc0..c57b050c3 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -155,4 +155,5 @@ v 1.9: - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). - Auto rename all case sensitive world folders to lower case (if possible). - Update GlobalGroups.yml for new/changed Towny permission nodes. - - Stop attempting to push empty permissions when players edit the yml's incorrectly. \ No newline at end of file + - Stop attempting to push empty permissions when players edit the yml's incorrectly. + - Catch errors caused by bad indentation in yml's. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index d9715d4be..0219a1a08 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -116,42 +116,46 @@ public class GlobalGroups { // Load each groups permissions list. if (allGroups != null) { - for (String groupName : allGroups.keySet()) { - Group newGroup = new Group(groupName.toLowerCase()); - Object element; - - // Permission nodes - element = GGroups.get("groups." + groupName + ".permissions"); - - if (element != null) - if (element instanceof List) { - try { - for (String node : (List) element) { - newGroup.addPermission(node); + try { + for (String groupName : allGroups.keySet()) { + Group newGroup = new Group(groupName.toLowerCase()); + Object element; + + // Permission nodes + element = GGroups.get("groups." + groupName + ".permissions"); + + if (element != null) + if (element instanceof List) { + try { + for (String node : (List) element) { + newGroup.addPermission(node); + } + } catch (ClassCastException e) { + throw new IllegalArgumentException("Invalid permission node for global group: " + groupName); } - } catch (ClassCastException e) { - throw new IllegalArgumentException("Invalid permission node for global group: " + groupName); - } - } else if (element instanceof String) { - newGroup.addPermission((String) element); - } else - throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); - - // Info nodes - element = GGroups.get("groups." + groupName + ".info"); - - if (element != null) - if (element instanceof MemorySection) { - Map vars = new HashMap(); - for (String key : ((MemorySection) element).getKeys(false)) { - vars.put(key, ((MemorySection) element).get(key)); - } - newGroup.setVariables(vars); - } else - throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); - - // Push a new group - addGroup(newGroup); + } else if (element instanceof String) { + newGroup.addPermission((String) element); + } else + throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); + + // Info nodes + element = GGroups.get("groups." + groupName + ".info"); + + if (element != null) + if (element instanceof MemorySection) { + Map vars = new HashMap(); + for (String key : ((MemorySection) element).getKeys(false)) { + vars.put(key, ((MemorySection) element).get(key)); + } + newGroup.setVariables(vars); + } else + throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); + + // Push a new group + addGroup(newGroup); + } + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type, or bad indentation in GlobalGroups! "); } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index c4e27fa1e..d7f146438 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -460,93 +460,97 @@ public class WorldDataHolder { Map> inheritance = new HashMap>(); try { Map allGroupsNode = (Map) groupsRootDataNode.get("groups"); - for (String groupKey : allGroupsNode.keySet()) { - Map thisGroupNode = (Map) allGroupsNode.get(groupKey); - Group thisGrp = ph.createGroup(groupKey); - if (thisGrp == null) { - throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); - } - if (thisGroupNode.get("default") == null) { - thisGroupNode.put("default", false); - } - if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { - if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); - GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); - } - ph.setDefaultGroup(thisGrp); - } - - //PERMISSIONS NODE - try { - if (thisGroupNode.get("permissions") == null) { - thisGroupNode.put("permissions", new ArrayList()); - } else { - if (thisGroupNode.get("permissions") instanceof List) { - for (Object o : ((List) thisGroupNode.get("permissions"))) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission(o.toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. - //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - } - } else if (thisGroupNode.get("permissions") instanceof String) { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission((String) thisGroupNode.get("permissions")); + try { + for (String groupKey : allGroupsNode.keySet()) { + Map thisGroupNode = (Map) allGroupsNode.get(groupKey); + Group thisGrp = ph.createGroup(groupKey); + if (thisGrp == null) { + throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + } + if (thisGroupNode.get("default") == null) { + thisGroupNode.put("default", false); + } + if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + if (ph.getDefaultGroup() != null) { + GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); + GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); + } + ph.setDefaultGroup(thisGrp); + } + + //PERMISSIONS NODE + try { + if (thisGroupNode.get("permissions") == null) { + thisGroupNode.put("permissions", new ArrayList()); } else { - throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + if (thisGroupNode.get("permissions") instanceof List) { + for (Object o : ((List) thisGroupNode.get("permissions"))) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission(o.toString()); + } catch (NullPointerException e) { + // Ignore this entry as it's null. + //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + } + } else if (thisGroupNode.get("permissions") instanceof String) { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission((String) thisGroupNode.get("permissions")); + } else { + throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + thisGrp.sortPermissions(); } - thisGrp.sortPermissions(); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - - //INFO NODE - try { - if (thisGroupNode.get("info") instanceof Map) { - Map infoNode = (Map) thisGroupNode.get("info"); - if (infoNode != null) { - thisGrp.setVariables(infoNode); - } - } else - throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e1) { - throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - - //END INFO NODE - - try { - if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { - Object inheritNode = thisGroupNode.get("inheritance"); - if (inheritNode == null) { - thisGroupNode.put("inheritance", new ArrayList()); - } else if (inheritNode instanceof List) { - List groupsInh = (List) inheritNode; - for (String grp : groupsInh) { - if (inheritance.get(groupKey) == null) { - List thisInherits = new ArrayList(); - inheritance.put(groupKey, thisInherits); - } - inheritance.get(groupKey).add(grp); - - } - } - }else - throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e2) { - throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - } + + //INFO NODE + try { + if (thisGroupNode.get("info") instanceof Map) { + Map infoNode = (Map) thisGroupNode.get("info"); + if (infoNode != null) { + thisGrp.setVariables(infoNode); + } + } else + throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception e1) { + throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + + //END INFO NODE + + try { + if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { + Object inheritNode = thisGroupNode.get("inheritance"); + if (inheritNode == null) { + thisGroupNode.put("inheritance", new ArrayList()); + } else if (inheritNode instanceof List) { + List groupsInh = (List) inheritNode; + for (String grp : groupsInh) { + if (inheritance.get(groupKey) == null) { + List thisInherits = new ArrayList(); + inheritance.put(groupKey, thisInherits); + } + inheritance.get(groupKey).add(grp); + + } + } + }else + throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception e2) { + throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + } + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + groupsFile.getPath()); + } } catch (Exception ex) { ex.printStackTrace(); throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details."); @@ -609,92 +613,96 @@ public class WorldDataHolder { // Load users if the file is NOT empty if (allUsersNode != null) - for (String usersKey : allUsersNode.keySet()) { - Map thisUserNode = null; - try { - thisUserNode = (Map) allUsersNode.get(usersKey); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); - } - User thisUser = ph.createUser(usersKey); - if (thisUser == null) { - throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); - } - if (thisUserNode.get("permissions") == null) { - thisUserNode.put("permissions", new ArrayList()); - } else { - if (thisUserNode.get("permissions") instanceof List) { - for (Object o : ((List) thisUserNode.get("permissions"))) { - /* - * Only add this permission if it's not empty - */ - if (!o.toString().isEmpty()) - thisUser.addPermission(o.toString()); + try { + for (String usersKey : allUsersNode.keySet()) { + Map thisUserNode = null; + try { + thisUserNode = (Map) allUsersNode.get(usersKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); + } + User thisUser = ph.createUser(usersKey); + if (thisUser == null) { + throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); + } + if (thisUserNode.get("permissions") == null) { + thisUserNode.put("permissions", new ArrayList()); + } else { + if (thisUserNode.get("permissions") instanceof List) { + for (Object o : ((List) thisUserNode.get("permissions"))) { + /* + * Only add this permission if it's not empty + */ + if (!o.toString().isEmpty()) + thisUser.addPermission(o.toString()); + } + } else if (thisUserNode.get("permissions") instanceof String) { + try { + /* + * Only add this permission if it's not empty + */ + if (!thisUserNode.get("permissions").toString().isEmpty()) + thisUser.addPermission(thisUserNode.get("permissions").toString()); + } catch (NullPointerException e) { + // Ignore this entry as it's null. + //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath()); + } + } + thisUser.sortPermissions(); + } + + //SUBGROUPS LOADING + if (thisUserNode.get("subgroups") == null) { + thisUserNode.put("subgroups", new ArrayList()); + } + if (thisUserNode.get("subgroups") instanceof List) { + for (Object o : ((List) thisUserNode.get("subgroups"))) { + Group subGrp = ph.getGroup(o.toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + } else if (thisUserNode.get("subgroups") instanceof String) { + Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); } - } else if (thisUserNode.get("permissions") instanceof String) { - try { - /* - * Only add this permission if it's not empty - */ - if (!thisUserNode.get("permissions").toString().isEmpty()) - thisUser.addPermission(thisUserNode.get("permissions").toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. - //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath()); - } } - thisUser.sortPermissions(); - } - - //SUBGROUPS LOADING - if (thisUserNode.get("subgroups") == null) { - thisUserNode.put("subgroups", new ArrayList()); - } - if (thisUserNode.get("subgroups") instanceof List) { - for (Object o : ((List) thisUserNode.get("subgroups"))) { - Group subGrp = ph.getGroup(o.toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - } else if (thisUserNode.get("subgroups") instanceof String) { - Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - - - //USER INFO NODE - - //INFO NODE - if (thisUserNode.get("info") instanceof Map) { - Map infoNode = (Map) thisUserNode.get("info"); - if (infoNode != null) { - thisUser.setVariables(infoNode); - } - } else if (thisUserNode.get("info") != null) - throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); - - //END INFO NODE - - - if (thisUserNode.get("group") != null) { - Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); - if (hisGroup == null) { - GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); - hisGroup = ph.getDefaultGroup(); - //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); - } - thisUser.setGroup(hisGroup); - } else { - thisUser.setGroup(ph.getDefaultGroup()); - } - } + + + //USER INFO NODE + + //INFO NODE + if (thisUserNode.get("info") instanceof Map) { + Map infoNode = (Map) thisUserNode.get("info"); + if (infoNode != null) { + thisUser.setVariables(infoNode); + } + } else if (thisUserNode.get("info") != null) + throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); + + //END INFO NODE + + + if (thisUserNode.get("group") != null) { + Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); + if (hisGroup == null) { + GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); + hisGroup = ph.getDefaultGroup(); + //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); + } + thisUser.setGroup(hisGroup); + } else { + thisUser.setGroup(ph.getDefaultGroup()); + } + } + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + usersFile.getPath()); + } ph.removeUsersChangedFlag(); // Update the LastModified time. -- cgit v1.2.3 From 7a249abc6712f3a0b8704656fbb05047a183f78b Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 29 Mar 2012 18:14:24 +0100 Subject: Update default permissions. --- EssentialsGroupManager/src/globalgroups.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index 885c6675d..fa78aa36a 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -19,24 +19,32 @@ groups: - essentials.balance.others - essentials.balancetop - essentials.chat.color + - essentials.chat.format - essentials.chat.shout - essentials.chat.question - essentials.compass - essentials.depth + - essentials.getpos - essentials.home - essentials.ignore + - essentials.itemdb - essentials.kit - essentials.kit.tools - essentials.mail - essentials.mail.send - essentials.me - essentials.msg + - essentials.msg.color + - essentials.msg.format - essentials.nick - essentials.pay - essentials.ping - essentials.powertool + - essentials.powertooltoggle - essentials.protect + - essentials.seen - essentials.sethome + - essentials.sethome.multiple - essentials.signs.use.* - essentials.signs.create.disposal - essentials.signs.create.mail @@ -58,14 +66,19 @@ groups: g:essentials_moderator: permissions: + - -essentials.spawner.enderdragon + - essentials.afk.kickexempt - essentials.ban - essentials.ban.notify - essentials.banip - essentials.broadcast + - essentials.chat.url + - essentials.chat.magic - essentials.clearinventory - essentials.delwarp - essentials.eco.loan - essentials.ext + - essentials.fly - essentials.getpos - essentials.helpop.recieve - essentials.home.others @@ -75,13 +88,18 @@ groups: - essentials.kick - essentials.kick.notify - essentials.kill + - essentials.kit.* + - essentials.msg.magic - essentials.mute + - essentials.nick.color - essentials.nick.others - essentials.realname + - essentials.seen.banreason - essentials.setwarp - essentials.signs.create.* - essentials.signs.break.* - essentials.spawner + - essentials.spawner.* - essentials.thunder - essentials.time - essentials.time.set @@ -93,6 +111,7 @@ groups: - essentials.togglejail - essentials.top - essentials.tp + - essentials.tp.others - essentials.tphere - essentials.tppos - essentials.tptoggle @@ -101,6 +120,7 @@ groups: - essentials.weather - essentials.whois - essentials.world + - essentials.world.* - groupmanager.listgroups - groupmanager.mandemote - groupmanager.manpromote -- cgit v1.2.3 From 3f732725245955da9e3e2527a00a6150bec18044 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 1 Apr 2012 03:44:37 +0100 Subject: Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../permissions/BukkitPermissions.java | 39 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c57b050c3..c6f45bb01 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -156,4 +156,5 @@ v 1.9: - Auto rename all case sensitive world folders to lower case (if possible). - Update GlobalGroups.yml for new/changed Towny permission nodes. - Stop attempting to push empty permissions when players edit the yml's incorrectly. - - Catch errors caused by bad indentation in yml's. \ No newline at end of file + - Catch errors caused by bad indentation in yml's. + - Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index dc08168dc..5c711351e 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -38,6 +38,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.permissions.Permission; @@ -342,6 +343,18 @@ public class BukkitPermissions { if (player != null) this.updatePermissions(player, null); } + + /** + * Force remove any attachments + * + * @param player + */ + private void removeAttachment(Player player) { + if (attachments.containsKey(player)) { + player.removeAttachment(attachments.get(player)); + attachments.remove(player); + } + } /** * Player events tracked to cause Superperms updates @@ -355,6 +368,12 @@ public class BukkitPermissions { public void onPlayerJoin(PlayerJoinEvent event) { setPlayer_join(true); Player player = event.getPlayer(); + + /* + * Tidy up any lose ends + */ + removeAttachment(player); + // force GM to create the player if they are not already listed. if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) { setPlayer_join(false); @@ -370,7 +389,25 @@ public class BukkitPermissions { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerKick(PlayerKickEvent event) { - attachments.remove(event.getPlayer()); + Player player = event.getPlayer(); + + /* + * force remove any attachments as bukkit may not + */ + removeAttachment(player); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) { + if (!GroupManager.isLoaded()) + return; + + Player player = event.getPlayer(); + + /* + * force remove any attachments as bukkit may not + */ + removeAttachment(player); } } -- cgit v1.2.3 From e2e51c9c95f95906ad370bee7bcf698918b9a20b Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 2 Apr 2012 21:12:19 +0100 Subject: Added a new permission node 'groupmanager.op'. This will cause players with this node to be treated as op's when using GroupManager commands (they will still require each commands permission node to use them). --- EssentialsGroupManager/src/Changelog.txt | 4 +++- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 +- EssentialsGroupManager/src/plugin.yml | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c6f45bb01..fd9d8ef35 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -157,4 +157,6 @@ v 1.9: - Update GlobalGroups.yml for new/changed Towny permission nodes. - Stop attempting to push empty permissions when players edit the yml's incorrectly. - Catch errors caused by bad indentation in yml's. - - Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions. \ No newline at end of file + - Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions. + - Added a new permission node 'groupmanager.op'. This will cause players with this node to be treated as op's when + using GroupManager commands (they will still require each commands permission node to use them). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 09ea3b247..8bd346735 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -303,7 +303,7 @@ public class GroupManager extends JavaPlugin { senderPlayer = (Player) sender; senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderGroup = senderUser.getGroup(); - isOpOverride = (isOpOverride && senderPlayer.isOp()); + isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op"))); System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " ")); if (isOpOverride || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) { diff --git a/EssentialsGroupManager/src/plugin.yml b/EssentialsGroupManager/src/plugin.yml index bf42a08c3..f7faa5896 100644 --- a/EssentialsGroupManager/src/plugin.yml +++ b/EssentialsGroupManager/src/plugin.yml @@ -163,4 +163,9 @@ commands: manclear: description: Clear world selection. Next commands will work on your world. usage: / - permissions: groupmanager.manclear \ No newline at end of file + permissions: groupmanager.manclear + +Permissions: + groupmanager.op: + description: User is treated as an op when using the GroupManager commands. + default: false \ No newline at end of file -- cgit v1.2.3 From 183602ac28d1e195cdd71e17dc5fc26f70f3a074 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 3 Apr 2012 14:30:27 +0100 Subject: Prevent Null entries in group inheritance from throwing errors. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../org/anjocaido/groupmanager/dataholder/WorldDataHolder.java | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index fd9d8ef35..eba17517c 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -159,4 +159,5 @@ v 1.9: - Catch errors caused by bad indentation in yml's. - Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions. - Added a new permission node 'groupmanager.op'. This will cause players with this node to be treated as op's when - using GroupManager commands (they will still require each commands permission node to use them). \ No newline at end of file + using GroupManager commands (they will still require each commands permission node to use them). + - Prevent Null entries in group inheritance from throwing errors. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index d7f146438..cee2ec0b8 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -563,10 +563,12 @@ public class WorldDataHolder { List inheritedList = inheritance.get(groupKey); Group thisGroup = ph.getGroup(groupKey); for (String inheritedKey : inheritedList) { - Group inheritedGroup = ph.getGroup(inheritedKey); - if (thisGroup != null && inheritedGroup != null) { - thisGroup.addInherits(inheritedGroup); - } + if (inheritedKey != null) { + Group inheritedGroup = ph.getGroup(inheritedKey); + if (thisGroup != null && inheritedGroup != null) { + thisGroup.addInherits(inheritedGroup); + } + } } } -- cgit v1.2.3 From 381886245b7070e989acb12442a8aa6f6f1d5009 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 5 Apr 2012 12:54:26 +0100 Subject: Update to 2.0 Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. --- EssentialsGroupManager/src/Changelog.txt | 4 ++- .../permissions/AnjoPermissionsHandler.java | 30 ++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index eba17517c..a636ac6fe 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -160,4 +160,6 @@ v 1.9: - Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions. - Added a new permission node 'groupmanager.op'. This will cause players with this node to be treated as op's when using GroupManager commands (they will still require each commands permission node to use them). - - Prevent Null entries in group inheritance from throwing errors. \ No newline at end of file + - Prevent Null entries in group inheritance from throwing errors. +v 2.0: + - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index 6b6ae58ea..08240441d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -144,7 +144,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { // Perm doesn't already exists and there is no negation for it // or It's a negated perm where a normal perm doesn't exists (don't allow inheritance to negate higher perms) if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm)) - || (negated && !playerPermArray.contains(perm.substring(1)))) + || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm))) playerPermArray.add(perm); } } @@ -164,20 +164,17 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { if (perms.contains("*")) { permArray.addAll(GroupManager.BukkitPermissions.getAllRegisteredPermissions(includeChildren)); allPerms = true; + perms.remove("*"); } for (String perm : perms) { - - if (!perm.equalsIgnoreCase("*")) { - + /** * all permission sets are passed here pre-sorted, alphabetically. * This means negated nodes will be processed before all permissions * other than *. */ - boolean negated = false; - if (perm.startsWith("-")) - negated = true; + boolean negated = perm.startsWith("-"); if (!permArray.contains(perm)) { permArray.add(perm); @@ -195,15 +192,16 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { Map children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet()); if (children != null) { - if (negated || (negated && allPerms)) { + if (negated) + if (allPerms) { - // Remove children of negated nodes - for (String child : children.keySet()) - if (children.get(child)) - if (permArray.contains(child)) - permArray.remove(child); + // Remove children of negated nodes + for (String child : children.keySet()) + if (children.get(child)) + if (permArray.contains(child)) + permArray.remove(child); - } else if (!negated){ + } else { // Add child nodes for (String child : children.keySet()) @@ -214,7 +212,6 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { } } } - } } return permArray; @@ -959,7 +956,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { for (String sonName : now.getInherits()) { Group son = ph.getGroup(sonName); if (son != null && !alreadyVisited.contains(son)) { - stack.push(son); + // Add rather than push to retain inheritance order. + stack.add(son); alreadyVisited.add(son); } } -- cgit v1.2.3 From f7bc04bc347c088d35ee5a939c026f28b2ce0c19 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 5 Apr 2012 15:02:08 +0100 Subject: Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index a636ac6fe..c5fe5564d 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -162,4 +162,5 @@ v 1.9: using GroupManager commands (they will still require each commands permission node to use them). - Prevent Null entries in group inheritance from throwing errors. v 2.0: - - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. \ No newline at end of file + - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. + - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index 08240441d..b40694bb0 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -155,8 +155,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return playerPermArray; } - private Set populatePerms (List perms, boolean includeChildren) { + private Set populatePerms (List permsList, boolean includeChildren) { + // Create a new array so it's modifiable. + List perms = new ArrayList(permsList); Set permArray = new HashSet(); Boolean allPerms = false; -- cgit v1.2.3 From bd7af593e7e77df0d59f32cf5b3b7d4170682af3 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 5 Apr 2012 21:06:48 +0100 Subject: Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../anjocaido/groupmanager/permissions/BukkitPermissions.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c5fe5564d..2cfe57f62 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -163,4 +163,5 @@ v 1.9: - Prevent Null entries in group inheritance from throwing errors. v 2.0: - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. - - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. \ No newline at end of file + - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. + - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 5c711351e..6df18cb05 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -351,7 +351,14 @@ public class BukkitPermissions { */ private void removeAttachment(Player player) { if (attachments.containsKey(player)) { - player.removeAttachment(attachments.get(player)); + try { + player.removeAttachment(attachments.get(player)); + } catch (IllegalArgumentException e) { + /* + * Failed to remove attachment + * This usually means Bukkit no longer know of it. + */ + } attachments.remove(player); } } -- cgit v1.2.3 From 25bd91eb807e19db9d045c8e5f4ee70ec085da33 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 6 Apr 2012 12:53:36 +0100 Subject: Remove all permission attachments when performing a manload or restart. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 3 +++ .../anjocaido/groupmanager/permissions/BukkitPermissions.java | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 2cfe57f62..a9355e608 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -164,4 +164,5 @@ v 1.9: v 2.0: - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. - - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). \ No newline at end of file + - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). + - Remove all permission attachments when performing a manload or restart. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 8bd346735..d1c62d4de 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -106,6 +106,9 @@ public class GroupManager extends JavaPlugin { } WorldEvents = null; + + // Remove all attachments before clearing + BukkitPermissions.removeAllAttachments(); BukkitPermissions = null; // EXAMPLE: Custom code, here we just output some info so we can check that diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 6df18cb05..3b66c1eb9 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -362,6 +362,15 @@ public class BukkitPermissions { attachments.remove(player); } } + + /** + * Remove all attachments in case of a restart or reload. + */ + public void removeAllAttachments() { + + for (Player player : attachments.keySet()) + removeAttachment(player); + } /** * Player events tracked to cause Superperms updates -- cgit v1.2.3 From 1c0a5c49a5c1ecd0708823034b0c8726c965cb16 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 11:47:07 +0100 Subject: Expand 'manwhois' to also list a users subgroups. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index a9355e608..42b7b989c 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -165,4 +165,5 @@ v 2.0: - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). - - Remove all permission attachments when performing a manload or restart. \ No newline at end of file + - Remove all permission attachments when performing a manload or restart. + - Expand 'manwhois' to also list a users subgroups. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index d1c62d4de..76babb1ec 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -1398,6 +1398,16 @@ public class GroupManager extends JavaPlugin { // Seems OK sender.sendMessage(ChatColor.YELLOW + "Name: " + ChatColor.GREEN + auxUser.getName()); sender.sendMessage(ChatColor.YELLOW + "Group: " + ChatColor.GREEN + auxUser.getGroup().getName()); + // Compile a list of subgroups + auxString = ""; + for (String subGroup : auxUser.subGroupListStringCopy()) { + auxString += subGroup + ", "; + } + if (auxString.lastIndexOf(",") > 0) { + auxString = auxString.substring(0, auxString.lastIndexOf(",")); + sender.sendMessage(ChatColor.YELLOW + "subgroups: " + auxString); + } + sender.sendMessage(ChatColor.YELLOW + "Overloaded: " + ChatColor.GREEN + dataHolder.isOverloaded(auxUser.getName())); auxGroup = dataHolder.surpassOverload(auxUser.getName()).getGroup(); if (!auxGroup.equals(auxUser.getGroup())) { -- cgit v1.2.3 From e8dd96354592de9cd8b43d6eeca332417e1708f9 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 17:21:48 +0100 Subject: Fix a concurrent modification error when removing all attachments. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../org/anjocaido/groupmanager/permissions/BukkitPermissions.java | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 42b7b989c..f699c3f6f 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -166,4 +166,5 @@ v 2.0: - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). - Remove all permission attachments when performing a manload or restart. - - Expand 'manwhois' to also list a users subgroups. \ No newline at end of file + - Expand 'manwhois' to also list a users subgroups. + - Fix a concurrent modification error when removing all attachments. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 3b66c1eb9..51f019efc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -20,6 +20,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -368,8 +369,11 @@ public class BukkitPermissions { */ public void removeAllAttachments() { - for (Player player : attachments.keySet()) - removeAttachment(player); + Iterator itr = attachments.keySet().iterator(); + + while (itr.hasNext()){ + removeAttachment(itr.next()); + } } /** -- cgit v1.2.3 From e8a42e394740ebedd6ae9a386e2ef6c0dcc41e33 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 19:24:46 +0100 Subject: Better handling of errors in user and group yml's. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../groupmanager/dataholder/WorldDataHolder.java | 407 ++++++++++++--------- 2 files changed, 232 insertions(+), 178 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index f699c3f6f..c6c3853fb 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -167,4 +167,5 @@ v 2.0: - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). - Remove all permission attachments when performing a manload or restart. - Expand 'manwhois' to also list a users subgroups. - - Fix a concurrent modification error when removing all attachments. \ No newline at end of file + - Fix a concurrent modification error when removing all attachments. + - Better handling of errors in user and group yml's. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index cee2ec0b8..135417068 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -14,6 +14,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -459,98 +460,140 @@ public class WorldDataHolder { //PROCESS GROUPS FILE Map> inheritance = new HashMap>(); try { + /* + * Fetch all child nodes under the 'groups' entry. + */ Map allGroupsNode = (Map) groupsRootDataNode.get("groups"); - try { - for (String groupKey : allGroupsNode.keySet()) { - Map thisGroupNode = (Map) allGroupsNode.get(groupKey); - Group thisGrp = ph.createGroup(groupKey); - if (thisGrp == null) { - throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); - } - if (thisGroupNode.get("default") == null) { - thisGroupNode.put("default", false); - } - if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { - if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); - GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); - } - ph.setDefaultGroup(thisGrp); - } - - //PERMISSIONS NODE - try { - if (thisGroupNode.get("permissions") == null) { - thisGroupNode.put("permissions", new ArrayList()); + Iterator groupItr = allGroupsNode.keySet().iterator(); + String groupKey; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupKey = groupItr.next(); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type for group entry (" + groupCount + ") in file: " + groupsFile.getPath()); + } + + /* + * Fetch this groups child nodes + */ + Map thisGroupNode = (Map) allGroupsNode.get(groupKey); + /* + * Create a new group with this name + * in the assigned data source. + */ + Group thisGrp = ph.createGroup(groupKey); + + if (thisGrp == null) { + throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + } + /* + * If no default node is found set it as false. + */ + if (thisGroupNode.get("default") == null) { + thisGroupNode.put("default", false); + } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + /* + * Set this as the default group. + * Warn if some other group has already claimed that position. + */ + if (ph.getDefaultGroup() != null) { + GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); + GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); + } + ph.setDefaultGroup(thisGrp); + } + + //PERMISSIONS NODE + try { + /* + * If no permissions node is found, or it's empty + * set an empty permission list + */ + if (thisGroupNode.get("permissions") == null) { + thisGroupNode.put("permissions", new ArrayList()); + } else { + /* + * There is a permission list Which seems to hold some data + */ + if (thisGroupNode.get("permissions") instanceof List) { + /* + * Check each entry and add it as a new permission. + */ + for (Object o : ((List) thisGroupNode.get("permissions"))) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission(o.toString()); + } catch (NullPointerException e) { + // Ignore this entry as it's null. It can be safely dropped + } + } + } else if (thisGroupNode.get("permissions") instanceof String) { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission((String) thisGroupNode.get("permissions")); } else { - if (thisGroupNode.get("permissions") instanceof List) { - for (Object o : ((List) thisGroupNode.get("permissions"))) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission(o.toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. - //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - } - } else if (thisGroupNode.get("permissions") instanceof String) { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission((String) thisGroupNode.get("permissions")); - } else { - throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - thisGrp.sortPermissions(); + throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - - //INFO NODE - try { - if (thisGroupNode.get("info") instanceof Map) { - Map infoNode = (Map) thisGroupNode.get("info"); - if (infoNode != null) { - thisGrp.setVariables(infoNode); - } - } else - throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e1) { - throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + /* + * Sort all permissions so they are in the correct order for checking. + */ + thisGrp.sortPermissions(); } - - //END INFO NODE - - try { - if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { - Object inheritNode = thisGroupNode.get("inheritance"); - if (inheritNode == null) { - thisGroupNode.put("inheritance", new ArrayList()); - } else if (inheritNode instanceof List) { - List groupsInh = (List) inheritNode; - for (String grp : groupsInh) { - if (inheritance.get(groupKey) == null) { - List thisInherits = new ArrayList(); - inheritance.put(groupKey, thisInherits); - } - inheritance.get(groupKey).add(grp); - - } - } - }else - throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e2) { - throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + groupsFile.getPath()); - } + } catch (Exception e) { + throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + + //INFO NODE + try { + if (thisGroupNode.get("info") instanceof Map) { + Map infoNode = (Map) thisGroupNode.get("info"); + if (infoNode != null) { + thisGrp.setVariables(infoNode); + } + } else + throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception e1) { + throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + + //END INFO NODE + + try { + if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { + Object inheritNode = thisGroupNode.get("inheritance"); + if (inheritNode == null) { + thisGroupNode.put("inheritance", new ArrayList()); + } else if (inheritNode instanceof List) { + List groupsInh = (List) inheritNode; + for (String grp : groupsInh) { + if (inheritance.get(groupKey) == null) { + List thisInherits = new ArrayList(); + inheritance.put(groupKey, thisInherits); + } + inheritance.get(groupKey).add(grp); + + } + } + }else + throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception e2) { + throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + } + } catch (Exception ex) { ex.printStackTrace(); throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details."); @@ -614,97 +657,107 @@ public class WorldDataHolder { Map allUsersNode = (Map) usersRootDataNode.get("users"); // Load users if the file is NOT empty - if (allUsersNode != null) - try { - for (String usersKey : allUsersNode.keySet()) { - Map thisUserNode = null; - try { - thisUserNode = (Map) allUsersNode.get(usersKey); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); - } - User thisUser = ph.createUser(usersKey); - if (thisUser == null) { - throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); - } - if (thisUserNode.get("permissions") == null) { - thisUserNode.put("permissions", new ArrayList()); - } else { - if (thisUserNode.get("permissions") instanceof List) { - for (Object o : ((List) thisUserNode.get("permissions"))) { - /* - * Only add this permission if it's not empty - */ - if (!o.toString().isEmpty()) - thisUser.addPermission(o.toString()); - } - } else if (thisUserNode.get("permissions") instanceof String) { - try { - /* - * Only add this permission if it's not empty - */ - if (!thisUserNode.get("permissions").toString().isEmpty()) - thisUser.addPermission(thisUserNode.get("permissions").toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. - //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath()); - } - } - thisUser.sortPermissions(); - } - - //SUBGROUPS LOADING - if (thisUserNode.get("subgroups") == null) { - thisUserNode.put("subgroups", new ArrayList()); - } - if (thisUserNode.get("subgroups") instanceof List) { - for (Object o : ((List) thisUserNode.get("subgroups"))) { - Group subGrp = ph.getGroup(o.toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - } else if (thisUserNode.get("subgroups") instanceof String) { - Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - - - //USER INFO NODE - - //INFO NODE - if (thisUserNode.get("info") instanceof Map) { - Map infoNode = (Map) thisUserNode.get("info"); - if (infoNode != null) { - thisUser.setVariables(infoNode); - } - } else if (thisUserNode.get("info") != null) - throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); - - //END INFO NODE - - - if (thisUserNode.get("group") != null) { - Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); - if (hisGroup == null) { - GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); - hisGroup = ph.getDefaultGroup(); - //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); + if (allUsersNode != null) { + + Iterator usersItr = allUsersNode.keySet().iterator(); + String usersKey; + Integer userCount = 0; + + while (usersItr.hasNext()) { + try { + userCount++; + // Attempt to fetch the next user name. + usersKey = usersItr.next(); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath()); + } + + Map thisUserNode = null; + try { + thisUserNode = (Map) allUsersNode.get(usersKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); + } + User thisUser = ph.createUser(usersKey); + if (thisUser == null) { + throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); + } + if (thisUserNode.get("permissions") == null) { + thisUserNode.put("permissions", new ArrayList()); + } else { + if (thisUserNode.get("permissions") instanceof List) { + for (Object o : ((List) thisUserNode.get("permissions"))) { + /* + * Only add this permission if it's not empty + */ + if (!o.toString().isEmpty()) + thisUser.addPermission(o.toString()); } - thisUser.setGroup(hisGroup); - } else { - thisUser.setGroup(ph.getDefaultGroup()); + } else if (thisUserNode.get("permissions") instanceof String) { + try { + /* + * Only add this permission if it's not empty + */ + if (!thisUserNode.get("permissions").toString().isEmpty()) + thisUser.addPermission(thisUserNode.get("permissions").toString()); + } catch (NullPointerException e) { + // Ignore this entry as it's null. + //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath()); + } } - } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + usersFile.getPath()); - } + thisUser.sortPermissions(); + } + + //SUBGROUPS LOADING + if (thisUserNode.get("subgroups") == null) { + thisUserNode.put("subgroups", new ArrayList()); + } + if (thisUserNode.get("subgroups") instanceof List) { + for (Object o : ((List) thisUserNode.get("subgroups"))) { + Group subGrp = ph.getGroup(o.toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + } else if (thisUserNode.get("subgroups") instanceof String) { + Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + + + //USER INFO NODE + + //INFO NODE + if (thisUserNode.get("info") instanceof Map) { + Map infoNode = (Map) thisUserNode.get("info"); + if (infoNode != null) { + thisUser.setVariables(infoNode); + } + } else if (thisUserNode.get("info") != null) + throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); + + //END INFO NODE + + + if (thisUserNode.get("group") != null) { + Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); + if (hisGroup == null) { + GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); + hisGroup = ph.getDefaultGroup(); + //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); + } + thisUser.setGroup(hisGroup); + } else { + thisUser.setGroup(ph.getDefaultGroup()); + } + } + } ph.removeUsersChangedFlag(); // Update the LastModified time. -- cgit v1.2.3 From ec4f5cc34d2d2bd4556e092e70192a78cd7d1b0f Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 21:30:49 +0100 Subject: Added missing confirmation message on '/manload'. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c6c3853fb..0a9708773 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -168,4 +168,5 @@ v 2.0: - Remove all permission attachments when performing a manload or restart. - Expand 'manwhois' to also list a users subgroups. - Fix a concurrent modification error when removing all attachments. - - Better handling of errors in user and group yml's. \ No newline at end of file + - Better handling of errors in user and group yml's. + - Added missing confirmation message on '/manload'. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 76babb1ec..e10675e8d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -1590,6 +1590,8 @@ public class GroupManager extends JavaPlugin { */ onDisable(); onEnable(); + + sender.sendMessage("All settings and worlds were reloaded!"); } /** -- cgit v1.2.3 From f02691863ba41d648c31a7167ed2a6fd3fe57bcd Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 10 Apr 2012 17:02:50 +0100 Subject: Properly fix concurrent modification when removing all attachments. --- .../groupmanager/permissions/BukkitPermissions.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 51f019efc..516679544 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -357,7 +357,7 @@ public class BukkitPermissions { } catch (IllegalArgumentException e) { /* * Failed to remove attachment - * This usually means Bukkit no longer know of it. + * This usually means Bukkit no longer knows of it. */ } attachments.remove(player); @@ -372,8 +372,17 @@ public class BukkitPermissions { Iterator itr = attachments.keySet().iterator(); while (itr.hasNext()){ - removeAttachment(itr.next()); + Player player = itr.next(); + try { + player.removeAttachment(attachments.get(player)); + } catch (IllegalArgumentException e) { + /* + * Failed to remove attachment + * This usually means Bukkit no longer knows of it. + */ + } } + attachments.clear(); } /** -- cgit v1.2.3 From cdae0898c7848d9d0c3717eb1cacf9fc9bb8a199 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 10 Apr 2012 20:40:04 +0100 Subject: Stop the error on shutdown if GM failed to load at startup. GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. Startup errors will now lock out ALL commands other than '/manload' --- EssentialsGroupManager/src/Changelog.txt | 5 +- .../org/anjocaido/groupmanager/GroupManager.java | 170 ++++++++++++++++----- .../org/anjocaido/groupmanager/utils/Tasks.java | 41 +++++ 3 files changed, 173 insertions(+), 43 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 0a9708773..2c38acf1b 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -169,4 +169,7 @@ v 2.0: - Expand 'manwhois' to also list a users subgroups. - Fix a concurrent modification error when removing all attachments. - Better handling of errors in user and group yml's. - - Added missing confirmation message on '/manload'. \ No newline at end of file + - Added missing confirmation message on '/manload'. + - Stop the error on shutdown if GM failed to load at startup. + - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. + - Startup errors will now lock out ALL commands other than '/manload' \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index e10675e8d..b39b640a4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -14,6 +14,7 @@ import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; @@ -60,6 +61,9 @@ public class GroupManager extends JavaPlugin { private Map selectedWorlds = new HashMap(); private WorldsHolder worldsHolder; private boolean validateOnlinePlayer = true; + + private String lastError = ""; + /** * @return the validateOnlinePlayer */ @@ -108,8 +112,10 @@ public class GroupManager extends JavaPlugin { WorldEvents = null; // Remove all attachments before clearing - BukkitPermissions.removeAllAttachments(); - BukkitPermissions = null; + if (BukkitPermissions != null) { + BukkitPermissions.removeAllAttachments(); + BukkitPermissions = null; + } // EXAMPLE: Custom code, here we just output some info so we can check that // all is well @@ -118,53 +124,108 @@ public class GroupManager extends JavaPlugin { GroupManager.logger.removeHandler(ch); } - @Override + //@Override public void onEnable() { - GroupManager.logger.setUseParentHandlers(false); - ch = new GMLoggerHandler(); - GroupManager.logger.addHandler(ch); - logger.setLevel(Level.ALL); - - // Create the backup folder, if it doesn't exist. - prepareFileFields(); - // Load the config.yml - prepareConfig(); - // Load the global groups - globalGroups = new GlobalGroups(this); - worldsHolder = new WorldsHolder(this); + + try { + lastError = ""; + + GroupManager.logger.setUseParentHandlers(false); + ch = new GMLoggerHandler(); + GroupManager.logger.addHandler(ch); + logger.setLevel(Level.ALL); + + // Create the backup folder, if it doesn't exist. + prepareFileFields(); + // Load the config.yml + prepareConfig(); + // Load the global groups + globalGroups = new GlobalGroups(this); + worldsHolder = new WorldsHolder(this); + + + PluginDescriptionFile pdfFile = this.getDescription(); + if (worldsHolder == null) { + GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!"); + this.getServer().getPluginManager().disablePlugin(this); + throw new IllegalStateException("An error ocurred while loading GroupManager"); + } + + // Set a few defaults (reloads) + setLoaded(false); + + // Initialize the world listener and bukkit permissions to handle + // events. + WorldEvents = new GMWorldListener(this); + BukkitPermissions = new BukkitPermissions(this); + + enableScheduler(); + + /* + * Schedule a Bukiit Permissions update for 1 tick later. All plugins + * will be loaded by then + */ + + if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { + GroupManager.logger.severe("Could not schedule superperms Update."); + setLoaded(true); + } + + System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); + + // Register as a service + this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); + } catch (Exception ex) { + + /* + * Store the error and write to the log. + */ + saveErrorLog(ex); + /* + * Throw an error so Bukkit knows about it. + */ + throw new IllegalArgumentException(ex.getMessage(),ex); - PluginDescriptionFile pdfFile = this.getDescription(); - if (worldsHolder == null) { - GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!"); - this.getServer().getPluginManager().disablePlugin(this); - throw new IllegalStateException("An error ocurred while loading GroupManager"); } - - // Set a few defaults (reloads) - setLoaded(false); + } + + /** + * Write an error.log + * + * @param ex + */ + private void saveErrorLog(Exception ex) { - // Initialize the world listener and bukkit permissions to handle - // events. - WorldEvents = new GMWorldListener(this); - BukkitPermissions = new BukkitPermissions(this); - - enableScheduler(); - - /* - * Schedule a Bukiit Permissions update for 1 tick later. All plugins - * will be loaded by then - */ - - if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { - GroupManager.logger.severe("Could not schedule superperms Update."); - setLoaded(true); + if (!getDataFolder().exists()) { + getDataFolder().mkdirs(); + } + + lastError = ex.getMessage(); + + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe("= ERROR REPORT START ="); + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe("=== PLEASE COPY AND PASTE THE ERROR.LOG FROM THE =="); + GroupManager.logger.severe("= GROUPMANAGER FOLDER TO AN ESSENTIALS DEVELOPER ="); + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe(lastError); + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe("= ERROR REPORT ENDED ="); + GroupManager.logger.severe("==================================================="); + + // Append this error to the error log. + try { + String error = "=============================== GM ERROR LOG ===============================\n\n"; + error += Tasks.getStackTraceAsString(ex); + error += "\n============================================================================\n"; + + Tasks.appendStringToFile(error, (getDataFolder() + System.getProperty("file.separator") + "ERROR.LOG")); + } catch (IOException e) { + // Failed to write file. + e.printStackTrace(); } - System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); - - // Register as a service - this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); } public static boolean isLoaded() { @@ -300,10 +361,17 @@ public class GroupManager extends JavaPlugin { Group senderGroup = null; User senderUser = null; boolean isOpOverride = config.isOpOverride(); + // DETERMINING PLAYER INFORMATION if (sender instanceof Player) { senderPlayer = (Player) sender; + + if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { + sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); + return true; + } + senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderGroup = senderUser.getGroup(); isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op"))); @@ -313,6 +381,12 @@ public class GroupManager extends JavaPlugin { playerCanDo = true; } } else if (sender instanceof ConsoleCommandSender) { + + if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { + sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); + return true; + } + isConsole = true; } @@ -1560,10 +1634,17 @@ public class GroupManager extends JavaPlugin { return true; case manload: + /** * Attempt to reload a specific world */ if (args.length > 0) { + + if (!lastError.isEmpty()) { + sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); + return true; + } + auxString = ""; for (int i = 0; i < args.length; i++) { auxString += args[i]; @@ -1588,6 +1669,11 @@ public class GroupManager extends JavaPlugin { /** * Reload all settings and data as no world was specified. */ + + /* + * Reset the last error as we are attempting a fresh load. + */ + lastError = ""; onDisable(); onEnable(); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java index f3defd94a..663da1123 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java @@ -4,12 +4,17 @@ */ package org.anjocaido.groupmanager.utils; +import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; @@ -17,11 +22,25 @@ import java.util.List; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; + /** * * @author gabrielcouto */ public abstract class Tasks { + + /** + * Gets the exception stack trace as a string. + * + * @param exception + * @return stack trace as a string + */ + public static String getStackTraceAsString(Exception exception) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + exception.printStackTrace(pw); + return sw.toString(); + } public static void copy(InputStream src, File dst) throws IOException { InputStream in = src; @@ -44,6 +63,28 @@ public abstract class Tasks { InputStream in = new FileInputStream(src); copy(in, dst); } + + /** + * Appends a string to a file + * + * @param data + * @param file + */ + public static void appendStringToFile(String data, String file) throws IOException { + + FileWriter outStream = new FileWriter("." + System.getProperty("file.separator") + file, true); + + BufferedWriter out = new BufferedWriter(outStream); + + data.replaceAll("\n", System.getProperty("line.separator")); + + out.append(new SimpleDateFormat("yyyy-MM-dd HH-mm").format(System.currentTimeMillis())); + out.append(System.getProperty("line.separator")); + out.append(data); + out.append(System.getProperty("line.separator")); + + out.close(); + } public static void removeOldFiles(GroupManager gm, File folder) { if (folder.isDirectory()) { -- cgit v1.2.3 From cd24ffbadac6c48931f5ff33457950103b0e62da Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 10 Apr 2012 20:48:34 +0100 Subject: Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 2c38acf1b..7c10cc3ac 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -172,4 +172,5 @@ v 2.0: - Added missing confirmation message on '/manload'. - Stop the error on shutdown if GM failed to load at startup. - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. - - Startup errors will now lock out ALL commands other than '/manload' \ No newline at end of file + - Startup errors will now lock out ALL commands other than '/manload' + - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index b39b640a4..1177e3357 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -457,9 +457,18 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional [world])"); return false; } - // Select the relevant world - dataHolder = worldsHolder.getWorldData((args.length == 3)? args[2]:Bukkit.getWorlds().get(0).getName()); - permissionHandler = dataHolder.getPermissionsHandler(); + + // Select the relevant world (if specified) + if (args.length == 3) { + dataHolder = worldsHolder.getWorldData(args[2]); + permissionHandler = dataHolder.getPermissionsHandler(); + } + + // Validating state of sender + if (dataHolder == null || permissionHandler == null) { + if (!setDefaultWorldHandler(sender)) + return true; + } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { return false; -- cgit v1.2.3 From 25759064ff4c518193185fe3e993634408230eb7 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Wed, 11 Apr 2012 19:10:28 +0100 Subject: Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. --- EssentialsGroupManager/src/Changelog.txt | 3 +- EssentialsGroupManager/src/globalgroups.yml | 186 ++++++++++++++------- EssentialsGroupManager/src/groups.yml | 23 ++- .../groupmanager/dataholder/WorldDataHolder.java | 10 +- 4 files changed, 146 insertions(+), 76 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 7c10cc3ac..b957f4515 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -173,4 +173,5 @@ v 2.0: - Stop the error on shutdown if GM failed to load at startup. - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. - Startup errors will now lock out ALL commands other than '/manload' - - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. \ No newline at end of file + - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. + - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. \ No newline at end of file diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index 885c6675d..fa8808e00 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -1,5 +1,101 @@ +# These groups only contain permission nodes. +# +# **** You can NOT add anything other than permission nodes **** +# +# These collections are to be inherited in your different worlds groups.yml's +# They can also be added as one of a users subgroups, but NOT as a primary group. +# These collections are available to ALL group and user yml's. +# +# Add to and customize these groups to fit yoru needs. + groups: +# Permission nodes for GroupManager +# by ElgarL, snowleo, continued from gabrielcouto's original +# http://dev.bukkit.org/server-mods/essentials/ + + g:groupmanager_default: + permissions: + - groupmanager.notify.self + + g:groupmanager_moderator: + permissions: + - groupmanager.listgroups + - groupmanager.mandemote + - groupmanager.manpromote + - groupmanager.manselect + - groupmanager.manuadd + - groupmanager.manudel + - groupmanager.manwhois + - groupmanager.notify.other + + g:groupmanager_admin: + permissions: + - groupmanager.mantogglevalidate + - groupmanager.mansave + - groupmanager.mangcheckp + - groupmanager.manglistp + - groupmanager.manucheckp + - groupmanager.manulistp + +# Permission nodes for CraftBukkit +# by many devs and contributors +# http://dl.bukkit.org/ + + g:bukkit_default: + permissions: + - bukkit.broadcast.user + - -bukkit.command.plugins + + g:bukkit_moderator: + permissions: + - bukkit.command.ban + - bukkit.command.ban.ip + - bukkit.command.ban.player + - bukkit.command.gamemode + - bukkit.command.kick + - bukkit.command.unban + - bukkit.command.unban.ip + - bukkit.command.unban.player + + g:bukkit_admin: + permissions: + - bukkit.broadcast + - bukkit.broadcast.admin + - bukkit.command.give + - bukkit.command.help + - bukkit.command.kill + - bukkit.command.list + - bukkit.command.me + - -bukkit.command.op + - -bukkit.command.op.give + - -bukkit.command.op.take + - bukkit.command.plugins + - bukkit.command.reload + - bukkit.command.save + - bukkit.command.save.disable + - bukkit.command.save.enable + - bukkit.command.save.perform + - bukkit.command.say + - bukkit.command.stop + - bukkit.command.teleport + - bukkit.command.tell + - bukkit.command.time + - bukkit.command.time.add + - bukkit.command.time.set + - bukkit.command.version + - bukkit.command.whitelist + - bukkit.command.whitelist.add + - bukkit.command.whitelist.disable + - bukkit.command.whitelist.enable + - bukkit.command.whitelist.list + - bukkit.command.whitelist.reload + - bukkit.command.whitelist.remove + +# Permission nodes for Essentials +# by ementalo, snowleo, and KHobbits +# http://dev.bukkit.org/server-mods/essentials/ + g:essentials_default: permissions: - essentials.help @@ -8,7 +104,6 @@ groups: - essentials.motd - essentials.rules - essentials.spawn - - groupmanager.notify.self g:essentials_builder: permissions: @@ -101,14 +196,6 @@ groups: - essentials.weather - essentials.whois - essentials.world - - groupmanager.listgroups - - groupmanager.mandemote - - groupmanager.manpromote - - groupmanager.manselect - - groupmanager.manuadd - - groupmanager.manudel - - groupmanager.manwhois - - groupmanager.notify.other g:essentials_admin: permissions: @@ -118,62 +205,13 @@ groups: - -essentials.reloadall - -essentials.plugin - essentials.* - - groupmanager.mantogglevalidate - - groupmanager.mansave - - groupmanager.mangcheckp - - groupmanager.manglistp - - groupmanager.manucheckp - - groupmanager.manulistp - - g:bukkit_default: - permissions: - - bukkit.broadcast.user - - -bukkit.command.plugins - - g:bukkit_moderator: - permissions: - - bukkit.command.ban - - bukkit.command.ban.ip - - bukkit.command.ban.player - - bukkit.command.gamemode - - bukkit.command.kick - - bukkit.command.unban - - bukkit.command.unban.ip - - bukkit.command.unban.player - g:bukkit_admin: +# Permission nodes for Towny by ElgarL +# http://dev.bukkit.org/server-mods/towny-advanced/ + + g:towny_default: permissions: - - bukkit.broadcast - - bukkit.broadcast.admin - - bukkit.command.give - - bukkit.command.help - - bukkit.command.kill - - bukkit.command.list - - bukkit.command.me - - -bukkit.command.op - - -bukkit.command.op.give - - -bukkit.command.op.take - - bukkit.command.plugins - - bukkit.command.reload - - bukkit.command.save - - bukkit.command.save.disable - - bukkit.command.save.enable - - bukkit.command.save.perform - - bukkit.command.say - - bukkit.command.stop - - bukkit.command.teleport - - bukkit.command.tell - - bukkit.command.time - - bukkit.command.time.add - - bukkit.command.time.set - - bukkit.command.version - - bukkit.command.whitelist - - bukkit.command.whitelist.add - - bukkit.command.whitelist.disable - - bukkit.command.whitelist.enable - - bukkit.command.whitelist.list - - bukkit.command.whitelist.reload - - bukkit.command.whitelist.remove + - towny.chat.general g:towny_builder: permissions: @@ -224,4 +262,24 @@ groups: - towny.admin - -towny.wild.destroy.119 - -towny.wild.destroy.120 - - towny.chat.admin \ No newline at end of file + - towny.chat.admin + +# Permission nodes for VanishNoPacket by mbaxter +# http://dev.bukkit.org/server-mods/vanish/ + + g:vanish_moderator: + permissions: + - -vanish.* + - vanish.vanish + - vanish.smokin + - vanish.nofollow + - vanish.nopickup + - vanish.preventincomingdamage + - vanish.hooks.dynmap.alwayshidden + - vanish.hooks.essentials.hide + + g:vanish_admin: + permissions: + - vanish.silentjoin + - vanish.silentquit + - vanish.silentchests \ No newline at end of file diff --git a/EssentialsGroupManager/src/groups.yml b/EssentialsGroupManager/src/groups.yml index ec8b0422f..9c63ffd94 100644 --- a/EssentialsGroupManager/src/groups.yml +++ b/EssentialsGroupManager/src/groups.yml @@ -1,10 +1,12 @@ # Group inheritance -# any inherited groups prefixed with a g: are global groups -# These groups are defined in the globalgroups.yml -# and can be inherited in any worlds groups/users.yml. +# +# Any inherited groups prefixed with a g: are global groups +# and are inherited from the GlobalGroups.yml. # # Groups without the g: prefix are groups local to this world -# and defined in the this groups.yml file. +# and are defined in the this groups.yml file. +# +# Local group inheritances define your promotion tree when using 'manpromote/mandemote' groups: Default: @@ -12,8 +14,10 @@ groups: permissions: - -bukkit.command.kill inheritance: - - g:essentials_default + - g:groupmanager_default - g:bukkit_default + - g:essentials_default + - g:towny_default info: prefix: '&e' build: false @@ -34,9 +38,11 @@ groups: permissions: [] inheritance: - builder - - g:essentials_moderator + - g:groupmanager_moderator - g:bukkit_moderator + - g:essentials_moderator - g:towny_moderator + - g:vanish_moderator info: prefix: '&5' build: true @@ -46,9 +52,11 @@ groups: permissions: [] inheritance: - moderator - - g:essentials_admin + - g:groupmanager_admin - g:bukkit_admin + - g:essentials_admin - g:towny_admin + - g:vanish_admin info: prefix: '&c' build: true @@ -57,6 +65,7 @@ groups: default: false permissions: - '*' + - -vanish.* inheritance: - admin info: diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 135417068..8c974f34a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -809,12 +809,14 @@ public class WorldDataHolder { String newLine = System.getProperty("line.separator"); out.write("# Group inheritance" + newLine); - out.write("# any inherited groups prefixed with a g: are global groups" + newLine); - out.write("# These groups are defined in the globalgroups.yml" + newLine); - out.write("# and can be inherited in any worlds groups/users.yml." + newLine); + out.write("#" + newLine); + out.write("# Any inherited groups prefixed with a g: are global groups" + newLine); + out.write("# and are inherited from the GlobalGroups.yml." + newLine); out.write("#" + newLine); out.write("# Groups without the g: prefix are groups local to this world" + newLine); - out.write("# and defined in the this groups.yml file." + newLine); + out.write("# and are defined in the this groups.yml file." + newLine); + out.write("#" + newLine); + out.write("# Local group inheritances define your promotion tree when using 'manpromote/mandemote'" + newLine); out.write(newLine); yaml.dump(root, out); -- cgit v1.2.3 From 62a297ec6d2dc417c2e8d97d5e3e9abbf15c6ed6 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 12 Apr 2012 01:21:22 +0100 Subject: Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GlobalGroups.java | 101 ++++--- .../groupmanager/dataholder/WorldDataHolder.java | 313 +++++++++++---------- 3 files changed, 234 insertions(+), 183 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index b957f4515..0bf6c47bf 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -174,4 +174,5 @@ v 2.0: - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. - Startup errors will now lock out ALL commands other than '/manload' - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. - - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. \ No newline at end of file + - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. + - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 0219a1a08..6fa8b0d1d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -8,6 +8,7 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -112,50 +113,70 @@ public class GlobalGroups { if (!GGroups.getKeys(false).isEmpty()) { // Read all global groups - Map allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); + Map allGroups = new HashMap(); + + try { + allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); + } catch (Exception ex) { + //ex.printStackTrace(); + throw new IllegalArgumentException("Your " + GlobalGroupsFile.getPath() + " file is invalid. See console for details.", ex); + } // Load each groups permissions list. if (allGroups != null) { - try { - for (String groupName : allGroups.keySet()) { - Group newGroup = new Group(groupName.toLowerCase()); - Object element; - - // Permission nodes - element = GGroups.get("groups." + groupName + ".permissions"); - - if (element != null) - if (element instanceof List) { - try { - for (String node : (List) element) { - newGroup.addPermission(node); - } - } catch (ClassCastException e) { - throw new IllegalArgumentException("Invalid permission node for global group: " + groupName); - } - } else if (element instanceof String) { - newGroup.addPermission((String) element); - } else - throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); - - // Info nodes - element = GGroups.get("groups." + groupName + ".info"); - - if (element != null) - if (element instanceof MemorySection) { - Map vars = new HashMap(); - for (String key : ((MemorySection) element).getKeys(false)) { - vars.put(key, ((MemorySection) element).get(key)); - } - newGroup.setVariables(vars); - } else - throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); - - // Push a new group - addGroup(newGroup); + + Iterator groupItr = allGroups.keySet().iterator(); + String groupName; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupName = groupItr.next(); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid group name for GlobalGroup entry (" + groupCount + ") in file: " + GlobalGroupsFile.getPath(), ex); } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type, or bad indentation in GlobalGroups! "); + + Group newGroup = new Group(groupName.toLowerCase()); + Object element; + + // Permission nodes + element = GGroups.get("groups." + groupName + ".permissions"); + + if (element != null) + if (element instanceof List) { + try { + for (String node : (List) element) { + newGroup.addPermission(node); + } + } catch (ClassCastException ex) { + throw new IllegalArgumentException("Invalid permission node for global group: " + groupName, ex); + } + } else if (element instanceof String) { + newGroup.addPermission((String) element); + } else + throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); + + // Info nodes + element = GGroups.get("groups." + groupName + ".info"); + + if (element != null) + if (element instanceof MemorySection) { + Map vars = new HashMap(); + for (String key : ((MemorySection) element).getKeys(false)) { + vars.put(key, ((MemorySection) element).get(key)); + } + newGroup.setVariables(vars); + } else + throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); + + // Push a new group + addGroup(newGroup); } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 8c974f34a..6b5958f4b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -459,160 +459,180 @@ public class WorldDataHolder { //PROCESS GROUPS FILE Map> inheritance = new HashMap>(); + + /* + * Fetch all child nodes under the 'groups' entry. + */ + Map allGroupsNode = new HashMap(); + try { - /* - * Fetch all child nodes under the 'groups' entry. - */ - Map allGroupsNode = (Map) groupsRootDataNode.get("groups"); - Iterator groupItr = allGroupsNode.keySet().iterator(); - String groupKey; - Integer groupCount = 0; - - /* - * loop each group entry - * and read it's data. - */ - while (groupItr.hasNext()) { - try { - groupCount++; - // Attempt to fetch the next group name. - groupKey = groupItr.next(); - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type for group entry (" + groupCount + ") in file: " + groupsFile.getPath()); - } - - /* - * Fetch this groups child nodes - */ - Map thisGroupNode = (Map) allGroupsNode.get(groupKey); - /* - * Create a new group with this name - * in the assigned data source. - */ - Group thisGrp = ph.createGroup(groupKey); - - if (thisGrp == null) { - throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + allGroupsNode = (Map) groupsRootDataNode.get("groups"); + } catch (Exception ex) { + //ex.printStackTrace(); + throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex); + } + + + Iterator groupItr = allGroupsNode.keySet().iterator(); + String groupKey; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupKey = groupItr.next(); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid group name for group entry (" + groupCount + ") in file: " + groupsFile.getPath(), ex); + } + + /* + * Fetch this groups child nodes + */ + Map thisGroupNode = new HashMap(); + + try { + thisGroupNode = (Map) allGroupsNode.get(groupKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid child nodes for group '" + groupKey + "' in file: " + groupsFile.getPath(), ex); + } + + /* + * Create a new group with this name + * in the assigned data source. + */ + Group thisGrp = ph.createGroup(groupKey); + + if (thisGrp == null) { + throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + } + + /* + * If no default node is found set it as false. + */ + if (thisGroupNode.get("default") == null) { + thisGroupNode.put("default", false); + } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + /* + * Set this as the default group. + * Warn if some other group has already claimed that position. + */ + if (ph.getDefaultGroup() != null) { + GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); + GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); } - /* - * If no default node is found set it as false. - */ - if (thisGroupNode.get("default") == null) { - thisGroupNode.put("default", false); - } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + ph.setDefaultGroup(thisGrp); + } + + //PERMISSIONS NODE + + /* + * If no permissions node is found, or it's empty + * set an empty permission list + */ + if (thisGroupNode.get("permissions") == null) { + thisGroupNode.put("permissions", new ArrayList()); + } else { + /* + * There is a permission list Which seems to hold some data + */ + if (thisGroupNode.get("permissions") instanceof List) { /* - * Set this as the default group. - * Warn if some other group has already claimed that position. + * Check each entry and add it as a new permission. */ - if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); - GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); + for (Object o : ((List) thisGroupNode.get("permissions"))) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission(o.toString()); + + } catch (NullPointerException ex) { + // Ignore this entry as it's null. It can be safely dropped + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } } - ph.setDefaultGroup(thisGrp); - } - - //PERMISSIONS NODE - try { + } else if (thisGroupNode.get("permissions") instanceof String) { /* - * If no permissions node is found, or it's empty - * set an empty permission list + * Only add this permission if it's not empty. */ - if (thisGroupNode.get("permissions") == null) { - thisGroupNode.put("permissions", new ArrayList()); - } else { - /* - * There is a permission list Which seems to hold some data - */ - if (thisGroupNode.get("permissions") instanceof List) { - /* - * Check each entry and add it as a new permission. - */ - for (Object o : ((List) thisGroupNode.get("permissions"))) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission(o.toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. It can be safely dropped - } - } - } else if (thisGroupNode.get("permissions") instanceof String) { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission((String) thisGroupNode.get("permissions")); - } else { - throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - /* - * Sort all permissions so they are in the correct order for checking. - */ - thisGrp.sortPermissions(); - } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - - //INFO NODE - try { - if (thisGroupNode.get("info") instanceof Map) { - Map infoNode = (Map) thisGroupNode.get("info"); - if (infoNode != null) { - thisGrp.setVariables(infoNode); - } - } else - throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e1) { - throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission((String) thisGroupNode.get("permissions")); - //END INFO NODE - - try { - if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { - Object inheritNode = thisGroupNode.get("inheritance"); - if (inheritNode == null) { - thisGroupNode.put("inheritance", new ArrayList()); - } else if (inheritNode instanceof List) { - List groupsInh = (List) inheritNode; - for (String grp : groupsInh) { - if (inheritance.get(groupKey) == null) { - List thisInherits = new ArrayList(); - inheritance.put(groupKey, thisInherits); - } - inheritance.get(groupKey).add(grp); - - } - } - }else - throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e2) { - throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } else { + throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } + /* + * Sort all permissions so they are in the correct order for checking. + */ + thisGrp.sortPermissions(); } - } catch (Exception ex) { - ex.printStackTrace(); - throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details."); + //INFO NODE + try { + if (thisGroupNode.get("info") instanceof Map) { + Map infoNode = (Map) thisGroupNode.get("info"); + if (infoNode != null) { + thisGrp.setVariables(infoNode); + } + } else + throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + //END INFO NODE + + try { + if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { + Object inheritNode = thisGroupNode.get("inheritance"); + if (inheritNode == null) { + thisGroupNode.put("inheritance", new ArrayList()); + } else if (inheritNode instanceof List) { + List groupsInh = (List) inheritNode; + for (String grp : groupsInh) { + if (inheritance.get(groupKey) == null) { + List thisInherits = new ArrayList(); + inheritance.put(groupKey, thisInherits); + } + inheritance.get(groupKey).add(grp); + + } + } + }else + throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } } + if (ph.getDefaultGroup() == null) { throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath()); } - for (String groupKey : inheritance.keySet()) { - List inheritedList = inheritance.get(groupKey); - Group thisGroup = ph.getGroup(groupKey); - for (String inheritedKey : inheritedList) { - if (inheritedKey != null) { - Group inheritedGroup = ph.getGroup(inheritedKey); - if (thisGroup != null && inheritedGroup != null) { - thisGroup.addInherits(inheritedGroup); - } - } - } + + /* + * Build the inheritance map and recored any errors + */ + for (String group : inheritance.keySet()) { + List inheritedList = inheritance.get(group); + Group thisGroup = ph.getGroup(group); + if (thisGroup != null) + for (String inheritedKey : inheritedList) { + if (inheritedKey != null) { + Group inheritedGroup = ph.getGroup(inheritedKey); + if (inheritedGroup != null) { + thisGroup.addInherits(inheritedGroup); + } else + GroupManager.logger.warning("Inherited group '" + inheritedKey + "' not found for group " + thisGroup.getName() + ". Ignoring entry in file: " + groupsFile.getPath()); + } + } } ph.removeGroupsChangedFlag(); @@ -654,7 +674,17 @@ public class WorldDataHolder { } // PROCESS USERS FILE - Map allUsersNode = (Map) usersRootDataNode.get("users"); + Map allUsersNode = new HashMap(); + + /* + * Fetch all child nodes under the 'users' entry. + */ + try { + allUsersNode = (Map) usersRootDataNode.get("users"); + } catch (Exception ex) { + //ex.printStackTrace(); + throw new IllegalArgumentException("Your " + usersFile.getPath() + " file is invalid. See console for details.", ex); + } // Load users if the file is NOT empty if (allUsersNode != null) { @@ -668,8 +698,8 @@ public class WorldDataHolder { userCount++; // Attempt to fetch the next user name. usersKey = usersItr.next(); - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath()); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath(), ex); } Map thisUserNode = null; @@ -702,7 +732,6 @@ public class WorldDataHolder { thisUser.addPermission(thisUserNode.get("permissions").toString()); } catch (NullPointerException e) { // Ignore this entry as it's null. - //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath()); } } thisUser.sortPermissions(); -- cgit v1.2.3 From 9f744beb135fb93ca0b875369c4d3bc48a20cbb8 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 12 Apr 2012 03:21:38 +0100 Subject: Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 0bf6c47bf..648f5d1de 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -175,4 +175,5 @@ v 2.0: - Startup errors will now lock out ALL commands other than '/manload' - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. - - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. \ No newline at end of file + - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. + - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 1177e3357..1c4011ff8 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -98,7 +98,7 @@ public class GroupManager extends JavaPlugin { setLoaded(false); // Un-register this service. - this.getServer().getServicesManager().unregister(this); + this.getServer().getServicesManager().unregister(this.worldsHolder); disableScheduler(); // Shutdown before we save, so it doesn't interfere. if (worldsHolder != null) { -- cgit v1.2.3 From 677534c0b7319691c3139559943b2a5c4e8d2c88 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 13:58:05 +0100 Subject: Fixed the 'last' nested throw/catch and rework all user and group reading to be certain to trap all errors. --- .../org/anjocaido/groupmanager/GlobalGroups.java | 3 + .../groupmanager/dataholder/WorldDataHolder.java | 292 ++++++++++++++------- 2 files changed, 193 insertions(+), 102 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 6fa8b0d1d..904055d31 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -142,6 +142,9 @@ public class GlobalGroups { throw new IllegalArgumentException("Invalid group name for GlobalGroup entry (" + groupCount + ") in file: " + GlobalGroupsFile.getPath(), ex); } + /* + * Create a new group with this name. + */ Group newGroup = new Group(groupName.toLowerCase()); Object element; diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 6b5958f4b..ce6db2b9b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -439,9 +439,11 @@ public class WorldDataHolder { @SuppressWarnings({"rawtypes", "unchecked"}) protected static void loadGroups(WorldDataHolder ph, File groupsFile) throws FileNotFoundException, IOException { - //READ GROUPS FILE + // READ GROUPS FILE + Yaml yamlGroups = new Yaml(new SafeConstructor()); Map groupsRootDataNode; + if (!groupsFile.exists()) { throw new IllegalArgumentException("The file which should contain groups does not exist!\n" + groupsFile.getPath()); } @@ -457,18 +459,17 @@ public class WorldDataHolder { groupsInputStream.close(); } - //PROCESS GROUPS FILE + // PROCESS GROUPS FILE + Map> inheritance = new HashMap>(); + Map allGroupsNode = null; /* - * Fetch all child nodes under the 'groups' entry. + * Fetch all groups under the 'groups' entry. */ - Map allGroupsNode = new HashMap(); - try { allGroupsNode = (Map) groupsRootDataNode.get("groups"); } catch (Exception ex) { - //ex.printStackTrace(); throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex); } @@ -479,9 +480,10 @@ public class WorldDataHolder { /* * loop each group entry - * and read it's data. + * and process it's data. */ while (groupItr.hasNext()) { + try { groupCount++; // Attempt to fetch the next group name. @@ -493,7 +495,7 @@ public class WorldDataHolder { /* * Fetch this groups child nodes */ - Map thisGroupNode = new HashMap(); + Map thisGroupNode = null; try { thisGroupNode = (Map) allGroupsNode.get(groupKey); @@ -511,62 +513,80 @@ public class WorldDataHolder { throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); } - /* - * If no default node is found set it as false. - */ - if (thisGroupNode.get("default") == null) { - thisGroupNode.put("default", false); - } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + // DEFAULT NODE + + Object nodeData = null; + try { + nodeData = thisGroupNode.get("default"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'permissions' for group: " + groupKey + " in file: " + groupsFile.getPath()); + } + + if (nodeData == null) { + /* + * If no 'default' node is found do nothing. + */ + } else if ((Boolean.parseBoolean(nodeData.toString()))) { /* * Set this as the default group. * Warn if some other group has already claimed that position. */ if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); - GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); + GroupManager.logger.warning("The group '" + thisGrp.getName() + "' is claiming to be default where '" + ph.getDefaultGroup().getName() + "' already was."); + GroupManager.logger.warning("Overriding first default request in file: " + groupsFile.getPath()); } ph.setDefaultGroup(thisGrp); } - //PERMISSIONS NODE + // PERMISSIONS NODE + + nodeData = null; + try { + nodeData = thisGroupNode.get("permissions"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'permissions' for '" + groupKey + "' in file: " + groupsFile.getPath()); + } - /* - * If no permissions node is found, or it's empty - * set an empty permission list - */ - if (thisGroupNode.get("permissions") == null) { - thisGroupNode.put("permissions", new ArrayList()); + if (nodeData == null) { + /* + * If no permissions node is found, or it's empty + * do nothing. + */ } else { /* * There is a permission list Which seems to hold some data */ - if (thisGroupNode.get("permissions") instanceof List) { + if (nodeData instanceof List) { /* * Check each entry and add it as a new permission. */ - for (Object o : ((List) thisGroupNode.get("permissions"))) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission(o.toString()); - - } catch (NullPointerException ex) { - // Ignore this entry as it's null. It can be safely dropped - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); - } + try { + for (Object o : ((List) nodeData)) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!o.toString().isEmpty()) + thisGrp.addPermission(o.toString()); + + } catch (NullPointerException ex) { + // Ignore this entry as it's null. It can be safely dropped + } + } + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in 'permissions' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); } - } else if (thisGroupNode.get("permissions") instanceof String) { + + + } else if (nodeData instanceof String) { /* * Only add this permission if it's not empty. */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission((String) thisGroupNode.get("permissions")); + if (!nodeData.toString().isEmpty()) + thisGrp.addPermission((String) nodeData); } else { - throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + throw new IllegalArgumentException("Unknown type of 'permissions' node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } /* * Sort all permissions so they are in the correct order for checking. @@ -574,44 +594,70 @@ public class WorldDataHolder { thisGrp.sortPermissions(); } - //INFO NODE - try { - if (thisGroupNode.get("info") instanceof Map) { - Map infoNode = (Map) thisGroupNode.get("info"); - if (infoNode != null) { - thisGrp.setVariables(infoNode); + // INFO NODE + + nodeData = null; + try { + nodeData = thisGroupNode.get("info"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'info' section for group: " + groupKey + " in file: " + groupsFile.getPath()); + } + + if (nodeData == null) { + /* + * No info section was found, so leave all variables as defaults. + */ + GroupManager.logger.warning("The group '" + thisGrp.getName() + "' has no 'info' section!"); + GroupManager.logger.warning("Using default values: " + groupsFile.getPath()); + + } else if (nodeData instanceof Map) { + try { + if (nodeData != null) { + thisGrp.setVariables((Map) nodeData); } - } else - throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in 'info' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + } else + throw new IllegalArgumentException("Unknown entry found in 'info' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + + // INHERITANCE NODE + + nodeData = null; + try { + nodeData = thisGroupNode.get("inheritance"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'inheritance' section for group: " + groupKey + " in file: " + groupsFile.getPath()); } - - //END INFO NODE + + if (nodeData == null || nodeData instanceof List) { + if (nodeData == null) { + /* + * If no inheritance node is found, or it's empty + * do nothing. + */ + } else if (nodeData instanceof List) { - try { - if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { - Object inheritNode = thisGroupNode.get("inheritance"); - if (inheritNode == null) { - thisGroupNode.put("inheritance", new ArrayList()); - } else if (inheritNode instanceof List) { - List groupsInh = (List) inheritNode; - for (String grp : groupsInh) { + try { + for (String grp : (List) nodeData) { if (inheritance.get(groupKey) == null) { - List thisInherits = new ArrayList(); - inheritance.put(groupKey, thisInherits); + inheritance.put(groupKey, new ArrayList()); } inheritance.get(groupKey).add(grp); - } - } - }else - throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); - } - } + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in 'inheritance' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + } + }else + throw new IllegalArgumentException("Unknown entry found in 'inheritance' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + + // END GROUP + + } if (ph.getDefaultGroup() == null) { throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath()); @@ -655,7 +701,7 @@ public class WorldDataHolder { @SuppressWarnings({"rawtypes", "unchecked"}) protected static void loadUsers(WorldDataHolder ph, File usersFile) throws FileNotFoundException, IOException { - //READ USERS FILE + // READ USERS FILE Yaml yamlUsers = new Yaml(new SafeConstructor()); Map usersRootDataNode; if (!usersFile.exists()) { @@ -674,7 +720,8 @@ public class WorldDataHolder { } // PROCESS USERS FILE - Map allUsersNode = new HashMap(); + + Map allUsersNode = null; /* * Fetch all child nodes under the 'users' entry. @@ -682,11 +729,11 @@ public class WorldDataHolder { try { allUsersNode = (Map) usersRootDataNode.get("users"); } catch (Exception ex) { - //ex.printStackTrace(); throw new IllegalArgumentException("Your " + usersFile.getPath() + " file is invalid. See console for details.", ex); } // Load users if the file is NOT empty + if (allUsersNode != null) { Iterator usersItr = allUsersNode.keySet().iterator(); @@ -706,30 +753,44 @@ public class WorldDataHolder { try { thisUserNode = (Map) allUsersNode.get(usersKey); } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); + throw new IllegalArgumentException("Bad format found for user: " + usersKey + " in file: " + usersFile.getPath()); } + User thisUser = ph.createUser(usersKey); if (thisUser == null) { throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); } - if (thisUserNode.get("permissions") == null) { - thisUserNode.put("permissions", new ArrayList()); + + // USER PERMISSIONS NODES + + Object nodeData = null; + try { + nodeData = thisUserNode.get("permissions"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'permissions' for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData == null) { + /* + * If no permissions node is found, or it's empty + * do nothing. + */ } else { - if (thisUserNode.get("permissions") instanceof List) { - for (Object o : ((List) thisUserNode.get("permissions"))) { + if (nodeData instanceof List) { + for (Object o : ((List) nodeData)) { /* * Only add this permission if it's not empty */ if (!o.toString().isEmpty()) thisUser.addPermission(o.toString()); } - } else if (thisUserNode.get("permissions") instanceof String) { + } else if (nodeData instanceof String) { try { /* * Only add this permission if it's not empty */ - if (!thisUserNode.get("permissions").toString().isEmpty()) - thisUser.addPermission(thisUserNode.get("permissions").toString()); + if (!nodeData.toString().isEmpty()) + thisUser.addPermission(nodeData.toString()); } catch (NullPointerException e) { // Ignore this entry as it's null. } @@ -737,49 +798,76 @@ public class WorldDataHolder { thisUser.sortPermissions(); } - //SUBGROUPS LOADING - if (thisUserNode.get("subgroups") == null) { - thisUserNode.put("subgroups", new ArrayList()); + // SUBGROUPS NODES + + nodeData = null; + try { + nodeData = thisUserNode.get("subgroups"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'subgroups' for user: " + usersKey + " in file: " + usersFile.getPath()); } - if (thisUserNode.get("subgroups") instanceof List) { - for (Object o : ((List) thisUserNode.get("subgroups"))) { + + if (nodeData == null) { + /* + * If no subgroups node is found, or it's empty + * do nothing. + */ + } else if (nodeData instanceof List) { + for (Object o : ((List) nodeData)) { Group subGrp = ph.getGroup(o.toString()); if (subGrp != null) { thisUser.addSubGroup(subGrp); } else { - GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + GroupManager.logger.warning("Subgroup '" + o.toString() + "' not found for user: " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); } } - } else if (thisUserNode.get("subgroups") instanceof String) { - Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); + } else if (nodeData instanceof String) { + Group subGrp = ph.getGroup(nodeData.toString()); if (subGrp != null) { thisUser.addSubGroup(subGrp); } else { - GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + GroupManager.logger.warning("Subgroup '" + nodeData.toString() + "' not found for user: " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); } } //USER INFO NODE - //INFO NODE - if (thisUserNode.get("info") instanceof Map) { - Map infoNode = (Map) thisUserNode.get("info"); - if (infoNode != null) { - thisUser.setVariables(infoNode); - } - } else if (thisUserNode.get("info") != null) - throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); + nodeData = null; + try { + nodeData = thisUserNode.get("info"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'info' section for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData == null) { + /* + * If no info node is found, or it's empty + * do nothing. + */ + } else if (nodeData instanceof Map) { + thisUser.setVariables((Map) nodeData); + + } else + throw new IllegalArgumentException("Unknown entry found in 'info' section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); //END INFO NODE - if (thisUserNode.get("group") != null) { - Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); + // PRIMARY GROUP + + nodeData = null; + try { + nodeData = thisUserNode.get("group"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'group' section for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData != null) { + Group hisGroup = ph.getGroup(nodeData.toString()); if (hisGroup == null) { GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); hisGroup = ph.getDefaultGroup(); - //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); } thisUser.setGroup(hisGroup); } else { -- cgit v1.2.3 From a028abe03630c1990105f5dbfef5ba44bf11602d Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 14:40:26 +0100 Subject: Update all code formatting to use tabs for indentation. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../anjocaido/groupmanager/GMConfiguration.java | 144 +- .../org/anjocaido/groupmanager/GlobalGroups.java | 192 +- .../org/anjocaido/groupmanager/GroupManager.java | 317 +-- .../groupmanager/Tasks/BukkitPermsUpdateTask.java | 15 +- .../org/anjocaido/groupmanager/data/DataUnit.java | 294 +-- .../src/org/anjocaido/groupmanager/data/Group.java | 317 +-- .../groupmanager/data/GroupVariables.java | 139 +- .../src/org/anjocaido/groupmanager/data/User.java | 32 +- .../anjocaido/groupmanager/data/UserVariables.java | 73 +- .../org/anjocaido/groupmanager/data/Variables.java | 352 +-- .../groupmanager/dataholder/GroupsDataHolder.java | 20 +- .../dataholder/OverloadedWorldHolder.java | 376 ++-- .../groupmanager/dataholder/UsersDataHolder.java | 18 +- .../groupmanager/dataholder/WorldDataHolder.java | 2279 ++++++++++---------- .../dataholder/worlds/WorldsHolder.java | 1238 +++++------ .../groupmanager/events/GMGroupEvent.java | 105 +- .../groupmanager/events/GMSystemEvent.java | 65 +- .../anjocaido/groupmanager/events/GMUserEvent.java | 107 +- .../groupmanager/events/GMWorldListener.java | 24 +- .../events/GroupManagerEventHandler.java | 23 +- .../permissions/AnjoPermissionsHandler.java | 152 +- .../permissions/BukkitPermissions.java | 153 +- .../permissions/PermissionsReaderInterface.java | 440 ++-- .../groupmanager/utils/GMLoggerHandler.java | 21 +- .../utils/GroupManagerPermissions.java | 41 +- .../groupmanager/utils/PermissionCheckResult.java | 102 +- .../utils/StringPermissionComparator.java | 71 +- .../org/anjocaido/groupmanager/utils/Tasks.java | 216 +- 29 files changed, 3829 insertions(+), 3500 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 648f5d1de..5549fef17 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -176,4 +176,5 @@ v 2.0: - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. - - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. \ No newline at end of file + - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. + - Update all code formatting to use tabs for indentation. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java index 98ff075dd..0832000f2 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java @@ -13,81 +13,89 @@ import org.anjocaido.groupmanager.utils.Tasks; import org.bukkit.configuration.file.YamlConfiguration; /** - * + * * @author gabrielcouto */ public class GMConfiguration { - private GroupManager plugin; - private File configFile; - private YamlConfiguration GMconfig; - - public GMConfiguration(GroupManager plugin) { - this.plugin = plugin; - load(); - } - - public void load() { - if (!plugin.getDataFolder().exists()) { - plugin.getDataFolder().mkdirs(); - } - configFile = new File(plugin.getDataFolder(), "config.yml"); - - if (!configFile.exists()) { - try { - Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile); - } catch (IOException ex) { - GroupManager.logger.log(Level.SEVERE, null, ex); - } - } - - GMconfig = new YamlConfiguration(); - - try { - GMconfig.load(configFile); - } catch (Exception ex) { - throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex); - } - - // Setup defaults - adjustLoggerLevel(); - plugin.setValidateOnlinePlayer(isToggleValidate()); - } - - public boolean isOpOverride() { - return GMconfig.getBoolean("settings.config.opOverrides", true); - } - public boolean isToggleValidate() { - return GMconfig.getBoolean("settings.config.validate_toggle", true); - } - - public Map getMirrorsMap() { - // Try to fetch the old mirror path first + private GroupManager plugin; + private File configFile; + private YamlConfiguration GMconfig; + + public GMConfiguration(GroupManager plugin) { + + this.plugin = plugin; + load(); + } + + public void load() { + + if (!plugin.getDataFolder().exists()) { + plugin.getDataFolder().mkdirs(); + } + configFile = new File(plugin.getDataFolder(), "config.yml"); + + if (!configFile.exists()) { + try { + Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile); + } catch (IOException ex) { + GroupManager.logger.log(Level.SEVERE, null, ex); + } + } + + GMconfig = new YamlConfiguration(); + + try { + GMconfig.load(configFile); + } catch (Exception ex) { + throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex); + } + + // Setup defaults + adjustLoggerLevel(); + plugin.setValidateOnlinePlayer(isToggleValidate()); + } + + public boolean isOpOverride() { + + return GMconfig.getBoolean("settings.config.opOverrides", true); + } + + public boolean isToggleValidate() { + + return GMconfig.getBoolean("settings.config.validate_toggle", true); + } + + public Map getMirrorsMap() { + + // Try to fetch the old mirror path first if (GMconfig.isConfigurationSection("settings.permission.world.mirror")) { return (Map) GMconfig.getConfigurationSection("settings.permission.world.mirror").getValues(false); - } else if (GMconfig.isConfigurationSection("settings.mirrors")){ + } else if (GMconfig.isConfigurationSection("settings.mirrors")) { return (Map) GMconfig.getConfigurationSection("settings.mirrors").getValues(false); } return null; - - } - - public Integer getSaveInterval() { - return GMconfig.getInt("settings.data.save.minutes", 10); - } - - public Integer getBackupDuration() { - return GMconfig.getInt("settings.data.save.hours", 24); - } - - public void adjustLoggerLevel() { - - try { - GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO"))); - return; - } catch (Exception e) { - } - - GroupManager.logger.setLevel(Level.INFO); - } + + } + + public Integer getSaveInterval() { + + return GMconfig.getInt("settings.data.save.minutes", 10); + } + + public Integer getBackupDuration() { + + return GMconfig.getInt("settings.data.save.hours", 24); + } + + public void adjustLoggerLevel() { + + try { + GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO"))); + return; + } catch (Exception e) { + } + + GroupManager.logger.setLevel(Level.INFO); + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 904055d31..647d729e5 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -24,8 +24,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; - - /** * @author ElgarL * @@ -42,6 +40,7 @@ public class GlobalGroups { protected File GlobalGroupsFile = null; public GlobalGroups(GroupManager plugin) { + this.plugin = plugin; load(); } @@ -50,6 +49,7 @@ public class GlobalGroups { * @return the haveGroupsChanged */ public boolean haveGroupsChanged() { + if (this.haveGroupsChanged) { return true; } @@ -65,20 +65,24 @@ public class GlobalGroups { * @return the timeStampGroups */ public long getTimeStampGroups() { + return timeStampGroups; } + /** * @param timeStampGroups the timeStampGroups to set */ protected void setTimeStampGroups(long timeStampGroups) { + this.timeStampGroups = timeStampGroups; } - + /** * @param haveGroupsChanged * the haveGroupsChanged to set */ public void setGroupsChanged(boolean haveGroupsChanged) { + this.haveGroupsChanged = haveGroupsChanged; } @@ -86,7 +90,7 @@ public class GlobalGroups { public void load() { GGroups = new YamlConfiguration(); - + GroupManager.setLoaded(false); // READ globalGroups FILE @@ -110,47 +114,47 @@ public class GlobalGroups { // Clear out old groups resetGlobalGroups(); - + if (!GGroups.getKeys(false).isEmpty()) { // Read all global groups Map allGroups = new HashMap(); - + try { allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); } catch (Exception ex) { - //ex.printStackTrace(); - throw new IllegalArgumentException("Your " + GlobalGroupsFile.getPath() + " file is invalid. See console for details.", ex); - } - + // ex.printStackTrace(); + throw new IllegalArgumentException("Your " + GlobalGroupsFile.getPath() + " file is invalid. See console for details.", ex); + } + // Load each groups permissions list. if (allGroups != null) { - + Iterator groupItr = allGroups.keySet().iterator(); - String groupName; - Integer groupCount = 0; - - /* - * loop each group entry - * and read it's data. - */ - while (groupItr.hasNext()) { - try { - groupCount++; - // Attempt to fetch the next group name. - groupName = groupItr.next(); - } catch (Exception ex) { + String groupName; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupName = groupItr.next(); + } catch (Exception ex) { throw new IllegalArgumentException("Invalid group name for GlobalGroup entry (" + groupCount + ") in file: " + GlobalGroupsFile.getPath(), ex); } - /* - * Create a new group with this name. - */ - Group newGroup = new Group(groupName.toLowerCase()); + /* + * Create a new group with this name. + */ + Group newGroup = new Group(groupName.toLowerCase()); Object element; - + // Permission nodes element = GGroups.get("groups." + groupName + ".permissions"); - + if (element != null) if (element instanceof List) { try { @@ -164,31 +168,31 @@ public class GlobalGroups { newGroup.addPermission((String) element); } else throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); - + // Info nodes element = GGroups.get("groups." + groupName + ".info"); - + if (element != null) if (element instanceof MemorySection) { Map vars = new HashMap(); for (String key : ((MemorySection) element).getKeys(false)) { - vars.put(key, ((MemorySection) element).get(key)); - } + vars.put(key, ((MemorySection) element).get(key)); + } newGroup.setVariables(vars); } else throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); - + // Push a new group addGroup(newGroup); } } - + removeGroupsChangedFlag(); } - + setTimeStampGroups(GlobalGroupsFile.lastModified()); GroupManager.setLoaded(true); - //GlobalGroupsFile = null; + // GlobalGroupsFile = null; } /** @@ -197,33 +201,33 @@ public class GlobalGroups { public void writeGroups(boolean overwrite) { - //File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml"); + // File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml"); if (haveGroupsChanged()) { if (overwrite || (!overwrite && (getTimeStampGroups() >= GlobalGroupsFile.lastModified()))) { Map root = new HashMap(); - + Map groupsMap = new HashMap(); root.put("groups", groupsMap); for (String groupKey : groups.keySet()) { Group group = groups.get(groupKey); - + // Group header Map aGroupMap = new HashMap(); groupsMap.put(group.getName(), aGroupMap); - + // Info nodes Map infoMap = new HashMap(); - aGroupMap.put("info", infoMap); - - for (String infoKey : group.getVariables().getVarKeyList()) { - infoMap.put(infoKey, group.getVariables().getVarObject(infoKey)); - } - - // Permission nodes + aGroupMap.put("info", infoMap); + + for (String infoKey : group.getVariables().getVarKeyList()) { + infoMap.put(infoKey, group.getVariables().getVarObject(infoKey)); + } + + // Permission nodes aGroupMap.put("permissions", group.getPermissionList()); } - + if (!root.isEmpty()) { DumperOptions opt = new DumperOptions(); opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); @@ -236,53 +240,55 @@ public class GlobalGroups { } setTimeStampGroups(GlobalGroupsFile.lastModified()); } else { - // Newer file found. - GroupManager.logger.log(Level.WARNING, "Newer GlobalGroups file found, but we have local changes!"); - throw new IllegalStateException("Unable to save unless you issue a '/mansave force'"); - } + // Newer file found. + GroupManager.logger.log(Level.WARNING, "Newer GlobalGroups file found, but we have local changes!"); + throw new IllegalStateException("Unable to save unless you issue a '/mansave force'"); + } removeGroupsChangedFlag(); } else { - //Check for newer file as no local changes. - if (getTimeStampGroups() < GlobalGroupsFile.lastModified()) { - System.out.print("Newer GlobalGroups file found (Loading changes)!"); - // Backup GlobalGroups file - backupFile(); - load(); - } - } + // Check for newer file as no local changes. + if (getTimeStampGroups() < GlobalGroupsFile.lastModified()) { + System.out.print("Newer GlobalGroups file found (Loading changes)!"); + // Backup GlobalGroups file + backupFile(); + load(); + } + } } - + /** - * Backup the BlobalGroups file - * @param w - */ - private void backupFile() { - - File backupFile = new File(plugin.getBackupFolder(), "bkp_ggroups_" + Tasks.getDateString() + ".yml"); - try { - Tasks.copy(GlobalGroupsFile, backupFile); - } catch (IOException ex) { - GroupManager.logger.log(Level.SEVERE, null, ex); - } - } - + * Backup the BlobalGroups file + * + * @param w + */ + private void backupFile() { + + File backupFile = new File(plugin.getBackupFolder(), "bkp_ggroups_" + Tasks.getDateString() + ".yml"); + try { + Tasks.copy(GlobalGroupsFile, backupFile); + } catch (IOException ex) { + GroupManager.logger.log(Level.SEVERE, null, ex); + } + } + /** * Adds a group, or replaces an existing one. * * @param groupToAdd */ public void addGroup(Group groupToAdd) { + // Create a new group if it already exists if (hasGroup(groupToAdd.getName())) { groupToAdd = groupToAdd.clone(); removeGroup(groupToAdd.getName()); } - + newGroup(groupToAdd); - haveGroupsChanged = true; - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); + haveGroupsChanged = true; + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); } /** @@ -291,6 +297,7 @@ public class GlobalGroups { * @param newGroup */ public Group newGroup(Group newGroup) { + // Push a new group if (!groups.containsKey(newGroup.getName().toLowerCase())) { groups.put(newGroup.getName().toLowerCase(), newGroup); @@ -306,6 +313,7 @@ public class GlobalGroups { * @param groupName */ public boolean removeGroup(String groupName) { + // Push a new group if (groups.containsKey(groupName.toLowerCase())) { groups.remove(groupName.toLowerCase()); @@ -324,6 +332,7 @@ public class GlobalGroups { * @return true if the group exists */ public boolean hasGroup(String groupName) { + return groups.containsKey(groupName.toLowerCase()); } @@ -379,6 +388,7 @@ public class GlobalGroups { * @return List of all group names */ public List getGroupsPermissions(String groupName) { + if (!hasGroup(groupName)) return null; @@ -391,6 +401,7 @@ public class GlobalGroups { * @return Set containing all group names. */ public Set getGlobalGroups() { + return groups.keySet(); } @@ -398,14 +409,16 @@ public class GlobalGroups { * Resets GlobalGroups. */ public void resetGlobalGroups() { + this.groups = new HashMap(); } - + /** * * @return a collection of the groups */ public Collection getGroupList() { + return groups.values(); } @@ -416,6 +429,7 @@ public class GlobalGroups { * @return Group object */ public Group getGroup(String groupName) { + if (!hasGroup(groupName)) return null; @@ -427,17 +441,19 @@ public class GlobalGroups { * @return the globalGroupsFile */ public File getGlobalGroupsFile() { + return GlobalGroupsFile; } - + /** * */ - public void removeGroupsChangedFlag() { - setGroupsChanged(false); - for (Group g : groups.values()) { - g.flagAsSaved(); - } - } + public void removeGroupsChangedFlag() { + + setGroupsChanged(false); + for (Group g : groups.values()) { + g.flagAsSaved(); + } + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 1c4011ff8..b75c2242e 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -45,7 +45,6 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; - @SuppressWarnings("unused") /** * @@ -61,13 +60,14 @@ public class GroupManager extends JavaPlugin { private Map selectedWorlds = new HashMap(); private WorldsHolder worldsHolder; private boolean validateOnlinePlayer = true; - + private String lastError = ""; - + /** * @return the validateOnlinePlayer */ public boolean isValidateOnlinePlayer() { + return validateOnlinePlayer; } @@ -75,6 +75,7 @@ public class GroupManager extends JavaPlugin { * @param validateOnlinePlayer the validateOnlinePlayer to set */ public void setValidateOnlinePlayer(boolean validateOnlinePlayer) { + this.validateOnlinePlayer = validateOnlinePlayer; } @@ -95,8 +96,9 @@ public class GroupManager extends JavaPlugin { @Override public void onDisable() { + setLoaded(false); - + // Un-register this service. this.getServer().getServicesManager().unregister(this.worldsHolder); @@ -110,31 +112,30 @@ public class GroupManager extends JavaPlugin { } WorldEvents = null; - + // Remove all attachments before clearing if (BukkitPermissions != null) { BukkitPermissions.removeAllAttachments(); BukkitPermissions = null; } - // EXAMPLE: Custom code, here we just output some info so we can check that - // all is well + // EXAMPLE: Custom code, here we just output some info so we can check that all is well PluginDescriptionFile pdfFile = this.getDescription(); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!"); GroupManager.logger.removeHandler(ch); } - //@Override + // @Override public void onEnable() { - + try { lastError = ""; - + GroupManager.logger.setUseParentHandlers(false); ch = new GMLoggerHandler(); GroupManager.logger.addHandler(ch); logger.setLevel(Level.ALL); - + // Create the backup folder, if it doesn't exist. prepareFileFields(); // Load the config.yml @@ -142,41 +143,40 @@ public class GroupManager extends JavaPlugin { // Load the global groups globalGroups = new GlobalGroups(this); worldsHolder = new WorldsHolder(this); - - + PluginDescriptionFile pdfFile = this.getDescription(); if (worldsHolder == null) { GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!"); this.getServer().getPluginManager().disablePlugin(this); throw new IllegalStateException("An error ocurred while loading GroupManager"); } - + // Set a few defaults (reloads) setLoaded(false); - - // Initialize the world listener and bukkit permissions to handle - // events. + + // Initialize the world listener and bukkit permissions to handle events. WorldEvents = new GMWorldListener(this); BukkitPermissions = new BukkitPermissions(this); - + enableScheduler(); - + /* - * Schedule a Bukiit Permissions update for 1 tick later. All plugins + * Schedule a Bukiit Permissions update for 1 tick later. All + * plugins * will be loaded by then */ - + if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { GroupManager.logger.severe("Could not schedule superperms Update."); setLoaded(true); } - + System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); - + // Register as a service this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); } catch (Exception ex) { - + /* * Store the error and write to the log. */ @@ -185,41 +185,41 @@ public class GroupManager extends JavaPlugin { /* * Throw an error so Bukkit knows about it. */ - throw new IllegalArgumentException(ex.getMessage(),ex); + throw new IllegalArgumentException(ex.getMessage(), ex); } } - + /** * Write an error.log * * @param ex */ private void saveErrorLog(Exception ex) { - + if (!getDataFolder().exists()) { - getDataFolder().mkdirs(); - } - + getDataFolder().mkdirs(); + } + lastError = ex.getMessage(); - + GroupManager.logger.severe("==================================================="); GroupManager.logger.severe("= ERROR REPORT START ="); GroupManager.logger.severe("==================================================="); GroupManager.logger.severe("=== PLEASE COPY AND PASTE THE ERROR.LOG FROM THE =="); GroupManager.logger.severe("= GROUPMANAGER FOLDER TO AN ESSENTIALS DEVELOPER ="); GroupManager.logger.severe("==================================================="); - GroupManager.logger.severe(lastError); + GroupManager.logger.severe(lastError); GroupManager.logger.severe("==================================================="); GroupManager.logger.severe("= ERROR REPORT ENDED ="); GroupManager.logger.severe("==================================================="); // Append this error to the error log. - try { - String error = "=============================== GM ERROR LOG ===============================\n\n"; - error += Tasks.getStackTraceAsString(ex); - error += "\n============================================================================\n"; - + try { + String error = "=============================== GM ERROR LOG ===============================\n\n"; + error += Tasks.getStackTraceAsString(ex); + error += "\n============================================================================\n"; + Tasks.appendStringToFile(error, (getDataFolder() + System.getProperty("file.separator") + "ERROR.LOG")); } catch (IOException e) { // Failed to write file. @@ -229,18 +229,22 @@ public class GroupManager extends JavaPlugin { } public static boolean isLoaded() { + return isLoaded; } public static void setLoaded(boolean isLoaded) { + GroupManager.isLoaded = isLoaded; } public InputStream getResourceAsStream(String fileName) { + return this.getClassLoader().getResourceAsStream(fileName); } private void prepareFileFields() { + // configFile = new File(this.getDataFolder(), "config.yml"); backupFolder = new File(this.getDataFolder(), "backup"); if (!backupFolder.exists()) { @@ -249,16 +253,19 @@ public class GroupManager extends JavaPlugin { } private void prepareConfig() { + config = new GMConfiguration(this); } public void enableScheduler() { + if (worldsHolder != null) { disableScheduler(); commiter = new Runnable() { @Override public void run() { + try { worldsHolder.saveChanges(false); GroupManager.logger.log(Level.INFO, " Data files refreshed."); @@ -268,18 +275,19 @@ public class GroupManager extends JavaPlugin { } }; scheduler = new ScheduledThreadPoolExecutor(1); - long minutes = (long)getGMConfig().getSaveInterval(); + long minutes = (long) getGMConfig().getSaveInterval(); if (minutes > 0) { - scheduler.scheduleAtFixedRate(commiter, minutes, minutes, TimeUnit.MINUTES); + scheduler.scheduleAtFixedRate(commiter, minutes, minutes, TimeUnit.MINUTES); GroupManager.logger.info("Scheduled Data Saving is set for every " + minutes + " minutes!"); } else GroupManager.logger.info("Scheduled Data Saving is Disabled!"); - + GroupManager.logger.info("Backups will be retained for " + getGMConfig().getBackupDuration() + " hours!"); } } public void disableScheduler() { + if (scheduler != null) { try { scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); @@ -297,6 +305,7 @@ public class GroupManager extends JavaPlugin { */ @Deprecated public void commit() { + if (worldsHolder != null) { worldsHolder.saveChanges(); } @@ -307,10 +316,12 @@ public class GroupManager extends JavaPlugin { */ @Deprecated public void reload() { + worldsHolder.reloadAll(); } public WorldsHolder getWorldsHolder() { + return worldsHolder; } @@ -321,6 +332,7 @@ public class GroupManager extends JavaPlugin { */ @Deprecated public AnjoPermissionsHandler getPermissionHandler() { + return worldsHolder.getDefaultWorld().getPermissionsHandler(); } @@ -332,6 +344,7 @@ public class GroupManager extends JavaPlugin { */ @Deprecated public WorldDataHolder getData() { + return worldsHolder.getDefaultWorld(); } @@ -342,6 +355,7 @@ public class GroupManager extends JavaPlugin { */ @Deprecated public OverloadedWorldHolder getOverloadedClassData() { + return worldsHolder.getDefaultWorld(); } @@ -355,23 +369,23 @@ public class GroupManager extends JavaPlugin { @SuppressWarnings({ "deprecation" }) @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + boolean playerCanDo = false; boolean isConsole = false; Player senderPlayer = null, targetPlayer = null; Group senderGroup = null; User senderUser = null; boolean isOpOverride = config.isOpOverride(); - // DETERMINING PLAYER INFORMATION if (sender instanceof Player) { senderPlayer = (Player) sender; - + if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); return true; } - + senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderGroup = senderUser.getGroup(); isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op"))); @@ -381,12 +395,12 @@ public class GroupManager extends JavaPlugin { playerCanDo = true; } } else if (sender instanceof ConsoleCommandSender) { - + if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); return true; } - + isConsole = true; } @@ -451,29 +465,29 @@ public class GroupManager extends JavaPlugin { if (isConsole || playerCanDo) { switch (execCmd) { case manuadd: - + // Validating arguments if ((args.length != 2) && (args.length != 3)) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional [world])"); return false; } - + // Select the relevant world (if specified) if (args.length == 3) { dataHolder = worldsHolder.getWorldData(args[2]); permissionHandler = dataHolder.getPermissionsHandler(); } - + // Validating state of sender if (dataHolder == null || permissionHandler == null) { if (!setDefaultWorldHandler(sender)) return true; } - + if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -509,7 +523,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "' in world '" + dataHolder.getName() + "'."); return true; - + case manudel: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -522,9 +536,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -545,7 +559,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updatePermissions(targetPlayer); return true; - + case manuaddsub: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -561,9 +575,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -586,7 +600,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "The subgroup '" + auxGroup.getName() + "' is already available to '" + auxUser.getName() + "'."); return true; - + case manudelsub: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -599,9 +613,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -622,12 +636,12 @@ public class GroupManager extends JavaPlugin { auxUser.removeSubGroup(auxGroup); sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list."); - //targetPlayer = this.getServer().getPlayer(auxUser.getName()); - //if (targetPlayer != null) - // BukkitPermissions.updatePermissions(targetPlayer); + // targetPlayer = this.getServer().getPlayer(auxUser.getName()); + // if (targetPlayer != null) + // BukkitPermissions.updatePermissions(targetPlayer); return true; - + case mangadd: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -649,7 +663,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You created a group named: " + auxGroup.getName()); return true; - + case mangdel: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -673,7 +687,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; - + case manuaddp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -686,9 +700,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -738,7 +752,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updatePermissions(targetPlayer); return true; - + case manudelp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -751,9 +765,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -789,7 +803,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updatePermissions(targetPlayer); return true; - + case manulistp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -801,11 +815,11 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ (+))"); return false; } - + if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -854,7 +868,7 @@ public class GroupManager extends JavaPlugin { } return true; - + case manucheckp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -868,9 +882,9 @@ public class GroupManager extends JavaPlugin { } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -881,9 +895,9 @@ public class GroupManager extends JavaPlugin { permissionResult = permissionHandler.checkFullGMPermission(auxUser, args[1], false); if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) { - //No permissions found in GM so fall through and check Bukkit. + // No permissions found in GM so fall through and check Bukkit. sender.sendMessage(ChatColor.RED + "The player doesn't have access to that permission"); - + } else { // This permission was found in groupmanager. if (permissionResult.owner instanceof User) { @@ -909,7 +923,7 @@ public class GroupManager extends JavaPlugin { } return true; - + case mangaddp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -964,7 +978,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; - + case mangdelp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1005,7 +1019,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; - + case manglistp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1054,7 +1068,7 @@ public class GroupManager extends JavaPlugin { } return true; - + case mangcheckp: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1078,8 +1092,7 @@ public class GroupManager extends JavaPlugin { return false; } // Seems OK - // auxString = - // permissionHandler.checkUserOnlyPermission(auxUser, args[1]); + // auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]); if (permissionResult.owner instanceof Group) { if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) { sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName()); @@ -1090,7 +1103,7 @@ public class GroupManager extends JavaPlugin { } return true; - + case mangaddi: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1116,7 +1129,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support inheritance."); return false; } - + // Validating permission if (permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " already inherits " + auxGroup2.getName() + " (might not be directly)"); @@ -1129,7 +1142,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; - + case mangdeli: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1155,7 +1168,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "GlobalGroups do NOT support inheritance."); return false; } - + // Validating permission if (!permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + "."); @@ -1172,7 +1185,7 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); return true; - + case manuaddv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1185,9 +1198,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -1204,9 +1217,9 @@ public class GroupManager extends JavaPlugin { } auxUser.getVariables().addVar(args[1], Variables.parseVariableValue(auxString)); sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the user " + auxUser.getName()); - + return true; - + case manudelv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1219,9 +1232,9 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } - + if (match != null) { auxUser = dataHolder.getUser(match.get(0)); } else { @@ -1234,9 +1247,9 @@ public class GroupManager extends JavaPlugin { // Seems OK auxUser.getVariables().removeVar(args[1]); sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the user " + ChatColor.GREEN + auxUser.getName()); - + return true; - + case manulistv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1249,7 +1262,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1269,9 +1282,9 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Variables of user " + auxUser.getName() + ": "); sender.sendMessage(auxString + "."); sender.sendMessage(ChatColor.YELLOW + "Plus all variables from group: " + auxUser.getGroupName()); - + return true; - + case manucheckv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1284,7 +1297,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1300,7 +1313,8 @@ public class GroupManager extends JavaPlugin { if (!auxUser.isSubGroupsEmpty() && auxGroup2 == null) for (Group subGroup : auxUser.subGroupListCopy()) { auxGroup2 = permissionHandler.nextGroupWithVariable(subGroup, args[1]); - if (auxGroup2 != null) continue; + if (auxGroup2 != null) + continue; } if (auxGroup2 == null) { sender.sendMessage(ChatColor.RED + "The user doesn't have access to that variable!"); @@ -1316,9 +1330,9 @@ public class GroupManager extends JavaPlugin { if (!auxGroup.equals(auxGroup2)) { sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName()); } - + return true; - + case mangaddv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1352,7 +1366,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the group " + auxGroup.getName()); return true; - + case mangdelv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1382,7 +1396,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the group " + ChatColor.GREEN + auxGroup.getName()); return true; - + case manglistv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1423,9 +1437,9 @@ public class GroupManager extends JavaPlugin { auxString = auxString.substring(0, auxString.lastIndexOf(",")); sender.sendMessage(ChatColor.YELLOW + "Plus all variables from groups: " + auxString); } - + return true; - + case mangcheckv: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1456,9 +1470,9 @@ public class GroupManager extends JavaPlugin { if (!auxGroup.equals(auxGroup2)) { sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName()); } - + return true; - + case manwhois: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1471,7 +1485,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1490,7 +1504,7 @@ public class GroupManager extends JavaPlugin { auxString = auxString.substring(0, auxString.lastIndexOf(",")); sender.sendMessage(ChatColor.YELLOW + "subgroups: " + auxString); } - + sender.sendMessage(ChatColor.YELLOW + "Overloaded: " + ChatColor.GREEN + dataHolder.isOverloaded(auxUser.getName())); auxGroup = dataHolder.surpassOverload(auxUser.getName()).getGroup(); if (!auxGroup.equals(auxUser.getGroup())) { @@ -1498,7 +1512,7 @@ public class GroupManager extends JavaPlugin { } // victim.permissions.add(args[1]); return true; - + case tempadd: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1511,7 +1525,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1532,7 +1546,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Player overloaded!"); return true; - + case tempdel: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1545,7 +1559,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1568,7 +1582,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You removed that player's overload. He's back to normal!"); return true; - + case templist: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1597,9 +1611,9 @@ public class GroupManager extends JavaPlugin { } overloadedUsers.get(dataHolder.getName().toLowerCase()).removeAll(removeList); sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode: " + ChatColor.WHITE + auxString); - + return true; - + case tempdelall: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1626,14 +1640,14 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + " " + count + "All users in overload mode are now normal again."); return true; - + case mansave: - + boolean forced = false; - + if ((args.length == 1) && (args[0].equalsIgnoreCase("force"))) forced = true; - + try { worldsHolder.saveChanges(forced); sender.sendMessage(ChatColor.YELLOW + " All changes were saved."); @@ -1643,17 +1657,17 @@ public class GroupManager extends JavaPlugin { return true; case manload: - + /** * Attempt to reload a specific world */ if (args.length > 0) { - + if (!lastError.isEmpty()) { sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); return true; } - + auxString = ""; for (int i = 0; i < args.length; i++) { auxString += args[i]; @@ -1666,7 +1680,7 @@ public class GroupManager extends JavaPlugin { globalGroups.load(); worldsHolder.loadWorld(auxString); - + sender.sendMessage("The request to reload world '" + auxString + "' was attempted."); isLoaded = true; @@ -1674,29 +1688,29 @@ public class GroupManager extends JavaPlugin { BukkitPermissions.updateAllPlayers(); } else { - + /** * Reload all settings and data as no world was specified. */ - + /* * Reset the last error as we are attempting a fresh load. */ lastError = ""; onDisable(); onEnable(); - + sender.sendMessage("All settings and worlds were reloaded!"); } - + /** * Fire an event as none will have been triggered in the reload. */ if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); return true; - + case listgroups: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1715,9 +1729,9 @@ public class GroupManager extends JavaPlugin { auxString = auxString.substring(0, auxString.lastIndexOf(",")); } sender.sendMessage(ChatColor.YELLOW + " Groups Available: " + ChatColor.WHITE + auxString); - + return true; - + case manpromote: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1730,7 +1744,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1773,7 +1787,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); return true; - + case mandemote: // Validating state of sender if (dataHolder == null || permissionHandler == null) { @@ -1786,7 +1800,7 @@ public class GroupManager extends JavaPlugin { return false; } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { - return false; + return false; } if (match != null) { auxUser = dataHolder.getUser(match.get(0)); @@ -1829,7 +1843,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); return true; - + case mantogglevalidate: validateOnlinePlayer = !validateOnlinePlayer; sender.sendMessage(ChatColor.YELLOW + "Validade if player is online, now set to: " + Boolean.toString(validateOnlinePlayer)); @@ -1860,9 +1874,9 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.YELLOW + "Your world now uses permissions of world name: '" + dataHolder.getName() + "' "); } } - + return true; - + case manselect: if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ )"); @@ -1893,9 +1907,9 @@ public class GroupManager extends JavaPlugin { permissionHandler = dataHolder.getPermissionsHandler(); selectedWorlds.put(sender, dataHolder.getName()); sender.sendMessage(ChatColor.YELLOW + "You have selected world '" + dataHolder.getName() + "'."); - + return true; - + case manclear: if (args.length != 0) { sender.sendMessage(ChatColor.RED + "Review your arguments count!"); @@ -1903,9 +1917,9 @@ public class GroupManager extends JavaPlugin { } selectedWorlds.remove(sender); sender.sendMessage(ChatColor.YELLOW + "You have removed your world selection. Working with current world(if possible)."); - + return true; - + default: break; } @@ -1955,7 +1969,7 @@ public class GroupManager extends JavaPlugin { } } - + /** * Load a List of players matching the name given. If none online, check * Offline. @@ -1974,7 +1988,7 @@ public class GroupManager extends JavaPlugin { if (Arrays.asList(this.getServer().getOfflinePlayers()).contains(Bukkit.getOfflinePlayer(playerName))) { match.add(playerName); } else { - //look for partial matches + // look for partial matches for (OfflinePlayer offline : this.getServer().getOfflinePlayers()) { if (offline.getName().toLowerCase().startsWith(playerName.toLowerCase())) match.add(offline.getName()); @@ -1994,7 +2008,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Too many matches found! (" + match.toString() + ")"); return null; } - + return match; } @@ -2003,6 +2017,7 @@ public class GroupManager extends JavaPlugin { * @return the config */ public GMConfiguration getGMConfig() { + return config; } @@ -2010,10 +2025,12 @@ public class GroupManager extends JavaPlugin { * @return the backupFolder */ public File getBackupFolder() { + return backupFolder; } public static GlobalGroups getGlobalGroups() { + return globalGroups; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java index f4b805c35..1a0fc2369 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java @@ -5,24 +5,25 @@ import org.anjocaido.groupmanager.GroupManager; /* * * Created by ElgarL - * */ public class BukkitPermsUpdateTask implements Runnable { - + public BukkitPermsUpdateTask() { - super(); + + super(); } - + @Override public void run() { + // Signal loaded and update BukkitPermissions. GroupManager.setLoaded(true); GroupManager.BukkitPermissions.collectPermissions(); GroupManager.BukkitPermissions.updateAllPlayers(); - + GroupManager.logger.info("Bukkit Permissions Updated!"); - + } - + } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java index e3250a1c1..bb04fa3d7 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java @@ -13,151 +13,169 @@ import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.utils.StringPermissionComparator; /** - * + * * @author gabrielcouto */ public abstract class DataUnit { - private WorldDataHolder dataSource; - private String name; - private boolean changed, sorted = false; - private ArrayList permissions = new ArrayList(); + private WorldDataHolder dataSource; + private String name; + private boolean changed, sorted = false; + private ArrayList permissions = new ArrayList(); - public DataUnit(WorldDataHolder dataSource, String name) { - this.dataSource = dataSource; - this.name = name; - } + public DataUnit(WorldDataHolder dataSource, String name) { - public DataUnit(String name) { - this.name = name; + this.dataSource = dataSource; + this.name = name; + } + + public DataUnit(String name) { + + this.name = name; + } + + /** + * Every group is matched only by their names and DataSources names. + * + * @param o + * @return true if they are equal. false if not. + */ + @Override + public boolean equals(Object o) { + + if (o instanceof DataUnit) { + DataUnit go = (DataUnit) o; + if (this.getName().equalsIgnoreCase(go.getName())) { + // Global Group match. + if (this.dataSource == null && go.getDataSource() == null) + return true; + // This is a global group, the object to test isn't. + if (this.dataSource == null && go.getDataSource() != null) + return false; + // This is not a global group, but the object to test is. + if (this.dataSource != null && go.getDataSource() == null) + return false; + // Match on group name and world name. + if (this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName())) + return true; + } + } + return false; + } + + @Override + public int hashCode() { + + int hash = 5; + hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0); + return hash; + } + + /** + * Set the data source to point to a different worldDataHolder + * + * @param source + */ + public void setDataSource(WorldDataHolder source) { + + this.dataSource = source; + } + + /** + * Get the current worldDataHolder this object is pointing to + * + * @return the dataSource + */ + public WorldDataHolder getDataSource() { + + return dataSource; + } + + /** + * @return the name + */ + public String getName() { + + return name; + } + + public void flagAsChanged() { + + WorldDataHolder testSource = getDataSource(); + String source = ""; + + if (testSource == null) + source = "GlobalGroups"; + else + source = testSource.getName(); + + GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!"); + // for(StackTraceElement st: Thread.currentThread().getStackTrace()){ + // GroupManager.logger.finest(st.toString()); + // } + sorted = false; + changed = true; + } + + public boolean isChanged() { + + return changed; + } + + public void flagAsSaved() { + + WorldDataHolder testSource = getDataSource(); + String source = ""; + + if (testSource == null) + source = "GlobalGroups"; + else + source = testSource.getName(); + + GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!"); + changed = false; + } + + public boolean hasSamePermissionNode(String permission) { + + return permissions.contains(permission); + } + + public void addPermission(String permission) { + + if (!hasSamePermissionNode(permission)) { + permissions.add(permission); + } + flagAsChanged(); + } + + public boolean removePermission(String permission) { + + flagAsChanged(); + return permissions.remove(permission); } /** - * Every group is matched only by their names and DataSources names. - * @param o - * @return true if they are equal. false if not. - */ - @Override - public boolean equals(Object o) { - if (o instanceof DataUnit) { - DataUnit go = (DataUnit) o; - if (this.getName().equalsIgnoreCase(go.getName())) { - // Global Group match. - if (this.dataSource == null && go.getDataSource() == null) - return true; - // This is a global group, the object to test isn't. - if (this.dataSource == null && go.getDataSource() != null) - return false; - // This is not a global group, but the object to test is. - if (this.dataSource != null && go.getDataSource() == null) - return false; - // Match on group name and world name. - if (this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName())) - return true; - } - } - return false; - } - - @Override - public int hashCode() { - int hash = 5; - hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0); - return hash; - } - - /** - * Set the data source to point to a different worldDataHolder - * - * @param source - */ - public void setDataSource(WorldDataHolder source) { - this.dataSource = source; - } - - /** - * Get the current worldDataHolder this object is pointing to - * - * @return the dataSource - */ - public WorldDataHolder getDataSource() { - return dataSource; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - public void flagAsChanged() { - WorldDataHolder testSource = getDataSource(); - String source = ""; - - if (testSource == null) - source = "GlobalGroups"; - else - source = testSource.getName(); - - GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!"); -// for(StackTraceElement st: Thread.currentThread().getStackTrace()){ -// GroupManager.logger.finest(st.toString()); -// } - sorted = false; - changed = true; - } - - public boolean isChanged() { - return changed; - } - - public void flagAsSaved() { - WorldDataHolder testSource = getDataSource(); - String source = ""; - - if (testSource == null) - source = "GlobalGroups"; - else - source = testSource.getName(); - - GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!"); - changed = false; - } - - public boolean hasSamePermissionNode(String permission) { - return permissions.contains(permission); - } - - public void addPermission(String permission) { - if (!hasSamePermissionNode(permission)) { - permissions.add(permission); - } - flagAsChanged(); - } - - public boolean removePermission(String permission) { - flagAsChanged(); - return permissions.remove(permission); - } - - /** - * Use this only to list permissions. - * You can't edit the permissions using the returned ArrayList instance - * @return a copy of the permission list - */ - public List getPermissionList() { - return Collections.unmodifiableList(permissions); - } - - public boolean isSorted() { - return this.sorted; - } - - public void sortPermissions() { - if (!isSorted()) { - Collections.sort(permissions, StringPermissionComparator.getInstance()); - sorted = true; - } - } + * Use this only to list permissions. + * You can't edit the permissions using the returned ArrayList instance + * + * @return a copy of the permission list + */ + public List getPermissionList() { + + return Collections.unmodifiableList(permissions); + } + + public boolean isSorted() { + + return this.sorted; + } + + public void sortPermissions() { + + if (!isSorted()) { + Collections.sort(permissions, StringPermissionComparator.getInstance()); + sorted = true; + } + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index 56ef7e870..751dc8fd6 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -15,160 +15,173 @@ import java.util.List; import java.util.Map; /** - * + * * @author gabrielcouto/ElgarL */ public class Group extends DataUnit implements Cloneable { - /** - * The group it inherits DIRECTLY! - */ - private ArrayList inherits = new ArrayList(); - /** - *This one holds the fields in INFO node. - * like prefix = 'c' - * or build = false - */ - private GroupVariables variables = new GroupVariables(this); - - /** - * Constructor for individual World Groups. - * - * @param name - */ - public Group(WorldDataHolder source, String name) { - super(source, name); - } - - /** - * Constructor for Global Groups. - * - * @param name - */ - public Group(String name) { - super(name); - } - - /** - * Is this a GlobalGroup - * - * @return true if this is a global group - */ - public boolean isGlobal() { - return (getDataSource() == null); - } - - /** - * Clone this group - * @return a clone of this group - */ - @Override - public Group clone() { - Group clone; - - if (isGlobal()) { - clone = new Group(this.getName()); - } else { - clone = new Group(getDataSource(), this.getName()); - clone.inherits = new ArrayList(this.getInherits()); - } - - for (String perm : this.getPermissionList()) { - clone.addPermission(perm); - } - clone.variables = ((GroupVariables) variables).clone(clone); - //clone.flagAsChanged(); - return clone; - } - - /** - * Use this to deliver a group from a different dataSource to another - * @param dataSource - * @return Null or Clone - */ - public Group clone(WorldDataHolder dataSource) { - if (dataSource.groupExists(this.getName())) { - return null; - } - - Group clone = dataSource.createGroup(this.getName()); - - // Don't add inheritance for GlobalGroups - if (!isGlobal()) { - clone.inherits = new ArrayList(this.getInherits()); - } - for (String perm : this.getPermissionList()) { - clone.addPermission(perm); - } - clone.variables = variables.clone(clone); - clone.flagAsChanged(); //use this to make the new dataSource save the new group - return clone; - } - - /** - * an unmodifiable list of inherits list - * You can't manage the list by here - * Lol... version 0.6 had a problem because this. - * @return the inherits - */ - public List getInherits() { - return Collections.unmodifiableList(inherits); - } - - /** - * @param inherit the inherits to set - */ - public void addInherits(Group inherit) { - if (!isGlobal()) { - if (!this.getDataSource().groupExists(inherit.getName())) { - getDataSource().addGroup(inherit); - } - if (!inherits.contains(inherit.getName().toLowerCase())) { - inherits.add(inherit.getName().toLowerCase()); - } - flagAsChanged(); - if (GroupManager.isLoaded()) { - GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); - } - } - } - - public boolean removeInherits(String inherit) { - if (!isGlobal()) { - if (this.inherits.contains(inherit.toLowerCase())) { - this.inherits.remove(inherit.toLowerCase()); - flagAsChanged(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); - return true; - } - } - return false; - } - - /** - * @return the variables - */ - public GroupVariables getVariables() { - return variables; - } - - /** - * - * @param varList - */ - public void setVariables(Map varList) { - if (!isGlobal()) { - GroupVariables temp = new GroupVariables(this, varList); - variables.clearVars(); - for (String key : temp.getVarKeyList()) { - variables.addVar(key, temp.getVarObject(key)); - } - flagAsChanged(); - if (GroupManager.isLoaded()) { - GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED); - } - } - } + /** + * The group it inherits DIRECTLY! + */ + private ArrayList inherits = new ArrayList(); + /** + * This one holds the fields in INFO node. + * like prefix = 'c' + * or build = false + */ + private GroupVariables variables = new GroupVariables(this); + + /** + * Constructor for individual World Groups. + * + * @param name + */ + public Group(WorldDataHolder source, String name) { + + super(source, name); + } + + /** + * Constructor for Global Groups. + * + * @param name + */ + public Group(String name) { + + super(name); + } + + /** + * Is this a GlobalGroup + * + * @return true if this is a global group + */ + public boolean isGlobal() { + + return (getDataSource() == null); + } + + /** + * Clone this group + * + * @return a clone of this group + */ + @Override + public Group clone() { + + Group clone; + + if (isGlobal()) { + clone = new Group(this.getName()); + } else { + clone = new Group(getDataSource(), this.getName()); + clone.inherits = new ArrayList(this.getInherits()); + } + + for (String perm : this.getPermissionList()) { + clone.addPermission(perm); + } + clone.variables = ((GroupVariables) variables).clone(clone); + //clone.flagAsChanged(); + return clone; + } + + /** + * Use this to deliver a group from a different dataSource to another + * + * @param dataSource + * @return Null or Clone + */ + public Group clone(WorldDataHolder dataSource) { + + if (dataSource.groupExists(this.getName())) { + return null; + } + + Group clone = dataSource.createGroup(this.getName()); + + // Don't add inheritance for GlobalGroups + if (!isGlobal()) { + clone.inherits = new ArrayList(this.getInherits()); + } + for (String perm : this.getPermissionList()) { + clone.addPermission(perm); + } + clone.variables = variables.clone(clone); + clone.flagAsChanged(); //use this to make the new dataSource save the new group + return clone; + } + + /** + * an unmodifiable list of inherits list + * You can't manage the list by here + * Lol... version 0.6 had a problem because this. + * + * @return the inherits + */ + public List getInherits() { + + return Collections.unmodifiableList(inherits); + } + + /** + * @param inherit the inherits to set + */ + public void addInherits(Group inherit) { + + if (!isGlobal()) { + if (!this.getDataSource().groupExists(inherit.getName())) { + getDataSource().addGroup(inherit); + } + if (!inherits.contains(inherit.getName().toLowerCase())) { + inherits.add(inherit.getName().toLowerCase()); + } + flagAsChanged(); + if (GroupManager.isLoaded()) { + GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); + } + } + } + + public boolean removeInherits(String inherit) { + + if (!isGlobal()) { + if (this.inherits.contains(inherit.toLowerCase())) { + this.inherits.remove(inherit.toLowerCase()); + flagAsChanged(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); + return true; + } + } + return false; + } + + /** + * @return the variables + */ + public GroupVariables getVariables() { + + return variables; + } + + /** + * + * @param varList + */ + public void setVariables(Map varList) { + + if (!isGlobal()) { + GroupVariables temp = new GroupVariables(this, varList); + variables.clearVars(); + for (String key : temp.getVarKeyList()) { + variables.addVar(key, temp.getVarObject(key)); + } + flagAsChanged(); + if (GroupManager.isLoaded()) { + GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED); + } + } + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java index 19db58851..e08d1db7d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java @@ -7,81 +7,88 @@ package org.anjocaido.groupmanager.data; import java.util.Map; /** - * + * * @author gabrielcouto */ public class GroupVariables extends Variables implements Cloneable { - private Group owner; + private Group owner; - public GroupVariables(Group owner) { - super(owner); - this.owner = owner; - addVar("prefix", ""); - addVar("suffix", ""); - addVar("build", false); - } + public GroupVariables(Group owner) { - public GroupVariables(Group owner, Map varList) { - super(owner); - variables = varList; - if (variables.get("prefix") == null) { - variables.put("prefix", ""); - owner.flagAsChanged(); - } - //thisGrp.prefix = infoNode.get("prefix").toString(); + super(owner); + this.owner = owner; + addVar("prefix", ""); + addVar("suffix", ""); + addVar("build", false); + } - if (variables.get("suffix") == null) { - variables.put("suffix", ""); - owner.flagAsChanged(); - } - //thisGrp.suffix = infoNode.get("suffix").toString(); + public GroupVariables(Group owner, Map varList) { - if (variables.get("build") == null) { - variables.put("build", false); - owner.flagAsChanged(); - } - this.owner = owner; - } + super(owner); + variables = varList; + if (variables.get("prefix") == null) { + variables.put("prefix", ""); + owner.flagAsChanged(); + } + //thisGrp.prefix = infoNode.get("prefix").toString(); - /** - * A clone of all vars here. - * @return GroupVariables clone - */ - protected GroupVariables clone(Group newOwner) { - GroupVariables clone = new GroupVariables(newOwner); - for (String key : variables.keySet()) { - clone.variables.put(key, variables.get(key)); - } - newOwner.flagAsChanged(); - return clone; - } + if (variables.get("suffix") == null) { + variables.put("suffix", ""); + owner.flagAsChanged(); + } + //thisGrp.suffix = infoNode.get("suffix").toString(); - /** - * Remove a var from the list - * @param name - */ - @Override - public void removeVar(String name) { - try { - this.variables.remove(name); - } catch (Exception e) { - } - if (name.equals("prefix")) { - addVar("prefix", ""); - } else if (name.equals("suffix")) { - addVar("suffix", ""); - } else if (name.equals("build")) { - addVar("build", false); - } - owner.flagAsChanged(); - } + if (variables.get("build") == null) { + variables.put("build", false); + owner.flagAsChanged(); + } + this.owner = owner; + } - /** - * @return the owner - */ - @Override - public Group getOwner() { - return owner; - } + /** + * A clone of all vars here. + * + * @return GroupVariables clone + */ + protected GroupVariables clone(Group newOwner) { + + GroupVariables clone = new GroupVariables(newOwner); + for (String key : variables.keySet()) { + clone.variables.put(key, variables.get(key)); + } + newOwner.flagAsChanged(); + return clone; + } + + /** + * Remove a var from the list + * + * @param name + */ + @Override + public void removeVar(String name) { + + try { + this.variables.remove(name); + } catch (Exception e) { + } + if (name.equals("prefix")) { + addVar("prefix", ""); + } else if (name.equals("suffix")) { + addVar("suffix", ""); + } else if (name.equals("build")) { + addVar("build", false); + } + owner.flagAsChanged(); + } + + /** + * @return the owner + */ + @Override + public Group getOwner() { + + return owner; + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 217ab904e..25b3cb3fe 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -16,7 +16,6 @@ import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; - /** * * @author gabrielcouto/ElgarL @@ -40,6 +39,7 @@ public class User extends DataUnit implements Cloneable { * @param name */ public User(WorldDataHolder source, String name) { + super(source, name); this.group = source.getDefaultGroup().getName(); } @@ -50,6 +50,7 @@ public class User extends DataUnit implements Cloneable { */ @Override public User clone() { + User clone = new User(getDataSource(), this.getName()); clone.group = this.group; for (String perm : this.getPermissionList()) { @@ -67,6 +68,7 @@ public class User extends DataUnit implements Cloneable { * @return null if given dataSource already contains the same user */ public User clone(WorldDataHolder dataSource) { + if (dataSource.isUserDeclared(this.getName())) { return null; } @@ -85,6 +87,7 @@ public class User extends DataUnit implements Cloneable { } public Group getGroup() { + Group result = getDataSource().getGroup(group); if (result == null) { this.setGroup(getDataSource().getDefaultGroup()); @@ -97,6 +100,7 @@ public class User extends DataUnit implements Cloneable { * @return the group */ public String getGroupName() { + Group result = getDataSource().getGroup(group); if (result == null) { group = getDataSource().getDefaultGroup().getName(); @@ -110,6 +114,7 @@ public class User extends DataUnit implements Cloneable { */ @Deprecated public void setGroup(String group) { + this.group = group; flagAsChanged(); if (GroupManager.isLoaded()) @@ -122,15 +127,17 @@ public class User extends DataUnit implements Cloneable { * the group to set */ public void setGroup(Group group) { + setGroup(group, true); } - + /** * @param group the group to set * @param updatePerms if we are to trigger a superperms update. - * + * */ public void setGroup(Group group, Boolean updatePerms) { + if (!this.getDataSource().groupExists(group.getName())) { getDataSource().addGroup(group); } @@ -151,12 +158,13 @@ public class User extends DataUnit implements Cloneable { if (notify) GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); - + GroupManagerEventHandler.callEvent(this, Action.USER_GROUP_CHANGED); } } public boolean addSubGroup(Group subGroup) { + // Don't allow adding a subgroup if it's already set as the primary. if (this.group.equalsIgnoreCase(subGroup.getName())) { return false; @@ -164,12 +172,12 @@ public class User extends DataUnit implements Cloneable { // User already has this subgroup if (containsSubGroup(subGroup)) return false; - + // If the group doesn't exists add it if (!this.getDataSource().groupExists(subGroup.getName())) { getDataSource().addGroup(subGroup); } - + subGroups.add(subGroup.getName()); flagAsChanged(); if (GroupManager.isLoaded()) { @@ -178,25 +186,29 @@ public class User extends DataUnit implements Cloneable { GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED); } return true; - + //subGroup = getDataSource().getGroup(subGroup.getName()); //removeSubGroup(subGroup); //subGroups.add(subGroup.getName()); } public int subGroupsSize() { + return subGroups.size(); } public boolean isSubGroupsEmpty() { + return subGroups.isEmpty(); } public boolean containsSubGroup(Group subGroup) { + return subGroups.contains(subGroup.getName()); } public boolean removeSubGroup(Group subGroup) { + try { if (subGroups.remove(subGroup.getName())) { flagAsChanged(); @@ -212,6 +224,7 @@ public class User extends DataUnit implements Cloneable { } public ArrayList subGroupListCopy() { + ArrayList val = new ArrayList(); for (String gstr : subGroups) { Group g = getDataSource().getGroup(gstr); @@ -225,6 +238,7 @@ public class User extends DataUnit implements Cloneable { } public ArrayList subGroupListStringCopy() { + return new ArrayList(subGroups); } @@ -232,6 +246,7 @@ public class User extends DataUnit implements Cloneable { * @return the variables */ public UserVariables getVariables() { + return variables; } @@ -240,6 +255,7 @@ public class User extends DataUnit implements Cloneable { * @param varList */ public void setVariables(Map varList) { + //UserVariables temp = new UserVariables(this, varList); variables.clearVars(); for (String key : varList.keySet()) { @@ -254,6 +270,7 @@ public class User extends DataUnit implements Cloneable { } public User updatePlayer(Player player) { + if (player != null) { bukkitPlayer = player; } @@ -261,6 +278,7 @@ public class User extends DataUnit implements Cloneable { } public Player getBukkitPlayer() { + if (bukkitPlayer == null) { bukkitPlayer = Bukkit.getPlayer(this.getName()); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java index 0b3948cab..f994595c1 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java @@ -7,42 +7,47 @@ package org.anjocaido.groupmanager.data; import java.util.Map; /** - * + * * @author gabrielcouto */ public class UserVariables extends Variables { - private User owner; - - public UserVariables(User owner) { - super(owner); - this.owner = owner; - } - - public UserVariables(User owner, Map varList) { - super(owner); - this.variables = varList; - this.owner = owner; - } - - /** - * A clone of all vars here. - * @return UserVariables clone - */ - protected UserVariables clone(User newOwner) { - UserVariables clone = new UserVariables(newOwner); - for (String key : variables.keySet()) { - clone.variables.put(key, variables.get(key)); - } - newOwner.flagAsChanged(); - return clone; - } - - /** - * @return the owner - */ - @Override - public User getOwner() { - return owner; - } + private User owner; + + public UserVariables(User owner) { + + super(owner); + this.owner = owner; + } + + public UserVariables(User owner, Map varList) { + + super(owner); + this.variables = varList; + this.owner = owner; + } + + /** + * A clone of all vars here. + * + * @return UserVariables clone + */ + protected UserVariables clone(User newOwner) { + + UserVariables clone = new UserVariables(newOwner); + for (String key : variables.keySet()) { + clone.variables.put(key, variables.get(key)); + } + newOwner.flagAsChanged(); + return clone; + } + + /** + * @return the owner + */ + @Override + public User getOwner() { + + return owner; + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java index 140d6626a..42ceba7e4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java @@ -9,178 +9,200 @@ import java.util.Map; import java.util.Set; /** - *A class that holds variables of a user/group. + * A class that holds variables of a user/group. * In groups, it holds the contents of INFO node. * Like: * prefix * suffix * build - * + * * @author gabrielcouto */ public abstract class Variables implements Cloneable { - private DataUnit owner; - protected Map variables = new HashMap(); - - public Variables(DataUnit owner) { - this.owner = owner; - } - - /** - * Add var to the the INFO node. - * examples: - * addVar("build",true); - * addVar("prefix","c"); - * @param name key name of the var - * @param o the object value of the var - */ - public void addVar(String name, Object o) { - if (o == null) { - return; - } - if (variables.containsKey(name)) { - variables.remove(name); - } - variables.put(name, o); - owner.flagAsChanged(); - } - - /** - * Returns the object inside the var - * @param name - * @return a Object if exists. null if doesn't exists - */ - public Object getVarObject(String name) { - return variables.get(name); - } - - /** - * Get the String value for the given var name - * @param name the var key name - * @return "" if null. or the toString() value of object - */ - public String getVarString(String name) { - Object o = variables.get(name); - try { - return o == null ? "" : o.toString(); - } catch (Exception e) { - return ""; - } - } - - /** - * - * @param name - * @return false if null. or a Boolean.parseBoolean of the string - */ - public Boolean getVarBoolean(String name) { - Object o = variables.get(name); - try { - return o == null ? false : Boolean.parseBoolean(o.toString()); - } catch (Exception e) { - return false; - } - } - - /** - * - * @param name - * @return -1 if null. or a parseInt of the string - */ - public Integer getVarInteger(String name) { - Object o = variables.get(name); - try { - return o == null ? -1 : Integer.parseInt(o.toString()); - } catch (Exception e) { - return -1; - } - } - - /** - * - * @param name - * @return -1 if null. or a parseDouble of the string - */ - public Double getVarDouble(String name) { - Object o = variables.get(name); - try { - return o == null ? -1.0D : Double.parseDouble(o.toString()); - } catch (Exception e) { - return -1.0D; - } - } - - /** - * All variable keys this is holding - * @return Set of all variable names. - */ - public Set getVarKeyList() { - return variables.keySet(); - } - - /** - * verify is a var exists - * @param name the key name of the var - * @return true if that var exists - */ - public boolean hasVar(String name) { - return variables.containsKey(name); - } - - /** - * Returns the quantity of vars this is holding - * @return the number of vars - */ - public int getSize() { - return variables.size(); - } - - /** - * Remove a var from the list - * @param name - */ - public void removeVar(String name) { - try { - variables.remove(name); - } catch (Exception e) { - } - owner.flagAsChanged(); - } - - public static Object parseVariableValue(String value) { - try { - Integer i = Integer.parseInt(value); - return i; - } catch (NumberFormatException e) { - } - try { - Double d = Double.parseDouble(value); - return d; - } catch (NumberFormatException e) { - } - if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) { - return true; - } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) { - return false; - } - return value; - - } - - public void clearVars() { - variables.clear(); - owner.flagAsChanged(); - } - - /** - * @return the owner - */ - public DataUnit getOwner() { - return owner; - } - - public boolean isEmpty() { - return variables.isEmpty(); - } + private DataUnit owner; + protected Map variables = new HashMap(); + + public Variables(DataUnit owner) { + + this.owner = owner; + } + + /** + * Add var to the the INFO node. + * examples: + * addVar("build",true); + * addVar("prefix","c"); + * + * @param name key name of the var + * @param o the object value of the var + */ + public void addVar(String name, Object o) { + + if (o == null) { + return; + } + if (variables.containsKey(name)) { + variables.remove(name); + } + variables.put(name, o); + owner.flagAsChanged(); + } + + /** + * Returns the object inside the var + * + * @param name + * @return a Object if exists. null if doesn't exists + */ + public Object getVarObject(String name) { + + return variables.get(name); + } + + /** + * Get the String value for the given var name + * + * @param name the var key name + * @return "" if null. or the toString() value of object + */ + public String getVarString(String name) { + + Object o = variables.get(name); + try { + return o == null ? "" : o.toString(); + } catch (Exception e) { + return ""; + } + } + + /** + * + * @param name + * @return false if null. or a Boolean.parseBoolean of the string + */ + public Boolean getVarBoolean(String name) { + + Object o = variables.get(name); + try { + return o == null ? false : Boolean.parseBoolean(o.toString()); + } catch (Exception e) { + return false; + } + } + + /** + * + * @param name + * @return -1 if null. or a parseInt of the string + */ + public Integer getVarInteger(String name) { + + Object o = variables.get(name); + try { + return o == null ? -1 : Integer.parseInt(o.toString()); + } catch (Exception e) { + return -1; + } + } + + /** + * + * @param name + * @return -1 if null. or a parseDouble of the string + */ + public Double getVarDouble(String name) { + + Object o = variables.get(name); + try { + return o == null ? -1.0D : Double.parseDouble(o.toString()); + } catch (Exception e) { + return -1.0D; + } + } + + /** + * All variable keys this is holding + * + * @return Set of all variable names. + */ + public Set getVarKeyList() { + + return variables.keySet(); + } + + /** + * verify is a var exists + * + * @param name the key name of the var + * @return true if that var exists + */ + public boolean hasVar(String name) { + + return variables.containsKey(name); + } + + /** + * Returns the quantity of vars this is holding + * + * @return the number of vars + */ + public int getSize() { + + return variables.size(); + } + + /** + * Remove a var from the list + * + * @param name + */ + public void removeVar(String name) { + + try { + variables.remove(name); + } catch (Exception e) { + } + owner.flagAsChanged(); + } + + public static Object parseVariableValue(String value) { + + try { + Integer i = Integer.parseInt(value); + return i; + } catch (NumberFormatException e) { + } + try { + Double d = Double.parseDouble(value); + return d; + } catch (NumberFormatException e) { + } + if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) { + return true; + } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) { + return false; + } + return value; + + } + + public void clearVars() { + + variables.clear(); + owner.flagAsChanged(); + } + + /** + * @return the owner + */ + public DataUnit getOwner() { + + return owner; + } + + public boolean isEmpty() { + + return variables.isEmpty(); + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java index 5d681013e..eaaaace74 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java @@ -6,8 +6,6 @@ import java.util.Map; import org.anjocaido.groupmanager.data.Group; - - /** * This container holds all Groups loaded from the relevant groupsFile. * @@ -31,9 +29,11 @@ public class GroupsDataHolder { * Constructor */ protected GroupsDataHolder() { + } - + public void setDataSource(WorldDataHolder dataSource) { + this.dataSource = dataSource; //push this data source to the users, so they pull the correct groups data. for (Group group : groups.values()) @@ -44,6 +44,7 @@ public class GroupsDataHolder { * @return the defaultGroup */ public Group getDefaultGroup() { + return defaultGroup; } @@ -51,6 +52,7 @@ public class GroupsDataHolder { * @param defaultGroup the defaultGroup to set */ public void setDefaultGroup(Group defaultGroup) { + this.defaultGroup = defaultGroup; } @@ -58,20 +60,23 @@ public class GroupsDataHolder { * @return the groups */ public Map getGroups() { + return groups; } - + /** * @param groups the groups to set */ public void setGroups(Map groups) { + this.groups = groups; } - + /** * @return the groupsFile */ public File getGroupsFile() { + return groupsFile; } @@ -79,6 +84,7 @@ public class GroupsDataHolder { * @param groupsFile the groupsFile to set */ public void setGroupsFile(File groupsFile) { + this.groupsFile = groupsFile; } @@ -86,6 +92,7 @@ public class GroupsDataHolder { * @return the haveGroupsChanged */ public boolean HaveGroupsChanged() { + return haveGroupsChanged; } @@ -93,6 +100,7 @@ public class GroupsDataHolder { * @param haveGroupsChanged the haveGroupsChanged to set */ public void setGroupsChanged(boolean haveGroupsChanged) { + this.haveGroupsChanged = haveGroupsChanged; } @@ -100,6 +108,7 @@ public class GroupsDataHolder { * @return the timeStampGroups */ public long getTimeStampGroups() { + return timeStampGroups; } @@ -107,6 +116,7 @@ public class GroupsDataHolder { * @param timeStampGroups the timeStampGroups to set */ public void setTimeStampGroups(long timeStampGroups) { + this.timeStampGroups = timeStampGroups; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java index b37c55e51..c8a3eb3ae 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java @@ -11,195 +11,205 @@ import java.util.Map; import org.anjocaido.groupmanager.data.User; /** - * + * * @author gabrielcouto */ public class OverloadedWorldHolder extends WorldDataHolder { - /** + /** * */ - protected Map overloadedUsers = new HashMap(); + protected Map overloadedUsers = new HashMap(); - /** - * - * @param ph - */ - public OverloadedWorldHolder(WorldDataHolder ph) { - super(ph.getName()); - this.setGroupsFile(ph.getGroupsFile()); - this.setUsersFile(ph.getUsersFile()); - //this.setDefaultGroup(ph.getDefaultGroup()); - this.groups = ph.groups; - this.users = ph.users; - } - - /** - * - * @param userName - * @return user object or a new user if none exists. - */ - @Override - public User getUser(String userName) { - //OVERLOADED CODE - String userNameLowered = userName.toLowerCase(); - if (overloadedUsers.containsKey(userNameLowered)) { - return overloadedUsers.get(userNameLowered); - } - //END CODE - if (getUsers().containsKey(userNameLowered)) { - return getUsers().get(userNameLowered); - } - User newUser = createUser(userName); - setUsersChanged(true); - return newUser; - } - - /** - * - * @param theUser - */ - @Override - public void addUser(User theUser) { - if (theUser.getDataSource() != this) { - theUser = theUser.clone(this); - } - if (theUser == null) { - return; - } - if ((theUser.getGroup() == null) || (!getGroups().containsKey(theUser.getGroupName().toLowerCase()))) { - theUser.setGroup(getDefaultGroup()); - } - //OVERLOADED CODE - if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) { - overloadedUsers.remove(theUser.getName().toLowerCase()); - overloadedUsers.put(theUser.getName().toLowerCase(), theUser); - return; - } - //END CODE - removeUser(theUser.getName()); - getUsers().put(theUser.getName().toLowerCase(), theUser); - setUsersChanged(true); - } - - /** - * - * @param userName - * @return true if removed/false if not found. - */ - @Override - public boolean removeUser(String userName) { - //OVERLOADED CODE - if (overloadedUsers.containsKey(userName.toLowerCase())) { - overloadedUsers.remove(userName.toLowerCase()); - return true; - } - //END CODE - if (getUsers().containsKey(userName.toLowerCase())) { - getUsers().remove(userName.toLowerCase()); - setUsersChanged(true); - return true; - } - return false; - } - - @Override - public boolean removeGroup(String groupName) { - if (groupName.equals(getDefaultGroup())) { - return false; - } - for (String key : getGroups().keySet()) { - if (groupName.equalsIgnoreCase(key)) { - getGroups().remove(key); - for (String userKey : getUsers().keySet()) { - User user = getUsers().get(userKey); - if (user.getGroupName().equalsIgnoreCase(key)) { - user.setGroup(getDefaultGroup()); - } - - } - //OVERLOADED CODE - for (String userKey : overloadedUsers.keySet()) { - User user = overloadedUsers.get(userKey); - if (user.getGroupName().equalsIgnoreCase(key)) { - user.setGroup(getDefaultGroup()); - } - - } - //END OVERLOAD - setGroupsChanged(true); - return true; - } - } - return false; - } - - /** - * - * @return Collection of all users - */ - @Override - public Collection getUserList() { - Collection overloadedList = new ArrayList(); - Collection normalList = getUsers().values(); - for (User u : normalList) { - if (overloadedUsers.containsKey(u.getName().toLowerCase())) { - overloadedList.add(overloadedUsers.get(u.getName().toLowerCase())); - } else { - overloadedList.add(u); - } - } - return overloadedList; - } - - /** - * - * @param userName - * @return true if user is overloaded. - */ - public boolean isOverloaded(String userName) { - return overloadedUsers.containsKey(userName.toLowerCase()); - } + /** + * + * @param ph + */ + public OverloadedWorldHolder(WorldDataHolder ph) { - /** - * - * @param userName - */ - public void overloadUser(String userName) { - if (!isOverloaded(userName)) { - User theUser = getUser(userName); - theUser = theUser.clone(); - if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) { - overloadedUsers.remove(theUser.getName().toLowerCase()); - } - overloadedUsers.put(theUser.getName().toLowerCase(), theUser); - } - } - - /** - * - * @param userName - */ - public void removeOverload(String userName) { - overloadedUsers.remove(userName.toLowerCase()); - } - - /** - * Gets the user in normal state. Surpassing the overload state. - * It doesn't affect permissions. But it enables plugins change the - * actual user permissions even in overload mode. - * - * @param userName - * @return user object - */ - public User surpassOverload(String userName) { - if (!isOverloaded(userName)) { - return getUser(userName); - } - if (getUsers().containsKey(userName.toLowerCase())) { - return getUsers().get(userName.toLowerCase()); - } - User newUser = createUser(userName); - return newUser; - } + super(ph.getName()); + this.setGroupsFile(ph.getGroupsFile()); + this.setUsersFile(ph.getUsersFile()); + //this.setDefaultGroup(ph.getDefaultGroup()); + this.groups = ph.groups; + this.users = ph.users; + } + + /** + * + * @param userName + * @return user object or a new user if none exists. + */ + @Override + public User getUser(String userName) { + + //OVERLOADED CODE + String userNameLowered = userName.toLowerCase(); + if (overloadedUsers.containsKey(userNameLowered)) { + return overloadedUsers.get(userNameLowered); + } + //END CODE + if (getUsers().containsKey(userNameLowered)) { + return getUsers().get(userNameLowered); + } + User newUser = createUser(userName); + setUsersChanged(true); + return newUser; + } + + /** + * + * @param theUser + */ + @Override + public void addUser(User theUser) { + + if (theUser.getDataSource() != this) { + theUser = theUser.clone(this); + } + if (theUser == null) { + return; + } + if ((theUser.getGroup() == null) || (!getGroups().containsKey(theUser.getGroupName().toLowerCase()))) { + theUser.setGroup(getDefaultGroup()); + } + //OVERLOADED CODE + if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) { + overloadedUsers.remove(theUser.getName().toLowerCase()); + overloadedUsers.put(theUser.getName().toLowerCase(), theUser); + return; + } + //END CODE + removeUser(theUser.getName()); + getUsers().put(theUser.getName().toLowerCase(), theUser); + setUsersChanged(true); + } + + /** + * + * @param userName + * @return true if removed/false if not found. + */ + @Override + public boolean removeUser(String userName) { + + //OVERLOADED CODE + if (overloadedUsers.containsKey(userName.toLowerCase())) { + overloadedUsers.remove(userName.toLowerCase()); + return true; + } + //END CODE + if (getUsers().containsKey(userName.toLowerCase())) { + getUsers().remove(userName.toLowerCase()); + setUsersChanged(true); + return true; + } + return false; + } + + @Override + public boolean removeGroup(String groupName) { + + if (groupName.equals(getDefaultGroup())) { + return false; + } + for (String key : getGroups().keySet()) { + if (groupName.equalsIgnoreCase(key)) { + getGroups().remove(key); + for (String userKey : getUsers().keySet()) { + User user = getUsers().get(userKey); + if (user.getGroupName().equalsIgnoreCase(key)) { + user.setGroup(getDefaultGroup()); + } + + } + //OVERLOADED CODE + for (String userKey : overloadedUsers.keySet()) { + User user = overloadedUsers.get(userKey); + if (user.getGroupName().equalsIgnoreCase(key)) { + user.setGroup(getDefaultGroup()); + } + + } + //END OVERLOAD + setGroupsChanged(true); + return true; + } + } + return false; + } + + /** + * + * @return Collection of all users + */ + @Override + public Collection getUserList() { + + Collection overloadedList = new ArrayList(); + Collection normalList = getUsers().values(); + for (User u : normalList) { + if (overloadedUsers.containsKey(u.getName().toLowerCase())) { + overloadedList.add(overloadedUsers.get(u.getName().toLowerCase())); + } else { + overloadedList.add(u); + } + } + return overloadedList; + } + + /** + * + * @param userName + * @return true if user is overloaded. + */ + public boolean isOverloaded(String userName) { + + return overloadedUsers.containsKey(userName.toLowerCase()); + } + + /** + * + * @param userName + */ + public void overloadUser(String userName) { + + if (!isOverloaded(userName)) { + User theUser = getUser(userName); + theUser = theUser.clone(); + if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) { + overloadedUsers.remove(theUser.getName().toLowerCase()); + } + overloadedUsers.put(theUser.getName().toLowerCase(), theUser); + } + } + + /** + * + * @param userName + */ + public void removeOverload(String userName) { + + overloadedUsers.remove(userName.toLowerCase()); + } + + /** + * Gets the user in normal state. Surpassing the overload state. + * It doesn't affect permissions. But it enables plugins change the + * actual user permissions even in overload mode. + * + * @param userName + * @return user object + */ + public User surpassOverload(String userName) { + + if (!isOverloaded(userName)) { + return getUser(userName); + } + if (getUsers().containsKey(userName.toLowerCase())) { + return getUsers().get(userName.toLowerCase()); + } + User newUser = createUser(userName); + return newUser; + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java index fa2ccaf84..665fe227d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java @@ -6,8 +6,6 @@ import java.util.Map; import org.anjocaido.groupmanager.data.User; - - /** * This container holds all Users loaded from the relevant usersFile. * @@ -30,27 +28,31 @@ public class UsersDataHolder { * Constructor */ protected UsersDataHolder() { + } - + public void setDataSource(WorldDataHolder dataSource) { + this.dataSource = dataSource; //push this data source to the users, so they pull the correct groups data. for (User user : users.values()) user.setDataSource(this.dataSource); - + } /** * @return the users */ public Map getUsers() { + return users; } - + /** * @param users the users to set */ public void setUsers(Map users) { + this.users = users; } @@ -58,6 +60,7 @@ public class UsersDataHolder { * @return the usersFile */ public File getUsersFile() { + return usersFile; } @@ -65,6 +68,7 @@ public class UsersDataHolder { * @param usersFile the usersFile to set */ public void setUsersFile(File usersFile) { + this.usersFile = usersFile; } @@ -72,6 +76,7 @@ public class UsersDataHolder { * @return the haveUsersChanged */ public boolean HaveUsersChanged() { + return haveUsersChanged; } @@ -79,6 +84,7 @@ public class UsersDataHolder { * @param haveUsersChanged the haveUsersChanged to set */ public void setUsersChanged(boolean haveUsersChanged) { + this.haveUsersChanged = haveUsersChanged; } @@ -86,6 +92,7 @@ public class UsersDataHolder { * @return the timeStampUsers */ public long getTimeStampUsers() { + return timeStampUsers; } @@ -93,6 +100,7 @@ public class UsersDataHolder { * @param timeStampUsers the timeStampUsers to set */ public void setTimeStampUsers(long timeStampUsers) { + this.timeStampUsers = timeStampUsers; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index ce6db2b9b..fefc698f9 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -45,339 +45,371 @@ import org.yaml.snakeyaml.reader.UnicodeReader; */ public class WorldDataHolder { - /** - * World name - */ - protected String name; - /** - * The actual groups holder - */ - protected GroupsDataHolder groups = new GroupsDataHolder(); /** - * The actual users holder - */ - protected UsersDataHolder users = new UsersDataHolder(); - /** + * World name + */ + protected String name; + /** + * The actual groups holder + */ + protected GroupsDataHolder groups = new GroupsDataHolder(); + /** + * The actual users holder + */ + protected UsersDataHolder users = new UsersDataHolder(); + /** * */ - protected AnjoPermissionsHandler permissionsHandler; + protected AnjoPermissionsHandler permissionsHandler; - /** - * Prevent direct instantiation - * @param worldName - */ - public WorldDataHolder(String worldName) { - name = worldName; - } - - /** - * The main constructor for a new WorldDataHolder - * @param worldName - * @param groups - * @param users - */ - public WorldDataHolder(String worldName, GroupsDataHolder groups, UsersDataHolder users) { - this.name = worldName; - this.groups = groups; - this.users = users; - - //this.defaultGroup = defaultGroup; - } - - /** - * update the dataSource to point to this object. - * - * This should be called whenever a set of world data is fetched. - */ - public void updateDataSource() { - this.groups.setDataSource(this); - this.users.setDataSource(this); - } - - /** - * Search for a user. If it doesn't exist, create a new one with - * default group. - * - * @param userName the name of the user - * @return class that manage that user permission - */ - public User getUser(String userName) { - if (getUsers().containsKey(userName.toLowerCase())) { - return getUsers().get(userName.toLowerCase()); - } - User newUser = createUser(userName); - return newUser; - } - - /** - * Add a user to the list. If it already exists, overwrite the old. - * @param theUser the user you want to add to the permission list - */ - public void addUser(User theUser) { - if (theUser.getDataSource() != this) { - theUser = theUser.clone(this); - } - if (theUser == null) { - return; - } - if ((theUser.getGroup() == null)) { - theUser.setGroup(groups.getDefaultGroup()); - } - removeUser(theUser.getName()); - getUsers().put(theUser.getName().toLowerCase(), theUser); - setUsersChanged(true); - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(theUser, Action.USER_ADDED); - } - - /** - * Removes the user from the list. (he might become a default user) - * @param userName the username from the user to remove - * @return true if it had something to remove - */ - public boolean removeUser(String userName) { - if (getUsers().containsKey(userName.toLowerCase())) { - getUsers().remove(userName.toLowerCase()); - setUsersChanged(true); - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED); - return true; - } - return false; - } - - /** - * - * @param userName - * @return true if we have data for this player. - */ - public boolean isUserDeclared(String userName) { - return getUsers().containsKey(userName.toLowerCase()); - } + * Prevent direct instantiation + * + * @param worldName + */ + public WorldDataHolder(String worldName) { - /** - * Change the default group of the file. - * @param group the group you want make default. - */ - public void setDefaultGroup(Group group) { - if (!getGroups().containsKey(group.getName().toLowerCase()) || (group.getDataSource() != this)) { - addGroup(group); - } - groups.setDefaultGroup(getGroup(group.getName())); - setGroupsChanged(true); - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED); - } - - /** - * Returns the default group of the file - * @return the default group - */ - public Group getDefaultGroup() { - return groups.getDefaultGroup(); - } - - /** - * Returns a group of the given name - * @param groupName the name of the group - * @return a group if it is found. null if not found. - */ - public Group getGroup(String groupName) { - if (groupName.toLowerCase().startsWith("g:")) - return GroupManager.getGlobalGroups().getGroup(groupName); - else - return getGroups().get(groupName.toLowerCase()); - } - - /** - * Check if a group exists. - * Its the same of getGroup, but check if it is null. - * @param groupName the name of the group - * @return true if exists. false if not. - */ - public boolean groupExists(String groupName) { - if (groupName.toLowerCase().startsWith("g:")) - return GroupManager.getGlobalGroups().hasGroup(groupName); - else - return getGroups().containsKey(groupName.toLowerCase()); - } - - /** - * Add a group to the list - * @param groupToAdd - */ - public void addGroup(Group groupToAdd) { - if (groupToAdd.getName().toLowerCase().startsWith("g:")) { - GroupManager.getGlobalGroups().addGroup(groupToAdd); - GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); - return; - } - - if (groupToAdd.getDataSource() != this) { - groupToAdd = groupToAdd.clone(this); - } - removeGroup(groupToAdd.getName()); - getGroups().put(groupToAdd.getName().toLowerCase(), groupToAdd); - setGroupsChanged(true); - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); - } - - /** - * Remove the group from the list - * @param groupName - * @return true if had something to remove. false the group was default or non-existant - */ - public boolean removeGroup(String groupName) { - if (groupName.toLowerCase().startsWith("g:")) { - return GroupManager.getGlobalGroups().removeGroup(groupName); - } - - if (getDefaultGroup() != null && groupName.equalsIgnoreCase(getDefaultGroup().getName())) { - return false; - } - if (getGroups().containsKey(groupName.toLowerCase())) { - getGroups().remove(groupName.toLowerCase()); - setGroupsChanged(true); - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED); - return true; - } - return false; - - } - - /** - * Creates a new User with the given name - * and adds it to this holder. - * @param userName the username you want - * @return null if user already exists. or new User - */ - public User createUser(String userName) { - if (getUsers().containsKey(userName.toLowerCase())) { - return null; - } - User newUser = new User(this, userName); - newUser.setGroup(groups.getDefaultGroup(), false); - addUser(newUser); - setUsersChanged(true); - return newUser; - } - - /** - * Creates a new Group with the given name - * and adds it to this holder - * @param groupName the groupname you want - * @return null if group already exists. or new Group - */ - public Group createGroup(String groupName) { - if (groupName.toLowerCase().startsWith("g:")) { - Group newGroup = new Group(groupName); - return GroupManager.getGlobalGroups().newGroup(newGroup); - } - - if (getGroups().containsKey(groupName.toLowerCase())) { - return null; - } - - Group newGroup = new Group(this, groupName); - addGroup(newGroup); - setGroupsChanged(true); - return newGroup; - } - - /** - * - * @return a collection of the groups - */ - public Collection getGroupList() { - return getGroups().values(); - } + name = worldName; + } - /** - * - * @return a collection of the users - */ - public Collection getUserList() { - return getUsers().values(); - } + /** + * The main constructor for a new WorldDataHolder + * + * @param worldName + * @param groups + * @param users + */ + public WorldDataHolder(String worldName, GroupsDataHolder groups, UsersDataHolder users) { - /** - * reads the file again - */ - public void reload() { - try { - reloadGroups(); - reloadUsers(); - } catch (Exception ex) { - Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex); - } - } - - /** - * Refresh Group data from file - */ - public void reloadGroups() { - GroupManager.setLoaded(false); - try { - // temporary holder in case the load fails. - WorldDataHolder ph = new WorldDataHolder(this.getName()); - - loadGroups(ph, getGroupsFile()); - // transfer new data - resetGroups(); - for (Group tempGroup : ph.getGroupList()) { - tempGroup.clone(this); - } - this.setDefaultGroup(getGroup(ph.getDefaultGroup().getName())); - this.removeGroupsChangedFlag(); - this.setTimeStampGroups(getGroupsFile().lastModified()); - - ph = null; - } catch (Exception ex) { - Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); - } - GroupManager.setLoaded(true); - GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); - } - - /** - * Refresh Users data from file - */ - public void reloadUsers() { - GroupManager.setLoaded(false); - try { - // temporary holder in case the load fails. - WorldDataHolder ph = new WorldDataHolder(this.getName()); - // copy groups for reference - for (Group tempGroup : this.getGroupList()) { - tempGroup.clone(ph); - } - // setup the default group before loading user data. - ph.setDefaultGroup(ph.getGroup(getDefaultGroup().getName())); - loadUsers(ph, getUsersFile()); - // transfer new data - resetUsers(); - for (User tempUser : ph.getUserList()) { - tempUser.clone(this); - } - this.removeUsersChangedFlag(); - this.setTimeStampUsers(getUsersFile().lastModified()); - - ph = null; - } catch (Exception ex) { - Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); - } - GroupManager.setLoaded(true); - GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); - } - - public void loadGroups(File groupsFile) { - - GroupManager.setLoaded(false); - try { - setGroupsFile(groupsFile); + this.name = worldName; + this.groups = groups; + this.users = users; + + // this.defaultGroup = defaultGroup; + } + + /** + * update the dataSource to point to this object. + * + * This should be called whenever a set of world data is fetched. + */ + public void updateDataSource() { + + this.groups.setDataSource(this); + this.users.setDataSource(this); + } + + /** + * Search for a user. If it doesn't exist, create a new one with + * default group. + * + * @param userName the name of the user + * @return class that manage that user permission + */ + public User getUser(String userName) { + + if (getUsers().containsKey(userName.toLowerCase())) { + return getUsers().get(userName.toLowerCase()); + } + User newUser = createUser(userName); + return newUser; + } + + /** + * Add a user to the list. If it already exists, overwrite the old. + * + * @param theUser the user you want to add to the permission list + */ + public void addUser(User theUser) { + + if (theUser.getDataSource() != this) { + theUser = theUser.clone(this); + } + if (theUser == null) { + return; + } + if ((theUser.getGroup() == null)) { + theUser.setGroup(groups.getDefaultGroup()); + } + removeUser(theUser.getName()); + getUsers().put(theUser.getName().toLowerCase(), theUser); + setUsersChanged(true); + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(theUser, Action.USER_ADDED); + } + + /** + * Removes the user from the list. (he might become a default user) + * + * @param userName the username from the user to remove + * @return true if it had something to remove + */ + public boolean removeUser(String userName) { + + if (getUsers().containsKey(userName.toLowerCase())) { + getUsers().remove(userName.toLowerCase()); + setUsersChanged(true); + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED); + return true; + } + return false; + } + + /** + * + * @param userName + * @return true if we have data for this player. + */ + public boolean isUserDeclared(String userName) { + + return getUsers().containsKey(userName.toLowerCase()); + } + + /** + * Change the default group of the file. + * + * @param group the group you want make default. + */ + public void setDefaultGroup(Group group) { + + if (!getGroups().containsKey(group.getName().toLowerCase()) || (group.getDataSource() != this)) { + addGroup(group); + } + groups.setDefaultGroup(getGroup(group.getName())); + setGroupsChanged(true); + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED); + } + + /** + * Returns the default group of the file + * + * @return the default group + */ + public Group getDefaultGroup() { + + return groups.getDefaultGroup(); + } + + /** + * Returns a group of the given name + * + * @param groupName the name of the group + * @return a group if it is found. null if not found. + */ + public Group getGroup(String groupName) { + + if (groupName.toLowerCase().startsWith("g:")) + return GroupManager.getGlobalGroups().getGroup(groupName); + else + return getGroups().get(groupName.toLowerCase()); + } + + /** + * Check if a group exists. + * Its the same of getGroup, but check if it is null. + * + * @param groupName the name of the group + * @return true if exists. false if not. + */ + public boolean groupExists(String groupName) { + + if (groupName.toLowerCase().startsWith("g:")) + return GroupManager.getGlobalGroups().hasGroup(groupName); + else + return getGroups().containsKey(groupName.toLowerCase()); + } + + /** + * Add a group to the list + * + * @param groupToAdd + */ + public void addGroup(Group groupToAdd) { + + if (groupToAdd.getName().toLowerCase().startsWith("g:")) { + GroupManager.getGlobalGroups().addGroup(groupToAdd); + GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); + return; + } + + if (groupToAdd.getDataSource() != this) { + groupToAdd = groupToAdd.clone(this); + } + removeGroup(groupToAdd.getName()); + getGroups().put(groupToAdd.getName().toLowerCase(), groupToAdd); + setGroupsChanged(true); + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); + } + + /** + * Remove the group from the list + * + * @param groupName + * @return true if had something to remove. false the group was default or + * non-existant + */ + public boolean removeGroup(String groupName) { + + if (groupName.toLowerCase().startsWith("g:")) { + return GroupManager.getGlobalGroups().removeGroup(groupName); + } + + if (getDefaultGroup() != null && groupName.equalsIgnoreCase(getDefaultGroup().getName())) { + return false; + } + if (getGroups().containsKey(groupName.toLowerCase())) { + getGroups().remove(groupName.toLowerCase()); + setGroupsChanged(true); + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED); + return true; + } + return false; + + } + + /** + * Creates a new User with the given name + * and adds it to this holder. + * + * @param userName the username you want + * @return null if user already exists. or new User + */ + public User createUser(String userName) { + + if (getUsers().containsKey(userName.toLowerCase())) { + return null; + } + User newUser = new User(this, userName); + newUser.setGroup(groups.getDefaultGroup(), false); + addUser(newUser); + setUsersChanged(true); + return newUser; + } + + /** + * Creates a new Group with the given name + * and adds it to this holder + * + * @param groupName the groupname you want + * @return null if group already exists. or new Group + */ + public Group createGroup(String groupName) { + + if (groupName.toLowerCase().startsWith("g:")) { + Group newGroup = new Group(groupName); + return GroupManager.getGlobalGroups().newGroup(newGroup); + } + + if (getGroups().containsKey(groupName.toLowerCase())) { + return null; + } + + Group newGroup = new Group(this, groupName); + addGroup(newGroup); + setGroupsChanged(true); + return newGroup; + } + + /** + * + * @return a collection of the groups + */ + public Collection getGroupList() { + + return getGroups().values(); + } + + /** + * + * @return a collection of the users + */ + public Collection getUserList() { + + return getUsers().values(); + } + + /** + * reads the file again + */ + public void reload() { + + try { + reloadGroups(); + reloadUsers(); + } catch (Exception ex) { + Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Refresh Group data from file + */ + public void reloadGroups() { + + GroupManager.setLoaded(false); + try { + // temporary holder in case the load fails. + WorldDataHolder ph = new WorldDataHolder(this.getName()); + + loadGroups(ph, getGroupsFile()); + // transfer new data + resetGroups(); + for (Group tempGroup : ph.getGroupList()) { + tempGroup.clone(this); + } + this.setDefaultGroup(getGroup(ph.getDefaultGroup().getName())); + this.removeGroupsChangedFlag(); + this.setTimeStampGroups(getGroupsFile().lastModified()); + + ph = null; + } catch (Exception ex) { + Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); + } + GroupManager.setLoaded(true); + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); + } + + /** + * Refresh Users data from file + */ + public void reloadUsers() { + + GroupManager.setLoaded(false); + try { + // temporary holder in case the load fails. + WorldDataHolder ph = new WorldDataHolder(this.getName()); + // copy groups for reference + for (Group tempGroup : this.getGroupList()) { + tempGroup.clone(ph); + } + // setup the default group before loading user data. + ph.setDefaultGroup(ph.getGroup(getDefaultGroup().getName())); + loadUsers(ph, getUsersFile()); + // transfer new data + resetUsers(); + for (User tempUser : ph.getUserList()) { + tempUser.clone(this); + } + this.removeUsersChangedFlag(); + this.setTimeStampUsers(getUsersFile().lastModified()); + + ph = null; + } catch (Exception ex) { + Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); + } + GroupManager.setLoaded(true); + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); + } + + public void loadGroups(File groupsFile) { + + GroupManager.setLoaded(false); + try { + setGroupsFile(groupsFile); loadGroups(this, groupsFile); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -387,14 +419,14 @@ public class WorldDataHolder { throw new IllegalArgumentException("Error access the groups file!\n" + groupsFile.getPath()); } - GroupManager.setLoaded(true); - } - - public void loadUsers(File usersFile) { + GroupManager.setLoaded(true); + } + + public void loadUsers(File usersFile) { - GroupManager.setLoaded(false); - try { - setUsersFile(usersFile); + GroupManager.setLoaded(false); + try { + setUsersFile(usersFile); loadUsers(this, usersFile); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -404,843 +436,888 @@ public class WorldDataHolder { throw new IllegalArgumentException("Error access the users file!\n" + usersFile.getPath()); } - GroupManager.setLoaded(true); - } - /** - * Returns a NEW data holder containing data read from the files - * - * @param worldName - * @param groupsFile - * @param usersFile - * - * @throws FileNotFoundException - * @throws IOException - */ - public static WorldDataHolder load(String worldName, File groupsFile, File usersFile) throws FileNotFoundException, IOException { - WorldDataHolder ph = new WorldDataHolder(worldName); - - GroupManager.setLoaded(false); - if (groupsFile != null) loadGroups(ph, groupsFile); - if (usersFile != null) loadUsers(ph, usersFile); - GroupManager.setLoaded(true); - - return ph; - } - - /** - * Updates the WorldDataHolder from the Groups file - * - * @param ph - * @param groupsFile - * - * @throws FileNotFoundException - * @throws IOException - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - protected static void loadGroups(WorldDataHolder ph, File groupsFile) throws FileNotFoundException, IOException { - - // READ GROUPS FILE - - Yaml yamlGroups = new Yaml(new SafeConstructor()); - Map groupsRootDataNode; - - if (!groupsFile.exists()) { - throw new IllegalArgumentException("The file which should contain groups does not exist!\n" + groupsFile.getPath()); - } - FileInputStream groupsInputStream = new FileInputStream(groupsFile); - try { - groupsRootDataNode = (Map) yamlGroups.load(new UnicodeReader(groupsInputStream)); - if (groupsRootDataNode == null) { - throw new NullPointerException(); - } - } catch (Exception ex) { - throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + groupsFile.getPath(), ex); - } finally { - groupsInputStream.close(); - } - - // PROCESS GROUPS FILE - - Map> inheritance = new HashMap>(); - Map allGroupsNode = null; - - /* - * Fetch all groups under the 'groups' entry. - */ - try { - allGroupsNode = (Map) groupsRootDataNode.get("groups"); - } catch (Exception ex) { - throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex); - } - - - Iterator groupItr = allGroupsNode.keySet().iterator(); - String groupKey; - Integer groupCount = 0; - - /* - * loop each group entry - * and process it's data. - */ - while (groupItr.hasNext()) { - - try { - groupCount++; - // Attempt to fetch the next group name. - groupKey = groupItr.next(); - } catch (Exception ex) { + GroupManager.setLoaded(true); + } + + /** + * Returns a NEW data holder containing data read from the files + * + * @param worldName + * @param groupsFile + * @param usersFile + * + * @throws FileNotFoundException + * @throws IOException + */ + public static WorldDataHolder load(String worldName, File groupsFile, File usersFile) throws FileNotFoundException, IOException { + + WorldDataHolder ph = new WorldDataHolder(worldName); + + GroupManager.setLoaded(false); + if (groupsFile != null) + loadGroups(ph, groupsFile); + if (usersFile != null) + loadUsers(ph, usersFile); + GroupManager.setLoaded(true); + + return ph; + } + + /** + * Updates the WorldDataHolder from the Groups file + * + * @param ph + * @param groupsFile + * + * @throws FileNotFoundException + * @throws IOException + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected static void loadGroups(WorldDataHolder ph, File groupsFile) throws FileNotFoundException, IOException { + + // READ GROUPS FILE + + Yaml yamlGroups = new Yaml(new SafeConstructor()); + Map groupsRootDataNode; + + if (!groupsFile.exists()) { + throw new IllegalArgumentException("The file which should contain groups does not exist!\n" + groupsFile.getPath()); + } + FileInputStream groupsInputStream = new FileInputStream(groupsFile); + try { + groupsRootDataNode = (Map) yamlGroups.load(new UnicodeReader(groupsInputStream)); + if (groupsRootDataNode == null) { + throw new NullPointerException(); + } + } catch (Exception ex) { + throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + groupsFile.getPath(), ex); + } finally { + groupsInputStream.close(); + } + + // PROCESS GROUPS FILE + + Map> inheritance = new HashMap>(); + Map allGroupsNode = null; + + /* + * Fetch all groups under the 'groups' entry. + */ + try { + allGroupsNode = (Map) groupsRootDataNode.get("groups"); + } catch (Exception ex) { + throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex); + } + + Iterator groupItr = allGroupsNode.keySet().iterator(); + String groupKey; + Integer groupCount = 0; + + /* + * loop each group entry + * and process it's data. + */ + while (groupItr.hasNext()) { + + try { + groupCount++; + // Attempt to fetch the next group name. + groupKey = groupItr.next(); + } catch (Exception ex) { throw new IllegalArgumentException("Invalid group name for group entry (" + groupCount + ") in file: " + groupsFile.getPath(), ex); } - - /* - * Fetch this groups child nodes - */ - Map thisGroupNode = null; - - try { - thisGroupNode = (Map) allGroupsNode.get(groupKey); - } catch (Exception ex) { + + /* + * Fetch this groups child nodes + */ + Map thisGroupNode = null; + + try { + thisGroupNode = (Map) allGroupsNode.get(groupKey); + } catch (Exception ex) { throw new IllegalArgumentException("Invalid child nodes for group '" + groupKey + "' in file: " + groupsFile.getPath(), ex); } - - /* - * Create a new group with this name - * in the assigned data source. - */ - Group thisGrp = ph.createGroup(groupKey); - - if (thisGrp == null) { - throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); - } - - // DEFAULT NODE - - Object nodeData = null; - try { - nodeData = thisGroupNode.get("default"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'permissions' for group: " + groupKey + " in file: " + groupsFile.getPath()); - } - - if (nodeData == null) { - /* - * If no 'default' node is found do nothing. - */ - } else if ((Boolean.parseBoolean(nodeData.toString()))) { - /* - * Set this as the default group. - * Warn if some other group has already claimed that position. - */ - if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group '" + thisGrp.getName() + "' is claiming to be default where '" + ph.getDefaultGroup().getName() + "' already was."); - GroupManager.logger.warning("Overriding first default request in file: " + groupsFile.getPath()); - } - ph.setDefaultGroup(thisGrp); - } - - // PERMISSIONS NODE - - nodeData = null; - try { - nodeData = thisGroupNode.get("permissions"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'permissions' for '" + groupKey + "' in file: " + groupsFile.getPath()); - } - - if (nodeData == null) { - /* - * If no permissions node is found, or it's empty - * do nothing. - */ - } else { - /* - * There is a permission list Which seems to hold some data - */ - if (nodeData instanceof List) { - /* - * Check each entry and add it as a new permission. - */ - try { - for (Object o : ((List) nodeData)) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!o.toString().isEmpty()) - thisGrp.addPermission(o.toString()); - - } catch (NullPointerException ex) { - // Ignore this entry as it's null. It can be safely dropped - } - } - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid formatting found in 'permissions' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); - } - - - } else if (nodeData instanceof String) { - /* - * Only add this permission if it's not empty. - */ - if (!nodeData.toString().isEmpty()) - thisGrp.addPermission((String) nodeData); - - } else { - throw new IllegalArgumentException("Unknown type of 'permissions' node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - /* - * Sort all permissions so they are in the correct order for checking. - */ - thisGrp.sortPermissions(); - } - - // INFO NODE - - nodeData = null; - try { - nodeData = thisGroupNode.get("info"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'info' section for group: " + groupKey + " in file: " + groupsFile.getPath()); - } - - if (nodeData == null) { - /* - * No info section was found, so leave all variables as defaults. - */ - GroupManager.logger.warning("The group '" + thisGrp.getName() + "' has no 'info' section!"); - GroupManager.logger.warning("Using default values: " + groupsFile.getPath()); - - } else if (nodeData instanceof Map) { - try { - if (nodeData != null) { - thisGrp.setVariables((Map) nodeData); - } - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid formatting found in 'info' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); - } - - } else - throw new IllegalArgumentException("Unknown entry found in 'info' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - - // INHERITANCE NODE - - nodeData = null; - try { - nodeData = thisGroupNode.get("inheritance"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'inheritance' section for group: " + groupKey + " in file: " + groupsFile.getPath()); - } - - if (nodeData == null || nodeData instanceof List) { - if (nodeData == null) { - /* - * If no inheritance node is found, or it's empty - * do nothing. - */ - } else if (nodeData instanceof List) { - - try { - for (String grp : (List) nodeData) { - if (inheritance.get(groupKey) == null) { - inheritance.put(groupKey, new ArrayList()); - } - inheritance.get(groupKey).add(grp); - } - - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid formatting found in 'inheritance' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); - } - - } - }else - throw new IllegalArgumentException("Unknown entry found in 'inheritance' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - - // END GROUP - - } - - if (ph.getDefaultGroup() == null) { - throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath()); - } - - /* - * Build the inheritance map and recored any errors - */ - for (String group : inheritance.keySet()) { - List inheritedList = inheritance.get(group); - Group thisGroup = ph.getGroup(group); - if (thisGroup != null) - for (String inheritedKey : inheritedList) { - if (inheritedKey != null) { - Group inheritedGroup = ph.getGroup(inheritedKey); - if (inheritedGroup != null) { - thisGroup.addInherits(inheritedGroup); - } else - GroupManager.logger.warning("Inherited group '" + inheritedKey + "' not found for group " + thisGroup.getName() + ". Ignoring entry in file: " + groupsFile.getPath()); - } - } - } - - ph.removeGroupsChangedFlag(); - // Update the LastModified time. - ph.setGroupsFile(groupsFile); - ph.setTimeStampGroups(groupsFile.lastModified()); - - //return ph; - } - - /** - * Updates the WorldDataHolder from the Users file - * - * @param ph - * @param usersFile - * - * @throws FileNotFoundException - * @throws IOException - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - protected static void loadUsers(WorldDataHolder ph, File usersFile) throws FileNotFoundException, IOException { - - // READ USERS FILE - Yaml yamlUsers = new Yaml(new SafeConstructor()); - Map usersRootDataNode; - if (!usersFile.exists()) { - throw new IllegalArgumentException("The file which should contain users does not exist!\n" + usersFile.getPath()); - } - FileInputStream usersInputStream = new FileInputStream(usersFile); - try { - usersRootDataNode = (Map) yamlUsers.load(new UnicodeReader(usersInputStream)); - if (usersRootDataNode == null) { - throw new NullPointerException(); - } - } catch (Exception ex) { - throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + usersFile.getPath(), ex); - } finally { - usersInputStream.close(); - } - - // PROCESS USERS FILE - - Map allUsersNode = null; - - /* - * Fetch all child nodes under the 'users' entry. - */ - try { - allUsersNode = (Map) usersRootDataNode.get("users"); - } catch (Exception ex) { - throw new IllegalArgumentException("Your " + usersFile.getPath() + " file is invalid. See console for details.", ex); - } - - // Load users if the file is NOT empty - - if (allUsersNode != null) { - - Iterator usersItr = allUsersNode.keySet().iterator(); - String usersKey; - Integer userCount = 0; - - while (usersItr.hasNext()) { - try { - userCount++; - // Attempt to fetch the next user name. - usersKey = usersItr.next(); - } catch (Exception ex) { - throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath(), ex); - } - - Map thisUserNode = null; - try { - thisUserNode = (Map) allUsersNode.get(usersKey); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found for user: " + usersKey + " in file: " + usersFile.getPath()); - } - - User thisUser = ph.createUser(usersKey); - if (thisUser == null) { - throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); - } - - // USER PERMISSIONS NODES - - Object nodeData = null; - try { - nodeData = thisUserNode.get("permissions"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'permissions' for user: " + usersKey + " in file: " + usersFile.getPath()); - } - - if (nodeData == null) { - /* - * If no permissions node is found, or it's empty - * do nothing. - */ - } else { - if (nodeData instanceof List) { - for (Object o : ((List) nodeData)) { - /* - * Only add this permission if it's not empty - */ - if (!o.toString().isEmpty()) - thisUser.addPermission(o.toString()); - } - } else if (nodeData instanceof String) { - try { - /* - * Only add this permission if it's not empty - */ - if (!nodeData.toString().isEmpty()) - thisUser.addPermission(nodeData.toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. - } - } - thisUser.sortPermissions(); - } - - // SUBGROUPS NODES - - nodeData = null; - try { - nodeData = thisUserNode.get("subgroups"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'subgroups' for user: " + usersKey + " in file: " + usersFile.getPath()); - } - - if (nodeData == null) { - /* - * If no subgroups node is found, or it's empty - * do nothing. - */ - } else if (nodeData instanceof List) { - for (Object o : ((List) nodeData)) { - Group subGrp = ph.getGroup(o.toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup '" + o.toString() + "' not found for user: " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - } else if (nodeData instanceof String) { - Group subGrp = ph.getGroup(nodeData.toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup '" + nodeData.toString() + "' not found for user: " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - - - //USER INFO NODE - - nodeData = null; - try { - nodeData = thisUserNode.get("info"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'info' section for user: " + usersKey + " in file: " + usersFile.getPath()); - } - - if (nodeData == null) { - /* - * If no info node is found, or it's empty - * do nothing. - */ - } else if (nodeData instanceof Map) { - thisUser.setVariables((Map) nodeData); - - } else - throw new IllegalArgumentException("Unknown entry found in 'info' section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); - - //END INFO NODE - - - // PRIMARY GROUP - - nodeData = null; - try { - nodeData = thisUserNode.get("group"); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in 'group' section for user: " + usersKey + " in file: " + usersFile.getPath()); - } - - if (nodeData != null) { - Group hisGroup = ph.getGroup(nodeData.toString()); - if (hisGroup == null) { - GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); - hisGroup = ph.getDefaultGroup(); - } - thisUser.setGroup(hisGroup); - } else { - thisUser.setGroup(ph.getDefaultGroup()); - } - } - } - - ph.removeUsersChangedFlag(); - // Update the LastModified time. - ph.setUsersFile(usersFile); - ph.setTimeStampUsers(usersFile.lastModified()); - } - - /** - * Write a dataHolder in a specified file - * @param ph - * @param groupsFile - */ - public static void writeGroups(WorldDataHolder ph, File groupsFile) { - Map root = new HashMap(); - - Map groupsMap = new HashMap(); - - root.put("groups", groupsMap); - for (String groupKey : ph.getGroups().keySet()) { - Group group = ph.getGroups().get(groupKey); - - Map aGroupMap = new HashMap(); - groupsMap.put(group.getName(), aGroupMap); - - if (ph.getDefaultGroup() == null) { - GroupManager.logger.severe("There is no default group for world: " + ph.getName()); - } - aGroupMap.put("default", group.equals(ph.getDefaultGroup())); - - Map infoMap = new HashMap(); - aGroupMap.put("info", infoMap); - - for (String infoKey : group.getVariables().getVarKeyList()) { - infoMap.put(infoKey, group.getVariables().getVarObject(infoKey)); - } - - aGroupMap.put("inheritance", group.getInherits()); - - aGroupMap.put("permissions", group.getPermissionList()); - } - - if (!root.isEmpty()) { - DumperOptions opt = new DumperOptions(); - opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final Yaml yaml = new Yaml(opt); - try { - OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(groupsFile), "UTF-8"); - - String newLine = System.getProperty("line.separator"); - - out.write("# Group inheritance" + newLine); - out.write("#" + newLine); - out.write("# Any inherited groups prefixed with a g: are global groups" + newLine); - out.write("# and are inherited from the GlobalGroups.yml." + newLine); - out.write("#" + newLine); - out.write("# Groups without the g: prefix are groups local to this world" + newLine); - out.write("# and are defined in the this groups.yml file." + newLine); - out.write("#" + newLine); - out.write("# Local group inheritances define your promotion tree when using 'manpromote/mandemote'" + newLine); - out.write(newLine); - - yaml.dump(root, out); - out.close(); - } catch (UnsupportedEncodingException ex) { - } catch (FileNotFoundException ex) { - } catch (IOException e) { + + /* + * Create a new group with this name + * in the assigned data source. + */ + Group thisGrp = ph.createGroup(groupKey); + + if (thisGrp == null) { + throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); } - } - - // Update the LastModified time. - ph.setGroupsFile(groupsFile); - ph.setTimeStampGroups(groupsFile.lastModified()); - ph.removeGroupsChangedFlag(); - - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); - - /*FileWriter tx = null; - try { - tx = new FileWriter(groupsFile, false); - tx.write(yaml.dump(root)); - tx.flush(); - } catch (Exception e) { - } finally { - try { - tx.close(); - } catch (IOException ex) { - } - }*/ - } - - /** - * Write a dataHolder in a specified file - * @param ph - * @param usersFile - */ - public static void writeUsers(WorldDataHolder ph, File usersFile) { - Map root = new HashMap(); - - Map usersMap = new HashMap(); - root.put("users", usersMap); - for (String userKey : ph.getUsers().keySet()) { - User user = ph.getUsers().get(userKey); - if ((user.getGroup() == null || user.getGroup().equals(ph.getDefaultGroup())) && user.getPermissionList().isEmpty() && user.getVariables().isEmpty() && user.isSubGroupsEmpty()) { - continue; - } - - Map aUserMap = new HashMap(); - usersMap.put(user.getName(), aUserMap); - - if (user.getGroup() == null) { - aUserMap.put("group", ph.getDefaultGroup().getName()); - } else { - aUserMap.put("group", user.getGroup().getName()); - } - //USER INFO NODE - BETA - if (user.getVariables().getSize() > 0) { - Map infoMap = new HashMap(); - aUserMap.put("info", infoMap); - for (String infoKey : user.getVariables().getVarKeyList()) { - infoMap.put(infoKey, user.getVariables().getVarObject(infoKey)); - } - } - //END USER INFO NODE - BETA - aUserMap.put("permissions", user.getPermissionList()); - - //SUBGROUPS NODE - BETA - aUserMap.put("subgroups", user.subGroupListStringCopy()); - //END SUBGROUPS NODE - BETA - } - - if (!root.isEmpty()) { - DumperOptions opt = new DumperOptions(); - opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final Yaml yaml = new Yaml(opt); - try { - OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(usersFile), "UTF-8"); - yaml.dump(root, out); - out.close(); - } catch (UnsupportedEncodingException ex) { - } catch (FileNotFoundException ex) { - } catch (IOException e) { + + // DEFAULT NODE + + Object nodeData = null; + try { + nodeData = thisGroupNode.get("default"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'permissions' for group: " + groupKey + " in file: " + groupsFile.getPath()); } - } - - // Update the LastModified time. - ph.setUsersFile(usersFile); - ph.setTimeStampUsers(usersFile.lastModified()); - ph.removeUsersChangedFlag(); - - if (GroupManager.isLoaded()) - GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); - - /*FileWriter tx = null; - try { - tx = new FileWriter(usersFile, false); - tx.write(yaml.dump(root)); - tx.flush(); - } catch (Exception e) { - } finally { - try { - tx.close(); - } catch (IOException ex) { - } - }*/ - } - - /** - * Don't use this. Unless you want to make this plugin to interact with original Nijikokun Permissions - * This method is supposed to make the original one reload the file, and propagate the changes made here. - * - * Prefer to use the AnjoCaido's fake version of Nijikokun's Permission plugin. - * The AnjoCaido's Permission can propagate the changes made on this plugin instantly, - * without need to save the file. - * - * @param server the server that holds the plugin - * @deprecated it is not used anymore... unless if you use original Permissions - */ - @Deprecated - public static void reloadOldPlugins(Server server) { - // Only reload permissions - PluginManager pm = server.getPluginManager(); - Plugin[] plugins = pm.getPlugins(); - for (int i = 0; i < plugins.length; i++) { - //plugins[i].getConfiguration().load(); - try { - plugins[i].getClass().getMethod("setupPermissions").invoke(plugins[i]); - } catch (Exception ex) { - continue; - } - } - } - - /** - * @return the permissionsHandler - */ - public AnjoPermissionsHandler getPermissionsHandler() { - if (permissionsHandler == null) { - permissionsHandler = new AnjoPermissionsHandler(this); - } - return permissionsHandler; - } - - /** + + if (nodeData == null) { + /* + * If no 'default' node is found do nothing. + */ + } else if ((Boolean.parseBoolean(nodeData.toString()))) { + /* + * Set this as the default group. + * Warn if some other group has already claimed that position. + */ + if (ph.getDefaultGroup() != null) { + GroupManager.logger.warning("The group '" + thisGrp.getName() + "' is claiming to be default where '" + ph.getDefaultGroup().getName() + "' already was."); + GroupManager.logger.warning("Overriding first default request in file: " + groupsFile.getPath()); + } + ph.setDefaultGroup(thisGrp); + } + + // PERMISSIONS NODE + + nodeData = null; + try { + nodeData = thisGroupNode.get("permissions"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'permissions' for '" + groupKey + "' in file: " + groupsFile.getPath()); + } + + if (nodeData == null) { + /* + * If no permissions node is found, or it's empty + * do nothing. + */ + } else { + /* + * There is a permission list Which seems to hold some data + */ + if (nodeData instanceof List) { + /* + * Check each entry and add it as a new permission. + */ + try { + for (Object o : ((List) nodeData)) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!o.toString().isEmpty()) + thisGrp.addPermission(o.toString()); + + } catch (NullPointerException ex) { + // Ignore this entry as it's null. It can be + // safely dropped + } + } + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in 'permissions' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + } else if (nodeData instanceof String) { + /* + * Only add this permission if it's not empty. + */ + if (!nodeData.toString().isEmpty()) + thisGrp.addPermission((String) nodeData); + + } else { + throw new IllegalArgumentException("Unknown type of 'permissions' node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + /* + * Sort all permissions so they are in the correct order for + * checking. + */ + thisGrp.sortPermissions(); + } + + // INFO NODE + + nodeData = null; + try { + nodeData = thisGroupNode.get("info"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'info' section for group: " + groupKey + " in file: " + groupsFile.getPath()); + } + + if (nodeData == null) { + /* + * No info section was found, so leave all variables as + * defaults. + */ + GroupManager.logger.warning("The group '" + thisGrp.getName() + "' has no 'info' section!"); + GroupManager.logger.warning("Using default values: " + groupsFile.getPath()); + + } else if (nodeData instanceof Map) { + try { + if (nodeData != null) { + thisGrp.setVariables((Map) nodeData); + } + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in 'info' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + } else + throw new IllegalArgumentException("Unknown entry found in 'info' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + + // INHERITANCE NODE + + nodeData = null; + try { + nodeData = thisGroupNode.get("inheritance"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'inheritance' section for group: " + groupKey + " in file: " + groupsFile.getPath()); + } + + if (nodeData == null || nodeData instanceof List) { + if (nodeData == null) { + /* + * If no inheritance node is found, or it's empty + * do nothing. + */ + } else if (nodeData instanceof List) { + + try { + for (String grp : (List) nodeData) { + if (inheritance.get(groupKey) == null) { + inheritance.put(groupKey, new ArrayList()); + } + inheritance.get(groupKey).add(grp); + } + + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in 'inheritance' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + } + } else + throw new IllegalArgumentException("Unknown entry found in 'inheritance' section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + + // END GROUP + + } + + if (ph.getDefaultGroup() == null) { + throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath()); + } + + /* + * Build the inheritance map and recored any errors + */ + for (String group : inheritance.keySet()) { + List inheritedList = inheritance.get(group); + Group thisGroup = ph.getGroup(group); + if (thisGroup != null) + for (String inheritedKey : inheritedList) { + if (inheritedKey != null) { + Group inheritedGroup = ph.getGroup(inheritedKey); + if (inheritedGroup != null) { + thisGroup.addInherits(inheritedGroup); + } else + GroupManager.logger.warning("Inherited group '" + inheritedKey + "' not found for group " + thisGroup.getName() + ". Ignoring entry in file: " + groupsFile.getPath()); + } + } + } + + ph.removeGroupsChangedFlag(); + // Update the LastModified time. + ph.setGroupsFile(groupsFile); + ph.setTimeStampGroups(groupsFile.lastModified()); + + // return ph; + } + + /** + * Updates the WorldDataHolder from the Users file + * + * @param ph + * @param usersFile + * + * @throws FileNotFoundException + * @throws IOException + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected static void loadUsers(WorldDataHolder ph, File usersFile) throws FileNotFoundException, IOException { + + // READ USERS FILE + Yaml yamlUsers = new Yaml(new SafeConstructor()); + Map usersRootDataNode; + if (!usersFile.exists()) { + throw new IllegalArgumentException("The file which should contain users does not exist!\n" + usersFile.getPath()); + } + FileInputStream usersInputStream = new FileInputStream(usersFile); + try { + usersRootDataNode = (Map) yamlUsers.load(new UnicodeReader(usersInputStream)); + if (usersRootDataNode == null) { + throw new NullPointerException(); + } + } catch (Exception ex) { + throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + usersFile.getPath(), ex); + } finally { + usersInputStream.close(); + } + + // PROCESS USERS FILE + + Map allUsersNode = null; + + /* + * Fetch all child nodes under the 'users' entry. + */ + try { + allUsersNode = (Map) usersRootDataNode.get("users"); + } catch (Exception ex) { + throw new IllegalArgumentException("Your " + usersFile.getPath() + " file is invalid. See console for details.", ex); + } + + // Load users if the file is NOT empty + + if (allUsersNode != null) { + + Iterator usersItr = allUsersNode.keySet().iterator(); + String usersKey; + Integer userCount = 0; + + while (usersItr.hasNext()) { + try { + userCount++; + // Attempt to fetch the next user name. + usersKey = usersItr.next(); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath(), ex); + } + + Map thisUserNode = null; + try { + thisUserNode = (Map) allUsersNode.get(usersKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + User thisUser = ph.createUser(usersKey); + if (thisUser == null) { + throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); + } + + // USER PERMISSIONS NODES + + Object nodeData = null; + try { + nodeData = thisUserNode.get("permissions"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'permissions' for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData == null) { + /* + * If no permissions node is found, or it's empty + * do nothing. + */ + } else { + if (nodeData instanceof List) { + for (Object o : ((List) nodeData)) { + /* + * Only add this permission if it's not empty + */ + if (!o.toString().isEmpty()) + thisUser.addPermission(o.toString()); + } + } else if (nodeData instanceof String) { + try { + /* + * Only add this permission if it's not empty + */ + if (!nodeData.toString().isEmpty()) + thisUser.addPermission(nodeData.toString()); + } catch (NullPointerException e) { + // Ignore this entry as it's null. + } + } + thisUser.sortPermissions(); + } + + // SUBGROUPS NODES + + nodeData = null; + try { + nodeData = thisUserNode.get("subgroups"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'subgroups' for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData == null) { + /* + * If no subgroups node is found, or it's empty + * do nothing. + */ + } else if (nodeData instanceof List) { + for (Object o : ((List) nodeData)) { + Group subGrp = ph.getGroup(o.toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup '" + o.toString() + "' not found for user: " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + } else if (nodeData instanceof String) { + Group subGrp = ph.getGroup(nodeData.toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup '" + nodeData.toString() + "' not found for user: " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + + // USER INFO NODE + + nodeData = null; + try { + nodeData = thisUserNode.get("info"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'info' section for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData == null) { + /* + * If no info node is found, or it's empty + * do nothing. + */ + } else if (nodeData instanceof Map) { + thisUser.setVariables((Map) nodeData); + + } else + throw new IllegalArgumentException("Unknown entry found in 'info' section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); + + // END INFO NODE + + // PRIMARY GROUP + + nodeData = null; + try { + nodeData = thisUserNode.get("group"); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in 'group' section for user: " + usersKey + " in file: " + usersFile.getPath()); + } + + if (nodeData != null) { + Group hisGroup = ph.getGroup(nodeData.toString()); + if (hisGroup == null) { + GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); + hisGroup = ph.getDefaultGroup(); + } + thisUser.setGroup(hisGroup); + } else { + thisUser.setGroup(ph.getDefaultGroup()); + } + } + } + + ph.removeUsersChangedFlag(); + // Update the LastModified time. + ph.setUsersFile(usersFile); + ph.setTimeStampUsers(usersFile.lastModified()); + } + + /** + * Write a dataHolder in a specified file + * + * @param ph + * @param groupsFile + */ + public static void writeGroups(WorldDataHolder ph, File groupsFile) { + + Map root = new HashMap(); + + Map groupsMap = new HashMap(); + + root.put("groups", groupsMap); + for (String groupKey : ph.getGroups().keySet()) { + Group group = ph.getGroups().get(groupKey); + + Map aGroupMap = new HashMap(); + groupsMap.put(group.getName(), aGroupMap); + + if (ph.getDefaultGroup() == null) { + GroupManager.logger.severe("There is no default group for world: " + ph.getName()); + } + aGroupMap.put("default", group.equals(ph.getDefaultGroup())); + + Map infoMap = new HashMap(); + aGroupMap.put("info", infoMap); + + for (String infoKey : group.getVariables().getVarKeyList()) { + infoMap.put(infoKey, group.getVariables().getVarObject(infoKey)); + } + + aGroupMap.put("inheritance", group.getInherits()); + + aGroupMap.put("permissions", group.getPermissionList()); + } + + if (!root.isEmpty()) { + DumperOptions opt = new DumperOptions(); + opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + final Yaml yaml = new Yaml(opt); + try { + OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(groupsFile), "UTF-8"); + + String newLine = System.getProperty("line.separator"); + + out.write("# Group inheritance" + newLine); + out.write("#" + newLine); + out.write("# Any inherited groups prefixed with a g: are global groups" + newLine); + out.write("# and are inherited from the GlobalGroups.yml." + newLine); + out.write("#" + newLine); + out.write("# Groups without the g: prefix are groups local to this world" + newLine); + out.write("# and are defined in the this groups.yml file." + newLine); + out.write("#" + newLine); + out.write("# Local group inheritances define your promotion tree when using 'manpromote/mandemote'" + newLine); + out.write(newLine); + + yaml.dump(root, out); + out.close(); + } catch (UnsupportedEncodingException ex) { + } catch (FileNotFoundException ex) { + } catch (IOException e) { + } + } + + // Update the LastModified time. + ph.setGroupsFile(groupsFile); + ph.setTimeStampGroups(groupsFile.lastModified()); + ph.removeGroupsChangedFlag(); + + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); + + /* + * FileWriter tx = null; + * try { + * tx = new FileWriter(groupsFile, false); + * tx.write(yaml.dump(root)); + * tx.flush(); + * } catch (Exception e) { + * } finally { + * try { + * tx.close(); + * } catch (IOException ex) { + * } + * } + */ + } + + /** + * Write a dataHolder in a specified file + * + * @param ph + * @param usersFile + */ + public static void writeUsers(WorldDataHolder ph, File usersFile) { + + Map root = new HashMap(); + + Map usersMap = new HashMap(); + root.put("users", usersMap); + for (String userKey : ph.getUsers().keySet()) { + User user = ph.getUsers().get(userKey); + if ((user.getGroup() == null || user.getGroup().equals(ph.getDefaultGroup())) && user.getPermissionList().isEmpty() && user.getVariables().isEmpty() && user.isSubGroupsEmpty()) { + continue; + } + + Map aUserMap = new HashMap(); + usersMap.put(user.getName(), aUserMap); + + if (user.getGroup() == null) { + aUserMap.put("group", ph.getDefaultGroup().getName()); + } else { + aUserMap.put("group", user.getGroup().getName()); + } + // USER INFO NODE - BETA + if (user.getVariables().getSize() > 0) { + Map infoMap = new HashMap(); + aUserMap.put("info", infoMap); + for (String infoKey : user.getVariables().getVarKeyList()) { + infoMap.put(infoKey, user.getVariables().getVarObject(infoKey)); + } + } + // END USER INFO NODE - BETA + aUserMap.put("permissions", user.getPermissionList()); + + // SUBGROUPS NODE - BETA + aUserMap.put("subgroups", user.subGroupListStringCopy()); + // END SUBGROUPS NODE - BETA + } + + if (!root.isEmpty()) { + DumperOptions opt = new DumperOptions(); + opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + final Yaml yaml = new Yaml(opt); + try { + OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(usersFile), "UTF-8"); + yaml.dump(root, out); + out.close(); + } catch (UnsupportedEncodingException ex) { + } catch (FileNotFoundException ex) { + } catch (IOException e) { + } + } + + // Update the LastModified time. + ph.setUsersFile(usersFile); + ph.setTimeStampUsers(usersFile.lastModified()); + ph.removeUsersChangedFlag(); + + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); + + /* + * FileWriter tx = null; + * try { + * tx = new FileWriter(usersFile, false); + * tx.write(yaml.dump(root)); + * tx.flush(); + * } catch (Exception e) { + * } finally { + * try { + * tx.close(); + * } catch (IOException ex) { + * } + * } + */ + } + + /** + * Don't use this. Unless you want to make this plugin to interact with + * original Nijikokun Permissions + * This method is supposed to make the original one reload the file, and + * propagate the changes made here. + * + * Prefer to use the AnjoCaido's fake version of Nijikokun's Permission + * plugin. + * The AnjoCaido's Permission can propagate the changes made on this plugin + * instantly, + * without need to save the file. + * + * @param server the server that holds the plugin + * @deprecated it is not used anymore... unless if you use original + * Permissions + */ + @Deprecated + public static void reloadOldPlugins(Server server) { + + // Only reload permissions + PluginManager pm = server.getPluginManager(); + Plugin[] plugins = pm.getPlugins(); + for (int i = 0; i < plugins.length; i++) { + // plugins[i].getConfiguration().load(); + try { + plugins[i].getClass().getMethod("setupPermissions").invoke(plugins[i]); + } catch (Exception ex) { + continue; + } + } + } + + /** + * @return the permissionsHandler + */ + public AnjoPermissionsHandler getPermissionsHandler() { + + if (permissionsHandler == null) { + permissionsHandler = new AnjoPermissionsHandler(this); + } + return permissionsHandler; + } + + /** * @param haveUsersChanged the haveUsersChanged to set */ public void setUsersChanged(boolean haveUsersChanged) { + users.setUsersChanged(haveUsersChanged); } - /** - * - * @return true if any user data has changed - */ - public boolean haveUsersChanged() { - if (users.HaveUsersChanged()) { - return true; - } - for (User u : users.getUsers().values()) { - if (u.isChanged()) { - return true; - } - } - return false; - } - - /** + /** + * + * @return true if any user data has changed + */ + public boolean haveUsersChanged() { + + if (users.HaveUsersChanged()) { + return true; + } + for (User u : users.getUsers().values()) { + if (u.isChanged()) { + return true; + } + } + return false; + } + + /** * @param setGroupsChanged the haveGroupsChanged to set */ public void setGroupsChanged(boolean setGroupsChanged) { + groups.setGroupsChanged(setGroupsChanged); } - - /** - * - * @return true if any group data has changed. - */ - public boolean haveGroupsChanged() { - if (groups.HaveGroupsChanged()) { - return true; - } - for (Group g : groups.getGroups().values()) { - if (g.isChanged()) { - return true; - } - } - return false; - } - - /** + + /** + * + * @return true if any group data has changed. + */ + public boolean haveGroupsChanged() { + + if (groups.HaveGroupsChanged()) { + return true; + } + for (Group g : groups.getGroups().values()) { + if (g.isChanged()) { + return true; + } + } + return false; + } + + /** * */ - public void removeUsersChangedFlag() { - setUsersChanged(false); - for (User u : getUsers().values()) { - u.flagAsSaved(); - } - } - - /** + public void removeUsersChangedFlag() { + + setUsersChanged(false); + for (User u : getUsers().values()) { + u.flagAsSaved(); + } + } + + /** * */ - public void removeGroupsChangedFlag() { - setGroupsChanged(false); - for (Group g : getGroups().values()) { - g.flagAsSaved(); - } - } - - /** - * @return the usersFile - */ - public File getUsersFile() { - return users.getUsersFile(); - } - - /** - * @param file the usersFile to set - */ - public void setUsersFile(File file) { - users.setUsersFile(file); - } + public void removeGroupsChangedFlag() { - /** - * @return the groupsFile - */ - public File getGroupsFile() { - return groups.getGroupsFile(); - } - - /** - * @param file the groupsFile to set - */ - public void setGroupsFile(File file) { - groups.setGroupsFile(file); - } + setGroupsChanged(false); + for (Group g : getGroups().values()) { + g.flagAsSaved(); + } + } - /** - * @return the name - */ - public String getName() { - return name; - } - - /** + /** + * @return the usersFile + */ + public File getUsersFile() { + + return users.getUsersFile(); + } + + /** + * @param file the usersFile to set + */ + public void setUsersFile(File file) { + + users.setUsersFile(file); + } + + /** + * @return the groupsFile + */ + public File getGroupsFile() { + + return groups.getGroupsFile(); + } + + /** + * @param file the groupsFile to set + */ + public void setGroupsFile(File file) { + + groups.setGroupsFile(file); + } + + /** + * @return the name + */ + public String getName() { + + return name; + } + + /** * Resets Groups. */ public void resetGroups() { - //setDefaultGroup(null); + + // setDefaultGroup(null); groups.setGroups(new HashMap()); } - /** + + /** * Resets Users */ public void resetUsers() { + users.setUsers(new HashMap()); } - - /** + + /** * @return the groups */ public Map getGroups() { + return groups.getGroups(); } - /** + + /** * @return the users */ public Map getUsers() { + return users.getUsers(); } - + /** * @return the groups */ public GroupsDataHolder getGroupsObject() { + return groups; } + /** * @param groupsDataHolder the GroupsDataHolder to set */ public void setGroupsObject(GroupsDataHolder groupsDataHolder) { + groups = groupsDataHolder; } - /** + + /** * @return the users */ public UsersDataHolder getUsersObject() { + return users; } + /** * @param usersDataHolder the UsersDataHolder to set */ public void setUsersObject(UsersDataHolder usersDataHolder) { + users = usersDataHolder; } - - /** + + /** * @return the timeStampGroups */ public long getTimeStampGroups() { + return groups.getTimeStampGroups(); } - /** + + /** * @return the timeStampUsers */ public long getTimeStampUsers() { + return users.getTimeStampUsers(); } @@ -1248,20 +1325,24 @@ public class WorldDataHolder { * @param timeStampGroups the timeStampGroups to set */ protected void setTimeStampGroups(long timeStampGroups) { + groups.setTimeStampGroups(timeStampGroups); } - /** + + /** * @param timeStampUsers the timeStampUsers to set */ protected void setTimeStampUsers(long timeStampUsers) { + users.setTimeStampUsers(timeStampUsers); } - + public void setTimeStamps() { + if (getGroupsFile() != null) setTimeStampGroups(getGroupsFile().lastModified()); if (getUsersFile() != null) setTimeStampUsers(getUsersFile().lastModified()); - } - + } + } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index bfa7d5cd2..ebacfdfac 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -26,432 +26,451 @@ import org.bukkit.configuration.MemorySection; import org.bukkit.entity.Player; /** - * + * * @author gabrielcouto */ public class WorldsHolder { - /** - * Map with instances of loaded worlds. - */ - private Map worldsData = new HashMap(); - - /** - * Map of mirrors: - * The key is the mirror. - * The object is the mirrored. - * - * Mirror shows the same data of mirrored. - */ - private Map mirrorsGroup = new HashMap(); - private Map mirrorsUser = new HashMap(); - - //private OverloadedWorldHolder defaultWorld; - private String serverDefaultWorldName; - private GroupManager plugin; - private File worldsFolder; - - /** - * - * @param plugin - */ - public WorldsHolder(GroupManager plugin) { - this.plugin = plugin; - // Setup folders and check files exist for the primary world - verifyFirstRun(); - initialLoad(); - if (serverDefaultWorldName == null) { - throw new IllegalStateException("There is no default group! OMG!"); - } - } - - private void initialLoad() { - // load the initial world - initialWorldLoading(); - // Configure and load any mirrors and additional worlds as defined in config.yml - mirrorSetUp(); - // search the worlds folder for any manually created worlds (not listed in config.yml) - loadAllSearchedWorlds(); - } - - private void initialWorldLoading() { - //Load the default world - loadWorld(serverDefaultWorldName); - //defaultWorld = getUpdatedWorldData(serverDefaultWorldName); - } - - private void loadAllSearchedWorlds() { - - /* - * Read all known worlds from Bukkit - * Create the data files if they don't already exist, - * and they are not mirrored. - */ - for (World world: plugin.getServer().getWorlds()) - if ((!worldsData.containsKey(world.getName().toLowerCase())) - && ((!mirrorsGroup.containsKey(world.getName().toLowerCase())) || (!mirrorsUser.containsKey(world.getName().toLowerCase())))) - setupWorldFolder(world.getName()); - /* - * Loop over all folders within the worlds folder - * and attempt to load the world data - */ - for (File folder : worldsFolder.listFiles()) { - if (folder.isDirectory()) { - GroupManager.logger.info("World Found: " + folder.getName()); - - /* - * don't load any worlds which are already loaded - * or fully mirrored worlds that don't need data. - */ - if (!worldsData.containsKey(folder.getName().toLowerCase()) - && ((!mirrorsGroup.containsKey(folder.getName().toLowerCase())) - || (!mirrorsUser.containsKey(folder.getName().toLowerCase())))) { - /* - * Call setupWorldFolder to check case sensitivity - * and convert to lower case, before we attempt to load this world. - */ - setupWorldFolder(folder.getName()); - loadWorld(folder.getName().toLowerCase()); - } - - } - } - } - - @SuppressWarnings("rawtypes") - public void mirrorSetUp() { - mirrorsGroup.clear(); - mirrorsUser.clear(); - Map mirrorsMap = plugin.getGMConfig().getMirrorsMap(); - - HashSet mirroredWorlds = new HashSet(); - - if (mirrorsMap != null) { - for (String source : mirrorsMap.keySet()) { - // Make sure all non mirrored worlds have a set of data files. - setupWorldFolder(source); - // Load the world data - if (!worldsData.containsKey(source.toLowerCase())) - loadWorld(source); - - if (mirrorsMap.get(source) instanceof ArrayList) { - ArrayList mirrorList = (ArrayList) mirrorsMap.get(source); - - // These worlds fully mirror their parent - for (Object o : mirrorList) { - String world = o.toString().toLowerCase(); - if (world != serverDefaultWorldName) { - try { - mirrorsGroup.remove(world); - mirrorsUser.remove(world); - } catch (Exception e) { - } - mirrorsGroup.put(world, getWorldData(source).getName()); - mirrorsUser.put(world, getWorldData(source).getName()); - - // Track this world so we can create a datasource for it later - mirroredWorlds.add(o.toString()); - - } else - GroupManager.logger.log(Level.WARNING, "Mirroring error with " + o.toString() + ". Recursive loop detected!"); - } - } else if (mirrorsMap.get(source) instanceof MemorySection) { - MemorySection subSection = (MemorySection) mirrorsMap.get(source); - - for (String key : subSection.getKeys(true)) { - - if (key.toLowerCase() != serverDefaultWorldName) { - - if (subSection.get(key) instanceof ArrayList) { - ArrayList mirrorList = (ArrayList) subSection.get(key); - - // These worlds have defined mirroring - for (Object o : mirrorList) { - String type = o.toString().toLowerCase(); - try { - if (type.equals("groups")) - mirrorsGroup.remove(key.toLowerCase()); - - if (type.equals("users")) - mirrorsUser.remove(key.toLowerCase()); - - } catch (Exception e) { - } - if (type.equals("groups")) - mirrorsGroup.put(key.toLowerCase(), getWorldData(source).getName()); - - if (type.equals("users")) - mirrorsUser.put(key.toLowerCase(), getWorldData(source).getName()); - } - - // Track this world so we can create a datasource for it later - mirroredWorlds.add(key); - - } else - GroupManager.logger.log(Level.WARNING, "Mirroring error with " + key + ". Recursive loop detected!"); - - } else { - throw new IllegalStateException("Unknown mirroring format for " + key); - } - - } - } - } - - // Create a datasource for any worlds not already loaded - for (String world : mirroredWorlds){ - if (!worldsData.containsKey(world.toLowerCase())) { - setupWorldFolder(world); - loadWorld(world, true); - } - } - } - } - - /** - * - */ - public void reloadAll() { - // Load global groups - GroupManager.getGlobalGroups().load(); - - ArrayList alreadyDone = new ArrayList(); - for (WorldDataHolder w : worldsData.values()) { - if (alreadyDone.contains(w)) { - continue; - } - if (!mirrorsGroup.containsKey(w.getName().toLowerCase())) - w.reloadGroups(); - if (!mirrorsUser.containsKey(w.getName().toLowerCase())) - w.reloadUsers(); - - alreadyDone.add(w); - } - - } - - /** - * - * @param worldName - */ - public void reloadWorld(String worldName) { - if (!mirrorsGroup.containsKey(worldName.toLowerCase())) - getWorldData(worldName).reloadGroups(); - if (!mirrorsUser.containsKey(worldName.toLowerCase())) - getWorldData(worldName).reloadUsers(); - } - - /** - * Wrapper to retain backwards compatibility - * (call this function to auto overwrite files) - */ - public void saveChanges() { - saveChanges(true); - } + /** + * Map with instances of loaded worlds. + */ + private Map worldsData = new HashMap(); + + /** + * Map of mirrors: + * The key is the mirror. + * The object is the mirrored. + * + * Mirror shows the same data of mirrored. + */ + private Map mirrorsGroup = new HashMap(); + private Map mirrorsUser = new HashMap(); + + //private OverloadedWorldHolder defaultWorld; + private String serverDefaultWorldName; + private GroupManager plugin; + private File worldsFolder; + + /** + * + * @param plugin + */ + public WorldsHolder(GroupManager plugin) { + + this.plugin = plugin; + // Setup folders and check files exist for the primary world + verifyFirstRun(); + initialLoad(); + if (serverDefaultWorldName == null) { + throw new IllegalStateException("There is no default group! OMG!"); + } + } + + private void initialLoad() { + + // load the initial world + initialWorldLoading(); + // Configure and load any mirrors and additional worlds as defined in config.yml + mirrorSetUp(); + // search the worlds folder for any manually created worlds (not listed in config.yml) + loadAllSearchedWorlds(); + } + + private void initialWorldLoading() { + + //Load the default world + loadWorld(serverDefaultWorldName); + //defaultWorld = getUpdatedWorldData(serverDefaultWorldName); + } + + private void loadAllSearchedWorlds() { + + /* + * Read all known worlds from Bukkit + * Create the data files if they don't already exist, + * and they are not mirrored. + */ + for (World world : plugin.getServer().getWorlds()) + if ((!worldsData.containsKey(world.getName().toLowerCase())) && ((!mirrorsGroup.containsKey(world.getName().toLowerCase())) || (!mirrorsUser.containsKey(world.getName().toLowerCase())))) + setupWorldFolder(world.getName()); + /* + * Loop over all folders within the worlds folder + * and attempt to load the world data + */ + for (File folder : worldsFolder.listFiles()) { + if (folder.isDirectory()) { + GroupManager.logger.info("World Found: " + folder.getName()); + + /* + * don't load any worlds which are already loaded + * or fully mirrored worlds that don't need data. + */ + if (!worldsData.containsKey(folder.getName().toLowerCase()) && ((!mirrorsGroup.containsKey(folder.getName().toLowerCase())) || (!mirrorsUser.containsKey(folder.getName().toLowerCase())))) { + /* + * Call setupWorldFolder to check case sensitivity + * and convert to lower case, before we attempt to load this + * world. + */ + setupWorldFolder(folder.getName()); + loadWorld(folder.getName().toLowerCase()); + } - /** + } + } + } + + @SuppressWarnings("rawtypes") + public void mirrorSetUp() { + + mirrorsGroup.clear(); + mirrorsUser.clear(); + Map mirrorsMap = plugin.getGMConfig().getMirrorsMap(); + + HashSet mirroredWorlds = new HashSet(); + + if (mirrorsMap != null) { + for (String source : mirrorsMap.keySet()) { + // Make sure all non mirrored worlds have a set of data files. + setupWorldFolder(source); + // Load the world data + if (!worldsData.containsKey(source.toLowerCase())) + loadWorld(source); + + if (mirrorsMap.get(source) instanceof ArrayList) { + ArrayList mirrorList = (ArrayList) mirrorsMap.get(source); + + // These worlds fully mirror their parent + for (Object o : mirrorList) { + String world = o.toString().toLowerCase(); + if (world != serverDefaultWorldName) { + try { + mirrorsGroup.remove(world); + mirrorsUser.remove(world); + } catch (Exception e) { + } + mirrorsGroup.put(world, getWorldData(source).getName()); + mirrorsUser.put(world, getWorldData(source).getName()); + + // Track this world so we can create a datasource for it later + mirroredWorlds.add(o.toString()); + + } else + GroupManager.logger.log(Level.WARNING, "Mirroring error with " + o.toString() + ". Recursive loop detected!"); + } + } else if (mirrorsMap.get(source) instanceof MemorySection) { + MemorySection subSection = (MemorySection) mirrorsMap.get(source); + + for (String key : subSection.getKeys(true)) { + + if (key.toLowerCase() != serverDefaultWorldName) { + + if (subSection.get(key) instanceof ArrayList) { + ArrayList mirrorList = (ArrayList) subSection.get(key); + + // These worlds have defined mirroring + for (Object o : mirrorList) { + String type = o.toString().toLowerCase(); + try { + if (type.equals("groups")) + mirrorsGroup.remove(key.toLowerCase()); + + if (type.equals("users")) + mirrorsUser.remove(key.toLowerCase()); + + } catch (Exception e) { + } + if (type.equals("groups")) + mirrorsGroup.put(key.toLowerCase(), getWorldData(source).getName()); + + if (type.equals("users")) + mirrorsUser.put(key.toLowerCase(), getWorldData(source).getName()); + } + + // Track this world so we can create a datasource for it later + mirroredWorlds.add(key); + + } else + GroupManager.logger.log(Level.WARNING, "Mirroring error with " + key + ". Recursive loop detected!"); + + } else { + throw new IllegalStateException("Unknown mirroring format for " + key); + } + + } + } + } + + // Create a datasource for any worlds not already loaded + for (String world : mirroredWorlds) { + if (!worldsData.containsKey(world.toLowerCase())) { + setupWorldFolder(world); + loadWorld(world, true); + } + } + } + } + + /** * */ - public void saveChanges(boolean overwrite) { - ArrayList alreadyDone = new ArrayList(); - Tasks.removeOldFiles(plugin, plugin.getBackupFolder()); - - // Write Global Groups - if (GroupManager.getGlobalGroups().haveGroupsChanged()) { - GroupManager.getGlobalGroups().writeGroups(overwrite); - } else { - if (GroupManager.getGlobalGroups().getTimeStampGroups() < GroupManager.getGlobalGroups().getGlobalGroupsFile().lastModified()) { - System.out.print("Newer GlobalGroups file found (Loading changes)!"); - GroupManager.getGlobalGroups().load(); - } - } - - for (OverloadedWorldHolder w : worldsData.values()) { - if (alreadyDone.contains(w)) { - continue; - } - if (w == null) { - GroupManager.logger.severe("WHAT HAPPENED?"); - continue; - } - if (!mirrorsGroup.containsKey(w.getName().toLowerCase())) - if (w.haveGroupsChanged()) { - if (overwrite || (!overwrite && (w.getTimeStampGroups() >= w.getGroupsFile().lastModified()))) { - // Backup Groups file - backupFile(w,true); - - WorldDataHolder.writeGroups(w, w.getGroupsFile()); - //w.removeGroupsChangedFlag(); - } else { - // Newer file found. - GroupManager.logger.log(Level.WARNING, "Newer Groups file found for " + w.getName() + ", but we have local changes!"); - throw new IllegalStateException("Unable to save unless you issue a '/mansave force'"); - } - } else { - //Check for newer file as no local changes. - if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) { - System.out.print("Newer Groups file found (Loading changes)!"); - // Backup Groups file - backupFile(w,true); - w.reloadGroups(); - } - } - if (!mirrorsUser.containsKey(w.getName().toLowerCase())) - if (w.haveUsersChanged()) { - if (overwrite || (!overwrite && (w.getTimeStampUsers() >= w.getUsersFile().lastModified()))) { - // Backup Users file - backupFile(w,false); - - WorldDataHolder.writeUsers(w, w.getUsersFile()); - //w.removeUsersChangedFlag(); - } else { - // Newer file found. - GroupManager.logger.log(Level.WARNING, "Newer Users file found for " + w.getName() + ", but we have local changes!"); - throw new IllegalStateException("Unable to save unless you issue a '/mansave force'"); - } - } else { - //Check for newer file as no local changes. - if (w.getTimeStampUsers() < w.getUsersFile().lastModified()) { - System.out.print("Newer Users file found (Loading changes)!"); - // Backup Users file - backupFile(w,false); - w.reloadUsers(); - } - } - alreadyDone.add(w); - } - } - - /** - * Backup the Groups/Users file - * @param w - * @param groups - */ - private void backupFile(OverloadedWorldHolder w, Boolean groups) { - - File backupFile = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + (groups ? "_g_" : "_u_") + Tasks.getDateString() + ".yml"); - try { - Tasks.copy((groups ? w.getGroupsFile() : w.getUsersFile()), backupFile); - } catch (IOException ex) { - GroupManager.logger.log(Level.SEVERE, null, ex); - } - } - - /** - * Returns the dataHolder for the given world. - * If the world is not on the worlds list, returns the default world - * holder. - * - * Mirrors return their parent world data. - * If no mirroring data it returns the default world. + public void reloadAll() { + + // Load global groups + GroupManager.getGlobalGroups().load(); + + ArrayList alreadyDone = new ArrayList(); + for (WorldDataHolder w : worldsData.values()) { + if (alreadyDone.contains(w)) { + continue; + } + if (!mirrorsGroup.containsKey(w.getName().toLowerCase())) + w.reloadGroups(); + if (!mirrorsUser.containsKey(w.getName().toLowerCase())) + w.reloadUsers(); + + alreadyDone.add(w); + } + + } + + /** + * + * @param worldName + */ + public void reloadWorld(String worldName) { + + if (!mirrorsGroup.containsKey(worldName.toLowerCase())) + getWorldData(worldName).reloadGroups(); + if (!mirrorsUser.containsKey(worldName.toLowerCase())) + getWorldData(worldName).reloadUsers(); + } + + /** + * Wrapper to retain backwards compatibility + * (call this function to auto overwrite files) + */ + public void saveChanges() { + + saveChanges(true); + } + + /** * - * @param worldName - * @return OverloadedWorldHolder - */ - public OverloadedWorldHolder getWorldData(String worldName) { - String worldNameLowered = worldName.toLowerCase(); - - // Find this worlds data - if (worldsData.containsKey(worldNameLowered)) - return getUpdatedWorldData(worldNameLowered); - - // Oddly no data source was found for this world so return the default. - GroupManager.logger.finest("Requested world " + worldName + " not found or badly mirrored. Returning default world..."); - return getDefaultWorld(); - } - - /** - * Get the requested world data and update it's dataSource to be relevant for this world - * - * @param worldName - * @return updated world holder - */ - private OverloadedWorldHolder getUpdatedWorldData(String worldName) { - String worldNameLowered = worldName.toLowerCase(); - - if (worldsData.containsKey(worldNameLowered)) { - OverloadedWorldHolder data = worldsData.get(worldNameLowered); - data.updateDataSource(); - return data; - } - return null; - - } - - /** - * Do a matching of playerName, if its found only one player, do - * getWorldData(player) - * - * @param playerName - * @return null if matching returned no player, or more than one. */ - public OverloadedWorldHolder getWorldDataByPlayerName(String playerName) { - List matchPlayer = plugin.getServer().matchPlayer(playerName); - if (matchPlayer.size() == 1) { - return getWorldData(matchPlayer.get(0)); - } - return null; - } - - /** - * Retrieves the field player.getWorld().getName() and do - * getWorld(worldName) - * - * @param player - * @return OverloadedWorldHolder - */ - public OverloadedWorldHolder getWorldData(Player player) { - return getWorldData(player.getWorld().getName()); - } - - /** - * It does getWorld(worldName).getPermissionsHandler() - * @param worldName - * @return AnjoPermissionsHandler - */ - public AnjoPermissionsHandler getWorldPermissions(String worldName) { - return getWorldData(worldName).getPermissionsHandler(); - } - - /** - * Returns the PermissionsHandler for this player data - * @param player - * @return AnjoPermissionsHandler - */ - public AnjoPermissionsHandler getWorldPermissions(Player player) { - return getWorldData(player).getPermissionsHandler(); - } - - /** - * Id does getWorldDataByPlayerName(playerName). - * If it doesnt return null, it will return result.getPermissionsHandler() - * @param playerName - * @return null if the player matching gone wrong. - */ - public AnjoPermissionsHandler getWorldPermissionsByPlayerName(String playerName) { - WorldDataHolder dh = getWorldDataByPlayerName(playerName); - if (dh != null) { - return dh.getPermissionsHandler(); - } - return null; - } - - private void verifyFirstRun() { - - Properties server = new Properties(); - try { - server.load(new FileInputStream(new File("server.properties"))); - serverDefaultWorldName = server.getProperty("level-name").toLowerCase(); - setupWorldFolder(serverDefaultWorldName); - } catch (IOException ex) { - GroupManager.logger.log(Level.SEVERE, null, ex); - } - - } - + public void saveChanges(boolean overwrite) { + + ArrayList alreadyDone = new ArrayList(); + Tasks.removeOldFiles(plugin, plugin.getBackupFolder()); + + // Write Global Groups + if (GroupManager.getGlobalGroups().haveGroupsChanged()) { + GroupManager.getGlobalGroups().writeGroups(overwrite); + } else { + if (GroupManager.getGlobalGroups().getTimeStampGroups() < GroupManager.getGlobalGroups().getGlobalGroupsFile().lastModified()) { + System.out.print("Newer GlobalGroups file found (Loading changes)!"); + GroupManager.getGlobalGroups().load(); + } + } + + for (OverloadedWorldHolder w : worldsData.values()) { + if (alreadyDone.contains(w)) { + continue; + } + if (w == null) { + GroupManager.logger.severe("WHAT HAPPENED?"); + continue; + } + if (!mirrorsGroup.containsKey(w.getName().toLowerCase())) + if (w.haveGroupsChanged()) { + if (overwrite || (!overwrite && (w.getTimeStampGroups() >= w.getGroupsFile().lastModified()))) { + // Backup Groups file + backupFile(w, true); + + WorldDataHolder.writeGroups(w, w.getGroupsFile()); + //w.removeGroupsChangedFlag(); + } else { + // Newer file found. + GroupManager.logger.log(Level.WARNING, "Newer Groups file found for " + w.getName() + ", but we have local changes!"); + throw new IllegalStateException("Unable to save unless you issue a '/mansave force'"); + } + } else { + //Check for newer file as no local changes. + if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) { + System.out.print("Newer Groups file found (Loading changes)!"); + // Backup Groups file + backupFile(w, true); + w.reloadGroups(); + } + } + if (!mirrorsUser.containsKey(w.getName().toLowerCase())) + if (w.haveUsersChanged()) { + if (overwrite || (!overwrite && (w.getTimeStampUsers() >= w.getUsersFile().lastModified()))) { + // Backup Users file + backupFile(w, false); + + WorldDataHolder.writeUsers(w, w.getUsersFile()); + //w.removeUsersChangedFlag(); + } else { + // Newer file found. + GroupManager.logger.log(Level.WARNING, "Newer Users file found for " + w.getName() + ", but we have local changes!"); + throw new IllegalStateException("Unable to save unless you issue a '/mansave force'"); + } + } else { + //Check for newer file as no local changes. + if (w.getTimeStampUsers() < w.getUsersFile().lastModified()) { + System.out.print("Newer Users file found (Loading changes)!"); + // Backup Users file + backupFile(w, false); + w.reloadUsers(); + } + } + alreadyDone.add(w); + } + } + + /** + * Backup the Groups/Users file + * + * @param w + * @param groups + */ + private void backupFile(OverloadedWorldHolder w, Boolean groups) { + + File backupFile = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + (groups ? "_g_" : "_u_") + Tasks.getDateString() + ".yml"); + try { + Tasks.copy((groups ? w.getGroupsFile() : w.getUsersFile()), backupFile); + } catch (IOException ex) { + GroupManager.logger.log(Level.SEVERE, null, ex); + } + } + + /** + * Returns the dataHolder for the given world. + * If the world is not on the worlds list, returns the default world + * holder. + * + * Mirrors return their parent world data. + * If no mirroring data it returns the default world. + * + * @param worldName + * @return OverloadedWorldHolder + */ + public OverloadedWorldHolder getWorldData(String worldName) { + + String worldNameLowered = worldName.toLowerCase(); + + // Find this worlds data + if (worldsData.containsKey(worldNameLowered)) + return getUpdatedWorldData(worldNameLowered); + + // Oddly no data source was found for this world so return the default. + GroupManager.logger.finest("Requested world " + worldName + " not found or badly mirrored. Returning default world..."); + return getDefaultWorld(); + } + + /** + * Get the requested world data and update it's dataSource to be relevant + * for this world + * + * @param worldName + * @return updated world holder + */ + private OverloadedWorldHolder getUpdatedWorldData(String worldName) { + + String worldNameLowered = worldName.toLowerCase(); + + if (worldsData.containsKey(worldNameLowered)) { + OverloadedWorldHolder data = worldsData.get(worldNameLowered); + data.updateDataSource(); + return data; + } + return null; + + } + + /** + * Do a matching of playerName, if its found only one player, do + * getWorldData(player) + * + * @param playerName + * @return null if matching returned no player, or more than one. + */ + public OverloadedWorldHolder getWorldDataByPlayerName(String playerName) { + + List matchPlayer = plugin.getServer().matchPlayer(playerName); + if (matchPlayer.size() == 1) { + return getWorldData(matchPlayer.get(0)); + } + return null; + } + + /** + * Retrieves the field player.getWorld().getName() and do + * getWorld(worldName) + * + * @param player + * @return OverloadedWorldHolder + */ + public OverloadedWorldHolder getWorldData(Player player) { + + return getWorldData(player.getWorld().getName()); + } + + /** + * It does getWorld(worldName).getPermissionsHandler() + * + * @param worldName + * @return AnjoPermissionsHandler + */ + public AnjoPermissionsHandler getWorldPermissions(String worldName) { + + return getWorldData(worldName).getPermissionsHandler(); + } + + /** + * Returns the PermissionsHandler for this player data + * + * @param player + * @return AnjoPermissionsHandler + */ + public AnjoPermissionsHandler getWorldPermissions(Player player) { + + return getWorldData(player).getPermissionsHandler(); + } + + /** + * Id does getWorldDataByPlayerName(playerName). + * If it doesnt return null, it will return result.getPermissionsHandler() + * + * @param playerName + * @return null if the player matching gone wrong. + */ + public AnjoPermissionsHandler getWorldPermissionsByPlayerName(String playerName) { + + WorldDataHolder dh = getWorldDataByPlayerName(playerName); + if (dh != null) { + return dh.getPermissionsHandler(); + } + return null; + } + + private void verifyFirstRun() { + + Properties server = new Properties(); + try { + server.load(new FileInputStream(new File("server.properties"))); + serverDefaultWorldName = server.getProperty("level-name").toLowerCase(); + setupWorldFolder(serverDefaultWorldName); + } catch (IOException ex) { + GroupManager.logger.log(Level.SEVERE, null, ex); + } + + } + public void setupWorldFolder(String worldName) { + String worldNameLowered = worldName.toLowerCase(); - + worldsFolder = new File(plugin.getDataFolder(), "worlds"); if (!worldsFolder.exists()) { worldsFolder.mkdirs(); @@ -459,22 +478,22 @@ public class WorldsHolder { File defaultWorldFolder = new File(worldsFolder, worldNameLowered); if ((!defaultWorldFolder.exists()) && ((!mirrorsGroup.containsKey(worldNameLowered))) || (!mirrorsUser.containsKey(worldNameLowered))) { - + /* - * check and convert all old case sensitive folders to lower case - */ + * check and convert all old case sensitive folders to lower case + */ File casedWorldFolder = new File(worldsFolder, worldName); - if ((casedWorldFolder.exists()) && (casedWorldFolder.getName().toLowerCase().equals(worldNameLowered))) { - /* - * Rename the old folder to the new lower cased format - */ - casedWorldFolder.renameTo(new File(worldsFolder, worldNameLowered)); - } else { - /* - * Else we just create the folder - */ - defaultWorldFolder.mkdirs(); - } + if ((casedWorldFolder.exists()) && (casedWorldFolder.getName().toLowerCase().equals(worldNameLowered))) { + /* + * Rename the old folder to the new lower cased format + */ + casedWorldFolder.renameTo(new File(worldsFolder, worldNameLowered)); + } else { + /* + * Else we just create the folder + */ + defaultWorldFolder.mkdirs(); + } } if (defaultWorldFolder.exists()) { if (!mirrorsGroup.containsKey(worldNameLowered)) { @@ -506,181 +525,188 @@ public class WorldsHolder { } } - /** - * Copies the specified world data to another world - * - * @param fromWorld - * @param toWorld - * @return true if successfully copied. - */ - public boolean cloneWorld(String fromWorld, String toWorld) { - - File fromWorldFolder = new File(worldsFolder, fromWorld.toLowerCase()); - File toWorldFolder = new File(worldsFolder, toWorld.toLowerCase()); - if (toWorldFolder.exists() || !fromWorldFolder.exists()) { - return false; - } - File fromWorldGroups = new File(fromWorldFolder, "groups.yml"); - File fromWorldUsers = new File(fromWorldFolder, "users.yml"); - if (!fromWorldGroups.exists() || !fromWorldUsers.exists()) { - return false; - } - File toWorldGroups = new File(toWorldFolder, "groups.yml"); - File toWorldUsers = new File(toWorldFolder, "users.yml"); - toWorldFolder.mkdirs(); - try { - Tasks.copy(fromWorldGroups, toWorldGroups); - Tasks.copy(fromWorldUsers, toWorldUsers); - } catch (IOException ex) { - Logger.getLogger(WorldsHolder.class.getName()).log(Level.SEVERE, null, ex); - return false; - } - return true; - } - - /** - * Wrapper for LoadWorld(String,Boolean) for backwards compatibility - * - * Load a world from file. - * If it already been loaded, summon reload method from dataHolder. - * @param worldName - */ - public void loadWorld(String worldName) { - loadWorld(worldName, false); - } - - /** - * Load a world from file. - * If it already been loaded, summon reload method from dataHolder. - * @param worldName - */ - public void loadWorld(String worldName, Boolean isMirror) { - - String worldNameLowered = worldName.toLowerCase(); - - if (worldsData.containsKey(worldNameLowered)) { - worldsData.get(worldNameLowered).reload(); - return; - } - GroupManager.logger.finest("Trying to load world " + worldName + "..."); - File thisWorldFolder = new File(worldsFolder, worldNameLowered); - if ((isMirror) || (thisWorldFolder.exists() && thisWorldFolder.isDirectory())) { - - // Setup file handles, if not mirrored - File groupsFile = (mirrorsGroup.containsKey(worldNameLowered))? null : new File(thisWorldFolder, "groups.yml"); - File usersFile = (mirrorsUser.containsKey(worldNameLowered))? null : new File(thisWorldFolder, "users.yml"); - - if ((groupsFile != null) && (!groupsFile.exists())) { - throw new IllegalArgumentException("Groups file for world '" + worldName + "' doesnt exist: " + groupsFile.getPath()); - } - if ((usersFile != null) && (!usersFile.exists())) { - throw new IllegalArgumentException("Users file for world '" + worldName + "' doesnt exist: " + usersFile.getPath()); - } - - WorldDataHolder tempHolder = new WorldDataHolder(worldName); - - // Map the group object for any mirror - if (mirrorsGroup.containsKey(worldNameLowered)) - tempHolder.setGroupsObject(this.getWorldData(mirrorsGroup.get(worldNameLowered)).getGroupsObject()); - else - tempHolder.loadGroups(groupsFile); - - // Map the user object for any mirror - if (mirrorsUser.containsKey(worldNameLowered)) - tempHolder.setUsersObject(this.getWorldData(mirrorsUser.get(worldNameLowered)).getUsersObject()); - else - tempHolder.loadUsers(usersFile); - - OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(tempHolder); - - // null the object so we don't keep file handles open where we shouldn't - tempHolder = null; - - // Set the file TimeStamps as it will be default from the initial load. - thisWorldData.setTimeStamps(); - - if (thisWorldData != null) { - GroupManager.logger.finest("Successful load of world " + worldName + "..."); - worldsData.put(worldNameLowered, thisWorldData); - return; - } - - //GroupManager.logger.severe("Failed to load world " + worldName + "..."); - } - } - - /** - * Tells if the such world has been mapped. - * - * It will return true if world is a mirror. - * - * @param worldName - * @return true if world is loaded or mirrored. false if not listed - */ - public boolean isInList(String worldName) { - if (worldsData.containsKey(worldName.toLowerCase()) || mirrorsGroup.containsKey(worldName.toLowerCase()) || mirrorsUser.containsKey(worldName.toLowerCase())) { - return true; - } - return false; - } - - /** - * Verify if world has it's own file permissions. - * - * @param worldName - * @return true if it has its own holder. false if not. - */ - public boolean hasOwnData(String worldName) { - if (worldsData.containsKey(worldName.toLowerCase()) && (!mirrorsGroup.containsKey(worldName.toLowerCase()) || !mirrorsUser.containsKey(worldName.toLowerCase()))) { - return true; - } - return false; - } - - /** - * @return the defaultWorld - */ - public OverloadedWorldHolder getDefaultWorld() { - return getUpdatedWorldData(serverDefaultWorldName); - } - - /** - * Returns all physically loaded worlds which have at least - * one of their own data sets for users or groups. - * - * @return ArrayList of all loaded worlds - */ - public ArrayList allWorldsDataList() { - ArrayList list = new ArrayList(); - for (OverloadedWorldHolder data : worldsData.values()) { - if ((!list.contains(data)) && (!mirrorsGroup.containsKey(data.getName().toLowerCase()) || !mirrorsUser.containsKey(data.getName().toLowerCase()))) { - - String worldNameLowered = data.getName().toLowerCase(); - String usersMirror = mirrorsUser.get(worldNameLowered); - String groupsMirror = mirrorsGroup.get(worldNameLowered); - - // is users mirrored? - if (usersMirror != null) { - - // If both are mirrored - if (groupsMirror != null) { - - // if the data sources are the same, return the parent - if (usersMirror == groupsMirror) { - if (!list.contains(usersMirror.toLowerCase())) - list.add(worldsData.get(usersMirror.toLowerCase())); - continue; - } - // Both data sources are mirrors, but they are from different parents - // so fall through to add the actual data object. - } - // Groups isn't a mirror so fall through to add this this worlds data source - } - - // users isn't mirrored so we need to add this worlds data source - list.add(data); - } - } - return list; - } + /** + * Copies the specified world data to another world + * + * @param fromWorld + * @param toWorld + * @return true if successfully copied. + */ + public boolean cloneWorld(String fromWorld, String toWorld) { + + File fromWorldFolder = new File(worldsFolder, fromWorld.toLowerCase()); + File toWorldFolder = new File(worldsFolder, toWorld.toLowerCase()); + if (toWorldFolder.exists() || !fromWorldFolder.exists()) { + return false; + } + File fromWorldGroups = new File(fromWorldFolder, "groups.yml"); + File fromWorldUsers = new File(fromWorldFolder, "users.yml"); + if (!fromWorldGroups.exists() || !fromWorldUsers.exists()) { + return false; + } + File toWorldGroups = new File(toWorldFolder, "groups.yml"); + File toWorldUsers = new File(toWorldFolder, "users.yml"); + toWorldFolder.mkdirs(); + try { + Tasks.copy(fromWorldGroups, toWorldGroups); + Tasks.copy(fromWorldUsers, toWorldUsers); + } catch (IOException ex) { + Logger.getLogger(WorldsHolder.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + /** + * Wrapper for LoadWorld(String,Boolean) for backwards compatibility + * + * Load a world from file. + * If it already been loaded, summon reload method from dataHolder. + * + * @param worldName + */ + public void loadWorld(String worldName) { + + loadWorld(worldName, false); + } + + /** + * Load a world from file. + * If it already been loaded, summon reload method from dataHolder. + * + * @param worldName + */ + public void loadWorld(String worldName, Boolean isMirror) { + + String worldNameLowered = worldName.toLowerCase(); + + if (worldsData.containsKey(worldNameLowered)) { + worldsData.get(worldNameLowered).reload(); + return; + } + GroupManager.logger.finest("Trying to load world " + worldName + "..."); + File thisWorldFolder = new File(worldsFolder, worldNameLowered); + if ((isMirror) || (thisWorldFolder.exists() && thisWorldFolder.isDirectory())) { + + // Setup file handles, if not mirrored + File groupsFile = (mirrorsGroup.containsKey(worldNameLowered)) ? null : new File(thisWorldFolder, "groups.yml"); + File usersFile = (mirrorsUser.containsKey(worldNameLowered)) ? null : new File(thisWorldFolder, "users.yml"); + + if ((groupsFile != null) && (!groupsFile.exists())) { + throw new IllegalArgumentException("Groups file for world '" + worldName + "' doesnt exist: " + groupsFile.getPath()); + } + if ((usersFile != null) && (!usersFile.exists())) { + throw new IllegalArgumentException("Users file for world '" + worldName + "' doesnt exist: " + usersFile.getPath()); + } + + WorldDataHolder tempHolder = new WorldDataHolder(worldName); + + // Map the group object for any mirror + if (mirrorsGroup.containsKey(worldNameLowered)) + tempHolder.setGroupsObject(this.getWorldData(mirrorsGroup.get(worldNameLowered)).getGroupsObject()); + else + tempHolder.loadGroups(groupsFile); + + // Map the user object for any mirror + if (mirrorsUser.containsKey(worldNameLowered)) + tempHolder.setUsersObject(this.getWorldData(mirrorsUser.get(worldNameLowered)).getUsersObject()); + else + tempHolder.loadUsers(usersFile); + + OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(tempHolder); + + // null the object so we don't keep file handles open where we shouldn't + tempHolder = null; + + // Set the file TimeStamps as it will be default from the initial load. + thisWorldData.setTimeStamps(); + + if (thisWorldData != null) { + GroupManager.logger.finest("Successful load of world " + worldName + "..."); + worldsData.put(worldNameLowered, thisWorldData); + return; + } + + //GroupManager.logger.severe("Failed to load world " + worldName + "..."); + } + } + + /** + * Tells if the such world has been mapped. + * + * It will return true if world is a mirror. + * + * @param worldName + * @return true if world is loaded or mirrored. false if not listed + */ + public boolean isInList(String worldName) { + + if (worldsData.containsKey(worldName.toLowerCase()) || mirrorsGroup.containsKey(worldName.toLowerCase()) || mirrorsUser.containsKey(worldName.toLowerCase())) { + return true; + } + return false; + } + + /** + * Verify if world has it's own file permissions. + * + * @param worldName + * @return true if it has its own holder. false if not. + */ + public boolean hasOwnData(String worldName) { + + if (worldsData.containsKey(worldName.toLowerCase()) && (!mirrorsGroup.containsKey(worldName.toLowerCase()) || !mirrorsUser.containsKey(worldName.toLowerCase()))) { + return true; + } + return false; + } + + /** + * @return the defaultWorld + */ + public OverloadedWorldHolder getDefaultWorld() { + + return getUpdatedWorldData(serverDefaultWorldName); + } + + /** + * Returns all physically loaded worlds which have at least + * one of their own data sets for users or groups. + * + * @return ArrayList of all loaded worlds + */ + public ArrayList allWorldsDataList() { + + ArrayList list = new ArrayList(); + for (OverloadedWorldHolder data : worldsData.values()) { + if ((!list.contains(data)) && (!mirrorsGroup.containsKey(data.getName().toLowerCase()) || !mirrorsUser.containsKey(data.getName().toLowerCase()))) { + + String worldNameLowered = data.getName().toLowerCase(); + String usersMirror = mirrorsUser.get(worldNameLowered); + String groupsMirror = mirrorsGroup.get(worldNameLowered); + + // is users mirrored? + if (usersMirror != null) { + + // If both are mirrored + if (groupsMirror != null) { + + // if the data sources are the same, return the parent + if (usersMirror == groupsMirror) { + if (!list.contains(usersMirror.toLowerCase())) + list.add(worldsData.get(usersMirror.toLowerCase())); + continue; + } + // Both data sources are mirrors, but they are from different parents + // so fall through to add the actual data object. + } + // Groups isn't a mirror so fall through to add this this worlds data source + } + + // users isn't mirrored so we need to add this worlds data source + list.add(data); + } + } + return list; + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java index fc9b8433b..af3fb6135 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMGroupEvent.java @@ -6,79 +6,82 @@ import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; - /** * @author ElgarL - * + * */ public class GMGroupEvent extends Event { - /** + /** * */ private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - ////////////////////////////// + return handlers; + } + + public static HandlerList getHandlerList() { + + return handlers; + } + + ////////////////////////////// protected Group group; - + protected String groupName; - - protected Action action; - - public GMGroupEvent(Group group, Action action) { - super(); - - this.group = group; - this.action = action; - this.groupName = group.getName(); - } - - public GMGroupEvent(String groupName, Action action) { - super(); - - this.groupName = groupName; - this.action = action; - } - - public Action getAction(){ - return this.action; - } - - public Group getGroup() { - return group; - } - - public String getGroupName() { - return groupName; - } - - public enum Action { - GROUP_PERMISSIONS_CHANGED, - GROUP_INHERITANCE_CHANGED, - GROUP_INFO_CHANGED, - GROUP_ADDED, - GROUP_REMOVED, - } - - public void schedule(final GMGroupEvent event) { + + protected Action action; + + public GMGroupEvent(Group group, Action action) { + + super(); + + this.group = group; + this.action = action; + this.groupName = group.getName(); + } + + public GMGroupEvent(String groupName, Action action) { + + super(); + + this.groupName = groupName; + this.action = action; + } + + public Action getAction() { + + return this.action; + } + + public Group getGroup() { + + return group; + } + + public String getGroupName() { + + return groupName; + } + + public enum Action { + GROUP_PERMISSIONS_CHANGED, GROUP_INHERITANCE_CHANGED, GROUP_INFO_CHANGED, GROUP_ADDED, GROUP_REMOVED, + } + + public void schedule(final GMGroupEvent event) { if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() { @Override public void run() { + Bukkit.getServer().getPluginManager().callEvent(event); } }, 1) == -1) GroupManager.logger.warning("Could not schedule GM Event."); - } + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java index 210960876..d11581356 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMSystemEvent.java @@ -5,57 +5,58 @@ import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; - /** * @author ElgarL - * + * */ public class GMSystemEvent extends Event { - /** + /** * */ private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - ////////////////////////////// - + + return handlers; + } + + public static HandlerList getHandlerList() { + + return handlers; + } + + ////////////////////////////// + protected Action action; - - public GMSystemEvent(Action action) { - super(); - - this.action = action; - } - - public Action getAction(){ - return this.action; - } - - public enum Action { - RELOADED, - SAVED, - DEFAULT_GROUP_CHANGED, - VALIDATE_TOGGLE, - } - - public void schedule(final GMSystemEvent event) { + + public GMSystemEvent(Action action) { + + super(); + + this.action = action; + } + + public Action getAction() { + + return this.action; + } + + public enum Action { + RELOADED, SAVED, DEFAULT_GROUP_CHANGED, VALIDATE_TOGGLE, + } + + public void schedule(final GMSystemEvent event) { if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() { @Override public void run() { + Bukkit.getServer().getPluginManager().callEvent(event); } }, 1) == -1) GroupManager.logger.warning("Could not schedule GM Event."); - } + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java index 206de8c86..361e7d4cc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMUserEvent.java @@ -6,81 +6,82 @@ import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; - /** * @author ElgarL - * + * */ public class GMUserEvent extends Event { - /** + /** * */ private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - ////////////////////////////// + return handlers; + } + + public static HandlerList getHandlerList() { + + return handlers; + } + + ////////////////////////////// protected User user; - + protected String userName; - - protected Action action; - - public GMUserEvent(User user, Action action) { - super(); - - this.user = user; - this.action = action; - this.userName = user.getName(); - } - - public GMUserEvent(String userName, Action action) { - super(); - - this.userName = userName; - this.action = action; - } - - public Action getAction(){ - return this.action; - } - - public User getUser() { - return user; - } - - public String getUserName() { - return userName; - } - - public enum Action { - USER_PERMISSIONS_CHANGED, - USER_INHERITANCE_CHANGED, - USER_INFO_CHANGED, - USER_GROUP_CHANGED, - USER_SUBGROUP_CHANGED, - USER_ADDED, - USER_REMOVED, - } - - public void schedule(final GMUserEvent event) { + + protected Action action; + + public GMUserEvent(User user, Action action) { + + super(); + + this.user = user; + this.action = action; + this.userName = user.getName(); + } + + public GMUserEvent(String userName, Action action) { + + super(); + + this.userName = userName; + this.action = action; + } + + public Action getAction() { + + return this.action; + } + + public User getUser() { + + return user; + } + + public String getUserName() { + + return userName; + } + + public enum Action { + USER_PERMISSIONS_CHANGED, USER_INHERITANCE_CHANGED, USER_INFO_CHANGED, USER_GROUP_CHANGED, USER_SUBGROUP_CHANGED, USER_ADDED, USER_REMOVED, + } + + public void schedule(final GMUserEvent event) { if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() { @Override public void run() { + Bukkit.getServer().getPluginManager().callEvent(event); } }, 1) == -1) GroupManager.logger.warning("Could not schedule GM Event."); - } + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java index fd1a9d7ff..f7a7109ab 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java @@ -6,31 +6,33 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.world.WorldInitEvent; - /** * @author ElgarL * - * Handle new world creation from other plugins - * + * Handle new world creation from other plugins + * */ public class GMWorldListener implements Listener { - + private final GroupManager plugin; public GMWorldListener(GroupManager instance) { + plugin = instance; registerEvents(); } - + private void registerEvents() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - + + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + @EventHandler(priority = EventPriority.LOWEST) public void onWorldInit(WorldInitEvent event) { - String worldName = event.getWorld().getName(); - - if (GroupManager.isLoaded() && !plugin.getWorldsHolder().isInList(worldName)) { + + String worldName = event.getWorld().getName(); + + if (GroupManager.isLoaded() && !plugin.getWorldsHolder().isInList(worldName)) { GroupManager.logger.info("New world detected..."); GroupManager.logger.info("Creating data for: " + worldName); plugin.getWorldsHolder().setupWorldFolder(worldName); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java index 3a4d8d266..5fc555cc4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java @@ -3,40 +3,51 @@ package org.anjocaido.groupmanager.events; import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.data.User; - /** * @author ElgarL * - * Handles all Event generation. - * + * Handles all Event generation. + * */ public class GroupManagerEventHandler { - + protected static void callEvent(GMGroupEvent event) { + event.schedule(event); } + protected static void callEvent(GMUserEvent event) { + event.schedule(event); } + protected static void callEvent(GMSystemEvent event) { + event.schedule(event); } public static void callEvent(Group group, GMGroupEvent.Action action) { + callEvent(new GMGroupEvent(group, action)); } + public static void callEvent(String groupName, GMGroupEvent.Action action) { + callEvent(new GMGroupEvent(groupName, action)); } - + public static void callEvent(User user, GMUserEvent.Action action) { + callEvent(new GMUserEvent(user, action)); } + public static void callEvent(String userName, GMUserEvent.Action action) { + callEvent(new GMUserEvent(userName, action)); } - + public static void callEvent(GMSystemEvent.Action action) { + callEvent(new GMSystemEvent(action)); } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index b40694bb0..2f64e4d99 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -39,6 +39,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @param holder */ public AnjoPermissionsHandler(WorldDataHolder holder) { + ph = holder; } @@ -51,6 +52,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean has(Player player, String permission) { + return permission(player, permission); } @@ -63,6 +65,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean permission(Player player, String permission) { + return checkUserPermission(ph.getUser(player.getName()).updatePlayer(player), permission); } @@ -74,6 +77,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return true if the player has the permission */ public boolean permission(String playerName, String permission) { + return checkUserPermission(ph.getUser(playerName), permission); } @@ -85,6 +89,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroup(String userName) { + return ph.getUser(userName).getGroup().getName(); } @@ -97,10 +102,11 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public List getAllPlayersPermissions(String userName) { + List perms = new ArrayList(); - + perms.addAll(getAllPlayersPermissions(userName, true)); - + return perms; } @@ -118,33 +124,32 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { // Add the players own permissions. playerPermArray.addAll(populatePerms(ph.getUser(userName).getPermissionList(), includeChildren)); - + ArrayList alreadyProcessed = new ArrayList(); - + // fetch all group permissions for (String group : getGroups(userName)) { // Don't process a group more than once. if (!alreadyProcessed.contains(group)) { alreadyProcessed.add(group); - + Set groupPermArray = new HashSet(); - + if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) { // GlobalGroups groupPermArray = populatePerms(GroupManager.getGlobalGroups().getGroupsPermissions(group), includeChildren); - + } else { // World Groups groupPermArray = populatePerms(ph.getGroup(group).getPermissionList(), includeChildren); } - + // Add all group permissions, unless negated by earlier permissions. for (String perm : groupPermArray) { boolean negated = (perm.startsWith("-")); // Perm doesn't already exists and there is no negation for it // or It's a negated perm where a normal perm doesn't exists (don't allow inheritance to negate higher perms) - if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm)) - || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm))) + if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm)) || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm))) playerPermArray.add(perm); } } @@ -154,68 +159,69 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return playerPermArray; } - - private Set populatePerms (List permsList, boolean includeChildren) { - + + private Set populatePerms(List permsList, boolean includeChildren) { + // Create a new array so it's modifiable. List perms = new ArrayList(permsList); Set permArray = new HashSet(); Boolean allPerms = false; - + // Allow * node to populate ALL permissions to Bukkit. if (perms.contains("*")) { permArray.addAll(GroupManager.BukkitPermissions.getAllRegisteredPermissions(includeChildren)); allPerms = true; perms.remove("*"); } - + for (String perm : perms) { - + + /** + * all permission sets are passed here pre-sorted, alphabetically. + * This means negated nodes will be processed before all permissions + * other than *. + */ + boolean negated = perm.startsWith("-"); + + if (!permArray.contains(perm)) { + permArray.add(perm); + + if ((negated) && (permArray.contains(perm.substring(1)))) + permArray.remove(perm.substring(1)); + /** - * all permission sets are passed here pre-sorted, alphabetically. - * This means negated nodes will be processed before all permissions - * other than *. + * Process child nodes if required, + * or this is a negated node AND we used * to include all + * permissions, + * in which case we need to remove all children of that node. */ - boolean negated = perm.startsWith("-"); - - if (!permArray.contains(perm)) { - permArray.add(perm); - - if ((negated) && (permArray.contains(perm.substring(1)))) - permArray.remove(perm.substring(1)); - - /** - * Process child nodes if required, - * or this is a negated node AND we used * to include all permissions, - * in which case we need to remove all children of that node. - */ - if ((includeChildren) || (negated && allPerms)) { - - Map children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet()); - - if (children != null) { - if (negated) - if (allPerms) { - - // Remove children of negated nodes - for (String child : children.keySet()) - if (children.get(child)) - if (permArray.contains(child)) - permArray.remove(child); - + if ((includeChildren) || (negated && allPerms)) { + + Map children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet()); + + if (children != null) { + if (negated) + if (allPerms) { + + // Remove children of negated nodes + for (String child : children.keySet()) + if (children.get(child)) + if (permArray.contains(child)) + permArray.remove(child); + } else { - + // Add child nodes for (String child : children.keySet()) if (children.get(child)) if ((!permArray.contains(child)) && (!permArray.contains("-" + child))) permArray.add(child); } - } } } + } } - + return permArray; } @@ -236,6 +242,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean inGroup(String name, String group) { + if (hasGroupInInheritance(ph.getUser(name).getGroup(), group)) { return true; } @@ -326,6 +333,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroupPrefix(String groupName) { + Group g = ph.getGroup(groupName); if (g == null) { return ""; @@ -341,6 +349,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroupSuffix(String groupName) { + Group g = ph.getGroup(groupName); if (g == null) { return ""; @@ -357,6 +366,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean canGroupBuild(String groupName) { + Group g = ph.getGroup(groupName); if (g == null) { return false; @@ -374,6 +384,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroupPermissionString(String groupName, String variable) { + Group start = ph.getGroup(groupName); if (start == null) { return null; @@ -395,6 +406,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public int getGroupPermissionInteger(String groupName, String variable) { + Group start = ph.getGroup(groupName); if (start == null) { return -1; @@ -416,6 +428,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean getGroupPermissionBoolean(String group, String variable) { + Group start = ph.getGroup(group); if (start == null) { return false; @@ -437,6 +450,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public double getGroupPermissionDouble(String group, String variable) { + Group start = ph.getGroup(group); if (start == null) { return -1; @@ -457,6 +471,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getUserPermissionString(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return ""; @@ -473,6 +488,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public int getUserPermissionInteger(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1; @@ -489,6 +505,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean getUserPermissionBoolean(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return false; @@ -505,6 +522,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public double getUserPermissionDouble(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1; @@ -523,6 +541,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getPermissionString(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return ""; @@ -562,6 +581,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public int getPermissionInteger(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1; @@ -601,6 +621,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean getPermissionBoolean(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return false; @@ -640,6 +661,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public double getPermissionDouble(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1.0D; @@ -676,6 +698,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult */ public PermissionCheckResult checkUserOnlyPermission(User user, String permission) { + user.sortPermissions(); PermissionCheckResult result = new PermissionCheckResult(); result.askedPermission = permission; @@ -699,6 +722,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return the node if permission is found. if not found, return null */ public PermissionCheckResult checkGroupOnlyPermission(Group group, String permission) { + group.sortPermissions(); PermissionCheckResult result = new PermissionCheckResult(); result.owner = group; @@ -721,6 +745,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return true if permission was found. false if not, or was negated. */ public boolean checkUserPermission(User user, String permission) { + PermissionCheckResult result = checkFullGMPermission(user, permission, true); if (result.resultType == PermissionCheckResult.Type.EXCEPTION || result.resultType == PermissionCheckResult.Type.FOUND) { return true; @@ -752,6 +777,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult */ public PermissionCheckResult checkFullGMPermission(User user, String targetPermission, Boolean checkBukkit) { + PermissionCheckResult result = new PermissionCheckResult(); result.accessLevel = targetPermission; result.resultType = PermissionCheckResult.Type.NOTFOUND; @@ -813,6 +839,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public Group nextGroupWithVariable(Group start, String variable, List alreadyChecked) { + return nextGroupWithVariable(start, variable); } @@ -829,6 +856,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return The group if found. Null if not. */ public Group nextGroupWithVariable(Group start, String targetVariable) { + if (start == null || targetVariable == null) { return null; } @@ -870,6 +898,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public boolean searchGroupInInheritance(Group start, String askedGroup, List alreadyChecked) { + return hasGroupInInheritance(start, askedGroup); } @@ -885,6 +914,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return true if it inherits the group. */ public boolean hasGroupInInheritance(Group start, String askedGroup) { + if (start == null || askedGroup == null) { return false; } @@ -920,6 +950,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public boolean checkGroupPermissionWithInheritance(Group start, String permission, List alreadyChecked) { + PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) { return true; @@ -942,6 +973,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult */ public PermissionCheckResult checkGroupPermissionWithInheritance(Group start, String targetPermission) { + if (start == null || targetPermission == null) { return null; } @@ -982,6 +1014,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public Group nextGroupWithPermission(Group start, String permission, List alreadyChecked) { + PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) { return (Group) checkGroupPermissionWithInheritance(start, permission).owner; @@ -1003,6 +1036,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public ArrayList listAllGroupsInherited(Group start, ArrayList alreadyChecked) { + return listAllGroupsInherited(start); } @@ -1016,6 +1050,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return the group that passed on test. null if no group passed. */ public ArrayList listAllGroupsInherited(Group start) { + if (start == null) { return null; } @@ -1055,6 +1090,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult.Type */ public PermissionCheckResult.Type comparePermissionString(String userAccessLevel, String fullPermissionName) { + int userAccessLevelLength; if (userAccessLevel == null || fullPermissionName == null || fullPermissionName.length() == 0 || (userAccessLevelLength = userAccessLevel.length()) == 0) { return PermissionCheckResult.Type.NOTFOUND; @@ -1080,12 +1116,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { } if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') { - return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ? - result : PermissionCheckResult.Type.NOTFOUND; + return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ? result : PermissionCheckResult.Type.NOTFOUND; } else { - return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, - Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ? - result : PermissionCheckResult.Type.NOTFOUND; + return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ? result : PermissionCheckResult.Type.NOTFOUND; } } @@ -1099,6 +1132,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String[] getGroups(String userName) { + ArrayList allGroups = listAllGroupsInherited(ph.getUser(userName).getGroup()); for (Group subg : ph.getUser(userName).subGroupListCopy()) { allGroups.addAll(listAllGroupsInherited(subg)); @@ -1120,6 +1154,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @SuppressWarnings("unused") private Group breadthFirstSearch(Group start, String targerPermission) { + if (start == null || targerPermission == null) { return null; } @@ -1149,11 +1184,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public Group getDefaultGroup() { + return ph.getDefaultGroup(); } @Override public String getInfoString(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1171,6 +1208,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public int getInfoInteger(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1188,6 +1226,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public double getInfoDouble(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1206,6 +1245,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public boolean getInfoBoolean(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1223,21 +1263,25 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public void addUserInfo(String name, String path, Object data) { + ph.getUser(name).getVariables().addVar(path, data); } @Override public void removeUserInfo(String name, String path) { + ph.getUser(name).getVariables().removeVar(path); } @Override public void addGroupInfo(String name, String path, Object data) { + ph.getGroup(name).getVariables().addVar(path, data); } @Override public void removeGroupInfo(String name, String path) { + ph.getGroup(name).getVariables().removeVar(path); } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 516679544..c366b65bf 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -1,18 +1,19 @@ /* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ package org.anjocaido.groupmanager.permissions; @@ -47,7 +48,6 @@ import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.PluginManager; - /** * * BukkitPermissions overrides to force GM reponses to Superperms @@ -62,11 +62,12 @@ public class BukkitPermissions { protected boolean dumpAllPermissions = true; protected boolean dumpMatchedPermissions = true; private boolean player_join = false; - + /** * @return the player_join */ public boolean isPlayer_join() { + return player_join; } @@ -74,6 +75,7 @@ public class BukkitPermissions { * @param player_join the player_join to set */ public void setPlayer_join(boolean player_join) { + this.player_join = player_join; } @@ -92,6 +94,7 @@ public class BukkitPermissions { } public BukkitPermissions(GroupManager plugin) { + this.plugin = plugin; this.collectPermissions(); this.registerEvents(); @@ -101,35 +104,38 @@ public class BukkitPermissions { } private void registerEvents() { + PluginManager manager = plugin.getServer().getPluginManager(); manager.registerEvents(new PlayerEvents(), plugin); manager.registerEvents(new BukkitEvents(), plugin); } - public void collectPermissions() { + registeredPermissions.clear(); for (Permission perm : Bukkit.getPluginManager().getPermissions()) { - registeredPermissions.put(perm.getName().toLowerCase(), perm); + registeredPermissions.put(perm.getName().toLowerCase(), perm); } - + } public void updatePermissions(Player player) { + this.updatePermissions(player, null); } - /** - * Push all permissions which are registered with GM for this player, on this world to Bukkit + * Push all permissions which are registered with GM for this player, on + * this world to Bukkit * and make it update for the child nodes. * * @param player * @param world */ public void updatePermissions(Player player, String world) { + if (player == null || !GroupManager.isLoaded()) { return; } @@ -155,17 +161,18 @@ public class BukkitPermissions { // Sort the perm list by parent/child, so it will push to superperms correctly. playerPermArray = sort(playerPermArray); - + Boolean value = false; - for (String permission : playerPermArray) { + for (String permission : playerPermArray) { value = (!permission.startsWith("-")); - newPerms.put((value? permission : permission.substring(1)), value); + newPerms.put((value ? permission : permission.substring(1)), value); } /** - * This is put in place until such a time as Bukkit pull 466 is implemented - * https://github.com/Bukkit/Bukkit/pull/466 - */ + * This is put in place until such a time as Bukkit pull 466 is + * implemented + * https://github.com/Bukkit/Bukkit/pull/466 + */ try { // Codename_B source @SuppressWarnings("unchecked") Map orig = (Map) permissions.get(attachment); @@ -182,7 +189,7 @@ public class BukkitPermissions { e.printStackTrace(); } } - + /** * Sort a permission node list by parent/child * @@ -190,20 +197,20 @@ public class BukkitPermissions { * @return List sorted for priority */ private List sort(List permList) { - + List result = new ArrayList(); - + for (String key : permList) { - String a = key.charAt(0) == '-'? key.substring(1):key; + String a = key.charAt(0) == '-' ? key.substring(1) : key; Map allchildren = GroupManager.BukkitPermissions.getAllChildren(a, new HashSet()); if (allchildren != null) { ListIterator itr = result.listIterator(); - - while (itr.hasNext()){ + + while (itr.hasNext()) { String node = (String) itr.next(); - String b = node.charAt(0) == '-'? node.substring(1):node; - + String b = node.charAt(0) == '-' ? node.substring(1) : node; + // Insert the parent node before the child if (allchildren.containsKey(b)) { itr.set(key); @@ -215,11 +222,10 @@ public class BukkitPermissions { if (!result.contains(key)) result.add(key); } - + return result; } - /** * Fetch all permissions which are registered with superperms. * {can include child nodes) @@ -228,13 +234,13 @@ public class BukkitPermissions { * @return List of all permission nodes */ public List getAllRegisteredPermissions(boolean includeChildren) { - + List perms = new ArrayList(); - + for (String key : registeredPermissions.keySet()) { if (!perms.contains(key)) { perms.add(key); - + if (includeChildren) { Map children = getAllChildren(key, new HashSet()); if (children != null) { @@ -244,32 +250,33 @@ public class BukkitPermissions { } } } - + } return perms; } - + /** * Returns a map of ALL child permissions registered with bukkit * null is empty * * @param node - * @param playerPermArray current list of perms to check against for negations + * @param playerPermArray current list of perms to check against for + * negations * @return Map of child permissions */ public Map getAllChildren(String node, Set playerPermArray) { - + LinkedList stack = new LinkedList(); Map alreadyVisited = new HashMap(); stack.push(node); alreadyVisited.put(node, true); - + while (!stack.isEmpty()) { String now = stack.pop(); - + Map children = getChildren(now); - - if ((children != null) && (!playerPermArray.contains("-"+now))) { + + if ((children != null) && (!playerPermArray.contains("-" + now))) { for (String childName : children.keySet()) { if (!alreadyVisited.containsKey(childName)) { stack.push(childName); @@ -279,24 +286,26 @@ public class BukkitPermissions { } } alreadyVisited.remove(node); - if (!alreadyVisited.isEmpty()) return alreadyVisited; - + if (!alreadyVisited.isEmpty()) + return alreadyVisited; + return null; } - + /** - * Returns a map of the child permissions (1 node deep) as registered with Bukkit. + * Returns a map of the child permissions (1 node deep) as registered with + * Bukkit. * null is empty * * @param node * @return Map of child permissions */ public Map getChildren(String node) { - + Permission perm = registeredPermissions.get(node.toLowerCase()); if (perm == null) return null; - + return perm.getChildren(); } @@ -308,6 +317,7 @@ public class BukkitPermissions { * @return List of permissions */ public List listPerms(Player player) { + List perms = new ArrayList(); /* @@ -332,25 +342,28 @@ public class BukkitPermissions { * force Bukkit to update every OnlinePlayers permissions. */ public void updateAllPlayers() { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { updatePermissions(player); } } - + /** * force Bukkit to update this Players permissions. */ public void updatePlayer(Player player) { + if (player != null) this.updatePermissions(player, null); } - + /** * Force remove any attachments * * @param player */ private void removeAttachment(Player player) { + if (attachments.containsKey(player)) { try { player.removeAttachment(attachments.get(player)); @@ -363,15 +376,15 @@ public class BukkitPermissions { attachments.remove(player); } } - + /** * Remove all attachments in case of a restart or reload. */ public void removeAllAttachments() { - + Iterator itr = attachments.keySet().iterator(); - - while (itr.hasNext()){ + + while (itr.hasNext()) { Player player = itr.next(); try { player.removeAttachment(attachments.get(player)); @@ -389,20 +402,21 @@ public class BukkitPermissions { * Player events tracked to cause Superperms updates * * @author ElgarL - * + * */ protected class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { + setPlayer_join(true); Player player = event.getPlayer(); - + /* * Tidy up any lose ends */ removeAttachment(player); - + // force GM to create the player if they are not already listed. if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) { setPlayer_join(false); @@ -410,29 +424,32 @@ public class BukkitPermissions { } setPlayer_join(false); } - + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerChangeWorld(PlayerChangedWorldEvent event) { // has changed worlds + updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName()); } @EventHandler(priority = EventPriority.LOWEST) public void onPlayerKick(PlayerKickEvent event) { + Player player = event.getPlayer(); - + /* * force remove any attachments as bukkit may not */ removeAttachment(player); } - + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerQuit(PlayerQuitEvent event) { + if (!GroupManager.isLoaded()) return; Player player = event.getPlayer(); - + /* * force remove any attachments as bukkit may not */ @@ -444,6 +461,7 @@ public class BukkitPermissions { @EventHandler(priority = EventPriority.NORMAL) public void onPluginEnable(PluginEnableEvent event) { + if (!GroupManager.isLoaded()) return; @@ -453,6 +471,7 @@ public class BukkitPermissions { @EventHandler(priority = EventPriority.NORMAL) public void onPluginDisable(PluginDisableEvent event) { + collectPermissions(); // updateAllPlayers(); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java index 3f49757e2..69f098949 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java @@ -12,227 +12,239 @@ import org.bukkit.entity.Player; /** * Made by Nijikokun. Changed by Gabriel Couto - * + * * This class is intended to *read* permissions from a single world. - * + * * @author Nijikokun * @author Gabriel Couto * @author ElgarL */ public abstract class PermissionsReaderInterface { - /** - * - * @param player - * @param string - * @return true if has permission - */ - public abstract boolean has(Player player, String string); - - /** - * - * @param player - * @param string - * @return true if has permission - */ - public abstract boolean permission(Player player, String string); - - /** - * - * @param userName - * @return group name for this player. - */ - public abstract String getGroup(String userName); - - /** - * - * @param userName - * @param groupName - * @return true if in group - */ - public abstract boolean inGroup(String userName, String groupName); - - /** - * - * @param groupName - * @return String of prefix - */ - public abstract String getGroupPrefix(String groupName); - - /** - * - * @param groupName - * @return String of suffix - */ - public abstract String getGroupSuffix(String groupName); - - /** - * - * @param groupName - * @return true if can build - */ - public abstract boolean canGroupBuild(String groupName); - - /** - * - * @param groupName - * @param node - * @return String value - */ - public abstract String getGroupPermissionString(String groupName, String node); - - /** - * - * @param groupName - * @param node - * @return integer value - */ - public abstract int getGroupPermissionInteger(String groupName, String node); - - /** - * - * @param groupName - * @param node - * @return boolean value - */ - public abstract boolean getGroupPermissionBoolean(String groupName, String node); - - /** - * - * @param groupName - * @param node - * @return double value - */ - public abstract double getGroupPermissionDouble(String groupName, String node); - - /** - * - * @param userName - * @param node - * @return String value - */ - public abstract String getUserPermissionString(String userName, String node); - - /** - * - * @param userName - * @param node - * @return integer value - */ - public abstract int getUserPermissionInteger(String userName, String node); - - /** - * - * @param userName - * @param node - * @return boolean value - */ - public abstract boolean getUserPermissionBoolean(String userName, String node); - - /** - * - * @param userName - * @param node - * @return double value - */ - public abstract double getUserPermissionDouble(String userName, String node); - - /** - * - * @param userName - * @param node - * @return String value - */ - public abstract String getPermissionString(String userName, String node); - - /** - * - * @param userName - * @param node - * @return integer value - */ - public abstract int getPermissionInteger(String userName, String node); - - /** - * - * @param userName - * @param node - * @return boolean value - */ - public abstract boolean getPermissionBoolean(String userName, String node); - - /** - * - * @param userName - * @param node - * @return double value - */ - public abstract double getPermissionDouble(String userName, String node); - -///////////////////////////// - /** - * Gets the appropriate prefix for the user. - * This method is a utility method for chat plugins to get the user's prefix - * without having to look at every one of the user's ancestors. - * Returns an empty string if user has no parent groups. - * - * @param user Player's name - * @return Player's prefix - */ - public abstract String getUserPrefix(String user); - - /** - * Gets the appropriate suffix for the user. - * This method is a utility method for chat plugins to get the user's suffix - * without having to look at every one of the user's ancestors. - * Returns an empty string if user has no parent groups. - * - * @param user Player's name - * @return Player's suffix - */ - public abstract String getUserSuffix(String user); - - /** - * Returns the group object representing the default group of the given world. - * This method will return null if the object does not exist or the world has no default group. - * @return Group object representing default world, or null if it doesn't exist or is not defined. - */ - public abstract Group getDefaultGroup(); - - /** - * Gets a array of the names of all parent groups in the same world. - * @param name Target user's name - * @return An array containing the names of all parent groups (including ancestors) that are in the same world - */ - public abstract String[] getGroups(String name); - - public abstract String getInfoString(String entryName, String path, boolean isGroup); - //public abstract String getInfoString(String entryName, String path, boolean isGroup, Comparator comparator); - - public abstract int getInfoInteger(String entryName, String path, boolean isGroup); - //public abstract int getInfoInteger(String entryName, String path, boolean isGroup, Comparator comparator); - - /** - * Gets a double from the Info node without inheritance. - * @param entryName - * @param path - * @param isGroup - * @return -1 if not found - */ - public abstract double getInfoDouble(String entryName, String path, boolean isGroup); - //public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator comparator); - - public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup); - //public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup, Comparator comparator); - - public abstract void addUserInfo(String name, String path, Object data); - - public abstract void removeUserInfo(String name, String path); - - public abstract void addGroupInfo(String name, String path, Object data); - - public abstract void removeGroupInfo(String name, String path); -////////////////////////////// + /** + * + * @param player + * @param string + * @return true if has permission + */ + public abstract boolean has(Player player, String string); + + /** + * + * @param player + * @param string + * @return true if has permission + */ + public abstract boolean permission(Player player, String string); + + /** + * + * @param userName + * @return group name for this player. + */ + public abstract String getGroup(String userName); + + /** + * + * @param userName + * @param groupName + * @return true if in group + */ + public abstract boolean inGroup(String userName, String groupName); + + /** + * + * @param groupName + * @return String of prefix + */ + public abstract String getGroupPrefix(String groupName); + + /** + * + * @param groupName + * @return String of suffix + */ + public abstract String getGroupSuffix(String groupName); + + /** + * + * @param groupName + * @return true if can build + */ + public abstract boolean canGroupBuild(String groupName); + + /** + * + * @param groupName + * @param node + * @return String value + */ + public abstract String getGroupPermissionString(String groupName, String node); + + /** + * + * @param groupName + * @param node + * @return integer value + */ + public abstract int getGroupPermissionInteger(String groupName, String node); + + /** + * + * @param groupName + * @param node + * @return boolean value + */ + public abstract boolean getGroupPermissionBoolean(String groupName, String node); + + /** + * + * @param groupName + * @param node + * @return double value + */ + public abstract double getGroupPermissionDouble(String groupName, String node); + + /** + * + * @param userName + * @param node + * @return String value + */ + public abstract String getUserPermissionString(String userName, String node); + + /** + * + * @param userName + * @param node + * @return integer value + */ + public abstract int getUserPermissionInteger(String userName, String node); + + /** + * + * @param userName + * @param node + * @return boolean value + */ + public abstract boolean getUserPermissionBoolean(String userName, String node); + + /** + * + * @param userName + * @param node + * @return double value + */ + public abstract double getUserPermissionDouble(String userName, String node); + + /** + * + * @param userName + * @param node + * @return String value + */ + public abstract String getPermissionString(String userName, String node); + + /** + * + * @param userName + * @param node + * @return integer value + */ + public abstract int getPermissionInteger(String userName, String node); + + /** + * + * @param userName + * @param node + * @return boolean value + */ + public abstract boolean getPermissionBoolean(String userName, String node); + + /** + * + * @param userName + * @param node + * @return double value + */ + public abstract double getPermissionDouble(String userName, String node); + + ///////////////////////////// + /** + * Gets the appropriate prefix for the user. + * This method is a utility method for chat plugins to get the user's prefix + * without having to look at every one of the user's ancestors. + * Returns an empty string if user has no parent groups. + * + * @param user Player's name + * @return Player's prefix + */ + public abstract String getUserPrefix(String user); + + /** + * Gets the appropriate suffix for the user. + * This method is a utility method for chat plugins to get the user's suffix + * without having to look at every one of the user's ancestors. + * Returns an empty string if user has no parent groups. + * + * @param user Player's name + * @return Player's suffix + */ + public abstract String getUserSuffix(String user); + + /** + * Returns the group object representing the default group of the given + * world. + * This method will return null if the object does not exist or the world + * has no default group. + * + * @return Group object representing default world, or null if it doesn't + * exist or is not defined. + */ + public abstract Group getDefaultGroup(); + + /** + * Gets a array of the names of all parent groups in the same world. + * + * @param name Target user's name + * @return An array containing the names of all parent groups (including + * ancestors) that are in the same world + */ + public abstract String[] getGroups(String name); + + public abstract String getInfoString(String entryName, String path, boolean isGroup); + + //public abstract String getInfoString(String entryName, String path, boolean isGroup, Comparator comparator); + + public abstract int getInfoInteger(String entryName, String path, boolean isGroup); + + //public abstract int getInfoInteger(String entryName, String path, boolean isGroup, Comparator comparator); + + /** + * Gets a double from the Info node without inheritance. + * + * @param entryName + * @param path + * @param isGroup + * @return -1 if not found + */ + public abstract double getInfoDouble(String entryName, String path, boolean isGroup); + + //public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator comparator); + + public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup); + + //public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup, Comparator comparator); + + public abstract void addUserInfo(String name, String path, Object data); + + public abstract void removeUserInfo(String name, String path); + + public abstract void addGroupInfo(String name, String path, Object data); + + public abstract void removeGroupInfo(String name, String path); + + ////////////////////////////// public abstract List getAllPlayersPermissions(String userName); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java index 87b6806ab..de5348b17 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java @@ -9,18 +9,19 @@ import java.util.logging.Level; import java.util.logging.LogRecord; /** - * + * * @author gabrielcouto */ public class GMLoggerHandler extends ConsoleHandler { - @Override - public void publish(LogRecord record) { - String message = "GroupManager - " + record.getLevel() + " - " + record.getMessage(); - if (record.getLevel().equals(Level.SEVERE) || record.getLevel().equals(Level.WARNING)) { - System.err.println(message); - } else { - System.out.println(message); - } - } + @Override + public void publish(LogRecord record) { + + String message = "GroupManager - " + record.getLevel() + " - " + record.getMessage(); + if (record.getLevel().equals(Level.SEVERE) || record.getLevel().equals(Level.WARNING)) { + System.err.println(message); + } else { + System.out.println(message); + } + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java index 0262bb33e..f8cef89c7 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java @@ -6,47 +6,10 @@ package org.anjocaido.groupmanager.utils; /** * Just a list of commands for this plugin + * * @author gabrielcouto */ public enum GroupManagerPermissions { - manuadd, - manudel, - manuaddsub, - manudelsub, - mangadd, - mangdel, - manuaddp, - manudelp, - manulistp, - manucheckp, - mangaddp, - mangdelp, - manglistp, - mangcheckp, - mangaddi, - mangdeli, - manuaddv, - manudelv, - manulistv, - manucheckv, - mangaddv, - mangdelv, - manglistv, - mangcheckv, - manwhois, - tempadd, - tempdel, - templist, - tempdelall, - mansave, - manload, - listgroups, - manpromote, - mandemote, - mantogglevalidate, - mantogglesave, - manworld, - manselect, - manclear + manuadd, manudel, manuaddsub, manudelsub, mangadd, mangdel, manuaddp, manudelp, manulistp, manucheckp, mangaddp, mangdelp, manglistp, mangcheckp, mangaddi, mangdeli, manuaddv, manudelv, manulistv, manucheckv, mangaddv, mangdelv, manglistv, mangcheckv, manwhois, tempadd, tempdel, templist, tempdelall, mansave, manload, listgroups, manpromote, mandemote, mantogglevalidate, mantogglesave, manworld, manselect, manclear } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java index 88ac48427..eb6633863 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java @@ -7,61 +7,61 @@ package org.anjocaido.groupmanager.utils; import org.anjocaido.groupmanager.data.DataUnit; /** - * + * * @author gabrielcouto */ public class PermissionCheckResult { - /** - * It should be the owner of the access level found. - * - * Use instanceof to find the owner type - */ - public DataUnit owner; - /** - * The permission node found in the DataUnit. - */ - public String accessLevel; - /** - * The full name of the permission you are looking for - */ - public String askedPermission; - /** - * The result conclusion of the search. - * It determines if the owner can do, or not. - * - * It even determines if it has an owner. - */ - public Type resultType = Type.NOTFOUND; + /** + * It should be the owner of the access level found. + * + * Use instanceof to find the owner type + */ + public DataUnit owner; + /** + * The permission node found in the DataUnit. + */ + public String accessLevel; + /** + * The full name of the permission you are looking for + */ + public String askedPermission; + /** + * The result conclusion of the search. + * It determines if the owner can do, or not. + * + * It even determines if it has an owner. + */ + public Type resultType = Type.NOTFOUND; - /** - * The type of result the search can give. - */ - public enum Type { + /** + * The type of result the search can give. + */ + public enum Type { - /** - * If found a matching node starting with '+'. - * It means the user CAN do the permission. - */ - EXCEPTION, - /** - * If found a matching node starting with '-'. - * It means the user CANNOT do the permission. - */ - NEGATION, - /** - * If just found a common matching node. - * IT means the user CAN do the permission. - */ - FOUND, - /** - * If no matchin node was found. - * It means the user CANNOT do the permission. - * - * owner field and accessLevel field should not be considered, - * when type is - * NOTFOUND - */ - NOTFOUND - } + /** + * If found a matching node starting with '+'. + * It means the user CAN do the permission. + */ + EXCEPTION, + /** + * If found a matching node starting with '-'. + * It means the user CANNOT do the permission. + */ + NEGATION, + /** + * If just found a common matching node. + * IT means the user CAN do the permission. + */ + FOUND, + /** + * If no matchin node was found. + * It means the user CANNOT do the permission. + * + * owner field and accessLevel field should not be considered, + * when type is + * NOTFOUND + */ + NOTFOUND + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java index ab2fd605b..5a56cd9fc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java @@ -7,43 +7,46 @@ package org.anjocaido.groupmanager.utils; import java.util.Comparator; /** - * + * * @author gabrielcouto */ public class StringPermissionComparator implements Comparator { - @Override - public int compare(String permA, String permB) { - boolean ap = permA.startsWith("+"); - boolean bp = permB.startsWith("+"); - boolean am = permA.startsWith("-"); - boolean bm = permB.startsWith("-"); - if (ap && bp) { - return 0; - } - if (ap && !bp) { - return -1; - } - if (!ap && bp) { - return 1; - } - if (am && bm) { - return 0; - } - if (am && !bm) { - return -1; - } - if (!am && bm) { - return 1; - } - return permA.compareToIgnoreCase(permB); - } - private static StringPermissionComparator instance; + @Override + public int compare(String permA, String permB) { - public static StringPermissionComparator getInstance() { - if (instance == null) { - instance = new StringPermissionComparator(); - } - return instance; - } + boolean ap = permA.startsWith("+"); + boolean bp = permB.startsWith("+"); + boolean am = permA.startsWith("-"); + boolean bm = permB.startsWith("-"); + if (ap && bp) { + return 0; + } + if (ap && !bp) { + return -1; + } + if (!ap && bp) { + return 1; + } + if (am && bm) { + return 0; + } + if (am && !bm) { + return -1; + } + if (!am && bm) { + return 1; + } + return permA.compareToIgnoreCase(permB); + } + + private static StringPermissionComparator instance; + + public static StringPermissionComparator getInstance() { + + if (instance == null) { + instance = new StringPermissionComparator(); + } + return instance; + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java index 663da1123..d75737c66 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java @@ -22,13 +22,12 @@ import java.util.List; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; - /** - * + * * @author gabrielcouto */ public abstract class Tasks { - + /** * Gets the exception stack trace as a string. * @@ -36,35 +35,38 @@ public abstract class Tasks { * @return stack trace as a string */ public static String getStackTraceAsString(Exception exception) { + StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); return sw.toString(); } - public static void copy(InputStream src, File dst) throws IOException { - InputStream in = src; - OutputStream out = new FileOutputStream(dst); - - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.close(); - try { - in.close(); - } catch (Exception e) { - } - } - - public static void copy(File src, File dst) throws IOException { - InputStream in = new FileInputStream(src); - copy(in, dst); - } - - /** + public static void copy(InputStream src, File dst) throws IOException { + + InputStream in = src; + OutputStream out = new FileOutputStream(dst); + + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + out.close(); + try { + in.close(); + } catch (Exception e) { + } + } + + public static void copy(File src, File dst) throws IOException { + + InputStream in = new FileInputStream(src); + copy(in, dst); + } + + /** * Appends a string to a file * * @param data @@ -82,86 +84,92 @@ public abstract class Tasks { out.append(System.getProperty("line.separator")); out.append(data); out.append(System.getProperty("line.separator")); - + out.close(); } - public static void removeOldFiles(GroupManager gm, File folder) { - if (folder.isDirectory()) { - long oldTime = System.currentTimeMillis() - (((long)gm.getGMConfig().getBackupDuration()*60*60)*1000); - for (File olds : folder.listFiles()) { - if (olds.isFile()) { - if (olds.lastModified() < oldTime) { - try { - olds.delete(); - } catch (Exception e) { - } - } - } - } - } - } - - public static String getDateString() { - GregorianCalendar now = new GregorianCalendar(); - String date = ""; - date += now.get(Calendar.DAY_OF_MONTH); - date += "-"; - date += now.get(Calendar.HOUR); - date += "-"; - date += now.get(Calendar.MINUTE); - return date; - } - - public static String getStringListInString(List list) { - if (list == null) { - return ""; - } - String result = ""; - for (int i = 0; i < list.size(); i++) { - result += list.get(i); - if (i < list.size() - 1) { - result += ", "; - } - } - return result; - } - - public static String getStringArrayInString(String[] list) { - if (list == null) { - return ""; - } - String result = ""; - for (int i = 0; i < list.length; i++) { - result += list[i]; - if (i < ((list.length) - 1)) { - result += ", "; - } - } - return result; - } - - public static String getGroupListInString(List list) { - if (list == null) { - return ""; - } - String result = ""; - for (int i = 0; i < list.size(); i++) { - result += list.get(i).getName(); - if (i < list.size() - 1) { - result += ", "; - } - } - return result; - } - - public static String join(String[] arr, String separator) { - if (arr.length == 0) - return ""; - String out = arr[0].toString(); - for (int i = 1; i < arr.length; i++) - out += separator + arr[i]; - return out; - } + public static void removeOldFiles(GroupManager gm, File folder) { + + if (folder.isDirectory()) { + long oldTime = System.currentTimeMillis() - (((long) gm.getGMConfig().getBackupDuration() * 60 * 60) * 1000); + for (File olds : folder.listFiles()) { + if (olds.isFile()) { + if (olds.lastModified() < oldTime) { + try { + olds.delete(); + } catch (Exception e) { + } + } + } + } + } + } + + public static String getDateString() { + + GregorianCalendar now = new GregorianCalendar(); + String date = ""; + date += now.get(Calendar.DAY_OF_MONTH); + date += "-"; + date += now.get(Calendar.HOUR); + date += "-"; + date += now.get(Calendar.MINUTE); + return date; + } + + public static String getStringListInString(List list) { + + if (list == null) { + return ""; + } + String result = ""; + for (int i = 0; i < list.size(); i++) { + result += list.get(i); + if (i < list.size() - 1) { + result += ", "; + } + } + return result; + } + + public static String getStringArrayInString(String[] list) { + + if (list == null) { + return ""; + } + String result = ""; + for (int i = 0; i < list.length; i++) { + result += list[i]; + if (i < ((list.length) - 1)) { + result += ", "; + } + } + return result; + } + + public static String getGroupListInString(List list) { + + if (list == null) { + return ""; + } + String result = ""; + for (int i = 0; i < list.size(); i++) { + result += list.get(i).getName(); + if (i < list.size() - 1) { + result += ", "; + } + } + return result; + } + + public static String join(String[] arr, String separator) { + + if (arr.length == 0) + return ""; + String out = arr[0].toString(); + for (int i = 1; i < arr.length; i++) + out += separator + arr[i]; + return out; + } } -- cgit v1.2.3 From 08bff3ea5f46865907e08cb75c25360c95e8798e Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 14:57:23 +0100 Subject: Stop using our own deprecated methods as we tell others to do. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 5549fef17..790821fa1 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -177,4 +177,5 @@ v 2.0: - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. - - Update all code formatting to use tabs for indentation. \ No newline at end of file + - Update all code formatting to use tabs for indentation. + - Stop using our own deprecated methods as we tell others to do. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index b75c2242e..c9c8fcbd5 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -29,7 +29,6 @@ import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder; import org.anjocaido.groupmanager.events.GMSystemEvent; import org.anjocaido.groupmanager.events.GMWorldListener; import org.anjocaido.groupmanager.events.GroupManagerEventHandler; -import org.anjocaido.groupmanager.events.GMGroupEvent.Action; import org.anjocaido.groupmanager.utils.GMLoggerHandler; import org.anjocaido.groupmanager.utils.PermissionCheckResult; import org.anjocaido.groupmanager.utils.Tasks; @@ -40,15 +39,14 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; -@SuppressWarnings("unused") + /** * - * @author gabrielcouto + * @author gabrielcouto, ElgarL */ public class GroupManager extends JavaPlugin { @@ -79,7 +77,6 @@ public class GroupManager extends JavaPlugin { this.validateOnlinePlayer = validateOnlinePlayer; } - private boolean isReady = false; private static boolean isLoaded = false; protected GMConfiguration config; @@ -111,7 +108,8 @@ public class GroupManager extends JavaPlugin { } } - WorldEvents = null; + if (WorldEvents != null) + WorldEvents = null; // Remove all attachments before clearing if (BukkitPermissions != null) { @@ -366,7 +364,7 @@ public class GroupManager extends JavaPlugin { * @param cmd * @param args */ - @SuppressWarnings({ "deprecation" }) + //@SuppressWarnings({ "deprecation" }) @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { @@ -1131,7 +1129,7 @@ public class GroupManager extends JavaPlugin { } // Validating permission - if (permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { + if (permissionHandler.hasGroupInInheritance(auxGroup, auxGroup2.getName())) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " already inherits " + auxGroup2.getName() + " (might not be directly)"); return false; } @@ -1170,7 +1168,7 @@ public class GroupManager extends JavaPlugin { } // Validating permission - if (!permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) { + if (!permissionHandler.hasGroupInInheritance(auxGroup, auxGroup2.getName())) { sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + "."); return false; } @@ -1461,7 +1459,7 @@ public class GroupManager extends JavaPlugin { return false; } // Validating permission - auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1], null); + auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1]); if (auxGroup2 == null) { sender.sendMessage(ChatColor.RED + "The group doesn't have access to that variable!"); } -- cgit v1.2.3 From 2f74510cce37c80341a844763675ec4e2a0d6516 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 15:00:55 +0100 Subject: Code tidy --- .../src/org/anjocaido/groupmanager/GroupManager.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index c9c8fcbd5..747056c04 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -50,7 +50,6 @@ import org.bukkit.plugin.java.JavaPlugin; */ public class GroupManager extends JavaPlugin { - // private File configFile; private File backupFolder; private Runnable commiter; private ScheduledThreadPoolExecutor scheduler; @@ -88,15 +87,15 @@ public class GroupManager extends JavaPlugin { public static final Logger logger = Logger.getLogger(GroupManager.class.getName()); // PERMISSIONS FOR COMMAND BEING LOADED - OverloadedWorldHolder dataHolder = null; - AnjoPermissionsHandler permissionHandler = null; + private OverloadedWorldHolder dataHolder = null; + private AnjoPermissionsHandler permissionHandler = null; @Override public void onDisable() { setLoaded(false); - // Un-register this service. + // Unregister this service. this.getServer().getServicesManager().unregister(this.worldsHolder); disableScheduler(); // Shutdown before we save, so it doesn't interfere. @@ -123,7 +122,7 @@ public class GroupManager extends JavaPlugin { GroupManager.logger.removeHandler(ch); } - // @Override + @Override public void onEnable() { try { @@ -159,9 +158,8 @@ public class GroupManager extends JavaPlugin { enableScheduler(); /* - * Schedule a Bukiit Permissions update for 1 tick later. All - * plugins - * will be loaded by then + * Schedule a Bukkit Permissions update for 1 tick later. + * All plugins will be loaded by then */ if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { @@ -243,7 +241,6 @@ public class GroupManager extends JavaPlugin { private void prepareFileFields() { - // configFile = new File(this.getDataFolder(), "config.yml"); backupFolder = new File(this.getDataFolder(), "backup"); if (!backupFolder.exists()) { getBackupFolder().mkdirs(); @@ -364,7 +361,6 @@ public class GroupManager extends JavaPlugin { * @param cmd * @param args */ - //@SuppressWarnings({ "deprecation" }) @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { -- cgit v1.2.3 From 1e30f23ca6bf6bc2fb848088d50092f1ca1b70c2 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 15:16:08 +0100 Subject: Finally remove all deprecated methods. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GroupManager.java | 55 ---------- .../src/org/anjocaido/groupmanager/data/User.java | 13 --- .../dataholder/OverloadedWorldHolder.java | 1 - .../dataholder/worlds/WorldsHolder.java | 1 - .../permissions/AnjoPermissionsHandler.java | 113 +-------------------- 6 files changed, 7 insertions(+), 179 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 790821fa1..f900d5aa9 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -178,4 +178,5 @@ v 2.0: - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. - Update all code formatting to use tabs for indentation. - - Stop using our own deprecated methods as we tell others to do. \ No newline at end of file + - Stop using our own deprecated methods as we tell others to do. + - Finally remove all deprecated methods. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 747056c04..df46b70d0 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -12,7 +12,6 @@ import org.anjocaido.groupmanager.data.Variables; import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder; -import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -295,65 +294,11 @@ public class GroupManager extends JavaPlugin { } } - /** - * Use the WorldsHolder saveChanges directly instead Saves the data on file - */ - @Deprecated - public void commit() { - - if (worldsHolder != null) { - worldsHolder.saveChanges(); - } - } - - /** - * Use worlds holder to reload a specific world Reloads the data - */ - @Deprecated - public void reload() { - - worldsHolder.reloadAll(); - } - public WorldsHolder getWorldsHolder() { return worldsHolder; } - /** - * The handler in the interface created by AnjoCaido - * - * @return AnjoPermissionsHandler - */ - @Deprecated - public AnjoPermissionsHandler getPermissionHandler() { - - return worldsHolder.getDefaultWorld().getPermissionsHandler(); - } - - /** - * A simple interface, for ones that don't want to mess with overloading. - * Yet it is affected by overloading. But seamless. - * - * @return the dataholder with all information - */ - @Deprecated - public WorldDataHolder getData() { - - return worldsHolder.getDefaultWorld(); - } - - /** - * Use this if you want to play with overloading. - * - * @return a dataholder with overloading interface - */ - @Deprecated - public OverloadedWorldHolder getOverloadedClassData() { - - return worldsHolder.getDefaultWorld(); - } - /** * Called when a command registered by this plugin is received. * diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 25b3cb3fe..c10658fb0 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -108,19 +108,6 @@ public class User extends DataUnit implements Cloneable { return group; } - /** - * @param group - * the group to set - */ - @Deprecated - public void setGroup(String group) { - - this.group = group; - flagAsChanged(); - if (GroupManager.isLoaded()) - if (!GroupManager.BukkitPermissions.isPlayer_join()) - GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer()); - } /** * @param group diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java index c8a3eb3ae..84561b6e5 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java @@ -30,7 +30,6 @@ public class OverloadedWorldHolder extends WorldDataHolder { super(ph.getName()); this.setGroupsFile(ph.getGroupsFile()); this.setUsersFile(ph.getUsersFile()); - //this.setDefaultGroup(ph.getDefaultGroup()); this.groups = ph.groups; this.users = ph.users; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index ebacfdfac..37d0a8430 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -46,7 +46,6 @@ public class WorldsHolder { private Map mirrorsGroup = new HashMap(); private Map mirrorsUser = new HashMap(); - //private OverloadedWorldHolder defaultWorld; private String serverDefaultWorldName; private GroupManager plugin; private File worldsFolder; diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index 2f64e4d99..efad11df4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -16,7 +16,6 @@ import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.utils.PermissionCheckResult; -import org.anjocaido.groupmanager.utils.PermissionCheckResult.Type; import org.bukkit.entity.Player; /** @@ -27,7 +26,7 @@ import org.bukkit.entity.Player; * * It holds permissions only for one single world. * - * @author gabrielcouto + * @author gabrielcouto, ElgarL */ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @@ -824,35 +823,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return result; } - /** - * Verifies if a given group has a variable. Including it's inheritance. - * - * it redirects to the other method now. This one was deprecated, and will - * be gone in a future release. - * - * @param start - * @param variable - * @param alreadyChecked - * @return returns the closest inherited group with the variable. - * @deprecated use now nextGroupWithVariable(Group start, String - * targetVariable) - */ - @Deprecated - public Group nextGroupWithVariable(Group start, String variable, List alreadyChecked) { - - return nextGroupWithVariable(start, variable); - } - /** * Returns the next group, including inheritance, which contains that * variable name. * * It does Breadth-first search * - * @param start - * the starting group to look for - * @param targetVariable - * the variable name + * @param start the starting group to look for + * @param targetVariable the variable name * @return The group if found. Null if not. */ public Group nextGroupWithVariable(Group start, String targetVariable) { @@ -880,37 +858,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return null; } - /** - * Check if given group inherits another group. - * - * redirected to the other method. this is deprecated now. and will be gone - * in the future releases. - * - * @param start - * The group to start the search. - * @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. - * @deprecated prefer using hasGroupInInheritance(Group start, String - * askedGroup) - */ - @Deprecated - public boolean searchGroupInInheritance(Group start, String askedGroup, List alreadyChecked) { - - return hasGroupInInheritance(start, askedGroup); - } /** * Check if given group inherits another group. * * It does Breadth-first search * - * @param start - * The group to start the search. - * @param askedGroup - * Name of the group you're looking for + * @param start The group to start the search. + * @param askedGroup Name of the group you're looking for * @return true if it inherits the group. */ public boolean hasGroupInInheritance(Group start, String askedGroup) { @@ -938,26 +893,6 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return false; } - /** - * Check if the group has given permission. Including it's inheritance - * - * @param start - * @param permission - * @param alreadyChecked - * @return true if PermissionCheckResult is EXCEPTION or FOUND - * @deprecated use the other checkGroupPermissionWithInheritance for - * everything - */ - @Deprecated - public boolean checkGroupPermissionWithInheritance(Group start, String permission, List alreadyChecked) { - - PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); - if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) { - return true; - } - return false; - } - /** * Returns the result of permission check. Including inheritance. If found * anything, the PermissionCheckResult that retuns will include the Group @@ -1002,44 +937,6 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return result; } - /** - * It uses checkGroupPermissionWithInheritance and cast the owner to Group - * type if result type was EXCEPTION or FOUND. - * - * @param start - * @param permission - * @param alreadyChecked - * @return the group that passed on test. null if no group passed. - * @deprecated use checkGroupPermissionWithInheritance for everything now. - */ - @Deprecated - public Group nextGroupWithPermission(Group start, String permission, List alreadyChecked) { - - PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission); - if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) { - return (Group) checkGroupPermissionWithInheritance(start, permission).owner; - } - return null; - } - - /** - * Return whole list of names of groups in a inheritance chain. Including a - * starting group. - * - * it now redirects to the other method. but get away from this one, it will - * disappear in a future release. - * - * @param start - * @param alreadyChecked - * @return the group that passed on test. null if no group passed. - * @deprecated use the other method with same name, instead - */ - @Deprecated - public ArrayList listAllGroupsInherited(Group start, ArrayList alreadyChecked) { - - return listAllGroupsInherited(start); - } - /** * Return whole list of names of groups in a inheritance chain. Including a * starting group. -- cgit v1.2.3 From 1599a36642014d2b3284288676999a39b417a841 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 23:56:50 +0100 Subject: Correct formatting in command list. --- .../utils/GroupManagerPermissions.java | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java index f8cef89c7..4a7298b9c 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java @@ -11,5 +11,43 @@ package org.anjocaido.groupmanager.utils; */ public enum GroupManagerPermissions { - manuadd, manudel, manuaddsub, manudelsub, mangadd, mangdel, manuaddp, manudelp, manulistp, manucheckp, mangaddp, mangdelp, manglistp, mangcheckp, mangaddi, mangdeli, manuaddv, manudelv, manulistv, manucheckv, mangaddv, mangdelv, manglistv, mangcheckv, manwhois, tempadd, tempdel, templist, tempdelall, mansave, manload, listgroups, manpromote, mandemote, mantogglevalidate, mantogglesave, manworld, manselect, manclear + manuadd, + manudel, + manuaddsub, + manudelsub, + mangadd, + mangdel, + manuaddp, + manudelp, + manulistp, + manucheckp, + mangaddp, + mangdelp, + manglistp, + mangcheckp, + mangaddi, + mangdeli, + manuaddv, + manudelv, + manulistv, + manucheckv, + mangaddv, + mangdelv, + manglistv, + mangcheckv, + manwhois, + tempadd, + tempdel, + templist, + tempdelall, + mansave, + manload, + listgroups, + manpromote, + mandemote, + mantogglevalidate, + mantogglesave, + manworld, + manselect, + manclear } -- cgit v1.2.3 From 6dc2e965092afc4aea815ff473185831fcaf621c Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 15 Apr 2012 22:00:13 +0100 Subject: Few missing default permissions. --- EssentialsGroupManager/src/globalgroups.yml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index 101e4d3c5..e8f51f2b1 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -118,6 +118,7 @@ groups: - essentials.chat.shout - essentials.chat.question - essentials.compass + - essentials.delhome - essentials.depth - essentials.getpos - essentials.home @@ -175,6 +176,7 @@ groups: - essentials.ext - essentials.fly - essentials.getpos + - essentials.getpos.others - essentials.helpop.recieve - essentials.home.others - essentials.invsee @@ -190,6 +192,7 @@ groups: - essentials.nick.others - essentials.realname - essentials.seen.banreason + - essentials.seen.extra - essentials.setwarp - essentials.signs.create.* - essentials.signs.break.* -- cgit v1.2.3 From da857895fc2eea8449c98c64719fe1e32f54c80c Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 16 Apr 2012 23:54:33 +0100 Subject: Re-initialize the WorldsHolder on a reload, as un-registering and re-registering a new holder means all plugins have to check for the new service on every quiery. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GroupManager.java | 96 ++++++++++++++-------- .../dataholder/worlds/WorldsHolder.java | 11 ++- 3 files changed, 72 insertions(+), 38 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index f900d5aa9..fcdc1ed9d 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -179,4 +179,5 @@ v 2.0: - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. - Update all code formatting to use tabs for indentation. - Stop using our own deprecated methods as we tell others to do. - - Finally remove all deprecated methods. \ No newline at end of file + - Finally remove all deprecated methods. + - Re-initialize the WorldsHolder on a reload, as un-registering and re-registering a new holder means all plugins have to check for the new service on every quiery. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index df46b70d0..3da9666c3 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -56,25 +56,7 @@ public class GroupManager extends JavaPlugin { private Map selectedWorlds = new HashMap(); private WorldsHolder worldsHolder; private boolean validateOnlinePlayer = true; - - private String lastError = ""; - - /** - * @return the validateOnlinePlayer - */ - public boolean isValidateOnlinePlayer() { - - return validateOnlinePlayer; - } - - /** - * @param validateOnlinePlayer the validateOnlinePlayer to set - */ - public void setValidateOnlinePlayer(boolean validateOnlinePlayer) { - - this.validateOnlinePlayer = validateOnlinePlayer; - } - + private static boolean isLoaded = false; protected GMConfiguration config; @@ -89,13 +71,28 @@ public class GroupManager extends JavaPlugin { private OverloadedWorldHolder dataHolder = null; private AnjoPermissionsHandler permissionHandler = null; + private String lastError = ""; + @Override public void onDisable() { + + onDisable(false); + } + + @Override + public void onEnable() { + + onEnable(false); + } + + public void onDisable(boolean restarting) { setLoaded(false); - // Unregister this service. - this.getServer().getServicesManager().unregister(this.worldsHolder); + if (!restarting) { + // Unregister this service if we are shutting down. + this.getServer().getServicesManager().unregister(this.worldsHolder); + } disableScheduler(); // Shutdown before we save, so it doesn't interfere. if (worldsHolder != null) { @@ -118,18 +115,26 @@ public class GroupManager extends JavaPlugin { // EXAMPLE: Custom code, here we just output some info so we can check that all is well PluginDescriptionFile pdfFile = this.getDescription(); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!"); - GroupManager.logger.removeHandler(ch); + + if (!restarting) + GroupManager.logger.removeHandler(ch); } - - @Override - public void onEnable() { + + public void onEnable(boolean restarting) { try { + /* + * reset local variables. + */ + overloadedUsers = new HashMap>(); + selectedWorlds = new HashMap(); lastError = ""; - - GroupManager.logger.setUseParentHandlers(false); - ch = new GMLoggerHandler(); - GroupManager.logger.addHandler(ch); + + if (!restarting) { + GroupManager.logger.setUseParentHandlers(false); + ch = new GMLoggerHandler(); + GroupManager.logger.addHandler(ch); + } logger.setLevel(Level.ALL); // Create the backup folder, if it doesn't exist. @@ -138,7 +143,11 @@ public class GroupManager extends JavaPlugin { prepareConfig(); // Load the global groups globalGroups = new GlobalGroups(this); - worldsHolder = new WorldsHolder(this); + + if (!restarting) + worldsHolder = new WorldsHolder(this); + else + worldsHolder.resetWorldsHolder(); PluginDescriptionFile pdfFile = this.getDescription(); if (worldsHolder == null) { @@ -169,7 +178,9 @@ public class GroupManager extends JavaPlugin { System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); // Register as a service - this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); + if (!restarting) + this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); + } catch (Exception ex) { /* @@ -222,6 +233,22 @@ public class GroupManager extends JavaPlugin { } } + + /** + * @return the validateOnlinePlayer + */ + public boolean isValidateOnlinePlayer() { + + return validateOnlinePlayer; + } + + /** + * @param validateOnlinePlayer the validateOnlinePlayer to set + */ + public void setValidateOnlinePlayer(boolean validateOnlinePlayer) { + + this.validateOnlinePlayer = validateOnlinePlayer; + } public static boolean isLoaded() { @@ -1633,11 +1660,10 @@ public class GroupManager extends JavaPlugin { */ /* - * Reset the last error as we are attempting a fresh load. + * Attempting a fresh load. */ - lastError = ""; - onDisable(); - onEnable(); + onDisable(true); + onEnable(true); sender.sendMessage("All settings and worlds were reloaded!"); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index 37d0a8430..a9ab4befa 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -57,12 +57,19 @@ public class WorldsHolder { public WorldsHolder(GroupManager plugin) { this.plugin = plugin; + resetWorldsHolder(); + } + + public void resetWorldsHolder() { + + mirrorsGroup = new HashMap(); + mirrorsUser = new HashMap(); + // Setup folders and check files exist for the primary world verifyFirstRun(); initialLoad(); - if (serverDefaultWorldName == null) { + if (serverDefaultWorldName == null) throw new IllegalStateException("There is no default group! OMG!"); - } } private void initialLoad() { -- cgit v1.2.3 From 6ac8abdac85e85b30aac1e94b4326cc52c41bf39 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 17 Apr 2012 18:57:11 +0100 Subject: Fix a couple of perms in GlobalGroups --- EssentialsGroupManager/src/globalgroups.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index fa8808e00..a08f9600e 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -212,13 +212,14 @@ groups: g:towny_default: permissions: - towny.chat.general + - towny.chat.local g:towny_builder: permissions: - towny.town.* - towny.nation.* - - towny.chat.tc - - towny.chat.nc + - towny.chat.town + - towny.chat.nation - towny.wild.build.6 - towny.wild.destroy.6 - towny.wild.destroy.14 -- cgit v1.2.3 From cd7bf5eff2a1daeb9ad792820265c70ff8b3e0dc Mon Sep 17 00:00:00 2001 From: ElgarL Date: Wed, 18 Apr 2012 22:22:35 +0100 Subject: Prevent null perms getting past the GlobalGroups loader. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GlobalGroups.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index fcdc1ed9d..e321c7741 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -180,4 +180,5 @@ v 2.0: - Update all code formatting to use tabs for indentation. - Stop using our own deprecated methods as we tell others to do. - Finally remove all deprecated methods. - - Re-initialize the WorldsHolder on a reload, as un-registering and re-registering a new holder means all plugins have to check for the new service on every quiery. \ No newline at end of file + - Re-initialize the WorldsHolder on a reload, as un-registering and re-registering a new holder means all plugins have to check for the new service on every quiery. + - Prevent null perms getting past the GlobalGroups loader. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 647d729e5..04d9e86be 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -159,12 +159,14 @@ public class GlobalGroups { if (element instanceof List) { try { for (String node : (List) element) { - newGroup.addPermission(node); + if ((node != null) && !node.isEmpty()) + newGroup.addPermission(node); } } catch (ClassCastException ex) { throw new IllegalArgumentException("Invalid permission node for global group: " + groupName, ex); } } else if (element instanceof String) { + if ((element != null) && !((String)element).isEmpty()) newGroup.addPermission((String) element); } else throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); -- cgit v1.2.3 From 4e10470acd507e41c1df334ae4489dc34fd4c308 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 21 Apr 2012 02:32:02 +0100 Subject: Remove unneeded dependency of craftbukkit (Eclipse building) --- EssentialsGroupManager/.classpath | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/.classpath b/EssentialsGroupManager/.classpath index 61f808b2d..bc8106503 100644 --- a/EssentialsGroupManager/.classpath +++ b/EssentialsGroupManager/.classpath @@ -2,6 +2,6 @@ - + -- cgit v1.2.3 From fc7689354f3dea2614f248a1f82eb740b6a4fb9f Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 21 Apr 2012 16:58:22 +0100 Subject: Fix forgetting sub groups on a manload. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GroupManager.java | 48 +++++++++++++++++++--- .../dataholder/worlds/WorldsHolder.java | 1 + .../permissions/BukkitPermissions.java | 9 +++- 4 files changed, 52 insertions(+), 9 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index e321c7741..c3ec8ccc1 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -181,4 +181,5 @@ v 2.0: - Stop using our own deprecated methods as we tell others to do. - Finally remove all deprecated methods. - Re-initialize the WorldsHolder on a reload, as un-registering and re-registering a new holder means all plugins have to check for the new service on every quiery. - - Prevent null perms getting past the GlobalGroups loader. \ No newline at end of file + - Prevent null perms getting past the GlobalGroups loader. + - Fix forgetting sub groups on a manload. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 3da9666c3..0571db4b6 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -103,13 +103,20 @@ public class GroupManager extends JavaPlugin { } } - if (WorldEvents != null) - WorldEvents = null; + // Remove all attachments before clearing if (BukkitPermissions != null) { BukkitPermissions.removeAllAttachments(); + } + + if (!restarting) { + + if (WorldEvents != null) + WorldEvents = null; + BukkitPermissions = null; + } // EXAMPLE: Custom code, here we just output some info so we can check that all is well @@ -130,6 +137,9 @@ public class GroupManager extends JavaPlugin { selectedWorlds = new HashMap(); lastError = ""; + /* + * Setup our logger if we are not restarting. + */ if (!restarting) { GroupManager.logger.setUseParentHandlers(false); ch = new GMLoggerHandler(); @@ -144,11 +154,17 @@ public class GroupManager extends JavaPlugin { // Load the global groups globalGroups = new GlobalGroups(this); + /* + * Configure the worlds holder. + */ if (!restarting) worldsHolder = new WorldsHolder(this); else worldsHolder.resetWorldsHolder(); + /* + * This should NEVER happen. No idea why it's still here. + */ PluginDescriptionFile pdfFile = this.getDescription(); if (worldsHolder == null) { GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!"); @@ -156,13 +172,30 @@ public class GroupManager extends JavaPlugin { throw new IllegalStateException("An error ocurred while loading GroupManager"); } - // Set a few defaults (reloads) + /* + * Prevent our registered events from triggering + * updates as we are not fully loaded. + */ setLoaded(false); - // Initialize the world listener and bukkit permissions to handle events. - WorldEvents = new GMWorldListener(this); - BukkitPermissions = new BukkitPermissions(this); + /* + * Initialize the world listener and bukkit permissions + * to handle events if this is a fresh start + * + * else + * + * Reset bukkit perms. + */ + if (!restarting) { + WorldEvents = new GMWorldListener(this); + BukkitPermissions = new BukkitPermissions(this); + } else { + BukkitPermissions.reset(); + } + /* + * Start the scheduler for data saving. + */ enableScheduler(); /* @@ -172,6 +205,9 @@ public class GroupManager extends JavaPlugin { if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { GroupManager.logger.severe("Could not schedule superperms Update."); + /* + * Flag that we are now loaded and should start processing events. + */ setLoaded(true); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index a9ab4befa..27a7d9a59 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -62,6 +62,7 @@ public class WorldsHolder { public void resetWorldsHolder() { + worldsData = new HashMap(); mirrorsGroup = new HashMap(); mirrorsUser = new HashMap(); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index c366b65bf..e8322c391 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -96,12 +96,17 @@ public class BukkitPermissions { public BukkitPermissions(GroupManager plugin) { this.plugin = plugin; - this.collectPermissions(); + this.reset(); this.registerEvents(); - this.updateAllPlayers(); + GroupManager.logger.info("Superperms support enabled."); } + + public void reset() { + this.collectPermissions(); + this.updateAllPlayers(); + } private void registerEvents() { -- cgit v1.2.3 From 06247732da564876d97de99aa706fd7e823c0df9 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 22 Apr 2012 12:12:50 +0100 Subject: Allow 'manucheckp' to notify when superperms reports false but it is really negated. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'EssentialsGroupManager') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c3ec8ccc1..4a3c232be 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -182,4 +182,5 @@ v 2.0: - Finally remove all deprecated methods. - Re-initialize the WorldsHolder on a reload, as un-registering and re-registering a new holder means all plugins have to check for the new service on every quiery. - Prevent null perms getting past the GlobalGroups loader. - - Fix forgetting sub groups on a manload. \ No newline at end of file + - Fix forgetting sub groups on a manload. + - Allow 'manucheckp' to notify when superperms reports false but it is really negated. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 0571db4b6..5f357641a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -921,7 +921,7 @@ public class GroupManager extends JavaPlugin { // superperms if (targetPlayer != null) { - sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1])); + sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]) + ((!targetPlayer.hasPermission(args[1]) && targetPlayer.isPermissionSet(args[1])) ? " (Negated)": "")); } return true; -- cgit v1.2.3