Posted April 12, 201510 yr 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!
April 12, 201510 yr http://www.minecraftforge.net/forum/index.php/topic,28953.0.html Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
April 12, 201510 yr Author I've read this post and the other tutorial ~10 times. I don't see any differences between my code and the code in the post you provided (except the discriminator, but there i tried both). Have I overlooked some thing?
April 12, 201510 yr Author Okay, thanks, i've corrected the byte[]-things. It totally clear. But it doesn't solve my problem. I do not receive any pluginmessages on both sides. I changed it to outgoing only on bukkit-side to first get this way running. 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 { public CommunicationMessage() { } @Override public void fromBytes(ByteBuf byteBuf) { } @Override public void toBytes(ByteBuf byteBuf) { } public static class Handler implements IMessageHandler<CommunicationMessage, IMessage> { @Override public IMessage onMessage(CommunicationMessage message, MessageContext ctx) { System.out.println(String.format("Received")); return null; // no response in this case } } } 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")) { System.out.println(message[0]); } } JoinListener: event.getPlayer().sendPluginMessage(plugin, "Channel", new byte[]{0}); Any other ideas?
April 12, 201510 yr Author Uuuuhhhh.... thats not what i wanted to hear... ;-) Do you know a good method to debug pluginmessages? Showing all incoming and outgoing plugin messages in forge and in spigot/bukkit?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.