mirror of
https://github.com/MilkBowl/Vault.git
synced 2025-02-06 23:41:29 +01:00
added bPerms support - minor housekeeping on some other methods
This commit is contained in:
parent
bb16efbd63
commit
b9cfea3d33
@ -43,6 +43,7 @@ import net.milkbowl.vault.permission.plugins.Permission_Permissions3;
|
||||
import net.milkbowl.vault.permission.plugins.Permission_PermissionsBukkit;
|
||||
import net.milkbowl.vault.permission.plugins.Permission_PermissionsEx;
|
||||
import net.milkbowl.vault.permission.plugins.Permission_SuperPerms;
|
||||
import net.milkbowl.vault.permission.plugins.Permission_bPermissions;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -223,6 +224,13 @@ public class Vault extends JavaPlugin {
|
||||
} else {
|
||||
log.info(String.format("[%s][Permission] PermissionsBukkit not found.", getDescription().getName()));
|
||||
}
|
||||
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"} )) {
|
||||
Permission bPerms = new Permission_bPermissions(this);
|
||||
getServer().getServicesManager().register(net.milkbowl.vault.permission.Permission.class, bPerms, this, ServicePriority.Highest);
|
||||
log.info(String.format("[%s][Permission] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
|
||||
} else {
|
||||
log.info(String.format("[%s][Permission] bPermissions not found.", getDescription().getName()));
|
||||
}
|
||||
// Try to load GroupManager
|
||||
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
|
||||
Permission gPerms = new Permission_GroupManager(this);
|
||||
|
@ -23,6 +23,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.milkbowl.vault.Vault;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -45,12 +46,12 @@ public class Permission_Permissions3 extends Permission {
|
||||
|
||||
private String name = "Permissions 3 (Yeti)";
|
||||
private PermissionHandler perms;
|
||||
private Plugin plugin = null;
|
||||
private Vault plugin = null;
|
||||
private PluginManager pluginManager = null;
|
||||
private Permissions permission = null;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Permission_Permissions3(Plugin plugin) {
|
||||
public Permission_Permissions3(Vault plugin) {
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
|
@ -21,6 +21,7 @@ package net.milkbowl.vault.permission.plugins;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.milkbowl.vault.Vault;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@ -40,12 +41,12 @@ public class Permission_PermissionsEx extends Permission {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private final String name = "PermissionsEx";
|
||||
private Plugin plugin = null;
|
||||
private Vault plugin = null;
|
||||
private PluginManager pluginManager = null;
|
||||
private PermissionsEx permission = null;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Permission_PermissionsEx(Plugin plugin) {
|
||||
public Permission_PermissionsEx(Vault plugin) {
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
@ -82,7 +83,7 @@ public class Permission_PermissionsEx extends Permission {
|
||||
|
||||
@Override
|
||||
public boolean playerHas(Player player, String permission) {
|
||||
return PermissionsEx.has(player, permission);
|
||||
return this.permission.has(player, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,13 +39,9 @@ public class Permission_SuperPerms extends Permission {
|
||||
|
||||
@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!");
|
||||
}
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
|
||||
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
|
||||
@ -67,13 +63,10 @@ public class Permission_SuperPerms extends Permission {
|
||||
|
||||
@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!");
|
||||
}
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
|
||||
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
|
||||
return paInfo.getAttachment().getPermissions().remove(permission);
|
||||
@ -124,6 +117,6 @@ public class Permission_SuperPerms extends Permission {
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
throw new UnsupportedOperationException(getName() + " does not support group listing!");
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,260 @@
|
||||
package net.milkbowl.vault.permission.plugins;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
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 de.bananaco.permissions.Permissions;
|
||||
import de.bananaco.permissions.interfaces.PermissionSet;
|
||||
import de.bananaco.permissions.worlds.WorldPermissionsManager;
|
||||
|
||||
import net.milkbowl.vault.Vault;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class Permission_bPermissions extends Permission {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private String name = "bPermissions";
|
||||
private Vault plugin = null;
|
||||
private PluginManager pluginManager = null;
|
||||
private WorldPermissionsManager perms;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Permission_bPermissions(Vault plugin) {
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
permissionServerListener = new PermissionServerListener();
|
||||
|
||||
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 p = plugin.getServer().getPluginManager().getPlugin("bPermissions");
|
||||
if (p != null) {
|
||||
perms = Permissions.getWorldPermissionsManager();
|
||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class PermissionServerListener extends ServerListener {
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (perms == null) {
|
||||
Plugin p = event.getPlugin();
|
||||
if(p.getDescription().getName().equals("bPermissions")) {
|
||||
if (p.isEnabled()) {
|
||||
perms = Permissions.getWorldPermissionsManager();
|
||||
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 this.perms != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String world, String player, String permission) {
|
||||
Player p = plugin.getServer().getPlayer(player);
|
||||
if (p == null)
|
||||
throw new UnsupportedOperationException("Offline Permissions are not supported!");
|
||||
return p.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAdd(String world, String player, String permission) {
|
||||
throw new UnsupportedOperationException("Player specific permissions are not supported!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddTransient(String world, String player, String permission) {
|
||||
Player p = plugin.getServer().getPlayer(player);
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
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) {
|
||||
throw new UnsupportedOperationException("Player specific permissions are not supported!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveTransient(String world, String player, String permission) {
|
||||
Player p = plugin.getServer().getPlayer(player);
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
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)
|
||||
return false;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return false;
|
||||
|
||||
if (set.getGroupNodes(group) == null)
|
||||
return false;
|
||||
|
||||
return set.getGroupNodes(group).contains(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAdd(String world, String group, String permission) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return false;
|
||||
|
||||
if (set.getGroupNodes(group) == null)
|
||||
return false;
|
||||
|
||||
set.addNode(permission, group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemove(String world, String group, String permission) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return false;
|
||||
|
||||
if (set.getGroupNodes(group) == null)
|
||||
return false;
|
||||
|
||||
set.removeNode(permission, group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, String player, String group) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return false;
|
||||
|
||||
if (set.getGroups(player) == null)
|
||||
return false;
|
||||
|
||||
return set.getGroups(player).contains(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, String player, String group) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return false;
|
||||
|
||||
if (set.getGroupNodes(group) == null)
|
||||
return false;
|
||||
|
||||
set.addGroup(player, group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, String player, String group) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return false;
|
||||
|
||||
set.removeGroup(player, group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, String player) {
|
||||
if (world == null)
|
||||
return null;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return null;
|
||||
|
||||
List<String> groups = set.getGroups(player);
|
||||
return groups == null ? null : groups.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, String player) {
|
||||
if (world == null)
|
||||
return null;
|
||||
|
||||
PermissionSet set = perms.getPermissionSet(world);
|
||||
if (set == null)
|
||||
return null;
|
||||
|
||||
List<String> groups = set.getGroups(player);
|
||||
if (groups == null || groups.isEmpty())
|
||||
return null;
|
||||
else
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
throw new UnsupportedOperationException("bPermissions does not support server-wide groups");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user