Search in sources :

Example 1 with PacketDefinition

use of io.xol.chunkstories.api.net.PacketDefinition in project chunkstories by Hugobros3.

the class PacketsContextCommon method findIdForPacket.

private short findIdForPacket(Packet packet) throws UnknowPacketException {
    WorldNetworked world = this.getWorld();
    if (world == null) {
        if ((packet instanceof PacketText))
            return 0x00;
        else if ((packet instanceof PacketSendFile))
            return 0x01;
        else
            // Throw an error if sending a packet while not within a world
            throw new UnknowPacketException(0xFF);
    } else {
        PacketDefinition def = world.getContent().packets().getPacketFromInstance(packet);
        if (def == null)
            logger.error("Could not find the definition of packet " + packet);
        short id = (short) world.getContentTranslator().getIdForPacket(def);
        if (id == -1) {
            logger.error("Could not find the id of packet definition " + def.getName());
            // ((AbstractContentTranslator)world.getContentTranslator()).test();
            throw new UnknowPacketException(packet);
        }
        return id;
    }
}
Also used : PacketText(io.xol.chunkstories.api.net.packets.PacketText) PacketSendFile(io.xol.chunkstories.net.packets.PacketSendFile) WorldNetworked(io.xol.chunkstories.api.world.WorldNetworked) PacketDefinition(io.xol.chunkstories.api.net.PacketDefinition) UnknowPacketException(io.xol.chunkstories.api.exceptions.net.UnknowPacketException)

Aggregations

UnknowPacketException (io.xol.chunkstories.api.exceptions.net.UnknowPacketException)1 PacketDefinition (io.xol.chunkstories.api.net.PacketDefinition)1 PacketText (io.xol.chunkstories.api.net.packets.PacketText)1 WorldNetworked (io.xol.chunkstories.api.world.WorldNetworked)1 PacketSendFile (io.xol.chunkstories.net.packets.PacketSendFile)1