Hello@all,
I'm Googling since yesterday morning and followed every interesting thread in this forum, the bukkit forum and many other sources, but my problem is not solved.
I want to communicate between a mod and my spigot server. But neither messages sent from forge nor the messages sent from spigot/bukkit are received on the other side.
What I do:
Forge-Side:
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
network = NetworkRegistry.INSTANCE.newSimpleChannel("Channel");
network.registerMessage(CommunicationMessage.Handler.class, CommunicationMessage.class, 0, Side.CLIENT);
System.out.println("Channel registered as CLIENT Side with 0");
}
public class CommunicationMessage implements IMessage {
private String text;
public CommunicationMessage() { }
public CommunicationMessage(String text) {
this.text = text;
}
@Override
public void fromBytes(ByteBuf buf) {
text = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, text);
}
public static class Handler implements IMessageHandler<CommunicationMessage, IMessage> {
@Override
public IMessage onMessage(CommunicationMessage message, MessageContext ctx) {
System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName()));
return null; // no response in this case
}
}
}
On the Spigot/Bukkit Side
@Override
public void onEnable() {
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "Channel");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "Channel", new PacketHandler(this));
this.getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
}
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if(channel.equalsIgnoreCase("Channel")) {
Bukkit.broadcastMessage(message.toString());
if(message.toString().equalsIgnoreCase(((byte)0)+"reg")) {
if(!plugin.players.contains(player))
plugin.players.add(player);
}
}
}
So. What i want to do - i know that currently my forge mod have no code to answer ;-):
When the player joins the Spigot/Bukkit Server, Spigot/Bukkit sends "reg" over "Channel".
When forge receives "reg" over Channel it should answer with "reg" over channel. So, Spigot/Bukkit knows the players using the Forge Mod.
So. What i am doing wrong?
Should i to it another way?
Who can help?
Many thanks!