Advertisement
AssortedBrunoz

setStressCommand

Dec 23rd, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package net.orion.stressedout.commands;
  2.  
  3. import com.mojang.brigadier.CommandDispatcher;
  4. import com.mojang.brigadier.arguments.IntegerArgumentType;
  5. import com.mojang.brigadier.context.CommandContext;
  6. import com.mojang.brigadier.exceptions.CommandSyntaxException;
  7. import net.minecraft.commands.CommandSourceStack;
  8. import net.minecraft.commands.Commands;
  9. import net.minecraft.commands.arguments.EntityArgument;
  10. import net.minecraft.network.chat.Component;
  11. import net.minecraft.server.level.ServerPlayer;
  12. import net.orion.stressedout.StressedOutMod;
  13.  
  14. import java.util.Collection;
  15.  
  16. public class SetStressCommand {
  17.  
  18.     public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
  19.         dispatcher.register(
  20.             Commands.literal("stress")
  21.                 .requires(source -> source.hasPermission(2))
  22.                     .then(
  23.                 Commands.literal("set")
  24.                     .then(
  25.                 Commands.argument("players", EntityArgument.players())
  26.                     .then(
  27.                 Commands.argument("value", IntegerArgumentType.integer(0))
  28.                         .executes(SetStressCommand::setStress)
  29.                     )
  30.                 )
  31.             )
  32.         );
  33.     }
  34.  
  35.     private static int setStress(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
  36.         CommandSourceStack source = context.getSource();
  37.         Collection<ServerPlayer> players = EntityArgument.getPlayers(context, "players");
  38.         int targetLevel = IntegerArgumentType.getInteger(context, "value");
  39.  
  40.  
  41.         for (ServerPlayer player : players)
  42.         {
  43.             player.getPersistentData().putInt(StressedOutMod.STRESSNBTKEY, targetLevel);
  44.  
  45.             source.sendSuccess(() -> Component.literal("Set \"").append(player.getDisplayName()).append("\" stress to " + targetLevel), false);
  46.         }
  47.  
  48.         return 1;
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement