Hello AGAIN! (I know that Bukkit is dead ) So I am trying to create a mod and a plugin that could communicate with each other. By the way, I need to send a simple message to Forge mod from the plugin. I found the old thread, which was written for 1.7.10 by one of the forums staff member and a guy :). Here is the code from old 2015:
//Forge part:
// --- Main class ---
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
SimpleNetworkWrapper 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");
}
//--- CommunicationMessage class ---
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
}
}
}
//Bukkit part:
//--- Main plugin class (In onEnable()): ---
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "Channel");
I really want to create this mod-plugin connection. I have great ideas, but I need some base. PLEASE, help me with this. Thanks in advance!!!