Skip to content

Commit

Permalink
Fix destroy packets that have been modified after the factory returns…
Browse files Browse the repository at this point in the history
… them.
  • Loading branch information
iso2013 committed Jun 17, 2018
1 parent 71687b5 commit 0fefb9c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>PacketEntityAPI</artifactId>
<groupId>net.blitzcube.peapi</groupId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>PacketEntityAPI</artifactId>
<groupId>net.blitzcube.peapi</groupId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.2-SNAPSHOT</version>
</parent>

<artifactId>Plugin</artifactId>
Expand Down Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>net.blitzcube.peapi</groupId>
<artifactId>API</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
2 changes: 2 additions & 0 deletions Plugin/src/main/java/net/blitzcube/peapi/PacketEntityAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.blitzcube.peapi.api.entity.modifier.IEntityModifierRegistry;
import net.blitzcube.peapi.api.entity.modifier.IModifiableEntity;
import net.blitzcube.peapi.api.listener.IListener;
import net.blitzcube.peapi.api.packet.IEntityGroupPacket;
import net.blitzcube.peapi.api.packet.IEntityPacket;
import net.blitzcube.peapi.api.packet.IEntityPacketFactory;
import net.blitzcube.peapi.entity.EntityIdentifier;
Expand Down Expand Up @@ -209,6 +210,7 @@ public void dispatchPacket(IEntityPacket packet, Player target) {

@Override
public void dispatchPacket(IEntityPacket packet, Player target, int delay) {
if (packet instanceof IEntityGroupPacket) ((IEntityGroupPacket) packet).apply();
PacketContainer c = packet.getRawPacket();
if (c == null) return;
if (delay > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.blitzcube.peapi.PacketEntityAPI;
import net.blitzcube.peapi.api.event.IEntityPacketEvent;
import net.blitzcube.peapi.api.packet.IEntityClickPacket;
import net.blitzcube.peapi.api.packet.IEntityDestroyPacket;
import net.blitzcube.peapi.api.packet.IEntityGroupPacket;
import net.blitzcube.peapi.api.packet.IEntityPacket;
import net.blitzcube.peapi.entity.fake.FakeEntity;
Expand Down Expand Up @@ -68,14 +69,14 @@ public void onPacketSending(PacketEvent packetEvent) {
if (w == null) return;
IEntityPacketEvent e = new EntityPacketEvent(manager, w, eT, target);
dispatcher.dispatch(e, null);
if (e.getPacket() instanceof IEntityGroupPacket) {
if ((e.getPacketType() == IEntityPacketEvent.EntityPacketType.DESTROY
&& ((IEntityGroupPacket) e.getPacket()).getGroup().size() == 0) || e.isCancelled()) {
if (w instanceof IEntityGroupPacket) {
if (w instanceof IEntityDestroyPacket && ((IEntityDestroyPacket) w).getGroup().size() == 0) {
packetEvent.setCancelled(true);
return;
}
((IEntityGroupPacket) e.getPacket()).apply();
} else if (e.isCancelled()) {
}
if (e.isCancelled()) {
packetEvent.setCancelled(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>net.blitzcube.peapi</groupId>
<artifactId>PacketEntityAPI</artifactId>
<packaging>pom</packaging>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.2-SNAPSHOT</version>
<modules>
<module>API</module>
<module>Plugin</module>
Expand Down

0 comments on commit 0fefb9c

Please sign in to comment.