mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 05:05:16 +01:00
Add player permissions check API
This commit is contained in:
parent
faa1948225
commit
8f9d2c01c2
@ -276,6 +276,20 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<String> checkPlayerPermissions(String player, Set<String> perms) {
|
||||
OfflinePlayer p = getServer().getOfflinePlayer(player);
|
||||
if(p.isBanned())
|
||||
return new HashSet<String>();
|
||||
Set<String> rslt = permissions.hasOfflinePermissions(player, perms);
|
||||
if (rslt == null) {
|
||||
rslt = new HashSet<String>();
|
||||
if(p.isOp()) {
|
||||
rslt.addAll(perms);
|
||||
}
|
||||
}
|
||||
return rslt;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Player access abstraction class
|
||||
|
@ -1,5 +1,10 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.dynmap.Log;
|
||||
@ -28,4 +33,19 @@ public class BukkitPermissions implements PermissionProvider {
|
||||
? player.hasPermission(name + "." + permission) || player.hasPermission(name + ".*")
|
||||
: true;
|
||||
}
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
Player p = Bukkit.getPlayerExact(name);
|
||||
HashSet<String> hasperms = null;
|
||||
if (p != null) {
|
||||
hasperms = new HashSet<String>();
|
||||
for(String perm : perms) {
|
||||
if (p.hasPermission(perm)) {
|
||||
hasperms.add(perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -38,4 +42,19 @@ public class NijikokunPermissions implements PermissionProvider {
|
||||
? permissions.has(player, name + "." + permission) || permissions.has(player, name + ".*")
|
||||
: true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
HashSet<String> hasperms = null;
|
||||
Player plyr = Bukkit.getPlayerExact(player);
|
||||
if(plyr != null) {
|
||||
hasperms = new HashSet<String>();
|
||||
for (String pp : perms) {
|
||||
if (permissions.has(plyr, pp)) {
|
||||
hasperms.add(pp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -24,4 +25,8 @@ public class OpPermissions implements PermissionProvider {
|
||||
: true
|
||||
: true;
|
||||
}
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -7,6 +10,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.Log;
|
||||
|
||||
import ru.tehkode.permissions.PermissionManager;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
public class PEXPermissions implements PermissionProvider {
|
||||
@ -34,4 +38,18 @@ public class PEXPermissions implements PermissionProvider {
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
return (player != null) ? pm.has(player, name + "." + permission) : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
HashSet<String> hasperms = new HashSet<String>();
|
||||
PermissionUser pu = pm.getUser(player);
|
||||
if(pu != null) {
|
||||
for (String pp : perms) {
|
||||
if (pu.has(pp)) {
|
||||
hasperms.add(pp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -9,6 +13,10 @@ import org.dynmap.Log;
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||
|
||||
import de.bananaco.bpermissions.api.ApiLayer;
|
||||
import de.bananaco.bpermissions.api.util.CalculableType;
|
||||
import de.bananaco.bpermissions.api.util.Permission;
|
||||
|
||||
public class PermBukkitPermissions implements PermissionProvider {
|
||||
String name;
|
||||
PermissionsPlugin plugin;
|
||||
@ -33,4 +41,17 @@ public class PermBukkitPermissions implements PermissionProvider {
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
return (player != null) ? plugin.getPlayerInfo(player.getName()).getPermissions().containsKey(name + "." + permission) : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
Map<String, Boolean> prm = plugin.getPlayerInfo(player).getPermissions();
|
||||
HashSet<String> hasperms = new HashSet<String>();
|
||||
for (String pp : perms) {
|
||||
Boolean pb = prm.get(pp);
|
||||
if ((pb != null) && pb.booleanValue()) {
|
||||
hasperms.add(pp);
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface PermissionProvider {
|
||||
boolean has(CommandSender sender, String permission);
|
||||
|
||||
Set<String> hasOfflinePermissions(String player, Set<String> perms);
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -10,9 +14,11 @@ import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
import de.bananaco.bpermissions.api.ApiLayer;
|
||||
import de.bananaco.bpermissions.api.util.CalculableType;
|
||||
import de.bananaco.bpermissions.api.util.Permission;
|
||||
|
||||
public class bPermPermissions implements PermissionProvider {
|
||||
String name;
|
||||
String defworld;
|
||||
|
||||
public static bPermPermissions create(Server server, String name) {
|
||||
Plugin permissionsPlugin = server.getPluginManager().getPlugin("bPermissions");
|
||||
@ -25,11 +31,25 @@ public class bPermPermissions implements PermissionProvider {
|
||||
|
||||
public bPermPermissions(String name) {
|
||||
this.name = name;
|
||||
defworld = Bukkit.getServer().getWorlds().get(0).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(CommandSender sender, String permission) {
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
return (player != null) ? ApiLayer.hasPermission(player.getWorld().getName(), CalculableType.USER, player.getName(), name + "." + permission) : true;
|
||||
return (player != null) ? ApiLayer.hasPermission(defworld, CalculableType.USER, player.getName(), name + "." + permission) : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
Permission[] p = ApiLayer.getPermissions(defworld, CalculableType.USER, player);
|
||||
HashSet<String> hasperms = new HashSet<String>();
|
||||
for (int i = 0; i < p.length; i++) {
|
||||
if (p[i].isTrue() && perms.contains(p[i].name())) {
|
||||
hasperms.add(p[i].name());
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user