Skip to content

Commit

Permalink
Add support for fabric permission api in game commands
Browse files Browse the repository at this point in the history
  • Loading branch information
UninenVille committed Dec 23, 2024
1 parent 2d1831c commit 80daa75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/main/java/xyz/nucleoid/plasmid/impl/command/GameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.logging.LogUtils;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.NbtCompoundArgumentType;
import net.minecraft.nbt.NbtOps;
Expand Down Expand Up @@ -62,7 +63,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(
literal("game")
.then(literal("open")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.open", 2))
.then(GameConfigArgument.argument("game_config")
.executes(GameCommand::openGame)
)
Expand All @@ -71,26 +72,25 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
)
)
.then(literal("propose")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.propose", 2))
.then(GameSpaceArgument.argument("game_space")
.executes(GameCommand::proposeGame)
)
.executes(GameCommand::proposeCurrentGame)
)
.then(literal("start")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.start", 2))
.executes(GameCommand::startGame)
)
.then(literal("stop")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.stop", 2))
.executes(GameCommand::stopGame)
.then(literal("confirm")
.requires(source -> source.hasPermissionLevel(2))
.executes(GameCommand::stopGameConfirmed)
)
)
.then(literal("kick")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.kick", 2))
.then(argument("targets", EntityArgumentType.players())
.executes(GameCommand::kickPlayers)
)
Expand All @@ -108,7 +108,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
)
)
.then(literal("joinall")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.joinall", 2))
.executes(GameCommand::joinAllGame)
.then(GameSpaceArgument.argument("game_space")
.executes(GameCommand::joinAllQualifiedGame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -31,13 +32,13 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
literal("game")
.then(literal("portal")
.then(literal("connect")
.requires(source -> source.hasPermissionLevel(3))
.requires(Permissions.require("plasmid.command.game.portal.connect", 3))
.then(GamePortalArgument.argument("portal")
.then(argument("entity", EntityArgumentType.entity()).executes(GamePortalCommand::connectEntity))
.then(argument("pos", BlockPosArgumentType.blockPos()).executes(GamePortalCommand::connectBlock))
))
.then(literal("disconnect")
.requires(source -> source.hasPermissionLevel(3))
.requires(Permissions.require("plasmid.command.game.portal.disconnect", 3))
.then(argument("entity", EntityArgumentType.entity()).executes(GamePortalCommand::disconnectEntity))
.then(argument("pos", BlockPosArgumentType.blockPos()).executes(GamePortalCommand::disconnectBlock))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.NbtCompoundArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import xyz.nucleoid.plasmid.impl.command.argument.GameConfigArgument;
Expand All @@ -16,7 +17,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(
literal("game")
.then(literal("test")
.requires(source -> source.hasPermissionLevel(2))
.requires(Permissions.require("plasmid.command.game.test", 2))
.then(GameConfigArgument.argument("game_config")
.executes(GameTestCommand::openTestGame)
)
Expand Down

0 comments on commit 80daa75

Please sign in to comment.