diff --git a/build.gradle b/build.gradle index 678f16aa..f788b207 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,8 @@ dependencies { // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. compileOnly "com.google.code.findbugs:jsr305:${project.jsr305_version}" + + modImplementation 'me.lucko:fabric-permissions-api:0.3.1' } processResources { diff --git a/src/main/java/carpet/commands/CounterCommand.java b/src/main/java/carpet/commands/CounterCommand.java index 28683814..37fd51fc 100644 --- a/src/main/java/carpet/commands/CounterCommand.java +++ b/src/main/java/carpet/commands/CounterCommand.java @@ -5,6 +5,7 @@ import carpet.helpers.HopperCounter; import carpet.utils.Messenger; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; @@ -15,21 +16,18 @@ import static net.minecraft.commands.Commands.literal; /** * Class for the /counter command which allows to use hoppers pointing into wool */ -public class CounterCommand -{ +public class CounterCommand { /** * The method used to register the command and make it available for the players to use. */ - public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) - { + public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder commandBuilder = literal("counter") - .requires(c -> CarpetSettings.hopperCounters) + .requires(c -> Permissions.check(c, "carpet.command.counter", CarpetSettings.hopperCounters)) .executes(c -> listAllCounters(c.getSource(), false)) .then(literal("reset") .executes(c -> resetCounters(c.getSource()))); - for (DyeColor dyeColor : DyeColor.values()) - { + for (DyeColor dyeColor : DyeColor.values()) { commandBuilder.then( literal(dyeColor.toString()) .executes(c -> displayCounter(c.getSource(), dyeColor, false)) @@ -37,31 +35,29 @@ public class CounterCommand .executes(c -> resetCounter(c.getSource(), dyeColor))) .then(literal("realtime") .executes(c -> displayCounter(c.getSource(), dyeColor, true))) - ); + ); } dispatcher.register(commandBuilder); } /** * A method to prettily display the contents of a counter to the player - * @param color The counter colour whose contents we are querying. + * + * @param color The counter colour whose contents we are querying. * @param realtime Whether or not to display it as in-game time or IRL time, which accounts for less than 20TPS which - * would make it slower than IRL + * would make it slower than IRL */ - private static int displayCounter(CommandSourceStack source, DyeColor color, boolean realtime) - { + private static int displayCounter(CommandSourceStack source, DyeColor color, boolean realtime) { HopperCounter counter = HopperCounter.getCounter(color); - for (Component message: counter.format(source.getServer(), realtime, false)) - { + for (Component message : counter.format(source.getServer(), realtime, false)) { source.sendSuccess(() -> message, false); } return 1; } - private static int resetCounters(CommandSourceStack source) - { + private static int resetCounters(CommandSourceStack source) { HopperCounter.resetAll(source.getServer(), false); Messenger.m(source, "w Restarted all counters"); return 1; @@ -69,11 +65,10 @@ public class CounterCommand /** * A method to reset the counter's timer to 0 and empty its items - * + * * @param color The counter whose contents we want to reset */ - private static int resetCounter(CommandSourceStack source, DyeColor color) - { + private static int resetCounter(CommandSourceStack source, DyeColor color) { HopperCounter.getCounter(color).reset(source.getServer()); Messenger.m(source, "w Restarted " + color + " counter"); return 1; @@ -81,13 +76,12 @@ public class CounterCommand /** * A method to prettily display all the counters to the player + * * @param realtime Whether or not to display it as in-game time or IRL time, which accounts for less than 20TPS which - * would make it slower than IRL + * would make it slower than IRL */ - private static int listAllCounters(CommandSourceStack source, boolean realtime) - { - for (Component message: HopperCounter.formatAll(source.getServer(), realtime)) - { + private static int listAllCounters(CommandSourceStack source, boolean realtime) { + for (Component message : HopperCounter.formatAll(source.getServer(), realtime)) { source.sendSuccess(() -> message, false); } return 1; diff --git a/src/main/java/carpet/commands/DistanceCommand.java b/src/main/java/carpet/commands/DistanceCommand.java index fe5c2e1b..f964c0cb 100644 --- a/src/main/java/carpet/commands/DistanceCommand.java +++ b/src/main/java/carpet/commands/DistanceCommand.java @@ -5,6 +5,7 @@ import carpet.utils.CommandHelper; import carpet.utils.DistanceCalculator; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.coordinates.Vec3Argument; @@ -17,7 +18,7 @@ public class DistanceCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder command = literal("distance"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandDistance)). + requires((player) -> Permissions.check(player,"carpet.command.distance",CommandHelper.canUseCommand(player, CarpetSettings.commandDistance))). then(literal("from"). executes( (c) -> DistanceCalculator.setStart(c.getSource(), c.getSource().getPosition())). then(argument("from", Vec3Argument.vec3()). diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index df2e544c..17fddef9 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -16,6 +16,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import java.util.List; import java.util.function.Predicate; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.blocks.BlockInput; @@ -40,7 +41,7 @@ public class DrawCommand public static void register(CommandDispatcher dispatcher, final CommandBuildContext context) { LiteralArgumentBuilder command = literal("draw"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandDraw)). + requires((player) -> Permissions.check(player,"carpet.command.draw",CommandHelper.canUseCommand(player, CarpetSettings.commandDraw))). then(literal("sphere"). then(argument("center", BlockPosArgument.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). diff --git a/src/main/java/carpet/commands/InfoCommand.java b/src/main/java/carpet/commands/InfoCommand.java index 4e36964c..37aa22d2 100644 --- a/src/main/java/carpet/commands/InfoCommand.java +++ b/src/main/java/carpet/commands/InfoCommand.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -27,7 +28,7 @@ public class InfoCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder command = literal("info"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandInfo)). + requires((player) -> Permissions.check(player, "carpet.command.info",CommandHelper.canUseCommand(player, CarpetSettings.commandInfo))). then(literal("block"). then(argument("block position", BlockPosArgument.blockPos()). executes( (c) -> infoBlock( diff --git a/src/main/java/carpet/commands/LogCommand.java b/src/main/java/carpet/commands/LogCommand.java index bd9cd4ea..1d8e51c5 100644 --- a/src/main/java/carpet/commands/LogCommand.java +++ b/src/main/java/carpet/commands/LogCommand.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -29,7 +30,7 @@ public class LogCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder literalargumentbuilder = Commands.literal("log"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandLog)). + requires((player) -> Permissions.check(player,"carpet.command.log",CommandHelper.canUseCommand(player, CarpetSettings.commandLog))). executes((context) -> listLogs(context.getSource())). then(Commands.literal("clear"). executes( (c) -> unsubFromAll(c.getSource(), c.getSource().getTextName())). diff --git a/src/main/java/carpet/commands/MobAICommand.java b/src/main/java/carpet/commands/MobAICommand.java index 53455830..40f690ca 100644 --- a/src/main/java/carpet/commands/MobAICommand.java +++ b/src/main/java/carpet/commands/MobAICommand.java @@ -6,6 +6,7 @@ import carpet.utils.MobAI; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.registries.Registries; @@ -21,7 +22,7 @@ public class MobAICommand public static void register(CommandDispatcher dispatcher, final CommandBuildContext commandBuildContext) { LiteralArgumentBuilder command = literal("track"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandTrackAI)). + requires((player) -> Permissions.check(player, "carpet.command.track",CommandHelper.canUseCommand(player, CarpetSettings.commandTrackAI))). then(argument("entity type", resource(commandBuildContext, Registries.ENTITY_TYPE)). suggests( (c, b) -> suggest(MobAI.availbleTypes(c.getSource()), b)). diff --git a/src/main/java/carpet/commands/PerimeterInfoCommand.java b/src/main/java/carpet/commands/PerimeterInfoCommand.java index bc478095..4bb82f91 100644 --- a/src/main/java/carpet/commands/PerimeterInfoCommand.java +++ b/src/main/java/carpet/commands/PerimeterInfoCommand.java @@ -6,6 +6,7 @@ import carpet.utils.Messenger; import carpet.utils.PerimeterDiagnostics; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; @@ -27,7 +28,7 @@ public class PerimeterInfoCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder command = literal("perimeterinfo"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandPerimeterInfo)). + requires((player) -> Permissions.check(player,"carpet.command.perimeterinfo",CommandHelper.canUseCommand(player, CarpetSettings.commandPerimeterInfo))). executes( (c) -> perimeterDiagnose( c.getSource(), BlockPos.containing(c.getSource().getPosition()), diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index 616fd25b..e729ed09 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -16,6 +16,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.SharedConstants; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; @@ -51,7 +52,7 @@ public class PlayerCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder command = literal("player") - .requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandPlayer)) + .requires((player) -> Permissions.check(player,"carpet.command.player",CommandHelper.canUseCommand(player, CarpetSettings.commandPlayer))) .then(argument("player", StringArgumentType.word()) .suggests((c, b) -> suggest(getPlayerSuggestions(c.getSource()), b)) .then(literal("stop").executes(manipulation(EntityPlayerActionPack::stopAll))) diff --git a/src/main/java/carpet/commands/ProfileCommand.java b/src/main/java/carpet/commands/ProfileCommand.java index 553f31c8..d0c052b5 100644 --- a/src/main/java/carpet/commands/ProfileCommand.java +++ b/src/main/java/carpet/commands/ProfileCommand.java @@ -6,6 +6,7 @@ import carpet.utils.CommandHelper; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; @@ -19,7 +20,7 @@ public class ProfileCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder literalargumentbuilder = literal("profile"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandProfile)). + requires((player) -> Permissions.check(player, "carpet.command.profile",CommandHelper.canUseCommand(player, CarpetSettings.commandProfile))). executes( (c) -> healthReport(c.getSource(), 100)). then(literal("health"). executes( (c) -> healthReport(c.getSource(), 100)). diff --git a/src/main/java/carpet/commands/SpawnCommand.java b/src/main/java/carpet/commands/SpawnCommand.java index e8824afa..42f76cae 100644 --- a/src/main/java/carpet/commands/SpawnCommand.java +++ b/src/main/java/carpet/commands/SpawnCommand.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.DimensionArgument; @@ -42,7 +43,7 @@ public class SpawnCommand public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { LiteralArgumentBuilder literalargumentbuilder = literal("spawn"). - requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandSpawn)); + requires((player) -> Permissions.check(player, "carpet.command.spawn",CommandHelper.canUseCommand(player, CarpetSettings.commandSpawn))); literalargumentbuilder. then(literal("list").