Merge pull request #66 from DThielke/master

Updated Starburst hooks.
This commit is contained in:
Nick Minkler 2012-01-18 09:49:34 -08:00
commit 5ad8a1c5c3
2 changed files with 228 additions and 268 deletions

BIN
lib/Starburst.jar Normal file → Executable file

Binary file not shown.

View File

@ -1,12 +1,8 @@
package net.milkbowl.vault.permission.plugins;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dthielke.starburst.*;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
@ -19,17 +15,37 @@ import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import com.dthielke.starburst.Group;
import com.dthielke.starburst.GroupSet;
import com.dthielke.starburst.StarburstPlugin;
import com.dthielke.starburst.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Permission_Starburst extends Permission {
private StarburstPlugin perms;
private String name = "Starburst";
private PermissionServerListener permissionServerListener;
private class PermissionServerListener extends ServerListener {
public void onPluginEnable(PluginEnableEvent event) {
if (perms == null) {
Plugin p = event.getPlugin();
if (p.getDescription().getName().equals("bPermissions") && p.isEnabled()) {
perms = (StarburstPlugin) p;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (perms != null) {
if (event.getPlugin().getDescription().getName().equals("bPermissions")) {
perms = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name));
}
}
}
}
public Permission_Starburst(Vault plugin) {
this.plugin = plugin;
@ -47,264 +63,6 @@ public class Permission_Starburst extends Permission {
}
}
}
private class PermissionServerListener extends ServerListener {
public void onPluginEnable(PluginEnableEvent event) {
if (perms == null) {
Plugin p = event.getPlugin();
if(p.getDescription().getName().equals("bPermissions") && p.isEnabled()) {
perms = (StarburstPlugin) p;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (perms != null) {
if (event.getPlugin().getDescription().getName().equals("bPermissions")) {
perms = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name));
}
}
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean isEnabled() {
return perms != null && perms.isEnabled();
}
@Override
public boolean hasSuperPermsCompat() {
return true;
}
@Override
public boolean playerHas(String world, String player, String permission) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return false;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
Group g = set.getUser(op);
if (g == null) {
return false;
}
Map<String, Boolean> effective = g.aggregatePermissions();
return effective.containsKey(permission.toLowerCase()) ? effective.get(permission.toLowerCase()) : false;
}
@Override
public boolean playerAdd(String world, String player, String permission) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return false;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
Group g = set.getUser(op);
if (g == null) {
return false;
}
g.addPermission(permission, true, true, op.isOnline());
return true;
}
@Override
public boolean playerRemove(String world, String player, String permission) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return false;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
Group g = set.getUser(op);
if (g == null) {
return false;
}
g.removePermission(permission, op.isOnline());
return true;
}
@Override
public boolean groupHas(String world, String group, String permission) {
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
Group g = set.getGroup(group);
if (g == null) {
return false;
}
Map<String, Boolean> effective = g.aggregatePermissions();
return effective.containsKey(permission.toLowerCase()) ? effective.get(permission.toLowerCase()) : false;
}
@Override
public boolean groupAdd(String world, String group, String permission) {
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
Group g = set.getGroup(group);
if (g == null) {
return false;
}
g.addPermission(permission, true, true, true);
return true;
}
@Override
public boolean groupRemove(String world, String group, String permission) {
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
Group g = set.getGroup(group);
if (g == null) {
return false;
}
g.removePermission(permission, true);
return true;
}
@Override
public boolean playerInGroup(String world, String player, String group) {
Player p = Bukkit.getServer().getPlayer(player);
if (p != null) {
return p.hasPermission("group." + group);
}
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return false;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
User u = set.getUser(op);
Group g = set.getGroup(group);
if (u == null || g == null) {
return false;
}
return u.getChildren().contains(g);
}
@Override
public boolean playerAddGroup(String world, String player, String group) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return false;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
User u = set.getUser(op);
Group g = set.getGroup(group);
if (u == null || g == null) {
return false;
}
u.addChild(g, op.isOnline());
return true;
}
@Override
public boolean playerRemoveGroup(String world, String player, String group) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return false;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
User u = set.getUser(op);
Group g = set.getGroup(group);
if (u == null || g == null) {
return false;
}
u.removeChild(g, op.isOnline());
return true;
}
@Override
public String[] getPlayerGroups(String world, String player) {
Player p = Bukkit.getServer().getPlayer(player);
if (p == null)
throw new UnsupportedOperationException(getName() + " does not support offline player resolution.");
List<String> groups = new ArrayList<String>();
for (PermissionAttachmentInfo pai : p.getEffectivePermissions()) {
if (!pai.getPermission().startsWith("group.") || !pai.getValue())
continue;
groups.add(pai.getPermission().substring(6));
}
return groups.toArray(new String[0]);
}
@Override
public String getPrimaryGroup(String world, String player) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if (op == null) {
return null;
}
GroupSet set;
World w = Bukkit.getWorld(world);
if (w != null) {
set = perms.getGroupManager().getDefaultGroupSet();
} else {
set = perms.getGroupManager().getWorldSet(w);
}
User u = set.getUser(op);
if (u == null) {
return null;
}
if (u.getChildren().isEmpty()) {
return null;
}
return u.getChildren().toArray(new Group[] {})[0].getName();
}
@Override
public String[] getGroups() {
@ -316,4 +74,206 @@ public class Permission_Starburst extends Permission {
}
return s;
}
@Override
public String getName() {
return name;
}
@Override
public String[] getPlayerGroups(String world, String player) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
Set<Group> children = user.getChildren(true);
List<String> groups = new ArrayList<String>();
for (Group child : children) {
groups.add(child.getName());
}
return groups.toArray(new String[groups.size()]);
}
@Override
public String getPrimaryGroup(String world, String player) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
Set<Group> children = user.getChildren(false);
if (!children.isEmpty()) {
return children.iterator().next().getName();
} else {
return null;
}
}
@Override
public boolean groupAdd(String world, String group, String permission) {
GroupManager gm = perms.getGroupManager();
GroupSet set = gm.getWorldSet(Bukkit.getWorld(world));
if (set.hasGroup(group)) {
Group g = set.getGroup(group);
boolean value = !permission.startsWith("^");
permission = value ? permission : permission.substring(1);
g.addPermission(permission, value, true, true);
for (User user : gm.getAffectedUsers(g)) {
user.applyPermissions(gm.getFactory());
}
return true;
} else {
return false;
}
}
@Override
public boolean groupHas(String world, String group, String permission) {
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
if (set.hasGroup(group)) {
Group g = set.getGroup(group);
return g.hasPermission(permission, true);
} else {
return false;
}
}
@Override
public boolean groupRemove(String world, String group, String permission) {
GroupManager gm = perms.getGroupManager();
GroupSet set = gm.getWorldSet(Bukkit.getWorld(world));
if (set.hasGroup(group)) {
Group g = set.getGroup(group);
boolean value = !permission.startsWith("^");
permission = value ? permission : permission.substring(1);
if (g.hasPermission(permission, false)) {
g.removePermission(permission, true);
for (User user : gm.getAffectedUsers(g)) {
user.applyPermissions(gm.getFactory());
}
return true;
} else {
return false;
}
} else {
return false;
}
}
@Override
public boolean hasSuperPermsCompat() {
return true;
}
@Override
public boolean isEnabled() {
return perms != null && perms.isEnabled();
}
@Override
public boolean playerAdd(String world, String player, String permission) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
boolean value = !permission.startsWith("^");
permission = value ? permission : permission.substring(1);
user.addPermission(permission, value, true, true);
if (user.isActive()) {
user.applyPermissions(perms.getGroupManager().getFactory());
}
return true;
}
@Override
public boolean playerAddGroup(String world, String player, String group) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
if (set.hasGroup(group)) {
Group g = set.getGroup(group);
if (!user.hasChild(g, false)) {
user.addChild(g, true);
if (user.isActive()) {
user.applyPermissions(perms.getGroupManager().getFactory());
}
return true;
} else {
return false;
}
} else {
return false;
}
}
@Override
public boolean playerHas(String world, String player, String permission) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
Group user = set.getUser(op);
return user.hasPermission(permission, true);
}
@Override
public boolean playerInGroup(String world, String player, String group) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
if (set.hasGroup(group)) {
Group g = set.getGroup(group);
return user.hasChild(g, true);
} else {
return false;
}
}
@Override
public boolean playerRemove(String world, String player, String permission) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
boolean value = !permission.startsWith("^");
permission = value ? permission : permission.substring(1);
if (user.hasPermission(permission, false)) {
user.removePermission(permission, true);
if (user.isActive()) {
user.applyPermissions(perms.getGroupManager().getFactory());
}
return true;
} else {
return false;
}
}
@Override
public boolean playerRemoveGroup(String world, String player, String group) {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world));
User user = set.getUser(op);
if (set.hasGroup(group)) {
Group g = set.getGroup(group);
if (user.hasChild(g, false)) {
user.removeChild(g, true);
if (user.isActive()) {
user.applyPermissions(perms.getGroupManager().getFactory());
}
return true;
} else {
return false;
}
} else {
return false;
}
}
}