Merge pull request #309 from krinsdeath/master

Updated Privileges' implementation in Vault
This commit is contained in:
Rodney Ramos 2012-12-02 14:20:36 -08:00
commit 7b5da490e3
3 changed files with 31 additions and 47 deletions

Binary file not shown.

View File

@ -23,7 +23,7 @@
<dependency> <dependency>
<groupId>net.krinsoft.privileges</groupId> <groupId>net.krinsoft.privileges</groupId>
<artifactId>Privileges</artifactId> <artifactId>Privileges</artifactId>
<version>1.4.0b45</version> <version>1.7b127</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/Privileges.jar</systemPath> <systemPath>${project.basedir}/lib/Privileges.jar</systemPath>
</dependency> </dependency>

View File

@ -2,12 +2,9 @@ package net.milkbowl.vault.permission.plugins;
import net.krinsoft.privileges.Privileges; import net.krinsoft.privileges.Privileges;
import net.krinsoft.privileges.groups.Group; import net.krinsoft.privileges.groups.Group;
import net.krinsoft.privileges.groups.GroupManager;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -16,21 +13,22 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.util.HashSet;
import java.util.Set;
public class Permission_Privileges extends Permission { public class Permission_Privileges extends Permission {
private final String name = ""; private final String name = "";
private GroupManager perms;
private Privileges privs; private Privileges privs;
public Permission_Privileges(Plugin plugin) { public Permission_Privileges(Plugin plugin) {
this.plugin = plugin; this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
// Load service in case it was loaded before // Load service in case it was loaded before
if (perms == null) { if (privs == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Privileges"); Plugin perms = plugin.getServer().getPluginManager().getPlugin("Privileges");
if (perms != null && perms.isEnabled()) { if (perms != null && perms.isEnabled()) {
this.privs = (Privileges) perms; this.privs = (Privileges) perms;
this.perms = privs.getGroupManager();
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
} }
} }
@ -45,13 +43,12 @@ public class Permission_Privileges extends Permission {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
if (permission.perms == null) { if (permission.privs == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("SimplyPerms"); Plugin perms = plugin.getServer().getPluginManager().getPlugin("SimplyPerms");
if (perms != null) { if (perms != null) {
if (perms.isEnabled()) { if (perms.isEnabled()) {
permission.privs = (Privileges) perms; permission.privs = (Privileges) perms;
permission.perms = permission.privs.getGroupManager();
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
} }
} }
@ -60,9 +57,8 @@ public class Permission_Privileges extends Permission {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
if (permission.perms != null) { if (permission.privs != null) {
if (event.getPlugin().getDescription().getName().equals("SimplyPerms")) { if (event.getPlugin().getDescription().getName().equals("SimplyPerms")) {
permission.perms = null;
permission.privs = null; permission.privs = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
} }
@ -83,7 +79,7 @@ public class Permission_Privileges extends Permission {
@Override @Override
public boolean playerHas(String world, String player, String permission) { public boolean playerHas(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player); Player p = plugin.getServer().getPlayer(player);
return p != null ? p.hasPermission(permission) : false; return p != null && p.hasPermission(permission);
} }
@Override @Override
@ -100,77 +96,65 @@ public class Permission_Privileges extends Permission {
@Override @Override
public boolean groupHas(String world, String group, String permission) { public boolean groupHas(String world, String group, String permission) {
ConfigurationSection priv = privs.getGroupNode(group); Group g = privs.getGroupManager().getGroup(group);
if (priv == null) { return g != null && g.hasPermission(permission, world);
return false;
} else {
return priv.getBoolean(permission);
}
} }
@Override @Override
public boolean groupAdd(String world, String group, String permission) { public boolean groupAdd(String world, String group, String permission) {
throw new UnsupportedOperationException("Privileges does not support modifying permissions."); Group g = privs.getGroupManager().getGroup(group);
return g != null && g.addPermission(permission, world);
} }
@Override @Override
public boolean groupRemove(String world, String group, String permission) { public boolean groupRemove(String world, String group, String permission) {
throw new UnsupportedOperationException("Privileges does not support modifying permissions."); Group g = privs.getGroupManager().getGroup(group);
return g != null && g.removePermission(permission, world);
} }
@Override @Override
public boolean playerInGroup(String world, String player, String group) { public boolean playerInGroup(String world, String player, String group) {
Player p = Bukkit.getPlayer(player); OfflinePlayer p = Bukkit.getOfflinePlayer(player);
if (p == null) { Group g = privs.getGroupManager().getGroup(p);
throw new UnsupportedOperationException("Privileges does not support offline players."); return g != null && g.getGroupTree().contains(group);
}
Group g = perms.getGroup(p);
return g != null && g.getName().equalsIgnoreCase(group);
} }
@Override @Override
public boolean playerAddGroup(String world, String player, String group) { public boolean playerAddGroup(String world, String player, String group) {
if (world != null) { privs.getGroupManager().setGroup(player, group);
return false;
}
perms.setGroup(player, group);
return true; return true;
} }
@Override @Override
public boolean playerRemoveGroup(String world, String player, String group) { public boolean playerRemoveGroup(String world, String player, String group) {
Group g = perms.getDefaultGroup(); Group g = privs.getGroupManager().getDefaultGroup();
if (g == null) { return g != null && playerAddGroup(world, player, g.getName());
return false;
}
return playerAddGroup(world, player, g.getName());
} }
@Override @Override
public String[] getPlayerGroups(String world, String player) { public String[] getPlayerGroups(String world, String player) {
Player p = Bukkit.getPlayer(player); OfflinePlayer p = Bukkit.getOfflinePlayer(player);
if (p == null) { if (p == null) {
throw new UnsupportedOperationException("Privileges does not support offline players."); throw new UnsupportedOperationException("Privileges does not support offline players.");
} }
Group g = perms.getGroup(p); Group g = privs.getGroupManager().getGroup(p);
return g != null ? new String[] { g.getName() } : null; return g != null ? g.getGroupTree().toArray(new String[g.getGroupTree().size()]) : null;
} }
@Override @Override
public String getPrimaryGroup(String world, String player) { public String getPrimaryGroup(String world, String player) {
Player p = Bukkit.getPlayer(player); OfflinePlayer p = Bukkit.getOfflinePlayer(player);
if (p == null) { Group g = privs.getGroupManager().getGroup(p);
throw new UnsupportedOperationException("Privileges does not support offline players.");
}
Group g = perms.getGroup(p);
return g != null ? g.getName() : null; return g != null ? g.getName() : null;
} }
@Override @Override
public String[] getGroups() { public String[] getGroups() {
FileConfiguration file = privs.getGroups(); Set<String> groups = new HashSet<String>();
ConfigurationSection groups = file.getConfigurationSection("groups"); for (Group g : privs.getGroupManager().getGroups()) {
return groups != null ? groups.getKeys(false).toArray(new String[0]) : null; groups.add(g.getName());
}
return groups.toArray(new String[groups.size()]);
} }
@Override @Override