2011-08-02 04:02:15 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-08-07 08:00:48 +00:00
|
|
|
|
2011-08-02 04:02:15 +00:00
|
|
|
public void load() {
|
|
|
|
// Permissions are already loaded
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2011-09-04 23:21:49 +00:00
|
|
|
int dotPos = permission.lastIndexOf(".");
|
|
|
|
while (dotPos > -1) {
|
|
|
|
if (player.hasPermission(permission.substring(0, dotPos + 1) + "*"))
|
|
|
|
return true;
|
|
|
|
dotPos = permission.lastIndexOf(".", dotPos - 1);
|
2011-08-02 04:02:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPermission(String worldName, String name, String permission) {
|
|
|
|
return hasPermission(name, permission); // no per-world ability to check permissions in dinnerperms
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean inGroup(String name, String group) {
|
|
|
|
Player player = server.getPlayer(name);
|
|
|
|
if (player == null)
|
|
|
|
return false;
|
|
|
|
return player.hasPermission(GROUP_PREFIX + group);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2011-09-09 22:10:25 +00:00
|
|
|
if (!(perm.startsWith(GROUP_PREFIX) && permAttach.getValue()))
|
2011-08-02 04:02:15 +00:00
|
|
|
continue;
|
2011-08-16 21:05:33 +00:00
|
|
|
groupNames.add(perm.substring(GROUP_PREFIX.length(), perm.length()));
|
2011-08-02 04:02:15 +00:00
|
|
|
}
|
2011-09-04 23:21:49 +00:00
|
|
|
return groupNames.toArray(new String[0]);
|
2011-08-02 04:02:15 +00:00
|
|
|
}
|
|
|
|
}
|