#1298 Make permission manager accept OfflinePlayers + fix permission purge

This commit is contained in:
Gabriele C 2017-09-03 02:07:00 +02:00
parent 72da27e734
commit 2fbdd46919
7 changed files with 53 additions and 59 deletions

View File

@ -256,7 +256,7 @@ public class PermissionsManager implements Reloadable {
*
* @return Permission groups, or an empty collection if this feature is not supported.
*/
public Collection<String> getGroups(Player player) {
public Collection<String> getGroups(OfflinePlayer player) {
return isEnabled() ? handler.getGroups(player) : Collections.emptyList();
}
@ -267,7 +267,7 @@ public class PermissionsManager implements Reloadable {
*
* @return The name of the primary permission group. Or null.
*/
public String getPrimaryGroup(Player player) {
public String getPrimaryGroup(OfflinePlayer player) {
return isEnabled() ? handler.getPrimaryGroup(player) : null;
}
@ -280,7 +280,7 @@ public class PermissionsManager implements Reloadable {
* @return True if the player is in the specified group, false otherwise.
* False is also returned if groups aren't supported by the used permissions system.
*/
public boolean isInGroup(Player player, String groupName) {
public boolean isInGroup(OfflinePlayer player, String groupName) {
return isEnabled() && handler.isInGroup(player, groupName);
}
@ -293,7 +293,7 @@ public class PermissionsManager implements Reloadable {
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean addGroup(Player player, String groupName) {
public boolean addGroup(OfflinePlayer player, String groupName) {
if (!isEnabled() || StringUtils.isEmpty(groupName)) {
return false;
}
@ -309,7 +309,7 @@ public class PermissionsManager implements Reloadable {
* @return True if at least one group was added, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean addGroups(Player player, Collection<String> groupNames) {
public boolean addGroups(OfflinePlayer player, Collection<String> groupNames) {
// If no permissions system is used, return false
if (!isEnabled()) {
return false;
@ -336,7 +336,7 @@ public class PermissionsManager implements Reloadable {
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean removeGroup(Player player, String groupName) {
public boolean removeGroup(OfflinePlayer player, String groupName) {
return isEnabled() && handler.removeFromGroup(player, groupName);
}
@ -349,7 +349,7 @@ public class PermissionsManager implements Reloadable {
* @return True if at least one group was removed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean removeGroups(Player player, Collection<String> groupNames) {
public boolean removeGroups(OfflinePlayer player, Collection<String> groupNames) {
// If no permissions system is used, return false
if (!isEnabled()) {
return false;
@ -377,7 +377,7 @@ public class PermissionsManager implements Reloadable {
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean setGroup(Player player, String groupName) {
public boolean setGroup(OfflinePlayer player, String groupName) {
return isEnabled() && handler.setGroup(player, groupName);
}
@ -391,7 +391,7 @@ public class PermissionsManager implements Reloadable {
* @return True if succeed, false otherwise.
* False will also be returned if this feature isn't supported for the used permissions system.
*/
public boolean removeAllGroups(Player player) {
public boolean removeAllGroups(OfflinePlayer player) {
// If no permissions system is used, return false
if (!isEnabled()) {
return false;

View File

@ -4,7 +4,7 @@ import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.CalculableType;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType;
import org.bukkit.entity.Player;
import org.bukkit.OfflinePlayer;
import java.util.Arrays;
import java.util.List;
@ -18,8 +18,8 @@ import java.util.List;
public class BPermissionsHandler implements PermissionHandler {
@Override
public boolean addToGroup(Player player, String group) {
ApiLayer.addGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
public boolean addToGroup(OfflinePlayer player, String group) {
ApiLayer.addGroup(null, CalculableType.USER, player.getName(), group);
return true;
}
@ -34,25 +34,25 @@ public class BPermissionsHandler implements PermissionHandler {
}
@Override
public boolean isInGroup(Player player, String group) {
return ApiLayer.hasGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
public boolean isInGroup(OfflinePlayer player, String group) {
return ApiLayer.hasGroup(null, CalculableType.USER, player.getName(), group);
}
@Override
public boolean removeFromGroup(Player player, String group) {
ApiLayer.removeGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
public boolean removeFromGroup(OfflinePlayer player, String group) {
ApiLayer.removeGroup(null, CalculableType.USER, player.getName(), group);
return true;
}
@Override
public boolean setGroup(Player player, String group) {
ApiLayer.setGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
public boolean setGroup(OfflinePlayer player, String group) {
ApiLayer.setGroup(null, CalculableType.USER, player.getName(), group);
return true;
}
@Override
public List<String> getGroups(Player player) {
return Arrays.asList(ApiLayer.getGroups(player.getWorld().getName(), CalculableType.USER, player.getName()));
public List<String> getGroups(OfflinePlayer player) {
return Arrays.asList(ApiLayer.getGroups(null, CalculableType.USER, player.getName()));
}
@Override

View File

@ -3,6 +3,7 @@ package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType;
import fr.xephi.authme.util.Utils;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.Collection;
@ -19,7 +20,7 @@ public interface PermissionHandler {
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
boolean addToGroup(Player player, String group);
boolean addToGroup(OfflinePlayer player, String group);
/**
* Check whether the current permissions system has group support.
@ -49,7 +50,7 @@ public interface PermissionHandler {
* @return True if the player is in the specified group, false otherwise.
* False is also returned if groups aren't supported by the used permissions system.
*/
default boolean isInGroup(Player player, String group) {
default boolean isInGroup(OfflinePlayer player, String group) {
return getGroups(player).contains(group);
}
@ -62,7 +63,7 @@ public interface PermissionHandler {
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
boolean removeFromGroup(Player player, String group);
boolean removeFromGroup(OfflinePlayer player, String group);
/**
* Set the permission group of a player, if supported.
@ -74,7 +75,7 @@ public interface PermissionHandler {
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
boolean setGroup(Player player, String group);
boolean setGroup(OfflinePlayer player, String group);
/**
* Get the permission groups of a player, if available.
@ -83,7 +84,7 @@ public interface PermissionHandler {
*
* @return Permission groups, or an empty list if this feature is not supported.
*/
Collection<String> getGroups(Player player);
Collection<String> getGroups(OfflinePlayer player);
/**
* Get the primary group of a player, if available.
@ -92,7 +93,7 @@ public interface PermissionHandler {
*
* @return The name of the primary permission group. Or null.
*/
default String getPrimaryGroup(Player player) {
default String getPrimaryGroup(OfflinePlayer player) {
Collection<String> groups = getGroups(player);
if (Utils.isCollectionEmpty(groups)) {
return null;

View File

@ -2,6 +2,7 @@ package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.PermissionUser;
@ -28,12 +29,12 @@ public class PermissionsExHandler implements PermissionHandler {
}
@Override
public boolean addToGroup(Player player, String group) {
public boolean addToGroup(OfflinePlayer player, String group) {
if (!PermissionsEx.getPermissionManager().getGroupNames().contains(group)) {
return false;
}
PermissionUser user = PermissionsEx.getUser(player);
PermissionUser user = PermissionsEx.getUser(player.getName());
user.addGroup(group);
return true;
}
@ -50,31 +51,31 @@ public class PermissionsExHandler implements PermissionHandler {
}
@Override
public boolean isInGroup(Player player, String group) {
PermissionUser user = permissionManager.getUser(player);
public boolean isInGroup(OfflinePlayer player, String group) {
PermissionUser user = permissionManager.getUser(player.getName());
return user.inGroup(group);
}
@Override
public boolean removeFromGroup(Player player, String group) {
PermissionUser user = permissionManager.getUser(player);
public boolean removeFromGroup(OfflinePlayer player, String group) {
PermissionUser user = permissionManager.getUser(player.getName());
user.removeGroup(group);
return true;
}
@Override
public boolean setGroup(Player player, String group) {
public boolean setGroup(OfflinePlayer player, String group) {
List<String> groups = new ArrayList<>();
groups.add(group);
PermissionUser user = permissionManager.getUser(player);
PermissionUser user = permissionManager.getUser(player.getName());
user.setParentsIdentifier(groups);
return true;
}
@Override
public List<String> getGroups(Player player) {
PermissionUser user = permissionManager.getUser(player);
public List<String> getGroups(OfflinePlayer player) {
PermissionUser user = permissionManager.getUser(player.getName());
return user.getParentIdentifiers(null);
}

View File

@ -3,8 +3,8 @@ package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.Arrays;
@ -41,7 +41,7 @@ public class VaultHandler implements PermissionHandler {
}
@Override
public boolean addToGroup(Player player, String group) {
public boolean addToGroup(OfflinePlayer player, String group) {
return vaultProvider.playerAddGroup(null, player, group);
}
@ -56,17 +56,17 @@ public class VaultHandler implements PermissionHandler {
}
@Override
public boolean isInGroup(Player player, String group) {
public boolean isInGroup(OfflinePlayer player, String group) {
return vaultProvider.playerInGroup(null, player, group);
}
@Override
public boolean removeFromGroup(Player player, String group) {
public boolean removeFromGroup(OfflinePlayer player, String group) {
return vaultProvider.playerRemoveGroup(null, player, group);
}
@Override
public boolean setGroup(Player player, String group) {
public boolean setGroup(OfflinePlayer player, String group) {
for (String groupName : getGroups(player)) {
removeFromGroup(player, groupName);
}
@ -75,12 +75,12 @@ public class VaultHandler implements PermissionHandler {
}
@Override
public List<String> getGroups(Player player) {
public List<String> getGroups(OfflinePlayer player) {
return Arrays.asList(vaultProvider.getPlayerGroups(null, player));
}
@Override
public String getPrimaryGroup(Player player) {
public String getPrimaryGroup(OfflinePlayer player) {
return vaultProvider.getPrimaryGroup(null, player);
}

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.OfflinePlayer;
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
import java.util.Collection;
@ -29,7 +29,7 @@ public class ZPermissionsHandler implements PermissionHandler {
}
@Override
public boolean addToGroup(Player player, String group) {
public boolean addToGroup(OfflinePlayer player, String group) {
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
"permissions player " + player.getName() + " addgroup " + group);
}
@ -42,34 +42,28 @@ public class ZPermissionsHandler implements PermissionHandler {
@Override
public boolean hasPermissionOffline(String name, PermissionNode node) {
Map<String, Boolean> perms = zPermissionsService.getPlayerPermissions(null, null, name);
if (perms.containsKey(node.getNode())) {
return perms.get(node.getNode());
} else {
return false;
}
return perms.getOrDefault(node.getNode(), false);
}
@Override
public boolean removeFromGroup(Player player, String group) {
public boolean removeFromGroup(OfflinePlayer player, String group) {
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
"permissions player " + player.getName() + " removegroup " + group);
}
@Override
public boolean setGroup(Player player, String group) {
public boolean setGroup(OfflinePlayer player, String group) {
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
"permissions player " + player.getName() + " setgroup " + group);
}
@Override
public Collection<String> getGroups(Player player) {
// TODO Gnat008 20160631: Use UUID not name?
public Collection<String> getGroups(OfflinePlayer player) {
return zPermissionsService.getPlayerGroups(player.getName());
}
@Override
public String getPrimaryGroup(Player player) {
// TODO Gnat008 20160631: Use UUID not name?
public String getPrimaryGroup(OfflinePlayer player) {
return zPermissionsService.getPlayerPrimaryGroup(player.getName());
}

View File

@ -191,15 +191,13 @@ public class PurgeExecutor {
ConsoleLogger.info("AutoPurge: Removed " + deletedFiles + " EssentialsFiles");
}
// TODO #676: What is this method for? Is it correct?
synchronized void purgePermissions(Collection<OfflinePlayer> cleared) {
if (!settings.getProperty(PurgeSettings.REMOVE_PERMISSIONS)) {
return;
}
for (OfflinePlayer offlinePlayer : cleared) {
String name = offlinePlayer.getName();
permissionsManager.removeAllGroups(bukkitService.getPlayerExact(name));
permissionsManager.removeAllGroups(offlinePlayer);
}
ConsoleLogger.info("AutoPurge: Removed permissions from " + cleared.size() + " player(s).");