Advertisement
AssortedBrunoz

getStressCommand

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