diff --git a/pom.xml b/pom.xml index 24d95fee5d..590b6495a2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.retrooper packetevents - 1.3.7.2 + 1.3.8 jar packetevents diff --git a/src/main/java/io/github/retrooper/packetevents/event/impl/PacketReceiveEvent.java b/src/main/java/io/github/retrooper/packetevents/event/impl/PacketReceiveEvent.java index 7443bbfcbb..36dd86add9 100644 --- a/src/main/java/io/github/retrooper/packetevents/event/impl/PacketReceiveEvent.java +++ b/src/main/java/io/github/retrooper/packetevents/event/impl/PacketReceiveEvent.java @@ -34,7 +34,7 @@ public String getPacketName() { } /** - * Get the raw NMS packet object + * Get the NMS packet object * * @return packet object */ @@ -42,6 +42,14 @@ public Object getNMSPacket() { return this.packet; } + /** + * Get the class of the NMS packet object + * @return packet object class + */ + public Class getNMSPacketClass() { + return getNMSPacket().getClass(); + } + /** * Returns if the packet has been cancelled * diff --git a/src/main/java/io/github/retrooper/packetevents/event/impl/PacketSendEvent.java b/src/main/java/io/github/retrooper/packetevents/event/impl/PacketSendEvent.java index 3609783940..7fdbc0fab0 100644 --- a/src/main/java/io/github/retrooper/packetevents/event/impl/PacketSendEvent.java +++ b/src/main/java/io/github/retrooper/packetevents/event/impl/PacketSendEvent.java @@ -28,7 +28,7 @@ public String getPacketName() { /** - * Get the raw NMS packet object + * Get the NMS packet object * * @return packet object */ @@ -36,6 +36,14 @@ public Object getNMSPacket() { return this.packet; } + /** + * Get the class of the NMS packet object + * @return packet object class + */ + public Class getNMSPacketClass() { + return getNMSPacket().getClass(); + } + public boolean isCancelled() { return cancelled; } diff --git a/src/main/java/io/github/retrooper/packetevents/example/MainExample.java b/src/main/java/io/github/retrooper/packetevents/example/MainExample.java index 6061dc380d..97a2781614 100644 --- a/src/main/java/io/github/retrooper/packetevents/example/MainExample.java +++ b/src/main/java/io/github/retrooper/packetevents/example/MainExample.java @@ -11,6 +11,7 @@ public class MainExample extends JavaPlugin { public void onEnable() { PacketEvents.start(this); + getAPI().getServerTickTask().cancel(); } diff --git a/src/main/java/io/github/retrooper/packetevents/packet/PacketTypeClasses.java b/src/main/java/io/github/retrooper/packetevents/packet/PacketTypeClasses.java new file mode 100644 index 0000000000..8e04d5b71e --- /dev/null +++ b/src/main/java/io/github/retrooper/packetevents/packet/PacketTypeClasses.java @@ -0,0 +1,48 @@ +package io.github.retrooper.packetevents.packet; + +import io.github.retrooper.packetevents.annotations.Nullable; +import io.github.retrooper.packetevents.utils.NMSUtils; + +public class PacketTypeClasses { + public static class Client { + private static String c = "PacketPlayIn"; + + @Nullable + public static final Class FLYING = NMSUtils.getNMSClassWithoutException(c + "Flying"); + + public static Class POSITION, POSITION_LOOK, LOOK, CLIENT_COMMAND, + TRANSACTION, BLOCK_DIG, ENTITY_ACTION, USE_ENTITY, + WINDOW_CLICK, STEER_VEHICLE, CUSTOM_PAYLOAD, ARM_ANIMATION, + BLOCK_PLACE, ABILITIES, HELD_ITEM_SLOT, CLOSE_WINDOW, + TAB_COMPLETE, CHAT, SET_CREATIVE_SLOT, KEEP_ALIVE; + + static { + try { + POSITION = NMSUtils.getNMSClass(c + "Position"); + POSITION_LOOK = NMSUtils.getNMSClass(c + "PositionLook"); + LOOK = NMSUtils.getNMSClass(c + "Look"); + + CLIENT_COMMAND = NMSUtils.getNMSClass(c + "ClientCommand"); + TRANSACTION = NMSUtils.getNMSClass(c + "Transaction"); + BLOCK_DIG = NMSUtils.getNMSClass(c + "BlockDig"); + ENTITY_ACTION = NMSUtils.getNMSClass(c + "EntityAction"); + USE_ENTITY = NMSUtils.getNMSClass(c + "UseEntity"); + WINDOW_CLICK = NMSUtils.getNMSClass(c + "WindowClick"); + STEER_VEHICLE = NMSUtils.getNMSClass(c + "SteerVehicle"); + CUSTOM_PAYLOAD = NMSUtils.getNMSClass(c + "CustomPayload"); + ARM_ANIMATION = NMSUtils.getNMSClass(c + "ArmAnimation"); + ABILITIES = NMSUtils.getNMSClass(c + "Abilities"); + HELD_ITEM_SLOT = NMSUtils.getNMSClass(c + "HeldItemSlot"); + CLOSE_WINDOW = NMSUtils.getNMSClass(c + "CloseWindow"); + TAB_COMPLETE = NMSUtils.getNMSClass(c + "TabComplete"); + CHAT = NMSUtils.getNMSClass(c + "Chat"); + SET_CREATIVE_SLOT = NMSUtils.getNMSClass(c + "SetCreativeSlot"); + KEEP_ALIVE = NMSUtils.getNMSClass(c + "KeepAlive"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + //Block place + } + } + +} diff --git a/src/main/java/io/github/retrooper/packetevents/utils/NMSUtils.java b/src/main/java/io/github/retrooper/packetevents/utils/NMSUtils.java index 2f9ea88059..f3b4a36737 100644 --- a/src/main/java/io/github/retrooper/packetevents/utils/NMSUtils.java +++ b/src/main/java/io/github/retrooper/packetevents/utils/NMSUtils.java @@ -81,6 +81,15 @@ public static Class getNMSClass(String name) throws ClassNotFoundException { return Class.forName(nmsDir + "." + name); } + public static Class getNMSClassWithoutException(String name) { + try { + return getNMSClass(name); + } catch (ClassNotFoundException e) { + return null; + } + + } + public static Class getOBCClass(String name) throws ClassNotFoundException { return Class.forName(obcDir + "." + name); }