2013-01-15 21:55:12 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2013-01-15 21:55:12 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2013-01-15 21:55:12 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2013-01-15 21:55:12 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2013-01-15 21:55:12 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.wepif;
|
|
|
|
|
|
|
|
import com.sk89q.util.yaml.YAMLProcessor;
|
|
|
|
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
|
|
|
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.World;
|
2014-09-08 03:04:56 +00:00
|
|
|
import org.bukkit.permissions.Permissible;
|
2013-01-15 21:55:12 +00:00
|
|
|
|
2014-09-08 03:04:56 +00:00
|
|
|
public class GroupManagerResolver extends DinnerPermsResolver {
|
2013-01-15 21:55:12 +00:00
|
|
|
private final WorldsHolder worldsHolder;
|
|
|
|
|
|
|
|
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
|
|
|
try {
|
|
|
|
WorldsHolder worldsHolder = server.getServicesManager().load(WorldsHolder.class);
|
|
|
|
|
|
|
|
if (worldsHolder == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new GroupManagerResolver(server, worldsHolder);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public GroupManagerResolver(Server server, WorldsHolder worldsHolder) {
|
2014-09-08 03:04:56 +00:00
|
|
|
super(server);
|
2013-01-15 21:55:12 +00:00
|
|
|
this.worldsHolder = worldsHolder;
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2013-01-15 21:55:12 +00:00
|
|
|
public void load() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-08 03:04:56 +00:00
|
|
|
/*
|
|
|
|
* True if the string is null or empty
|
|
|
|
*/
|
|
|
|
private boolean nameNotSafe(String perm) {
|
|
|
|
return perm == null || perm.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
private AnjoPermissionsHandler getPermissionHandler(World world) {
|
|
|
|
if (world != null) {
|
2013-01-15 21:55:12 +00:00
|
|
|
return worldsHolder.getWorldPermissions(world.getName());
|
|
|
|
} else {
|
2014-09-08 03:04:56 +00:00
|
|
|
return worldsHolder.getDefaultWorld().getPermissionsHandler();
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2014-09-08 03:04:56 +00:00
|
|
|
public String[] getGroups(String name) {
|
|
|
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(null);
|
2013-01-15 21:55:12 +00:00
|
|
|
if (permissionHandler == null) {
|
2014-09-08 03:04:56 +00:00
|
|
|
return new String[0];
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
2014-09-08 03:04:56 +00:00
|
|
|
return permissionHandler.getGroups(name);
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2014-09-08 03:04:56 +00:00
|
|
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
|
|
|
if (nameNotSafe(permission)) {
|
2013-01-15 21:55:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-08 03:04:56 +00:00
|
|
|
|
|
|
|
Permissible permissible = getPermissible(player);
|
|
|
|
if (permissible == null) {
|
|
|
|
return getPermissionHandler(player.getPlayer().getWorld()).permission(player.getName(), permission);
|
|
|
|
} else {
|
|
|
|
return permissible.hasPermission(permission);
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2014-09-08 03:04:56 +00:00
|
|
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
|
|
|
if (nameNotSafe(permission)) {
|
|
|
|
return false;
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-08 03:04:56 +00:00
|
|
|
String name = player.getName();
|
|
|
|
World world = worldName != null ? server.getWorld(worldName) : player.getPlayer().getWorld();
|
2013-01-15 21:55:12 +00:00
|
|
|
|
2014-09-08 03:04:56 +00:00
|
|
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(world);
|
|
|
|
return permissionHandler != null && permissionHandler.permission(name, permission);
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2013-01-15 21:55:12 +00:00
|
|
|
public boolean inGroup(OfflinePlayer player, String group) {
|
2014-09-08 03:04:56 +00:00
|
|
|
if (super.inGroup(player, group)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nameNotSafe(group)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(null);
|
|
|
|
return permissionHandler != null && permissionHandler.inGroup(player.getName(), group);
|
2013-01-15 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2013-01-15 21:55:12 +00:00
|
|
|
public String[] getGroups(OfflinePlayer player) {
|
|
|
|
return getGroups(player.getName());
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:04:04 +00:00
|
|
|
@Override
|
2013-01-15 21:55:12 +00:00
|
|
|
public String getDetectionMessage() {
|
|
|
|
return "GroupManager detected! Using GroupManager for permissions.";
|
|
|
|
}
|
|
|
|
}
|