diff --git a/src/net/crystalyx/bukkit/simplyperms/SimplyAPI.java b/src/net/crystalyx/bukkit/simplyperms/SimplyAPI.java index a288dbe..1c9b94c 100644 --- a/src/net/crystalyx/bukkit/simplyperms/SimplyAPI.java +++ b/src/net/crystalyx/bukkit/simplyperms/SimplyAPI.java @@ -1,12 +1,7 @@ package net.crystalyx.bukkit.simplyperms; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.configuration.file.YamlConfiguration; import net.crystalyx.bukkit.simplyperms.io.PermsConfig; @@ -98,148 +93,103 @@ public class SimplyAPI implements PermsConfig { return plugin.config.getAllPlayers(); } + @Override public List getAllGroups() { - if (plugin.getNode("groups") != null) { - return new ArrayList(plugin.getNode("groups").getKeys(false)); - } - else { - return new ArrayList(); - } + return plugin.config.getAllGroups(); } + @Override public List getGroupWorlds(String group) { - if (group.isEmpty()) group = getDefaultGroup(); - if (plugin.getNode("groups/" + group + "/worlds") != null) { - return new ArrayList(plugin.getNode("groups/" + group + "/worlds").getKeys(false)); - } - else { - return new ArrayList(); - } + return plugin.config.getGroupWorlds(group); } + @Override public List getGroupInheritance(String group) { - if (group.isEmpty()) group = getDefaultGroup(); - return plugin.getConfig().getStringList("groups/" + group + "/inheritance"); + return plugin.config.getGroupInheritance(group); } + @Override public void addGroupInheritance(String group, String inherit) { - if (group.isEmpty()) group = getDefaultGroup(); - List inheritances = getGroupInheritance(group); - if (!inheritances.contains(inherit)) inheritances.add(inherit); - plugin.getConfig().set("groups/" + group + "/inheritance", inheritances); + plugin.config.addGroupInheritance(group, inherit); } + @Override public void removeGroupInheritance(String group, String inherit) { - if (group.isEmpty()) group = getDefaultGroup(); - List inheritances = getGroupInheritance(group); - inheritances.remove(inherit); - plugin.getConfig().set("groups/" + group + "/inheritance", inheritances); + plugin.config.removeGroupInheritance(group, inherit); } + @Override public void removeGroupInheritances(String group) { - if (group.isEmpty()) group = getDefaultGroup(); - plugin.getConfig().set("groups/" + group + "/inheritance", null); + plugin.config.removeGroupInheritances(group); } + @Override public Map getGroupPermissions(String group, String world) { - if (group.isEmpty()) group = getDefaultGroup(); - Map finalPerms = new HashMap(); - String permNode = (!world.isEmpty()) ? "groups/" + group + "/worlds/" + world : "groups/" + group + "/permissions"; - if (plugin.getNode(permNode) != null) { - for (Entry permGroup : plugin.getNode(permNode).getValues(false).entrySet()) { - finalPerms.put(permGroup.getKey(), (Boolean) permGroup.getValue()); - } - } - return finalPerms; + return plugin.config.getGroupPermissions(group, world); } + @Override public Map getGroupPermissions(String group) { - return getGroupPermissions(group, ""); + return plugin.config.getGroupPermissions(group); } + @Override public void addGroupPermission(String group, String world, String permission, boolean value) { - if (group.isEmpty()) group = getDefaultGroup(); - Map permissions = getGroupPermissions(group, world); - if (permissions.containsKey(permission)) permissions.remove(permission); - permissions.put(permission, value); - if (!world.isEmpty()) { - plugin.getConfig().set("groups/" + group + "/worlds/" + world, permissions); - } - else { - plugin.getConfig().set("groups/" + group + "/permissions", permissions); - } + plugin.config.addGroupPermission(group, world, permission, value); } + @Override public void addGroupPermission(String group, String permission, boolean value) { - addGroupPermission(group, "", permission, value); + plugin.config.addGroupPermission(group, permission, value); } + @Override public void removeGroupPermission(String group, String world, String permission) { - if (group.isEmpty()) group = getDefaultGroup(); - Map permissions = getGroupPermissions(group, world); - permissions.remove(permission); - if (!world.isEmpty()) { - plugin.getConfig().set("groups/" + group + "/worlds/" + world, (permissions.isEmpty()) ? null : permissions); - } - else { - plugin.getConfig().set("groups/" + group + "/permissions", (permissions.isEmpty()) ? null : permissions); - } + plugin.config.removeGroupPermission(group, world, permission); } + @Override public void removeGroupPermission(String group, String permission) { - removeGroupPermission(group, "", permission); + plugin.config.removeGroupPermission(group, permission); } + @Override public void removeGroupPermissions(String group) { - if (group.isEmpty()) group = getDefaultGroup(); - plugin.getConfig().set("groups/" + group + "/permissions", null); + plugin.config.removeGroupPermissions(group); } + @Override public void removeGroup(String group) { - plugin.getConfig().set("groups/" + group, null); + plugin.config.removeGroup(group); } + @Override public Map getMessages() { - if (plugin.getNode("messages") != null) { - return plugin.getNode("messages").getValues(false); - } - else { - return new HashMap(); - } + return plugin.config.getMessages(); } + @Override public void addMessage(String key, String message) { - Map messages = getMessages(); - if (!messages.containsKey(key)) messages.put(key, message); - plugin.getConfig().set("messages", messages); + plugin.config.addMessage(key, message); } + @Override public void removeMessage(String key) { - Map messages = getMessages(); - messages.remove(key); - plugin.getConfig().set("messages", messages); + plugin.config.removeMessage(key); } + @Override public String getDefaultGroup() { - return plugin.getConfig().getString("default", "default"); + return plugin.config.getDefaultGroup(); } + @Override public void setDefaultGroup(String group) { - if (group.isEmpty()) group = "default"; - plugin.getConfig().set("default", group); + plugin.config.setDefaultGroup(group); } public void refreshPermissions() { plugin.refreshPermissions(); } - protected List getKeys(YamlConfiguration config, String node) { - if (config.isConfigurationSection(node)) { - return new ArrayList(config.getConfigurationSection(node).getKeys(false)); - } - else { - return new ArrayList(); - } - } - } diff --git a/src/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java b/src/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java index 9dd35ba..867a49b 100755 --- a/src/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java +++ b/src/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java @@ -2,6 +2,7 @@ package net.crystalyx.bukkit.simplyperms; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -204,6 +205,15 @@ public class SimplyPlugin extends JavaPlugin { } } + public List getKeys(YamlConfiguration config, String node) { + if (config.isConfigurationSection(node)) { + return new ArrayList(config.getConfigurationSection(node).getKeys(false)); + } + else { + return new ArrayList(); + } + } + protected void calculateAttachment(Player player) { if (player == null) { return; diff --git a/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java b/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java index 9fc1d69..235f66a 100644 --- a/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java +++ b/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java @@ -26,7 +26,7 @@ public class ImportPermBukkit extends SimplyAPI implements ImportManager { plugin.getConfig().set("debug", permBukkit.getBoolean("debug")); addMessage("build", permBukkit.getString("messages/build")); - for (String player : getKeys(permBukkit, "users")) { + for (String player : plugin.getKeys(permBukkit, "users")) { for (String group : permBukkit.getStringList("users/" + player + "/groups")) { addPlayerGroup(player, group); } @@ -35,19 +35,19 @@ public class ImportPermBukkit extends SimplyAPI implements ImportManager { addPlayerPermission(player, perm.getKey(), (Boolean) perm.getValue()); } - for (String world : getKeys(permBukkit, "users/" + player + "/worlds")) { + for (String world : plugin.getKeys(permBukkit, "users/" + player + "/worlds")) { for (Entry worldperm : permBukkit.getConfigurationSection("users/" + player + "/worlds/" + world).getValues(false).entrySet()) { addPlayerPermission(player, world, worldperm.getKey(), (Boolean) worldperm.getValue()); } } } - for (String group : getKeys(permBukkit, "groups")) { + for (String group : plugin.getKeys(permBukkit, "groups")) { for (Entry perms : permBukkit.getConfigurationSection("groups/" + group + "/permissions").getValues(false).entrySet()) { addGroupPermission(group, perms.getKey(), (Boolean) perms.getValue()); } - for (String world : getKeys(permBukkit, "groups/" + group + "/worlds")) { + for (String world : plugin.getKeys(permBukkit, "groups/" + group + "/worlds")) { for (Entry worldperm : permBukkit.getConfigurationSection("groups/" + group + "/worlds/" + world).getValues(false).entrySet()) { addGroupPermission(group, world, worldperm.getKey(), (Boolean) worldperm.getValue()); } diff --git a/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermEx.java b/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermEx.java index 62499ab..962aff2 100644 --- a/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermEx.java +++ b/src/net/crystalyx/bukkit/simplyperms/imports/ImportPermEx.java @@ -23,7 +23,7 @@ public class ImportPermEx extends SimplyAPI implements ImportManager { plugin.getConfig().set("debug", permEx.getBoolean("permissions.debug")); permEx.load("plugins/PermissionsEx/" + permEx.getString("permissions.backends.file.file")); - for (String player : getKeys(permEx, "users")) { + for (String player : plugin.getKeys(permEx, "users")) { for (String group : permEx.getStringList("users." + player + ".group")) { addPlayerGroup(player, group); } @@ -32,19 +32,19 @@ public class ImportPermEx extends SimplyAPI implements ImportManager { addPlayerPermission(player, perm.replace("-", ""), !perm.startsWith("-")); } - for (String world : getKeys(permEx, "users." + player + ".permissions.worlds")) { + for (String world : plugin.getKeys(permEx, "users." + player + ".permissions.worlds")) { for (String worldperm : permEx.getStringList("users." + player + ".permissions.worlds." + world)) { addPlayerPermission(player, world, worldperm.replace("-", ""), !worldperm.startsWith("-")); } } } - for (String group : getKeys(permEx, "groups")) { + for (String group : plugin.getKeys(permEx, "groups")) { for (String perm : permEx.getStringList("groups." + group + ".permissions")) { addGroupPermission(group, perm.replace("-", ""), !perm.startsWith("-")); } - for (String world : getKeys(permEx, "groups." + group + ".permissions.worlds")) { + for (String world : plugin.getKeys(permEx, "groups." + group + ".permissions.worlds")) { for (String worldperm : permEx.getStringList("groups." + group + ".permissions.worlds." + world)) { addGroupPermission(group, world, worldperm.replace("-", ""), !worldperm.startsWith("-")); } diff --git a/src/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java b/src/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java index b1e5ac3..dfe0ea4 100644 --- a/src/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java +++ b/src/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java @@ -24,14 +24,14 @@ public class ImportPrivileges extends SimplyAPI implements ImportManager { plugin.getConfig().set("debug", privileges.getBoolean("debug")); privileges.load("plugins/Privileges/users.yml"); - for (String player : getKeys(privileges, "users")) { + for (String player : plugin.getKeys(privileges, "users")) { addPlayerGroup(player, privileges.getString("users." + player + ".group")); for (String permission : privileges.getStringList("users." + player + ".permissions")) { addPlayerPermission(player, permission.replace("-", ""), !permission.startsWith("-")); } - for (String world : getKeys(privileges, "users." + player + ".worlds")) { + for (String world : plugin.getKeys(privileges, "users." + player + ".worlds")) { for (String worldpermission : privileges.getStringList("users." + player + ".worlds." + world)) { addPlayerPermission(player, world, worldpermission.replace("-", ""), !worldpermission.startsWith("-")); } @@ -39,12 +39,12 @@ public class ImportPrivileges extends SimplyAPI implements ImportManager { } privileges.load("plugins/Privileges/groups.yml"); - for (String group : getKeys(privileges, "groups")) { + for (String group : plugin.getKeys(privileges, "groups")) { for (String permission : privileges.getStringList("groups." + group + ".permissions")) { addGroupPermission(group, permission.replace("-", ""), !permission.startsWith("-")); } - for (String world : getKeys(privileges, "groups." + group + ".worlds")) { + for (String world : plugin.getKeys(privileges, "groups." + group + ".worlds")) { for (String worldpermission : privileges.getStringList("groups." + group + ".worlds." + world)) { addGroupPermission(group, world, worldpermission.replace("-", ""), !worldpermission.startsWith("-")); } diff --git a/src/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java b/src/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java index 28d8b49..895429a 100755 --- a/src/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java +++ b/src/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java @@ -141,4 +141,154 @@ public class ConfigFile implements PermsConfig { } } + @Override + public List getAllGroups() { + if (plugin.getNode("groups") != null) { + return new ArrayList(plugin.getNode("groups").getKeys(false)); + } + else { + return new ArrayList(); + } + } + + @Override + public List getGroupWorlds(String group) { + if (group.isEmpty()) group = getDefaultGroup(); + if (plugin.getNode("groups/" + group + "/worlds") != null) { + return new ArrayList(plugin.getNode("groups/" + group + "/worlds").getKeys(false)); + } + else { + return new ArrayList(); + } + } + + @Override + public List getGroupInheritance(String group) { + if (group.isEmpty()) group = getDefaultGroup(); + return plugin.getConfig().getStringList("groups/" + group + "/inheritance"); + } + + @Override + public void addGroupInheritance(String group, String inherit) { + if (group.isEmpty()) group = getDefaultGroup(); + List inheritances = getGroupInheritance(group); + if (!inheritances.contains(inherit)) inheritances.add(inherit); + plugin.getConfig().set("groups/" + group + "/inheritance", inheritances); + } + + @Override + public void removeGroupInheritance(String group, String inherit) { + if (group.isEmpty()) group = getDefaultGroup(); + List inheritances = getGroupInheritance(group); + inheritances.remove(inherit); + plugin.getConfig().set("groups/" + group + "/inheritance", inheritances); + } + + @Override + public void removeGroupInheritances(String group) { + if (group.isEmpty()) group = getDefaultGroup(); + plugin.getConfig().set("groups/" + group + "/inheritance", null); + } + + @Override + public Map getGroupPermissions(String group, String world) { + if (group.isEmpty()) group = getDefaultGroup(); + Map finalPerms = new HashMap(); + String permNode = (!world.isEmpty()) ? "groups/" + group + "/worlds/" + world : "groups/" + group + "/permissions"; + if (plugin.getNode(permNode) != null) { + for (Entry permGroup : plugin.getNode(permNode).getValues(false).entrySet()) { + finalPerms.put(permGroup.getKey(), (Boolean) permGroup.getValue()); + } + } + return finalPerms; + } + + @Override + public Map getGroupPermissions(String group) { + return getGroupPermissions(group, ""); + } + + @Override + public void addGroupPermission(String group, String world, String permission, boolean value) { + if (group.isEmpty()) group = getDefaultGroup(); + Map permissions = getGroupPermissions(group, world); + if (permissions.containsKey(permission)) permissions.remove(permission); + permissions.put(permission, value); + if (!world.isEmpty()) { + plugin.getConfig().set("groups/" + group + "/worlds/" + world, permissions); + } + else { + plugin.getConfig().set("groups/" + group + "/permissions", permissions); + } + } + + @Override + public void addGroupPermission(String group, String permission, boolean value) { + addGroupPermission(group, "", permission, value); + } + + @Override + public void removeGroupPermission(String group, String world, String permission) { + if (group.isEmpty()) group = getDefaultGroup(); + Map permissions = getGroupPermissions(group, world); + permissions.remove(permission); + if (!world.isEmpty()) { + plugin.getConfig().set("groups/" + group + "/worlds/" + world, (permissions.isEmpty()) ? null : permissions); + } + else { + plugin.getConfig().set("groups/" + group + "/permissions", (permissions.isEmpty()) ? null : permissions); + } + } + + @Override + public void removeGroupPermission(String group, String permission) { + removeGroupPermission(group, "", permission); + } + + @Override + public void removeGroupPermissions(String group) { + if (group.isEmpty()) group = getDefaultGroup(); + plugin.getConfig().set("groups/" + group + "/permissions", null); + } + + @Override + public void removeGroup(String group) { + plugin.getConfig().set("groups/" + group, null); + } + + @Override + public Map getMessages() { + if (plugin.getNode("messages") != null) { + return plugin.getNode("messages").getValues(false); + } + else { + return new HashMap(); + } + } + + @Override + public void addMessage(String key, String message) { + Map messages = getMessages(); + if (!messages.containsKey(key)) messages.put(key, message); + plugin.getConfig().set("messages", messages); + } + + @Override + public void removeMessage(String key) { + Map messages = getMessages(); + messages.remove(key); + plugin.getConfig().set("messages", messages); + } + + @Override + public String getDefaultGroup() { + return plugin.getConfig().getString("default", "default"); + } + + @Override + public void setDefaultGroup(String group) { + if (group.isEmpty()) group = "default"; + plugin.getConfig().set("default", group); + } + } diff --git a/src/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java b/src/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java index fce801d..d1195e5 100755 --- a/src/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java +++ b/src/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java @@ -15,6 +15,7 @@ import net.crystalyx.bukkit.simplyperms.SimplyPlugin; public class ConfigSQL implements PermsConfig { private SimplyPlugin plugin; + private ConfigFile config; private Connection connection; private String table_players; private String table_groups; @@ -27,6 +28,7 @@ public class ConfigSQL implements PermsConfig { public ConfigSQL(SimplyPlugin plugin) { this.plugin = plugin; + config = new ConfigFile(plugin); table_players = plugin.getConfig().getString("db/table/players"); table_groups = plugin.getConfig().getString("db/table/groups"); column_playerid = plugin.getConfig().getString("db/column/playerid"); @@ -327,4 +329,99 @@ public class ConfigSQL implements PermsConfig { return results; } + @Override + public List getAllGroups() { + return config.getAllGroups(); + } + + @Override + public List getGroupWorlds(String group) { + return config.getGroupWorlds(group); + } + + @Override + public List getGroupInheritance(String group) { + return config.getGroupInheritance(group); + } + + @Override + public void addGroupInheritance(String group, String inherit) { + config.addGroupInheritance(group, inherit); + } + + @Override + public void removeGroupInheritance(String group, String inherit) { + config.removeGroupInheritance(group, inherit); + } + + @Override + public void removeGroupInheritances(String group) { + config.removeGroupInheritances(group); + } + + @Override + public Map getGroupPermissions(String group, String world) { + return config.getGroupPermissions(group, world); + } + + @Override + public Map getGroupPermissions(String group) { + return config.getGroupPermissions(group); + } + + @Override + public void addGroupPermission(String group, String world, String permission, boolean value) { + config.addGroupPermission(group, world, permission, value); + } + + @Override + public void addGroupPermission(String group, String permission, boolean value) { + config.addGroupPermission(group, permission, value); + } + + @Override + public void removeGroupPermission(String group, String world, String permission) { + config.removeGroupPermission(group, world, permission); + } + + @Override + public void removeGroupPermission(String group, String permission) { + config.removeGroupPermission(group, permission); + } + + @Override + public void removeGroupPermissions(String group) { + config.removeGroupPermissions(group); + } + + @Override + public void removeGroup(String group) { + config.removeGroup(group); + } + + @Override + public Map getMessages() { + return config.getMessages(); + } + + @Override + public void addMessage(String key, String message) { + config.addMessage(key, message); + } + + @Override + public void removeMessage(String key) { + config.removeMessage(key); + } + + @Override + public String getDefaultGroup() { + return config.getDefaultGroup(); + } + + @Override + public void setDefaultGroup(String group) { + config.setDefaultGroup(group); + } + } diff --git a/src/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java b/src/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java index 59eedfe..ace7af3 100755 --- a/src/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java +++ b/src/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java @@ -37,4 +37,42 @@ public interface PermsConfig { public List getAllPlayers(); + public List getAllGroups(); + + public List getGroupWorlds(String group); + + public List getGroupInheritance(String group); + + public void addGroupInheritance(String group, String inherit); + + public void removeGroupInheritance(String group, String inherit); + + public void removeGroupInheritances(String group); + + public Map getGroupPermissions(String group, String world); + + public Map getGroupPermissions(String group); + + public void addGroupPermission(String group, String world, String permission, boolean value); + + public void addGroupPermission(String group, String permission, boolean value); + + public void removeGroupPermission(String group, String world, String permission); + + public void removeGroupPermission(String group, String permission); + + public void removeGroupPermissions(String group); + + public void removeGroup(String group); + + public Map getMessages(); + + public void addMessage(String key, String message); + + public void removeMessage(String key); + + public String getDefaultGroup(); + + public void setDefaultGroup(String group); + }