Posted June 28, 20214 yr 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?
June 29, 20214 yr 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; } } Edited June 29, 20214 yr by SonMooSans
June 29, 20214 yr 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.