partially added BukkitPerms - add transient support to P2/GM using

bukkit perm backend.
This commit is contained in:
Sleaker 2011-08-17 21:26:44 -07:00
parent 4f63ad2113
commit e47de32687
4 changed files with 470 additions and 2 deletions

View File

@ -185,7 +185,37 @@ public abstract class Permission {
public boolean playerRemove(Player player, String permission) {
return playerRemove(player.getWorld().getName(), player.getName(), permission);
}
/**
* Remove transient permission to a player.
* @param world World name
* @param player Player name
* @param permission Permission node
* @return Success or Failure
*/
abstract public boolean playerRemoveTransient(String world, String player, String permission);
/**
* Remove transient permission from a player.
* @param world World name
* @param player Player name
* @param permission Permission node
* @return Success or Failure
*/
public boolean playerRemoveTransient(World world, String player, String permission) {
return playerRemoveTransient(world.getName(), player, permission);
}
/**
* Remove transient permission from a player.
* @param player Player Object
* @param permission Permission node
* @return Success or Failure
*/
public boolean playerRemoveTransient(Player player, String permission) {
return playerRemove(player.getWorld().getName(), player.getName(), permission);
}
/**
* Checks if group has a permission node.
* @param world World name

View File

@ -6,11 +6,14 @@ import net.milkbowl.vault.permission.Permission;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -221,6 +224,7 @@ public class Permission_GroupManager extends Permission {
@Override
public void setGroupInfoString(String world, String groupName, String node, String value) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
}
@Override
@ -275,6 +279,41 @@ public class Permission_GroupManager extends Permission {
@Override
public boolean playerAddTransient(String world, String player, String permission) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
}
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
}
@Override
public boolean playerRemoveTransient(String world, String player, String permission) {
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
}
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission);
}
}
return false;
}
}

View File

@ -8,6 +8,8 @@ import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -283,7 +285,42 @@ public class Permission_Permissions2 extends Permission {
@Override
public boolean playerAddTransient(String world, String player, String permission) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
}
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
}
@Override
public boolean playerRemoveTransient(String world, String player, String permission) {
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
}
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission);
}
}
return false;
}
}

View File

@ -0,0 +1,362 @@
package net.milkbowl.vault.permission.plugins;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.platymuus.bukkit.permissions.Group;
import com.platymuus.bukkit.permissions.PermissionsPlugin;
import net.milkbowl.vault.permission.Permission;
public class Permission_PermissionsBukkit extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "PermissionsBukkit";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private PermissionsPlugin perms = null;
private PermissionServerListener permissionServerListener = null;
private ConsoleCommandSender ccs;
public Permission_PermissionsBukkit(Plugin plugin) {
this.plugin = plugin;
ccs = new ConsoleCommandSender(plugin.getServer());
pluginManager = this.plugin.getServer().getPluginManager();
permissionServerListener = new PermissionServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
if (perms != null) {
perms = (PermissionsPlugin) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
private class PermissionServerListener extends ServerListener {
Permission_PermissionsBukkit permission = null;
public PermissionServerListener(Permission_PermissionsBukkit permission) {
this.permission = permission;
}
public void onPluginEnable(PluginEnableEvent event) {
if (permission.perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
if (perms != null) {
if (perms.isEnabled()) {
permission.perms = (PermissionsPlugin) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (permission.perms != null) {
if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) {
permission.perms = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean isEnabled() {
if (perms == null) {
return false;
} else {
return perms.isEnabled();
}
}
@Override
public boolean playerHas(String world, String player, String permission) {
if (world != null && !world.isEmpty()) {
return perms.getPlayerInfo(player).getWorldPermissions(world).get(permission) == null ? false : perms.getPlayerInfo(player).getWorldPermissions(world).get(permission);
}
return perms.getPlayerInfo(player).getPermissions().get(permission);
}
@Override
public boolean playerAdd(String world, String player, String permission) {
if (world == null) {
plugin.getServer().dispatchCommand(arg0, arg1)
}
}
@Override
public boolean playerAddTransient(String world, String player, String permission) {
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
}
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
}
@Override
public boolean playerRemove(String world, String player, String permission) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean playerRemoveTransient(String world, String player, String permission) {
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
}
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission);
}
}
return false;
}
@Override
public boolean groupHas(String world, String group, String permission) {
if (world != null && !world.isEmpty()) {
return perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) == null ? false : perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission);
}
return perms.getGroup(group).getInfo().getPermissions().get(permission);
}
@Override
public boolean groupAdd(String world, String group, String permission) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean groupRemove(String world, String group, String permission) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean playerInGroup(String world, String player, String group) {
if (world != null) {
for (Group g : perms.getPlayerInfo(player).getGroups()) {
if (g.getName().equals(group)) {
return g.getInfo().getWorlds().contains(world);
}
}
return false;
}
return perms.getGroup(group).getPlayers().contains(player);
}
@Override
public boolean playerAddGroup(String world, String player, String group) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean playerRemoveGroup(String world, String player, String group) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setPlayerInfoInteger(String world, String player, String node, int value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public int getGroupInfoInteger(String world, String group, String node, int defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setGroupInfoInteger(String world, String group, String node,int value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setPlayerInfoDouble(String world, String player, String node, double value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public double getGroupInfoDouble(String world, String group, String node, double defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setGroupInfoDouble(String world, String group, String node, double value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setPlayerInfoBoolean(String world, String player, String node, boolean value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) {
return this.groupHas(world, group, node);
}
@Override
public void setGroupInfoBoolean(String world, String group, String node, boolean value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setPlayerInfoString(String world, String player, String node, String value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public String getGroupInfoString(String world, String group, String node, String defaultValue) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public void setGroupInfoString(String world, String group, String node, String value) {
throw new UnsupportedOperationException(getName() + " does not support info nodes.");
}
@Override
public String[] getPlayerGroups(String world, String player) {
List<String> groupList = new ArrayList<String>();
if (world != null) {
for (Group group : perms.getPlayerInfo(player).getGroups()) {
if (group.getInfo().getWorlds().contains(world)) {
groupList.add(group.getName());
}
}
return groupList.toArray(new String[0]);
}
for (Group group : perms.getPlayerInfo(player).getGroups()) {
groupList.add(group.getName());
}
return groupList.toArray(new String[0]);
}
@Override
public String getPrimaryGroup(String world, String player) {
if (world != null) {
}
if (perms.getPlayerInfo(player).getGroups() != null ) {
return perms.getPlayerInfo(player).getGroups().get(0).getName();
}
return null;
}
@Override
public String getPlayerPrefix(String world, String player) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setPlayerPrefix(String world, String player, String prefix) {
// TODO Auto-generated method stub
}
@Override
public String getPlayerSuffix(String world, String player) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setPlayerSuffix(String world, String player, String suffix) {
// TODO Auto-generated method stub
}
@Override
public String getGroupPrefix(String world, String group) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setGroupPrefix(String world, String group, String prefix) {
// TODO Auto-generated method stub
}
@Override
public String getGroupSuffix(String world, String group) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setGroupSuffix(String world, String group, String suffix) {
// TODO Auto-generated method stub
}
}