Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a88e95e116 | ||
|
|
7c583bf8ec | ||
|
|
c3911483a5 | ||
|
|
f37d7f4040 | ||
|
|
c39c9691a8 | ||
|
|
a1c591a616 | ||
|
|
999e21bf77 | ||
|
|
c8e5a37472 | ||
|
|
c6fffca506 | ||
|
|
f1206a1fc6 | ||
|
|
29a4280b50 | ||
|
|
552f63a27f | ||
|
|
612608181d | ||
|
|
8e652f0c44 | ||
|
|
4a3e89d713 | ||
|
|
3dd6d1e0b9 | ||
|
|
f42e1ad71d | ||
|
|
b44f36185a | ||
|
|
1621adad02 | ||
|
|
d2682242ae | ||
|
|
0b26fe3266 | ||
|
|
0354ddf765 | ||
|
|
82e0d01c29 | ||
|
|
57b68f185c | ||
|
|
8f9b8c0433 | ||
|
|
27ced0fc36 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.7.5</version>
|
||||
|
||||
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
|
||||
<build>
|
||||
@@ -95,6 +95,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.github.spigot</groupId>
|
||||
<artifactId>1.9</artifactId>
|
||||
<version>1.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.github.spigot</groupId>
|
||||
<artifactId>1.8.8</artifactId>
|
||||
|
||||
@@ -48,19 +48,23 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public final class PacketEvents implements Listener {
|
||||
private static final String nettyHandlerIdentifier = generateRandomNettyIdentifier();
|
||||
|
||||
private static final PacketEventsAPI packetEventsAPI = new PacketEventsAPI();
|
||||
private static final PacketEvents instance = new PacketEvents();
|
||||
private static final ArrayList<Plugin> plugins = new ArrayList<Plugin>(1);
|
||||
private static final ArrayList<Plugin> plugins = new ArrayList<>(1);
|
||||
private static boolean loaded, initialized;
|
||||
private static final PEVersion version = new PEVersion(1, 7);
|
||||
private static final PEVersion version = new PEVersion(1, 7, 5);
|
||||
|
||||
private static PacketEventsSettings settings = new PacketEventsSettings();
|
||||
/** General executor service, basically for anything that the packet executor service doesn't do.
|
||||
*/
|
||||
public static ExecutorService generalExecutorService = Executors.newCachedThreadPool();
|
||||
//Executor used for player injecting/ejecting and for packet processing/event calling
|
||||
public static ExecutorService packetHandlingExecutorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
/**
|
||||
* This loads the PacketEvents API.
|
||||
@@ -131,6 +135,14 @@ public final class PacketEvents implements Listener {
|
||||
load();
|
||||
if (!initialized) {
|
||||
settings = packetEventsSettings;
|
||||
int packetHandlingThreadCount = settings.getPacketHandlingThreadCount();
|
||||
//if the count is 1 or is invalid
|
||||
if(packetHandlingThreadCount == 1 || packetHandlingThreadCount < 0) {
|
||||
packetHandlingExecutorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
else {
|
||||
packetHandlingExecutorService = Executors.newFixedThreadPool(packetHandlingThreadCount);
|
||||
}
|
||||
plugins.add(pl);
|
||||
|
||||
//Register Bukkit listener
|
||||
@@ -142,12 +154,7 @@ public final class PacketEvents implements Listener {
|
||||
}
|
||||
|
||||
if (settings.shouldCheckForUpdates()) {
|
||||
Future<?> future = NettyPacketManager.executorService.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new UpdateChecker().handleUpdate();
|
||||
}
|
||||
});
|
||||
PacketEvents.generalExecutorService.execute(() -> new UpdateChecker().handleUpdate());
|
||||
}
|
||||
|
||||
if (getAPI().getServerUtils().isBungeeCordEnabled()) {
|
||||
@@ -164,14 +171,17 @@ public final class PacketEvents implements Listener {
|
||||
*/
|
||||
public static void stop() {
|
||||
if (initialized) {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
getAPI().getPlayerUtils().ejectPlayer(p);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
PacketEvents.getAPI().packetManager.ejectPlayer(player);
|
||||
}
|
||||
|
||||
if (PacketEvents.getAPI().packetManager.tinyProtocol != null) {
|
||||
PacketEvents.getAPI().packetManager.tinyProtocol.unregisterChannelHandler();
|
||||
}
|
||||
getAPI().getEventManager().unregisterAllListeners();
|
||||
|
||||
PacketEvents.generalExecutorService.shutdownNow();
|
||||
PacketEvents.packetHandlingExecutorService.shutdownNow();
|
||||
initialized = false;
|
||||
NettyPacketManager.executorService.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,10 +201,6 @@ public final class PacketEvents implements Listener {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public static String getHandlerName(final String name) {
|
||||
return "pe-" + nettyHandlerIdentifier + "-" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PacketEvents settings.
|
||||
*
|
||||
@@ -212,8 +218,12 @@ public final class PacketEvents implements Listener {
|
||||
public void onLogin(PlayerLoginEvent e) {
|
||||
if (PacketEvents.getSettings().shouldInjectEarly()) {
|
||||
assert getAPI().packetManager.tinyProtocol != null;
|
||||
if (getAPI().packetManager.tinyProtocol.canInject(e.getPlayer())) {
|
||||
getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
try {
|
||||
if (getAPI().packetManager.canInject(e.getPlayer())) {
|
||||
getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "We are unable to inject you. Please try again!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,26 +243,15 @@ public final class PacketEvents implements Listener {
|
||||
}
|
||||
}
|
||||
if (!PacketEvents.getSettings().shouldInjectEarly()) {
|
||||
PacketEvents.getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
if (getAPI().packetManager.canInject(e.getPlayer())) {
|
||||
PacketEvents.getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(final PlayerQuitEvent e) {
|
||||
PacketEvents.getAPI().getPlayerUtils().ejectPlayer(e.getPlayer());
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
private static String generateRandomNettyIdentifier() {
|
||||
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
while (sb.length() < 13) {
|
||||
int index = (int) (random.nextFloat() * alphabet.length());
|
||||
sb.append(alphabet.charAt(index));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,15 +25,33 @@
|
||||
package io.github.retrooper.packetevents.enums;
|
||||
|
||||
public enum Direction {
|
||||
DOWN, UP, NORTH, SOUTH, WEST, EAST, NORTH_EAST,
|
||||
NORTH_WEST, SOUTH_EAST,
|
||||
SOUTH_WEST, WEST_NORTH_WEST,
|
||||
NORTH_NORTH_WEST, NORTH_NORTH_EAST,
|
||||
EAST_NORTH_EAST, EAST_SOUTH_EAST,
|
||||
SOUTH_SOUTH_EAST, SOUTH_SOUTH_WEST,
|
||||
WEST_SOUTH_WEST, SELF, NULL;
|
||||
/**
|
||||
* -Y offset
|
||||
*/
|
||||
DOWN,
|
||||
|
||||
public static Direction get(final int i) {
|
||||
return values()[i];
|
||||
}
|
||||
/**
|
||||
* +Y offset
|
||||
*/
|
||||
UP,
|
||||
|
||||
/**
|
||||
* -Z offset
|
||||
*/
|
||||
NORTH,
|
||||
|
||||
/**
|
||||
* +Z offset
|
||||
*/
|
||||
SOUTH,
|
||||
|
||||
/**
|
||||
* -X offset
|
||||
*/
|
||||
WEST,
|
||||
|
||||
/**
|
||||
* +X offset
|
||||
*/
|
||||
EAST;
|
||||
}
|
||||
@@ -25,25 +25,30 @@
|
||||
package io.github.retrooper.packetevents.event.manager;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.eventtypes.CancellableEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.eventtypes.CancellableEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.*;
|
||||
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibListener;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibAPIListener;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public final class EventManager {
|
||||
private final ConcurrentHashMap<PacketListener, ConcurrentLinkedQueue<Method>> registeredMethods = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<PacketListener, List<Method>> staticRegisteredMethods = new HashMap<>();
|
||||
public void callEvent(final PacketEvent e) {
|
||||
for (final PacketListener listener : registeredMethods.keySet()) {
|
||||
ConcurrentLinkedQueue<Method> methods = registeredMethods.get(listener);
|
||||
//STATIC LISTENERS
|
||||
for (final PacketListener listener : staticRegisteredMethods.keySet()) {
|
||||
List<Method> methods = staticRegisteredMethods.get(listener);
|
||||
final boolean[] isCancelled = {false};
|
||||
final byte[] eventPriority = {PacketEventPriority.LOWEST};
|
||||
for (Method method : methods) {
|
||||
@@ -64,19 +69,15 @@ public final class EventManager {
|
||||
isCancelled[0] = ce.isCancelled();
|
||||
}
|
||||
}
|
||||
if (e instanceof CancellableEvent) {
|
||||
CancellableEvent cancellableEvent = (CancellableEvent) e;
|
||||
cancellableEvent.setCancelled(isCancelled[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerListener(final PacketListener listener) {
|
||||
final ConcurrentLinkedQueue<Method> methods = new ConcurrentLinkedQueue<>();
|
||||
final List<Method> methods = new ArrayList<>();
|
||||
for (final Method m : listener.getClass().getDeclaredMethods()) {
|
||||
if(!m.isAccessible()) {
|
||||
if (!m.isAccessible()) {
|
||||
m.setAccessible(true);
|
||||
}
|
||||
if (m.isAnnotationPresent(PacketHandler.class)
|
||||
@@ -88,9 +89,9 @@ public final class EventManager {
|
||||
if (!methods.isEmpty()) {
|
||||
if (ProtocolLibUtils.isAvailable()
|
||||
&& PacketEvents.getSettings().shouldUseProtocolLibIfAvailable()) {
|
||||
ProtocolLibListener.registerProtocolLibListener(listener, methods);
|
||||
ProtocolLibAPIListener.registerProtocolLibListener(listener, methods);
|
||||
} else {
|
||||
registeredMethods.put(listener, methods);
|
||||
staticRegisteredMethods.put(listener, methods);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +103,7 @@ public final class EventManager {
|
||||
}
|
||||
|
||||
public void unregisterListener(final PacketListener e) {
|
||||
registeredMethods.remove(e);
|
||||
staticRegisteredMethods.remove(e);
|
||||
}
|
||||
|
||||
public void unregisterListeners(final PacketListener... listeners) {
|
||||
@@ -112,10 +113,10 @@ public final class EventManager {
|
||||
}
|
||||
|
||||
public void unregisterAllListeners() {
|
||||
registeredMethods.clear();
|
||||
staticRegisteredMethods.clear();
|
||||
}
|
||||
|
||||
public boolean isRegistered(final PacketListener listener) {
|
||||
return registeredMethods.containsKey(listener);
|
||||
return staticRegisteredMethods.containsKey(listener);
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,13 @@ import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PlayerEjectEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PlayerInjectEvent;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.animation.WrappedPacketOutAnimation;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.explosion.WrappedPacketOutExplosion;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.chat.WrappedPacketInChat;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.helditemslot.WrappedPacketOutHeldItemSlot;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class MainExample extends JavaPlugin implements PacketListener {
|
||||
@@ -45,12 +46,11 @@ public class MainExample extends JavaPlugin implements PacketListener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PacketEvents.getSettings().injectAsync(true).ejectAsync(true)
|
||||
.backupServerVersion(ServerVersion.v_1_7_10).
|
||||
useProtocolLibIfAvailable(true).checkForUpdates(true).injectEarly(true);
|
||||
PacketEvents.getSettings().injectAsync(true).ejectAsync(true).
|
||||
backupServerVersion(ServerVersion.v_1_7_10).useProtocolLibIfAvailable(true).
|
||||
checkForUpdates(true).injectEarly(true).packetHandlingThreadCount(1);
|
||||
PacketEvents.getAPI().getEventManager().registerListener(this);
|
||||
PacketEvents.init(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,8 +39,13 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
private static final AtomicInteger handlerID = new AtomicInteger();
|
||||
private final int handlerNumber = handlerID.getAndIncrement();
|
||||
private final Plugin plugin;
|
||||
private final boolean tinyProtocolMode;
|
||||
public final TinyProtocol tinyProtocol;
|
||||
@@ -104,7 +109,6 @@ public class PacketManager {
|
||||
PacketEvents.getAPI().getEventManager().callEvent(ejectEvent);
|
||||
if (!ejectEvent.isCancelled()) {
|
||||
keepAliveMap.remove(player.getUniqueId());
|
||||
NMSUtils.channelCache.remove(player.getUniqueId());
|
||||
if (tinyProtocolMode) {
|
||||
tinyProtocol.ejectPlayer(player);
|
||||
} else {
|
||||
@@ -118,7 +122,6 @@ public class PacketManager {
|
||||
PacketEvents.getAPI().getEventManager().callEvent(ejectEvent);
|
||||
if (!ejectEvent.isCancelled()) {
|
||||
keepAliveMap.remove(player.getUniqueId());
|
||||
NMSUtils.channelCache.remove(player.getUniqueId());
|
||||
if (tinyProtocolMode) {
|
||||
tinyProtocol.ejectPlayerAsync(player);
|
||||
} else {
|
||||
@@ -127,6 +130,30 @@ public class PacketManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void ejectChannel(Object channel) {
|
||||
if (!PacketEvents.getSettings().shouldEjectAsync()) {
|
||||
ejectChannelSync(channel);
|
||||
} else {
|
||||
ejectChannelAsync(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void ejectChannelSync(Object channel) {
|
||||
if (tinyProtocolMode) {
|
||||
tinyProtocol.ejectChannelSync(channel);
|
||||
} else {
|
||||
nettyProtocol.ejectChannelSync(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void ejectChannelAsync(Object channel) {
|
||||
if (tinyProtocolMode) {
|
||||
tinyProtocol.ejectChannelAsync(channel);
|
||||
} else {
|
||||
nettyProtocol.ejectChannelAsync(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPacket(Object channel, Object packet) {
|
||||
if (tinyProtocolMode) {
|
||||
tinyProtocol.sendPacket(channel, packet);
|
||||
@@ -135,70 +162,74 @@ public class PacketManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInject(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getNettyHandlerName() {
|
||||
return "pe-" + plugin.getName() + "-" + handlerNumber;
|
||||
}
|
||||
|
||||
public Object read(Player player, Object channel, Object packet) {
|
||||
switch (ClassUtil.getClassSimpleName(packet.getClass())) {
|
||||
case "PacketHandshakingInSetProtocol":
|
||||
case "PacketLoginInCustomPayload":
|
||||
case "PacketLoginInStart":
|
||||
case "PacketLoginInEncryptionBegin":
|
||||
final PacketLoginEvent packetLoginEvent = new PacketLoginEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetLoginEvent);
|
||||
interceptLogin(packetLoginEvent);
|
||||
if (packetLoginEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
break;
|
||||
case "PacketStatusInPing":
|
||||
if (player == null) {
|
||||
String simpleClassName = ClassUtil.getClassSimpleName(packet.getClass());
|
||||
//Status packet
|
||||
if (simpleClassName.startsWith("PacketS")) {
|
||||
final PacketStatusEvent packetStatusEvent = new PacketStatusEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetStatusEvent);
|
||||
interceptStatus(packetStatusEvent);
|
||||
if (packetStatusEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
final PacketReceiveEvent packetReceiveEvent = new PacketReceiveEvent(player, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetReceiveEvent);
|
||||
interceptRead(packetReceiveEvent);
|
||||
if (packetReceiveEvent.isCancelled()) {
|
||||
} else {
|
||||
//Login packet
|
||||
final PacketLoginEvent packetLoginEvent = new PacketLoginEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetLoginEvent);
|
||||
interceptLogin(packetLoginEvent);
|
||||
if (packetLoginEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
final PacketReceiveEvent packetReceiveEvent = new PacketReceiveEvent(player, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetReceiveEvent);
|
||||
interceptRead(packetReceiveEvent);
|
||||
if (packetReceiveEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Object write(Player player, Object channel, Object packet) {
|
||||
switch (ClassUtil.getClassSimpleName(packet.getClass())) {
|
||||
case "PacketLoginOutDisconnect":
|
||||
case "PacketLoginOutEncryptionBegin":
|
||||
case "PacketLoginOutSetCompression":
|
||||
case "PacketLoginOutSuccess":
|
||||
final PacketLoginEvent packetLoginEvent = new PacketLoginEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetLoginEvent);
|
||||
interceptLogin(packetLoginEvent);
|
||||
if (packetLoginEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
break;
|
||||
case "PacketStatusOutPong":
|
||||
if (player == null) {
|
||||
String simpleClassName = ClassUtil.getClassSimpleName(packet.getClass());
|
||||
//Status packet
|
||||
if (simpleClassName.startsWith("PacketS")) {
|
||||
final PacketStatusEvent packetStatusEvent = new PacketStatusEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetStatusEvent);
|
||||
interceptStatus(packetStatusEvent);
|
||||
if (packetStatusEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
final PacketSendEvent packetSendEvent = new PacketSendEvent(player, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetSendEvent);
|
||||
interceptWrite(packetSendEvent);
|
||||
if (packetSendEvent.isCancelled()) {
|
||||
}
|
||||
//Login packet
|
||||
else {
|
||||
final PacketLoginEvent packetLoginEvent = new PacketLoginEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetLoginEvent);
|
||||
interceptLogin(packetLoginEvent);
|
||||
if (packetLoginEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
final PacketSendEvent packetSendEvent = new PacketSendEvent(player, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetSendEvent);
|
||||
interceptWrite(packetSendEvent);
|
||||
if (packetSendEvent.isCancelled()) {
|
||||
packet = null;
|
||||
}
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
@@ -223,6 +254,7 @@ public class PacketManager {
|
||||
case "PacketLoginOutSetCompression":
|
||||
case "PacketLoginOutSuccess":
|
||||
case "PacketStatusOutPong":
|
||||
case "PacketStatusOutServerInfo":
|
||||
break;
|
||||
default:
|
||||
PacketEvents.getAPI().getEventManager().callEvent(new PostPacketSendEvent(player, packet));
|
||||
@@ -263,4 +295,5 @@ public class PacketManager {
|
||||
private void interceptStatus(PacketStatusEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+41
-21
@@ -33,24 +33,22 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class NettyPacketManager {
|
||||
public static boolean v1_7_nettyMode = false;
|
||||
public static final ExecutorService
|
||||
executorService =
|
||||
Executors.newFixedThreadPool(Math.max(Runtime.getRuntime().availableProcessors(), 64));
|
||||
public static final boolean v1_7_nettyMode;
|
||||
|
||||
static {
|
||||
boolean v1_7_nettyMode1;
|
||||
try {
|
||||
Class.forName("io.netty.channel.Channel");
|
||||
Class.forName("net.minecraft.util.io.netty.channel.Channel");
|
||||
v1_7_nettyMode1 = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
v1_7_nettyMode = true;
|
||||
v1_7_nettyMode1 = false;
|
||||
}
|
||||
v1_7_nettyMode = v1_7_nettyMode1;
|
||||
}
|
||||
|
||||
private Plugin plugin;
|
||||
private Object npm;
|
||||
private final Object npm;
|
||||
|
||||
public NettyPacketManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
if (v1_7_nettyMode) {
|
||||
npm = new NettyPacketManager_7();
|
||||
} else {
|
||||
@@ -65,10 +63,10 @@ public class NettyPacketManager {
|
||||
*/
|
||||
public void injectPlayer(final Player player) {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.injectPlayer(player);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.injectPlayer(player);
|
||||
}
|
||||
}
|
||||
@@ -81,12 +79,12 @@ public class NettyPacketManager {
|
||||
public void injectPlayerAsync(final Player player) {
|
||||
//Redundant channel variable created just so we can cache it synchronously.
|
||||
Object channel = NMSUtils.getChannel(player);
|
||||
executorService.execute(() -> {
|
||||
PacketEvents.packetHandlingExecutorService.execute(() -> {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.injectPlayer(player);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.injectPlayer(player);
|
||||
}
|
||||
});
|
||||
@@ -99,10 +97,10 @@ public class NettyPacketManager {
|
||||
*/
|
||||
public void ejectPlayer(final Player player) {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.ejectPlayer(player);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.ejectPlayer(player);
|
||||
}
|
||||
}
|
||||
@@ -113,23 +111,45 @@ public class NettyPacketManager {
|
||||
* @param player
|
||||
*/
|
||||
public void ejectPlayerAsync(final Player player) {
|
||||
executorService.execute(() -> {
|
||||
PacketEvents.packetHandlingExecutorService.execute(() -> {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.ejectPlayer(player);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.ejectPlayer(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ejectChannelSync(Object channel) {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.ejectChannel(channel);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.ejectChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void ejectChannelAsync(Object channel) {
|
||||
PacketEvents.packetHandlingExecutorService.execute(() -> {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.ejectChannel(channel);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.ejectChannel(channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void sendPacket(Object channel, Object packet) {
|
||||
if (v1_7_nettyMode) {
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
|
||||
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
|
||||
npm_7.sendPacket(channel, packet);
|
||||
} else {
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
|
||||
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
|
||||
npm_8.sendPacket(channel, packet);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-9
@@ -64,21 +64,22 @@ final class NettyPacketManager_7 {
|
||||
}
|
||||
};
|
||||
final ChannelPipeline pipeline = ((Channel) NMSUtils.getChannel(player)).pipeline();
|
||||
pipeline.addBefore("packet_handler", PacketEvents.getHandlerName(player.getName()), channelDuplexHandler);
|
||||
pipeline.addBefore("packet_handler", PacketEvents.getAPI().packetManager.getNettyHandlerName(), channelDuplexHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Eject a player using 1.7.10 netty import location.
|
||||
* @param player Target Player
|
||||
*/
|
||||
public void ejectPlayer(final Player player) {
|
||||
Channel channel = (Channel) NMSUtils.getChannelNoCache(player);
|
||||
public void ejectPlayer(Player player) {
|
||||
Channel channel = (Channel) NMSUtils.getChannel(player);
|
||||
assert channel != null;
|
||||
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
|
||||
ejectChannel(channel);
|
||||
}
|
||||
|
||||
public void ejectChannel(Object ch) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.pipeline().remove(PacketEvents.getAPI().packetManager.getNettyHandlerName());
|
||||
}
|
||||
|
||||
public void sendPacket(Object rawChannel, Object packet) {
|
||||
Channel channel = (Channel)rawChannel;
|
||||
Channel channel = (Channel) rawChannel;
|
||||
channel.pipeline().writeAndFlush(packet);
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -64,7 +64,7 @@ final class NettyPacketManager_8 {
|
||||
}
|
||||
};
|
||||
final ChannelPipeline pipeline = ((Channel) NMSUtils.getChannel(player)).pipeline();
|
||||
pipeline.addBefore("packet_handler", PacketEvents.getHandlerName(player.getName()), channelDuplexHandler);
|
||||
pipeline.addBefore("packet_handler", PacketEvents.getAPI().packetManager.getNettyHandlerName(), channelDuplexHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,9 +72,14 @@ final class NettyPacketManager_8 {
|
||||
* @param player
|
||||
*/
|
||||
public void ejectPlayer(final Player player) {
|
||||
final Channel channel = (Channel) NMSUtils.getChannelNoCache(player);
|
||||
final Channel channel = (Channel) NMSUtils.getChannel(player);
|
||||
assert channel != null;
|
||||
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
|
||||
ejectChannel(channel);
|
||||
}
|
||||
|
||||
public void ejectChannel(Object channel) {
|
||||
Channel ch = (Channel)channel;
|
||||
ch.pipeline().remove(PacketEvents.getAPI().packetManager.getNettyHandlerName());
|
||||
}
|
||||
|
||||
public void sendPacket(Object rawChannel, Object packet) {
|
||||
|
||||
+22
-17
@@ -24,7 +24,6 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetmanager.tinyprotocol;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.packetmanager.netty.NettyPacketManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -80,6 +79,26 @@ public class TinyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public void ejectChannelSync(Object channel) {
|
||||
if (!NettyPacketManager.v1_7_nettyMode) {
|
||||
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
|
||||
tp8.ejectChannelSync(channel);
|
||||
} else {
|
||||
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
|
||||
tp7.ejectChannelSync(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void ejectChannelAsync(Object channel) {
|
||||
if (!NettyPacketManager.v1_7_nettyMode) {
|
||||
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
|
||||
tp8.ejectChannelAsync(channel);
|
||||
} else {
|
||||
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
|
||||
tp7.ejectChannelAsync(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPacket(Object channel, Object packet) {
|
||||
if (!NettyPacketManager.v1_7_nettyMode) {
|
||||
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
|
||||
@@ -90,14 +109,6 @@ public class TinyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public Object read(Player player, Object channel, Object packet) {
|
||||
return PacketEvents.getAPI().packetManager.read(player, channel, packet);
|
||||
}
|
||||
|
||||
public Object write(Player player, Object channel, Object packet) {
|
||||
return PacketEvents.getAPI().packetManager.write(player, channel, packet);
|
||||
}
|
||||
|
||||
public Object getChannel(Player player) {
|
||||
if (NettyPacketManager.v1_7_nettyMode) {
|
||||
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
|
||||
@@ -108,13 +119,7 @@ public class TinyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInject(Player player) {
|
||||
if (NettyPacketManager.v1_7_nettyMode) {
|
||||
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
|
||||
return !tp7.uninjectedChannels.contains(getChannel(player));
|
||||
} else {
|
||||
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
|
||||
return !tp8.uninjectedChannels.contains(getChannel(player));
|
||||
}
|
||||
public void unregisterChannelHandler() {
|
||||
|
||||
}
|
||||
}
|
||||
+14
-58
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
* This file is part of Hawk Anticheat.
|
||||
* Copyright (C) 2018 Hawk Development Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.retrooper.packetevents.packetmanager.tinyprotocol;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
@@ -27,12 +10,8 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.util.io.netty.channel.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@@ -72,23 +51,19 @@ public class TinyProtocol7 {
|
||||
private static final FieldAccessor<GameProfile> getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0);
|
||||
|
||||
// Speedup channel/protocol lookup
|
||||
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||
private Listener listener;
|
||||
|
||||
// Channels that have already been removed
|
||||
public Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().<Channel, Boolean>makeMap());
|
||||
private final Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||
|
||||
// List of network markers
|
||||
private List<Object> networkManagers;
|
||||
|
||||
// Injected channel handlers
|
||||
private List<Channel> serverChannels = Lists.newArrayList();
|
||||
private final List<Channel> serverChannels = Lists.newArrayList();
|
||||
private ChannelInboundHandlerAdapter serverChannelHandler;
|
||||
private ChannelInitializer<Channel> beginInitProtocol;
|
||||
private ChannelInitializer<Channel> endInitProtocol;
|
||||
|
||||
// Current handler name
|
||||
private String handlerName;
|
||||
private final String handlerName;
|
||||
|
||||
protected volatile boolean closed;
|
||||
protected Plugin plugin;
|
||||
@@ -252,7 +227,7 @@ public class TinyProtocol7 {
|
||||
* @return The packet to recieve instead, or NULL to cancel.
|
||||
*/
|
||||
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
||||
return PacketEvents.getAPI().packetManager.read(sender, channel,packet);
|
||||
return PacketEvents.getAPI().packetManager.read(sender, channel, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +336,6 @@ public class TinyProtocol7 {
|
||||
if (interceptor == null) {
|
||||
interceptor = new PacketInterceptor();
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -379,13 +353,12 @@ public class TinyProtocol7 {
|
||||
if (interceptor == null) {
|
||||
interceptor = new PacketInterceptor();
|
||||
final PacketInterceptor pi = interceptor;
|
||||
NettyPacketManager.executorService.execute(new Runnable() {
|
||||
PacketEvents.packetHandlingExecutorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, pi);
|
||||
}
|
||||
});
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -429,6 +402,14 @@ public class TinyProtocol7 {
|
||||
uninjectChannelAsync(channel);
|
||||
}
|
||||
|
||||
public void ejectChannelSync(Object ch) {
|
||||
uninjectChannel((Channel)ch);
|
||||
}
|
||||
|
||||
public void ejectChannelAsync(Object ch) {
|
||||
uninjectChannelAsync((Channel)ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninject a specific channel.
|
||||
* <p>
|
||||
@@ -437,29 +418,18 @@ public class TinyProtocol7 {
|
||||
* @param channel - the injected channel.
|
||||
*/
|
||||
public void uninjectChannel(final Channel channel) {
|
||||
// No need to guard against this if we're closing
|
||||
if (!closed) {
|
||||
uninjectedChannels.add(channel);
|
||||
}
|
||||
|
||||
// See ChannelInjector in ProtocolLib, line 590
|
||||
channel.pipeline().remove(handlerName);
|
||||
}
|
||||
|
||||
public void uninjectChannelAsync(Channel channel) {
|
||||
// No need to guard against this if we're closing
|
||||
if (!closed) {
|
||||
uninjectedChannels.add(channel);
|
||||
}
|
||||
|
||||
// See ChannelInjector in ProtocolLib, line 590
|
||||
NettyPacketManager.executorService.execute(new Runnable() {
|
||||
PacketEvents.packetHandlingExecutorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.pipeline().remove(handlerName);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,20 +455,6 @@ public class TinyProtocol7 {
|
||||
/**
|
||||
* Cease listening for packets. This is called automatically when your plugin is disabled.
|
||||
*/
|
||||
public final void close() {
|
||||
if (!closed) {
|
||||
closed = true;
|
||||
|
||||
// Remove our handlers
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
uninjectPlayer(player);
|
||||
}
|
||||
|
||||
// Clean up Bukkit
|
||||
HandlerList.unregisterAll(listener);
|
||||
unregisterChannelHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel handler that is inserted into the player's channel pipeline, allowing us to intercept sent and received packets.
|
||||
|
||||
+34
-54
@@ -1,21 +1,3 @@
|
||||
/*
|
||||
* This file is part of Hawk Anticheat.
|
||||
* Copyright (C) 2018 Hawk Development Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.packetmanager.tinyprotocol;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -28,16 +10,13 @@ import io.github.retrooper.packetevents.packetmanager.tinyprotocol.Reflection.Me
|
||||
import io.netty.channel.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -65,33 +44,36 @@ public class TinyProtocol8 {
|
||||
private static final Class<Object> serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection");
|
||||
private static final FieldAccessor<Object> getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0);
|
||||
private static final FieldAccessor<Object> getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0);
|
||||
private static final MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass);
|
||||
private static final MethodInvoker getNetworkMarkers;
|
||||
|
||||
// Packets we have to intercept
|
||||
private static final Class<?> PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart");
|
||||
private static final Class<?> PACKET_HANDSHAKING_IN_SET_PROTOCOL = Reflection.getMinecraftClass("PacketHandshakingInSetProtocol");
|
||||
private static final FieldAccessor<GameProfile> getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0);
|
||||
private static final FieldAccessor<Integer> protocolId = Reflection.getField(PACKET_HANDSHAKING_IN_SET_PROTOCOL, int.class, 0);
|
||||
private static final FieldAccessor<Enum> protocolType = Reflection.getField(PACKET_HANDSHAKING_IN_SET_PROTOCOL, Enum.class, 0);
|
||||
|
||||
static {
|
||||
MethodInvoker tempNetworkMarkers;
|
||||
try {
|
||||
tempNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass);
|
||||
} catch (Exception ex) {
|
||||
tempNetworkMarkers = null;
|
||||
}
|
||||
getNetworkMarkers = tempNetworkMarkers;
|
||||
}
|
||||
|
||||
// Speedup channel/protocol lookup
|
||||
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||
private Listener listener;
|
||||
|
||||
// Channels that have already been removed
|
||||
public Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().<Channel, Boolean>makeMap());
|
||||
private final Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||
|
||||
// List of network markers
|
||||
private List<Object> networkManagers;
|
||||
|
||||
// Injected channel handlers
|
||||
private List<Channel> serverChannels = Lists.newArrayList();
|
||||
private final List<Channel> serverChannels = Lists.newArrayList();
|
||||
private ChannelInboundHandlerAdapter serverChannelHandler;
|
||||
private ChannelInitializer<Channel> beginInitProtocol;
|
||||
private ChannelInitializer<Channel> endInitProtocol;
|
||||
|
||||
// Current handler name
|
||||
private String handlerName;
|
||||
private final String handlerName;
|
||||
|
||||
protected volatile boolean closed;
|
||||
protected Plugin plugin;
|
||||
@@ -142,7 +124,7 @@ public class TinyProtocol8 {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Cannot inject incomming channel " + channel, e);
|
||||
plugin.getLogger().log(Level.SEVERE, "Cannot inject incoming channel " + channel, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +165,11 @@ public class TinyProtocol8 {
|
||||
boolean looking = true;
|
||||
|
||||
// We need to synchronize against this list
|
||||
networkManagers = (List<Object>) getNetworkMarkers.invoke(null, serverConnection);
|
||||
if(getNetworkMarkers != null) {
|
||||
networkManagers = (List<Object>) getNetworkMarkers.invoke(null, serverConnection);}
|
||||
else {
|
||||
networkManagers = new ArrayList<>();
|
||||
}
|
||||
createServerChannelHandler();
|
||||
|
||||
// Find the correct list, or implicitly throw an exception
|
||||
@@ -367,7 +353,6 @@ public class TinyProtocol8 {
|
||||
if (interceptor == null) {
|
||||
interceptor = new PacketInterceptor();
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -385,14 +370,12 @@ public class TinyProtocol8 {
|
||||
if (interceptor == null) {
|
||||
interceptor = new PacketInterceptor();
|
||||
final PacketInterceptor pi = interceptor;
|
||||
NettyPacketManager.executorService.execute(new Runnable() {
|
||||
PacketEvents.packetHandlingExecutorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, pi);
|
||||
}
|
||||
});
|
||||
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -436,6 +419,14 @@ public class TinyProtocol8 {
|
||||
uninjectChannelAsync(channel);
|
||||
}
|
||||
|
||||
public void ejectChannelSync(Object ch) {
|
||||
uninjectChannel((Channel) ch);
|
||||
}
|
||||
|
||||
public void ejectChannelAsync(Object ch) {
|
||||
uninjectChannelAsync((Channel) ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninject a specific channel.
|
||||
* <p>
|
||||
@@ -444,23 +435,13 @@ public class TinyProtocol8 {
|
||||
* @param channel - the injected channel.
|
||||
*/
|
||||
public void uninjectChannel(final Channel channel) {
|
||||
// No need to guard against this if we're closing
|
||||
if (!closed) {
|
||||
uninjectedChannels.add(channel);
|
||||
}
|
||||
|
||||
// See ChannelInjector in ProtocolLib, line 590
|
||||
channel.pipeline().remove(handlerName);
|
||||
}
|
||||
|
||||
public void uninjectChannelAsync(Channel channel) {
|
||||
// No need to guard against this if we're closing
|
||||
if (!closed) {
|
||||
uninjectedChannels.add(channel);
|
||||
}
|
||||
|
||||
// See ChannelInjector in ProtocolLib, line 590
|
||||
NettyPacketManager.executorService.execute(new Runnable() {
|
||||
PacketEvents.packetHandlingExecutorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.pipeline().remove(handlerName);
|
||||
@@ -502,7 +483,6 @@ public class TinyProtocol8 {
|
||||
}
|
||||
|
||||
// Clean up Bukkit
|
||||
HandlerList.unregisterAll(listener);
|
||||
unregisterChannelHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@ import java.util.Map;
|
||||
public class PacketType {
|
||||
public static class Status {
|
||||
public static final Map<Class<?>, Byte> packetIds = new HashMap<>();
|
||||
public static final byte PING = 0, PONG = 1;
|
||||
public static final byte IN_START = 0, PING = 1, PONG = 2, SERVER_INFO = 3;
|
||||
|
||||
public static void init() {
|
||||
packetIds.put(PacketTypeClasses.Status.IN_START, IN_START);
|
||||
packetIds.put(PacketTypeClasses.Status.PING, PING);
|
||||
packetIds.put(PacketTypeClasses.Status.PONG, PONG);
|
||||
packetIds.put(PacketTypeClasses.Status.SERVER_INFO, SERVER_INFO);
|
||||
}
|
||||
}
|
||||
public static class Login {
|
||||
|
||||
@@ -29,11 +29,13 @@ import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
public class PacketTypeClasses {
|
||||
public static class Status {
|
||||
public static Class<?> PING, PONG;
|
||||
public static Class<?> IN_START, PING, PONG, SERVER_INFO;
|
||||
|
||||
public static void load() {
|
||||
IN_START = NMSUtils.getNMSClassWithoutException("PacketStatusInStart");
|
||||
PING = NMSUtils.getNMSClassWithoutException("PacketStatusInPing");
|
||||
PONG = NMSUtils.getNMSClassWithoutException("PacketStatusOutPong");
|
||||
SERVER_INFO = NMSUtils.getNMSClassWithoutException("PacketStatusOutServerInfo");
|
||||
PacketType.Status.init();
|
||||
}
|
||||
}
|
||||
@@ -44,7 +46,7 @@ public class PacketTypeClasses {
|
||||
|
||||
public static void load() {
|
||||
HANDSHAKE = NMSUtils.getNMSClassWithoutException("PacketHandshakingInSetProtocol");
|
||||
//In and Out custom payload login packets have been here since AROUND 1.13.2?
|
||||
//In and Out custom payload login packets have been here since AROUND 1.13.2.
|
||||
IN_CUSTOM_PAYLOAD = NMSUtils.getNMSClassWithoutException("PacketLoginInCustomPayload");
|
||||
OUT_CUSTOM_PAYLOAD = NMSUtils.getNMSClassWithoutException("PacketLoginOutCustomPayload");
|
||||
IN_START = NMSUtils.getNMSClassWithoutException("PacketLoginInStart");
|
||||
@@ -137,12 +139,8 @@ public class PacketTypeClasses {
|
||||
|
||||
try {
|
||||
BLOCK_PLACE = NMSUtils.getNMSClass(c + "BlockPlace");
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
}
|
||||
try {
|
||||
USE_ITEM = NMSUtils.getNMSClass(c + "UseItem");
|
||||
} catch (ClassNotFoundException e2) {
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
+128
-111
@@ -47,6 +47,7 @@ import io.github.retrooper.packetevents.packetwrappers.out.entityvelocity.Wrappe
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.experience.WrappedPacketOutExperience;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.explosion.WrappedPacketOutExplosion;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.gamestatechange.WrappedPacketOutGameStateChange;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.helditemslot.WrappedPacketOutHeldItemSlot;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.keepalive.WrappedPacketOutKeepAlive;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.kickdisconnect.WrappedPacketOutKickDisconnect;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.position.WrappedPacketOutPosition;
|
||||
@@ -54,7 +55,6 @@ import io.github.retrooper.packetevents.packetwrappers.out.transaction.WrappedPa
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.updatehealth.WrappedPacketOutUpdateHealth;
|
||||
import io.github.retrooper.packetevents.utils.reflection.ClassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@@ -65,31 +65,18 @@ import java.util.Map;
|
||||
public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
private static final Map<Class<?>, Map<Class<?>, Field[]>> fieldCache = new HashMap<>();
|
||||
public static ServerVersion version;
|
||||
protected final Player player;
|
||||
protected Object packet;
|
||||
private Class<?> packetClass;
|
||||
|
||||
public WrappedPacket() {
|
||||
this.player = null;
|
||||
|
||||
}
|
||||
|
||||
public WrappedPacket(final Object packet) {
|
||||
this(packet, packet.getClass());
|
||||
}
|
||||
|
||||
public WrappedPacket(final Object packet, final Class<?> packetClass) {
|
||||
this(null, packet, packetClass);
|
||||
}
|
||||
|
||||
public WrappedPacket(final Player player, final Object packet) {
|
||||
this(player, packet, packet.getClass());
|
||||
}
|
||||
|
||||
public WrappedPacket(final Player player, final Object packet, Class<?> packetClass) {
|
||||
if (packet == null) {
|
||||
this.player = null;
|
||||
return;
|
||||
}
|
||||
public WrappedPacket(final Object packet, Class<?> packetClass) {
|
||||
if (packet.getClass().getSuperclass().equals(PacketTypeClasses.Client.FLYING)) {
|
||||
packetClass = PacketTypeClasses.Client.FLYING;
|
||||
} else if (packet.getClass().getSuperclass().equals(PacketTypeClasses.Server.ENTITY)) {
|
||||
@@ -100,128 +87,108 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
|
||||
if (!fieldCache.containsKey(packetClass)) {
|
||||
final Field[] declaredFields = packetClass.getDeclaredFields();
|
||||
List<Field> boolFields = new ArrayList<>();
|
||||
List<Field> byteFields = new ArrayList<>();
|
||||
List<Field> shortFields = new ArrayList<>();
|
||||
List<Field> intFields = new ArrayList<>();
|
||||
List<Field> longFields = new ArrayList<>();
|
||||
List<Field> floatFields = new ArrayList<>();
|
||||
List<Field> doubleFields = new ArrayList<>();
|
||||
List<Field> stringFields = new ArrayList<>();
|
||||
|
||||
List<Field> boolArrayFields = new ArrayList<>();
|
||||
List<Field> byteArrayFields = new ArrayList<>();
|
||||
List<Field> shortArrayFields = new ArrayList<>();
|
||||
List<Field> intArrayFields = new ArrayList<>();
|
||||
List<Field> longArrayFields = new ArrayList<>();
|
||||
List<Field> floatArrayFields = new ArrayList<>();
|
||||
List<Field> doubleArrayFields = new ArrayList<>();
|
||||
List<Field> stringArrayFields = new ArrayList<>();
|
||||
|
||||
for (Field f : declaredFields) {
|
||||
f.setAccessible(true);
|
||||
if (f.getType().equals(boolean.class)) {
|
||||
boolFields.add(f);
|
||||
} else if (f.getType().equals(byte.class)) {
|
||||
byteFields.add(f);
|
||||
} else if (f.getType().equals(short.class)) {
|
||||
shortFields.add(f);
|
||||
} else if (f.getType().equals(int.class)) {
|
||||
intFields.add(f);
|
||||
} else if (f.getType().equals(long.class)) {
|
||||
longFields.add(f);
|
||||
} else if (f.getType().equals(float.class)) {
|
||||
floatFields.add(f);
|
||||
} else if (f.getType().equals(double.class)) {
|
||||
doubleFields.add(f);
|
||||
} else if (f.getType().equals(String.class)) {
|
||||
stringFields.add(f);
|
||||
} else if (f.getType().equals(boolean[].class)) {
|
||||
boolArrayFields.add(f);
|
||||
} else if (f.getType().equals(byte[].class)) {
|
||||
byteArrayFields.add(f);
|
||||
} else if (f.getType().equals(short[].class)) {
|
||||
shortArrayFields.add(f);
|
||||
} else if (f.getType().equals(int[].class)) {
|
||||
intArrayFields.add(f);
|
||||
} else if (f.getType().equals(long[].class)) {
|
||||
longArrayFields.add(f);
|
||||
} else if (f.getType().equals(float[].class)) {
|
||||
floatArrayFields.add(f);
|
||||
} else if (f.getType().equals(double[].class)) {
|
||||
doubleArrayFields.add(f);
|
||||
} else if (f.getType().equals(String[].class)) {
|
||||
stringArrayFields.add(f);
|
||||
}
|
||||
}
|
||||
List<Field> boolFields = getFields(boolean.class, declaredFields);
|
||||
List<Field> byteFields = getFields(byte.class, declaredFields);
|
||||
List<Field> shortFields = getFields(short.class, declaredFields);
|
||||
List<Field> intFields = getFields(int.class, declaredFields);
|
||||
;
|
||||
List<Field> longFields = getFields(long.class, declaredFields);
|
||||
;
|
||||
List<Field> floatFields = getFields(float.class, declaredFields);
|
||||
;
|
||||
List<Field> doubleFields = getFields(double.class, declaredFields);
|
||||
;
|
||||
List<Field> stringFields = getFields(String.class, declaredFields);
|
||||
;
|
||||
|
||||
List<Field> boolArrayFields = getFields(boolean[].class, declaredFields);
|
||||
;
|
||||
List<Field> byteArrayFields = getFields(byte[].class, declaredFields);
|
||||
;
|
||||
List<Field> shortArrayFields = getFields(short[].class, declaredFields);
|
||||
;
|
||||
List<Field> intArrayFields = getFields(int[].class, declaredFields);
|
||||
;
|
||||
List<Field> longArrayFields = getFields(long[].class, declaredFields);
|
||||
;
|
||||
List<Field> floatArrayFields = getFields(float[].class, declaredFields);
|
||||
;
|
||||
List<Field> doubleArrayFields = getFields(double[].class, declaredFields);
|
||||
;
|
||||
List<Field> stringArrayFields = getFields(String[].class, declaredFields);
|
||||
;
|
||||
|
||||
Field[] tmp = new Field[0];
|
||||
|
||||
Map<Class<?>, Field[]> map = new HashMap<>();
|
||||
if (!boolFields.isEmpty()) {
|
||||
map.put(boolean.class, boolFields.toArray(new Field[0]));
|
||||
if (boolFields != null) {
|
||||
map.put(boolean.class, boolFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!byteFields.isEmpty()) {
|
||||
map.put(byte.class, byteFields.toArray(new Field[0]));
|
||||
if (byteFields != null) {
|
||||
map.put(byte.class, byteFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!shortFields.isEmpty()) {
|
||||
map.put(short.class, shortFields.toArray(new Field[0]));
|
||||
if (shortFields != null) {
|
||||
map.put(short.class, shortFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!intFields.isEmpty()) {
|
||||
map.put(int.class, intFields.toArray(new Field[0]));
|
||||
if (intFields != null) {
|
||||
map.put(int.class, intFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!longFields.isEmpty()) {
|
||||
map.put(long.class, longFields.toArray(new Field[0]));
|
||||
if (longFields != null) {
|
||||
map.put(long.class, longFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!floatFields.isEmpty()) {
|
||||
map.put(float.class, floatFields.toArray(new Field[0]));
|
||||
if (floatFields != null) {
|
||||
map.put(float.class, floatFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!doubleFields.isEmpty()) {
|
||||
map.put(double.class, doubleFields.toArray(new Field[0]));
|
||||
if (doubleFields != null) {
|
||||
map.put(double.class, doubleFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!stringFields.isEmpty()) {
|
||||
map.put(String.class, stringFields.toArray(new Field[0]));
|
||||
if (stringFields != null) {
|
||||
map.put(String.class, stringFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!boolArrayFields.isEmpty()) {
|
||||
map.put(boolean[].class, boolArrayFields.toArray(new Field[0]));
|
||||
if (boolArrayFields != null) {
|
||||
map.put(boolean[].class, boolArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!byteArrayFields.isEmpty()) {
|
||||
map.put(byte[].class, byteArrayFields.toArray(new Field[0]));
|
||||
if (byteArrayFields != null) {
|
||||
map.put(byte[].class, byteArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!shortArrayFields.isEmpty()) {
|
||||
map.put(short[].class, shortArrayFields.toArray(new Field[0]));
|
||||
if (shortArrayFields != null) {
|
||||
map.put(short[].class, shortArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!intArrayFields.isEmpty()) {
|
||||
map.put(int[].class, intArrayFields.toArray(new Field[0]));
|
||||
if (intArrayFields != null) {
|
||||
map.put(int[].class, intArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!longArrayFields.isEmpty()) {
|
||||
map.put(long[].class, longArrayFields.toArray(new Field[0]));
|
||||
if (longArrayFields != null) {
|
||||
map.put(long[].class, longArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!floatArrayFields.isEmpty()) {
|
||||
map.put(float[].class, floatArrayFields.toArray(new Field[0]));
|
||||
if (floatArrayFields != null) {
|
||||
map.put(float[].class, floatArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!doubleArrayFields.isEmpty()) {
|
||||
map.put(double[].class, doubleArrayFields.toArray(new Field[0]));
|
||||
if (doubleArrayFields != null) {
|
||||
map.put(double[].class, doubleArrayFields.toArray(tmp));
|
||||
}
|
||||
|
||||
if (!stringArrayFields.isEmpty()) {
|
||||
map.put(String[].class, stringArrayFields.toArray(new Field[0]));
|
||||
if (stringArrayFields != null) {
|
||||
map.put(String[].class, stringArrayFields.toArray(tmp));
|
||||
}
|
||||
fieldCache.put(packetClass, map);
|
||||
}
|
||||
this.player = player;
|
||||
this.packet = packet;
|
||||
setup();
|
||||
}
|
||||
@@ -256,6 +223,7 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
WrappedPacketOutExplosion.load();
|
||||
WrappedPacketOutEntityStatus.load();
|
||||
WrappedPacketOutExperience.load();
|
||||
WrappedPacketOutHeldItemSlot.load();
|
||||
}
|
||||
|
||||
protected void setup() {
|
||||
@@ -500,7 +468,7 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
|
||||
@Override
|
||||
public String readString(int index) {
|
||||
return (String) read(String.class, index);
|
||||
return (String) read(String.class, index);
|
||||
}
|
||||
|
||||
public Object readAnyObject(int index) {
|
||||
@@ -523,7 +491,8 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
public Object readObject(int index, Class<?> type) {
|
||||
Map<Class<?>, Field[]> cached = fieldCache.get(packetClass);
|
||||
if (cached != null) {
|
||||
if (!cached.containsKey(type)) {
|
||||
Field[] cachedFields = cached.get(type);
|
||||
if (cachedFields == null) {
|
||||
List<Field> typeFields = new ArrayList<>();
|
||||
for (Field f : packetClass.getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
@@ -533,20 +502,30 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
}
|
||||
if (!typeFields.isEmpty()) {
|
||||
cached.put(type, typeFields.toArray(new Field[0]));
|
||||
cachedFields = cached.get(type);
|
||||
}
|
||||
else {
|
||||
throw new WrapperFieldNotFoundException("The class you are trying to read fields from does not contain any fields!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
return cached.get(type)[index].get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
return cachedFields[index].get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new WrapperFieldNotFoundException(packetClass, type, index);
|
||||
}
|
||||
|
||||
public Object[] readObjectArray(int index, Class<?> type) {
|
||||
return (Object[]) readObject(index, type);
|
||||
if (type.equals(String.class)) {
|
||||
return readStringArray(index);
|
||||
}
|
||||
try {
|
||||
return (Object[]) readObject(index, getArrayClass(type));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException("PacketEvents failed to find the array class of type " + type.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -591,7 +570,7 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
|
||||
private void write(Class<?> type, int index, Object value) throws WrapperFieldNotFoundException {
|
||||
Field field = getField(type, index);
|
||||
if(field == null) {
|
||||
if (field == null) {
|
||||
throw new WrapperFieldNotFoundException(packetClass, type, index);
|
||||
}
|
||||
try {
|
||||
@@ -603,7 +582,7 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
|
||||
private Object read(Class<?> type, int index) throws WrapperFieldNotFoundException {
|
||||
Field field = getField(type, index);
|
||||
if(field == null) {
|
||||
if (field == null) {
|
||||
throw new WrapperFieldNotFoundException(packetClass, type, index);
|
||||
}
|
||||
try {
|
||||
@@ -626,4 +605,42 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Field> getFields(Class<?> type, Field[] fields) {
|
||||
List<Field> ret = new ArrayList<>();
|
||||
for (Field field : fields) {
|
||||
if (field.getType() == type) {
|
||||
ret.add(field);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Class<?> getArrayClass(Class<?> componentType) throws ClassNotFoundException {
|
||||
ClassLoader classLoader = componentType.getClassLoader();
|
||||
String name;
|
||||
if (componentType.isArray()) {
|
||||
// just add a leading "["
|
||||
name = "[" + componentType.getName();
|
||||
} else if (componentType == boolean.class) {
|
||||
name = "[Z";
|
||||
} else if (componentType == byte.class) {
|
||||
name = "[B";
|
||||
} else if (componentType == char.class) {
|
||||
name = "[C";
|
||||
} else if (componentType == double.class) {
|
||||
name = "[D";
|
||||
} else if (componentType == float.class) {
|
||||
name = "[F";
|
||||
} else if (componentType == int.class) {
|
||||
name = "[I";
|
||||
} else if (componentType == long.class) {
|
||||
name = "[J";
|
||||
} else if (componentType == short.class) {
|
||||
name = "[S";
|
||||
} else {
|
||||
// must be an object non-array class
|
||||
name = "[L" + componentType.getName() + ";";
|
||||
}
|
||||
return classLoader != null ? classLoader.loadClass(name) : Class.forName(name);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -26,7 +26,7 @@ package io.github.retrooper.packetevents.packetwrappers;
|
||||
|
||||
public interface WrapperPacketWriter {
|
||||
|
||||
//TODO write for the arrays
|
||||
// TODO write for the arrays
|
||||
void writeBoolean(int index, boolean value);
|
||||
|
||||
void writeByte(int index, byte value);
|
||||
|
||||
-2
@@ -26,9 +26,7 @@ package io.github.retrooper.packetevents.packetwrappers.in.abilities;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.NotNull;
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
public final class WrappedPacketInAbilities extends WrappedPacket {
|
||||
|
||||
|
||||
+27
-12
@@ -25,17 +25,21 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockdig;
|
||||
|
||||
import io.github.retrooper.packetevents.enums.Direction;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
private static Class<?> blockDigClass, blockPositionClass, enumDirectionClass, digTypeClass;
|
||||
private static boolean isVersionLowerThan_v_1_8;
|
||||
private Object blockPosObj, enumDirObj, digTypeObj;
|
||||
private Object blockPosObj;
|
||||
private Object enumDirObj;
|
||||
|
||||
public WrappedPacketInBlockDig(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
@@ -74,8 +78,12 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
if(blockPosObj == null) {
|
||||
blockPosObj = readObject(0, blockPositionClass);
|
||||
}
|
||||
WrappedPacket blockPosWrapper = new WrappedPacket(blockPosObj);
|
||||
return blockPosWrapper.readInt(0);
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +99,12 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
if(blockPosObj == null) {
|
||||
blockPosObj = readObject(0, blockPositionClass);
|
||||
}
|
||||
WrappedPacket blockPosWrapper = new WrappedPacket(blockPosObj);
|
||||
return blockPosWrapper.readInt(1);
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,19 +120,22 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
if(blockPosObj == null) {
|
||||
blockPosObj = readObject(0, blockPositionClass);
|
||||
}
|
||||
WrappedPacket blockPosWrapper = new WrappedPacket(blockPosObj);
|
||||
return blockPosWrapper.readInt(2);
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direction
|
||||
* Is Direction.NULL on 1.7.10 FOR NOW
|
||||
* Get the direction / Get the face.
|
||||
* @return Direction
|
||||
*/
|
||||
public Direction getDirection() {
|
||||
if(isVersionLowerThan_v_1_8) {
|
||||
return Direction.NULL;
|
||||
return Direction.values()[readInt(3)];
|
||||
}
|
||||
else {
|
||||
if(enumDirObj == null) {
|
||||
|
||||
+28
-68
@@ -24,115 +24,75 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.enums.Direction;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public final class WrappedPacketInBlockPlace extends WrappedPacket {
|
||||
private static boolean isHigherThan_v_1_8_8, isHigherThan_v_1_7_10;
|
||||
private WrappedPacket cachedWrappedPacket;
|
||||
|
||||
public WrappedPacketInBlockPlace(final Player player, final Object packet) {
|
||||
super(player, packet);
|
||||
public WrappedPacketInBlockPlace(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
isHigherThan_v_1_8_8 = version.isHigherThan(ServerVersion.v_1_8_8);
|
||||
isHigherThan_v_1_7_10 = version.isHigherThan(ServerVersion.v_1_7_10);
|
||||
if (isHigherThan_v_1_7_10) {
|
||||
WrappedPacketInBlockPlace_1_8.load();
|
||||
}
|
||||
WrappedPacketInBlockPlace_1_9.load();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
public Direction getDirection() {
|
||||
if (isHigherThan_v_1_8_8) {
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(packet);
|
||||
return Direction.valueOf(((Enum) blockPlace_1_9.getEnumDirectionObject()).name());
|
||||
} else if (isHigherThan_v_1_7_10) {
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
return Direction.values()[blockPlace_1_8.getFace()];
|
||||
} else {
|
||||
WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(packet);
|
||||
return Direction.values()[blockPlace_1_7_10.face];
|
||||
}
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
if (isHigherThan_v_1_8_8) {
|
||||
if (cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(getPlayer(), packet);
|
||||
cachedWrappedPacket = blockPlace_1_9;
|
||||
return blockPlace_1_9.getBlock().getX();
|
||||
}
|
||||
return ((WrappedPacketInBlockPlace_1_9)cachedWrappedPacket).getBlock().getX();
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(packet);
|
||||
return blockPlace_1_9.getX();
|
||||
} else if (isHigherThan_v_1_7_10) {
|
||||
if(cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
cachedWrappedPacket = blockPlace_1_8;
|
||||
return blockPlace_1_8.getX();
|
||||
}
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
return blockPlace_1_8.getX();
|
||||
} else {
|
||||
WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(packet);
|
||||
return blockPlace_1_7_10.x;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
if (isHigherThan_v_1_8_8) {
|
||||
if (cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(getPlayer(), packet);
|
||||
cachedWrappedPacket = blockPlace_1_9;
|
||||
return blockPlace_1_9.getBlock().getY();
|
||||
}
|
||||
return ((WrappedPacketInBlockPlace_1_9)cachedWrappedPacket).getBlock().getX();
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(packet);
|
||||
return blockPlace_1_9.getY();
|
||||
|
||||
} else if (isHigherThan_v_1_7_10) {
|
||||
if(cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
cachedWrappedPacket = blockPlace_1_8;
|
||||
return blockPlace_1_8.getY();
|
||||
}
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
return blockPlace_1_8.getY();
|
||||
} else {
|
||||
WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(packet);
|
||||
return blockPlace_1_7_10.y;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
if (isHigherThan_v_1_8_8) {
|
||||
if (cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(getPlayer(), packet);
|
||||
cachedWrappedPacket = blockPlace_1_9;
|
||||
return blockPlace_1_9.getBlock().getZ();
|
||||
}
|
||||
return ((WrappedPacketInBlockPlace_1_9)cachedWrappedPacket).getBlock().getX();
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(packet);
|
||||
return blockPlace_1_9.getZ();
|
||||
} else if (isHigherThan_v_1_7_10) {
|
||||
if(cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
cachedWrappedPacket = blockPlace_1_8;
|
||||
return blockPlace_1_8.getZ();
|
||||
}
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
return blockPlace_1_8.getZ();
|
||||
} else {
|
||||
WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(packet);
|
||||
return blockPlace_1_7_10.z;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
if (isHigherThan_v_1_8_8) {
|
||||
if (cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(getPlayer(), packet);
|
||||
cachedWrappedPacket = blockPlace_1_9;
|
||||
return new ItemStack(blockPlace_1_9.getBlock().getType());
|
||||
}
|
||||
return new ItemStack(((WrappedPacketInBlockPlace_1_9)cachedWrappedPacket).getBlock().getType());
|
||||
} else if (isHigherThan_v_1_7_10) {
|
||||
if(cachedWrappedPacket == null) {
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
cachedWrappedPacket = blockPlace_1_8;
|
||||
return blockPlace_1_8.getItemStack();
|
||||
}
|
||||
} else {
|
||||
WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(packet);
|
||||
return blockPlace_1_7_10.itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-5
@@ -25,14 +25,12 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
final class WrappedPacketInBlockPlace_1_7_10 extends WrappedPacket {
|
||||
public int x, y, z;
|
||||
public ItemStack itemStack;
|
||||
public int blockFace;
|
||||
public int face;
|
||||
|
||||
WrappedPacketInBlockPlace_1_7_10(final Object packet) {
|
||||
super(packet);
|
||||
@@ -41,13 +39,14 @@ final class WrappedPacketInBlockPlace_1_7_10 extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
final PacketPlayInBlockPlace blockPlace = (PacketPlayInBlockPlace) packet;
|
||||
final net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace blockPlace =
|
||||
(net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace) packet;
|
||||
|
||||
x = blockPlace.c();
|
||||
y = blockPlace.d();
|
||||
z = blockPlace.e();
|
||||
|
||||
this.blockFace = blockPlace.d();
|
||||
this.face = blockPlace.d();
|
||||
|
||||
net.minecraft.server.v1_7_R4.ItemStack stack = blockPlace.getItemStack();
|
||||
this.itemStack = org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack.asBukkitCopy(stack);
|
||||
|
||||
+14
-22
@@ -24,8 +24,6 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.exceptions.WrapperFieldNotFoundException;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
@@ -34,60 +32,54 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
final class WrappedPacketInBlockPlace_1_8 extends WrappedPacket {
|
||||
private static Class<?> blockPlaceClass, blockPositionClass, blockPositionSuperClass;
|
||||
private Object blockPosObj;
|
||||
|
||||
WrappedPacketInBlockPlace_1_8(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
protected static void load() {
|
||||
blockPlaceClass = PacketTypeClasses.Client.BLOCK_PLACE;
|
||||
try {
|
||||
blockPositionClass = NMSUtils.getNMSClass("BlockPosition");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
blockPositionSuperClass = blockPositionClass.getSuperclass();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
if(blockPosObj == null) {
|
||||
blockPosObj = new WrappedPacket(packet).readObject(0, blockPositionClass);
|
||||
blockPosObj = readObject(1, NMSUtils.blockPosClass);
|
||||
}
|
||||
try {
|
||||
return (int)Reflection.getMethod(blockPositionSuperClass, "getX", 0).invoke(blockPosObj);
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public int getY() {
|
||||
if(blockPosObj == null) {
|
||||
blockPosObj = new WrappedPacket(packet).readObject(0, blockPositionClass);
|
||||
blockPosObj = readObject(1, NMSUtils.blockPosClass);
|
||||
}
|
||||
try {
|
||||
return (int)Reflection.getMethod(blockPositionSuperClass, "getY", 0).invoke(blockPosObj);
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
if(blockPosObj == null) {
|
||||
blockPosObj = new WrappedPacket(packet).readObject(0, blockPositionClass);
|
||||
blockPosObj = readObject(1, NMSUtils.blockPosClass);
|
||||
}
|
||||
try {
|
||||
return (int)Reflection.getMethod(blockPositionSuperClass, "getZ", 0).invoke(blockPosObj);
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return NMSUtils.toBukkitItemStack(readObject(0, NMSUtils.nmsItemStackClass));
|
||||
}
|
||||
|
||||
public int getFace() {
|
||||
return readInt(0);
|
||||
}
|
||||
}
|
||||
+73
-9
@@ -26,20 +26,84 @@ package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.BlockIteratorUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
final class WrappedPacketInBlockPlace_1_9 extends WrappedPacket {
|
||||
public WrappedPacketInBlockPlace_1_9(final Player player, final Object packet) {
|
||||
super(player, packet);
|
||||
private Object blockPosObj;
|
||||
private static Class<?> movingObjectPositionBlockClass;
|
||||
|
||||
public static void load() {
|
||||
movingObjectPositionBlockClass = NMSUtils.getNMSClassWithoutException("MovingObjectPositionBlock");
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
public WrappedPacketInBlockPlace_1_9(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return BlockIteratorUtils.getBlockLookingAt(getPlayer(),3);
|
||||
public int getX() {
|
||||
if (blockPosObj == null) {
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
blockPosObj = readObject(0, NMSUtils.blockPosClass);
|
||||
} else {
|
||||
Object movingObjectPos = readObject(0, movingObjectPositionBlockClass);
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(movingObjectPos);
|
||||
blockPosObj = movingObjectPosWrapper.readObject(0, NMSUtils.blockPosClass);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
if (blockPosObj == null) {
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
blockPosObj = readObject(0, NMSUtils.blockPosClass);
|
||||
} else {
|
||||
Object movingObjectPos = readObject(0, movingObjectPositionBlockClass);
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(movingObjectPos);
|
||||
blockPosObj = movingObjectPosWrapper.readObject(0, NMSUtils.blockPosClass);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
if (blockPosObj == null) {
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
blockPosObj = readObject(0, NMSUtils.blockPosClass);
|
||||
} else {
|
||||
Object movingObjectPos = readObject(0, movingObjectPositionBlockClass);
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(movingObjectPos);
|
||||
blockPosObj = movingObjectPosWrapper.readObject(0, NMSUtils.blockPosClass);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Object getEnumDirectionObject() {
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
return readObject(0, NMSUtils.enumDirectionClass);
|
||||
} else {
|
||||
Object movingObjectPos = readObject(0, movingObjectPositionBlockClass);
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(movingObjectPos);
|
||||
return movingObjectPosWrapper.readObject(0, NMSUtils.enumDirectionClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -46,7 +46,7 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
packetDataSerializerClass = NMSUtils.getNMSClassWithoutException("PacketDataSerializer");
|
||||
try {
|
||||
byteBufClass = NMSUtils.getNettyClass("buffer.ByteBuf");
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
|
||||
}
|
||||
try {
|
||||
|
||||
+5
-6
@@ -34,14 +34,13 @@ import org.bukkit.entity.Entity;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
private static final HashMap<String, PlayerAction> cachedPlayerActionNames = new HashMap<String, PlayerAction>();
|
||||
private static final HashMap<Integer, PlayerAction> cachedPlayerActionIDs = new HashMap<Integer, PlayerAction>();
|
||||
private static final HashMap<String, PlayerAction> cachedPlayerActionNames = new HashMap<>();
|
||||
private static final HashMap<Integer, PlayerAction> cachedPlayerActionIDs = new HashMap<>();
|
||||
@Nullable
|
||||
private static Class<?> enumPlayerActionClass;
|
||||
private static boolean isLowerThan_v_1_8;
|
||||
private Entity entity;
|
||||
private int entityId = -1;
|
||||
private PlayerAction action;
|
||||
|
||||
public WrappedPacketInEntityAction(final Object packet) {
|
||||
super(packet);
|
||||
@@ -91,10 +90,10 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
* @return Entity ID
|
||||
*/
|
||||
public int getEntityId() {
|
||||
if(entityId != -1) {
|
||||
return entityId;
|
||||
if(entityId == -1) {
|
||||
entityId = readInt(0);
|
||||
}
|
||||
return readInt(0);
|
||||
return entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -24,7 +24,6 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.helditemslot;
|
||||
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
public final class WrappedPacketInHeldItemSlot extends WrappedPacket {
|
||||
|
||||
+1
-3
@@ -29,16 +29,14 @@ import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
public final class WrappedPacketInKeepAlive extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
private static boolean integerPresentInIndex0;
|
||||
private long id;
|
||||
|
||||
public WrappedPacketInKeepAlive(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Client.KEEP_ALIVE;
|
||||
Class<?> packetClass = PacketTypeClasses.Client.KEEP_ALIVE;
|
||||
integerPresentInIndex0 = Reflection.getField(packetClass, int.class, 0) != null;
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -25,7 +25,6 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.settings;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
@@ -45,7 +44,6 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
Class<?> packetClass = PacketTypeClasses.Client.SETTINGS;
|
||||
|
||||
isLowerThan_v_1_8 = version.isLowerThan(ServerVersion.v_1_8);
|
||||
|
||||
|
||||
+33
-22
@@ -30,6 +30,8 @@ import io.github.retrooper.packetevents.packetwrappers.out.chat.WrappedPacketOut
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketInUpdateSign extends WrappedPacket {
|
||||
private static boolean v_1_7_mode, strArrayMode;
|
||||
private static Class<?> blockPosClass, iChatBaseComponentClass;
|
||||
@@ -59,45 +61,54 @@ public class WrappedPacketInUpdateSign extends WrappedPacket {
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
if(v_1_7_mode) {
|
||||
if (v_1_7_mode) {
|
||||
return readInt(0);
|
||||
}
|
||||
else {
|
||||
if(blockPosObj == null) {
|
||||
} else {
|
||||
if (blockPosObj == null) {
|
||||
blockPosObj = readObject(0, blockPosClass);
|
||||
WrappedPacket blockPosWrapper = new WrappedPacket(blockPosObj);
|
||||
return blockPosWrapper.readInt(0);
|
||||
|
||||
}
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
if(v_1_7_mode) {
|
||||
if (v_1_7_mode) {
|
||||
return readInt(1);
|
||||
}
|
||||
else {
|
||||
if(blockPosObj == null) {
|
||||
} else {
|
||||
if (blockPosObj == null) {
|
||||
blockPosObj = readObject(0, blockPosClass);
|
||||
WrappedPacket blockPosWrapper = new WrappedPacket(blockPosObj);
|
||||
return blockPosWrapper.readInt(1);
|
||||
|
||||
}
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
if(v_1_7_mode) {
|
||||
if (v_1_7_mode) {
|
||||
return readInt(2);
|
||||
}
|
||||
else {
|
||||
if(blockPosObj == null) {
|
||||
} else {
|
||||
if (blockPosObj == null) {
|
||||
blockPosObj = readObject(0, blockPosClass);
|
||||
WrappedPacket blockPosWrapper = new WrappedPacket(blockPosObj);
|
||||
return blockPosWrapper.readInt(2);
|
||||
|
||||
}
|
||||
try {
|
||||
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String[] getTextLines() {
|
||||
@@ -106,7 +117,7 @@ public class WrappedPacketInUpdateSign extends WrappedPacket {
|
||||
return readStringArray(0);
|
||||
} else {
|
||||
//1.8 uses this for example
|
||||
Object[] iChatComponents = readObjectArray(0, iChatBaseComponentClass);
|
||||
Object[] iChatComponents = (Object[]) readAnyObject(1);
|
||||
String[] lines = new String[iChatComponents.length];
|
||||
for (int i = 0; i < iChatComponents.length; i++) {
|
||||
lines[i] = WrappedPacketOutChat.
|
||||
|
||||
+25
-6
@@ -22,13 +22,32 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.protocollib;
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.vehiclemove;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import org.bukkit.entity.Player;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
class ProtocolLibAPIAccessor {
|
||||
public static int getProtocolVersion(final Player player) {
|
||||
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);
|
||||
public class WrappedPacketInVehicleMove extends WrappedPacket {
|
||||
public WrappedPacketInVehicleMove(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return readDouble(0);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return readDouble(1);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return readDouble(2);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return readFloat(0);
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return readFloat(1);
|
||||
}
|
||||
}
|
||||
+7
-5
@@ -35,10 +35,11 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
private static final HashMap<String, Integer> invClickTypeMapCache = new HashMap<String, Integer>();
|
||||
private static final HashMap<Integer, ArrayList<WindowClickType>> windowClickTypeCache = new HashMap<Integer, ArrayList<WindowClickType>>();
|
||||
private static Class<?> packetClass, invClickTypeClass;
|
||||
private static boolean isClickModePrimitive = false;
|
||||
private static final HashMap<String, Integer> invClickTypeMapCache = new HashMap<>();
|
||||
private static final HashMap<Integer, ArrayList<WindowClickType>> windowClickTypeCache = new HashMap<>();
|
||||
private static Class<?> invClickTypeClass;
|
||||
private static boolean isClickModePrimitive;
|
||||
// TODO: All the fields below are useless cuz there is never a value assigned to them - change this
|
||||
private int id;
|
||||
private int slot;
|
||||
private int button;
|
||||
@@ -51,7 +52,7 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Client.WINDOW_CLICK;
|
||||
Class<?> packetClass = PacketTypeClasses.Client.WINDOW_CLICK;
|
||||
invClickTypeClass = NMSUtils.getNMSClassWithoutException("InventoryClickType");
|
||||
|
||||
invClickTypeMapCache.put("PICKUP", 0);
|
||||
@@ -156,6 +157,7 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
return WindowClickType.UNKNOWN;
|
||||
}
|
||||
|
||||
// TODO: This has no use cuz the fields used are never getting assigned a value to them
|
||||
if (mode == 4) {
|
||||
if (slot == -999) {
|
||||
if (button == 0) {
|
||||
|
||||
-1
@@ -25,7 +25,6 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.abilities;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
+2
-3
@@ -32,9 +32,8 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketOutAbilities extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private boolean isListening = false;
|
||||
private boolean isListening;
|
||||
private boolean vulnerable, flying, allowFlight, instantBuild;
|
||||
private float flySpeed, walkSpeed;
|
||||
|
||||
@@ -55,7 +54,7 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.ABILITIES;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.ABILITIES;
|
||||
|
||||
try {
|
||||
packetConstructor = packetClass.getConstructor(PlayerAbilitiesUtils.playerAbilitiesClass);
|
||||
|
||||
+5
-4
@@ -33,13 +33,14 @@ import org.bukkit.entity.Entity;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class WrappedPacketOutAnimation extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> animationClass, nmsEntityClass;
|
||||
private static Class<?> nmsEntityClass;
|
||||
private static Constructor<?> animationConstructor;
|
||||
|
||||
private static final HashMap<Integer, EntityAnimationType> cachedAnimationIDS = new HashMap<Integer, EntityAnimationType>();
|
||||
private static final HashMap<EntityAnimationType, Integer> cachedAnimations = new HashMap<EntityAnimationType, Integer>();
|
||||
private static final Map<Integer, EntityAnimationType> cachedAnimationIDS = new HashMap<>();
|
||||
private static final Map<EntityAnimationType, Integer> cachedAnimations = new HashMap<>();
|
||||
private Entity entity;
|
||||
private int entityID = -1;
|
||||
private EntityAnimationType type;
|
||||
@@ -58,7 +59,7 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
animationClass = PacketTypeClasses.Server.ANIMATION;
|
||||
Class<?> animationClass = PacketTypeClasses.Server.ANIMATION;
|
||||
try {
|
||||
nmsEntityClass = NMSUtils.getNMSClass("Entity");
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
+4
-5
@@ -25,12 +25,11 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.chat;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Beta;
|
||||
import io.github.retrooper.packetevents.annotations.NotNull;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -56,9 +55,9 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
//0 = Byte
|
||||
//1 = Byte, Boolean
|
||||
private static byte chatTypeMessageEnumConstructorMode;
|
||||
private static final HashMap<ChatPosition, Byte> cachedChatPositions = new HashMap<ChatPosition, Byte>();
|
||||
private static final HashMap<Byte, ChatPosition> cachedChatPositionIntegers = new HashMap<Byte, ChatPosition>();
|
||||
private static final HashMap<String, Byte> cachedChatMessageTypeIntegers = new HashMap<String, Byte>();
|
||||
private static final HashMap<ChatPosition, Byte> cachedChatPositions = new HashMap<>();
|
||||
private static final HashMap<Byte, ChatPosition> cachedChatPositionIntegers = new HashMap<>();
|
||||
private static final HashMap<String, Byte> cachedChatMessageTypeIntegers = new HashMap<>();
|
||||
private String message;
|
||||
private ChatPosition chatPosition;
|
||||
private UUID uuid;
|
||||
|
||||
+2
-3
@@ -36,7 +36,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class WrappedPacketOutCustomPayload extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> constructor;
|
||||
private static Constructor<?> packetDataSerializerConstructor;
|
||||
private static Constructor<?> minecraftKeyConstructor;
|
||||
@@ -49,13 +48,13 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
private boolean isListening = false;
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.CUSTOM_PAYLOAD;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.CUSTOM_PAYLOAD;
|
||||
packetDataSerializerClass = NMSUtils.getNMSClassWithoutException("PacketDataSerializer");
|
||||
minecraftKeyClass = NMSUtils.getNMSClassWithoutException("MinecraftKey");
|
||||
|
||||
try {
|
||||
byteBufClass = NMSUtils.getNettyClass("buffer.ByteBuf");
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
|
||||
}
|
||||
try {
|
||||
|
||||
+5
-6
@@ -36,14 +36,13 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketOutEntity extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
//Byte = 1.7.10->1.8.8, Int = 1.9->1.15.x, Short = 1.16.x
|
||||
private static byte mode = 0; //byte = 0, int = 1, short = 2
|
||||
private static double dXYZDivisor = 0.0;
|
||||
private static int yawByteIndex = 0;
|
||||
private static byte mode; //byte = 0, int = 1, short = 2
|
||||
private static double dXYZDivisor;
|
||||
private static int yawByteIndex;
|
||||
private static int pitchByteIndex = 1;
|
||||
private Entity entity;
|
||||
private boolean isListening = false;
|
||||
private boolean isListening;
|
||||
private static Constructor<?> entityPacketConstructor;
|
||||
private int entityID;
|
||||
private double deltaX, deltaY, deltaZ;
|
||||
@@ -75,7 +74,7 @@ public class WrappedPacketOutEntity extends WrappedPacket implements SendableWra
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.ENTITY;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.ENTITY;
|
||||
|
||||
Field dxField = Reflection.getField(packetClass, 1);
|
||||
assert dxField != null;
|
||||
|
||||
+2
-3
@@ -27,8 +27,7 @@ package io.github.retrooper.packetevents.packetwrappers.out.entitymetadata;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
public class WrappedPacketOutEntityMetadata extends WrappedPacket {
|
||||
private boolean isListening = false;
|
||||
private int entityID;
|
||||
private boolean isListening;
|
||||
public WrappedPacketOutEntityMetadata(Object packet) {
|
||||
super(packet);
|
||||
isListening = true;
|
||||
@@ -38,7 +37,7 @@ public class WrappedPacketOutEntityMetadata extends WrappedPacket {
|
||||
if (isListening) {
|
||||
return readInt(0);
|
||||
} else {
|
||||
return entityID;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -35,8 +35,8 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketOutEntityTeleport extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean legacyVersionMode = false;
|
||||
private static boolean ultraLegacyVersionMode = false;
|
||||
private static boolean legacyVersionMode;
|
||||
private static boolean ultraLegacyVersionMode;
|
||||
private boolean listeningMode = false;
|
||||
private static final float rotationMultiplier = 256.0F / 360.0F;
|
||||
private static Constructor<?> constructor;
|
||||
|
||||
+3
-3
@@ -36,12 +36,12 @@ import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketOutEntityVelocity extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> velocityConstructor, vec3dConstructor;
|
||||
private static Class<?> velocityClass, vec3dClass;
|
||||
private static Class<?> vec3dClass;
|
||||
private static boolean isVec3dPresent;
|
||||
private int entityID = -1;
|
||||
private double velocityX, velocityY, velocityZ;
|
||||
private Entity entity;
|
||||
private boolean isListening = false;
|
||||
private boolean isListening;
|
||||
|
||||
public WrappedPacketOutEntityVelocity(final Object packet) {
|
||||
super(packet);
|
||||
@@ -69,7 +69,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
* 1.14+ use int, Vec3D style
|
||||
*/
|
||||
public static void load() {
|
||||
velocityClass = PacketTypeClasses.Server.ENTITY_VELOCITY;
|
||||
Class<?> velocityClass = PacketTypeClasses.Server.ENTITY_VELOCITY;
|
||||
if (version.isHigherThan(ServerVersion.v_1_13_2)) {
|
||||
try {
|
||||
vec3dClass = NMSUtils.getNMSClass("Vec3D");
|
||||
|
||||
+3
-4
@@ -36,14 +36,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WrappedPacketOutExplosion extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> chunkPosClass, blockPosClass, vec3DClass;
|
||||
private static Constructor<?> chunkPosConstructor, blockPosConstructor, packetConstructor, vec3dConstructor;
|
||||
|
||||
public static void load() {
|
||||
chunkPosClass = NMSUtils.getNMSClassWithoutException("ChunkPosition");
|
||||
blockPosClass = NMSUtils.getNMSClassWithoutException("BlockPosition");
|
||||
Class<?> chunkPosClass = NMSUtils.getNMSClassWithoutException("ChunkPosition");
|
||||
Class<?> blockPosClass = NMSUtils.getNMSClassWithoutException("BlockPosition");
|
||||
Class<?> packetClass = NMSUtils.getNMSClassWithoutException("PacketPlayOutExplosion");
|
||||
vec3DClass = NMSUtils.getNMSClassWithoutException("Vec3D");
|
||||
Class<?> vec3DClass = NMSUtils.getNMSClassWithoutException("Vec3D");
|
||||
try {
|
||||
packetConstructor = packetClass.getConstructor(double.class, double.class, double.class, float.class, List.class, vec3DClass);
|
||||
vec3dConstructor = vec3DClass.getDeclaredConstructor(double.class, double.class, double.class);
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 retrooper
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.helditemslot;
|
||||
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketOutHeldItemSlot extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> packetConstructor;
|
||||
public static void load() {
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Server.HELD_ITEM_SLOT.getConstructor(int.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private int slot;
|
||||
public WrappedPacketOutHeldItemSlot(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutHeldItemSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public int getCurrentSelectedSlot() {
|
||||
if(packet == null){
|
||||
return slot;
|
||||
}
|
||||
return readInt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() {
|
||||
try {
|
||||
return packetConstructor.newInstance(slot);
|
||||
} catch (InstantiationException |
|
||||
IllegalAccessException |
|
||||
InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -33,11 +33,10 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketOutKeepAlive extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> keepAliveConstructor;
|
||||
private static boolean integerMode;
|
||||
private long id;
|
||||
private boolean isListening = false;
|
||||
private boolean isListening;
|
||||
|
||||
public WrappedPacketOutKeepAlive(Object packet) {
|
||||
super(packet);
|
||||
@@ -45,11 +44,11 @@ public class WrappedPacketOutKeepAlive extends WrappedPacket implements Sendable
|
||||
}
|
||||
|
||||
public WrappedPacketOutKeepAlive(long id) {
|
||||
super();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.KEEP_ALIVE;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.KEEP_ALIVE;
|
||||
integerMode = Reflection.getField(packetClass, int.class, 0) != null;
|
||||
|
||||
if (integerMode) {
|
||||
@@ -91,7 +90,7 @@ public class WrappedPacketOutKeepAlive extends WrappedPacket implements Sendable
|
||||
public Object asNMSPacket() {
|
||||
if (integerMode) {
|
||||
try {
|
||||
return keepAliveConstructor.newInstance((int) id);
|
||||
return keepAliveConstructor.newInstance(id);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,10 +34,10 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketOutKickDisconnect extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass, iChatBaseComponentClass;
|
||||
private static Class<?> iChatBaseComponentClass;
|
||||
private static Constructor<?> kickDisconnectConstructor;
|
||||
private String kickMessage;
|
||||
private boolean isListening = false;
|
||||
private boolean isListening;
|
||||
|
||||
public WrappedPacketOutKickDisconnect(final Object packet) {
|
||||
super(packet);
|
||||
@@ -50,7 +50,7 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.KICK_DISCONNECT;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.KICK_DISCONNECT;
|
||||
try {
|
||||
iChatBaseComponentClass = NMSUtils.getNMSClass("IChatBaseComponent");
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
+2
-7
@@ -24,27 +24,22 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.position;
|
||||
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
public final class WrappedPacketOutPosition extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
private boolean isListening = false;
|
||||
private final boolean isListening = true;
|
||||
|
||||
public WrappedPacketOutPosition(Object packet) {
|
||||
super(packet);
|
||||
isListening = true;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.POSITION;
|
||||
}
|
||||
public static void load() {}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
|
||||
+1
-2
@@ -32,7 +32,6 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketOutTransaction extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int windowId;
|
||||
private short actionNumber;
|
||||
@@ -51,7 +50,7 @@ public class WrappedPacketOutTransaction extends WrappedPacket implements Sendab
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.TRANSACTION;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.TRANSACTION;
|
||||
|
||||
try {
|
||||
packetConstructor = packetClass.getConstructor(int.class, short.class, boolean.class);
|
||||
|
||||
+2
-3
@@ -33,11 +33,10 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private float health, foodSaturation;
|
||||
private int food;
|
||||
private boolean isListening = false;
|
||||
private boolean isListening;
|
||||
|
||||
public WrappedPacketOutUpdateHealth(final Object packet) {
|
||||
super(packet);
|
||||
@@ -59,7 +58,7 @@ public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.UPDATE_HEALTH;
|
||||
Class<?> packetClass = PacketTypeClasses.Server.UPDATE_HEALTH;
|
||||
|
||||
try {
|
||||
packetConstructor = packetClass.getConstructor(float.class, int.class, float.class);
|
||||
|
||||
@@ -25,14 +25,16 @@
|
||||
package io.github.retrooper.packetevents.settings;
|
||||
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
|
||||
public class PacketEventsSettings {
|
||||
private ServerVersion backupServerVersion = ServerVersion.v_1_7_10;
|
||||
private boolean injectAsync = true;
|
||||
private boolean ejectAsync = true;
|
||||
private boolean useProtocolLibIfAvailable = false;
|
||||
private boolean useProtocolLibIfAvailable;
|
||||
private boolean checkForUpdates = true;
|
||||
private boolean injectEarly = true;
|
||||
private int packetHandlingThreadCount = 1;
|
||||
|
||||
public PacketEventsSettings backupServerVersion(ServerVersion serverVersion) {
|
||||
this.backupServerVersion = serverVersion;
|
||||
@@ -66,6 +68,11 @@ public class PacketEventsSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketEventsSettings packetHandlingThreadCount(int threadCount) {
|
||||
this.packetHandlingThreadCount = threadCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerVersion getBackupServerVersion() {
|
||||
return backupServerVersion;
|
||||
}
|
||||
@@ -89,4 +96,8 @@ public class PacketEventsSettings {
|
||||
public boolean shouldInjectEarly() {
|
||||
return injectEarly;
|
||||
}
|
||||
|
||||
public int getPacketHandlingThreadCount() {
|
||||
return packetHandlingThreadCount;
|
||||
}
|
||||
}
|
||||
@@ -37,30 +37,31 @@ import java.net.URLConnection;
|
||||
|
||||
public class UpdateChecker {
|
||||
public void handleUpdate() {
|
||||
inform("Checking for an update, please wait...");
|
||||
PEVersion localVersion = PacketEvents.getVersion();
|
||||
try {
|
||||
String line = readLatestVersion();
|
||||
PEVersion newVersion = new PEVersion(line);
|
||||
if (localVersion.isOlder(newVersion)) {
|
||||
inform("[PacketEvents] There is an update available for the PacketEvents API! (" + newVersion.toString() + ")");
|
||||
inform("There is an update available for the PacketEvents API! Your build: (" + localVersion.toString() + ") | Update: (" + newVersion.toString() + ")");
|
||||
}
|
||||
else if(localVersion.equals(newVersion)) {
|
||||
inform("[PacketEvents] You are on the latest released version of PacketEvents. (" + newVersion.toString() + ")");
|
||||
inform("You are on the latest released version of PacketEvents. Your build: (" + newVersion.toString() + ")");
|
||||
}
|
||||
else if(localVersion.isNewer(newVersion)) {
|
||||
inform("[PacketEvents] You are on a dev or pre released build of PacketEvents. Your build: (" + localVersion.toString() + ") | Last released build: (" + newVersion.toString() + ")");
|
||||
inform("You are on a dev or pre released build of PacketEvents. Your build: (" + localVersion.toString() + ") | Last released build: (" + newVersion.toString() + ")");
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
report("[PacketEvents] We failed to find the latest released version of PacketEvents. Your build: (" + localVersion.toString() + ")");
|
||||
} catch (IOException exception) {
|
||||
report("We failed to find the latest released version of PacketEvents. Your build: (" + localVersion.toString() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private void inform(String message) {
|
||||
Bukkit.getLogger().info(message);
|
||||
Bukkit.getLogger().info("[PacketEvents] " + message);
|
||||
}
|
||||
|
||||
private void report(String message) {
|
||||
Bukkit.getLogger().info(ChatColor.DARK_RED + message);
|
||||
Bukkit.getLogger().info(ChatColor.DARK_RED + "[PacketEvents] " + message);
|
||||
}
|
||||
|
||||
private String readLatestVersion() throws IOException {
|
||||
@@ -68,7 +69,6 @@ public class UpdateChecker {
|
||||
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
|
||||
return reader.readLine();
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -61,9 +61,7 @@ public class WrappedGameProfile {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,12 @@ public final class NMSUtils {
|
||||
public static String nettyPrefix = "io.netty";
|
||||
public static Class<?> nmsEntityClass, minecraftServerClass, craftWorldClass, playerInteractManagerClass, entityPlayerClass, playerConnectionClass, craftServerClass,
|
||||
craftPlayerClass, serverConnectionClass, craftEntityClass,
|
||||
craftItemStack, nmsItemStackClass, networkManagerClass, nettyChannelClass, gameProfileClass, iChatBaseComponentClass;
|
||||
private static Method craftWorldGetHandle, getCraftWorldHandleMethod, getServerConnection, getCraftPlayerHandle, getCraftEntityHandle, asBukkitCopy;
|
||||
craftItemStack, nmsItemStackClass, networkManagerClass, nettyChannelClass, gameProfileClass, iChatBaseComponentClass,
|
||||
blockPosClass, enumDirectionClass;
|
||||
private static Method craftWorldGetHandle;
|
||||
private static Method getCraftPlayerHandle;
|
||||
private static Method getCraftEntityHandle;
|
||||
private static Method asBukkitCopy;
|
||||
private static Field entityPlayerPingField, playerConnectionField;
|
||||
|
||||
public static final HashMap<UUID, Object> channelCache = new HashMap<>();
|
||||
@@ -90,13 +94,12 @@ public final class NMSUtils {
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
blockPosClass = NMSUtils.getNMSClassWithoutException("BlockPosition");
|
||||
enumDirectionClass = NMSUtils.getNMSClassWithoutException("EnumDirection");
|
||||
//METHODS
|
||||
try {
|
||||
getCraftWorldHandleMethod = craftWorldClass.getMethod("getHandle");
|
||||
getCraftPlayerHandle = craftPlayerClass.getMethod("getHandle");
|
||||
getCraftEntityHandle = craftEntityClass.getMethod("getHandle");
|
||||
getServerConnection = minecraftServerClass.getMethod("getServerConnection");
|
||||
asBukkitCopy = craftItemStack.getMethod("asBukkitCopy", nmsItemStackClass);
|
||||
craftWorldGetHandle = craftWorldClass.getMethod("getHandle");
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
package io.github.retrooper.packetevents.utils.player;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
|
||||
public enum ClientVersion {
|
||||
LOWER_THAN_SUPPORTED_VERSIONS(4),
|
||||
v_1_7_10(5),
|
||||
|
||||
@@ -26,10 +26,8 @@ package io.github.retrooper.packetevents.utils.player;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.event.impl.PlayerEjectEvent;
|
||||
import io.github.retrooper.packetevents.packetmanager.netty.NettyPacketManager;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
+7
-9
@@ -30,21 +30,21 @@ import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
|
||||
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class ProtocolLibListener {
|
||||
|
||||
public static void registerProtocolLibListener(PacketListener listener, ConcurrentLinkedQueue<Method> methods) {
|
||||
public class ProtocolLibAPIListener {
|
||||
public static void registerProtocolLibListener(PacketListener listener, List<Method> methods) {
|
||||
if (ProtocolLibUtils.isAvailable()) {
|
||||
for (Method m : methods) {
|
||||
if (m.getParameterTypes()[0].equals(PacketReceiveEvent.class)) {
|
||||
@@ -62,7 +62,7 @@ public class ProtocolLibListener {
|
||||
break;
|
||||
case PacketEventPriority.HIGHEST:
|
||||
priority = ListenerPriority.HIGHEST;
|
||||
break;
|
||||
break;
|
||||
case PacketEventPriority.MONITOR:
|
||||
priority = ListenerPriority.MONITOR;
|
||||
break;
|
||||
@@ -141,6 +141,4 @@ public class ProtocolLibListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,14 +25,9 @@
|
||||
package io.github.retrooper.packetevents.utils.protocollib;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ProtocolLibUtils {
|
||||
public static boolean isAvailable() {
|
||||
return Bukkit.getPluginManager().isPluginEnabled("ProtocolLib");
|
||||
}
|
||||
|
||||
public static int getProtocolVersion(final Player player) {
|
||||
return ProtocolLibAPIAccessor.getProtocolVersion(player);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ClassUtil {
|
||||
private static final Map<String, String> classSimpleNameCache = new HashMap<String, String>();
|
||||
private static final Map<String, String> classSimpleNameCache = new HashMap<>();
|
||||
|
||||
public static String getClassSimpleName(Class<?> cls) {
|
||||
String simpleClassName = classSimpleNameCache.get(cls.getName());
|
||||
|
||||
@@ -48,13 +48,7 @@ public class PEVersion {
|
||||
//1.2.3.4
|
||||
text += ".";
|
||||
|
||||
int dotCount = 0;
|
||||
char[] chars = text.toCharArray();
|
||||
for (char c : chars) {
|
||||
if (c == '.') {
|
||||
dotCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//1.2.3.4.
|
||||
int arrayIndex = 0;
|
||||
|
||||
@@ -50,7 +50,7 @@ public enum ServerVersion {
|
||||
this.protocolId = protocolId;
|
||||
}
|
||||
|
||||
public short toProtocolVersion() {
|
||||
public short getProtocolVersion() {
|
||||
return protocolId;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ package io.github.retrooper.packetevents.utils.vector;
|
||||
|
||||
public class Vector3i {
|
||||
public int x, y, z;
|
||||
public Vector3i() {
|
||||
|
||||
}
|
||||
public Vector3i() {}
|
||||
|
||||
public Vector3i(int x, int y, int z) {
|
||||
this.x = x;
|
||||
|
||||
+3
-8
@@ -25,7 +25,6 @@
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibUtils;
|
||||
import io.github.retrooper.packetevents.utils.protocolsupport.ProtocolSupportUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.v_1_7_10.ProtocolVersionAccessor_v_1_7;
|
||||
@@ -39,9 +38,8 @@ public class VersionLookupUtils {
|
||||
public static void handleLoadedDependencies() {
|
||||
protocolAccessMode = (byte) (ViaUtils.isAvailable() ?
|
||||
0 : ProtocolSupportUtils.isAvailable() ?
|
||||
1 : ProtocolLibUtils.isAvailable() ?
|
||||
2 : PacketEvents.getAPI().getServerUtils().getVersion() == ServerVersion.v_1_7_10 ?
|
||||
3 : -1);
|
||||
1 : PacketEvents.getAPI().getServerUtils().getVersion() == ServerVersion.v_1_7_10 ?
|
||||
2 : -1);
|
||||
}
|
||||
|
||||
public static boolean hasHandledLoadedDependencies() {
|
||||
@@ -50,8 +48,7 @@ public class VersionLookupUtils {
|
||||
|
||||
public static boolean isDependencyAvailable() {
|
||||
return ViaUtils.isAvailable()
|
||||
|| ProtocolSupportUtils.isAvailable()
|
||||
|| ProtocolLibUtils.isAvailable();
|
||||
|| ProtocolSupportUtils.isAvailable();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +68,6 @@ public class VersionLookupUtils {
|
||||
case 1:
|
||||
return ProtocolSupportUtils.getProtocolVersion(player);
|
||||
case 2:
|
||||
return ProtocolLibUtils.getProtocolVersion(player);
|
||||
case 3:
|
||||
return ProtocolVersionAccessor_v_1_7.getProtocolVersion(player);
|
||||
default:
|
||||
return -1;
|
||||
|
||||
Reference in new issue
Block a user