diff --git a/src/main/java/com/github/steveice10/packetlib/packet/PacketProtocol.java b/src/main/java/com/github/steveice10/packetlib/packet/PacketProtocol.java index 77613f00..11556482 100644 --- a/src/main/java/com/github/steveice10/packetlib/packet/PacketProtocol.java +++ b/src/main/java/com/github/steveice10/packetlib/packet/PacketProtocol.java @@ -14,10 +14,10 @@ import java.util.Map; * All implementations must have a no-params constructor for server protocol creation. */ public abstract class PacketProtocol { - private final Map> incoming = new HashMap>(); - private final Map, Integer> outgoing = new HashMap, Integer>(); + private final Map> incoming = new HashMap<>(); + private final Map, Integer> outgoing = new HashMap<>(); - private final Map> outgoingClasses = new HashMap>(); + private final Map> outgoingClasses = new HashMap<>(); /** * Gets the prefix used when locating SRV records for this protocol. @@ -110,12 +110,12 @@ public abstract class PacketProtocol { * * @param id Id of the packet to create. * @return The created packet. - * @throws IllegalArgumentException If the packet ID less than zero or it is not registered. + * @throws IllegalArgumentException If the packet ID is not registered. * @throws IllegalStateException If the packet does not have a no-params constructor or cannot be instantiated. */ public final Packet createIncomingPacket(int id) { - Class packet; - if(id < 0 || (packet = this.incoming.get(id)) == null) { + Class packet = this.incoming.get(id); + if (packet == null) { throw new IllegalArgumentException("Invalid packet id: " + id); } @@ -168,11 +168,11 @@ public abstract class PacketProtocol { * Gets the packet class for a packet id. * @param id The packet id. * @return The registered packet's class - * @throws IllegalArgumentException If the packet ID less than zero or it is not registered. + * @throws IllegalArgumentException If the packet ID is not registered. */ public final Class getOutgoingClass(int id) { - Class packet; - if(id < 0 || (packet = this.outgoingClasses.get(id)) == null) { + Class packet = this.outgoingClasses.get(id); + if(packet == null) { throw new IllegalArgumentException("Invalid packet id: " + id); }