Jump to content

Recommended Posts

Posted

I made a mod that follows players to send message as custom display name using command:

/assend

It is working when I execute the command, but when I execute this command by command block, nothing happened

the command block output is 

Quote

[XX:XX:XX] /assend Name helloworld <--[HERE]

Java code of that command:

  static int SendAs(CommandContext<CommandSource> commandContext) throws CommandSyntaxException
  {
  String Name = StringArgumentType.getString(commandContext, "Name");
  String Input = MessageArgument.getMessage(commandContext, "Input").getUnformattedComponentText();
  TranslationTextComponent finalText = new TranslationTextComponent("chat.type.announcement",
                  Name, input);
  commandContext.getSource().getServer().getPlayerList().func_232641_a_(finalText, ChatType.SYSTEM, Util.DUMMY_UUID);
  return 1;
  }

How can i fix it?

Posted (edited)
package minecrafttest.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
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 net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.FunctionObject;
import net.minecraft.command.arguments.MessageArgument;
import net.minecraft.entity.Entity;
import net.minecraft.util.Util;
import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;

import java.util.Collection;
import java.util.Random;
import java.util.RandomAccess;

import static net.minecraft.util.math.MathHelper.clamp;
public class sayCommand {
  public static void register(CommandDispatcher<CommandSource> dispatcher) {
    LiteralArgumentBuilder<CommandSource> mbequoteCommand
            = Commands.literal("assend")
            .requires((commandSource) -> commandSource.hasPermissionLevel(4))
            .then(Commands.argument("Name", StringArgumentType.string())
                    .then(Commands.argument("Input", MessageArgument.message())
                            .executes(sayCommand::SendAs)

                    )
            );


    dispatcher.register(mbequoteCommand);
  }
  static int SendAs(CommandContext<CommandSource> commandContext) throws CommandSyntaxException
  {
    String Name = StringArgumentType.getString(commandContext, "Name");
    String input = MessageArgument.getMessage(commandContext, "Input").getUnformattedComponentText();
    TranslationTextComponent finalText = new TranslationTextComponent("chat.type.announcement",
            Name, input);
    commandContext.getSource().getServer().getPlayerList().func_232641_a_(finalText, ChatType.SYSTEM, Util.DUMMY_UUID);
    return 1;
  }
}

 

Minecraft_ 1.16.4 - Singleplayer 29_6_2021 15_34_59.png

Edited by SonMooSans
Posted

I think I found the problem, it works after I removed this:

.requires((commandSource) -> commandSource.hasPermissionLevel(4))

How can I let the command blocks run it when Require Permission Level is 4?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.