Merge pull request #2670 from SijmenSchoon/v3.0

Update LuckPerms and bStats
This commit is contained in:
mikeprimm 2019-12-14 13:38:29 -06:00 committed by GitHub
commit e14179bff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 49 deletions

View File

@ -19,7 +19,7 @@ allprojects {
apply plugin: 'java'
group = 'us.dynmap'
version = '3.0-beta-6'
version = '3.0-beta-7'
}

View File

@ -4,7 +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 'net.luckperms:api:5.0'
compile project(":dynmap-api")
compile project(path: ":DynmapCore", configuration: "shadow")
compile group: 'ru.tehkode', name: 'PermissionsEx', version:'1.19.1'

View File

@ -16,7 +16,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.bstats.Metrics;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@ -1584,21 +1584,18 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
private void initMetrics() {
metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.MultiLineChart("features_used") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> hashMap) {
metrics.addCustomChart(new Metrics.MultiLineChart("features_used", () -> {
Map<String, Integer> hashMap = new HashMap<>();
hashMap.put("internal_web_server", core.configuration.getBoolean("disable-webserver", false) ? 0 : 1);
hashMap.put("login_security", core.configuration.getBoolean("login-enabled", false) ? 1 : 0);
hashMap.put("player_info_protected", core.player_info_protected ? 1 : 0);
for (String mod : modsused)
hashMap.put(mod + "_blocks", 1);
return hashMap;
}
});
}));
metrics.addCustomChart(new Metrics.MultiLineChart("map_data") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> hashMap) {
metrics.addCustomChart(new Metrics.MultiLineChart("map_data", () -> {
Map<String, Integer> hashMap = new HashMap<>();
hashMap.put("worlds", core.mapManager != null ? core.mapManager.getWorlds().size() : 0);
int maps = 0, hdmaps = 0;
if (core.mapManager != null)
@ -1611,8 +1608,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
hashMap.put("maps", maps);
hashMap.put("hd_maps", hdmaps);
return hashMap;
}
});
}));
}
@Override
public void processSignChange(int blkid, String world, int x, int y, int z,

View File

@ -6,9 +6,12 @@ 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 net.luckperms.api.LuckPerms;
import net.luckperms.api.model.user.User;
import net.luckperms.api.model.user.UserManager;
import net.luckperms.api.cacheddata.CachedPermissionData;
import net.luckperms.api.cacheddata.CachedDataManager;
import net.luckperms.api.query.QueryOptions;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -18,19 +21,19 @@ import org.dynmap.Log;
public class LuckPermsPermissions implements PermissionProvider {
String name;
LuckPermsApi luckPerms;
LuckPerms luckPerms;
public static LuckPermsPermissions create(Server server, String name) {
if (!server.getPluginManager().isPluginEnabled("LuckPerms"))
return null;
LuckPermsApi luckPerms = server.getServicesManager().load(LuckPermsApi.class);
LuckPerms luckPerms = server.getServicesManager().load(LuckPerms.class);
if (luckPerms == null)
return null;
Log.info("Using LuckPerms " + luckPerms.getPlatformInfo().getVersion() + " for access control");
Log.info("Using LuckPerms " + luckPerms.getPluginMetadata().getVersion() + " for access control");
return new LuckPermsPermissions(name, luckPerms);
}
public LuckPermsPermissions(String name, LuckPermsApi luckPerms) {
public LuckPermsPermissions(String name, LuckPerms luckPerms) {
this.name = name;
this.luckPerms = luckPerms;
}
@ -43,10 +46,10 @@ public class LuckPermsPermissions implements PermissionProvider {
@Override
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
Set<String> result = new HashSet<>();
PermissionData user = getUser(player);
CachedPermissionData user = getUser(player);
if (user != null) {
for (String p : perms) {
if (user.getPermissionValue(name + "." + p).asBoolean())
if (user.checkPermission(name + "." + p).asBoolean())
result.add(p);
}
}
@ -55,34 +58,39 @@ public class LuckPermsPermissions implements PermissionProvider {
@Override
public boolean hasOfflinePermission(String player, String perm) {
PermissionData user = getUser(player);
CachedPermissionData user = getUser(player);
if (user == null)
return false;
return user.getPermissionValue(name + "." + perm).asBoolean();
return user.checkPermission(name + "." + perm).asBoolean();
}
private PermissionData getUser(String username) {
private CachedPermissionData 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));
uuid = joinFuture(luckPerms.getUserManager().lookupUniqueId(username));
if (uuid == null)
return null;
User user = luckPerms.getUser(uuid);
User user = luckPerms.getUserManager().getUser(uuid);
if (user == null) {
joinFuture(luckPerms.getStorage().loadUser(uuid));
user = luckPerms.getUser(uuid);
joinFuture(luckPerms.getUserManager().loadUser(uuid));
user = luckPerms.getUserManager().getUser(uuid);
}
if (user == null)
return null;
return user.getCachedData().getPermissionData(luckPerms.getContextManager().getStaticContexts());
CachedDataManager data = user.getCachedData();
return luckPerms
.getContextManager()
.getQueryOptions(user)
.map(queryOptions -> data.getPermissionData(queryOptions))
.orElse(null);
}
private static <T> T joinFuture(Future<T> future) {