Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.1 LuckPerms support #71

Open
MJRamon opened this issue Jul 2, 2024 · 1 comment
Open

1.20.1 LuckPerms support #71

MJRamon opened this issue Jul 2, 2024 · 1 comment

Comments

@MJRamon
Copy link

MJRamon commented Jul 2, 2024

Does it support LuckPerms? If not, can you add support for it? Thank you.

@JustusJG
Copy link

I've made a LuckPerms support but it's for 1.21. Maybe it works in 1.20.1 too. It's not perfect, it works for me.

diff --git a/build.gradle b/build.gradle
index ca86766..b616c53 100644
--- a/build.gradle
+++ b/build.gradle
@@ -9,10 +9,10 @@ version = project.mod_version + "+" + project.minecraft_version
 group = project.maven_group
 
 repositories {
+  mavenCentral()
   maven { url = "https://maven.nucleoid.xyz" }
   maven { url = "https://maven.gegy.dev/" }
   maven { url = "https://jitpack.io" }
   maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
 }
 
 dependencies {
@@ -26,6 +26,8 @@ dependencies {
 
   modCompileOnly "dev.gegy:player-roles-api:1.6.8"
   modCompileOnly "me.lucko:fabric-permissions-api:0.2-SNAPSHOT"
+
+  compileOnly 'net.luckperms:api:5.4'
 }
 
 processResources {
diff --git a/src/main/java/xyz/nucleoid/leukocyte/roles/RoleAccessor.java b/src/main/java/xyz/nucleoid/leukocyte/roles/RoleAccessor.java
index 62d2703..5e58843 100644
--- a/src/main/java/xyz/nucleoid/leukocyte/roles/RoleAccessor.java
+++ b/src/main/java/xyz/nucleoid/leukocyte/roles/RoleAccessor.java
@@ -3,12 +3,18 @@ package xyz.nucleoid.leukocyte.roles;
 import dev.gegy.roles.api.PlayerRolesApi;
 import dev.gegy.roles.api.Role;
 import net.fabricmc.loader.api.FabricLoader;
+import net.luckperms.api.LuckPerms;
+import net.luckperms.api.LuckPermsProvider;
+import net.luckperms.api.model.group.Group;
 import net.minecraft.server.network.ServerPlayerEntity;
 
+import java.util.Collection;
+import java.util.Comparator;
 import java.util.stream.Stream;
 
 public interface RoleAccessor {
-    RoleAccessor INSTANCE = FabricLoader.getInstance().isModLoaded("player_roles") ? new PlayerRoles() : new None();
+    RoleAccessor INSTANCE = FabricLoader.getInstance().isModLoaded("player_roles") ? new PlayerRoles() :
+            FabricLoader.getInstance().isModLoaded("luckperms") ? new LPGroups() : new None();
 
     Stream<String> getAllRoles();
 
@@ -48,4 +54,23 @@ public interface RoleAccessor {
             }
         }
     }
+
+    final class LPGroups implements RoleAccessor {
+        LPGroups() {
+        }
+
+        @Override
+        public Stream<String> getAllRoles() {
+            Collection<Group> groups = LuckPermsProvider.get().getGroupManager().getLoadedGroups();
+
+            return groups.stream()
+                    .sorted(Comparator.comparingInt(group -> group.getWeight().orElse(0)))
+                    .map(Group::getName);
+        }
+
+        @Override
+        public boolean hasRole(ServerPlayerEntity player, String roleId) {
+            return PermissionAccessor.INSTANCE.hasPermission(player, "group." + roleId);
+        }
+    }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants