Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07692f87f2 | ||
|
|
7f94b254a2 | ||
|
|
ceb3581c28 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>packetevents</name>
|
||||
<properties>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package io.github.retrooper.packetevents;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.enums.ClientVersion;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketLoginEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PlayerInjectEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PostPlayerInjectEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.ServerTickEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.*;
|
||||
import io.github.retrooper.packetevents.event.manager.EventManager;
|
||||
import io.github.retrooper.packetevents.handler.TinyProtocolHandler;
|
||||
import io.github.retrooper.packetevents.packet.Packet;
|
||||
@@ -17,21 +16,20 @@ import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class PacketEvents implements PacketListener{
|
||||
public final class PacketEvents implements PacketListener, Listener {
|
||||
|
||||
|
||||
/*
|
||||
* Login wrappers TODO
|
||||
* PacketLoginInStart
|
||||
* PacketLoginInEncryptionBegin
|
||||
* Wrappers TODO:
|
||||
* Spawn entity
|
||||
*/
|
||||
|
||||
private static boolean hasRegistered;
|
||||
@@ -61,6 +59,7 @@ public final class PacketEvents implements PacketListener{
|
||||
//Register Bukkit and PacketListener
|
||||
getEventManager().registerListener(getInstance());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(getInstance(), plugin);
|
||||
//Initialize the TinyProtocolHandler
|
||||
TinyProtocolHandler.initTinyProtocol(plugin);
|
||||
|
||||
@@ -205,6 +204,13 @@ public final class PacketEvents implements PacketListener{
|
||||
}
|
||||
}
|
||||
|
||||
@PacketHandler
|
||||
public void onPacket(final PacketEvent e) {
|
||||
if(e instanceof PacketReceiveEvent) {
|
||||
// System.out.println("RECEIVED");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not check the client version in or before the PlayerInjectEvent, use the PostPlayerInjectEvent.
|
||||
* It is not recommended to do much in the PlayerInjectEvent, as some fields in the Player object are be null.
|
||||
@@ -219,6 +225,7 @@ public final class PacketEvents implements PacketListener{
|
||||
|
||||
/**
|
||||
* Called after the PlayerJoinEvent ONLY if the player has been injected!
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
@PacketHandler
|
||||
@@ -235,7 +242,7 @@ public final class PacketEvents implements PacketListener{
|
||||
}
|
||||
|
||||
/**
|
||||
* Version independant player injection
|
||||
* Version independent player injection
|
||||
* @param player
|
||||
*/
|
||||
public static void injectPlayer(final Player player) {
|
||||
@@ -244,6 +251,7 @@ public final class PacketEvents implements PacketListener{
|
||||
|
||||
/**
|
||||
* Version independant player injection
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void uninjectPlayer(final Player player) {
|
||||
@@ -252,6 +260,7 @@ public final class PacketEvents implements PacketListener{
|
||||
|
||||
/**
|
||||
* Returns whether we have injected the player
|
||||
*
|
||||
* @param player
|
||||
* @return hasInjected
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.github.retrooper.packetevents.annotations;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
/**
|
||||
* Is for sure not null.
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.github.retrooper.packetevents.event.manager;
|
||||
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -19,8 +19,9 @@ public final class EventManager {
|
||||
//Annotated methods
|
||||
final List<Method> methods = registeredMethods.get(listener);
|
||||
for (final Method method : methods) {
|
||||
if (method.getParameterTypes()[0].equals(PacketEvent.class)
|
||||
|| method.getParameterTypes()[0].getSimpleName().equals(e.getClass().getSimpleName())) {
|
||||
final Class<?> parameterType = method.getParameterTypes()[0];
|
||||
if (parameterType.equals(PacketEvent.class)
|
||||
|| parameterType.isInstance(e)) {
|
||||
try {
|
||||
method.invoke(listener, e);
|
||||
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||
@@ -33,13 +34,19 @@ public final class EventManager {
|
||||
|
||||
|
||||
public void registerListener(final PacketListener e) {
|
||||
if (registeredMethods.containsKey(e)) {
|
||||
return;
|
||||
}
|
||||
final List<Method> methods = new ArrayList<Method>();
|
||||
for (final Method m : e.getClass().getMethods()) {
|
||||
if (m.isAnnotationPresent(PacketHandler.class)) {
|
||||
if (m.isAnnotationPresent(PacketHandler.class)
|
||||
&& m.getParameterTypes().length == 1) {
|
||||
methods.add(m);
|
||||
}
|
||||
}
|
||||
registeredMethods.put(e, methods);
|
||||
if (!methods.isEmpty()) {
|
||||
registeredMethods.put(e, methods);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterListener(final PacketListener e) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.retrooper.packetevents.example;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class MainExample extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PacketEvents.start(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PacketEvents.stop();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.retrooper.packetevents.handler;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketLoginEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
|
||||
@@ -10,8 +11,6 @@ import net.minecraft.util.io.netty.channel.Channel;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
|
||||
public final class TinyProtocolHandler_1_7 {
|
||||
private final Plugin plugin;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.retrooper.packetevents.handler;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketLoginEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
@@ -11,8 +12,6 @@ import io.netty.channel.Channel;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
|
||||
public final class TinyProtocolHandler_1_8 {
|
||||
private static final ServerVersion version = PacketEvents.getServerVersion();
|
||||
private final Plugin plugin;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package io.github.retrooper.packetevents.mojang;
|
||||
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GameProfile {
|
||||
private final UUID id;
|
||||
private final String name;
|
||||
private final PropertyMap properties = new PropertyMap();
|
||||
private boolean legacy;
|
||||
|
||||
public GameProfile(UUID id, String name) {
|
||||
if (id == null && StringUtils.isBlank(name)) {
|
||||
throw new IllegalArgumentException("Name and ID cannot both be blank");
|
||||
} else {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public PropertyMap getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return this.id != null && StringUtils.isNotBlank(this.getName());
|
||||
}
|
||||
|
||||
public boolean equalsMojangGameProfile(com.mojang.authlib.GameProfile profile) {
|
||||
if (profile != null) {
|
||||
if (profile.getId() != null && getId() != null && profile.getId() == getId()
|
||||
&& profile.getName() != null && getName() != null && profile.getName().equals(getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o != null && this.getClass() == o.getClass()) {
|
||||
GameProfile that = (GameProfile) o;
|
||||
if (this.id != null) {
|
||||
if (!this.id.equals(that.id)) {
|
||||
return false;
|
||||
}
|
||||
} else if (that.id != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.name != null) {
|
||||
if (this.name.equals(that.name)) {
|
||||
return true;
|
||||
}
|
||||
} else if (that.name == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = this.id != null ? this.id.hashCode() : 0;
|
||||
result = 31 * result + (this.name != null ? this.name.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (new ToStringBuilder(this)).append("id", this.id).append("name", this.name).append("properties", this.properties).append("legacy", this.legacy).toString();
|
||||
}
|
||||
|
||||
public boolean isLegacy() {
|
||||
return this.legacy;
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,8 @@ public abstract class Packet {
|
||||
public static final String PING = "PacketStatusInPing";
|
||||
public static final String START = "PacketStatusInStart";
|
||||
public static final String SUCCESS = "PacketLoginOutSuccess";
|
||||
public static final String ENCRYPTION_BEGIN_IN = "PacketLoginInEncryptionBegin";
|
||||
public static final String ENCRYPTION_BEGIN_OUT = "PacketLoginOutEncryptionBegin";
|
||||
|
||||
public static final String[] LOGIN_PACKETS = new String[]{"PacketHandshakingInSetProtocol", "PacketLoginInStart", "PacketLoginInEncryptionBegin"};
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,12 +1,12 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.entityaction;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.PlayerAction;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.login;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.tinyprotocol.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
|
||||
public final class WrappedPacketLoginInEncryptionBegin extends WrappedPacket {
|
||||
private byte[] publicKey, verifyToken;
|
||||
public WrappedPacketLoginInEncryptionBegin(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
this.publicKey = fields[0].get(packet);
|
||||
this.verifyToken = fields[1].get(packet);
|
||||
}
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public byte[] getVerifyToken() {
|
||||
return verifyToken;
|
||||
}
|
||||
|
||||
private static Class<?> packetClass;
|
||||
|
||||
private static final Reflection.FieldAccessor<byte[]>[] fields = new Reflection.FieldAccessor[2];
|
||||
|
||||
static {
|
||||
try {
|
||||
packetClass = NMSUtils.getNMSClass("PacketLoginInEncryptionBegin");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
fields[0] = Reflection.getField(packetClass, byte[].class, 0);
|
||||
fields[1] = Reflection.getField(packetClass, byte[].class, 1);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.login;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.tinyprotocol.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
|
||||
public final class WrappedPacketLoginOutEncryptionBegin extends WrappedPacket {
|
||||
private String encodedString;
|
||||
private PublicKey encodedKey;
|
||||
private byte[] byteArray;
|
||||
|
||||
public WrappedPacketLoginOutEncryptionBegin(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
//string - a (encodedstring)
|
||||
//public key - b (encoded)
|
||||
//byte array - c(byte array)
|
||||
this.encodedString = fields[0].get(packet).toString();
|
||||
this.encodedKey = (PublicKey) fields[1].get(packet);
|
||||
this.byteArray = (byte[]) fields[2].get(packet);
|
||||
}
|
||||
|
||||
public String getEncodedString() {
|
||||
return encodedString;
|
||||
}
|
||||
|
||||
public PublicKey getEncodedKey() {
|
||||
return encodedKey;
|
||||
}
|
||||
|
||||
public byte[] getByteArray() {
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
private static Class<?> packetClass;
|
||||
|
||||
private static final Reflection.FieldAccessor<?>[] fields = new Reflection.FieldAccessor[3];
|
||||
|
||||
static {
|
||||
try {
|
||||
packetClass = NMSUtils.getNMSClass("PacketLoginOutEncryptionBegin");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
fields[0] = Reflection.getField(packetClass, String.class, 0);
|
||||
fields[1] = Reflection.getField(packetClass, PublicKey.class, 1);
|
||||
fields[2] = Reflection.getField(packetClass, byte[].class, 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.login;
|
||||
|
||||
import io.github.retrooper.packetevents.mojang.GameProfile;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.tinyprotocol.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
|
||||
public final class WrappedPacketLoginStart extends WrappedPacket {
|
||||
private GameProfile gameProfile;
|
||||
public WrappedPacketLoginStart(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
com.mojang.authlib.GameProfile gp = gameProfileAccessor.get(packet);
|
||||
this.gameProfile = new GameProfile(gp.getId(), gp.getName());
|
||||
}
|
||||
|
||||
public GameProfile getGameProfile() {
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
private static Class<?> packetClass;
|
||||
|
||||
private static final Reflection.FieldAccessor<com.mojang.authlib.GameProfile> gameProfileAccessor;
|
||||
|
||||
static {
|
||||
try {
|
||||
packetClass = NMSUtils.getNMSClass("PacketLoginInStart");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
gameProfileAccessor = Reflection.getField(packetClass, com.mojang.authlib.GameProfile.class, 0);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.login;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.tinyprotocol.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
|
||||
public final class WrappedPacketLoginStatusPing extends WrappedPacket {
|
||||
private long number;
|
||||
public WrappedPacketLoginStatusPing(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
this.number = numberAccessor.get(packet);
|
||||
}
|
||||
|
||||
public long getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
private static Class<?> packetClass;
|
||||
|
||||
private static final Reflection.FieldAccessor<Long> numberAccessor;
|
||||
|
||||
static {
|
||||
try {
|
||||
packetClass = NMSUtils.getNMSClass("PacketStatusInPing");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
numberAccessor = Reflection.getField(packetClass, long.class, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.retrooper.packetevents.utils;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.utils.nms_entityfinder.EntityFinderUtils;
|
||||
@@ -8,7 +9,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
Reference in new issue
Block a user