Skip to content

Commit

Permalink
TestExample improved and bugs fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Apr 20, 2020
1 parent 7a3db02 commit 2916e57
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.23.Final</version>
<version>4.1.42.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/purplex/packetevents/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.comphenix.tinyprotocol.*;
import io.netty.channel.Channel;
import me.purplex.packetevents.events.PacketReceiveEvent;
import me.purplex.packetevents.example.TestExample;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/me/purplex/packetevents/example/TestExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,35 @@
import me.purplex.packetevents.events.PacketListener;
import me.purplex.packetevents.events.PacketReceiveEvent;
import me.purplex.packetevents.events.PacketSendEvent;
import me.purplex.packetevents.packets.Packet;

public class TestExample implements PacketListener {
/**
* How to register a packet listener?
*
* PacketEvents.getPacketManager().registerPacketListener(new TestExample());
*/


@PacketHandler
public void onPacketReceive(PacketReceiveEvent e) {

//ONLY CLIENT PACKETS ALLOWED HERE!
if(e.getPacketName().equals(Packet.Client.USE_ENTITY)) {
e.getPlayer().sendMessage("You have attacked an entity!");
}
else if(e.getPacketName().equals(Packet.Client.ARM_ANIMATION)) {
e.getPlayer().sendMessage("You swung your arm.");
}
else if(e.getPacketName().equals(Packet.Client.POSITION)) {
e.getPlayer().sendMessage("You updated your position!");
}
}

@PacketHandler
public void onPacketSend(PacketSendEvent e) {

//ONLY SERVER PACKETS ALLOWED HERE!
if(e.getPacketName().equals(Packet.Server.ENTITY_VELOCITY)) {
e.getPlayer().sendMessage("You took velocity!");
}
}
}

0 comments on commit 2916e57

Please sign in to comment.