diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-10-03 10:19:31 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-10-03 10:19:31 +0100 |
commit | aa0935c64bf46fafe350e51e6b2a128c448126c9 (patch) | |
tree | cc839357c08f18236617c58abb79a66b51beafc0 | |
parent | 16111b56adeee3b18329a6d198c4a58ac5b84083 (diff) | |
parent | 49e2c38289f4ca2eaa09f4f469376b45772ca8c0 (diff) | |
download | Essentials-aa0935c64bf46fafe350e51e6b2a128c448126c9.tar Essentials-aa0935c64bf46fafe350e51e6b2a128c448126c9.tar.gz Essentials-aa0935c64bf46fafe350e51e6b2a128c448126c9.tar.lz Essentials-aa0935c64bf46fafe350e51e6b2a128c448126c9.tar.xz Essentials-aa0935c64bf46fafe350e51e6b2a128c448126c9.zip |
Merge remote branch 'remotes/ess/groupmanager' into essmaster
9 files changed, 205 insertions, 124 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 4f90b82cd..b8034e19c 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -23,4 +23,16 @@ v 1.1: - Fix for GM not checking inheritance for known superperms nodes.
- Optimized getAllPlayersPermissions and fixed pushing unknown perms to superperms.
v 1.2:
- - Changed priority if Registered events to lowest.
\ No newline at end of file + - Changed priority of Registered events to lowest.
+ - Fixed an issue with superperms where plugins define perms with inheritance after the root perms
+ - Rewrote Config loading to use Bukkits Configuration features
+ - Added an opOverride setting in config.
+ If present and set to false, op's will not get overriding permissions in GroupManager.
+ (one op will not be able to alter another op's settings)
+ - GM will now create all relevant world data files for non mirrored worlds.
+ (for all worlds named in config.yml)
+ - Attempt to stop GM wiping groups/users yml's on a bad shut down.
+ - Added event handling to manage new world creation at runtime.
+ - Added the ability to handle unknown worlds at server start.
+ (GM will create the data files for any worlds it finds which are not in the config.yml)
+ - Fix for Bukkit passing a null To location on a player Portaling
\ No newline at end of file diff --git a/EssentialsGroupManager/src/config.yml b/EssentialsGroupManager/src/config.yml index 688d3f3ea..a5bca810e 100644 --- a/EssentialsGroupManager/src/config.yml +++ b/EssentialsGroupManager/src/config.yml @@ -1,12 +1,19 @@ settings: + config: + # With this enabled anyone set as op has full permissions when managing GroupManager + opOverrides: true data: save: + # How often GroupManager will save it's data back to groups and users.yml minutes: 10 logging: + # level of detail GroupManager will use when logging. + # Acceptable entries are - ALL,CONFIG,FINE,FINER,FINEST,INFO,OFF,SEVERE,WARNING level: INFO permission: world: mirror: + # Worlds listed here have their permissions mirrored in their children. world: - world_nether - world2 diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java index 153221ed9..aa838d9e8 100755..100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java @@ -5,15 +5,12 @@ package org.anjocaido.groupmanager; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; import java.util.logging.Level; + import org.anjocaido.groupmanager.utils.Tasks; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.SafeConstructor; -import org.yaml.snakeyaml.reader.UnicodeReader; +import org.bukkit.util.config.Configuration; /** * @@ -22,9 +19,9 @@ import org.yaml.snakeyaml.reader.UnicodeReader; public class GMConfiguration { private GroupManager plugin; - private Map<String, Object> rootDataNode; private File configFile; - + private Configuration GMconfig; + public GMConfiguration(GroupManager plugin) { this.plugin = plugin; load(); @@ -44,77 +41,37 @@ public class GMConfiguration { } } - Yaml yaml = new Yaml(new SafeConstructor()); - FileInputStream rx = null; - try { - rx = new FileInputStream(configFile); - } catch (FileNotFoundException ex) { - GroupManager.logger.log(Level.SEVERE, null, ex); - } + GMconfig = new Configuration(configFile); + try { - rootDataNode = (Map<String, Object>) yaml.load(new UnicodeReader(rx)); - if (rootDataNode == null) { - throw new NullPointerException(); - } + GMconfig.load(); } catch (Exception ex) { throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex); - } finally { - try { - rx.close(); - } catch (IOException ex) { - } } adjustLoggerLevel(); } + + public boolean isOpOverride() { + return GMconfig.getBoolean("settings.config.opOverrides", true); + } - public Map<String, Object> getMirrorsMap() { - if (rootDataNode.get("settings") instanceof Map) { - Map<String, Object> settingsNode = (Map<String, Object>) rootDataNode.get("settings"); - if (settingsNode.get("permission") instanceof Map) { - Map<String, Object> permissionNode = (Map<String, Object>) settingsNode.get("permission"); - if (permissionNode.get("world") instanceof Map) { - Map<String, Object> worldsNode = (Map<String, Object>) permissionNode.get("world"); - if (worldsNode.get("mirror") instanceof Map) { - Map<String, Object> mirrorsNode = (Map<String, Object>) worldsNode.get("mirror"); - return mirrorsNode; - } - } - } - } - return null; + @SuppressWarnings("unchecked") + public Map<String, Object> getMirrorsMap() { + return (Map<String, Object>) GMconfig.getProperty("settings.permission.world.mirror"); } - public Integer getSaveInterval() { - if (rootDataNode.get("settings") instanceof Map) { - Map<String, Object> settingsNode = (Map<String, Object>) rootDataNode.get("settings"); - if (settingsNode.get("data") instanceof Map) { - Map<String, Object> dataNode = (Map<String, Object>) settingsNode.get("data"); - if (dataNode.get("save") instanceof Map) { - Map<String, Object> saveNode = (Map<String, Object>) dataNode.get("save"); - if (saveNode.get("minutes") instanceof Integer) { - return (Integer) saveNode.get("minutes"); - } - } - } - } - return 10; + public Integer getSaveInterval() { + return GMconfig.getInt("settings.data.save.minutes", 10); } public void adjustLoggerLevel() { - if (rootDataNode.get("settings") instanceof Map) { - Map<String, Object> settingsNode = (Map<String, Object>) rootDataNode.get("settings"); - if (settingsNode.get("logging") instanceof Map) { - Map<String, Object> loggingNode = (Map<String, Object>) settingsNode.get("logging"); - if (loggingNode.get("level") instanceof String) { - String level = (String) loggingNode.get("level"); - try { - GroupManager.logger.setLevel(Level.parse(level)); - return; - } catch (Exception e) { - } - } - } + + try { + GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO"))); + return; + } catch (Exception e) { } - GroupManager.logger.setLevel(Level.INFO); + + GroupManager.logger.setLevel(Level.INFO); } }
\ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index dcec36639..a13406eab 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder; +import org.anjocaido.groupmanager.events.GMWorldListener; import org.anjocaido.groupmanager.utils.GMLoggerHandler; import org.anjocaido.groupmanager.utils.PermissionCheckResult; import org.anjocaido.groupmanager.utils.Tasks; @@ -32,9 +33,12 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.world.WorldListener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; + @SuppressWarnings("unused") /** * @@ -55,6 +59,7 @@ public class GroupManager extends JavaPlugin { private GMConfiguration config; private GMLoggerHandler ch; public static BukkitPermissions BukkitPermissions; + private static WorldListener WorldEvents; public static final Logger logger = Logger.getLogger(GroupManager.class.getName()); //PERMISSIONS FOR COMMAND BEING LOADED @@ -69,6 +74,10 @@ public class GroupManager extends JavaPlugin { worldsHolder.saveChanges(); } disableScheduler(); + + WorldEvents = null; + BukkitPermissions = null; + // EXAMPLE: Custom code, here we just output some info so we can check all is well PluginDescriptionFile pdfFile = this.getDescription(); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!"); @@ -94,8 +103,10 @@ public class GroupManager extends JavaPlugin { throw new IllegalStateException("An error ocurred while loading GroupManager"); } + // Initialize the world listener and bukkit permissions to handle events. + WorldEvents = new GMWorldListener(this); BukkitPermissions = new BukkitPermissions(this); - + enableScheduler(); /* @@ -108,9 +119,10 @@ public class GroupManager extends JavaPlugin { setLoaded(true); } - //setLoaded(true); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); } + + public static boolean isLoaded() { return isLoaded; @@ -232,6 +244,7 @@ public class GroupManager extends JavaPlugin { Player senderPlayer = null, targetPlayer = null; Group senderGroup = null; User senderUser = null; + boolean isOpOverride = config.isOpOverride(); //DETERMINING PLAYER INFORMATION @@ -239,8 +252,10 @@ public class GroupManager extends JavaPlugin { senderPlayer = (Player) sender; senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderGroup = senderUser.getGroup(); + isOpOverride = (isOpOverride && senderPlayer.isOp()); + System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " ")); - if (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) { + if (isOpOverride || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) { playerCanDo = true; } } else if (sender instanceof ConsoleCommandSender) { @@ -338,23 +353,23 @@ public class GroupManager extends JavaPlugin { } //VALIDANDO PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } - if (!isConsole && !senderPlayer.isOp() && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { + if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "The new group must be a higher rank."); return false; } @@ -392,7 +407,7 @@ public class GroupManager extends JavaPlugin { auxUser = dataHolder.getUser(args[0]); } //VALIDANDO PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } @@ -436,7 +451,7 @@ public class GroupManager extends JavaPlugin { return false; } //VALIDANDO PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } @@ -472,7 +487,7 @@ public class GroupManager extends JavaPlugin { auxUser = dataHolder.getUser(args[0]); } //VALIDANDO PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } @@ -557,7 +572,7 @@ public class GroupManager extends JavaPlugin { return false; } permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); - if (!isConsole && !senderPlayer.isOp() && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) + if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) { sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have."); return false; @@ -620,12 +635,12 @@ public class GroupManager extends JavaPlugin { auxUser = dataHolder.getUser(args[0]); } //VALIDANDO SUA PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher."); return false; } permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); - if (!isConsole && !senderPlayer.isOp() && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) + if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) { sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have."); return false; @@ -1554,23 +1569,23 @@ public class GroupManager extends JavaPlugin { return false; } //VALIDANDO PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } - if (!isConsole && !senderPlayer.isOp() && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { + if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "The new group must be a higher rank."); return false; } @@ -1612,23 +1627,23 @@ public class GroupManager extends JavaPlugin { return false; } //VALIDANDO PERMISSAO - if (!isConsole && !senderPlayer.isOp() && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { + if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) { sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher."); return false; } - if (!isConsole && !senderPlayer.isOp() && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { + if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) { sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) { sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don' inherit."); return false; } - if (!isConsole && !senderPlayer.isOp() && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { + if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line."); return false; } - if (!isConsole && !senderPlayer.isOp() && (permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { + if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { sender.sendMessage(ChatColor.RED + "The new group must be a lower rank."); return false; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java index 27951112d..f4b805c35 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java @@ -18,6 +18,7 @@ public class BukkitPermsUpdateTask implements Runnable { public void run() {
// Signal loaded and update BukkitPermissions.
GroupManager.setLoaded(true);
+ GroupManager.BukkitPermissions.collectPermissions();
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManager.logger.info("Bukkit Permissions Updated!");
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 77d933fa0..4a9f806d8 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -767,13 +767,15 @@ public class WorldDataHolder { aGroupMap.put("permissions", group.getPermissionList()); } - DumperOptions opt = new DumperOptions(); - opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final Yaml yaml = new Yaml(opt); - try { - yaml.dump(root, new OutputStreamWriter(new FileOutputStream(groupsFile), "UTF-8")); - } catch (UnsupportedEncodingException ex) { - } catch (FileNotFoundException ex) { + if (!root.isEmpty()) { + DumperOptions opt = new DumperOptions(); + opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + final Yaml yaml = new Yaml(opt); + try { + yaml.dump(root, new OutputStreamWriter(new FileOutputStream(groupsFile), "UTF-8")); + } catch (UnsupportedEncodingException ex) { + } catch (FileNotFoundException ex) { + } } /*FileWriter tx = null; @@ -829,13 +831,16 @@ public class WorldDataHolder { aUserMap.put("subgroups", user.subGroupListStringCopy()); //END SUBGROUPS NODE - BETA } - DumperOptions opt = new DumperOptions(); - opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final Yaml yaml = new Yaml(opt); - try { - yaml.dump(root, new OutputStreamWriter(new FileOutputStream(usersFile), "UTF-8")); - } catch (UnsupportedEncodingException ex) { - } catch (FileNotFoundException ex) { + + if (!root.isEmpty()) { + DumperOptions opt = new DumperOptions(); + opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + final Yaml yaml = new Yaml(opt); + try { + yaml.dump(root, new OutputStreamWriter(new FileOutputStream(usersFile), "UTF-8")); + } catch (UnsupportedEncodingException ex) { + } catch (FileNotFoundException ex) { + } } /*FileWriter tx = null; try { diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index a2c34be16..50e6ef547 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -21,6 +21,7 @@ import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder; import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler; import org.anjocaido.groupmanager.utils.Tasks; +import org.bukkit.World; import org.bukkit.entity.Player; /** @@ -52,6 +53,7 @@ public class WorldsHolder { */ public WorldsHolder(GroupManager plugin) { this.plugin = plugin; + // Setup folders and check files exist for the primary world verifyFirstRun(); initialLoad(); if (defaultWorld == null) { @@ -60,21 +62,48 @@ public class WorldsHolder { } private void initialLoad() { + // load the initial world initialWorldLoading(); + // Configure and load any mirrors and additional worlds as defined in config.yml mirrorSetUp(); + // search the worlds folder for any manually created worlds (not listed in config.yml) + loadAllSearchedWorlds(); } private void initialWorldLoading() { - //LOAD EVERY WORLD POSSIBLE + //Load the default world loadWorld(serverDefaultWorldName); defaultWorld = worldsData.get(serverDefaultWorldName); - + } + + private void loadAllSearchedWorlds() { + + /* + * Read all known worlds from Bukkit + * Create the data files if they don't already exist, + * and they are not mirrored. + */ + for (World world: plugin.getServer().getWorlds()) + if ((!worldsData.containsKey(world.getName().toLowerCase())) + && (!mirrors.containsKey(world.getName().toLowerCase()))) + setupWorldFolder(world.getName()); + /* + * Loop over all folders within the worlds folder + * and attempt to load the world data + */ for (File folder : worldsFolder.listFiles()) { - if (folder.getName().equalsIgnoreCase(serverDefaultWorldName)) { - continue; - } - if (folder.isDirectory()) { - loadWorld(folder.getName()); + if (folder.isDirectory()) { + GroupManager.logger.info("World Found: " + folder.getName()); + + /* + * don't load any worlds which are already loaded + * or mirrored worlds that don't need data. + */ + if (worldsData.containsKey(folder.getName().toLowerCase()) + || mirrors.containsKey(folder.getName().toLowerCase())) { + continue; + } + loadWorld(folder.getName()); } } } @@ -85,6 +114,12 @@ public class WorldsHolder { Map<String, Object> mirrorsMap = plugin.getConfig().getMirrorsMap(); if (mirrorsMap != null) { for (String source : mirrorsMap.keySet()) { + // Make sure all non mirrored worlds have a set of data files. + setupWorldFolder(source); + // Load the world data + if (!worldsData.containsKey(source.toLowerCase())) + loadWorld(source); + if (mirrorsMap.get(source) instanceof ArrayList) { ArrayList mirrorList = (ArrayList) mirrorsMap.get(source); for (Object o : mirrorList) { @@ -246,18 +281,25 @@ public class WorldsHolder { } private void verifyFirstRun() { - worldsFolder = new File(plugin.getDataFolder(), "worlds"); - if (!worldsFolder.exists()) { - worldsFolder.mkdirs(); - } + Properties server = new Properties(); try { server.load(new FileInputStream(new File("server.properties"))); + serverDefaultWorldName = server.getProperty("level-name").toLowerCase(); + setupWorldFolder(serverDefaultWorldName); } catch (IOException ex) { GroupManager.logger.log(Level.SEVERE, null, ex); } - serverDefaultWorldName = server.getProperty("level-name").toLowerCase(); - File defaultWorldFolder = new File(worldsFolder, serverDefaultWorldName); + + } + + public void setupWorldFolder(String worldName) { + worldsFolder = new File(plugin.getDataFolder(), "worlds"); + if (!worldsFolder.exists()) { + worldsFolder.mkdirs(); + } + + File defaultWorldFolder = new File(worldsFolder, worldName); if (!defaultWorldFolder.exists()) { defaultWorldFolder.mkdirs(); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java new file mode 100644 index 000000000..037971314 --- /dev/null +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GMWorldListener.java @@ -0,0 +1,43 @@ +package org.anjocaido.groupmanager.events;
+
+import org.anjocaido.groupmanager.GroupManager;
+import org.bukkit.event.Event;
+import org.bukkit.event.world.WorldInitEvent;
+import org.bukkit.event.world.WorldListener;
+
+
+/**
+ * @author ElgarL
+ *
+ * Handle new world creation from other plugins
+ *
+ */
+public class GMWorldListener extends WorldListener {
+
+ private final GroupManager plugin;
+
+ public GMWorldListener(GroupManager instance) {
+ plugin = instance;
+ registerEvents();
+ }
+
+ private void registerEvents() {
+ plugin.getServer().getPluginManager().registerEvent(Event.Type.WORLD_INIT, this, Event.Priority.Lowest, plugin);
+ }
+
+ @Override
+ public void onWorldInit(WorldInitEvent event) {
+ String worldName = event.getWorld().getName();
+
+ if (GroupManager.isLoaded() && !plugin.getWorldsHolder().isInList(worldName)) {
+ GroupManager.logger.info("New world detected...");
+ GroupManager.logger.info("Creating data for: " + worldName);
+ plugin.getWorldsHolder().setupWorldFolder(worldName);
+ plugin.getWorldsHolder().loadWorld(worldName);
+ if (plugin.getWorldsHolder().isInList(worldName)) {
+ GroupManager.logger.info("Don't forget to configure/mirror this world in config.yml.");
+ } else
+ GroupManager.logger.severe("Failed to configure this world.");
+ }
+ }
+}
\ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 20f6331bc..19d90854b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -43,7 +43,6 @@ import org.bukkit.event.server.ServerListener; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
-//import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@@ -93,7 +92,7 @@ public class BukkitPermissions { manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin);
}
- private void collectPermissions() {
+ public void collectPermissions() {
registeredPermissions.clear();
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
for(Permission permission : bukkitPlugin.getDescription().getPermissions())
@@ -134,8 +133,8 @@ public class BukkitPermissions { Boolean value;
for (Permission permission : registeredPermissions) {
value = worldData.getPermissionsHandler().checkUserPermission(user, permission.getName());
-
- attachment.setPermission(permission, value);
+ if (value == true)
+ attachment.setPermission(permission, value);
}
// Add any missing permissions for this player (non bukkit plugins)
@@ -199,7 +198,7 @@ public class BukkitPermissions { @Override
public void onPlayerPortal(PlayerPortalEvent event) { // will portal into another world
- if(!event.getFrom().getWorld().equals(event.getTo().getWorld())){ // only if world actually changed
+ if(event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())){ // only if world actually changed
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
}
}
@@ -211,7 +210,7 @@ public class BukkitPermissions { @Override
public void onPlayerTeleport(PlayerTeleportEvent event) { // can be teleported into another world
- if (!event.getFrom().getWorld().equals(event.getTo().getWorld())) { // only if world actually changed
+ if (event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // only if world actually changed
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
}
}
|