Compare commits

...
6 Commits
Author SHA1 Message Date
retrooper ba1a4afa79 1.5.9 packetevents release 2020-08-24 15:47:15 +02:00
retrooper d2925592fc 1.5.9 bug fixes, about to release 2020-08-24 15:35:24 +02:00
retrooper d97c1a03ee 1.5.9 pre release 2020-08-24 14:33:24 +02:00
retrooper a1d48d3b20 Release 1.5.8.2
* Code cleanup
* PacketReceiveEvent#getNMSPacketClass() deprecated
* PacketReceiveEvent#getPacketName() deprecated
* PacketSendEvent#getNMSPacketClass() deprecated
* PacketSendEvent#getPacketName() deprecated
* PlayerUninjectEvent#PlayerUninjectEvent(Player player, boolean sync) deprecated, use PlayerUninjectEvent#PlayerUninjectEvent(Player player)
* WrappedPacketInBlockDig null pointers fixed for 1.7.10, just Direction field will be Direction.NULL, I will fix later
* Clientbound wrappers cleaned up
2020-08-19 16:46:21 +02:00
retrooper 4ce0463465 Release 1.5.8.2
* WrappedPacketInBlockDig fixed for 1.7.10.
Only the Direction field is set to Direction.NULL.
I cannot get it to work, this is a quick solution for now.
2020-08-19 16:07:57 +02:00
retrooper 6725caad36 Release 1.5.8.1, pom fix attempt, Jitpack release failed so this should fix it 2020-08-17 19:56:06 +02:00
43 changed files with 276 additions and 319 deletions

No files matched your search

