Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

  • Author
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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.