refactor: use fabric-permission-api for better compatibility
This commit is contained in:
3 files changed
+6
-22
No files matched your search
+1
-1
@@ -26,7 +26,7 @@ dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
modImplementation 'me.lucko:fabric-permissions-api:0.3.1'
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
shadow('com.maxmind.geoip2:geoip2:4.2.0')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ib67.sfcraft.util;
|
||||
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -21,28 +22,10 @@ public record Permission<T extends Entity>(String key, boolean byDefault) {
|
||||
}
|
||||
|
||||
public boolean hasPermission(T t) {
|
||||
if (t.getCommandTags().contains(SFConsts.SPECIAL_SUDO)) return true;
|
||||
if (Permissions.check(t, SFConsts.SPECIAL_SUDO)) return true;
|
||||
if (byDefault) {
|
||||
return !t.getCommandTags().contains("-" + key);
|
||||
}
|
||||
return t.getCommandTags().contains(key);
|
||||
}
|
||||
|
||||
public void grant(T t) {
|
||||
if (!hasPermission(t)) {
|
||||
t.getCommandTags().remove("-" + key);
|
||||
if (!byDefault) {
|
||||
t.addCommandTag(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void revoke(T t) {
|
||||
if (hasPermission(t)) {
|
||||
t.removeCommandTag(key);
|
||||
if (byDefault) {
|
||||
t.addCommandTag("-" + key);
|
||||
}
|
||||
return !Permissions.check(t, "-"+key);
|
||||
}
|
||||
return Permissions.check(t, key);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
"sfcraft.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabric-permissions-api-v0": "*",
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric": "*",
|
||||
"minecraft": "${minecraft_version}"
|
||||
|
||||
Reference in new issue
Block a user