Adds some sanity checks in PacketEvent.setPacket().

Thanks libraryaddict. :)
This commit is contained in:
Kristian S. Stangeland 2014-03-22 23:20:16 +01:00
parent 7adb6548aa
commit 45e236b54a

View File

@ -167,6 +167,10 @@ public class PacketEvent extends EventObject implements Cancellable {
public void setPacket(PacketContainer packet) { public void setPacket(PacketContainer packet) {
if (readOnly) if (readOnly)
throw new IllegalStateException("The packet event is read-only."); throw new IllegalStateException("The packet event is read-only.");
if (packet == null)
throw new IllegalArgumentException("Cannot set packet to NULL. Use setCancelled() instead.");
if (this.packet != null && this.packet.getType() != packet.getType())
throw new IllegalArgumentException("Cannot change packet type from " + this.packet.getType() + " to " + packet.getType());
this.packet = packet; this.packet = packet;
} }