mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-08-26 07:22:56 +02:00
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)
This commit is contained in:
parent
0462026f33
commit
f712b56671
|
@ -24,4 +24,10 @@ v 1.1:
|
|||
- Optimized getAllPlayersPermissions and fixed pushing unknown perms to superperms.
|
||||
v 1.2:
|
||||
- Changed priority of Registered events to lowest.
|
||||
- Fixed an issue with superperms where plugins define perms with inheritance after the root perms
|
||||
- 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)
|
|
@ -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
|
||||
|
|
90
EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
Executable file → Normal file
90
EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
Executable file → Normal file
|
@ -5,15 +5,11 @@
|
|||
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 +18,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 +40,37 @@ public class GMConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
Yaml yaml = new Yaml(new SafeConstructor());
|
||||
FileInputStream rx = null;
|
||||
GMconfig = new Configuration(configFile);
|
||||
|
||||
try {
|
||||
rx = new FileInputStream(configFile);
|
||||
} 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();
|
||||
}
|
||||
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 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;
|
||||
|
||||
public boolean isOpOverride() {
|
||||
return GMconfig.getBoolean("settings.config.opOverrides", true);
|
||||
}
|
||||
|
||||
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;
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getMirrorsMap() {
|
||||
return (Map<String, Object>) GMconfig.getProperty("settings.permission.world.mirror");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -232,6 +232,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 +240,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 +341,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 +395,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 +439,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 +475,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 +560,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 +623,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 +1557,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 +1615,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;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
|
|||
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||
import org.anjocaido.groupmanager.utils.Tasks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -85,6 +86,8 @@ 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);
|
||||
if (mirrorsMap.get(source) instanceof ArrayList) {
|
||||
ArrayList mirrorList = (ArrayList) mirrorsMap.get(source);
|
||||
for (Object o : mirrorList) {
|
||||
|
@ -246,17 +249,24 @@ public class WorldsHolder {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setupWorldFolder(String worldName) {
|
||||
worldsFolder = new File(plugin.getDataFolder(), "worlds");
|
||||
if (!worldsFolder.exists()) {
|
||||
worldsFolder.mkdirs();
|
||||
}
|
||||
Properties server = new Properties();
|
||||
try {
|
||||
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()) {
|
||||
defaultWorldFolder.mkdirs();
|
||||
|
|
Loading…
Reference in New Issue
Block a user