flan/fabric/src/main/java/io/github/flemmli97/flan/fabric/platform/integration/permissions/PermissionNodeHandlerImpl.java

51 lines
1.8 KiB
Java
Raw Normal View History

2022-02-27 16:25:31 +00:00
package io.github.flemmli97.flan.fabric.platform.integration.permissions;
2021-07-20 22:27:08 +00:00
2021-12-05 12:21:22 +00:00
import io.github.flemmli97.flan.Flan;
2021-07-20 22:27:08 +00:00
import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.platform.integration.permissions.PermissionNodeHandler;
2022-08-03 20:50:16 +00:00
import me.lucko.fabric.api.permissions.v0.Options;
2021-12-05 12:21:22 +00:00
import me.lucko.fabric.api.permissions.v0.Permissions;
2021-12-03 21:37:35 +00:00
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;
2021-07-20 22:27:08 +00:00
2022-02-27 16:25:31 +00:00
public class PermissionNodeHandlerImpl implements PermissionNodeHandler {
@Override
public boolean perm(CommandSourceStack src, String perm, boolean adminCmd) {
2021-12-05 12:21:22 +00:00
if (Flan.permissionAPI) {
2021-07-20 22:27:08 +00:00
if (adminCmd)
return Permissions.check(src, perm, ConfigHandler.config.permissionLevel);
return Permissions.check(src, perm, true);
}
2021-12-03 21:37:35 +00:00
return !adminCmd || src.hasPermission(ConfigHandler.config.permissionLevel);
2021-07-20 22:27:08 +00:00
}
@Override
public boolean perm(ServerPlayer src, String perm, boolean adminCmd) {
2021-12-05 12:21:22 +00:00
if (Flan.permissionAPI) {
2021-07-20 22:27:08 +00:00
if (adminCmd)
return Permissions.check(src, perm, ConfigHandler.config.permissionLevel);
return Permissions.check(src, perm, true);
}
2021-12-03 21:37:35 +00:00
return !adminCmd || src.hasPermissions(ConfigHandler.config.permissionLevel);
2021-07-20 22:27:08 +00:00
}
2022-11-24 14:20:11 +00:00
@Override
public boolean permBelowEqVal(ServerPlayer src, String perm, int val, int fallback) {
2022-08-03 20:50:16 +00:00
if (Flan.permissionAPI) {
int max = Options.get(src, perm, fallback, Integer::parseInt);
return val <= max;
}
2021-07-30 17:56:12 +00:00
return val <= fallback;
2021-07-20 22:27:08 +00:00
}
2022-11-24 14:20:11 +00:00
@Override
public int permVal(ServerPlayer src, String perm, int fallback) {
if (Flan.permissionAPI) {
return Options.get(src, perm, fallback, Integer::parseInt);
}
return fallback;
}
2021-07-20 22:27:08 +00:00
}