From 9e7174dcdea52746503c0f2c907359975c6e9feb Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Sun, 1 Dec 2019 03:38:05 +0100 Subject: [PATCH] Update LuckPerms and bStats --- build.gradle | 2 +- spigot/build.gradle | 4 +- .../java/org/dynmap/bukkit/DynmapPlugin.java | 54 +++++++++---------- .../permissions/LuckPermsPermissions.java | 44 ++++++++------- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/build.gradle b/build.gradle index a1e9a0e3..92bbd828 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ allprojects { maven { url "http://repo.mikeprimm.com" } maven { url "http://repo.maven.apache.org/maven2" } maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" } - maven { url "http://repo.bstats.org/content/repositories/releases/" } + maven { url "https://repo.codemc.org/repository/maven-public/" } } apply plugin: 'java' diff --git a/spigot/build.gradle b/spigot/build.gradle index 121ff590..bc4b7994 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -4,14 +4,14 @@ 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' compile group: 'de.bananaco', name: 'bPermissions', version:'2.9.1' compile group: 'com.platymuus.bukkit.permissions', name: 'PermissionsBukkit', version:'1.6' compile group: 'org.anjocaido', name: 'EssentialsGroupManager', version:'2.10.1' - compile group: 'org.bstats', name: 'bstats-bukkit', version:'1.1' + compile group: 'org.bstats', name: 'bstats-bukkit', version:'1.5' compile group: 'com.googlecode.json-simple', name: 'json-simple', version:'1.1.1' compile group: 'com.google.code.gson', name: 'gson', version:'2.8.2' compile project(':bukkit-helper') diff --git a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index be7e73e1..d36e6484 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -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; @@ -1585,35 +1585,31 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { private void initMetrics() { metrics = new Metrics(this); - metrics.addCustomChart(new Metrics.MultiLineChart("features_used") { - @Override - public HashMap getValues(HashMap 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("features_used", () -> { + Map 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 getValues(HashMap hashMap) { - hashMap.put("worlds", core.mapManager != null ? core.mapManager.getWorlds().size() : 0); - int maps = 0, hdmaps = 0; - if (core.mapManager != null) - for (DynmapWorld w : core.mapManager.getWorlds()) { - for (MapType mt : w.maps) - if (mt instanceof HDMap) - ++hdmaps; - maps += w.maps.size(); - } - hashMap.put("maps", maps); - hashMap.put("hd_maps", hdmaps); - return hashMap; - } - }); + metrics.addCustomChart(new Metrics.MultiLineChart("map_data", () -> { + Map hashMap = new HashMap<>(); + hashMap.put("worlds", core.mapManager != null ? core.mapManager.getWorlds().size() : 0); + int maps = 0, hdmaps = 0; + if (core.mapManager != null) + for (DynmapWorld w : core.mapManager.getWorlds()) { + for (MapType mt : w.maps) + if (mt instanceof HDMap) + ++hdmaps; + maps += w.maps.size(); + } + 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, diff --git a/spigot/src/main/java/org/dynmap/bukkit/permissions/LuckPermsPermissions.java b/spigot/src/main/java/org/dynmap/bukkit/permissions/LuckPermsPermissions.java index 7ab582b2..f0848a7e 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/permissions/LuckPermsPermissions.java +++ b/spigot/src/main/java/org/dynmap/bukkit/permissions/LuckPermsPermissions.java @@ -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 hasOfflinePermissions(String player, Set perms) { Set 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 joinFuture(Future future) { @@ -92,4 +100,4 @@ public class LuckPermsPermissions implements PermissionProvider { throw new RuntimeException(e); } } -} \ No newline at end of file +}