src/main/java/org/spacehq/packetlib/packet/PacketProtocol.java
public final Packet createIncomingPacket(int id) {
        if(id < 0 || !this.incoming.containsKey(id) || this.incoming.get(id) == null) {
            throw new IllegalArgumentException("Invalid packet id: " + id);
        }

        Class<? extends Packet> packet = this.incoming.get(id);
        try {
            Constructor<? extends Packet> constructor = packet.getDeclaredConstructor();
            if(!constructor.isAccessible()) {
                constructor.setAccessible(true);
            }

            return constructor.newInstance();
        } catch(NoSuchMethodError e) {
            throw new IllegalStateException("Packet \"" + id + ", " + packet.getName() + "\" does not have a no-params constructor for instantiation.");
        } catch(Exception e) {
            throw new IllegalStateException("Failed to instantiate packet \"" + id + ", " + packet.getName() + "\".", e);
        }
    }
/**
     * Creates a new instance of an incoming packet with the given id.
     *
     * @param id Id of the packet to create.
     * @return The created packet.
     * @throws IllegalArgumentException If the packet ID is invalid.
     * @throws IllegalStateException    If the packet does not have a no-params constructor or cannot be instantiated.
     */
Creates a new instance of an incoming packet with the given id.
@param id Id of the packet to create.
@return The created packet.
@throws IllegalArgumentException If the packet ID is invalid.
@throws IllegalStateException    If the packet does not have a no-params constructor or cannot be instantiated.
Creates a new instance of an incoming packet with the given id . @param id Id of the packet to create . @return The created packet . @throws IllegalArgumentException If the packet ID is invalid . @throws IllegalStateException If the packet does not have a no - params constructor or cannot be instantiated .
public final Packet createIncomingPacket(int id) {
        if(id < 0 || !this.incoming.containsKey(id) || this.incoming.get(id) == null) {
            throw new IllegalArgumentException("Invalid packet id: " + id);
        }
        Class<? extends Packet> packet = this.incoming.get(id);
        try {
            Constructor<? extends Packet> constructor = packet.getDeclaredConstructor();
            if(!constructor.isAccessible()) {
                constructor.setAccessible(true);
            }
            return constructor.newInstance();
        } catch(NoSuchMethodError e) {
            throw new IllegalStateException("Packet \"" + id + ", " + packet.getName() + "\" does not have a no-params constructor for instantiation.");
        } catch(Exception e) {
            throw new IllegalStateException("Failed to instantiate packet \"" + id + ", " + packet.getName() + "\".", e);
        }
    }
public final Packet createIncomingPacket ( int id ) { if ( id < 0 || ! this . incoming . containsKey ( id ) || this . incoming . get ( id ) == null ) { throw new IllegalArgumentException ( "Invalid packet id: " + id ) ; } Class < ? extends Packet > packet = this . incoming . get ( id ) ; try { Constructor < ? extends Packet > constructor = packet . getDeclaredConstructor ( ) ; if ( ! constructor . isAccessible ( ) ) { constructor . setAccessible ( true ) ; } return constructor . newInstance ( ) ; } catch ( NoSuchMethodError e ) { throw new IllegalStateException ( "Packet \"" + id + ", " + packet . getName ( ) + "\" does not have a no-params constructor for instantiation." ) ; } catch ( Exception e ) { throw new IllegalStateException ( "Failed to instantiate packet \"" + id + ", " + packet . getName ( ) + "\"." , e ) ; } }
Creates a new instance of an incoming packet with the given id.
Creates a new instance of an incoming packet with the given id .