diff options
Diffstat (limited to 'EssentialsGroupManager/src')
7 files changed, 611 insertions, 298 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c5fe5564d..b957f4515 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -163,4 +163,15 @@ 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).
+ - 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.
+ - 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'
+ - 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 fa78aa36a..101e4d3c5 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:
@@ -121,14 +216,6 @@ groups: - essentials.whois
- essentials.world
- essentials.world.*
- - groupmanager.listgroups
- - groupmanager.mandemote
- - groupmanager.manpromote
- - groupmanager.manselect
- - groupmanager.manuadd
- - groupmanager.manudel
- - groupmanager.manwhois
- - groupmanager.notify.other
g:essentials_admin:
permissions:
@@ -138,62 +225,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:
@@ -244,4 +282,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
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/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 8bd346735..1177e3357 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<CommandSender, String> selectedWorlds = new HashMap<CommandSender, String>(); private WorldsHolder worldsHolder; private boolean validateOnlinePlayer = true; + + private String lastError = ""; + /** * @return the validateOnlinePlayer */ @@ -106,7 +110,12 @@ public class GroupManager extends JavaPlugin { } WorldEvents = null; - BukkitPermissions = 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 @@ -115,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() { @@ -297,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"))); @@ -310,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; } @@ -380,9 +457,18 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group> | 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; @@ -1395,6 +1481,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())) { @@ -1547,10 +1643,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]; @@ -1575,8 +1678,15 @@ 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(); + + sender.sendMessage("All settings and worlds were reloaded!"); } /** diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index cee2ec0b8..8c974f34a 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<String, List<String>> inheritance = new HashMap<String, List<String>>(); try { + /* + * Fetch all child nodes under the 'groups' entry. + */ Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups"); - try { - for (String groupKey : allGroupsNode.keySet()) { - Map<String, Object> thisGroupNode = (Map<String, Object>) 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<String>()); + Iterator<String> 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<String, Object> thisGroupNode = (Map<String, Object>) 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<String>()); + } 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<String>) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - thisGrp.sortPermissions(); + throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>) 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<String, Object> infoNode = (Map<String, Object>) 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<String>()); - } else if (inheritNode instanceof List) { - List<String> groupsInh = (List<String>) inheritNode; - for (String grp : groupsInh) { - if (inheritance.get(groupKey) == null) { - List<String> thisInherits = new ArrayList<String>(); - 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<String, Object> infoNode = (Map<String, Object>) 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<String>()); + } else if (inheritNode instanceof List) { + List<String> groupsInh = (List<String>) inheritNode; + for (String grp : groupsInh) { + if (inheritance.get(groupKey) == null) { + List<String> thisInherits = new ArrayList<String>(); + 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<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users"); // Load users if the file is NOT empty - if (allUsersNode != null) - try { - for (String usersKey : allUsersNode.keySet()) { - Map<String, Object> thisUserNode = null; - try { - thisUserNode = (Map<String, Object>) 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<String>()); - } 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<String>()); - } - 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<String, Object> infoNode = (Map<String, Object>) 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<String> 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<String, Object> thisUserNode = null; + try { + thisUserNode = (Map<String, Object>) 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<String>()); + } 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<String>()); + } + 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<String, Object> infoNode = (Map<String, Object>) 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. @@ -756,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); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 5c711351e..516679544 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;
@@ -351,10 +352,38 @@ 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 knows of it.
+ */
+ }
attachments.remove(player);
}
}
+
+ /**
+ * Remove all attachments in case of a restart or reload.
+ */
+ public void removeAllAttachments() {
+
+ Iterator<Player> itr = attachments.keySet().iterator();
+
+ while (itr.hasNext()){
+ 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();
+ }
/**
* Player events tracked to cause Superperms updates
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()) { |