SPIGOT-BUNGEECORD插件消息传递不起作用



我正在尝试制作具有'全局'配置文件的插件。现在,我试图使用插件消息传递通过字符串将整个配置文件发送到另一台服务器。我遵循了指南,网址为https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/,并在发送的内容上对我自己的小扭曲进行了。我正在尝试在插件插件中发送插件消息,所以也许这就是问题所在。这是代码是我用于发送它的代码的摘要(我删除了ReadFile((,clearfile((和writefile((,让我知道您是否想要这些(:

public class Main extends JavaPlugin implements PluginMessageListener {
public void onEnable() {
    this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
}
public void onDisable() {}
public void updateConfig() {
    String updateConfig = "";
    for (String s : readFile(this.getDataFolder() + "/config.yml")) {
        if (updateConfig.equals("")) {
            updateConfig = s;
        } else {
            updateConfig = updateConfig + " |n| " + s;
        }
    }
    Bukkit.getLogger().info("Sending config update...");
    sendUpdateconfig(updateConfig);
}
public void sendUpdateconfig(String update) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    try {
        out.writeUTF("Forward");
        out.writeUTF("ALL");
        out.writeUTF("FooServer");
        ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
        DataOutputStream msgout = new DataOutputStream(msgbytes);
        msgout.writeUTF(update);
        msgout.writeShort(295);
        out.writeShort(msgbytes.toByteArray().length);
        out.write(msgbytes.toByteArray());
        Player player = Iterables.getLast(Bukkit.getOnlinePlayers());
        player.getServer().sendPluginMessage(this, "BungeeCord", out.toByteArray());
        Bukkit.getLogger().info("Sent " + update);
        Bukkit.getLogger().info("Short sent: 295");
        Bukkit.getLogger().info("Sent through player " + player.getName());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    Bukkit.getLogger().info("Recieved message...");
    if (!channel.equals("BungeeCord")) {
        return;
    }
    try {
        Bukkit.getLogger().info("Recieved message...");
        ByteArrayDataInput in = ByteStreams.newDataInput(message);
        String subChannel = in.readUTF();
        if (!subChannel.equals("FooServer")) {
            Bukkit.getLogger().info("Loading message....");
            short len = in.readShort();
            byte[] msgbytes = new byte[len];
            in.readFully(msgbytes);
            DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
            String somedata = msgin.readUTF();
            short somenumber = msgin.readShort();
            if (somenumber == 295) {
                Bukkit.getLogger().info("Updating config...");
                String[] toWrite = somedata.split(" |n| ");
                String path = (this.getDataFolder() + "/config.yml");
                clearFile(path);
                for (String s : toWrite) {
                    writeFile(path, s);
                }
                Bukkit.getLogger().info("Config updated!");
            }
        } else {
            Bukkit.getLogger().info("Message sent by this plugin.");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

我发送消息的方式只是通过致电,updateconfig((;当称之为时,永远不会运行OnpluginMessageCeevierd。我做错了吗?插件消息只能由BungeeCord插件发送吗?提前致谢。如果您对代码有任何疑问,请告诉我。

不工作beadaws witr(要发送到的字符串服务器,或全部发送到每个服务器(除了发送插件消息的那个服务器((!为了使用它,您可以使用我们自己的频道或redis

相关内容

最新更新