Merge remote branch 'remotes/ess/groupmanager' into essmaster

This commit is contained in:
KHobbits 2011-10-03 10:19:31 +01:00
commit aa0935c64b
9 changed files with 208 additions and 127 deletions

View File

@ -23,4 +23,16 @@ v 1.1:
- Fix for GM not checking inheritance for known superperms nodes. - Fix for GM not checking inheritance for known superperms nodes.
- Optimized getAllPlayersPermissions and fixed pushing unknown perms to superperms. - Optimized getAllPlayersPermissions and fixed pushing unknown perms to superperms.
v 1.2: v 1.2:
- Changed priority if Registered events to lowest. - 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

View File

@ -1,12 +1,19 @@
settings: settings:
config:
# With this enabled anyone set as op has full permissions when managing GroupManager
opOverrides: true
data: data:
save: save:
# How often GroupManager will save it's data back to groups and users.yml
minutes: 10 minutes: 10
logging: logging:
# level of detail GroupManager will use when logging.
# Acceptable entries are - ALL,CONFIG,FINE,FINER,FINEST,INFO,OFF,SEVERE,WARNING
level: INFO level: INFO
permission: permission:
world: world:
mirror: mirror:
# Worlds listed here have their permissions mirrored in their children.
world: world:
- world_nether - world_nether
- world2 - world2

View File

