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
|
|
|
|
2011-12-04 17:56:35 +00:00
|
|
|
package com.sk89q.wepif;
|
2011-08-25 06:56:29 +00:00
|
|
|
|
2011-10-23 05:22:50 +00:00
|
|
|
import com.sk89q.util.yaml.YAMLProcessor;
|
2011-12-04 17:56:35 +00:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2011-08-25 06:56:29 +00:00
|
|
|
import org.bukkit.Server;
|
2013-09-01 06:00:49 +00:00
|
|
|
import org.bukkit.permissions.Permissible;
|
2011-08-25 06:56:29 +00:00
|
|
|
import ru.tehkode.permissions.PermissionManager;
|
|
|
|
import ru.tehkode.permissions.PermissionUser;
|
|
|
|
|
2013-09-01 06:00:49 +00:00
|
|
|
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
|
|
|
|
2011-10-23 05:22:50 +00:00
|
|
|
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
2011-10-23 16:19:29 +00:00
|
|
|
try {
|
|
|
|
PermissionManager manager = server.getServicesManager().load(PermissionManager.class);
|
2011-09-27 07:32:46 +00:00
|
|
|
|
2011-10-23 16:19:29 +00:00
|
|
|
if (manager == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new PermissionsExResolver(server, manager);
|
|
|
|
} catch (Throwable t) {
|
2011-09-27 03:40:18 +00:00
|
|
|
return null;
|
2011-09-24 19:24:10 +00:00
|
|
|
}
|
2011-09-27 03:40:18 +00:00
|
|
|
}
|
2011-09-27 07:32:46 +00:00
|
|
|
|
2011-09-27 03:40:18 +00:00
|
|
|
public PermissionsExResolver(Server server, PermissionManager manager) {
|
2013-09-01 06:00:49 +00:00
|
|
|
super(server);
|
2011-09-27 03:40:18 +00:00
|
|
|
this.manager = manager;
|
2011-08-25 06:56:29 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
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
|
|
|
|
2011-12-04 17:56:35 +00:00
|
|
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
2013-09-01 06:00:49 +00:00
|
|
|
Permissible permissible = getPermissible(player);
|
|
|
|
if (permissible == null) {
|
|
|
|
return manager.has(player.getName(), permission, null);
|
|
|
|
} else {
|
|
|
|
return permissible.hasPermission(permission);
|
|
|
|
}
|
2011-12-04 17:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
|
|
|
return hasPermission(worldName, player.getName(), permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean inGroup(OfflinePlayer player, String group) {
|
2013-09-26 02:35:17 +00:00
|
|
|
return super.inGroup(player, group) || manager.getUser(player.getName()).inGroup(group);
|
2011-12-04 17:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String[] getGroups(OfflinePlayer player) {
|
2013-09-01 06:00:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2011-12-04 17:56:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 03:40:18 +00:00
|
|
|
public String getDetectionMessage() {
|
|
|
|
return "PermissionsEx detected! Using PermissionsEx for permissions.";
|
|
|
|
}
|
2011-08-25 06:56:29 +00:00
|
|
|
}
|