Commit 70b1c22e8151a7d2b087cc92d465e3a3b9ea8b32
1 parent
8e714482
don't pass handled packet events to packet handlers, they should implement the a…
…ppropriate interface instead
Showing
1 changed file
with
16 additions
and
12 deletions
java/common/com/mumfrey/liteloader/core/PacketEvents.java
| @@ -131,17 +131,17 @@ public abstract class PacketEvents implements InterfaceProvider | @@ -131,17 +131,17 @@ public abstract class PacketEvents implements InterfaceProvider | ||
| 131 | 131 | ||
| 132 | private void handlePacket(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) | 132 | private void handlePacket(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) |
| 133 | { | 133 | { |
| 134 | - this.handlePacketEvent(e, netHandler, packetId); | ||
| 135 | - | ||
| 136 | - if (this.packetHandlers[packetId] == null || e.isCancelled()) | 134 | + if (this.handlePacketEvent(e, netHandler, packetId) || this.packetHandlers[packetId] == null || e.isCancelled()) |
| 137 | { | 135 | { |
| 138 | return; | 136 | return; |
| 139 | } | 137 | } |
| 140 | 138 | ||
| 141 | - if (!this.packetHandlers[packetId].all().handlePacket(netHandler, e.getSource())) | 139 | + if (this.packetHandlers[packetId].all().handlePacket(netHandler, e.getSource())) |
| 142 | { | 140 | { |
| 143 | - e.cancel(); | 141 | + return; |
| 144 | } | 142 | } |
| 143 | + | ||
| 144 | + e.cancel(); | ||
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | /** | 147 | /** |
| @@ -149,46 +149,50 @@ public abstract class PacketEvents implements InterfaceProvider | @@ -149,46 +149,50 @@ public abstract class PacketEvents implements InterfaceProvider | ||
| 149 | * @param netHandler | 149 | * @param netHandler |
| 150 | * @param packetId | 150 | * @param packetId |
| 151 | * @param packet | 151 | * @param packet |
| 152 | + * | ||
| 153 | + * @return true if the packet was handled by a local handler and shouldn't be forwarded to later handlers | ||
| 152 | */ | 154 | */ |
| 153 | - protected void handlePacketEvent(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) | 155 | + protected boolean handlePacketEvent(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) |
| 154 | { | 156 | { |
| 155 | Packet packet = e.getSource(); | 157 | Packet packet = e.getSource(); |
| 156 | 158 | ||
| 157 | if (packetId == this.loginSuccessPacketId) | 159 | if (packetId == this.loginSuccessPacketId) |
| 158 | { | 160 | { |
| 159 | this.handlePacket(e, netHandler, (S02PacketLoginSuccess)packet); | 161 | this.handlePacket(e, netHandler, (S02PacketLoginSuccess)packet); |
| 160 | - return; | 162 | + return true; |
| 161 | } | 163 | } |
| 162 | 164 | ||
| 163 | if (packetId == this.serverChatPacketId) | 165 | if (packetId == this.serverChatPacketId) |
| 164 | { | 166 | { |
| 165 | this.handlePacket(e, netHandler, (S02PacketChat)packet); | 167 | this.handlePacket(e, netHandler, (S02PacketChat)packet); |
| 166 | - return; | 168 | + return true; |
| 167 | } | 169 | } |
| 168 | 170 | ||
| 169 | if (packetId == this.clientChatPacketId) | 171 | if (packetId == this.clientChatPacketId) |
| 170 | { | 172 | { |
| 171 | this.handlePacket(e, netHandler, (C01PacketChatMessage)packet); | 173 | this.handlePacket(e, netHandler, (C01PacketChatMessage)packet); |
| 172 | - return; | 174 | + return true; |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | if (packetId == this.joinGamePacketId) | 177 | if (packetId == this.joinGamePacketId) |
| 176 | { | 178 | { |
| 177 | this.handlePacket(e, netHandler, (S01PacketJoinGame)packet); | 179 | this.handlePacket(e, netHandler, (S01PacketJoinGame)packet); |
| 178 | - return; | 180 | + return true; |
| 179 | } | 181 | } |
| 180 | 182 | ||
| 181 | if (packetId == this.serverPayloadPacketId) | 183 | if (packetId == this.serverPayloadPacketId) |
| 182 | { | 184 | { |
| 183 | this.handlePacket(e, netHandler, (S3FPacketCustomPayload)packet); | 185 | this.handlePacket(e, netHandler, (S3FPacketCustomPayload)packet); |
| 184 | - return; | 186 | + return true; |
| 185 | } | 187 | } |
| 186 | 188 | ||
| 187 | if (packetId == this.clientPayloadPacketId) | 189 | if (packetId == this.clientPayloadPacketId) |
| 188 | { | 190 | { |
| 189 | this.handlePacket(e, netHandler, (C17PacketCustomPayload)packet); | 191 | this.handlePacket(e, netHandler, (C17PacketCustomPayload)packet); |
| 190 | - return; | 192 | + return true; |
| 191 | } | 193 | } |
| 194 | + | ||
| 195 | + return false; | ||
| 192 | } | 196 | } |
| 193 | 197 | ||
| 194 | /** | 198 | /** |