From 4ecd0844eb027bc16999d63bdca1c3e1d77729e0 Mon Sep 17 00:00:00 2001 From: Photon-GitHub Date: Thu, 27 Sep 2018 02:37:35 +0200 Subject: [PATCH 1/4] Remove old deprecated "recievePacket" method. --- .../packetwrapper/AbstractPacket.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java index 88fc4b97..64fc9cfd 100644 --- a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java +++ b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java @@ -79,24 +79,6 @@ public void broadcastPacket() { ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); } - /** - * Simulate receiving the current packet from the given sender. - * - * @param sender - the sender. - * @throws RuntimeException If the packet cannot be received. - * @deprecated Misspelled. recieve to receive - * @see #receivePacket(Player) - */ - @Deprecated - public void recievePacket(Player sender) { - try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, - getHandle()); - } catch (Exception e) { - throw new RuntimeException("Cannot recieve packet.", e); - } - } - /** * Simulate receiving the current packet from the given sender. * From 222d78cd7aaf777f76a310749d017fb1f96a3983 Mon Sep 17 00:00:00 2001 From: Photon-GitHub Date: Thu, 27 Sep 2018 02:44:56 +0200 Subject: [PATCH 2/4] Use Preconditions instead of throwing the exceptions manually. --- .../java/com/comphenix/packetwrapper/AbstractPacket.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java index 64fc9cfd..2ea66286 100644 --- a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java +++ b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java @@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import com.comphenix.protocol.PacketType; @@ -39,12 +40,8 @@ public abstract class AbstractPacket { */ protected AbstractPacket(PacketContainer handle, PacketType type) { // Make sure we're given a valid packet - if (handle == null) - throw new IllegalArgumentException("Packet handle cannot be NULL."); - if (!Objects.equal(handle.getType(), type)) - throw new IllegalArgumentException(handle.getHandle() - + " is not a packet of type " + type); - + Preconditions.checkNotNull(handle, "Packet handle cannot be NULL."); + Preconditions.checkArgument(Objects.equal(handle.getType(), type), handle.getHandle() + " is not a packet of type " + type); this.handle = handle; } From 9d3d7424bbeb1b01aca10d22dff5fb29025a66e0 Mon Sep 17 00:00:00 2001 From: Photon-GitHub Date: Thu, 27 Sep 2018 02:51:05 +0200 Subject: [PATCH 3/4] Improve formatting --- .../java/com/comphenix/packetwrapper/AbstractPacket.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java index 2ea66286..85ed046f 100644 --- a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java +++ b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java @@ -62,8 +62,7 @@ public PacketContainer getHandle() { */ public void sendPacket(Player receiver) { try { - ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, - getHandle()); + ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle()); } catch (InvocationTargetException e) { throw new RuntimeException("Cannot send packet.", e); } @@ -84,8 +83,7 @@ public void broadcastPacket() { */ public void receivePacket(Player sender) { try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, - getHandle()); + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); } catch (Exception e) { throw new RuntimeException("Cannot receive packet.", e); } From 59a7600e8ea8870dcc32119aebd94d3fac201279 Mon Sep 17 00:00:00 2001 From: Photon-GitHub Date: Thu, 11 Oct 2018 01:44:51 +0200 Subject: [PATCH 4/4] Correct the intendation. --- .../packetwrapper/AbstractPacket.java | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java index 85ed046f..63f496e6 100644 --- a/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java +++ b/PacketWrapper/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java @@ -2,17 +2,17 @@ * PacketWrapper - ProtocolLib wrappers for Minecraft packets * Copyright (C) dmulloy2 * Copyright (C) Kristian S. Strangeland - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -29,63 +29,63 @@ import com.google.common.base.Objects; public abstract class AbstractPacket { - // The packet we will be modifying - protected PacketContainer handle; + // The packet we will be modifying + protected PacketContainer handle; - /** - * Constructs a new strongly typed wrapper for the given packet. - * - * @param handle - handle to the raw packet data. - * @param type - the packet type. - */ - protected AbstractPacket(PacketContainer handle, PacketType type) { - // Make sure we're given a valid packet - Preconditions.checkNotNull(handle, "Packet handle cannot be NULL."); + /** + * Constructs a new strongly typed wrapper for the given packet. + * + * @param handle - handle to the raw packet data. + * @param type - the packet type. + */ + protected AbstractPacket(PacketContainer handle, PacketType type) { + // Make sure we're given a valid packet + Preconditions.checkNotNull(handle, "Packet handle cannot be NULL."); Preconditions.checkArgument(Objects.equal(handle.getType(), type), handle.getHandle() + " is not a packet of type " + type); - this.handle = handle; - } + this.handle = handle; + } - /** - * Retrieve a handle to the raw packet data. - * - * @return Raw packet data. - */ - public PacketContainer getHandle() { - return handle; - } + /** + * Retrieve a handle to the raw packet data. + * + * @return Raw packet data. + */ + public PacketContainer getHandle() { + return handle; + } - /** - * Send the current packet to the given receiver. - * - * @param receiver - the receiver. - * @throws RuntimeException If the packet cannot be sent. - */ - public void sendPacket(Player receiver) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle()); - } catch (InvocationTargetException e) { - throw new RuntimeException("Cannot send packet.", e); - } - } + /** + * Send the current packet to the given receiver. + * + * @param receiver - the receiver. + * @throws RuntimeException If the packet cannot be sent. + */ + public void sendPacket(Player receiver) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle()); + } catch (InvocationTargetException e) { + throw new RuntimeException("Cannot send packet.", e); + } + } - /** - * Send the current packet to all online players. - */ - public void broadcastPacket() { - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); - } + /** + * Send the current packet to all online players. + */ + public void broadcastPacket() { + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); + } - /** - * Simulate receiving the current packet from the given sender. - * - * @param sender - the sender. - * @throws RuntimeException if the packet cannot be received. - */ - public void receivePacket(Player sender) { - try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); - } catch (Exception e) { - throw new RuntimeException("Cannot receive packet.", e); - } - } + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException if the packet cannot be received. + */ + public void receivePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot receive packet.", e); + } + } }