mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 02:07:39 +00:00
Added DinnerPerms support to WEPIF
This commit is contained in:
parent
2efa37f0b2
commit
cb7ec82905
@ -0,0 +1,71 @@
|
|||||||
|
package com.sk89q.bukkit.migration;
|
||||||
|
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DinnerPermsResolver implements PermissionsResolver {
|
||||||
|
|
||||||
|
private static final String GROUP_PREFIX = "group.";
|
||||||
|
private final Server server;
|
||||||
|
|
||||||
|
public DinnerPermsResolver(Server server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
// Permissions are already loaded
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String name, String permission) {
|
||||||
|
Player player = server.getPlayer(name);
|
||||||
|
if (player == null)
|
||||||
|
return false; // Permissions are only registered for online players
|
||||||
|
if ( player.hasPermission("*") || player.hasPermission(permission))
|
||||||
|
return true;
|
||||||
|
int i = 0;
|
||||||
|
while (i <= permission.length() + 1) {
|
||||||
|
int dotPos = permission.indexOf(".", i);
|
||||||
|
if (dotPos > -1) {
|
||||||
|
if (player.hasPermission(permission.substring(0, dotPos + 1) + "*"))
|
||||||
|
return true;
|
||||||
|
i += dotPos;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
|
return hasPermission(name, permission); // no per-world ability to check permissions in dinnerperms
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(String name, String group) {
|
||||||
|
Player player = server.getPlayer(name);
|
||||||
|
if (player == null)
|
||||||
|
return false;
|
||||||
|
return player.hasPermission(GROUP_PREFIX + group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getGroups(String name) {
|
||||||
|
Player player = server.getPlayer(name);
|
||||||
|
if (player == null)
|
||||||
|
return new String[0];
|
||||||
|
List<String> groupNames = new ArrayList<String>();
|
||||||
|
for (PermissionAttachmentInfo permAttach : player.getEffectivePermissions()) {
|
||||||
|
String perm = permAttach.getPermission();
|
||||||
|
if (!perm.startsWith(GROUP_PREFIX))
|
||||||
|
continue;
|
||||||
|
groupNames.add(perm.substring(perm.indexOf(GROUP_PREFIX), perm.length()));
|
||||||
|
}
|
||||||
|
return groupNames.toArray(new String[groupNames.size()]);
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
if (tryPluginPermissionsResolver()) return;
|
if (tryPluginPermissionsResolver()) return;
|
||||||
if (tryNijiPermissions()) return;
|
if (tryNijiPermissions()) return;
|
||||||
if (tryFlatFilePermissions()) return;
|
if (tryFlatFilePermissions()) return;
|
||||||
|
if (tryDinnerPerms()) return;
|
||||||
|
|
||||||
perms = new ConfigurationPermissionsResolver(config);
|
perms = new ConfigurationPermissionsResolver(config);
|
||||||
logger.info(name + ": No known permissions plugin detected. Using configuration file for permissions.");
|
logger.info(name + ": No known permissions plugin detected. Using configuration file for permissions.");
|
||||||
@ -75,7 +76,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
perms = new PluginPermissionsResolver(
|
perms = new PluginPermissionsResolver(
|
||||||
(PermissionsProvider) plugin);
|
(PermissionsProvider) plugin);
|
||||||
logger.info(name + ": Using plugin '"
|
logger.info(name + ": Using plugin '"
|
||||||
+ plugin.getDescription().getName() + " for permissions.");
|
+ plugin.getDescription().getName() + "' for permissions.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,6 +84,14 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean tryDinnerPerms() {
|
||||||
|
if (!config.getBoolean("permissions.dinner-perms", true))
|
||||||
|
return false;
|
||||||
|
perms = new DinnerPermsResolver(server);
|
||||||
|
logger.info(name + ": Using the Bukkit Permissions API.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPluginPermissionsResolver(Plugin plugin) {
|
public void setPluginPermissionsResolver(Plugin plugin) {
|
||||||
if (!(plugin instanceof PermissionsProvider)) {
|
if (!(plugin instanceof PermissionsProvider)) {
|
||||||
return;
|
return;
|
||||||
@ -91,7 +100,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
perms = new PluginPermissionsResolver(
|
perms = new PluginPermissionsResolver(
|
||||||
(PermissionsProvider) plugin);
|
(PermissionsProvider) plugin);
|
||||||
logger.info(name + ": Using plugin '"
|
logger.info(name + ": Using plugin '"
|
||||||
+ plugin.getDescription().getName() + " for permissions.");
|
+ plugin.getDescription().getName() + "' for permissions.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
|
@ -63,6 +63,7 @@ debug: false
|
|||||||
# See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit
|
# See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit
|
||||||
# Now with multiworld support (see example)
|
# Now with multiworld support (see example)
|
||||||
permissions:
|
permissions:
|
||||||
|
dinner-perms: true
|
||||||
groups:
|
groups:
|
||||||
default:
|
default:
|
||||||
permissions:
|
permissions:
|
||||||
|
Loading…
Reference in New Issue
Block a user