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.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 GetStressCommand {
- public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
- dispatcher.register(
- Commands.literal("stress")
- .requires(source -> source.hasPermission(2))
- .then(
- Commands.literal("get")
- .then(
- Commands.argument("players", EntityArgument.players())
- .executes(GetStressCommand::checkStress)
- )
- )
- );
- }
- private static int checkStress(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
- CommandSourceStack source = context.getSource();
- Collection<ServerPlayer> players = EntityArgument.getPlayers(context, "players");
- for (ServerPlayer player : players)
- {
- int stressLevel = player.getPersistentData().getInt(StressedOutMod.STRESSNBTKEY);
- source.sendSuccess(() -> Component.literal("\"").append(player.getDisplayName()).append("\" has " + stressLevel + " stress"), false);
- }
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement