Hello,
I want my plugin to send an integer to my mod but I don't understand how to get the integer.
Registering in main class :
SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel("MyChannel");
network.registerMessage(CommunicationMessage.Handler.class, CommunicationMessage.class, 0, Side.CLIENT);
My CommunicationMessage class :
public class CommunicationMessage implements IMessage {
private static int actualMana;
public CommunicationMessage() {
}
public CommunicationMessage(int actualMana) {
this.actualMana = actualMana;
}
@Override
public void fromBytes(ByteBuf buf) {
actualMana = ByteBufUtils.readVarInt(buf, 100000);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeVarInt(buf, actualMana, 100000);
}
public static class Handler implements IMessageHandler<CommunicationMessage, IMessage> {
@Override
public IMessage onMessage(CommunicationMessage message, MessageContext ctx) {
Minecraft.getMinecraft().player.sendChatMessage("detected");
return null;
}
}
}
Registering in plugin the channel :
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "MyChannel");
How I send the packet in my plugin :
public static void sendManaToHUD(Player p, int actualMana) {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeInt(0);
output.writeInt(actualMana);
p.sendPluginMessage(ModPluginAPI.pl, "MyChannel", output.toByteArray());
}
So, the packet is detected within my onMessage event, but how do I get the integer I sent ?
I checked and the ByteBuf is null so the int actualMana too.
Could you explain what I did wrong ?
Thank you very much