Jump to content

Recommended Posts

Posted

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!

Posted

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?

 

Posted

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?

 

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.