Add optional support for fabric-permissions-api

This commit is contained in:
Lukas Rieger (Blue) 2022-01-16 14:23:04 +01:00
parent 3f049d0523
commit 407c9586ec
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
5 changed files with 47 additions and 25 deletions

View File

@ -24,19 +24,19 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.IOException;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
import de.bluecolored.bluemap.core.world.World;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import java.io.IOException;
import java.util.Optional;
public class FabricCommandSource implements CommandSource {
private FabricMod mod;
@ -56,7 +56,12 @@ public void sendMessage(Text text) {
@Override
public boolean hasPermission(String permission) {
return delegate.hasPermissionLevel(1);
try {
Class.forName("me.lucko.fabric.api.permissions.v0.Permissions");
return Permissions.check(delegate, permission, 1);
} catch (ClassNotFoundException ex) {
return delegate.hasPermissionLevel(1);
}
}
@Override

View File

@ -24,19 +24,19 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.IOException;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
import de.bluecolored.bluemap.core.world.World;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import java.io.IOException;
import java.util.Optional;
public class FabricCommandSource implements CommandSource {
private FabricMod mod;
@ -56,7 +56,12 @@ public void sendMessage(Text text) {
@Override
public boolean hasPermission(String permission) {
return delegate.hasPermissionLevel(1);
try {
Class.forName("me.lucko.fabric.api.permissions.v0.Permissions");
return Permissions.check(delegate, permission, 1);
} catch (ClassNotFoundException ex) {
return delegate.hasPermissionLevel(1);
}
}
@Override

View File

@ -24,11 +24,7 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.IOException;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
@ -38,6 +34,9 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import java.io.IOException;
import java.util.Optional;
public class FabricCommandSource implements CommandSource {
private FabricMod mod;
@ -57,7 +56,12 @@ public void sendMessage(Text text) {
@Override
public boolean hasPermission(String permission) {
return Permissions.check(delegate, permission, 1);
try {
Class.forName("me.lucko.fabric.api.permissions.v0.Permissions");
return Permissions.check(delegate, permission, 1);
} catch (ClassNotFoundException ex) {
return delegate.hasPermissionLevel(1);
}
}
@Override

View File

@ -24,11 +24,7 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.IOException;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
@ -38,6 +34,9 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import java.io.IOException;
import java.util.Optional;
public class FabricCommandSource implements CommandSource {
private FabricMod mod;
@ -57,7 +56,12 @@ public void sendMessage(Text text) {
@Override
public boolean hasPermission(String permission) {
return Permissions.check(delegate, permission, 1);
try {
Class.forName("me.lucko.fabric.api.permissions.v0.Permissions");
return Permissions.check(delegate, permission, 1);
} catch (ClassNotFoundException ex) {
return delegate.hasPermissionLevel(1);
}
}
@Override

View File

@ -24,11 +24,7 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.IOException;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
@ -38,6 +34,9 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import java.io.IOException;
import java.util.Optional;
public class FabricCommandSource implements CommandSource {
private FabricMod mod;
@ -57,7 +56,12 @@ public void sendMessage(Text text) {
@Override
public boolean hasPermission(String permission) {
return Permissions.check(delegate, permission, 1);
try {
Class.forName("me.lucko.fabric.api.permissions.v0.Permissions");
return Permissions.check(delegate, permission, 1);
} catch (ClassNotFoundException ex) {
return delegate.hasPermissionLevel(1);
}
}
@Override