Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.orion.stressedout.commands;
- import com.mojang.brigadier.CommandDispatcher;
- import com.mojang.brigadier.arguments.IntegerArgumentType;
- import com.mojang.brigadier.context.CommandContext;
- import com.mojang.brigadier.exceptions.CommandSyntaxException;
- import net.minecraft.commands.CommandSourceStack;
- import net.minecraft.commands.Commands;
- import net.minecraft.commands.arguments.EntityArgument;
- import net.minecraft.network.chat.Component;
- import net.minecraft.server.level.ServerPlayer;
- import net.orion.stressedout.StressedOutMod;
- import java.util.Collection;
- public class SetStressCommand {
- public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
- dispatcher.register(
- Commands.literal("stress")
- .requires(source -> source.hasPermission(2))
- .then(
- Commands.literal("set")
- .then(
- Commands.argument("players", EntityArgument.players())
- .then(
- Commands.argument("value", IntegerArgumentType.integer(0))
- .executes(SetStressCommand::setStress)
- )
- )
- )
- );
- }
- private static int setStress(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
- CommandSourceStack source = context.getSource();
- Collection<ServerPlayer> players = EntityArgument.getPlayers(context, "players");
- int targetLevel = IntegerArgumentType.getInteger(context, "value");
- for (ServerPlayer player : players)
- {
- player.getPersistentData().putInt(StressedOutMod.STRESSNBTKEY, targetLevel);
- source.sendSuccess(() -> Component.literal("Set \"").append(player.getDisplayName()).append("\" stress to " + targetLevel), false);
- }
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement