mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 10:07:37 +01:00
Merge branch 'v3.0' of https://github.com/webbukkit/dynmap.git into v3.0
This commit is contained in:
commit
dd07037da3
@ -4,6 +4,7 @@ description = 'dynmap'
|
||||
dependencies {
|
||||
compile group: 'org.bukkit', name: 'bukkit', version:'1.7.10-R0.1-SNAPSHOT'
|
||||
compile 'com.nijikokun.bukkit:Permissions:3.1.6'
|
||||
compile 'me.lucko.luckperms:luckperms-api:4.3'
|
||||
compile project(":dynmap-api")
|
||||
compile project(path: ":DynmapCore", configuration: "shadow")
|
||||
compile group: 'ru.tehkode', name: 'PermissionsEx', version:'1.19.1'
|
||||
|
@ -89,6 +89,7 @@ import org.dynmap.bukkit.permissions.PermBukkitPermissions;
|
||||
import org.dynmap.bukkit.permissions.GroupManagerPermissions;
|
||||
import org.dynmap.bukkit.permissions.PermissionProvider;
|
||||
import org.dynmap.bukkit.permissions.bPermPermissions;
|
||||
import org.dynmap.bukkit.permissions.LuckPermsPermissions;
|
||||
import org.dynmap.common.BiomeMap;
|
||||
import org.dynmap.common.DynmapCommandSender;
|
||||
import org.dynmap.common.DynmapPlayer;
|
||||
@ -827,6 +828,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
permissions = NijikokunPermissions.create(getServer(), "dynmap");
|
||||
if (permissions == null)
|
||||
permissions = GroupManagerPermissions.create(getServer(), "dynmap");
|
||||
if (permissions == null)
|
||||
permissions = LuckPermsPermissions.create(getServer(), "dynmap");
|
||||
if (permissions == null)
|
||||
permissions = BukkitPermissions.create("dynmap", perdefs);
|
||||
if (permissions == null)
|
||||
|
@ -0,0 +1,95 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.caching.PermissionData;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.dynmap.Log;
|
||||
|
||||
public class LuckPermsPermissions implements PermissionProvider {
|
||||
String name;
|
||||
LuckPermsApi luckPerms;
|
||||
|
||||
public static LuckPermsPermissions create(Server server, String name) {
|
||||
if (!server.getPluginManager().isPluginEnabled("LuckPerms"))
|
||||
return null;
|
||||
LuckPermsApi luckPerms = server.getServicesManager().load(LuckPermsApi.class);
|
||||
if (luckPerms == null)
|
||||
return null;
|
||||
Log.info("Using LuckPerms " + luckPerms.getPlatformInfo().getVersion() + " for access control");
|
||||
return new LuckPermsPermissions(name, luckPerms);
|
||||
}
|
||||
|
||||
public LuckPermsPermissions(String name, LuckPermsApi luckPerms) {
|
||||
this.name = name;
|
||||
this.luckPerms = luckPerms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(CommandSender sender, String permission) {
|
||||
return sender.hasPermission(name + "." + permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
Set<String> result = new HashSet<>();
|
||||
PermissionData user = getUser(player);
|
||||
if (user != null) {
|
||||
for (String p : perms) {
|
||||
if (user.getPermissionValue(name + "." + p).asBoolean())
|
||||
result.add(p);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOfflinePermission(String player, String perm) {
|
||||
PermissionData user = getUser(player);
|
||||
if (user == null)
|
||||
return false;
|
||||
return user.getPermissionValue(name + "." + perm).asBoolean();
|
||||
}
|
||||
|
||||
private PermissionData getUser(String username) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
|
||||
UUID uuid;
|
||||
|
||||
if (offlinePlayer != null && offlinePlayer.getUniqueId() != null)
|
||||
uuid = offlinePlayer.getUniqueId();
|
||||
else
|
||||
uuid = joinFuture(luckPerms.getStorage().getUUID(username));
|
||||
|
||||
if (uuid == null)
|
||||
return null;
|
||||
|
||||
User user = luckPerms.getUser(uuid);
|
||||
if (user == null) {
|
||||
joinFuture(luckPerms.getStorage().loadUser(uuid));
|
||||
user = luckPerms.getUser(uuid);
|
||||
}
|
||||
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
return user.getCachedData().getPermissionData(luckPerms.getContextManager().getStaticContexts());
|
||||
}
|
||||
|
||||
private static <T> T joinFuture(Future<T> future) {
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ main: org.dynmap.bukkit.DynmapPlugin
|
||||
version: "${version}-${buildnumber}"
|
||||
authors: [mikeprimm]
|
||||
website: "https://forums.dynmap.us"
|
||||
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit, GroupManager ]
|
||||
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit, GroupManager, LuckPerm ]
|
||||
commands:
|
||||
dynmap:
|
||||
description: Controls Dynmap.
|
||||
|
Loading…
Reference in New Issue
Block a user