当玩家加入世界MC Forge 1.18.2时,如何执行命令



因此,当玩家加入MC 1.18.2 Forge中的一个可点击的世界时,我试图在聊天中发送一条消息(它将链接到github上的一个问题页面),但我不知道如何在点击时执行tellraw命令。所有关于ClickEvents的教程都已经过时了,所以我不能使用它们中的任何一个。提前谢谢。

命令:/tellraw @s {"text":"PLACEHOLDER","clickEvent":{"action":"open_url","value":"https://www.google.com/search?q=PLACEHOLDER"},"hoverEvent":{"action":"show_text","contents":["PLACEHOLDER"]}}

我当前的代码:

static int messageAlreadyReceived = 0;
@SubscribeEvent
public static void onEntityJoinWorld(@NotNull EntityJoinWorldEvent event) {
if(event.getEntity() != null && event.getEntity() instanceof Player) {
if(messageAlreadyReceived == 0) {
messageAlreadyReceived = 1;
Entity player = event.getEntity();
String testVariable = "CLICK ME";
String testVariable2 = "CLICK ME 2";
TextComponent tC = new TextComponent(testVariable);
TextComponent tC2 = new TextComponent(testVariable2);
TextComponent tC3 = new TextComponent(testVariable);
tC.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kill @a"));
player.sendMessage(tC, player.getUUID());
tC2.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "kill @a"));
player.sendMessage(tC2, player.getUUID());
ClickEvent cE1 = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/kill @a");
player.sendMessage(tC3.setStyle(Style.EMPTY.withClickEvent(cE1)), player.getUUID());
ClickEvent cE2 = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "kill @a");
player.sendMessage(tC3.setStyle(Style.EMPTY.withClickEvent(cE2)), player.getUUID());
} else {
messageAlreadyReceived = 0;
}
}
}

Java:17.0.2
Minecraft:Forge 1.18.2-40.0.5

问题正文中的答案:

我通过发送消息代码如下所示找到了答案:player.sendMessage(tC.plainCopy().withStyle(Style.EMPTY.withClickEvent(cE1)), player.getUUID());

相关内容

  • 没有找到相关文章

最新更新