1.6.2 in github (the previous commit is 1.6.1)

This commit is contained in:
Michel Roux 2012-04-29 02:22:45 +02:00
parent 0cc3fd6ada
commit 9edaca011d
56 changed files with 150 additions and 44 deletions

View File

@ -1,2 +0,0 @@
Manifest-Version: 1.0

1
config.yml Executable file → Normal file
View File

@ -1,4 +1,5 @@
debug: false
default: default
db:
type: file
database: minecraft

33
net/crystalyx/bukkit/simplyperms/SimplyAPI.java Executable file → Normal file
View File

@ -108,7 +108,7 @@ public class SimplyAPI implements PermsConfig {
}
public List<String> getGroupWorlds(String group) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
if (plugin.getNode("groups/" + group + "/worlds") != null) {
return new ArrayList<String>(plugin.getNode("groups/" + group + "/worlds").getKeys(false));
}
@ -118,31 +118,31 @@ public class SimplyAPI implements PermsConfig {
}
public List<String> getGroupInheritance(String group) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
return plugin.getConfig().getStringList("groups/" + group + "/inheritance");
}
public void addGroupInheritance(String group, String inherit) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
List<String> inheritances = getGroupInheritance(group);
if (!inheritances.contains(inherit)) inheritances.add(inherit);
plugin.getConfig().set("groups/" + group + "/inheritance", inheritances);
}
public void removeGroupInheritance(String group, String inherit) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
List<String> inheritances = getGroupInheritance(group);
inheritances.remove(inherit);
plugin.getConfig().set("groups/" + group + "/inheritance", inheritances);
}
public void removeGroupInheritances(String group) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
plugin.getConfig().set("groups/" + group + "/inheritance", null);
}
public Map<String, Boolean> getGroupPermissions(String group, String world) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
Map<String, Boolean> finalPerms = new HashMap<String, Boolean>();
String permNode = (!world.isEmpty()) ? "groups/" + group + "/worlds/" + world : "groups/" + group + "/permissions";
if (plugin.getNode(permNode) != null) {
@ -158,7 +158,7 @@ public class SimplyAPI implements PermsConfig {
}
public void addGroupPermission(String group, String world, String permission, boolean value) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
Map<String, Boolean> permissions = getGroupPermissions(group, world);
if (permissions.containsKey(permission)) permissions.remove(permission);
permissions.put(permission, value);
@ -175,7 +175,7 @@ public class SimplyAPI implements PermsConfig {
}
public void removeGroupPermission(String group, String world, String permission) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
Map<String, Boolean> permissions = getGroupPermissions(group, world);
permissions.remove(permission);
if (!world.isEmpty()) {
@ -191,15 +191,11 @@ public class SimplyAPI implements PermsConfig {
}
public void removeGroupPermissions(String group) {
if (group.isEmpty()) group = "default";
if (group.isEmpty()) group = getDefaultGroup();
plugin.getConfig().set("groups/" + group + "/permissions", null);
}
public void removeGroup(String group) {
if (group.isEmpty() || group.equals("default")) {
plugin.debug("You can't delete default group !");
return;
}
plugin.getConfig().set("groups/" + group, null);
}
@ -224,12 +220,21 @@ public class SimplyAPI implements PermsConfig {
plugin.getConfig().set("messages", messages);
}
public String getDefaultGroup() {
return plugin.getConfig().getString("default", "default");
}
public void setDefaultGroup(String group) {
if (group.isEmpty()) group = "default";
plugin.getConfig().set("default", group);
}
public void refreshPermissions() {
plugin.refreshPermissions();
}
protected List<String> getKeys(YamlConfiguration config, String node) {
if (config.getConfigurationSection(node) != null) {
if (config.isConfigurationSection(node)) {
return new ArrayList<String>(config.getConfigurationSection(node).getKeys(false));
}
else {

View File

@ -4,12 +4,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import net.crystalyx.bukkit.simplyperms.imports.ImportDB;
import net.crystalyx.bukkit.simplyperms.imports.ImportFile;
import net.crystalyx.bukkit.simplyperms.imports.ImportManager;
import net.crystalyx.bukkit.simplyperms.imports.ImportPermBukkit;
import net.crystalyx.bukkit.simplyperms.imports.ImportPermEx;
import net.crystalyx.bukkit.simplyperms.imports.ImportPrivileges;
import org.bukkit.ChatColor;
@ -168,6 +170,8 @@ public class SimplyCommands implements CommandExecutor {
manager = new ImportPermBukkit(plugin);
} else if (pluginName.equals("privileges")) {
manager = new ImportPrivileges(plugin);
} else if (pluginName.equals("permissionsex")) {
manager = new ImportPermEx(plugin);
} else if (pluginName.equals("file")) {
manager = new ImportFile(plugin);
} else if (plugin.getConfig().getString("db/type") != null
@ -227,7 +231,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Users in " + ChatColor.WHITE + group + ChatColor.GREEN + " (" + ChatColor.WHITE + count + ChatColor.GREEN + "): " + ChatColor.WHITE + text);
return true;
} else if (subcommand.equals("setperm")) {
if (!checkPerm(sender, "group.setperm")) return true;
if (split.length >= 4 && !checkPerm(sender, "group.setperm", Arrays.asList(split[3].split(",")))) return true;
if (split.length != 4 && split.length != 5) return usage(sender, command, "group setperm");
String group = split[2];
String perm = split[3];
@ -254,7 +258,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Group " + ChatColor.WHITE + group + ChatColor.GREEN + " now has " + ChatColor.WHITE + perm + ChatColor.GREEN + " = " + ChatColor.WHITE + value + ChatColor.GREEN + ".");
return true;
} else if (subcommand.equals("unsetperm")) {
if (!checkPerm(sender, "group.unsetperm")) return true;
if (split.length >= 4 && !checkPerm(sender, "group.unsetperm", Arrays.asList(split[3].split(",")))) return true;
if (split.length != 4) return usage(sender, command, "group unsetperm");
String group = split[2].toLowerCase();
String perm = split[3];
@ -312,7 +316,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is in groups (" + ChatColor.WHITE + count + ChatColor.GREEN + "): " + ChatColor.WHITE + text);
return true;
} else if (subcommand.equals("setgroup")) {
if (!checkPerm(sender, "player.setgroup")) return true;
if (split.length == 4 && !checkPerm(sender, "player.setgroup", Arrays.asList(split[3].split(",")))) return true;
if (split.length != 4) return usage(sender, command, "player setgroup");
String player = split[2].toLowerCase();
String[] groups = split[3].split(",");
@ -327,7 +331,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is now in " + ChatColor.WHITE + split[3] + ChatColor.GREEN + ".");
return true;
} else if (subcommand.equals("addgroup")) {
if (!checkPerm(sender, "player.addgroup")) return true;
if (split.length == 4 && !checkPerm(sender, "player.addgroup", Arrays.asList(split[3]))) return true;
if (split.length != 4) return usage(sender, command, "player addgroup");
String player = split[2].toLowerCase();
String group = split[3];
@ -343,7 +347,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is now in " + ChatColor.WHITE + group + ChatColor.GREEN + ".");
return true;
} else if (subcommand.equals("removegroup")) {
if (!checkPerm(sender, "player.removegroup")) return true;
if (split.length == 4 && !checkPerm(sender, "player.removegroup", Arrays.asList(split[3]))) return true;
if (split.length != 4) return usage(sender, command, "player removegroup");
String player = split[2].toLowerCase();
String group = split[3];
@ -374,7 +378,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is no longer in config file.");
return true;
} else if (subcommand.equals("setperm")) {
if (!checkPerm(sender, "player.setperm")) return true;
if (split.length >= 4 && !checkPerm(sender, "player.setperm", Arrays.asList(split[3].split(",")))) return true;
if (split.length != 4 && split.length != 5) return usage(sender, command, "player setperm");
String player = split[2].toLowerCase();
String perm = split[3];
@ -392,7 +396,7 @@ public class SimplyCommands implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " now has " + ChatColor.WHITE + perm + ChatColor.GREEN + " = " + ChatColor.WHITE + value + ChatColor.GREEN + ".");
return true;
} else if (subcommand.equals("unsetperm")) {
if (!checkPerm(sender, "player.unsetperm")) return true;
if (split.length >= 4 && !checkPerm(sender, "player.unsetperm", Arrays.asList(split[3].split(",")))) return true;
if (split.length != 4) return usage(sender, command, "player unsetperm");
String player = split[2].toLowerCase();
String perm = split[3];
@ -428,6 +432,27 @@ public class SimplyCommands implements CommandExecutor {
return ok;
}
private boolean checkPerm(CommandSender sender, String node, List<String> subnodes) {
boolean ok = sender.hasPermission("permissions." + node);
if (!ok) {
for (String subnode : subnodes) {
String testnode = "";
for (String sub : subnode.split(".")) {
testnode += sub;
if (sender.hasPermission("permissions." + node + "." + testnode)) {
ok = true;
break;
}
}
if (ok) break;
}
}
if (!ok) {
sender.sendMessage(ChatColor.RED + "You do not have permissions to do that.");
}
return ok;
}
private boolean usage(CommandSender sender, Command command) {
sender.sendMessage(ChatColor.RED + "[====" + ChatColor.GREEN + " /permissons " + ChatColor.RED + "====]");
for (String line : command.getUsage().split("\\n")) {

View File

@ -16,6 +16,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.plugin.java.JavaPlugin;
@ -32,6 +33,20 @@ public class SimplyPlugin extends JavaPlugin {
// -- Basic stuff
@Override
public void onEnable() {
// Unregister existing PermissionsBukkit nodes
if (getServer().getPluginManager().isPluginEnabled("PermissionsBukkit")) {
for (Permission perm : getServer().getPluginManager().getPlugin("PermissionsBukkit").getDescription().getPermissions()) {
getServer().getPluginManager().removePermission(perm);
}
}
// Disable others permissions plugin
for (String permPlugin : getDescription().getSoftDepend()) {
if (getServer().getPluginManager().isPluginEnabled(permPlugin)) {
getServer().getPluginManager().disablePlugin(getServer().getPluginManager().getPlugin(permPlugin));
}
}
// Take care of configuration
configFile = new File(getDataFolder(), "config.yml");
if (!configFile.exists()) {
@ -146,7 +161,7 @@ public class SimplyPlugin extends JavaPlugin {
}
}
protected ConfigurationSection getNode(String node) {
public ConfigurationSection getNode(String node) {
for (String entry : getConfig().getKeys(true)) {
if (node.equalsIgnoreCase(entry) && getConfig().isConfigurationSection(entry)) {
return getConfig().getConfigurationSection(entry);
@ -213,13 +228,14 @@ public class SimplyPlugin extends JavaPlugin {
// -- Private stuff
private Map<String, Boolean> calculatePlayerPermissions(String player, String world) {
String default_group = getConfig().getString("default", "default");
if (!config.isPlayerInDB(player)) {
return calculateGroupPermissions("default", world);
return calculateGroupPermissions(default_group, world);
}
Map<String, Boolean> perms = new HashMap<String, Boolean>();
List<String> groups = config.getPlayerGroups(player);
if (groups.isEmpty()) groups.add("default");
if (groups.isEmpty()) groups.add(default_group);
for (Entry<String, Boolean> entry : config.getPlayerPermissions(player).entrySet()) {
perms.put(entry.getKey(), entry.getValue());

0
net/crystalyx/bukkit/simplyperms/imports/ImportDB.java Executable file → Normal file
View File

View File

View File

View File

View File

@ -0,0 +1,62 @@
package net.crystalyx.bukkit.simplyperms.imports;
import org.bukkit.configuration.file.YamlConfiguration;
import net.crystalyx.bukkit.simplyperms.SimplyAPI;
import net.crystalyx.bukkit.simplyperms.SimplyPlugin;
public class ImportPermEx extends SimplyAPI implements ImportManager {
private SimplyPlugin plugin;
private YamlConfiguration permEx;
public ImportPermEx(SimplyPlugin plugin) {
super(plugin);
this.plugin = plugin;
this.permEx = new YamlConfiguration();
}
@Override
public void run() throws Exception {
try {
permEx.load("plugins/PermissionsEx/config.yml");
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 group : permEx.getStringList("users." + player + ".group")) {
addPlayerGroup(player, group);
}
for (String perm : permEx.getStringList("users." + player + ".permissions")) {
addPlayerPermission(player, perm.replace("-", ""), !perm.startsWith("-"));
}
for (String world : 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 perm : permEx.getStringList("groups." + group + ".permissions")) {
addGroupPermission(group, perm.replace("-", ""), !perm.startsWith("-"));
}
for (String world : getKeys(permEx, "groups." + group + ".permissions.worlds")) {
for (String worldperm : permEx.getStringList("groups." + group + ".permissions.worlds." + world)) {
addGroupPermission(group, world, worldperm.replace("-", ""), !worldperm.startsWith("-"));
}
}
for (String inherit : permEx.getStringList("groups." + group + ".inheritance")) {
addGroupInheritance(group, inherit);
}
}
} catch (Exception e) {
throw e;
}
}
}

View File

@ -20,7 +20,7 @@ public class ImportPrivileges extends SimplyAPI implements ImportManager {
public void run() throws Exception {
try {
privileges.load("plugins/Privileges/config.yml");
String defaultGroup = privileges.getString("default_group");
setDefaultGroup(privileges.getString("default_group"));
plugin.getConfig().set("debug", privileges.getBoolean("debug"));
privileges.load("plugins/Privileges/users.yml");
@ -28,32 +28,30 @@ public class ImportPrivileges extends SimplyAPI implements ImportManager {
addPlayerGroup(player, privileges.getString("users." + player + ".group"));
for (String permission : privileges.getStringList("users." + player + ".permissions")) {
addPlayerPermission(player, permission, !permission.contains("-"));
addPlayerPermission(player, permission.replace("-", ""), !permission.startsWith("-"));
}
for (String world : getKeys(privileges, "users." + player + ".worlds")) {
for (String worldpermission : privileges.getStringList("users." + player + ".worlds." + world)) {
addPlayerPermission(player, world, worldpermission, !worldpermission.contains("-"));
addPlayerPermission(player, world, worldpermission.replace("-", ""), !worldpermission.startsWith("-"));
}
}
}
privileges.load("plugins/Privileges/groups.yml");
for (String group : getKeys(privileges, "groups")) {
String simplyGroup = (group.equals(defaultGroup)) ? "default" : group;
for (String permission : privileges.getStringList("groups." + group + ".permissions")) {
addGroupPermission(simplyGroup, permission, !permission.contains("-"));
addGroupPermission(group, permission.replace("-", ""), !permission.startsWith("-"));
}
for (String world : getKeys(privileges, "groups." + group + ".worlds")) {
for (String worldpermission : privileges.getStringList("groups." + group + ".worlds." + world)) {
addGroupPermission(simplyGroup, world, worldpermission, !worldpermission.contains("-"));
addGroupPermission(group, world, worldpermission.replace("-", ""), !worldpermission.startsWith("-"));
}
}
for (String inherit : privileges.getStringList("groups." + group + ".inheritance")) {
addGroupInheritance(simplyGroup, inherit);
addGroupInheritance(group, inherit);
}
}
} catch (Exception e) {

View File

@ -35,7 +35,7 @@ public class ConfigFile implements PermsConfig {
@Override
public void addPlayerGroup(String player, String group) {
if (group.isEmpty() || group.equals("default")) return;
if (group.isEmpty()) return;
List<String> groups = getPlayerGroups(player);
if (!groups.contains(group)) groups.add(group);
plugin.getConfig().set("users/" + player + "/groups", groups);
@ -108,8 +108,8 @@ public class ConfigFile implements PermsConfig {
public Map<String, Boolean> getPlayerPermissions(String player, String world) {
Map<String, Boolean> finalPerms = new HashMap<String, Boolean>();
String permNode = (!world.isEmpty()) ? "users/" + player + "/worlds/" + world : "users/" + player + "/permissions";
if (plugin.getConfig().getConfigurationSection(permNode) != null) {
for (Entry<String, Object> permPlayer : plugin.getConfig().getConfigurationSection(permNode).getValues(false).entrySet()) {
if (plugin.getNode(permNode) != null) {
for (Entry<String, Object> permPlayer : plugin.getNode(permNode).getValues(false).entrySet()) {
finalPerms.put(permPlayer.getKey(), (Boolean) permPlayer.getValue());
}
}
@ -118,13 +118,13 @@ public class ConfigFile implements PermsConfig {
@Override
public boolean isPlayerInDB(String player) {
return plugin.getConfig().getConfigurationSection("users/" + player) != null;
return plugin.getNode("users/" + player) != null;
}
@Override
public List<String> getPlayerWorlds(String player) {
if (plugin.getConfig().getConfigurationSection("users/" + player + "/worlds") != null) {
return new ArrayList<String>(plugin.getConfig().getConfigurationSection("users/" + player + "/worlds").getKeys(false));
if (plugin.getNode("users/" + player + "/worlds") != null) {
return new ArrayList<String>(plugin.getNode("users/" + player + "/worlds").getKeys(false));
}
else {
return new ArrayList<String>();
@ -133,8 +133,8 @@ public class ConfigFile implements PermsConfig {
@Override
public List<String> getAllPlayers() {
if (plugin.getConfig().getConfigurationSection("users") != null) {
return new ArrayList<String>(plugin.getConfig().getConfigurationSection("users").getKeys(false));
if (plugin.getNode("users") != null) {
return new ArrayList<String>(plugin.getNode("users").getKeys(false));
}
else {
return new ArrayList<String>();

0
net/crystalyx/bukkit/simplyperms/preventions/Bow.java Executable file → Normal file
View File

View File

0
net/crystalyx/bukkit/simplyperms/preventions/Chat.java Executable file → Normal file
View File

View File

View File

View File

View File

0
net/crystalyx/bukkit/simplyperms/preventions/Item.java Executable file → Normal file
View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

3
plugin.yml Executable file → Normal file
View File

@ -2,7 +2,8 @@ name: SimplyPerms
main: net.crystalyx.bukkit.simplyperms.SimplyPlugin
author: Xefir Destiny
website: http://www.crystalyx.net/
version: 1.6.1
version: 1.6.2
softdepend: [ PermissionsBukkit, Privileges, GroupManager, PermissionsEx, bPermissions, zPermissions ]
commands:
permissions:
aliases: [ perms, perm, p ]