mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-11-27 13:07:23 +01:00
added some offline permission support for zPerms via reflection
This commit is contained in:
parent
a03eb5f822
commit
d6fd09b1ea
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.milkbowl.vault.permission.plugins;
|
package net.milkbowl.vault.permission.plugins;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -32,11 +33,15 @@ import org.bukkit.event.server.PluginEnableEvent;
|
|||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsPlugin;
|
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsPlugin;
|
||||||
|
import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionDao;
|
||||||
|
import org.tyrannyofheaven.bukkit.zPermissions.model.Entry;
|
||||||
|
import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity;
|
||||||
|
|
||||||
public class Permission_zPermissions extends Permission {
|
public class Permission_zPermissions extends Permission {
|
||||||
|
|
||||||
private final String name = "zPermissions";
|
private final String name = "zPermissions";
|
||||||
private ZPermissionsPlugin perms;
|
private ZPermissionsPlugin perms = null;
|
||||||
|
private PermissionDao dao = null;
|
||||||
private final ConsoleCommandSender ccs;
|
private final ConsoleCommandSender ccs;
|
||||||
|
|
||||||
public Permission_zPermissions(Vault plugin) {
|
public Permission_zPermissions(Vault plugin) {
|
||||||
@ -48,6 +53,16 @@ public class Permission_zPermissions extends Permission {
|
|||||||
Plugin p = plugin.getServer().getPluginManager().getPlugin("zPermissions");
|
Plugin p = plugin.getServer().getPluginManager().getPlugin("zPermissions");
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
perms = (ZPermissionsPlugin) p;
|
perms = (ZPermissionsPlugin) p;
|
||||||
|
try {
|
||||||
|
Field f = perms.getClass().getField("dao");
|
||||||
|
f.setAccessible(true);
|
||||||
|
dao = (PermissionDao) f.get(perms);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
}
|
||||||
|
|
||||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,6 +76,15 @@ public class Permission_zPermissions extends Permission {
|
|||||||
Plugin p = event.getPlugin();
|
Plugin p = event.getPlugin();
|
||||||
if(p.getDescription().getName().equals("zPermissions") && p.isEnabled()) {
|
if(p.getDescription().getName().equals("zPermissions") && p.isEnabled()) {
|
||||||
perms = (ZPermissionsPlugin) p;
|
perms = (ZPermissionsPlugin) p;
|
||||||
|
try {
|
||||||
|
Field f = perms.getClass().getField("dao");
|
||||||
|
f.setAccessible(true);
|
||||||
|
dao = (PermissionDao) f.get(perms);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
}
|
||||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +95,7 @@ public class Permission_zPermissions extends Permission {
|
|||||||
if (perms != null) {
|
if (perms != null) {
|
||||||
if (event.getPlugin().getDescription().getName().equals("zPermissions")) {
|
if (event.getPlugin().getDescription().getName().equals("zPermissions")) {
|
||||||
perms = null;
|
perms = null;
|
||||||
perms = null;
|
dao = null;
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,23 +124,35 @@ public class Permission_zPermissions extends Permission {
|
|||||||
@Override
|
@Override
|
||||||
public boolean playerHas(String world, String player, String permission) {
|
public boolean playerHas(String world, String player, String permission) {
|
||||||
Player p = Bukkit.getServer().getPlayer(player);
|
Player p = Bukkit.getServer().getPlayer(player);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
throw new UnsupportedOperationException(getName() + " does not support offline player resolution.");
|
if (dao != null) {
|
||||||
else
|
PermissionEntity entity = dao.getEntity(player, false);
|
||||||
|
for (Entry e : entity.getPermissions()) {
|
||||||
|
if (e.getPermission().equalsIgnoreCase(permission)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
return playerHas(p, permission);
|
return playerHas(p, permission);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerAdd(String world, String player, String permission) {
|
public boolean playerAdd(String world, String player, String permission) {
|
||||||
if (world != null)
|
if (world != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return plugin.getServer().dispatchCommand(ccs, "permissions player set " + player + " " + permission);
|
return plugin.getServer().dispatchCommand(ccs, "permissions player set " + player + " " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerRemove(String world, String player, String permission) {
|
public boolean playerRemove(String world, String player, String permission) {
|
||||||
if (world != null)
|
if (world != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return plugin.getServer().dispatchCommand(ccs, "permissions player unset " + player + " " + permission);
|
return plugin.getServer().dispatchCommand(ccs, "permissions player unset " + player + " " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,47 +163,55 @@ public class Permission_zPermissions extends Permission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupAdd(String world, String group, String permission) {
|
public boolean groupAdd(String world, String group, String permission) {
|
||||||
if (world != null)
|
if (world != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return plugin.getServer().dispatchCommand(ccs, "permissions group set " + group + " " + permission);
|
return plugin.getServer().dispatchCommand(ccs, "permissions group set " + group + " " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupRemove(String world, String group, String permission) {
|
public boolean groupRemove(String world, String group, String permission) {
|
||||||
if (world != null)
|
if (world != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return plugin.getServer().dispatchCommand(ccs, "permissions group unset " + group + " " + permission);
|
return plugin.getServer().dispatchCommand(ccs, "permissions group unset " + group + " " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(String world, String player, String group) {
|
public boolean playerInGroup(String world, String player, String group) {
|
||||||
Player p = Bukkit.getServer().getPlayer(player);
|
Player p = Bukkit.getServer().getPlayer(player);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
throw new UnsupportedOperationException(getName() + " does not support offline player resolution.");
|
if (dao != null) {
|
||||||
|
return dao.getMembers(group).contains(player);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return p.hasPermission("group." + group);
|
return p.hasPermission("group." + group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerAddGroup(String world, String player, String group) {
|
public boolean playerAddGroup(String world, String player, String group) {
|
||||||
if (world != null)
|
if (world != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return plugin.getServer().dispatchCommand(ccs, "permissions group add " + player);
|
return plugin.getServer().dispatchCommand(ccs, "permissions group add " + player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerRemoveGroup(String world, String player, String group) {
|
public boolean playerRemoveGroup(String world, String player, String group) {
|
||||||
if (world != null)
|
if (world != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return plugin.getServer().dispatchCommand(ccs, "permissions group remove " + player);
|
return plugin.getServer().dispatchCommand(ccs, "permissions group remove " + player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPlayerGroups(String world, String player) {
|
public String[] getPlayerGroups(String world, String player) {
|
||||||
Player p = Bukkit.getServer().getPlayer(player);
|
Player p = Bukkit.getServer().getPlayer(player);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
throw new UnsupportedOperationException(getName() + " does not support offline player resolution.");
|
throw new UnsupportedOperationException(getName() + " does not support offline player resolution.");
|
||||||
|
}
|
||||||
List<String> groups = new ArrayList<String>();
|
List<String> groups = new ArrayList<String>();
|
||||||
for (PermissionAttachmentInfo pai : p.getEffectivePermissions()) {
|
for (PermissionAttachmentInfo pai : p.getEffectivePermissions()) {
|
||||||
if (!pai.getPermission().startsWith("group.") || !pai.getValue())
|
if (!pai.getPermission().startsWith("group.") || !pai.getValue())
|
||||||
|
Loading…
Reference in New Issue
Block a user