mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-26 19:18:29 +01:00
Make permissions-plugin specific implementations extend Vault, fix build permission checks
This commit is contained in:
parent
904a9700b2
commit
b19dbb1b8f
@ -1,24 +1,18 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VaultHandler extends SuperpermsHandler {
|
public abstract class AbstractVaultHandler extends SuperpermsHandler {
|
||||||
|
|
||||||
private Essentials plugin;
|
|
||||||
private static Permission perms = null;
|
private static Permission perms = null;
|
||||||
private static Chat chat = null;
|
private static Chat chat = null;
|
||||||
|
|
||||||
public VaultHandler(Essentials plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setupProviders() {
|
public boolean setupProviders() {
|
||||||
try {
|
try {
|
||||||
Class.forName("net.milkbowl.vault.permission.Permission");
|
Class.forName("net.milkbowl.vault.permission.Permission");
|
||||||
@ -27,9 +21,9 @@ public class VaultHandler extends SuperpermsHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredServiceProvider<Permission> permsProvider = plugin.getServer().getServicesManager().getRegistration(Permission.class);
|
RegisteredServiceProvider<Permission> permsProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
perms = permsProvider.getProvider();
|
perms = permsProvider.getProvider();
|
||||||
RegisteredServiceProvider<Chat> chatProvider = plugin.getServer().getServicesManager().getRegistration(Chat.class);
|
RegisteredServiceProvider<Chat> chatProvider = Bukkit.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
chat = chatProvider.getProvider();
|
chat = chatProvider.getProvider();
|
||||||
return perms != null && chat != null;
|
return perms != null && chat != null;
|
||||||
}
|
}
|
@ -1,51 +1,11 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
import de.bananaco.bpermissions.api.ApiLayer;
|
|
||||||
import de.bananaco.bpermissions.api.util.CalculableType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class BPermissions2Handler extends SuperpermsHandler {
|
|
||||||
public BPermissions2Handler() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(final Player base) {
|
|
||||||
final List<String> groups = getGroups(base);
|
|
||||||
if (groups == null || groups.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return groups.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(final Player base) {
|
|
||||||
final String[] groups = ApiLayer.getGroups(base.getWorld().getName(), CalculableType.USER, base.getName());
|
|
||||||
return Arrays.asList(groups);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(final Player base, final String group) {
|
|
||||||
return ApiLayer.hasGroupRecursive(base.getWorld().getName(), CalculableType.USER, base.getName(), group);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class BPermissions2Handler extends AbstractVaultHandler {
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(final Player base, final String group) {
|
public boolean canBuild(final Player base, final String group) {
|
||||||
return hasPermission(base, "bPermissions.build");
|
return hasPermission(base, "bPermissions.build");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrefix(final Player base) {
|
|
||||||
return ApiLayer.getValue(base.getWorld().getName(), CalculableType.USER, base.getName(), "prefix");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuffix(final Player base) {
|
|
||||||
return ApiLayer.getValue(base.getWorld().getName(), CalculableType.USER, base.getName(), "suffix");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
public class GenericVaultHandler extends AbstractVaultHandler {
|
||||||
|
}
|
@ -6,78 +6,18 @@ import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
public class GroupManagerHandler extends AbstractVaultHandler {
|
||||||
public class GroupManagerHandler implements IPermissionsHandler {
|
|
||||||
private final transient GroupManager groupManager;
|
private final transient GroupManager groupManager;
|
||||||
|
|
||||||
public GroupManagerHandler(final Plugin permissionsPlugin) {
|
public GroupManagerHandler(final Plugin permissionsPlugin) {
|
||||||
groupManager = ((GroupManager) permissionsPlugin);
|
groupManager = ((GroupManager) permissionsPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(final Player base) {
|
|
||||||
final AnjoPermissionsHandler handler = getHandler(base);
|
|
||||||
if (handler == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return handler.getGroup(base.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(final Player base) {
|
|
||||||
final AnjoPermissionsHandler handler = getHandler(base);
|
|
||||||
if (handler == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Arrays.asList(handler.getGroups(base.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(final Player base, final String group) {
|
public boolean canBuild(final Player base, final String group) {
|
||||||
final AnjoPermissionsHandler handler = getHandler(base);
|
final AnjoPermissionsHandler handler = getHandler(base);
|
||||||
if (handler == null) {
|
return handler != null && handler.canUserBuild(base.getName());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return handler.canUserBuild(base.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(final Player base, final String group) {
|
|
||||||
AnjoPermissionsHandler handler = getHandler(base);
|
|
||||||
if (handler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return handler.inGroup(base.getName(), group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(final Player base, final String node) {
|
|
||||||
AnjoPermissionsHandler handler = getHandler(base);
|
|
||||||
if (handler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return handler.has(base, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrefix(final Player base) {
|
|
||||||
AnjoPermissionsHandler handler = getHandler(base);
|
|
||||||
if (handler == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return handler.getUserPrefix(base.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuffix(final Player base) {
|
|
||||||
AnjoPermissionsHandler handler = getHandler(base);
|
|
||||||
if (handler == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return handler.getUserSuffix(base.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnjoPermissionsHandler getHandler(final Player base) {
|
private AnjoPermissionsHandler getHandler(final Player base) {
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
package com.earth2me.essentials.perm;
|
|
||||||
|
|
||||||
import com.platymuus.bukkit.permissions.Group;
|
|
||||||
import com.platymuus.bukkit.permissions.PermissionInfo;
|
|
||||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class PermissionsBukkitHandler extends SuperpermsHandler {
|
|
||||||
private final transient PermissionsPlugin plugin;
|
|
||||||
|
|
||||||
public PermissionsBukkitHandler(final Plugin plugin) {
|
|
||||||
this.plugin = (PermissionsPlugin) plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(final Player base) {
|
|
||||||
final List<Group> groups = getPBGroups(base);
|
|
||||||
if (groups == null || groups.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return groups.get(0).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(final Player base) {
|
|
||||||
final List<Group> groups = getPBGroups(base);
|
|
||||||
if (groups.size() == 1) {
|
|
||||||
return Collections.singletonList(groups.get(0).getName());
|
|
||||||
}
|
|
||||||
final List<String> groupNames = new ArrayList<String>(groups.size());
|
|
||||||
for (Group group : groups) {
|
|
||||||
groupNames.add(group.getName());
|
|
||||||
}
|
|
||||||
return groupNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Group> getPBGroups(final Player base) {
|
|
||||||
final PermissionInfo info = plugin.getPlayerInfo(base.getName());
|
|
||||||
if (info == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
final List<Group> groups = info.getGroups();
|
|
||||||
if (groups == null || groups.isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(final Player base, final String group) {
|
|
||||||
final List<Group> groups = getPBGroups(base);
|
|
||||||
for (Group group1 : groups) {
|
|
||||||
if (group1.getName().equalsIgnoreCase(group)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -5,88 +5,16 @@ import ru.tehkode.permissions.PermissionManager;
|
|||||||
import ru.tehkode.permissions.PermissionUser;
|
import ru.tehkode.permissions.PermissionUser;
|
||||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||||
|
|
||||||
import java.util.Arrays;
|
public class PermissionsExHandler extends AbstractVaultHandler {
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class PermissionsExHandler extends SuperpermsHandler {
|
|
||||||
private final transient PermissionManager manager;
|
private final transient PermissionManager manager;
|
||||||
|
|
||||||
public PermissionsExHandler() {
|
public PermissionsExHandler() {
|
||||||
manager = PermissionsEx.getPermissionManager();
|
manager = PermissionsEx.getPermissionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(final Player base) {
|
|
||||||
final PermissionUser user = manager.getUser(base.getName());
|
|
||||||
if (user == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] groupsNames = user.getGroupsNames();
|
|
||||||
if (groupsNames == null || groupsNames.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return groupsNames[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(final Player base) {
|
|
||||||
final PermissionUser user = manager.getUser(base.getName());
|
|
||||||
if (user == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] groupsNames = user.getGroupsNames();
|
|
||||||
if (groupsNames == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Arrays.asList(groupsNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(final Player base, final String group) {
|
public boolean canBuild(final Player base, final String group) {
|
||||||
final PermissionUser user = manager.getUser(base.getName());
|
final PermissionUser user = manager.getUser(base.getName());
|
||||||
if (user == null) {
|
return user != null && user.getOptionBoolean("build", base.getWorld().getName(), false);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return user.getOptionBoolean("build", base.getWorld().getName(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(final Player base, final String group) {
|
|
||||||
final PermissionUser user = manager.getUser(base.getName());
|
|
||||||
if (user == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return user.inGroup(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(final Player base, final String node) {
|
|
||||||
return super.hasPermission(base, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrefix(final Player base) {
|
|
||||||
final PermissionUser user = manager.getUser(base.getName());
|
|
||||||
if (user == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return user.getPrefix(base.getWorld().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuffix(final Player base) {
|
|
||||||
final PermissionUser user = manager.getUser(base.getName());
|
|
||||||
if (user == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return user.getSuffix(base.getWorld().getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ public class PermissionsHandler implements IPermissionsHandler {
|
|||||||
private transient IPermissionsHandler handler = new NullPermissionsHandler();
|
private transient IPermissionsHandler handler = new NullPermissionsHandler();
|
||||||
private transient String defaultGroup = "default";
|
private transient String defaultGroup = "default";
|
||||||
private final transient Essentials ess;
|
private final transient Essentials ess;
|
||||||
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
|
||||||
private transient boolean useSuperperms = false;
|
private transient boolean useSuperperms = false;
|
||||||
|
|
||||||
public PermissionsHandler(final Essentials plugin) {
|
public PermissionsHandler(final Essentials plugin) {
|
||||||
@ -96,23 +95,12 @@ public class PermissionsHandler implements IPermissionsHandler {
|
|||||||
|
|
||||||
public void checkPermissions() {
|
public void checkPermissions() {
|
||||||
final PluginManager pluginManager = ess.getServer().getPluginManager();
|
final PluginManager pluginManager = ess.getServer().getPluginManager();
|
||||||
|
|
||||||
final Plugin vaultAPI = pluginManager.getPlugin("Vault");
|
final Plugin vaultAPI = pluginManager.getPlugin("Vault");
|
||||||
if (vaultAPI != null && vaultAPI.isEnabled()) {
|
if (vaultAPI != null && vaultAPI.isEnabled()) {
|
||||||
if (!(handler instanceof VaultHandler)) {
|
|
||||||
VaultHandler vault = new VaultHandler(ess);
|
|
||||||
if (vault.setupProviders()) {
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using Vault based permissions.");
|
|
||||||
handler = vault;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Plugin permExPlugin = pluginManager.getPlugin("PermissionsEx");
|
final Plugin permExPlugin = pluginManager.getPlugin("PermissionsEx");
|
||||||
if (permExPlugin != null && permExPlugin.isEnabled()) {
|
if (permExPlugin != null && permExPlugin.isEnabled()) {
|
||||||
if (!(handler instanceof PermissionsExHandler)) {
|
if (!(handler instanceof PermissionsExHandler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using PermissionsEx based permissions.");
|
ess.getLogger().info("Using PermissionsEX based permissions with Vault.");
|
||||||
handler = new PermissionsExHandler();
|
handler = new PermissionsExHandler();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -121,26 +109,17 @@ public class PermissionsHandler implements IPermissionsHandler {
|
|||||||
final Plugin GMplugin = pluginManager.getPlugin("GroupManager");
|
final Plugin GMplugin = pluginManager.getPlugin("GroupManager");
|
||||||
if (GMplugin != null && GMplugin.isEnabled()) {
|
if (GMplugin != null && GMplugin.isEnabled()) {
|
||||||
if (!(handler instanceof GroupManagerHandler)) {
|
if (!(handler instanceof GroupManagerHandler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using GroupManager based permissions.");
|
ess.getLogger().info("Using GroupManager based permissions with Vault.");
|
||||||
handler = new GroupManagerHandler(GMplugin);
|
handler = new GroupManagerHandler(GMplugin);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Plugin permBukkitPlugin = pluginManager.getPlugin("PermissionsBukkit");
|
|
||||||
if (permBukkitPlugin != null && permBukkitPlugin.isEnabled()) {
|
|
||||||
if (!(handler instanceof PermissionsBukkitHandler)) {
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using PermissionsBukkit based permissions.");
|
|
||||||
handler = new PermissionsBukkitHandler(permBukkitPlugin);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Plugin simplyPermsPlugin = pluginManager.getPlugin("SimplyPerms");
|
final Plugin simplyPermsPlugin = pluginManager.getPlugin("SimplyPerms");
|
||||||
if (simplyPermsPlugin != null && simplyPermsPlugin.isEnabled()) {
|
if (simplyPermsPlugin != null && simplyPermsPlugin.isEnabled()) {
|
||||||
if (!(handler instanceof SimplyPermsHandler)) {
|
if (!(handler instanceof SimplyPermsHandler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using SimplyPerms based permissions.");
|
ess.getLogger().info("Using SimplyPerms based permissions with Vault.");
|
||||||
handler = new SimplyPermsHandler(simplyPermsPlugin);
|
handler = new SimplyPermsHandler();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -148,8 +127,8 @@ public class PermissionsHandler implements IPermissionsHandler {
|
|||||||
final Plugin privPlugin = pluginManager.getPlugin("Privileges");
|
final Plugin privPlugin = pluginManager.getPlugin("Privileges");
|
||||||
if (privPlugin != null && privPlugin.isEnabled()) {
|
if (privPlugin != null && privPlugin.isEnabled()) {
|
||||||
if (!(handler instanceof PrivilegesHandler)) {
|
if (!(handler instanceof PrivilegesHandler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using Privileges based permissions.");
|
ess.getLogger().info("Using Privileges based permissions with Vault.");
|
||||||
handler = new PrivilegesHandler(privPlugin);
|
handler = new PrivilegesHandler();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -157,30 +136,31 @@ public class PermissionsHandler implements IPermissionsHandler {
|
|||||||
final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions");
|
final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions");
|
||||||
if (bPermPlugin != null && bPermPlugin.isEnabled()) {
|
if (bPermPlugin != null && bPermPlugin.isEnabled()) {
|
||||||
if (!(handler instanceof BPermissions2Handler)) {
|
if (!(handler instanceof BPermissions2Handler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using bPermissions2 based permissions.");
|
ess.getLogger().info("Using bPermissions based permissions with Vault.");
|
||||||
handler = new BPermissions2Handler();
|
handler = new BPermissions2Handler();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Plugin zPermsPlugin = pluginManager.getPlugin("zPermissions");
|
if (!(handler instanceof GenericVaultHandler)) {
|
||||||
if (zPermsPlugin != null && zPermsPlugin.isEnabled()) {
|
AbstractVaultHandler vault = new GenericVaultHandler();
|
||||||
if (!(handler instanceof ZPermissionsHandler)) {
|
if (vault.setupProviders()) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using zPermissions based permissions.");
|
ess.getLogger().info("Using generic Vault based permissions.");
|
||||||
handler = new ZPermissionsHandler(ess);
|
handler = vault;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useSuperperms) {
|
if (useSuperperms) {
|
||||||
if (!(handler instanceof SuperpermsHandler)) {
|
if (!(handler instanceof SuperpermsHandler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using superperms based permissions.");
|
ess.getLogger().info("Using superperms based permissions.");
|
||||||
handler = new SuperpermsHandler();
|
handler = new SuperpermsHandler();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(handler instanceof ConfigPermissionsHandler)) {
|
if (!(handler instanceof ConfigPermissionsHandler)) {
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using config file enhanced permissions.");
|
ess.getLogger().info("Essentials: Using config file enhanced permissions.");
|
||||||
LOGGER.log(Level.INFO, "Permissions listed in as player-commands will be given to all users.");
|
ess.getLogger().info("Permissions listed in as player-commands will be given to all users.");
|
||||||
handler = new ConfigPermissionsHandler(ess);
|
handler = new ConfigPermissionsHandler(ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,10 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
import net.krinsoft.privileges.Privileges;
|
|
||||||
import net.krinsoft.privileges.groups.Group;
|
|
||||||
import net.krinsoft.privileges.groups.GroupManager;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PrivilegesHandler extends SuperpermsHandler {
|
public class PrivilegesHandler extends SuperpermsHandler {
|
||||||
private final transient Privileges plugin;
|
|
||||||
private final GroupManager manager;
|
|
||||||
|
|
||||||
public PrivilegesHandler(final Plugin plugin) {
|
|
||||||
this.plugin = (Privileges) plugin;
|
|
||||||
this.manager = this.plugin.getGroupManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(final Player base) {
|
|
||||||
Group group = manager.getGroup(base);
|
|
||||||
if (group == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return group.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(final Player base) {
|
|
||||||
Group group = manager.getGroup(base);
|
|
||||||
if (group == null) {
|
|
||||||
return new ArrayList<String>();
|
|
||||||
}
|
|
||||||
return group.getGroupTree();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(final Player base, final String group) {
|
|
||||||
Group pGroup = manager.getGroup(base);
|
|
||||||
if (pGroup == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return pGroup.isMemberOf(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(Player base, String group) {
|
public boolean canBuild(Player base, String group) {
|
||||||
return hasPermission(base, "privileges.build");
|
return hasPermission(base, "privileges.build");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,48 +1,10 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
import net.crystalyx.bukkit.simplyperms.SimplyAPI;
|
|
||||||
import net.crystalyx.bukkit.simplyperms.SimplyPlugin;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SimplyPermsHandler extends SuperpermsHandler {
|
|
||||||
|
|
||||||
private final transient SimplyAPI api;
|
|
||||||
|
|
||||||
public SimplyPermsHandler(final Plugin plugin) {
|
|
||||||
this.api = ((SimplyPlugin) plugin).getAPI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(final Player base) {
|
|
||||||
final List<String> groups = api.getPlayerGroups(base.getName());
|
|
||||||
if (groups == null || groups.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return groups.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(final Player base) {
|
|
||||||
return api.getPlayerGroups(base.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(final Player base, final String group) {
|
|
||||||
final List<String> groups = api.getPlayerGroups(base.getName());
|
|
||||||
for (String group1 : groups) {
|
|
||||||
if (group1.equalsIgnoreCase(group)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class SimplyPermsHandler extends AbstractVaultHandler {
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(Player base, String group) {
|
public boolean canBuild(Player base, String group) {
|
||||||
return hasPermission(base, "permissions.allow.build");
|
return hasPermission(base, "permissions.allow.build");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,138 +0,0 @@
|
|||||||
package com.earth2me.essentials.perm;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.ServiceRegisterEvent;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
|
||||||
public class ZPermissionsHandler extends SuperpermsHandler implements Listener {
|
|
||||||
private ZPermissionsService service = null;
|
|
||||||
private boolean hasGetPlayerPrimaryGroup = false; // This is a post-1.0 addition
|
|
||||||
|
|
||||||
public ZPermissionsHandler(Plugin plugin) {
|
|
||||||
acquireZPermissionsService();
|
|
||||||
if (!isReady()) {
|
|
||||||
// Shouldn't get to this point, since caller checks if zPerms
|
|
||||||
// is enabled. But for the sake of correctness...
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServiceRegister(ServiceRegisterEvent event) {
|
|
||||||
if (ZPermissionsService.class.equals(event.getProvider().getService())) {
|
|
||||||
acquireZPermissionsService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup(Player base) {
|
|
||||||
if (!isReady()) {
|
|
||||||
return super.getGroup(base);
|
|
||||||
} else {
|
|
||||||
return getPrimaryGroup(base.getUniqueId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroups(Player base) {
|
|
||||||
if (!isReady()) {
|
|
||||||
return super.getGroups(base);
|
|
||||||
} else {
|
|
||||||
return new ArrayList<String>(service.getPlayerGroups(base.getUniqueId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(Player base, String group) {
|
|
||||||
if (!isReady()) {
|
|
||||||
return super.inGroup(base, group);
|
|
||||||
} else {
|
|
||||||
Set<String> groups = service.getPlayerGroups(base.getUniqueId());
|
|
||||||
for (String test : groups) {
|
|
||||||
if (test.equalsIgnoreCase(group)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrefix(Player base) {
|
|
||||||
if (!isReady()) {
|
|
||||||
return super.getPrefix(base);
|
|
||||||
} else {
|
|
||||||
return getPrefixSuffix(base, "prefix");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuffix(Player base) {
|
|
||||||
if (!isReady()) {
|
|
||||||
return super.getSuffix(base);
|
|
||||||
} else {
|
|
||||||
return getPrefixSuffix(base, "suffix");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPrefixSuffix(Player base, String metadataName) {
|
|
||||||
String playerPrefixSuffix;
|
|
||||||
try {
|
|
||||||
playerPrefixSuffix = service.getPlayerMetadata(base.getUniqueId(), metadataName, String.class);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
// User error. They set prefix to a non-string.
|
|
||||||
playerPrefixSuffix = null;
|
|
||||||
}
|
|
||||||
if (playerPrefixSuffix == null) {
|
|
||||||
// Try prefix/suffix of their "primary group"
|
|
||||||
try {
|
|
||||||
return service.getGroupMetadata(getPrimaryGroup(base.getUniqueId()), metadataName, String.class);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
// User error, again
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return playerPrefixSuffix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void acquireZPermissionsService() {
|
|
||||||
service = Bukkit.getServicesManager().load(ZPermissionsService.class);
|
|
||||||
if (isReady()) {
|
|
||||||
// getPlayerPrimaryGroup(String) was added in an unreleased version
|
|
||||||
// Check if it exists.
|
|
||||||
try {
|
|
||||||
service.getClass().getMethod("getPlayerPrimaryGroup", String.class);
|
|
||||||
hasGetPlayerPrimaryGroup = true;
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
hasGetPlayerPrimaryGroup = false;
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
hasGetPlayerPrimaryGroup = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isReady() {
|
|
||||||
return service != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPrimaryGroup(UUID playerId) {
|
|
||||||
if (hasGetPlayerPrimaryGroup) {
|
|
||||||
return service.getPlayerPrimaryGroup(playerId);
|
|
||||||
} else {
|
|
||||||
// Fall back to using highest-weight assigned group
|
|
||||||
List<String> groups = service.getPlayerAssignedGroups(playerId);
|
|
||||||
return groups.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user