Merge branch 'master' of github.com:essentials/Essentials

This commit is contained in:
ementalo 2012-04-12 21:26:34 +01:00
commit bbd2c53dd8
9 changed files with 725 additions and 360 deletions

View File

@ -39,7 +39,7 @@ public class EssentialsConf extends YamlConfiguration
this.configFile = configFile;
}
public void load()
public synchronized void load()
{
configFile = configFile.getAbsoluteFile();
if (!configFile.getParentFile().exists())
@ -356,7 +356,7 @@ public class EssentialsConf extends YamlConfiguration
}
@Override
public void save(final File file) throws IOException
public synchronized void save(final File file) throws IOException
{
if (file == null)
{

View File

@ -163,4 +163,17 @@ 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.
- 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.
- 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.

View File

@ -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
- 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

View File

@ -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:

View File

@ -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<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
Map<String, Object> allGroups = new HashMap<String, Object>();
try {
allGroups = (Map<String, Object>) 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<String>) 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<String, Object> vars = new HashMap<String, Object>();
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<String> 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<String>) 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<String, Object> vars = new HashMap<String, Object>();
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);
}
}

View File

@ -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
*/
@ -94,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) {
@ -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);
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);
// 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);
/*
* Throw an error so Bukkit knows about it.
*/
throw new IllegalArgumentException(ex.getMessage(),ex);
}
}
/**
* Write an error.log
*
* @param ex
*/
private void saveErrorLog(Exception ex) {
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("===================================================");
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");
// 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();
}
// 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);
}
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!");
}
/**

View File

@ -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;
@ -458,118 +459,180 @@ public class WorldDataHolder {
//PROCESS GROUPS FILE
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
/*
* Fetch all child nodes under the 'groups' entry.
*/
Map<String, Object> allGroupsNode = new HashMap<String, Object>();
try {
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>());
} 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();
}
} 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 e) {
throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + groupsFile.getPath());
}
allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.");
//ex.printStackTrace();
throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex);
}
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 ex) {
throw new IllegalArgumentException("Invalid group name for group entry (" + groupCount + ") in file: " + groupsFile.getPath(), ex);
}
/*
* Fetch this groups child nodes
*/
Map<String, Object> thisGroupNode = new HashMap<String, Object>();
try {
thisGroupNode = (Map<String, Object>) 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());
}
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<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 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) {
/*
* 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());
}
/*
* Sort all permissions so they are in the correct order for checking.
*/
thisGrp.sortPermissions();
}
//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 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<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 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<String> 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<String> 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();
@ -611,100 +674,119 @@ public class WorldDataHolder {
}
// PROCESS USERS FILE
Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
Map<String, Object> allUsersNode = new HashMap<String, Object>();
/*
* Fetch all child nodes under the 'users' entry.
*/
try {
allUsersNode = (Map<String, Object>) 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)
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());
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 ex) {
throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath(), ex);
}
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.
}
}
//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());
}
}
} 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 +838,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);

View File

@ -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

View File

@ -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()) {