mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-11-24 03:25:11 +01:00
Merge branch 'master' of https://Sleaker@github.com/MilkBowl/Vault.git
This commit is contained in:
commit
7786d37785
Binary file not shown.
@ -363,10 +363,10 @@ public class Vault extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Try to load zPermission
|
//Try to load zPermission
|
||||||
if (packageExists("org.tyrannyofheaven.bukkit.zPermissions")) {
|
if (packageExists("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsPlugin")) {
|
||||||
Permission zPerms = new Permission_zPermissions(this);
|
Permission zPerms = new Permission_zPermissions(this);
|
||||||
sm.register(Permission.class, zPerms, this, ServicePriority.Highest);
|
sm.register(Permission.class, zPerms, this, ServicePriority.Highest);
|
||||||
log.info(String.format("[%s][Permission] GroupManager found: %s", getDescription().getName(), zPerms.isEnabled() ? "Loaded" : "Waiting"));
|
log.info(String.format("[%s][Permission] zPermissions found: %s", getDescription().getName(), zPerms.isEnabled() ? "Loaded" : "Waiting"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Try to load bPermissions
|
//Try to load bPermissions
|
||||||
|
@ -15,14 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package net.milkbowl.vault.permission.plugins;
|
package net.milkbowl.vault.permission.plugins;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
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;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -30,72 +31,42 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
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 = null;
|
private ZPermissionsService service;
|
||||||
private PermissionDao dao = null;
|
|
||||||
private final ConsoleCommandSender ccs;
|
private final ConsoleCommandSender ccs;
|
||||||
|
|
||||||
public Permission_zPermissions(Vault plugin) {
|
public Permission_zPermissions(Vault plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
ccs = Bukkit.getServer().getConsoleSender();
|
ccs = Bukkit.getServer().getConsoleSender();
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin);
|
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin);
|
||||||
// Load Plugin in case it was loaded before
|
// Load service in case it was loaded before
|
||||||
if (perms == null) {
|
if (service == null) {
|
||||||
Plugin p = plugin.getServer().getPluginManager().getPlugin("zPermissions");
|
service = plugin.getServer().getServicesManager().load(ZPermissionsService.class);
|
||||||
if (p != null) {
|
if (service != null)
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class PermissionServerListener implements Listener {
|
public class PermissionServerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
if (perms == null) {
|
if (service == null) {
|
||||||
Plugin p = event.getPlugin();
|
service = plugin.getServer().getServicesManager().load(ZPermissionsService.class);
|
||||||
if(p.getDescription().getName().equals("zPermissions") && p.isEnabled()) {
|
if (service != null)
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPluginDisable(PluginDisableEvent event) {
|
public void onPluginDisable(PluginDisableEvent event) {
|
||||||
if (perms != null) {
|
if (service != null) {
|
||||||
if (event.getPlugin().getDescription().getName().equals("zPermissions")) {
|
if (event.getPlugin().getDescription().getName().equals("zPermissions")) {
|
||||||
perms = null;
|
service = 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,11 +80,7 @@ public class Permission_zPermissions extends Permission {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
if (perms == null) {
|
return service != null;
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return perms.isEnabled();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -125,15 +92,17 @@ public class Permission_zPermissions extends Permission {
|
|||||||
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) {
|
||||||
if (dao != null) {
|
Map<String, Boolean> perms = service.getPlayerPermissions(world, null, player);
|
||||||
PermissionEntity entity = dao.getEntity(player, false);
|
Boolean value = perms.get(permission.toLowerCase());
|
||||||
for (Entry e : entity.getPermissions()) {
|
if (value != null)
|
||||||
if (e.getPermission().equalsIgnoreCase(permission)) {
|
return value;
|
||||||
return true;
|
// Use default at this point
|
||||||
}
|
org.bukkit.permissions.Permission perm = Bukkit.getPluginManager().getPermission(permission);
|
||||||
}
|
if (perm != null) {
|
||||||
return false;
|
OfflinePlayer op = Bukkit.getServer().getOfflinePlayer(player);
|
||||||
|
return perm.getDefault().getValue(op != null ? op.isOp() : false);
|
||||||
}
|
}
|
||||||
|
// Have no clue
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return playerHas(p, permission);
|
return playerHas(p, permission);
|
||||||
@ -145,7 +114,7 @@ public class Permission_zPermissions extends 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 " + player + " set " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,11 +122,20 @@ public class Permission_zPermissions extends 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 " + player + " unset " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupHas(String world, String group, String permission) {
|
public boolean groupHas(String world, String group, String permission) {
|
||||||
|
Map<String, Boolean> perms = service.getGroupPermissions(world, null, group);
|
||||||
|
Boolean value = perms.get(permission.toLowerCase());
|
||||||
|
if (value != null)
|
||||||
|
return value;
|
||||||
|
// Use default, if possible
|
||||||
|
org.bukkit.permissions.Permission perm = Bukkit.getPluginManager().getPermission(permission);
|
||||||
|
if (perm != null)
|
||||||
|
return perm.getDefault().getValue(false); // OP flag assumed to be false...
|
||||||
|
// Who knows...
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +144,7 @@ public class Permission_zPermissions extends 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 " + group + " set " + permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -174,28 +152,27 @@ public class Permission_zPermissions extends 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 " + group + " unset " + 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);
|
Set<String> groups = service.getPlayerGroups(player);
|
||||||
if (p == null) {
|
// Groups are case-insensitive...
|
||||||
if (dao != null) {
|
for (String g : groups) {
|
||||||
return dao.getMembers(group).contains(player);
|
if (g.equalsIgnoreCase(group)) {
|
||||||
} else {
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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 " + group + " add " + player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -203,31 +180,26 @@ public class Permission_zPermissions extends Permission {
|
|||||||
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 " + 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);
|
return service.getPlayerGroups(player).toArray(new String[0]);
|
||||||
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
|
@Override
|
||||||
public String getPrimaryGroup(String world, String player) {
|
public String getPrimaryGroup(String world, String player) {
|
||||||
throw new UnsupportedOperationException(getName() + " does not support primary group resolution.");
|
// Has no concept of primary group... use highest-priority assigned group instead
|
||||||
|
List<String> groups = service.getPlayerAssignedGroups(player);
|
||||||
|
if (!groups.isEmpty())
|
||||||
|
return groups.get(0);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups() {
|
public String[] getGroups() {
|
||||||
throw new UnsupportedOperationException(getName() + " does not support group resolution.");
|
return service.getAllGroups().toArray(new String[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user