mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Made GroupManager a DinnerPerms based resolver
This commit is contained in:
parent
3098dc0226
commit
a0b9de0acf
@ -25,11 +25,10 @@ import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
public class GroupManagerResolver implements PermissionsResolver {
|
public class GroupManagerResolver extends DinnerPermsResolver {
|
||||||
private final WorldsHolder worldsHolder;
|
private final WorldsHolder worldsHolder;
|
||||||
private final Server server;
|
|
||||||
|
|
||||||
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
||||||
try {
|
try {
|
||||||
@ -46,7 +45,7 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GroupManagerResolver(Server server, WorldsHolder worldsHolder) {
|
public GroupManagerResolver(Server server, WorldsHolder worldsHolder) {
|
||||||
this.server = server;
|
super(server);
|
||||||
this.worldsHolder = worldsHolder;
|
this.worldsHolder = worldsHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,57 +54,24 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnjoPermissionsHandler getPermissionHandler(String name, String worldName) {
|
/*
|
||||||
if (name == null || name.isEmpty()) {
|
* True if the string is null or empty
|
||||||
return null;
|
*/
|
||||||
}
|
private boolean nameNotSafe(String perm) {
|
||||||
if (worldName == null || worldName.isEmpty()) {
|
return perm == null || perm.isEmpty();
|
||||||
Player player = server.getPlayerExact(name);
|
|
||||||
if (player == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
World world = player.getWorld();
|
|
||||||
if (world == null) {
|
|
||||||
return worldsHolder.getDefaultWorld().getPermissionsHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AnjoPermissionsHandler getPermissionHandler(World world) {
|
||||||
|
if (world != null) {
|
||||||
return worldsHolder.getWorldPermissions(world.getName());
|
return worldsHolder.getWorldPermissions(world.getName());
|
||||||
} else {
|
} else {
|
||||||
return worldsHolder.getWorldPermissions(worldName);
|
return worldsHolder.getDefaultWorld().getPermissionsHandler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String name, String permission) {
|
|
||||||
return hasPermission(null, name, permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
|
||||||
if (permission == null || permission.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
AnjoPermissionsHandler permissionHandler = getPermissionHandler(name, worldName);
|
|
||||||
if (permissionHandler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return permissionHandler.permission(name, permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(String name, String group) {
|
|
||||||
if (group == null || group.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
AnjoPermissionsHandler permissionHandler = getPermissionHandler(name, null);
|
|
||||||
if (permissionHandler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return permissionHandler.inGroup(name, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups(String name) {
|
public String[] getGroups(String name) {
|
||||||
AnjoPermissionsHandler permissionHandler = getPermissionHandler(name, null);
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(null);
|
||||||
if (permissionHandler == null) {
|
if (permissionHandler == null) {
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
@ -114,17 +80,43 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return hasPermission(player.getName(), permission);
|
if (nameNotSafe(permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Permissible permissible = getPermissible(player);
|
||||||
|
if (permissible == null) {
|
||||||
|
return getPermissionHandler(player.getPlayer().getWorld()).permission(player.getName(), permission);
|
||||||
|
} else {
|
||||||
|
return permissible.hasPermission(permission);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
if (nameNotSafe(permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = player.getName();
|
||||||
|
World world = worldName != null ? server.getWorld(worldName) : player.getPlayer().getWorld();
|
||||||
|
|
||||||
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(world);
|
||||||
|
return permissionHandler != null && permissionHandler.permission(name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return inGroup(player.getName(), group);
|
if (super.inGroup(player, group)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameNotSafe(group)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(null);
|
||||||
|
return permissionHandler != null && permissionHandler.inGroup(player.getName(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user