@ -5,15 +5,12 @@
package org.anjocaido.groupmanager; package org.anjocaido.groupmanager;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import org.anjocaido.groupmanager.utils.Tasks; import org.anjocaido.groupmanager.utils.Tasks;
import org.yaml.snakeyaml.Yaml; import org.bukkit.util.config.Configuration;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.reader.UnicodeReader;
/** /**
* *
@ -22,8 +19,8 @@ import org.yaml.snakeyaml.reader.UnicodeReader;
public class GMConfiguration { public class GMConfiguration {
private GroupManager plugin; private GroupManager plugin;
private Map<String, Object> rootDataNode;
private File configFile; private File configFile;
private Configuration GMconfig;
public GMConfiguration(GroupManager plugin) { public GMConfiguration(GroupManager plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -44,77 +41,37 @@ public class GMConfiguration {
} }
} }
Yaml yaml = new Yaml(new SafeConstructor()); GMconfig = new Configuration(configFile);
FileInputStream rx = null;
try { try {
rx = new FileInputStream(configFile); GMconfig.load();
} catch (FileNotFoundException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex);
}
try {
rootDataNode = (Map<String, Object>) yaml.load(new UnicodeReader(rx));
if (rootDataNode == null) {
throw new NullPointerException();
}
} catch (Exception ex) { } catch (Exception ex) {
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex); throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
} finally {
try {
rx.close();
} catch (IOException ex) {
}
} }
adjustLoggerLevel(); adjustLoggerLevel();
} }
public boolean isOpOverride() {
return GMconfig.getBoolean("settings.config.opOverrides", true);
}
@SuppressWarnings("unchecked")
public Map<String, Object> getMirrorsMap() { public Map<String, Object> getMirrorsMap() {
if (rootDataNode.get("settings") instanceof Map) { return (Map<String, Object>) GMconfig.getProperty("settings.permission.world.mirror");
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;
} }
public Integer getSaveInterval() { public Integer getSaveInterval() {
if (rootDataNode.get("settings") instanceof Map) { return GMconfig.getInt("settings.data.save.minutes", 10);
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 void adjustLoggerLevel() { 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 { try {
GroupManager.logger.setLevel(Level.parse(level)); GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO")));
return; return;
} catch (Exception e) { } catch (Exception e) {
} }
}
}
}
GroupManager.logger.setLevel(Level.INFO); GroupManager.logger.setLevel(Level.INFO);
} }
} }

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder; import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
import org.anjocaido.groupmanager.events.GMWorldListener;
import org.anjocaido.groupmanager.utils.GMLoggerHandler; import org.anjocaido.groupmanager.utils.GMLoggerHandler;
import org.anjocaido.groupmanager.utils.PermissionCheckResult; import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.anjocaido.groupmanager.utils.Tasks; import org.anjocaido.groupmanager.utils.Tasks;
@ -32,9 +33,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; 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.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@SuppressWarnings("unused") @SuppressWarnings("unused")
/** /**
* *
@ -55,6 +59,7 @@ public class GroupManager extends JavaPlugin {
private GMConfiguration config; private GMConfiguration config;
private GMLoggerHandler ch; private GMLoggerHandler ch;
public static BukkitPermissions BukkitPermissions; public static BukkitPermissions BukkitPermissions;
private static WorldListener WorldEvents;
public static final Logger logger = Logger.getLogger(GroupManager.class.getName()); public static final Logger logger = Logger.getLogger(GroupManager.class.getName());
//PERMISSIONS FOR COMMAND BEING LOADED //PERMISSIONS FOR COMMAND BEING LOADED
@ -69,6 +74,10 @@ public class GroupManager extends JavaPlugin {
worldsHolder.saveChanges(); worldsHolder.saveChanges();
} }
disableScheduler(); disableScheduler();
WorldEvents = null;
BukkitPermissions = null;
// EXAMPLE: Custom code, here we just output some info so we can check all is well // EXAMPLE: Custom code, here we just output some info so we can check all is well
PluginDescriptionFile pdfFile = this.getDescription(); PluginDescriptionFile pdfFile = this.getDescription();
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!"); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
@ -94,6 +103,8 @@ public class GroupManager extends JavaPlugin {
throw new IllegalStateException("An error ocurred while loading GroupManager"); 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); BukkitPermissions = new BukkitPermissions(this);
enableScheduler(); enableScheduler();
@ -108,10 +119,11 @@ public class GroupManager extends JavaPlugin {
setLoaded(true); setLoaded(true);
} }
//setLoaded(true);
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
} }
public static boolean isLoaded() { public static boolean isLoaded() {
return isLoaded; return isLoaded;
} }
@ -232,6 +244,7 @@ public class GroupManager extends JavaPlugin {
Player senderPlayer = null, targetPlayer = null; Player senderPlayer = null, targetPlayer = null;
Group senderGroup = null; Group senderGroup = null;
User senderUser = null; User senderUser = null;
boolean isOpOverride = config.isOpOverride();
//DETERMINING PLAYER INFORMATION //DETERMINING PLAYER INFORMATION
@ -239,8 +252,10 @@ public class GroupManager extends JavaPlugin {
senderPlayer = (Player) sender; senderPlayer = (Player) sender;
senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
senderGroup = senderUser.getGroup(); senderGroup = senderUser.getGroup();
isOpOverride = (isOpOverride && senderPlayer.isOp());
System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " ")); 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; playerCanDo = true;
} }
} else if (sender instanceof ConsoleCommandSender) { } else if (sender instanceof ConsoleCommandSender) {
@ -338,23 +353,23 @@ public class GroupManager extends JavaPlugin {
} }
//VALIDANDO PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; 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."); sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
return false; 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."); sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit.");
return false; 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."); sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
return false; 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."); sender.sendMessage(ChatColor.RED + "The new group must be a higher rank.");
return false; return false;
} }
@ -392,7 +407,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]); auxUser = dataHolder.getUser(args[0]);
} }
//VALIDANDO PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; return false;
} }
@ -436,7 +451,7 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
//VALIDANDO PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; return false;
} }
@ -472,7 +487,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]); auxUser = dataHolder.getUser(args[0]);
} }
//VALIDANDO PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; return false;
} }
@ -557,7 +572,7 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); 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))) { || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have."); sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
return false; return false;
@ -620,12 +635,12 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]); auxUser = dataHolder.getUser(args[0]);
} }
//VALIDANDO SUA PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
return false; return false;
} }
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); 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))) { || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have."); sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
return false; return false;
@ -1554,23 +1569,23 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
//VALIDANDO PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; 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."); sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
return false; 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."); sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit.");
return false; 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."); sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
return false; 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."); sender.sendMessage(ChatColor.RED + "The new group must be a higher rank.");
return false; return false;
} }
@ -1612,23 +1627,23 @@ public class GroupManager extends JavaPlugin {
return false; return false;
} }
//VALIDANDO PERMISSAO //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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; 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."); sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
return false; 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."); sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don' inherit.");
return false; 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."); sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
return false; 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."); sender.sendMessage(ChatColor.RED + "The new group must be a lower rank.");
return false; return false;
} }

View File

@ -18,6 +18,7 @@ public class BukkitPermsUpdateTask implements Runnable {
public void run() { public void run() {
// Signal loaded and update BukkitPermissions. // Signal loaded and update BukkitPermissions.
GroupManager.setLoaded(true); GroupManager.setLoaded(true);
GroupManager.BukkitPermissions.collectPermissions();
GroupManager.BukkitPermissions.updateAllPlayers(); GroupManager.BukkitPermissions.updateAllPlayers();
GroupManager.logger.info("Bukkit Permissions Updated!"); GroupManager.logger.info("Bukkit Permissions Updated!");

View File

@ -767,6 +767,7 @@ public class WorldDataHolder {
aGroupMap.put("permissions", group.getPermissionList()); aGroupMap.put("permissions", group.getPermissionList());
} }
if (!root.isEmpty()) {
DumperOptions opt = new DumperOptions(); DumperOptions opt = new DumperOptions();
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final Yaml yaml = new Yaml(opt); final Yaml yaml = new Yaml(opt);
@ -775,6 +776,7 @@ public class WorldDataHolder {
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
} }
}
/*FileWriter tx = null; /*FileWriter tx = null;
try { try {
@ -829,6 +831,8 @@ public class WorldDataHolder {
aUserMap.put("subgroups", user.subGroupListStringCopy()); aUserMap.put("subgroups", user.subGroupListStringCopy());
//END SUBGROUPS NODE - BETA //END SUBGROUPS NODE - BETA
} }
if (!root.isEmpty()) {
DumperOptions opt = new DumperOptions(); DumperOptions opt = new DumperOptions();
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final Yaml yaml = new Yaml(opt); final Yaml yaml = new Yaml(opt);
@ -837,6 +841,7 @@ public class WorldDataHolder {
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
} }
}
/*FileWriter tx = null; /*FileWriter tx = null;
try { try {
tx = new FileWriter(usersFile, false); tx = new FileWriter(usersFile, false);

View File

@ -21,6 +21,7 @@ import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder; import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler; import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.anjocaido.groupmanager.utils.Tasks; import org.anjocaido.groupmanager.utils.Tasks;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
@ -52,6 +53,7 @@ public class WorldsHolder {
*/ */
public WorldsHolder(GroupManager plugin) { public WorldsHolder(GroupManager plugin) {
this.plugin = plugin; this.plugin = plugin;
// Setup folders and check files exist for the primary world
verifyFirstRun(); verifyFirstRun();
initialLoad(); initialLoad();
if (defaultWorld == null) { if (defaultWorld == null) {
@ -60,20 +62,47 @@ public class WorldsHolder {
} }
private void initialLoad() { private void initialLoad() {
// load the initial world
initialWorldLoading(); initialWorldLoading();
// Configure and load any mirrors and additional worlds as defined in config.yml
mirrorSetUp(); mirrorSetUp();
// search the worlds folder for any manually created worlds (not listed in config.yml)
loadAllSearchedWorlds();
} }
private void initialWorldLoading() { private void initialWorldLoading() {
//LOAD EVERY WORLD POSSIBLE //Load the default world
loadWorld(serverDefaultWorldName); loadWorld(serverDefaultWorldName);
defaultWorld = worldsData.get(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()) { for (File folder : worldsFolder.listFiles()) {
if (folder.getName().equalsIgnoreCase(serverDefaultWorldName)) { 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; continue;
} }
if (folder.isDirectory()) {
loadWorld(folder.getName()); loadWorld(folder.getName());
} }
} }
@ -85,6 +114,12 @@ public class WorldsHolder {
Map<String, Object> mirrorsMap = plugin.getConfig().getMirrorsMap(); Map<String, Object> mirrorsMap = plugin.getConfig().getMirrorsMap();
if (mirrorsMap != null) { if (mirrorsMap != null) {
for (String source : mirrorsMap.keySet()) { 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) { if (mirrorsMap.get(source) instanceof ArrayList) {
ArrayList mirrorList = (ArrayList) mirrorsMap.get(source); ArrayList mirrorList = (ArrayList) mirrorsMap.get(source);
for (Object o : mirrorList) { for (Object o : mirrorList) {
@ -246,18 +281,25 @@ public class WorldsHolder {
} }
private void verifyFirstRun() { private void verifyFirstRun() {
Properties server = new Properties();
try {
server.load(new FileInputStream(new File("server.properties")));
serverDefaultWorldName = server.getProperty("level-name").toLowerCase();
setupWorldFolder(serverDefaultWorldName);
} catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex);
}
}
public void setupWorldFolder(String worldName) {
worldsFolder = new File(plugin.getDataFolder(), "worlds"); worldsFolder = new File(plugin.getDataFolder(), "worlds");
if (!worldsFolder.exists()) { if (!worldsFolder.exists()) {
worldsFolder.mkdirs(); worldsFolder.mkdirs();
} }
Properties server = new Properties();
try { File defaultWorldFolder = new File(worldsFolder, worldName);
server.load(new FileInputStream(new File("server.properties")));
} catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex);
}
serverDefaultWorldName = server.getProperty("level-name").toLowerCase();
File defaultWorldFolder = new File(worldsFolder, serverDefaultWorldName);
if (!defaultWorldFolder.exists()) { if (!defaultWorldFolder.exists()) {
defaultWorldFolder.mkdirs(); defaultWorldFolder.mkdirs();
} }

View File

@ -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.");
}
}
}

View File

@ -43,7 +43,6 @@ import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
//import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -93,7 +92,7 @@ public class BukkitPermissions {
manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin); manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin);
} }
private void collectPermissions() { public void collectPermissions() {
registeredPermissions.clear(); registeredPermissions.clear();
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) { for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
for(Permission permission : bukkitPlugin.getDescription().getPermissions()) for(Permission permission : bukkitPlugin.getDescription().getPermissions())
@ -134,7 +133,7 @@ public class BukkitPermissions {
Boolean value; Boolean value;
for (Permission permission : registeredPermissions) { for (Permission permission : registeredPermissions) {
value = worldData.getPermissionsHandler().checkUserPermission(user, permission.getName()); value = worldData.getPermissionsHandler().checkUserPermission(user, permission.getName());
if (value == true)
attachment.setPermission(permission, value); attachment.setPermission(permission, value);
} }
@ -199,7 +198,7 @@ public class BukkitPermissions {
@Override @Override
public void onPlayerPortal(PlayerPortalEvent event) { // will portal into another world 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()); updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
} }
} }
@ -211,7 +210,7 @@ public class BukkitPermissions {
@Override @Override
public void onPlayerTeleport(PlayerTeleportEvent event) { // can be teleported into another world 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()); updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
} }
} }