Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9347e7a133 | ||
|
|
33ed5ff904 | ||
|
|
291994d388 | ||
|
|
f6ea9675bf | ||
|
|
cc303f56a4 | ||
|
|
290bd0a8fe | ||
|
|
a8573cc8e1 | ||
|
|
814bd941c0 | ||
|
|
d3f6d32848 | ||
|
|
5e1b82ea8a | ||
|
|
e49cae5d67 | ||
|
|
8168bb2085 | ||
|
|
621a7c98b9 | ||
|
|
28da2aafc4 | ||
|
|
e89e6fac28 | ||
|
|
a5e067af9e | ||
|
|
04de7fd5ea | ||
|
|
815428f35b | ||
|
|
833f569150 | ||
|
|
6b227d55aa | ||
|
|
57a6c26c07 | ||
|
|
b2da168f6a | ||
|
|
4c1e14af57 | ||
|
|
5f9e82617f | ||
|
|
9868facdde | ||
|
|
d45f8bddac | ||
|
|
e4b086e7e5 | ||
|
|
7afe3c63cd | ||
|
|
5103acf414 | ||
|
|
70b763b5a3 | ||
|
|
e1370b803f | ||
|
|
ac3ca0ddf7 | ||
|
|
15bec5525a | ||
|
|
0e8dcb6a40 | ||
|
|
836efcfa03 | ||
|
|
774e6decf3 | ||
|
|
839265e0b9 | ||
|
|
32c94c85f1 | ||
|
|
a36df67f6f | ||
|
|
cdb46f476c | ||
|
|
96e5e7393e | ||
|
|
130001a44c | ||
|
|
1328ea81e8 | ||
|
|
a42153cff9 | ||
|
|
79929f5700 |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# packetevents by retrooper
|
||||
# packetevents
|
||||
|
||||
A lightweight spigot packetlistener & packetsender coded by retrooper.
|
||||
A spigot packet API with some nice utlities.
|
||||
|
||||
## About
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.6.7</version>
|
||||
<version>1.6.8</version>
|
||||
|
||||
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
|
||||
<build>
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package io.github.retrooper.packetevents;
|
||||
|
||||
import io.github.retrooper.packetevents.api.PacketEventsAPI;
|
||||
import io.github.retrooper.packetevents.enums.ClientVersion;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
@@ -32,8 +31,8 @@ import io.github.retrooper.packetevents.event.impl.BukkitMoveEvent;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms_entityfinder.EntityFinderUtils;
|
||||
import io.github.retrooper.packetevents.utils.entityfinder.EntityFinderUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -44,34 +43,33 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class PacketEvents implements Listener {
|
||||
private static final PacketEventsAPI packetEventsAPI = new PacketEventsAPI();
|
||||
private static final PacketEvents instance = new PacketEvents();
|
||||
private static final PacketEventsSettings settings = new PacketEventsSettings();
|
||||
private static final ArrayList<Plugin> plugins = new ArrayList<Plugin>(1);
|
||||
private static boolean hasLoaded, isStarted;
|
||||
private static boolean loaded, initialized, isBungee;
|
||||
|
||||
/**
|
||||
* This loads the PacketEvents API.
|
||||
*
|
||||
* <p>
|
||||
* ServerVersion:
|
||||
* In this method we detect and cache the server version.
|
||||
*
|
||||
* <p>
|
||||
* NMSUtils:
|
||||
* We setup some NMS utilities.
|
||||
*
|
||||
* <p>
|
||||
* Packet ID System:
|
||||
* All the packet classes we will be needing are cached in a Map with an integer ID.
|
||||
*
|
||||
* <p>
|
||||
* Version Lookup Utils:
|
||||
* We setup the client protocol version system.
|
||||
* We check if ViaVersion, ProtocolSupport or ProtocolLib is present.
|
||||
*
|
||||
* <p>
|
||||
* Wrappers:
|
||||
* All PacketEvents' wrappers are setup and do all loading they need to do.
|
||||
*
|
||||
*/
|
||||
public static void load() {
|
||||
ServerVersion version = ServerVersion.getVersion();
|
||||
@@ -90,25 +88,25 @@ public final class PacketEvents implements Listener {
|
||||
ClientVersion.prepareLookUp();
|
||||
|
||||
WrappedPacket.loadAllWrappers();
|
||||
hasLoaded = true;
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates PacketEvents
|
||||
*
|
||||
* <p>
|
||||
* Loading:
|
||||
* Loads PacketEvents if you haven't already.
|
||||
*
|
||||
* <p>
|
||||
* Registering:
|
||||
* Registers this class as a Bukkit listener to inject/eject players.
|
||||
*
|
||||
* @param pl JavaPlugin instance
|
||||
*/
|
||||
public static void init(final Plugin pl) {
|
||||
if (!hasLoaded) {
|
||||
if (!loaded) {
|
||||
load();
|
||||
}
|
||||
if (!isStarted) {
|
||||
if (!initialized) {
|
||||
plugins.add(pl);
|
||||
//Register Bukkit listener
|
||||
Bukkit.getPluginManager().registerEvents(instance, plugins.get(0));
|
||||
@@ -116,12 +114,22 @@ public final class PacketEvents implements Listener {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
getAPI().getPlayerUtils().injectPlayer(p);
|
||||
}
|
||||
isStarted = true;
|
||||
initialized = true;
|
||||
|
||||
Class<?> spigotConfigClass;
|
||||
try {
|
||||
spigotConfigClass = Class.forName("org.spigotmc.SpigotConfig");
|
||||
Field f = spigotConfigClass.getDeclaredField("bungee");
|
||||
isBungee = f.getBoolean(null);
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
|
||||
isBungee = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PacketEvents if you haven't already, Sets everything up, injects all players
|
||||
*
|
||||
* @param pl Plugin instance
|
||||
* @deprecated Use {@link #init(Plugin)}
|
||||
*/
|
||||
@@ -134,27 +142,27 @@ public final class PacketEvents implements Listener {
|
||||
*
|
||||
*/
|
||||
public static void stop() {
|
||||
if (isStarted) {
|
||||
if (initialized) {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
getAPI().getPlayerUtils().ejectPlayer(p);
|
||||
}
|
||||
getAPI().getEventManager().unregisterAllListeners();
|
||||
|
||||
isStarted = false;
|
||||
initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasLoaded() {
|
||||
return hasLoaded;
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean hasStarted() {
|
||||
return isStarted;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static boolean isInitialized() {
|
||||
return isStarted;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static PacketEventsAPI getAPI() {
|
||||
@@ -171,21 +179,27 @@ public final class PacketEvents implements Listener {
|
||||
}
|
||||
|
||||
public static String getHandlerName(final String name) {
|
||||
return "pe-" + settings.getIdentifier() + "-" + name;
|
||||
return "pe-" + PacketEvents.getAPI().getSettings().getIdentifier() + "-" + name;
|
||||
}
|
||||
|
||||
public static PacketEventsSettings getSettings() {
|
||||
return settings;
|
||||
return PacketEvents.getAPI().getSettings();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
if(!VersionLookupUtils.hasLoaded()) {
|
||||
if (!VersionLookupUtils.hasLoaded()) {
|
||||
VersionLookupUtils.load();
|
||||
}
|
||||
ClientVersion version = ClientVersion.fromProtocolVersion(VersionLookupUtils.getProtocolVersion(e.getPlayer()));
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(e.getPlayer().getUniqueId(), version);
|
||||
PacketEvents.getAPI().getPlayerUtils().injectPlayer(e.getPlayer());
|
||||
//for now we don't support bungee, rather handle it than have it FALSE
|
||||
//and return the version of the server.
|
||||
if (isBungee) {
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(e.getPlayer().getUniqueId(), ClientVersion.ACCESS_FAILURE);
|
||||
} else {
|
||||
ClientVersion version = ClientVersion.fromProtocolVersion(VersionLookupUtils.getProtocolVersion(e.getPlayer()));
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(e.getPlayer().getUniqueId(), version);
|
||||
PacketEvents.getAPI().getPlayerUtils().injectPlayer(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
+27
-3
@@ -22,16 +22,19 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.api;
|
||||
package io.github.retrooper.packetevents;
|
||||
|
||||
import io.github.retrooper.packetevents.event.manager.EventManager;
|
||||
import io.github.retrooper.packetevents.utils.api.PlayerUtils;
|
||||
import io.github.retrooper.packetevents.utils.api.ServerUtils;
|
||||
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import io.github.retrooper.packetevents.utils.player.PlayerUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerUtils;
|
||||
|
||||
public final class PacketEventsAPI {
|
||||
private final EventManager eventManager = new EventManager();
|
||||
private final PlayerUtils playerUtils = new PlayerUtils();
|
||||
private final ServerUtils serverUtils = new ServerUtils();
|
||||
private final PacketEventsSettings settings = new PacketEventsSettings();
|
||||
//private final UpdateChecker updateChecker = new UpdateChecker();
|
||||
|
||||
/**
|
||||
* Not thread safe
|
||||
@@ -61,6 +64,7 @@ public final class PacketEventsAPI {
|
||||
|
||||
/**
|
||||
* Get all utilities to do with the player
|
||||
*
|
||||
* @return Player Utilities
|
||||
*/
|
||||
public PlayerUtils getPlayerUtils() {
|
||||
@@ -69,6 +73,7 @@ public final class PacketEventsAPI {
|
||||
|
||||
/**
|
||||
* Get all utilities to do with the server
|
||||
*
|
||||
* @return Server Utilities
|
||||
*/
|
||||
public ServerUtils getServerUtils() {
|
||||
@@ -79,9 +84,28 @@ public final class PacketEventsAPI {
|
||||
/**
|
||||
* Get the event manager
|
||||
* Used to call events, register and unregister listeners
|
||||
*
|
||||
* @return PacketEvents' event manager
|
||||
*/
|
||||
public EventManager getEventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PacketEvents settings.
|
||||
*
|
||||
* @return Configure some settings for the API
|
||||
*/
|
||||
public PacketEventsSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
/*
|
||||
/**
|
||||
* Get the update checker
|
||||
* @return Update Checker
|
||||
*
|
||||
public UpdateChecker getUpdateChecker() {
|
||||
return updateChecker;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.enums;
|
||||
|
||||
@Deprecated
|
||||
public enum EventSynchronization {
|
||||
NORMAL, FORCE_SYNC, FORCE_ASYNC
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.enums;
|
||||
|
||||
@Deprecated
|
||||
public interface PacketEventPriority {
|
||||
byte LOWEST = 0;
|
||||
byte LOW = 1;
|
||||
|
||||
@@ -26,7 +26,7 @@ package io.github.retrooper.packetevents.event.impl;
|
||||
|
||||
import io.github.retrooper.packetevents.event.CancellableEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.packet.PacketType;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ package io.github.retrooper.packetevents.event.impl;
|
||||
|
||||
import io.github.retrooper.packetevents.event.CancellableEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.packet.PacketType;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,7 +111,8 @@ public final class EventManager {
|
||||
}
|
||||
|
||||
if (!methods.isEmpty()) {
|
||||
if (ProtocolLibUtils.isAvailable()) {
|
||||
if (ProtocolLibUtils.isAvailable()
|
||||
&& PacketEvents.getAPI().getSettings().isUseProtocolLibIfAvailable()) {
|
||||
ProtocolLibListener.registerProtocolLibListener(listener, methods);
|
||||
} else {
|
||||
registeredMethods.put(listener, methods);
|
||||
|
||||
+8
-35
@@ -22,40 +22,13 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.reflectionutils.fielddata;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class FieldWithName {
|
||||
|
||||
private final Class<?> cls;
|
||||
private final String name;
|
||||
|
||||
public FieldWithName(Class<?> cls, String name) {
|
||||
this.cls = cls;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Class<?> getCls() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldWithName that = (FieldWithName) o;
|
||||
return name.equals(that.name) &&
|
||||
Objects.equals(cls, that.cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(cls, name);
|
||||
}
|
||||
package io.github.retrooper.packetevents.event.priority;
|
||||
|
||||
public interface PacketEventPriority {
|
||||
byte LOWEST = 0;
|
||||
byte LOW = 1;
|
||||
byte NORMAL = 2;
|
||||
byte HIGH = 3;
|
||||
byte HIGHEST = 4;
|
||||
byte MONITOR = 5;
|
||||
}
|
||||
@@ -25,7 +25,12 @@
|
||||
package io.github.retrooper.packetevents.example;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.updatesign.WrappedPacketInUpdateSign;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.entityvelocity.WrappedPacketOutEntityVelocity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class MainExample extends JavaPlugin implements PacketListener {
|
||||
@@ -37,7 +42,14 @@ public class MainExample extends JavaPlugin implements PacketListener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
//Deprecated, as it is no longer needed
|
||||
//Deprecated, as it is no longer needed.
|
||||
/*
|
||||
*
|
||||
* PacketEvents will generate a random identifier for you if you do not set one
|
||||
* before initializing PacketEvents
|
||||
*
|
||||
*/
|
||||
|
||||
PacketEvents.getSettings().setIdentifier("official_api");
|
||||
|
||||
PacketEvents.init(this);
|
||||
|
||||
+9
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.handler;
|
||||
package io.github.retrooper.packetevents.nettyhandler;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
@@ -170,4 +170,12 @@ public class NettyPacketHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void sendPacket(Object channel, Object packet) {
|
||||
if(v1_7_nettyMode) {
|
||||
NettyPacketHandler_7.sendPacket(channel, packet);
|
||||
}
|
||||
else {
|
||||
NettyPacketHandler_8.sendPacket(channel, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -22,10 +22,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.handler;
|
||||
package io.github.retrooper.packetevents.nettyhandler;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.ChannelDuplexHandler;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
|
||||
@@ -33,8 +33,6 @@ import net.minecraft.util.io.netty.channel.ChannelPipeline;
|
||||
import net.minecraft.util.io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
final class NettyPacketHandler_7 {
|
||||
|
||||
/**
|
||||
@@ -70,7 +68,13 @@ final class NettyPacketHandler_7 {
|
||||
* @param player
|
||||
*/
|
||||
public static void ejectPlayer(final Player player) {
|
||||
final Channel channel = (Channel) NMSUtils.getChannel(player);
|
||||
Channel channel = (Channel) NMSUtils.getChannel(player);
|
||||
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
|
||||
NMSUtils.channelCache.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static void sendPacket(Object rawChannel, Object packet) {
|
||||
Channel channel = (Channel)rawChannel;
|
||||
channel.pipeline().writeAndFlush(packet);
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -22,10 +22,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.handler;
|
||||
package io.github.retrooper.packetevents.nettyhandler;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -33,8 +33,6 @@ import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
final class NettyPacketHandler_8 {
|
||||
/**
|
||||
* Inject a player with 1.8+ netty import location.
|
||||
@@ -71,5 +69,11 @@ final class NettyPacketHandler_8 {
|
||||
public static void ejectPlayer(final Player player) {
|
||||
final Channel channel = (Channel) NMSUtils.getChannel(player);
|
||||
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
|
||||
NMSUtils.channelCache.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static void sendPacket(Object rawChannel, Object packet) {
|
||||
Channel channel = (Channel)rawChannel;
|
||||
channel.pipeline().writeAndFlush(packet);
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,9 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packet;
|
||||
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
public class PacketTypeClasses {
|
||||
public static class Client {
|
||||
@@ -52,9 +53,9 @@ public class PacketTypeClasses {
|
||||
POSITION_LOOK = NMSUtils.getNMSClass(c + "PositionLook");
|
||||
LOOK = NMSUtils.getNMSClass(c + "Look");
|
||||
} catch (ClassNotFoundException e) {
|
||||
POSITION = Reflection.getSubClass(FLYING, c + "Position");
|
||||
POSITION_LOOK = Reflection.getSubClass(FLYING, c + "PositionLook");
|
||||
LOOK = Reflection.getSubClass(FLYING, c + "Look");
|
||||
POSITION = SubclassUtil.getSubClass(FLYING, c + "Position");
|
||||
POSITION_LOOK = SubclassUtil.getSubClass(FLYING, c + "PositionLook");
|
||||
LOOK = SubclassUtil.getSubClass(FLYING, c + "Look");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -195,9 +196,9 @@ public class PacketTypeClasses {
|
||||
MAP = NMSUtils.getNMSClassWithoutException(s + "Map");
|
||||
OPEN_WINDOW_MERCHANT = NMSUtils.getNMSClassWithoutException(s + "OpenWindowMerchant");
|
||||
ENTITY = NMSUtils.getNMSClassWithoutException(s + "Entity");
|
||||
REL_ENTITY_MOVE = Reflection.getSubClass(ENTITY, s + "RelEntityMove");
|
||||
REL_ENTITY_MOVE_LOOK = Reflection.getSubClass(ENTITY, s + "RelEntityMoveLook");
|
||||
ENTITY_LOOK = Reflection.getSubClass(ENTITY, s + "EntityLook");
|
||||
REL_ENTITY_MOVE = SubclassUtil.getSubClass(ENTITY, s + "RelEntityMove");
|
||||
REL_ENTITY_MOVE_LOOK = SubclassUtil.getSubClass(ENTITY, s + "RelEntityMoveLook");
|
||||
ENTITY_LOOK = SubclassUtil.getSubClass(ENTITY, s + "EntityLook");
|
||||
if (REL_ENTITY_MOVE == null) {
|
||||
//is not a subclass and should be accessed normally
|
||||
REL_ENTITY_MOVE = NMSUtils.getNMSClassWithoutException(s + "RelEntityMove");
|
||||
|
||||
+3
-1
@@ -22,7 +22,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.packet;
|
||||
package io.github.retrooper.packetevents.packettype;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -40,6 +40,7 @@ import io.github.retrooper.packetevents.packetwrappers.in.keepalive.WrappedPacke
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.settings.WrappedPacketInSettings;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.steervehicle.WrappedPacketInSteerVehicle;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.transaction.WrappedPacketInTransaction;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.updatesign.WrappedPacketInUpdateSign;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.useentity.WrappedPacketInUseEntity;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.windowclick.WrappedPacketInWindowClick;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.abilities.WrappedPacketOutAbilities;
|
||||
@@ -47,15 +48,22 @@ import io.github.retrooper.packetevents.packetwrappers.out.animation.WrappedPack
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.chat.WrappedPacketOutChat;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.entity.WrappedPacketOutEntity;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.entityvelocity.WrappedPacketOutEntityVelocity;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.gamestatechange.WrappedPacketOutGameStateChange;
|
||||
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;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.transaction.WrappedPacketOutTransaction;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.updatehealth.WrappedPacketOutUpdateHealth;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class WrappedPacket implements WrapperPacketReader {
|
||||
protected final List<Field> fields = new ArrayList<>();
|
||||
public static ServerVersion version;
|
||||
protected final Player player;
|
||||
protected Object packet;
|
||||
@@ -70,15 +78,22 @@ public class WrappedPacket implements WrapperPacketReader {
|
||||
}
|
||||
|
||||
public WrappedPacket(final Player player, final Object packet) {
|
||||
this.player = player;
|
||||
if (packet == null) return;
|
||||
this.packet = packet;
|
||||
if (packet == null) {
|
||||
this.player = null;
|
||||
return;
|
||||
}
|
||||
this.packetClass = packet.getClass();
|
||||
if (packet.getClass().getSuperclass().equals(PacketTypeClasses.Client.FLYING)) {
|
||||
packetClass = PacketTypeClasses.Client.FLYING;
|
||||
} else if (packet.getClass().getSuperclass().equals(PacketTypeClasses.Server.ENTITY)) {
|
||||
packetClass = PacketTypeClasses.Server.ENTITY;
|
||||
}
|
||||
for (Field f : packetClass.getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
fields.add(f);
|
||||
}
|
||||
this.player = player;
|
||||
this.packet = packet;
|
||||
setup();
|
||||
}
|
||||
|
||||
@@ -99,6 +114,7 @@ public class WrappedPacket implements WrapperPacketReader {
|
||||
WrappedPacketInSteerVehicle.load();
|
||||
WrappedPacketInTransaction.load();
|
||||
WrappedPacketInUseEntity.load();
|
||||
WrappedPacketInUpdateSign.load();
|
||||
WrappedPacketInWindowClick.load();
|
||||
|
||||
//CLIENTBOUND
|
||||
@@ -112,6 +128,7 @@ public class WrappedPacket implements WrapperPacketReader {
|
||||
WrappedPacketOutPosition.load();
|
||||
WrappedPacketOutTransaction.load();
|
||||
WrappedPacketOutUpdateHealth.load();
|
||||
WrappedPacketOutGameStateChange.load();
|
||||
//WrappedPacketOutCustomPayload.load();
|
||||
}
|
||||
|
||||
@@ -121,90 +138,214 @@ public class WrappedPacket implements WrapperPacketReader {
|
||||
|
||||
@Override
|
||||
public boolean readBoolean(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, boolean.class, index).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
return (boolean) readObject(index, boolean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, byte.class, index).getByte(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
return (byte) readObject(index, byte.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, short.class, index).getShort(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
return (short) readObject(index, short.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, int.class, index).getInt(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
return (int) readObject(index, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, long.class, index).getLong(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
return (long) readObject(index, long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, float.class, index).getFloat(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
return (float) readObject(index, float.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, double.class, index).getDouble(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return (double) readObject(index, double.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean[] readBooleanArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (boolean[].class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (boolean[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return new boolean[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readByteArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (byte[].class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (byte[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public short[] readShortArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (short[].class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (short[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new short[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] readIntArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (int[].class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (int[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] readLongArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (long[].class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (long[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new long[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] readFloatArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (float.class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (float[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new float[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] readDoubleArray(int index) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (double[].class.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (double[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new double[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] readStringArray(int index) {
|
||||
Object[] array = readObjectArray(index, String[].class);
|
||||
int len = array.length;
|
||||
String[] stringArray = new String[len];
|
||||
for(int i = 0; i < len; i++) {
|
||||
stringArray[i] = array[i].toString();
|
||||
}
|
||||
return stringArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] readObjectArray(int index, Class<?> type) {
|
||||
int currentIndex = 0;
|
||||
for(Field f : fields) {
|
||||
if (type.isAssignableFrom(f.getType())) {
|
||||
if(index == currentIndex++) {
|
||||
try {
|
||||
return (Object[]) f.get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(int index, Class<?> type) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, type, index).get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
int currentIndex = 0;
|
||||
for (Field f : fields) {
|
||||
if (type.isAssignableFrom(f.getType())) {
|
||||
if (index == currentIndex++) {
|
||||
try {
|
||||
return f.get(packet);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readAnyObject(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, index).get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
int currentIndex = 0;
|
||||
for (Field f : fields) {
|
||||
if (index == currentIndex++) {
|
||||
try {
|
||||
return f.get(packet);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+18
@@ -40,6 +40,24 @@ public interface WrapperPacketReader {
|
||||
|
||||
double readDouble(int index);
|
||||
|
||||
boolean[] readBooleanArray(int index);
|
||||
|
||||
byte[] readByteArray(int index);
|
||||
|
||||
short[] readShortArray(int index);
|
||||
|
||||
int[] readIntArray(int index);
|
||||
|
||||
long[] readLongArray(int index);
|
||||
|
||||
float[] readFloatArray(int index);
|
||||
|
||||
double[] readDoubleArray(int index);
|
||||
|
||||
String[] readStringArray(int index);
|
||||
|
||||
Object[] readObjectArray(int index, Class<?> type);
|
||||
|
||||
Object readObject(int index, Class<?> type);
|
||||
|
||||
Object readAnyObject(int index);
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import io.github.retrooper.packetevents.annotations.NotNull;
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
public final class WrappedPacketInAbilities extends WrappedPacket {
|
||||
private static boolean isMoreThanOneBoolPresent;
|
||||
|
||||
+8
-8
@@ -28,8 +28,9 @@ import io.github.retrooper.packetevents.enums.Direction;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
|
||||
public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
@@ -59,7 +60,7 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//It is probably a subclass
|
||||
digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType");
|
||||
digTypeClass = SubclassUtil.getSubClass(blockDigClass, "EnumPlayerDigType");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +73,7 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
//1.7.10
|
||||
try {
|
||||
if (isVersionLowerThan_v_1_8) {
|
||||
enumDigType = PlayerDigType.values()[(Reflection.getField(blockDigClass, int.class, 4).getInt(packet))];
|
||||
enumDigType = PlayerDigType.values()[(readInt(4))];
|
||||
x = readInt(0);
|
||||
y = readInt(1);
|
||||
z = readInt(2);
|
||||
@@ -83,10 +84,9 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
final Object enumDirectionObj = readObject(0, enumDirectionClass);
|
||||
final Object digTypeObj = readObject(0, digTypeClass);
|
||||
|
||||
Class<?> blockPosSuper = blockPositionClass;
|
||||
x = Reflection.getField(blockPosSuper, int.class, 0).getInt(blockPosObj);
|
||||
y = Reflection.getField(blockPosSuper, int.class, 1).getInt(blockPosObj);
|
||||
z = Reflection.getField(blockPosSuper, int.class, 2).getInt(blockPosObj);
|
||||
x = Reflection.getField(blockPositionClass, int.class, 0).getInt(blockPosObj);
|
||||
y = Reflection.getField(blockPositionClass, int.class, 1).getInt(blockPosObj);
|
||||
z = Reflection.getField(blockPositionClass, int.class, 2).getInt(blockPosObj);
|
||||
|
||||
//.toString() won't work so we must do this
|
||||
enumDirection = Direction.valueOf(((Enum)enumDirectionObj).name());
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@ package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ package io.github.retrooper.packetevents.packetwrappers.in.chat;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInChat extends WrappedPacket {
|
||||
private static Class<?> chatPacketClass;
|
||||
|
||||
+3
-3
@@ -26,8 +26,8 @@ package io.github.retrooper.packetevents.packetwrappers.in.clientcommand;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
public final class WrappedPacketInClientCommand extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
@@ -45,7 +45,7 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
|
||||
enumClientCommandClass = NMSUtils.getNMSClass("EnumClientCommand");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//Probably a subclass
|
||||
enumClientCommandClass = Reflection.getSubClass(packetClass, "EnumClientCommand");
|
||||
enumClientCommandClass = SubclassUtil.getSubClass(packetClass, "EnumClientCommand");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -27,9 +27,8 @@ package io.github.retrooper.packetevents.packetwrappers.in.custompayload;
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.clientcommand.WrappedPacketInClientCommand;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -55,7 +54,7 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
//Only on 1.13+
|
||||
nmsMinecraftKey = NMSUtils.getNMSClass("MinecraftKey");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//Its okay, this means they are on versions 1.7.10 ~ 1.12.2
|
||||
//Its okay, this means they are on versions 1.7.10 - 1.12.2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-9
@@ -26,10 +26,9 @@ package io.github.retrooper.packetevents.packetwrappers.in.entityaction;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -45,15 +44,16 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
private int entityId;
|
||||
private PlayerAction action;
|
||||
private int jumpBoost;
|
||||
|
||||
public WrappedPacketInEntityAction(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
entityActionClass = PacketTypeClasses.Client.ENTITY_ACTION;
|
||||
entityActionClass = NMSUtils.getNMSClassWithoutException("PacketPlayInEntityAction");
|
||||
isLowerThan_v_1_8 = version.isLowerThan(ServerVersion.v_1_8);
|
||||
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
|
||||
enumPlayerActionClass = Reflection.getSubClass(entityActionClass, "EnumPlayerAction");
|
||||
if (!isLowerThan_v_1_8) {
|
||||
enumPlayerActionClass = SubclassUtil.getSubClass(entityActionClass, "EnumPlayerAction");
|
||||
}
|
||||
//All the already existing values
|
||||
for (PlayerAction val : PlayerAction.values()) {
|
||||
@@ -90,8 +90,8 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
this.action = cachedPlayerActionIDs.get(animationIndex);
|
||||
} else {
|
||||
final Object enumObj = readObject(0, enumPlayerActionClass);
|
||||
final String enumName = enumObj.toString();
|
||||
this.action = cachedPlayerActionNames.get(enumName);
|
||||
final String enumValueName = enumObj.toString();
|
||||
this.action = cachedPlayerActionNames.get(enumValueName);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,16 +101,21 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Lookup the associated entity by the ID that was sent in the packet.
|
||||
*
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return NMSUtils.getEntityById(this.entityId);
|
||||
if(entity == null) {
|
||||
return entity = NMSUtils.getEntityById(this.entityId);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the entity.
|
||||
* If you do not want to use {@link #getEntity()},
|
||||
* you lookup the entity by yourself with this entity ID.
|
||||
*
|
||||
* @return Entity ID
|
||||
*/
|
||||
public int getEntityId() {
|
||||
@@ -119,6 +124,7 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get the player action.
|
||||
*
|
||||
* @return Player Action
|
||||
*/
|
||||
public PlayerAction getAction() {
|
||||
@@ -127,6 +133,7 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get the jump boost integer.
|
||||
*
|
||||
* @return Jump Boost
|
||||
*/
|
||||
public int getJumpBoost() {
|
||||
|
||||
-109
@@ -27,7 +27,6 @@ package io.github.retrooper.packetevents.packetwrappers.in.flying;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public class WrappedPacketInFlying extends WrappedPacket {
|
||||
private static Class<?> flyingClass;
|
||||
@@ -94,112 +93,4 @@ public class WrappedPacketInFlying extends WrappedPacket {
|
||||
return isLook;
|
||||
}
|
||||
|
||||
public static class WrappedPacketInPosition extends WrappedPacket {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private boolean onGround;
|
||||
public WrappedPacketInPosition(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
x = readDouble(0);
|
||||
y = readDouble(1);
|
||||
z = readDouble(2);
|
||||
onGround = readBoolean(0);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WrappedPacketInPosition_Look extends WrappedPacket {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private boolean onGround;
|
||||
public WrappedPacketInPosition_Look(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
x = readDouble(0);
|
||||
y = readDouble(1);
|
||||
z = readDouble(2);
|
||||
yaw = readFloat(0);
|
||||
pitch = readFloat(1);
|
||||
onGround = readBoolean(0);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WrappedPacketInLook extends WrappedPacketInFlying {
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private boolean onGround;
|
||||
public WrappedPacketInLook(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
yaw = readFloat(0);
|
||||
pitch = readFloat(1);
|
||||
onGround = readBoolean(0);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-1
@@ -26,7 +26,6 @@ package io.github.retrooper.packetevents.packetwrappers.in.helditemslot;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInHeldItemSlot extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ package io.github.retrooper.packetevents.packetwrappers.in.keepalive;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
public final class WrappedPacketInKeepAlive extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
@@ -55,7 +55,7 @@ public final class WrappedPacketInKeepAlive extends WrappedPacket {
|
||||
* Get the ID response from the client.
|
||||
*
|
||||
* You may cast this down to an int if you are on 1.7.10 - 1.12.2.
|
||||
* On 1.13.2 - 1.16.2 a long is sent.
|
||||
* On 1.13.2 - 1.16.3 a long is sent.
|
||||
* @return response ID
|
||||
*/
|
||||
public long getId() {
|
||||
|
||||
+4
-3
@@ -28,8 +28,8 @@ import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -58,7 +58,8 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
} catch (ClassNotFoundException e) {
|
||||
Class<?> entityHumanClass = NMSUtils.getNMSClassWithoutException("EntityHuman");
|
||||
//They are just on an outdated version
|
||||
chatVisibilityEnumClass = Reflection.getSubClass(entityHumanClass, "EnumChatVisibility");
|
||||
assert entityHumanClass != null;
|
||||
chatVisibilityEnumClass = SubclassUtil.getSubClass(entityHumanClass, "EnumChatVisibility");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ package io.github.retrooper.packetevents.packetwrappers.in.steervehicle;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public class WrappedPacketInSteerVehicle extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ package io.github.retrooper.packetevents.packetwrappers.in.transaction;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInTransaction extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.in.updatesign;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.chat.WrappedPacketOutChat;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
public class WrappedPacketInUpdateSign extends WrappedPacket {
|
||||
private static boolean v_1_7_mode, strArrayMode;
|
||||
private static Class<?> blockPosClass, iChatBaseComponentClass;
|
||||
|
||||
private int x, y, z;
|
||||
private String[] lines;
|
||||
|
||||
public static void load() {
|
||||
v_1_7_mode = Reflection.getField(PacketTypeClasses.Client.UPDATE_SIGN, int.class, 0) != null;
|
||||
strArrayMode = Reflection.getField(PacketTypeClasses.Client.UPDATE_SIGN, String[].class, 0) != null;
|
||||
|
||||
try {
|
||||
blockPosClass = NMSUtils.getNMSClass("BlockPosition");
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (!v_1_7_mode) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
iChatBaseComponentClass = NMSUtils.getNMSClass("IChatBaseComponent");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public WrappedPacketInUpdateSign(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
if (v_1_7_mode) {
|
||||
x = readInt(0);
|
||||
y = readInt(1);
|
||||
z = readInt(2);
|
||||
} else {
|
||||
Object blockPos = readObject(0, blockPosClass);
|
||||
try {
|
||||
x = Reflection.getField(blockPosClass, int.class, 0).getInt(packet);
|
||||
y = Reflection.getField(blockPosClass, int.class, 1).getInt(packet);
|
||||
z = Reflection.getField(blockPosClass, int.class, 2).getInt(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (strArrayMode) {
|
||||
//1.7.10 and the newest versions use this
|
||||
lines = readStringArray(0);
|
||||
} else {
|
||||
//1.8 uses this for example
|
||||
Object[] iChatComponents = readObjectArray(0, iChatBaseComponentClass);
|
||||
for (int i = 0; i < iChatComponents.length; i++) {
|
||||
lines[i] = WrappedPacketOutChat.
|
||||
toStringFromIChatBaseComponent(iChatComponents[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getBlockPositionX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getBlockPositionY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getBlockPositionZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public String[] getTextLines() {
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -24,10 +24,9 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.useentity;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public final class WrappedPacketInUseEntity extends WrappedPacket {
|
||||
@@ -41,19 +40,25 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
useEntityClass = PacketTypeClasses.Client.USE_ENTITY;
|
||||
|
||||
//System.out.println("USE ENTITY HAS BEEN LOADED BROOOIOII");
|
||||
useEntityClass = NMSUtils.getNMSClassWithoutException("PacketPlayInUseEntity");
|
||||
/*if(useEntityClass == null) {
|
||||
System.out.println("failed to init use entity wtfffff");
|
||||
}*/
|
||||
try {
|
||||
enumEntityUseActionClass = NMSUtils.getNMSClass("EnumEntityUseAction");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//That is fine, it is probably a subclass
|
||||
enumEntityUseActionClass = Reflection.getSubClass(useEntityClass, "EnumEntityUseAction");
|
||||
enumEntityUseActionClass = SubclassUtil.getSubClass(useEntityClass, "EnumEntityUseAction");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
this.entityID = readInt(0);
|
||||
if(enumEntityUseActionClass == null) {
|
||||
System.out.println("cls is null");
|
||||
}
|
||||
final Object useActionEnum = readObject(0, enumEntityUseActionClass);
|
||||
this.action = EntityUseAction.valueOf(useActionEnum.toString());
|
||||
}
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@ package io.github.retrooper.packetevents.packetwrappers.in.windowclick;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.abilities;
|
||||
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
-1
@@ -27,7 +27,6 @@ package io.github.retrooper.packetevents.packetwrappers.out.abilities;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
+1
-2
@@ -27,8 +27,7 @@ package io.github.retrooper.packetevents.packetwrappers.out.animation;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
+4
-3
@@ -29,8 +29,9 @@ import io.github.retrooper.packetevents.annotations.NotNull;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -100,7 +101,7 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
chatSerializerClass = NMSUtils.getNMSClass("ChatSerializer");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//That is fine, it is probably a subclass
|
||||
chatSerializerClass = Reflection.getSubClass(iChatBaseComponentClass, "ChatSerializer");
|
||||
chatSerializerClass = SubclassUtil.getSubClass(iChatBaseComponentClass, "ChatSerializer");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ package io.github.retrooper.packetevents.packetwrappers.out.custompayload;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@ package io.github.retrooper.packetevents.packetwrappers.out.entity;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
+15
-10
@@ -28,8 +28,7 @@ import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -39,7 +38,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
private static Constructor<?> velocityConstructor, vec3dConstructor;
|
||||
private static Class<?> velocityClass, vec3dClass;
|
||||
private static boolean isVec3dPresent;
|
||||
private int entityId;
|
||||
private int entityID;
|
||||
private double velocityX, velocityY, velocityZ;
|
||||
private Entity entity;
|
||||
public WrappedPacketOutEntityVelocity(final Object packet) {
|
||||
@@ -47,14 +46,20 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityVelocity(final Entity entity, final double velocityX, final double velocityY, final double velocityZ) {
|
||||
super();
|
||||
this.entityId = entity.getEntityId();
|
||||
this.entityID = entity.getEntityId();
|
||||
this.entity = entity;
|
||||
this.velocityX = velocityX;
|
||||
this.velocityY = velocityY;
|
||||
this.velocityZ = velocityZ;
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityVelocity(int entityID, double velX, double velY, double velZ) {
|
||||
this.entityID = entityID;
|
||||
this.velocityX = velX;
|
||||
this.velocityY = velY;
|
||||
this.velocityZ = velZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Velocity Constructor parameter types:
|
||||
* 1.7.10 -> 1.13.2 use int, double, double, double style,
|
||||
@@ -89,7 +94,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
@Override
|
||||
protected void setup() {
|
||||
//ENTITY ID
|
||||
this.entityId = readInt(0);
|
||||
this.entityID = readInt(0);
|
||||
|
||||
int x = readInt(1);
|
||||
int y = readInt(2);
|
||||
@@ -109,7 +114,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
if(entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityId);
|
||||
return entity = NMSUtils.getEntityById(this.entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +124,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
* @return Entity ID
|
||||
*/
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
return entityID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,13 +155,13 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
public Object asNMSPacket() {
|
||||
if (!isVec3dPresent) {
|
||||
try {
|
||||
return velocityConstructor.newInstance(entityId, velocityX, velocityY, velocityZ);
|
||||
return velocityConstructor.newInstance(entityID, velocityX, velocityY, velocityZ);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return velocityConstructor.newInstance(entityId, vec3dConstructor.newInstance(velocityX, velocityY, velocityZ));
|
||||
return velocityConstructor.newInstance(entityID, vec3dConstructor.newInstance(velocityX, velocityY, velocityZ));
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.gamestatechange;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.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.reflection.SubclassUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketOutGameStateChange extends WrappedPacket implements SendableWrapper {
|
||||
private int reason;
|
||||
private double value;
|
||||
|
||||
private static Constructor<?> packetConstructor, reasonClassConstructor;
|
||||
private static Class<?> reasonClassType;
|
||||
|
||||
private static boolean reasonIntMode;
|
||||
private static boolean valueFloatMode;
|
||||
|
||||
public static void load() {
|
||||
reasonClassType = SubclassUtil.getSubClass(PacketTypeClasses.Server.GAME_STATE_CHANGE, "a");
|
||||
if(reasonClassType != null) {
|
||||
try {
|
||||
reasonClassConstructor = reasonClassType.getConstructor(int.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
reasonIntMode = reasonClassType == null;
|
||||
valueFloatMode = Reflection.getField(PacketTypeClasses.Server.GAME_STATE_CHANGE, double.class, 0) == null;
|
||||
|
||||
try {
|
||||
Class<?> valueClassType;
|
||||
if (valueFloatMode) {
|
||||
valueClassType = float.class;
|
||||
} else {
|
||||
//Just an older version(1.7.10/1.8.x or so)
|
||||
valueClassType = double.class;
|
||||
}
|
||||
if(reasonClassType == null) {
|
||||
reasonClassType = int.class;
|
||||
}
|
||||
packetConstructor = PacketTypeClasses.Server.GAME_STATE_CHANGE.getConstructor(reasonClassType, valueClassType);
|
||||
reasonClassType = null;
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "PacketEvents failed to find the constructor for the outbound Game state packet wrapper.");
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public WrappedPacketOutGameStateChange(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutGameStateChange(int reason, double value) {
|
||||
this.reason = reason;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public WrappedPacketOutGameStateChange(int reason, float value){
|
||||
this(reason, (double)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
if (reasonIntMode) {
|
||||
reason = readInt(0);
|
||||
} else {
|
||||
//this packet is obfuscated quite strongly(1.16), so we must do this
|
||||
Object reasonObject = readObject(12, reasonClassType);
|
||||
try {
|
||||
reason = Reflection.getField(reasonClassType, int.class, 0).getInt(reasonObject);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (valueFloatMode) {
|
||||
value = readFloat(0);
|
||||
} else {
|
||||
value = readDouble(0);
|
||||
}
|
||||
}
|
||||
|
||||
public int getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() {
|
||||
if (reasonClassType == null) {
|
||||
try {
|
||||
if (valueFloatMode) {
|
||||
return packetConstructor.newInstance(reason, (float) value);
|
||||
} else {
|
||||
return packetConstructor.newInstance(reason, value);
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Object reasonObject = null;
|
||||
try {
|
||||
reasonObject = reasonClassConstructor.newInstance(reason);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (valueFloatMode) {
|
||||
return packetConstructor.newInstance(reasonObject, (float) value);
|
||||
} else {
|
||||
return packetConstructor.newInstance(reasonObject, value);
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -27,7 +27,7 @@ package io.github.retrooper.packetevents.packetwrappers.out.keepalive;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -79,7 +79,7 @@ public class WrappedPacketOutKeepAlive extends WrappedPacket implements Sendable
|
||||
* Get the Keep Alive ID.
|
||||
*
|
||||
* You may cast this down to an int if you are on 1.7.10 - 1.12.2.
|
||||
* On 1.13.2 - 1.16.2 a long is sent.
|
||||
* On 1.13.2 - 1.16.3 a long is sent.
|
||||
*
|
||||
* @return Get Keep Alive ID
|
||||
*/
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.chat.WrappedPacketOutChat;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ package io.github.retrooper.packetevents.packetwrappers.out.position;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketOutPosition extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
|
||||
-1
@@ -27,7 +27,6 @@ package io.github.retrooper.packetevents.packetwrappers.out.transaction;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ package io.github.retrooper.packetevents.packetwrappers.out.updatehealth;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* 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.reflectionutils;
|
||||
|
||||
|
||||
import io.github.retrooper.packetevents.reflectionutils.fielddata.FieldWithIndex;
|
||||
import io.github.retrooper.packetevents.reflectionutils.fielddata.FieldWithName;
|
||||
import io.github.retrooper.packetevents.reflectionutils.fielddata.FieldWithTypeAndIndex;
|
||||
import io.github.retrooper.packetevents.reflectionutils.methoddata.MethodWithIndexAndParams;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author retrooper
|
||||
*/
|
||||
public final class Reflection {
|
||||
private static final HashMap<Class<?>, Field[]> cachedFields = new HashMap<Class<?>, Field[]>();
|
||||
private static final HashMap<Class<?>, Method[]> cachedMethods = new HashMap<Class<?>, Method[]>();
|
||||
private static final HashMap<Class<?>, Class<?>[]> cachedSubclasses = new HashMap<Class<?>, Class<?>[]>();
|
||||
|
||||
|
||||
//FIELDS
|
||||
private static final HashMap<FieldWithName, Field> fieldWithNameHashMap = new HashMap<FieldWithName, Field>();
|
||||
private static final HashMap<FieldWithTypeAndIndex, Field> fieldWithTypeAndIndexHashMap = new HashMap<FieldWithTypeAndIndex, Field>();
|
||||
private static final HashMap<FieldWithIndex, Field> fieldWithIndexHashMap = new HashMap<FieldWithIndex, Field>();
|
||||
private static final HashMap<MethodWithIndexAndParams, Method> methodWithIndexAndParamsHashMap = new HashMap<MethodWithIndexAndParams, Method>();
|
||||
|
||||
public static Field[] getFields(final Class<?> cls) {
|
||||
if (cachedFields.containsKey(cls)) {
|
||||
return cachedFields.get(cls);
|
||||
} else {
|
||||
final Field[] fields = cls.getDeclaredFields();
|
||||
for (final Field f : fields) {
|
||||
f.setAccessible(true);
|
||||
}
|
||||
cachedFields.put(cls, fields);
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> cls, final String name) {
|
||||
final FieldWithName fwn = new FieldWithName(cls, name);
|
||||
if (!fieldWithNameHashMap.containsKey(fwn)) {
|
||||
for (final Field f : getFields(cls)) {
|
||||
if (f.getName().equals(name)) {
|
||||
fieldWithNameHashMap.put(fwn, f);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fieldWithNameHashMap.get(fwn);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> cls, final Class<?> dataType, final int index) {
|
||||
final FieldWithTypeAndIndex fwtai = new FieldWithTypeAndIndex(cls, dataType, index);
|
||||
if (!fieldWithTypeAndIndexHashMap.containsKey(fwtai)) {
|
||||
int i = 0;
|
||||
for (final Field f : getFields(cls)) {
|
||||
if (f.getType().equals(dataType)) {
|
||||
if (i++ == index) {
|
||||
fieldWithTypeAndIndexHashMap.put(fwtai, f);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fieldWithTypeAndIndexHashMap.get(fwtai);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> cls, final int index) {
|
||||
final FieldWithIndex fwi = new FieldWithIndex(cls, index);
|
||||
if (!fieldWithIndexHashMap.containsKey(fwi)) {
|
||||
final Field[] fields = getFields(cls);
|
||||
if (fields.length <= index) {
|
||||
return null;
|
||||
}
|
||||
final Field field = fields[index];
|
||||
fieldWithIndexHashMap.put(fwi, field);
|
||||
return field;
|
||||
} else {
|
||||
return fieldWithIndexHashMap.get(fwi);
|
||||
}
|
||||
}
|
||||
|
||||
//METHODS
|
||||
public static Method[] getMethods(final Class<?> cls) {
|
||||
if (cachedMethods.containsKey(cls)) {
|
||||
return cachedMethods.get(cls);
|
||||
} else {
|
||||
final Method[] methods = cls.getDeclaredMethods();
|
||||
for (final Method m : methods) {
|
||||
m.setAccessible(true);
|
||||
}
|
||||
cachedMethods.put(cls, methods);
|
||||
return methods;
|
||||
}
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final int index, final Class<?>... params) {
|
||||
final MethodWithIndexAndParams mwiap = new MethodWithIndexAndParams(cls, index, params);
|
||||
if (!methodWithIndexAndParamsHashMap.containsKey(mwiap)) {
|
||||
int i = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (Arrays.equals(m.getParameterTypes(), params) && index == i++) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return methodWithIndexAndParamsHashMap.get(mwiap);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//THE REST LATER
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final String name, Class<?> returning, Class<?>... params) {
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getName().equals(name) && Arrays.equals(m.getParameterTypes(), params) && m.getReturnType().equals(returning)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final String name, final int index) {
|
||||
int i = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getName().equals(name) && index == i++) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final Class<?> returning, final int index) {
|
||||
int i = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getReturnType().equals(returning) && index == i++) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final String name, final Class<?> returning) {
|
||||
int i = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getName().equals(name) && m.getReturnType().equals(returning)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Class<?>[] getSubClasses(final Class<?> cls) {
|
||||
if (cachedSubclasses.containsKey(cls)) {
|
||||
return cachedSubclasses.get(cls);
|
||||
} else {
|
||||
final Class<?>[] subclasses = cls.getDeclaredClasses();
|
||||
cachedSubclasses.put(cls, subclasses);
|
||||
return subclasses;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getSubClass(final Class<?> cls, final String name) {
|
||||
for (final Class<?> subclass : getSubClasses(cls)) {
|
||||
if (subclass.getSimpleName().equals(name)) {
|
||||
return subclass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Class<?> getSubClass(final Class<?> cls, final int index) {
|
||||
final Class<?>[] subclasses = getSubClasses(cls);
|
||||
for (int i = 0; i < index + 1; i++) {
|
||||
final Class<?> c = subclasses[i];
|
||||
if (i == index) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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.reflectionutils.fielddata;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class FieldWithTypeAndIndex {
|
||||
private final Class<?> cls, type;
|
||||
private final int index;
|
||||
|
||||
public FieldWithTypeAndIndex(Class<?> cls, Class<?> type, int index) {
|
||||
this.cls = cls;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Class<?> getCls() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldWithTypeAndIndex that = (FieldWithTypeAndIndex) o;
|
||||
return index == that.index &&
|
||||
Objects.equals(cls, that.cls) &&
|
||||
Objects.equals(type, that.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(cls, type, index);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,9 +32,11 @@ public class PacketEventsSettings {
|
||||
|
||||
private ServerVersion defaultServerVersion = ServerVersion.v_1_7_10;
|
||||
private String identifier = "";
|
||||
private boolean autoResolveClientProtocolVersion;
|
||||
private boolean uninjectAsync = false;
|
||||
private boolean injectAsync = false;
|
||||
private boolean autoResolveClientProtocolVersion = false;
|
||||
private boolean uninjectAsync = true;
|
||||
private boolean injectAsync = true;
|
||||
private boolean useProtocolLibIfAvailable = true;
|
||||
private boolean checkForUpdates = true;
|
||||
|
||||
/**
|
||||
* If PacketEvents fails to detect your server version, it will use the recommended version
|
||||
@@ -60,6 +62,7 @@ public class PacketEventsSettings {
|
||||
* If you manually set the identifier using its setter '#setIdentifier(String)'.
|
||||
* We will use that identifier to generate each player's handler name.
|
||||
* If you do not set the identifier manually, we automatically generate one for you.
|
||||
*
|
||||
* @return stored identifier or new generated identifier
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
@@ -85,7 +88,6 @@ public class PacketEventsSettings {
|
||||
* @deprecated This method is deprecated as you no longer need to set an identifier,
|
||||
* a unique identifier is already automatically generated for you.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setIdentifier(final String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
@@ -99,6 +101,7 @@ public class PacketEventsSettings {
|
||||
* (when ViaVersion, ProtocolLib or ProtocolSupport can't be found on the server),
|
||||
* should it assume that the client is using the same version as the server?
|
||||
* Returns ACCESS_FAILURE if this is set to FALSE(default value is false).
|
||||
*
|
||||
* @param autoResolveClientProtocolVersion boolean
|
||||
*/
|
||||
public void setDoAutoResolveClientProtocolVersion(boolean autoResolveClientProtocolVersion) {
|
||||
@@ -132,4 +135,30 @@ public class PacketEventsSettings {
|
||||
public void setInjectAsync(boolean injectAsync) {
|
||||
this.injectAsync = injectAsync;
|
||||
}
|
||||
|
||||
public boolean isUseProtocolLibIfAvailable() {
|
||||
return this.useProtocolLibIfAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Would you like PacketEvents to make use of ProtocolLib if it is available?
|
||||
* If yes, enable this, if not disable this.
|
||||
* Having this on can help your plugin have compatibility
|
||||
* with other plugins that might be using ProtocolLib.
|
||||
* Especially if they or you are doing packet cancellations,
|
||||
* PacketEvents passes the event priority to ProtocolLib.
|
||||
*
|
||||
* @param val boolean
|
||||
*/
|
||||
public void setUseProtocolLibIfAvailable(boolean val) {
|
||||
this.useProtocolLibIfAvailable = val;
|
||||
}
|
||||
|
||||
/*public void setShouldCheckForUpdates(boolean val) {
|
||||
this.checkForUpdates = val;
|
||||
}
|
||||
|
||||
public boolean shouldCheckForUpdates() {
|
||||
return checkForUpdates;
|
||||
}*/
|
||||
}
|
||||
+2
-2
@@ -22,11 +22,11 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.nms_entityfinder;
|
||||
package io.github.retrooper.packetevents.utils.entityfinder;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
+19
-23
@@ -22,13 +22,14 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils;
|
||||
package io.github.retrooper.packetevents.utils.nms;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.nettyhandler.NettyPacketHandler;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms_entityfinder.EntityFinderUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.entityfinder.EntityFinderUtils;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -37,12 +38,14 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class NMSUtils {
|
||||
public static ServerVersion version;
|
||||
private static final String nmsDir = ServerVersion.getNMSDirectory();
|
||||
private static final String obcDir = ServerVersion.getOBCDirectory();
|
||||
public static String nettyPrefix;
|
||||
public static String nettyPrefix = "io.netty";
|
||||
public static Class<?> minecraftServerClass, craftWorldsClass,
|
||||
packetClass, entityPlayerClass, playerConnectionClass,
|
||||
craftPlayerClass, serverConnectionClass, craftEntityClass,
|
||||
@@ -50,9 +53,10 @@ public final class NMSUtils {
|
||||
private static Method getCraftWorldHandleMethod, getServerConnection, getCraftPlayerHandle, getCraftEntityHandle, sendPacketMethod, asBukkitCopy;
|
||||
private static Field entityPlayerPingField, playerConnectionField;
|
||||
|
||||
public static final HashMap<UUID, Object> channelCache = new HashMap<UUID, Object>();
|
||||
|
||||
public static void load() {
|
||||
try {
|
||||
nettyPrefix = "io.netty";
|
||||
Class.forName(nettyPrefix + ".channel.Channel");
|
||||
} catch (ClassNotFoundException e) {
|
||||
nettyPrefix = "net.minecraft.util.io.netty";
|
||||
@@ -192,12 +196,16 @@ public final class NMSUtils {
|
||||
}
|
||||
|
||||
public static Object getChannel(final Player player) {
|
||||
try {
|
||||
return Reflection.getField(networkManagerClass, nettyChannelClass, 0).get(getNetworkManager(player));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
UUID uuid = player.getUniqueId();
|
||||
if(!channelCache.containsKey(uuid)) {
|
||||
try {
|
||||
Object channel = Reflection.getField(networkManagerClass, nettyChannelClass, 0).get(getNetworkManager(player));
|
||||
channelCache.put(uuid, channel);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return channelCache.get(uuid);
|
||||
}
|
||||
|
||||
public static int getPlayerPing(final Player player) {
|
||||
@@ -224,18 +232,6 @@ public final class NMSUtils {
|
||||
}
|
||||
|
||||
public static void sendNMSPacket(final Player player, final Object nmsPacket) {
|
||||
Object entityPlayer = getEntityPlayer(player);
|
||||
Object playerConnection = null;
|
||||
try {
|
||||
playerConnection = playerConnectionField.get(entityPlayer);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
sendPacketMethod.invoke(playerConnection, nmsPacket);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
NettyPacketHandler.sendPacket(getChannel(player), nmsPacket);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -22,13 +22,13 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.api;
|
||||
package io.github.retrooper.packetevents.utils.player;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.enums.ClientVersion;
|
||||
import io.github.retrooper.packetevents.handler.NettyPacketHandler;
|
||||
import io.github.retrooper.packetevents.nettyhandler.NettyPacketHandler;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+6
-6
@@ -31,7 +31,7 @@ import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.enums.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
|
||||
@@ -47,9 +47,9 @@ public class ProtocolLibListener {
|
||||
if (ProtocolLibUtils.isAvailable()) {
|
||||
for (Method m : methods) {
|
||||
if (m.getParameterTypes()[0].equals(PacketReceiveEvent.class)) {
|
||||
PacketHandler annot = m.getAnnotation(PacketHandler.class);
|
||||
PacketHandler annotation = m.getAnnotation(PacketHandler.class);
|
||||
ListenerPriority priority;
|
||||
switch (annot.priority()) {
|
||||
switch (annotation.priority()) {
|
||||
case PacketEventPriority.LOWEST:
|
||||
priority = ListenerPriority.LOWEST;
|
||||
break;
|
||||
@@ -61,7 +61,7 @@ public class ProtocolLibListener {
|
||||
break;
|
||||
case PacketEventPriority.HIGHEST:
|
||||
priority = ListenerPriority.HIGHEST;
|
||||
break;
|
||||
break;
|
||||
case PacketEventPriority.MONITOR:
|
||||
priority = ListenerPriority.MONITOR;
|
||||
break;
|
||||
@@ -85,9 +85,9 @@ public class ProtocolLibListener {
|
||||
}
|
||||
});
|
||||
} else if (m.getParameterTypes()[0].equals(PacketSendEvent.class)) {
|
||||
PacketHandler annot = m.getAnnotation(PacketHandler.class);
|
||||
PacketHandler annotation = m.getAnnotation(PacketHandler.class);
|
||||
ListenerPriority priority;
|
||||
switch (annot.priority()) {
|
||||
switch (annotation.priority()) {
|
||||
case PacketEventPriority.LOWEST:
|
||||
priority = ListenerPriority.LOWEST;
|
||||
break;
|
||||
|
||||
+9
-31
@@ -22,39 +22,17 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.reflectionutils.fielddata;
|
||||
package io.github.retrooper.packetevents.utils.reflection;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class FieldWithIndex {
|
||||
private final Class<?> cls;
|
||||
private final int index;
|
||||
public class ClassUtil {
|
||||
private static final HashMap<Class<?>, String> classSimpleNameCache = new HashMap<Class<?>, String>();
|
||||
|
||||
public FieldWithIndex(Class<?> cls, int index) {
|
||||
this.cls = cls;
|
||||
this.index = index;
|
||||
public static String getClassSimpleName(Class<?> cls) {
|
||||
if(!classSimpleNameCache.containsKey(cls)) {
|
||||
classSimpleNameCache.put(cls, cls.getSimpleName());
|
||||
}
|
||||
return classSimpleNameCache.get(cls);
|
||||
}
|
||||
|
||||
public Class<?> getCls() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldWithIndex that = (FieldWithIndex) o;
|
||||
return index == that.index &&
|
||||
Objects.equals(cls, that.cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(cls, index);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.utils.reflection;
|
||||
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Reflection {
|
||||
|
||||
//FIELDS
|
||||
public static Field[] getFields(Class<?> cls) {
|
||||
Field[] declaredFields = cls.getDeclaredFields();
|
||||
for (Field f : declaredFields) {
|
||||
f.setAccessible(true);
|
||||
}
|
||||
return declaredFields;
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> cls, final String name) {
|
||||
for (final Field f : getFields(cls)) {
|
||||
if (f.getName().equals(name)) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> cls, final Class<?> dataType, final int index) {
|
||||
int currentIndex = 0;
|
||||
for (final Field f : getFields(cls)) {
|
||||
if (f.getType().equals(dataType)) {
|
||||
if (currentIndex++ == index) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> cls, final int index) {
|
||||
return getFields(cls)[index];
|
||||
}
|
||||
|
||||
//METHODS
|
||||
public static Method[] getMethods(final Class<?> cls) {
|
||||
Method[] declaredMethods = cls.getDeclaredMethods();
|
||||
for (Method m : declaredMethods) {
|
||||
m.setAccessible(true);
|
||||
}
|
||||
return declaredMethods;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final int index, final Class<?>... params) {
|
||||
int currentIndex = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (Arrays.equals(m.getParameterTypes(), params) && index == currentIndex++) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final String name, Class<?> returning, Class<?>... params) {
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getName().equals(name) && Arrays.equals(m.getParameterTypes(), params) && m.getReturnType().equals(returning)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final String name, final int index) {
|
||||
int currentIndex = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getName().equals(name) && index == currentIndex++) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final Class<?> returning, final int index) {
|
||||
int currentIndex = 0;
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getReturnType().equals(returning) && index == currentIndex++) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(final Class<?> cls, final String name, final Class<?> returning) {
|
||||
for (final Method m : getMethods(cls)) {
|
||||
if (m.getName().equals(name) && m.getReturnType().equals(returning)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+28
-35
@@ -22,46 +22,39 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.reflectionutils.methoddata;
|
||||
package io.github.retrooper.packetevents.utils.reflection;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class MethodWithIndexAndParams {
|
||||
private final Class<?> cls;
|
||||
private final int index;
|
||||
private final Class<?>[] params;
|
||||
|
||||
public MethodWithIndexAndParams(Class<?> cls, int index, Class<?>[] params) {
|
||||
this.cls = cls;
|
||||
this.index = index;
|
||||
this.params = params;
|
||||
public class SubclassUtil {
|
||||
public static Class<?> getSubClass(Class<?> cls, String name) {
|
||||
for (Class<?> subClass : cls.getDeclaredClasses()) {
|
||||
if (ClassUtil.getClassSimpleName(subClass).equals(name)) {
|
||||
return subClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class<?> getCls() {
|
||||
return cls;
|
||||
public static Class<?> getSubClass(Class<?> cls, int index) {
|
||||
int currentIndex = 0;
|
||||
for (Class<?> subClass : cls.getDeclaredClasses()) {
|
||||
if (index == currentIndex++) {
|
||||
return subClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
public static Class<?> getSubClass(Class<?> cls, Annotation annotation, int index) {
|
||||
int currentIndex = 0;
|
||||
for(Class<?> subClass : cls.getDeclaredClasses()) {
|
||||
if(subClass.getAnnotation(annotation.getClass()) != null) {
|
||||
if(index == currentIndex++) {
|
||||
return subClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class<?>[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MethodWithIndexAndParams that = (MethodWithIndexAndParams) o;
|
||||
return index == that.index &&
|
||||
Objects.equals(cls, that.cls) &&
|
||||
Objects.equals(params, that.params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(cls, params, index);
|
||||
}
|
||||
|
||||
}
|
||||
+13
-5
@@ -22,11 +22,11 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.api;
|
||||
package io.github.retrooper.packetevents.utils.server;
|
||||
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.enums.SystemOS;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@@ -74,7 +74,7 @@ public final class ServerUtils {
|
||||
/**
|
||||
* Use {@link #getOperatingSystem()}
|
||||
* @deprecated Method rename pending to next minor update.
|
||||
* @return
|
||||
* @return Operating system of the current machine
|
||||
*/
|
||||
@Deprecated
|
||||
public SystemOS getPlatform() {
|
||||
@@ -82,10 +82,18 @@ public final class ServerUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Operating System the server is running on.
|
||||
* @return Get Server Operating System
|
||||
* @deprecated Use {@link #getOS()}
|
||||
*/
|
||||
@Deprecated
|
||||
public SystemOS getOperatingSystem() {
|
||||
return SystemOS.getOperatingSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the operating system of the local machine
|
||||
* @return Get Operating System
|
||||
*/
|
||||
public SystemOS getOS() {
|
||||
return SystemOS.getOperatingSystem();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.v_1_7_10;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.utils.vector;
|
||||
|
||||
@Deprecated
|
||||
public final class Vector3d {
|
||||
public double x, y, z;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.utils.vector;
|
||||
|
||||
@Deprecated
|
||||
public final class Vector3f {
|
||||
public float x, y, z;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.vector;
|
||||
|
||||
@Deprecated
|
||||
public final class Vector3i {
|
||||
public int x, y, z;
|
||||
|
||||
|
||||
+1
@@ -28,6 +28,7 @@ import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibUtils;
|
||||
import io.github.retrooper.packetevents.utils.protocolsupport.ProtocolSupportUtils;
|
||||
import io.github.retrooper.packetevents.utils.v_1_7_10.ProtocolVersionAccessor_v_1_7;
|
||||
import io.github.retrooper.packetevents.utils.viaversion.ViaUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
Reference in new issue
Block a user