From 1653ceb5fe15387808d63b0ece73df5e742b3d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bro=C4=8Dko?= Date: Sun, 9 Sep 2018 19:14:49 +0200 Subject: [PATCH] LuckPerms dependency --- .classpath | 4 ++- pom.xml | 14 ++++++++ resources/plugin.yml | 7 ++-- src/cz/marwland/mc/core/util/UserUtil.java | 40 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 src/cz/marwland/mc/core/util/UserUtil.java diff --git a/.classpath b/.classpath index b866b22..1c7a2a9 100644 --- a/.classpath +++ b/.classpath @@ -12,7 +12,7 @@ - + @@ -25,4 +25,6 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9b143a6..91a1e96 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,20 @@ 6.2 provided + + com.massivecraft.massivecore + MassiveCore + 2.14.1-SNAPSHOT + system + /home/erik/Dokumenty/Java/marwland/res/MassiveCore.jar + + + com.massivecraft.factions + Factions + 2.14.1-SNAPSHOT + system + /home/erik/Dokumenty/Java/marwland/res/Factions.jar + diff --git a/resources/plugin.yml b/resources/plugin.yml index 014be65..a8fd570 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -4,8 +4,5 @@ version: 0.0.1 api-version: 1.12 author: ericek111 website: https://git.lixko.eu/MarwLand/MarwCore -softdepend: [WorldGuard] -commands: - first: - description: First command. - usage: /first \ No newline at end of file +depend: [LuckPerms] +softdepend: [WorldGuard, Factions] diff --git a/src/cz/marwland/mc/core/util/UserUtil.java b/src/cz/marwland/mc/core/util/UserUtil.java new file mode 100644 index 0000000..22c5381 --- /dev/null +++ b/src/cz/marwland/mc/core/util/UserUtil.java @@ -0,0 +1,40 @@ +package cz.marwland.mc.core.util; + +import org.bukkit.entity.Player; + +import me.lucko.luckperms.LuckPerms; +import me.lucko.luckperms.api.Contexts; +import me.lucko.luckperms.api.LuckPermsApi; +import me.lucko.luckperms.api.User; +import me.lucko.luckperms.api.caching.MetaData; +import me.lucko.luckperms.api.caching.PermissionData; +import me.lucko.luckperms.api.context.ImmutableContextSet; + +public class UserUtil { + + private static final LuckPermsApi api = LuckPerms.getApi(); + + public static User getOnlineUser(Player p) { + if (!p.isOnline()) { + throw new IllegalStateException("Player is offline"); + } + return api.getUserManager().getUser(p.getUniqueId()); + } + + public static Contexts getPlayersContexts(Player p) { + //ImmutableContextSet contextSet = api.getContextManager().getApplicableContext(p); + Contexts contexts = api.getContextManager().getApplicableContexts(p); + return contexts; + } + + public static String getPlayersMeta(Player player, String key, String defaultValue) { + User user = getOnlineUser(player); + MetaData metaData = user.getCachedData().getMetaData(getPlayersContexts(player)); + return metaData.getMeta().getOrDefault(key, defaultValue); + } + + public static String getPlayersMeta(Player player, String key) { + return getPlayersMeta(player, key, null); + } + +}