summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-04-11 21:57:58 +0200
committersnowleo <schneeleo@gmail.com>2012-04-11 21:57:58 +0200
commit3f9e19d279c7f9534733b9868ca24a11e7e0e19b (patch)
treefff53a637c0e967ab1762901fa44176ab644e6ec /EssentialsGroupManager/src/org/anjocaido
parentc9e64d9e46c3e97b4be897b4449fdad667753d8e (diff)
parent25759064ff4c518193185fe3e993634408230eb7 (diff)
downloadEssentials-3f9e19d279c7f9534733b9868ca24a11e7e0e19b.tar
Essentials-3f9e19d279c7f9534733b9868ca24a11e7e0e19b.tar.gz
Essentials-3f9e19d279c7f9534733b9868ca24a11e7e0e19b.tar.lz
Essentials-3f9e19d279c7f9534733b9868ca24a11e7e0e19b.tar.xz
Essentials-3f9e19d279c7f9534733b9868ca24a11e7e0e19b.zip
Merge branch 'refs/heads/groupmanager'
Conflicts: EssentialsGroupManager/src/globalgroups.yml
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java198
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java417
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java31
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java41
4 files changed, 461 insertions, 226 deletions
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()) {