首页 > 解决方案 > 从 BungeeCord 中的 Spigot 执行命令

问题描述

我需要从 BungeeCord 的 Spigot 执行命令,但我不知道该怎么做。我使用了更多功能……例如 Forward Channel、Message Channel、BungeeCord.getInstance().dispatchCommand、ProxyServer.getInstance().dispatchCommand。这些选项都不起作用。顺便说一下 BungeeCord[..].dispatchCommand i ProxyServer 在控制台中发送错误。我第一次使用 BungeeCord API。我正在寻找更多选择,也许我使用了一个糟糕的 api。

标签: javabukkit

解决方案


You will have to use the Messaging Channels directly from Spigot and send information to BungeeCord with that.

Here is a little example on how you want to do this :

ByteArrayOutputStream b = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(b);
    try {
        out.writeUTF("Message");
        out.writeUTF("ALL");
        out.writeUTF("/alert Testing command distance");
    } catch(Exception e) {
        e.printStackTrace();
    }

    p.sendPluginMessage(getPlugin(), "BungeeCord", b.toByteArray());

You can of course change the information you want to send, here is the official wiki about messaging channels : https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#message

PS: You have to register the Channel in your onEnable()

this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");

推荐阅读