Plex-FAWE/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsExResolver.java

94 lines
3.1 KiB
Java
Raw Normal View History

2011-09-19 06:24:21 +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
2011-09-19 06:24:21 +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
2011-09-19 06:24:21 +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.
2011-09-19 06:24:21 +00:00
*
2014-04-04 22:03:18 +00:00
* You should have received a copy of the GNU Lesser General Public License
2011-09-19 06:24:21 +00:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2011-09-27 07:32:46 +00:00
*/
2011-09-19 06:24:21 +00:00
package com.sk89q.wepif;
2011-08-25 06:56:29 +00:00
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
2011-08-25 06:56:29 +00:00
import org.bukkit.Server;
import org.bukkit.permissions.Permissible;
2011-08-25 06:56:29 +00:00
import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.PermissionUser;
public class PermissionsExResolver extends DinnerPermsResolver {
2011-08-25 06:56:29 +00:00
private final PermissionManager manager;
2011-09-27 07:32:46 +00:00
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
try {
PermissionManager manager = server.getServicesManager().load(PermissionManager.class);
2011-09-27 07:32:46 +00:00
if (manager == null) {
return null;
}
return new PermissionsExResolver(server, manager);
} catch (Throwable t) {
return null;
2011-09-24 19:24:10 +00:00
}
}
2011-09-27 07:32:46 +00:00
public PermissionsExResolver(Server server, PermissionManager manager) {
super(server);
this.manager = manager;
2011-08-25 06:56:29 +00:00
}
2011-09-24 19:32:03 +00:00
2014-07-29 18:04:04 +00:00
@Override
2011-08-25 06:56:29 +00:00
public boolean hasPermission(String worldName, String name, String permission) {
return manager.has(name, permission, worldName);
}
2011-09-24 19:32:03 +00:00
2014-07-29 18:04:04 +00:00
@Override
public boolean hasPermission(OfflinePlayer player, String permission) {
Permissible permissible = getPermissible(player);
if (permissible == null) {
return manager.has(player.getName(), permission, null);
} else {
return permissible.hasPermission(permission);
}
}
2014-07-29 18:04:04 +00:00
@Override
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
2014-07-29 18:04:04 +00:00
@Override
public boolean inGroup(OfflinePlayer player, String group) {
return super.inGroup(player, group) || manager.getUser(player.getName()).inGroup(group);
}
2014-07-29 18:04:04 +00:00
@Override
public String[] getGroups(OfflinePlayer player) {
if (getPermissible(player) == null) {
PermissionUser user = manager.getUser(player.getName());
if (user == null) {
return new String[0];
}
return user.getGroupsNames();
} else {
return super.getGroups(player);
}
}
2014-07-29 18:04:04 +00:00
@Override
public String getDetectionMessage() {
return "PermissionsEx detected! Using PermissionsEx for permissions.";
}
2011-08-25 06:56:29 +00:00
}