+23 -1
View File
@@ -6,7 +6,29 @@
<groupId>io.github.retrooper</groupId>
<artifactId>packetevents</artifactId>
<version>1.5.8</version>
<version>1.5.9</version>
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<name>packetevents</name>
@@ -1,17 +1,13 @@
package io.github.retrooper.packetevents;
import io.github.retrooper.packetevents.annotations.PacketHandler;
import io.github.retrooper.packetevents.api.PacketEventsAPI;
import io.github.retrooper.packetevents.enums.ClientVersion;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.BukkitMoveEvent;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.in.settings.WrappedPacketInSettings;
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
import io.github.retrooper.packetevents.utils.onlineplayers.OnlinePlayerUtilities;
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -22,14 +18,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
public final class PacketEvents implements PacketListener, Listener {
private static Plugin plugin;
private static final PacketEventsAPI packetEventsAPI = new PacketEventsAPI();
private static final PacketEvents instance = new PacketEvents();
private static boolean hasLoaded, hasStarted;
private static final PacketEventsSettings settings = new PacketEventsSettings();
private static Plugin plugin;
private static boolean hasLoaded, hasStarted;
/**
* Call this before start()
@@ -60,7 +54,7 @@ public final class PacketEvents implements PacketListener, Listener {
Bukkit.getPluginManager().registerEvents(instance, plugin);
for (final Player p : OnlinePlayerUtilities.getOnlinePlayers()) {
for (final Player p : Bukkit.getOnlinePlayers()) {
getAPI().getPlayerUtils().injectPlayer(p);
}
hasStarted = true;
@@ -72,7 +66,7 @@ public final class PacketEvents implements PacketListener, Listener {
*/
public static void stop() {
if (hasStarted) {
for (final Player p : OnlinePlayerUtilities.getOnlinePlayers()) {
for (final Player p : Bukkit.getOnlinePlayers()) {
getAPI().getPlayerUtils().uninjectPlayerNow(p);
}
@@ -1,6 +1,6 @@
package io.github.retrooper.packetevents.annotations;
import io.github.retrooper.packetevents.annotations.data.EventSynchronization;
import io.github.retrooper.packetevents.enums.EventSynchronization;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -1,5 +0,0 @@
package io.github.retrooper.packetevents.annotations.data;
public enum EventSynchronization {
FORCE_SYNC, FORCE_ASYNC, NORMAL
}
@@ -11,6 +11,7 @@ public enum ClientVersion {
v_1_15, v_1_15_1, v_1_15_2, v_1_16, v_1_16_PRE_1, v_1_16_PRE_2, v_1_16_PRE_3, v_1_16_PRE_4, v_1_16_PRE_5, v_1_16_PRE_6, v_1_16_PRE_7, v_1_16_PRE_8, v_1_16_RC_1, v_1_16_1, v_1_16_2, HIGHER_THAN_V_1_16_2, INVALID, ACCESS_FAILURE;
private static final Map<Integer, ClientVersion> VERSION_LOOKUP = new HashMap<Integer, ClientVersion>();
public static void prepareLookUp() {
VERSION_LOOKUP.put(-1, ACCESS_FAILURE);
VERSION_LOOKUP.put(1, LESS_THAN_V_1_7_10);
@@ -0,0 +1,5 @@
package io.github.retrooper.packetevents.enums;
public enum EventSynchronization {
NORMAL, FORCE_SYNC, FORCE_ASYNC
}
@@ -3,8 +3,6 @@ package io.github.retrooper.packetevents.enums;
import io.github.retrooper.packetevents.PacketEvents;
import org.bukkit.Bukkit;
import java.util.HashMap;
/**
* @author retrooper
*/
@@ -12,9 +10,10 @@ public enum ServerVersion {
v_1_7_10, v_1_8, v_1_8_3, v_1_8_8, v_1_9, v_1_9_4, v_1_10, v_1_11, v_1_12, v_1_13, v_1_13_2, v_1_14, v_1_15, v_1_16, v_1_16_1, v_1_16_2,
ERROR, EMPTY;
public static ServerVersion[] reversedValues;
private static final String nmsVersionSuffix = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
public static ServerVersion[] reversedValues;
private static ServerVersion cachedVersion;
private static ServerVersion getVers() {
for (final ServerVersion val : reversedValues) {
String valName = val.name().substring(2).replace("_", ".");
@@ -133,10 +132,10 @@ public enum ServerVersion {
if (this.equals(ServerVersion.v_1_16)) {
return 735;
}
if(this.equals(ServerVersion.v_1_16_1)) {
if (this.equals(ServerVersion.v_1_16_1)) {
return 736;
}
if(this.equals(ServerVersion.v_1_16_2)) {
if (this.equals(ServerVersion.v_1_16_2)) {
return 737;
}
return -1;
@@ -34,14 +34,14 @@ public final class BukkitMoveEvent extends PacketEvent {
return to;
}
public void setCancelled(final boolean val) {
this.cancelled = val;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(final boolean val) {
this.cancelled = val;
}
public void cancel() {
setCancelled(true);
}
@@ -24,8 +24,10 @@ public final class PacketReceiveEvent extends PacketEvent {
}
/**
* Get the packet's name (NMS packet class simple name)
* Get the packet's name (NMS packet class simple name).
* Deprecated, it is recommended not to use this for performance reasons.
*/
@Deprecated
public String getPacketName() {
return this.packet.getClass().getSimpleName();
}
@@ -41,11 +43,13 @@ public final class PacketReceiveEvent extends PacketEvent {
/**
* Get the class of the NMS packet object
* Deprecated, as it is useless, rather use getNMSPacket().getClass()
*
* @return packet object class
*/
@Deprecated
public Class<?> getNMSPacketClass() {
return getNMSPacket().getClass();
return packet.getClass();
}
/**
@@ -54,11 +58,7 @@ public final class PacketReceiveEvent extends PacketEvent {
* @return packet id
*/
public byte getPacketId() {
Byte id = PacketType.Client.packetIds.get(getNMSPacketClass());
if (id == null) {
return -1;
}
return id;
return PacketType.Client.packetIds.getOrDefault(packet.getClass(), (byte) -1);
}
/**
@@ -23,7 +23,9 @@ public final class PacketSendEvent extends PacketEvent {
/**
* Get the packet's name (NMS packet class simple name)
* Deprecated, it is recommended not to use this for performance reasons.
*/
@Deprecated
public String getPacketName() {
return this.packet.getClass().getSimpleName();
}
@@ -34,12 +36,7 @@ public final class PacketSendEvent extends PacketEvent {
* @return packet id
*/
public byte getPacketId() {
Byte id =
PacketType.Server.packetIds.get(getNMSPacketClass());
if (id == null) {
return -1;
}
return id;
return PacketType.Server.packetIds.getOrDefault(packet.getClass(), (byte) -1);
}
/**
@@ -52,12 +49,14 @@ public final class PacketSendEvent extends PacketEvent {
}
/**
* Get the class of the NMS packet object
* Get the class of the NMS packet object.
* Deprecated because it is useless, rather use getNMSPacket().getClass().
*
* @return packet object class
*/
@Deprecated
public Class<?> getNMSPacketClass() {
return getNMSPacket().getClass();
return packet.getClass();
}
public boolean isCancelled() {
@@ -5,14 +5,20 @@ import org.bukkit.entity.Player;
public final class PlayerUninjectEvent extends PacketEvent {
private final Player player;
private boolean cancelled;
private final boolean sync;
private boolean cancelled;
public PlayerUninjectEvent(final Player player, final boolean sync) {
@Deprecated
public PlayerUninjectEvent(final Player player, @Deprecated final boolean sync) {
this.player = player;
this.sync = sync;
}
public PlayerUninjectEvent(final Player player) {
this.player = player;
this.sync = true;
}
public void cancel() {
setCancelled(true);
}
@@ -31,7 +37,9 @@ public final class PlayerUninjectEvent extends PacketEvent {
* By default all uninjections are called aynchronously in this build.
*
* @return If the uninjection was done async or sync
* @deprecated because it is unneeded
*/
@Deprecated
public boolean isSync() {
return sync;
}
@@ -2,7 +2,6 @@ package io.github.retrooper.packetevents.event.manager;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.annotations.PacketHandler;
import io.github.retrooper.packetevents.annotations.data.EventSynchronization;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketListener;
import org.bukkit.Bukkit;
@@ -12,21 +11,10 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class EventManager {
private final ExecutorService executorService;
private final HashMap<PacketListener, List<Method>> registeredMethods = new HashMap<PacketListener, List<Method>>();
public EventManager(final int threadCount) {
executorService = Executors.newFixedThreadPool(threadCount);
}
public EventManager() {
this(Runtime.getRuntime().availableProcessors());
}
public void callEvent(final PacketEvent e) {
for (final PacketListener listener : registeredMethods.keySet()) {
//Annotated methods
@@ -46,12 +34,21 @@ public final class EventManager {
}
}
};
if (annotation.synchronization() == EventSynchronization.FORCE_ASYNC) {
executorService.execute(invokeMethod);
} else if (annotation.synchronization() == EventSynchronization.FORCE_SYNC) {
Bukkit.getScheduler().runTask(PacketEvents.getPlugin(), invokeMethod);
} else {
invokeMethod.run();
switch (annotation.synchronization()) {
case FORCE_ASYNC:
Bukkit.getScheduler().runTaskAsynchronously(PacketEvents.getPlugin(), invokeMethod);
break;
case FORCE_SYNC:
Bukkit.getScheduler().runTask(PacketEvents.getPlugin(), invokeMethod);
break;
default:
try {
method.invoke(listener, e);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
break;
}
}
}
@@ -2,13 +2,12 @@ package io.github.retrooper.packetevents.example;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.annotations.PacketHandler;
import io.github.retrooper.packetevents.enums.EventSynchronization;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import io.github.retrooper.packetevents.packetwrappers.in.armanimation.WrappedPacketInArmAnimation;
import io.github.retrooper.packetevents.packetwrappers.in.custompayload.WrappedPacketInCustomPayload;
import io.github.retrooper.packetevents.packetwrappers.in.helditemslot.WrappedPacketInHeldItemSlot;
import io.github.retrooper.packetevents.packetwrappers.in.settings.WrappedPacketInSettings;
import io.github.retrooper.packetevents.packetwrappers.out.entity.WrappedPacketOutEntity;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
public class MainExample extends JavaPlugin implements PacketListener {
@@ -24,15 +23,16 @@ public class MainExample extends JavaPlugin implements PacketListener {
PacketEvents.getSettings().setIdentifier("official_api");
PacketEvents.start(this);
//If packetevents cannot detect your server version, it will use the default you specify version
//If PacketEvents cannot detect your server version, it will use the default you specify version
// getAPI().getSettings().setDefaultServerVersion(ServerVersion.v_1_7_10);
PacketEvents.getAPI().getEventManager().registerListeners(this);
// PacketEvents.getAPI().getEventManager().registerListeners(this);
}
@Override
public void onDisable() {
PacketEvents.stop();
}
}
@@ -34,7 +34,7 @@ public class NettyPacketHandler {
public static Future<?> uninjectPlayer(final Player player) {
try {
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player, false);
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(uninjectEvent);
if (!uninjectEvent.isCancelled()) {
if (v1_7_nettyMode) {
@@ -51,7 +51,7 @@ public class NettyPacketHandler {
public static void uninjectPlayerNow(final Player player) {
try {
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player, true);
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(uninjectEvent);
if (!uninjectEvent.isCancelled()) {
if (v1_7_nettyMode) {
@@ -2,11 +2,7 @@ package io.github.retrooper.packetevents.handler;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.utils.NMSUtils;
import net.minecraft.util.io.netty.channel.Channel;
import net.minecraft.util.io.netty.channel.ChannelDuplexHandler;
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
import net.minecraft.util.io.netty.channel.ChannelPipeline;
import net.minecraft.util.io.netty.channel.ChannelPromise;
import net.minecraft.util.io.netty.channel.*;
import org.bukkit.entity.Player;
import java.util.concurrent.Future;
@@ -2,11 +2,7 @@ package io.github.retrooper.packetevents.handler;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.utils.NMSUtils;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.channel.*;
import org.bukkit.entity.Player;
import java.util.concurrent.Future;
@@ -5,19 +5,8 @@ import java.util.Map;
public class PacketType {
public static class Client {
public static class Util {
public static boolean isInstanceOfFlying(final byte packetId) {
return packetId == FLYING
|| packetId == POSITION
|| packetId == POSITION_LOOK
|| packetId == LOOK;
}
}
public static final Map<Class<?>, Byte> packetIds = new HashMap<Class<?>, Byte>();
public static final byte TELEPORT_ACCEPT = 0,
TILE_NBT_QUERY = 1, DIFFICULTY_CHANGE = 2, CHAT = 3, CLIENT_COMMAND = 4,
SETTINGS = 5, TAB_COMPLETE = 6, TRANSACTION = 7, ENCHANT_ITEM = 8,
@@ -81,6 +70,15 @@ public class PacketType {
packetIds.put(PacketTypeClasses.Client.USE_ITEM, USE_ITEM);
packetIds.put(PacketTypeClasses.Client.BLOCK_PLACE, BLOCK_PLACE);
}
public static class Util {
public static boolean isInstanceOfFlying(final byte packetId) {
return packetId == FLYING
|| packetId == POSITION
|| packetId == POSITION_LOOK
|| packetId == LOOK;
}
}
}
public static class Server {
@@ -205,6 +203,13 @@ public class PacketType {
packetIds.put(PacketTypeClasses.Server.TAGS, TAGS);
packetIds.put(PacketTypeClasses.Server.MAP_CHUNK_BULK, MAP_CHUNK_BULK);
}
public static class Util {
public static boolean isInstanceOfEntity(final byte packetId) {
return packetId == ENTITY || packetId == REL_ENTITY_MOVE ||
packetId == REL_ENTITY_MOVE_LOOK || packetId == ENTITY_LOOK;
}
}
}
@@ -6,6 +6,9 @@ import io.github.retrooper.packetevents.utils.NMSUtils;
public class PacketTypeClasses {
public static class Client {
private static final 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,
@@ -17,9 +20,6 @@ public class PacketTypeClasses {
AUTO_RECIPE, RECIPE_DISPLAYED, ITEM_NAME, RESOURCE_PACK_STATUS,
ADVANCEMENTS, TR_SEL, BEACON, SET_COMMAND_BLOCK,
SET_COMMAND_MINECART, SET_JIGSAW, STRUCT, UPDATE_SIGN, SPECTATE;
private static final String c = "PacketPlayIn";
@Nullable
public static final Class<?> FLYING = NMSUtils.getNMSClassWithoutException(c + "Flying");
public static void load() {
try {
@@ -8,6 +8,11 @@ public class WrappedPacket {
protected final Player player;
protected Object packet;
public WrappedPacket() {
this.player= null;
this.packet = null;
}
public WrappedPacket(final Object packet) {
this.player = null;
if (packet == null) return;
@@ -1,7 +1,6 @@
package io.github.retrooper.packetevents.packetwrappers.in.armanimation;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
//TODO: Test on 1.9, 1.11, 1.13, 1.14
@@ -23,11 +23,13 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
e.printStackTrace();
}
try {
digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType");
} catch (ClassNotFoundException e) {
//It is probably a subclass
digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType");
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
try {
digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType");
} catch (ClassNotFoundException e) {
//It is probably a subclass
digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType");
}
}
}
@@ -43,12 +45,15 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
protected void setup() {
Direction enumDirection = null;
PlayerDigType enumDigType = null;
int x = 0, y = 0, z = 0;
//1.7.10
try {
if (version.isLowerThan(ServerVersion.v_1_8)) {
setupCoordinates(blockDigClass, packet);
enumDirection = Direction.get(Reflection.getField(digTypeClass, int.class, 3).getInt(packet));
enumDigType = PlayerDigType.get(Reflection.getField(digTypeClass, int.class, 4).getInt(packet));
enumDigType = PlayerDigType.get(Reflection.getField(blockDigClass, int.class, 4).getInt(packet));
x = Reflection.getField(blockDigClass, int.class, 0).getInt(packet);
y = Reflection.getField(blockDigClass, int.class, 1).getInt(packet);
z = Reflection.getField(blockDigClass, int.class, 2).getInt(packet);
enumDirection = null;
} else {
//1.8+
final Object blockPosObj = Reflection.getField(blockDigClass, blockPositionClass, 0).get(packet);
@@ -56,7 +61,9 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
final Object digTypeObj = Reflection.getField(blockDigClass, digTypeClass, 0).get(packet);
Class<?> blockPosSuper = blockPositionClass;
setupCoordinates(blockPosSuper, blockPosObj);
x = Reflection.getField(blockPosSuper, int.class, 0).getInt(blockPosObj);
y = Reflection.getField(blockPosSuper, int.class, 1).getInt(blockPosObj);
z = Reflection.getField(blockPosSuper, int.class, 2).getInt(blockPosObj);
enumDirection = Direction.valueOf(((Enum) enumDirectionObj).name());
enumDigType = PlayerDigType.valueOf(((Enum) digTypeObj).name());
@@ -64,16 +71,13 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
this.direction = enumDirection;
this.digType = enumDigType;
}
private void setupCoordinates(final Class<?> cls, final Object object) throws IllegalAccessException {
final int x = Reflection.getField(cls, int.class, 0).getInt(object);
final int y = Reflection.getField(cls, int.class, 1).getInt(object);
final int z = Reflection.getField(cls, int.class, 2).getInt(object);
this.blockPosition = new Vector3i(x, y, z);
if (enumDirection == null) {
this.direction = Direction.NULL;
} else {
this.direction = enumDirection;
}
this.digType = enumDigType;
}
public Vector3i getBlockPosition() {
@@ -2,7 +2,6 @@ package io.github.retrooper.packetevents.packetwrappers.in.clientcommand;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.enums.minecraft.PlayerAction;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
@@ -16,9 +15,9 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInClientCommand");
if(version.isHigherThan(ServerVersion.v_1_7_10)) {
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
enumClientCommandClass = Reflection.getSubClass(packetClass, "EnumClientCommand");
}else {
} else {
enumClientCommandClass = NMSUtils.getNMSClass("EnumClientCommand");
}
} catch (Exception e) {
@@ -35,8 +34,8 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
@Override
public void setup() {
try {
if(version.isLowerThan(ServerVersion.v_1_8)) {
clientCommand = ClientCommand.get(Reflection.getField(enumClientCommandClass, int.class, 1).getInt(packet));
if (version.isLowerThan(ServerVersion.v_1_8)) {
clientCommand = ClientCommand.values()[(Reflection.getField(enumClientCommandClass, int.class, 1).getInt(packet))];
} else {
final Object enumObj = Reflection.getField(packetClass, enumClientCommandClass, 0).get(packet);
this.clientCommand = ClientCommand.valueOf(enumObj.toString());
@@ -50,17 +49,10 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
return clientCommand;
}
public static enum ClientCommand {
public enum ClientCommand {
PERFORM_RESPAWN,
REQUEST_STATS,
OPEN_INVENTORY_ACHIEVEMENT;
private ClientCommand() {
}
public static ClientCommand get(final int i) {
return values()[i];
}
}
}
@@ -14,7 +14,7 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
} catch (Exception e) {
e.printStackTrace();
}
try{
try {
//Only on 1.13+
nmsMinecraftKey = NMSUtils.getNMSClass("MinecraftKey");
} catch (Exception e) {
@@ -31,7 +31,7 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
@Override
public void setup() {
if(Reflection.getField(packetClass, String.class, 0) == null) {
if (Reflection.getField(packetClass, String.class, 0) == null) {
try {
this.minecraftKey = Reflection.getField(packetClass, nmsMinecraftKey, 0).get(packet);
this.dataSerializer = Reflection.getField(packetClass, nmsPacketDataSerializer, 0).get(packet);
@@ -40,7 +40,7 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
}
} else {
try {
this.data = (String)Reflection.getField(packetClass, String.class, 0).get(packet);
this.data = (String) Reflection.getField(packetClass, String.class, 0).get(packet);
this.dataSerializer = Reflection.getField(packetClass, nmsPacketDataSerializer, 0).get(packet);
} catch (Exception e) {
//intentionally empty, allegedly 1.7.10 produces a NPE?
@@ -51,7 +51,7 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
public String getData() {
return data;
}
public Object getMinecraftKey() {
return minecraftKey;
}
@@ -11,6 +11,7 @@ import java.util.HashMap;
public class WrappedPacketInSettings extends WrappedPacket {
private static Class<?> packetClass;
private static Class<?> chatVisibilityEnumClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInSettings");
@@ -27,25 +28,19 @@ public class WrappedPacketInSettings extends WrappedPacket {
}
}
public enum ChatVisibility {
ENABLED, COMMANDS_ONLY, HIDDEN
}
public enum DisplayedSkinPart {
CAPE, JACKET, LEFT_SLEEVE, RIGHT_SLEEVE, LEFT_PANTS, RIGHT_PANTS, HAT
}
private String locale;
private byte viewDistance;
private ChatVisibility chatVisibility;
private boolean chatColors;
private HashMap<DisplayedSkinPart, Boolean> displayedSkinParts;
public WrappedPacketInSettings(final Object packet) {
super(packet);
}
public static Class<?> getChatVisibilityEnumClass() {
return chatVisibilityEnumClass;
}
@Override
protected void setup() {
try {
@@ -57,13 +52,11 @@ public class WrappedPacketInSettings extends WrappedPacket {
//CHAT VISIBILITY
Object chatVisibilityEnumObject = Reflection.getField(packetClass, chatVisibilityEnumClass, 0).get(packet);
String enumValueAsString = chatVisibilityEnumObject.toString();
if(enumValueAsString.equals("FULL")) {
if (enumValueAsString.equals("FULL")) {
chatVisibility = ChatVisibility.ENABLED;
}
else if(enumValueAsString.equals("SYSTEM")) {
} else if (enumValueAsString.equals("SYSTEM")) {
chatVisibility = ChatVisibility.COMMANDS_ONLY;
}
else {
} else {
chatVisibility = ChatVisibility.HIDDEN;
}
@@ -73,12 +66,11 @@ public class WrappedPacketInSettings extends WrappedPacket {
//DISPLAYED SKIN PARTS
this.displayedSkinParts = new HashMap<DisplayedSkinPart, Boolean>();
if(version.isLowerThan(ServerVersion.v_1_8)) {
if (version.isLowerThan(ServerVersion.v_1_8)) {
//in 1.7.10 only the cape display skin part is sent
boolean capeEnabled = Reflection.getField(packetClass, boolean.class, 1).getBoolean(packet);
displayedSkinParts.put(DisplayedSkinPart.CAPE, capeEnabled);
}
else {
} else {
//in 1.8, all the skin parts are sent
int skinPartFlags = Reflection.getField(packetClass, int.class, 1).getInt(packet);
displayedSkinParts.put(DisplayedSkinPart.CAPE, (skinPartFlags & 0x01) != 0);
@@ -96,10 +88,6 @@ public class WrappedPacketInSettings extends WrappedPacket {
}
public static Class<?> getChatVisibilityEnumClass() {
return chatVisibilityEnumClass;
}
public String getLocale() {
return locale;
}
@@ -129,14 +117,23 @@ public class WrappedPacketInSettings extends WrappedPacket {
/**
* On 1.7.10, some skin parts will default to 'false' as 1.7.10
* only sends the 'cape' skin part.
*
* @param part
* @return
*/
public boolean isDisplaySkinPartEnabled(DisplayedSkinPart part) {
//1.7.10, we will default the other skin parts to return false.
if(!displayedSkinParts.containsKey(part)) {
return false;
if (!displayedSkinParts.containsKey(part)) {
return false;
}
return displayedSkinParts.get(part);
}
public enum ChatVisibility {
ENABLED, COMMANDS_ONLY, HIDDEN
}
public enum DisplayedSkinPart {
CAPE, JACKET, LEFT_SLEEVE, RIGHT_SLEEVE, LEFT_PANTS, RIGHT_PANTS, HAT
}
}
@@ -32,7 +32,6 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
}
private int entityId;
private Entity entity;
private EntityUseAction action;
public WrappedPacketInUseEntity(final Object packet) {
@@ -43,7 +42,6 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
protected void setup() {
try {
this.entityId = Reflection.getField(useEntityClass, int.class, 0).getInt(packet);
this.entity = NMSUtils.getEntityById(this.entityId);
final Object useActionEnum = Reflection.getField(useEntityClass, enumEntityUseActionClass, 0).get(packet);
this.action = EntityUseAction.valueOf(useActionEnum.toString());
} catch (IllegalAccessException e) {
@@ -52,7 +50,7 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
}
public Entity getEntity() {
return entity;
return NMSUtils.getEntityById(this.entityId);
}
public int getEntityId() {
@@ -35,7 +35,7 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
public WrappedPacketOutAbilities(final boolean isVulnerable, final boolean isFlying, final boolean allowFlight, final boolean canBuildInstantly,
final float flySpeed, final float walkSpeed) {
super(null);
super();
this.vulnerable = isVulnerable;
this.flying = isFlying;
this.allowFlight = allowFlight;
@@ -38,7 +38,7 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
}
public WrappedPacketOutAnimation(final Entity target, final EntityAnimationType type) {
super(null);
super();
this.entityID = target.getEntityId();
this.entity = target;
this.type = type;
@@ -44,7 +44,7 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
}
public WrappedPacketOutChat(final String message) {
super(null);
super();
this.message = "{\"text\": \"" + message + "\"}";
}
@@ -1,16 +1,47 @@
package io.github.retrooper.packetevents.packetwrappers.out.entity;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.entity.Entity;
import java.lang.reflect.Field;
public class WrappedPacketOutEntity extends WrappedPacket {
private int entityId;
private static Class<?> packetClass;
private static byte mode = 0; //byte = 0, int = 1, short = 2
private static double dXYZDivisor = 0.0;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutEntity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Field dxField = Reflection.getField(packetClass, 1);
if (dxField.equals(Reflection.getField(packetClass, byte.class, 0))) {
mode = 0;
} else if (dxField.equals(Reflection.getField(packetClass, int.class, 1))) {
mode = 1;
} else if (dxField.equals(Reflection.getField(packetClass, short.class, 0))) {
mode = 2;
}
if (mode == 0) {
dXYZDivisor = 32.0;
} else {
dXYZDivisor = 4096.0;
}
}
private int entityID;
private double deltaX, deltaY, deltaZ;
private byte yaw, pitch;
private boolean onGround;
public WrappedPacketOutEntity(Object packet) {
super(packet);
}
@@ -18,38 +49,42 @@ public class WrappedPacketOutEntity extends WrappedPacket {
@Override
protected void setup() {
try {
this.entityId = Reflection.getField(packetClass, int.class, 0).getInt(packet);
this.entityID = Reflection.getField(packetClass, int.class, 0).getInt(packet);
this.onGround = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
if (version.isLowerThan(ServerVersion.v_1_9)) {
byte dX = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
byte dY = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
byte dZ = Reflection.getField(packetClass, byte.class, 2).getByte(packet);
int dX = 1, dY = 1, dZ = 1;
this.deltaX = dX / 32.0;
this.deltaY = dY / 32.0;
this.deltaZ = dZ / 32.0;
this.yaw = Reflection.getField(packetClass, byte.class, 3).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 4).getByte(packet);
} else {
short dX = Reflection.getField(packetClass, short.class, 0).getShort(packet);
short dY = Reflection.getField(packetClass, short.class, 1).getShort(packet);
short dZ = Reflection.getField(packetClass, short.class, 2).getShort(packet);
this.deltaX = dX / 4096.0;
this.deltaY = dY / 4096.0;
this.deltaZ = dZ / 4096.0;
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
switch (mode) {
case 0:
dX = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
dY = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
dZ = Reflection.getField(packetClass, byte.class, 2).getByte(packet);
this.yaw = Reflection.getField(packetClass, byte.class, 3).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 4).getByte(packet);
break;
case 1:
dX = Reflection.getField(packetClass, int.class, 1).getInt(packet);
dY = Reflection.getField(packetClass, int.class, 2).getInt(packet);
dZ = Reflection.getField(packetClass, int.class, 3).getInt(packet);
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
break;
case 2:
dX = Reflection.getField(packetClass, short.class, 0).getShort(packet);
dY = Reflection.getField(packetClass, short.class, 1).getShort(packet);
dZ = Reflection.getField(packetClass, short.class, 2).getShort(packet);
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
break;
}
this.deltaX = dX / dXYZDivisor;
this.deltaY = dY / dXYZDivisor;
this.deltaZ = dZ / dXYZDivisor;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public byte getPitch() {
return pitch;
}
@@ -70,21 +105,15 @@ public class WrappedPacketOutEntity extends WrappedPacket {
return deltaX;
}
public Entity getEntity() {
return NMSUtils.getEntityById(entityID);
}
public int getEntityId() {
return entityId;
return entityID;
}
public boolean isOnGround() {
return onGround;
}
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutEntity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
@@ -54,7 +54,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
}
public WrappedPacketOutEntityVelocity(final Entity entity, final double velocityX, final double velocityY, final double velocityZ) {
super(null);
super();
this.entityId = entity.getEntityId();
this.entity = entity;
this.velocityX = velocityX;
@@ -3,9 +3,18 @@ package io.github.retrooper.packetevents.packetwrappers.out.keepalive;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import net.minecraft.server.v1_8_R3.PacketPlayOutKeepAlive;
public class WrappedPacketOutKeepAlive extends WrappedPacket {
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutKeepAlive");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private long id;
public WrappedPacketOutKeepAlive(Object packet) {
@@ -38,15 +47,4 @@ public class WrappedPacketOutKeepAlive extends WrappedPacket {
}
}
}
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutKeepAlive");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
PacketPlayOutKeepAlive p;
}
}
@@ -35,7 +35,7 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
}
public WrappedPacketOutKickDisconnect(final String kickMessage) {
super(null);
super();
this.kickMessage = kickMessage;
}
@@ -1,44 +0,0 @@
package io.github.retrooper.packetevents.packetwrappers.out.playerinfo;
import io.github.retrooper.packetevents.enums.minecraft.Gamemode;
import io.github.retrooper.packetevents.enums.minecraft.PlayerInfoAction;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
public class WrappedPacketOutPlayerInfo extends WrappedPacket {
private PlayerInfoAction action;
public WrappedPacketOutPlayerInfo(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketPlayOutPlayerInfo.PlayerInfoData dl;
}
private static Class<?> packetClass, enumPlayerInfoActionClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutPlayerInfo");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
enumPlayerInfoActionClass = NMSUtils.getNMSClass("EnumPLayerInfoAction");
} catch (ClassNotFoundException e) {
enumPlayerInfoActionClass = Reflection.getSubClass(packetClass, "EnumPlayerInfoAction");
}
}
public class PlayerDataInfo {
public PlayerDataInfo(Object gameProfile, int var, Gamemode gamemode, String s) {
}
}
}
@@ -35,7 +35,7 @@ public class WrappedPacketOutTransaction extends WrappedPacket implements Sendab
}
public WrappedPacketOutTransaction(final int windowId, final short actionNumber, final boolean accepted) {
super(null);
super();
this.windowId = windowId;
this.actionNumber = actionNumber;
this.accepted = accepted;
@@ -41,7 +41,7 @@ public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements
* @param foodSaturation
*/
public WrappedPacketOutUpdateHealth(final float health, final int food, final float foodSaturation) {
super(null);
super();
this.health = health;
this.food = food;
this.foodSaturation = foodSaturation;
@@ -18,7 +18,7 @@ public class FieldWithIndex {
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -27,10 +27,10 @@ public class FieldWithIndex {
return index == that.index &&
Objects.equals(cls, that.cls);
}
@Override
public int hashCode() {
return Objects.hash(cls, index);
}
public int hashCode() {
return Objects.hash(cls, index);
}
}
@@ -19,7 +19,7 @@ public class FieldWithName {
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -28,10 +28,10 @@ public class FieldWithName {
return name.equals(that.name) &&
Objects.equals(cls, that.cls);
}
@Override
public int hashCode() {
return Objects.hash(cls, name);
}
public int hashCode() {
return Objects.hash(cls, name);
}
}
@@ -23,7 +23,7 @@ public class FieldWithTypeAndIndex {
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -33,10 +33,10 @@ public class FieldWithTypeAndIndex {
Objects.equals(cls, that.cls) &&
Objects.equals(type, that.type);
}
@Override
public int hashCode() {
return Objects.hash(cls, type, index);
}
public int hashCode() {
return Objects.hash(cls, type, index);
}
}
@@ -24,7 +24,7 @@ public class MethodWithIndexAndParams {
public Class<?>[] getParams() {
return params;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -34,10 +34,10 @@ public class MethodWithIndexAndParams {
Objects.equals(cls, that.cls) &&
Objects.equals(params, that.params);
}
@Override
public int hashCode() {
return Objects.hash(cls, params, index);
}
public int hashCode() {
return Objects.hash(cls, params, index);
}
}
@@ -16,9 +16,9 @@ import java.lang.reflect.Method;
public final class NMSUtils {
private static final ServerVersion version = ServerVersion.getVersion();
public static String nettyPrefix;
private static final String nmsDir = ServerVersion.getNMSDirectory();
private static final String obcDir = ServerVersion.getOBCDirectory();
public static String nettyPrefix;
public static Class<?> minecraftServerClass, craftWorldsClass,
packetClass, entityPlayerClass, playerConnectionClass,
craftPlayerClass, serverConnectionClass, craftEntityClass,
@@ -1,16 +0,0 @@
package io.github.retrooper.packetevents.utils.onlineplayers;
import io.github.retrooper.packetevents.enums.ServerVersion;
import org.bukkit.entity.Player;
public class OnlinePlayerUtilities {
private static final ServerVersion version = ServerVersion.getVersion();
public static Player[] getOnlinePlayers() {
if (version.isLowerThan(ServerVersion.v_1_9)) {
return OnlinePlayerUtils_8.getOnlinePlayers();
} else {
return OnlinePlayerUtils_9.getOnlinePlayers();
}
}
}
@@ -1,12 +0,0 @@
package io.github.retrooper.packetevents.utils.onlineplayers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class OnlinePlayerUtils_8 {
public static Player[] getOnlinePlayers() {
return Bukkit.getServer().getOnlinePlayers().toArray(new Player[0]);
}
}
@@ -1,10 +0,0 @@
package io.github.retrooper.packetevents.utils.onlineplayers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class OnlinePlayerUtils_9 {
public static Player[] getOnlinePlayers() {
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
}
}