When trying to send a package from the Spigot Plugin, this warning appears
I tried to decode it any way or even removed everything, all without success
Unknown custom packet identifier: mod_id:channel_id
Network Init:
public class NetworkHandler {
public static final String FD_ID = "mod_id";
public static final String PROTOCOL_VERSION = Integer.toString(1);
public static void init() {
SimpleChannel network = NetworkRegistry.newSimpleChannel(
new ResourceLocation(FD_ID, FDCore.FD_CHANNEL),
() -> PROTOCOL_VERSION,
PROTOCOL_VERSION::equals,
PROTOCOL_VERSION::equals);
network.registerMessage(0, UIPacket.class, UIPacket::encode, UIPacket::decode, UIPacket::handle);
}
}
UIPacket:
public class UIPacket {
private final JsonObject jsonObject;
public UIPacket(JsonObject jsonObject) {
this.jsonObject = jsonObject;
}
public static void encode(UIPacket packet, PacketBuffer buf) {
buf.writeUtf(packet.jsonObject.toString(), 262144);
}
public static UIPacket decode(PacketBuffer buf) {
int bytesCount = buf.readableBytes();
byte[] imageBytes = new byte[bytesCount];
for (int i = 0; i < bytesCount; ++i)
imageBytes[i] = buf.readByte();
// buf.readUtf(262144);
return new UIPacket(new JsonParser().parse(new String(imageBytes).substring(1)).getAsJsonObject());
}
public static void handle(UIPacket packet, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
JsonObject jsonObject = packet.jsonObject;
for (UIHandler handler : Handlers.handlersList) {
if (jsonObject.has(handler.getId())) {
handler.handle(jsonObject);
break;
}
}
});
}
Spigot:
// init
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, CHANNEL);
// sending
player.sendPluginMessage(plugin, CHANNEL, "text".getBytes(StandardCharsets.UTF_8));