This commit is contained in:
Sleaker 2012-01-29 16:11:23 -08:00
commit 6cebf40386

View File

@ -1,5 +1,8 @@
package net.milkbowl.vault.permission.plugins; package net.milkbowl.vault.permission.plugins;
import java.util.HashSet;
import java.util.Set;
import net.milkbowl.vault.Vault; import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
@ -11,15 +14,16 @@ 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 de.bananaco.bpermissions.api.Group; import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.User;
import de.bananaco.bpermissions.api.World; import de.bananaco.bpermissions.api.World;
import de.bananaco.bpermissions.api.WorldManager; import de.bananaco.bpermissions.api.WorldManager;
import de.bananaco.bpermissions.api.util.Calculable;
import de.bananaco.bpermissions.api.util.CalculableType;
public class Permission_bPermissions2 extends Permission { public class Permission_bPermissions2 extends Permission {
private String name = "bPermissions2"; private String name = "bPermissions2";
private WorldManager perms; private boolean hooked = false;
public Permission_bPermissions2(Vault plugin) { public Permission_bPermissions2(Vault plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -27,10 +31,10 @@ public class Permission_bPermissions2 extends Permission {
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin);
// Load Plugin in case it was loaded before // Load Plugin in case it was loaded before
if (perms == null) { if (!hooked) {
Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions");
if (p != null) { if (p != null) {
perms = WorldManager.getInstance(); hooked = true;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
} }
} }
@ -40,10 +44,10 @@ public class Permission_bPermissions2 extends Permission {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
if (perms == null) { if (!hooked) {
Plugin p = event.getPlugin(); Plugin p = event.getPlugin();
if(p.getDescription().getName().equals("bPermissions") && p.isEnabled()) { if(p.getDescription().getName().equals("bPermissions") && p.isEnabled()) {
perms = WorldManager.getInstance(); hooked = true;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
} }
} }
@ -51,9 +55,9 @@ public class Permission_bPermissions2 extends Permission {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
if (perms != null) { if (hooked) {
if (event.getPlugin().getDescription().getName().equals("bPermissions")) { if (event.getPlugin().getDescription().getName().equals("bPermissions")) {
perms = null; hooked = false;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name));
} }
} }
@ -67,44 +71,23 @@ public class Permission_bPermissions2 extends Permission {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
return this.perms != null; return hooked;
} }
@Override @Override
public boolean playerHas(String world, String player, String permission) { public boolean playerHas(String world, String player, String permission) {
World w = perms.getWorld(world); return ApiLayer.hasPermission(world, CalculableType.USER, player, permission);
if (w == null) {
return false;
}
User user = w.getUser(player);
return user == null ? false : user.hasPermission(permission);
} }
@Override @Override
public boolean playerAdd(String world, String player, String permission) { public boolean playerAdd(String world, String player, String permission) {
World w = perms.getWorld(world); ApiLayer.addPermission(world, CalculableType.USER, player, de.bananaco.bpermissions.api.util.Permission.loadFromString(permission));
if (w == null) { return true;
return false;
}
User user = w.getUser(player);
if (user == null) {
return false;
}
user.addPermission(permission, true);
return true;
} }
@Override @Override
public boolean playerRemove(String world, String player, String permission) { public boolean playerRemove(String world, String player, String permission) {
World w = perms.getWorld(world); ApiLayer.removePermission(world, CalculableType.USER, player, permission);
if (w == null) {
return false;
}
User user = w.getUser(player);
if (user == null) {
return false;
}
user.removePermission(permission);
return true; return true;
} }
@ -112,91 +95,41 @@ public class Permission_bPermissions2 extends Permission {
@Override @Override
public boolean groupHas(String world, String group, String permission) { public boolean groupHas(String world, String group, String permission) {
World w = perms.getWorld(world); return ApiLayer.hasPermission(world, CalculableType.GROUP, group, permission);
if (w == null) {
return false;
}
Group g = w.getGroup(group);
return g != null ? g.getPermissionsAsString().contains(permission) : false;
} }
@Override @Override
public boolean groupAdd(String world, String group, String permission) { public boolean groupAdd(String world, String group, String permission) {
World w = perms.getWorld(world); ApiLayer.addPermission(world, CalculableType.GROUP, group, de.bananaco.bpermissions.api.util.Permission.loadFromString(permission));
if (w == null) { return true;
return false;
}
Group g = w.getGroup(group);
if (g == null) {
return false;
}
g.addPermission(permission, true);
return true;
} }
@Override @Override
public boolean groupRemove(String world, String group, String permission) { public boolean groupRemove(String world, String group, String permission) {
World w = perms.getWorld(world); ApiLayer.removePermission(world, CalculableType.GROUP, group, permission);
if (w == null) {
return false;
}
Group g = w.getGroup(group);
if (g == null) {
return false;
}
g.removePermission(permission);
return true; return true;
} }
@Override @Override
public boolean playerInGroup(String world, String player, String group) { public boolean playerInGroup(String world, String player, String group) {
World w = perms.getWorld(world); return ApiLayer.hasGroup(world, CalculableType.USER, player, group);
if (w == null) {
return false;
}
User user = w.getUser(player);
return user != null ? user.getGroupsAsString().contains(group) : false;
} }
@Override @Override
public boolean playerAddGroup(String world, String player, String group) { public boolean playerAddGroup(String world, String player, String group) {
World w = perms.getWorld(world); ApiLayer.addGroup(world, CalculableType.USER, player, group);
if (w == null) {
return false;
}
User user = w.getUser(player);
if (user == null) {
return false;
}
user.addGroup(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) {
World w = perms.getWorld(world); ApiLayer.removeGroup(world, CalculableType.USER, player, group);
if (w == null) {
return false;
}
User user = w.getUser(player);
if (user == null) {
return false;
}
user.removeGroup(group);
return true; return true;
} }
@Override @Override
public String[] getPlayerGroups(String world, String player) { public String[] getPlayerGroups(String world, String player) {
World w = perms.getWorld(world); return ApiLayer.getGroups(world, CalculableType.USER, name);
if (w == null) {
return null;
}
User user = w.getUser(player);
return user != null ? user.getGroupsAsString().toArray(new String[0]) : null;
} }
@Override @Override
@ -207,7 +140,17 @@ public class Permission_bPermissions2 extends Permission {
@Override @Override
public String[] getGroups() { public String[] getGroups() {
throw new UnsupportedOperationException("bPermissions does not support server-wide groups"); String[] groups = null;
Set<String> gSet = new HashSet<String>();
for(World world : WorldManager.getInstance().getAllWorlds()) {
Set<Calculable> gr = world.getAll(CalculableType.GROUP);
for(Calculable c : gr) {
gSet.add(c.getNameLowerCase());
}
}
// Convert to String
groups = gSet.toArray(new String[gSet.size()]);
return groups;
} }
@Override @Override