EAA_MOD/src/main/java/net/saltymc/eaa/commands/EchoCommand.java
2022-09-21 14:39:09 +02:00

38 lines
1.5 KiB
Java

package net.saltymc.eaa.commands;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.toast.*;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
public class EchoCommand extends EaaModCommand{
public int run(CommandContext<FabricClientCommandSource> context) { // throws CommandSyntaxException
FabricClientCommandSource source = context.getSource();
String nachricht = StringArgumentType.getString(context,"nachricht");
SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.TUTORIAL_HINT, Text.of("ECHO"), Text.of(nachricht));
source.sendFeedback(
Text.literal("You said: ")
.formatted(Formatting.RED)
.append(Text.literal(nachricht + ""))
);
return 1;
}
public LiteralArgumentBuilder<FabricClientCommandSource> getCommandSpecification() {
return literal("/echo").then(
argument("nachricht", StringArgumentType.greedyString())
.executes(this)
);
}
}