- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试制作一个具有“全局”配置文件的插件。现在,我正在尝试使用插件消息传递通过字符串将整个配置文件发送到另一台服务器。我已按照 https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/ 上的指南进行操作并对所发送的内容进行了我自己的一点改动。我正在尝试在 spigot 插件中发送插件消息,所以也许这就是问题所在。下面的代码是我用来发送它的代码的摘要(我取出了 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();当调用它时,onPluginMessageReceived 永远不会运行。我做错了什么吗?插件消息只能由bungeecord 插件发送吗?提前致谢。如果您对代码有任何疑问,请告诉我。
最佳答案
不工作,因为它是写入的(要发送到的字符串服务器,或全部发送到每个服务器(发送插件消息的服务器除外))!要使用它,您可以使用我们自己的 channel 或redis
关于java - Spigot-Bungeecord 插件消息传递不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48671819/
我尝试使用插件关闭我的 BungeeCord-/Proxy-Server。但我找不到类似 Bukkit.shutdown(); 或 Bukkit.dispatchCommand(); 的东西,它们可用
我正在设置一个新的 Minecraft 服务器,并且想使用我自己的插件更改我的子服务器。 这不起作用 getProxy().getServers().put("game25568", new Serv
我正在尝试制作一个具有“全局”配置文件的插件。现在,我正在尝试使用插件消息传递通过字符串将整个配置文件发送到另一台服务器。我已按照 https://www.spigotmc.org/wiki/bukk
我有多个 Spigot 实例在 Bungeecord 服务器上运行。我有一个插件可以在每台服务器上进行自定义配置文件管理。该配置文件管理插件读取和写入 Mongo 数据库。所有代码都工作得很好,我不是
我正在开发一个带有 MySQL 数据库的 Minecraft 服务器来处理所有玩家权限(排名、姓名等)。我使用bungeecord作为代理进行托管,并尝试将以下插件链接到数据库中,以便它们在服务器范围
我目前正在为 Bukkit(Paper Spigot)开发一个充当队列的插件。该插件在队列服务器中运行,当正确服务器的玩家数量少于设定数量时,该插件会将玩家转移到正确的服务器。我需要从正确的服务器获取
我试图通过“BungeeCord Plugin Messaging Channel”从代理向服务器发送消息。我使用了以下代码: 在 BungeeCord 插件中: ByteArrayO
我是一名优秀的程序员,十分优秀!