Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c3726c165 | ||
|
|
51a58f79a5 | ||
|
|
8691304925 | ||
|
|
9fef95d96e | ||
|
|
4d42a23510 | ||
|
|
787df36fe0 | ||
|
|
a59ea40e12 | ||
|
|
fdb3a23acc | ||
|
|
60d24ac3c1 | ||
|
|
7634540bd7 | ||
|
|
0a475e4242 | ||
|
|
ff3b66b22e |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<version>1.6.7</version>
|
||||
|
||||
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
|
||||
<build>
|
||||
@@ -115,12 +115,5 @@
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -28,11 +28,9 @@ 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;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.impl.BukkitMoveEvent;
|
||||
import io.github.retrooper.packetevents.packet.PacketType;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
@@ -40,7 +38,6 @@ import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@@ -54,7 +51,7 @@ public final class PacketEvents implements Listener {
|
||||
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, hasStarted;
|
||||
private static boolean hasLoaded, isStarted;
|
||||
|
||||
/**
|
||||
* This loads the PacketEvents API.
|
||||
@@ -103,7 +100,7 @@ public final class PacketEvents implements Listener {
|
||||
* Loads PacketEvents if you haven't already.
|
||||
*
|
||||
* Registering:
|
||||
* Registers this class as a Bukkit listener to inject/uninject players.
|
||||
* Registers this class as a Bukkit listener to inject/eject players.
|
||||
*
|
||||
* @param pl JavaPlugin instance
|
||||
*/
|
||||
@@ -111,7 +108,7 @@ public final class PacketEvents implements Listener {
|
||||
if (!hasLoaded) {
|
||||
load();
|
||||
}
|
||||
if (!hasStarted) {
|
||||
if (!isStarted) {
|
||||
plugins.add(pl);
|
||||
//Register Bukkit listener
|
||||
Bukkit.getPluginManager().registerEvents(instance, plugins.get(0));
|
||||
@@ -119,7 +116,7 @@ public final class PacketEvents implements Listener {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
getAPI().getPlayerUtils().injectPlayer(p);
|
||||
}
|
||||
hasStarted = true;
|
||||
isStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,11 +134,13 @@ public final class PacketEvents implements Listener {
|
||||
*
|
||||
*/
|
||||
public static void stop() {
|
||||
if (hasStarted) {
|
||||
if (isStarted) {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
getAPI().getPlayerUtils().ejectPlayer(p);
|
||||
}
|
||||
getAPI().getEventManager().unregisterAllListeners();
|
||||
|
||||
isStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +148,13 @@ public final class PacketEvents implements Listener {
|
||||
return hasLoaded;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean hasStarted() {
|
||||
return hasStarted;
|
||||
return isStarted;
|
||||
}
|
||||
|
||||
public static boolean isInitialized() {
|
||||
return isStarted;
|
||||
}
|
||||
|
||||
public static PacketEventsAPI getAPI() {
|
||||
@@ -174,7 +178,7 @@ public final class PacketEvents implements Listener {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
if(!VersionLookupUtils.hasLoaded()) {
|
||||
VersionLookupUtils.load();
|
||||
@@ -184,13 +188,13 @@ public final class PacketEvents implements Listener {
|
||||
PacketEvents.getAPI().getPlayerUtils().injectPlayer(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onQuit(final PlayerQuitEvent e) {
|
||||
PacketEvents.getAPI().getPlayerUtils().ejectPlayer(e.getPlayer());
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onMove(final PlayerMoveEvent e) {
|
||||
BukkitMoveEvent moveEvent = new BukkitMoveEvent(e);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(moveEvent);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package io.github.retrooper.packetevents.annotations;
|
||||
|
||||
import io.github.retrooper.packetevents.enums.EventSynchronization;
|
||||
import io.github.retrooper.packetevents.enums.PacketEventPriority;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -36,5 +37,8 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
public @interface PacketHandler {
|
||||
@Deprecated
|
||||
EventSynchronization synchronization() default EventSynchronization.NORMAL;
|
||||
|
||||
byte priority() default PacketEventPriority.NORMAL;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.enums;
|
||||
|
||||
public interface PacketEventPriority {
|
||||
byte LOWEST = 0;
|
||||
byte LOW = 1;
|
||||
byte NORMAL = 2;
|
||||
byte HIGH = 3;
|
||||
byte HIGHEST = 4;
|
||||
byte MONITOR = 5;
|
||||
}
|
||||
@@ -44,7 +44,13 @@ public interface CancellableEvent {
|
||||
|
||||
/**
|
||||
* Cancel the event.
|
||||
* This is the same as just doing: CancellableEvent#setCancelled(true)
|
||||
* You can achieve the same result by just using {@link #setCancelled(boolean)}
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Uncancel the event.
|
||||
* You can achieve the same result by just using {@link #setCancelled(boolean)}
|
||||
*/
|
||||
void uncancel();
|
||||
}
|
||||
@@ -50,6 +50,11 @@ public final class BukkitMoveEvent extends PacketEvent implements CancellableEve
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
setCancelled(true);
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncancel() {
|
||||
this.cancelled = false;
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,11 @@ public final class PacketReceiveEvent extends PacketEvent implements Cancellable
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncancel() {
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
||||
@@ -101,5 +101,8 @@ public final class PacketSendEvent extends PacketEvent implements CancellableEve
|
||||
public void cancel() {
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncancel() { this.cancelled = false;}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ public final class PlayerInjectEvent extends PacketEvent implements CancellableE
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncancel() {this.cancelled = false; }
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ public final class PlayerUninjectEvent extends PacketEvent implements Cancellabl
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncancel() {this.cancelled = false; }
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
|
||||
@@ -26,29 +26,34 @@ package io.github.retrooper.packetevents.event.manager;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.enums.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.event.CancellableEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketEvent;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibListener;
|
||||
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public final class EventManager {
|
||||
private final HashMap<PacketListener, List<Method>> registeredMethods = new HashMap<PacketListener, List<Method>>();
|
||||
private final ConcurrentHashMap<PacketListener, ConcurrentLinkedQueue<Method>> registeredMethods = new ConcurrentHashMap<>();
|
||||
|
||||
public void callEvent(final PacketEvent e) {
|
||||
for (final PacketListener listener : registeredMethods.keySet()) {
|
||||
//Annotated methods
|
||||
final List<Method> methods = registeredMethods.get(listener);
|
||||
for (final Method method : methods) {
|
||||
final Class<?> parameterType = method.getParameterTypes()[0];
|
||||
ConcurrentLinkedQueue<Method> methods = registeredMethods.get(listener);
|
||||
final boolean[] isCancelled = {false};
|
||||
final byte[] eventPriority = {PacketEventPriority.LOWEST};
|
||||
for (Method method : methods) {
|
||||
Class<?> parameterType = method.getParameterTypes()[0];
|
||||
if (parameterType.equals(PacketEvent.class)
|
||||
|| parameterType.isInstance(e)) {
|
||||
final PacketHandler annotation = method.getAnnotation(PacketHandler.class);
|
||||
final Runnable invokeMethod = new Runnable() {
|
||||
|
||||
PacketHandler annotation = method.getAnnotation(PacketHandler.class);
|
||||
Runnable invokeMethod = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -56,9 +61,15 @@ public final class EventManager {
|
||||
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (e instanceof CancellableEvent) {
|
||||
CancellableEvent ce = (CancellableEvent) e;
|
||||
if (annotation.priority() >= eventPriority[0]) {
|
||||
eventPriority[0] = annotation.priority();
|
||||
isCancelled[0] = ce.isCancelled();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
switch (annotation.synchronization()) {
|
||||
case FORCE_ASYNC:
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PacketEvents.getPlugin(), invokeMethod);
|
||||
@@ -72,23 +83,39 @@ public final class EventManager {
|
||||
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (e instanceof CancellableEvent) {
|
||||
CancellableEvent ce = (CancellableEvent) e;
|
||||
if (annotation.priority() >= eventPriority[0]) {
|
||||
eventPriority[0] = annotation.priority();
|
||||
isCancelled[0] = ce.isCancelled();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (e instanceof CancellableEvent) {
|
||||
CancellableEvent cancellableEvent = (CancellableEvent) e;
|
||||
cancellableEvent.setCancelled(isCancelled[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerListener(final PacketListener e) {
|
||||
final List<Method> methods = new ArrayList<Method>();
|
||||
for (final Method m : e.getClass().getDeclaredMethods()) {
|
||||
public void registerListener(final PacketListener listener) {
|
||||
final ConcurrentLinkedQueue<Method> methods = new ConcurrentLinkedQueue<>();
|
||||
for (final Method m : listener.getClass().getDeclaredMethods()) {
|
||||
if (m.isAnnotationPresent(PacketHandler.class)
|
||||
&& m.getParameterTypes().length == 1) {
|
||||
methods.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
if (!methods.isEmpty()) {
|
||||
registeredMethods.put(e, methods);
|
||||
if (ProtocolLibUtils.isAvailable()) {
|
||||
ProtocolLibListener.registerProtocolLibListener(listener, methods);
|
||||
} else {
|
||||
registeredMethods.put(listener, methods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,7 @@
|
||||
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.packet.PacketType;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.useentity.WrappedPacketInUseEntity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class MainExample extends JavaPlugin implements PacketListener {
|
||||
@@ -45,7 +41,7 @@ public class MainExample extends JavaPlugin implements PacketListener {
|
||||
PacketEvents.getSettings().setIdentifier("official_api");
|
||||
|
||||
PacketEvents.init(this);
|
||||
// PacketEvents.getAPI().getEventManager().registerListener(this);
|
||||
PacketEvents.getAPI().getEventManager().registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -27,6 +27,6 @@ package io.github.retrooper.packetevents.packetwrappers;
|
||||
/**
|
||||
* This interface indicates that a packet wrapper supports being sent to a client.
|
||||
*/
|
||||
public interface Sendable {
|
||||
public interface SendableWrapper {
|
||||
Object asNMSPacket();
|
||||
}
|
||||
+108
-16
@@ -22,9 +22,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.api;
|
||||
package io.github.retrooper.packetevents.packetwrappers;
|
||||
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.abilities.WrappedPacketInAbilities;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.armanimation.WrappedPacketInArmAnimation;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.blockdig.WrappedPacketInBlockDig;
|
||||
@@ -51,38 +52,34 @@ import io.github.retrooper.packetevents.packetwrappers.out.kickdisconnect.Wrappe
|
||||
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;
|
||||
|
||||
public class WrappedPacket {
|
||||
public class WrappedPacket implements WrapperPacketReader {
|
||||
public static ServerVersion version;
|
||||
protected final Player player;
|
||||
protected Object packet;
|
||||
private Class<?> packetClass;
|
||||
|
||||
public WrappedPacket() {
|
||||
this.player = null;
|
||||
this.packet = null;
|
||||
this(null);
|
||||
}
|
||||
|
||||
public WrappedPacket(final Object packet) {
|
||||
this.player = null;
|
||||
if (packet == null) return;
|
||||
this.packet = packet;
|
||||
try {
|
||||
setup();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this(null, packet);
|
||||
}
|
||||
|
||||
public WrappedPacket(final Player player, final Object packet) {
|
||||
this.player = player;
|
||||
if (packet == null) return;
|
||||
this.packet = packet;
|
||||
try {
|
||||
setup();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
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;
|
||||
}
|
||||
setup();
|
||||
}
|
||||
|
||||
public static void loadAllWrappers() {
|
||||
@@ -115,10 +112,105 @@ public class WrappedPacket {
|
||||
WrappedPacketOutPosition.load();
|
||||
WrappedPacketOutTransaction.load();
|
||||
WrappedPacketOutUpdateHealth.load();
|
||||
//WrappedPacketOutCustomPayload.load();
|
||||
}
|
||||
|
||||
protected void setup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readBoolean(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, boolean.class, index).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, byte.class, index).getByte(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, short.class, index).getShort(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, int.class, index).getInt(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, long.class, index).getLong(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, float.class, index).getFloat(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, double.class, index).getDouble(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(int index, Class<?> type) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, type, index).get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readAnyObject(int index) {
|
||||
try {
|
||||
return Reflection.getField(packetClass, index).get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString(int index) {
|
||||
return readObject(index, String.class).toString();
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface WrapperPacketReader {
|
||||
|
||||
boolean readBoolean(int index);
|
||||
|
||||
byte readByte(int index);
|
||||
|
||||
short readShort(int index);
|
||||
|
||||
int readInt(int index);
|
||||
|
||||
long readLong(int index);
|
||||
|
||||
float readFloat(int index);
|
||||
|
||||
double readDouble(int index);
|
||||
|
||||
Object readObject(int index, Class<?> type);
|
||||
|
||||
Object readAnyObject(int index);
|
||||
|
||||
String readString(int index);
|
||||
}
|
||||
+14
-17
@@ -24,13 +24,13 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.abilities;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.NotNull;
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInAbilities extends WrappedPacket {
|
||||
private static Class<?> abilitiesClass;
|
||||
private static boolean isMoreThanOneBoolPresent;
|
||||
private boolean isVulnerable;
|
||||
private boolean isFlying;
|
||||
@@ -38,30 +38,26 @@ public final class WrappedPacketInAbilities extends WrappedPacket {
|
||||
private boolean instantBuild;
|
||||
private float flySpeed;
|
||||
private float walkSpeed;
|
||||
|
||||
public WrappedPacketInAbilities(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
abilitiesClass = PacketTypeClasses.Client.ABILITIES;
|
||||
isMoreThanOneBoolPresent = Reflection.getField(abilitiesClass, boolean.class, 1) != null;
|
||||
isMoreThanOneBoolPresent = Reflection.getField(PacketTypeClasses.Client.ABILITIES, boolean.class, 1) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
if (isMoreThanOneBoolPresent) {
|
||||
this.isVulnerable = Reflection.getField(abilitiesClass, boolean.class, 0).getBoolean(packet);
|
||||
this.isFlying = Reflection.getField(abilitiesClass, boolean.class, 1).getBoolean(packet);
|
||||
this.allowFly = Reflection.getField(abilitiesClass, boolean.class, 2).getBoolean(packet);
|
||||
this.instantBuild = Reflection.getField(abilitiesClass, boolean.class, 3).getBoolean(packet);
|
||||
this.flySpeed = Reflection.getField(abilitiesClass, float.class, 0).getFloat(packet);
|
||||
this.walkSpeed = Reflection.getField(abilitiesClass, float.class, 1).getFloat(packet);
|
||||
} else {
|
||||
this.isFlying = Reflection.getField(abilitiesClass, boolean.class, 0).getBoolean(packet);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
if (isMoreThanOneBoolPresent) {
|
||||
this.isVulnerable = readBoolean(0);
|
||||
this.isFlying = readBoolean(1);
|
||||
this.allowFly = readBoolean(2);
|
||||
this.instantBuild = readBoolean(3);
|
||||
this.flySpeed = readFloat(0);
|
||||
this.walkSpeed = readFloat(1);
|
||||
} else {
|
||||
this.isFlying = readBoolean(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +72,7 @@ public final class WrappedPacketInAbilities extends WrappedPacket {
|
||||
return isVulnerable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public boolean isFlying() {
|
||||
return isFlying;
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.armanimation;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
public final class WrappedPacketInArmAnimation extends WrappedPacket {
|
||||
private static Class<?> packetClass;
|
||||
|
||||
+10
-9
@@ -27,7 +27,7 @@ package io.github.retrooper.packetevents.packetwrappers.in.blockdig;
|
||||
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.api.WrappedPacket;
|
||||
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.vector.Vector3i;
|
||||
@@ -73,23 +73,24 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
try {
|
||||
if (isVersionLowerThan_v_1_8) {
|
||||
enumDigType = PlayerDigType.values()[(Reflection.getField(blockDigClass, int.class, 4).getInt(packet))];
|
||||
x = Reflection.getField(blockDigClass, int.class, 0).getInt(packet);
|
||||
y = Reflection.getField(blockDigClass, int.class, 1).getInt(packet);
|
||||
z = Reflection.getField(blockDigClass, int.class, 2).getInt(packet);
|
||||
x = readInt(0);
|
||||
y = readInt(1);
|
||||
z = readInt(2);
|
||||
enumDirection = null;
|
||||
} else {
|
||||
//1.8+
|
||||
final Object blockPosObj = Reflection.getField(blockDigClass, blockPositionClass, 0).get(packet);
|
||||
final Object enumDirectionObj = Reflection.getField(blockDigClass, enumDirectionClass, 0).get(packet);
|
||||
final Object digTypeObj = Reflection.getField(blockDigClass, digTypeClass, 0).get(packet);
|
||||
final Object blockPosObj = readObject(0, blockPositionClass);
|
||||
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);
|
||||
|
||||
enumDirection = Direction.valueOf(((Enum) enumDirectionObj).name());
|
||||
enumDigType = PlayerDigType.valueOf(((Enum) digTypeObj).name());
|
||||
//.toString() won't work so we must do this
|
||||
enumDirection = Direction.valueOf(((Enum)enumDirectionObj).name());
|
||||
enumDigType = PlayerDigType.valueOf(((Enum)digTypeObj).name());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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.vector.Vector3i;
|
||||
@@ -62,7 +62,7 @@ final class WrappedPacketInBlockPlace_1_8 extends WrappedPacket {
|
||||
this.blockPosition.z = (int) Reflection.getMethod(blockPositionSuperClass, "getZ", 0).invoke(nmsBlockPos);
|
||||
|
||||
|
||||
this.itemStack = NMSUtils.toBukkitItemStack(Reflection.getField(blockPlaceClass, NMSUtils.nmsItemStackClass, 0).get(packet));
|
||||
this.itemStack = NMSUtils.toBukkitItemStack(readObject(0, NMSUtils.nmsItemStackClass));
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
|
||||
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.BlockIteratorUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+2
-7
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.chat;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInChat extends WrappedPacket {
|
||||
@@ -42,12 +42,7 @@ public final class WrappedPacketInChat extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
final Object obj = Reflection.getField(chatPacketClass, String.class, 0).get(packet);
|
||||
this.message = obj.toString();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.message = readString(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-7
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.clientcommand;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
|
||||
@@ -51,16 +51,13 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
try {
|
||||
Object enumObj = Reflection.getField(packetClass, enumClientCommandClass, 0).get(packet);
|
||||
this.clientCommand = ClientCommand.valueOf(enumObj.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Object enumObj = readObject(0, enumClientCommandClass);
|
||||
this.clientCommand = ClientCommand.valueOf(enumObj.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Client Command enum sent in the packet
|
||||
*
|
||||
* @return ClientCommand
|
||||
*/
|
||||
public ClientCommand getClientCommand() {
|
||||
|
||||
+4
-7
@@ -26,7 +26,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.api.WrappedPacket;
|
||||
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;
|
||||
|
||||
@@ -61,12 +62,8 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
@Override
|
||||
public void setup() {
|
||||
if (!strPresentInIndex0) {
|
||||
try {
|
||||
this.minecraftKey = Reflection.getField(packetClass, nmsMinecraftKey, 0).get(packet);
|
||||
this.dataSerializer = Reflection.getField(packetClass, nmsPacketDataSerializer, 0).get(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.minecraftKey = readObject(0, nmsMinecraftKey);
|
||||
this.dataSerializer = readObject(0, nmsPacketDataSerializer);
|
||||
|
||||
} else {
|
||||
Field dataSerializerField = Reflection.getField(packetClass, nmsPacketDataSerializer, 0);
|
||||
|
||||
+21
-25
@@ -27,7 +27,7 @@ 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.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -76,31 +76,27 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
final int entityId = Reflection.getField(entityActionClass, int.class, 0).getInt(packet);
|
||||
final int jumpBoost;
|
||||
if (isLowerThan_v_1_8) {
|
||||
jumpBoost = Reflection.getField(entityActionClass, int.class, 2).getInt(packet);
|
||||
} else {
|
||||
jumpBoost = Reflection.getField(entityActionClass, int.class, 1).getInt(packet);
|
||||
}
|
||||
|
||||
//1.7.10
|
||||
if (isLowerThan_v_1_8) {
|
||||
int animationIndex = Reflection.getField(entityActionClass, int.class, 1).getInt(packet); // TODO: += if packetdataserializer.version < 16
|
||||
this.action = cachedPlayerActionIDs.get(animationIndex);
|
||||
} else {
|
||||
final Object enumObj = Reflection.getField(entityActionClass, enumPlayerActionClass, 0).get(packet);
|
||||
final String enumName = enumObj.toString();
|
||||
this.action = cachedPlayerActionNames.get(enumName);
|
||||
}
|
||||
|
||||
|
||||
this.entityId = entityId;
|
||||
this.jumpBoost = jumpBoost;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
final int entityId = readInt(0);
|
||||
final int jumpBoost;
|
||||
if (isLowerThan_v_1_8) {
|
||||
jumpBoost = readInt(2);
|
||||
} else {
|
||||
jumpBoost = readInt(1);
|
||||
}
|
||||
|
||||
//1.7.10
|
||||
if (isLowerThan_v_1_8) {
|
||||
int animationIndex = readInt(1);
|
||||
this.action = cachedPlayerActionIDs.get(animationIndex);
|
||||
} else {
|
||||
final Object enumObj = readObject(0, enumPlayerActionClass);
|
||||
final String enumName = enumObj.toString();
|
||||
this.action = cachedPlayerActionNames.get(enumName);
|
||||
}
|
||||
|
||||
|
||||
this.entityId = entityId;
|
||||
this.jumpBoost = jumpBoost;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+94
-69
@@ -26,19 +26,19 @@ package io.github.retrooper.packetevents.packetwrappers.in.flying;
|
||||
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public class WrappedPacketInFlying extends WrappedPacket {
|
||||
private static Class<?> flyingClass;
|
||||
protected double x;
|
||||
protected double y;
|
||||
protected double z;
|
||||
protected float yaw;
|
||||
protected float pitch;
|
||||
protected boolean onGround;
|
||||
protected boolean isPosition;
|
||||
protected boolean isLook;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private boolean onGround;
|
||||
private boolean isPosition;
|
||||
private boolean isLook;
|
||||
public WrappedPacketInFlying(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
@@ -49,45 +49,40 @@ public class WrappedPacketInFlying extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
//x, y, z, yaw pitch, onGround, isPosition, isLook
|
||||
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
|
||||
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
|
||||
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
|
||||
x = readDouble(0);
|
||||
y = readDouble(1);
|
||||
z = readDouble(2);
|
||||
|
||||
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
|
||||
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
|
||||
yaw = readFloat(0);
|
||||
pitch = readFloat(1);
|
||||
|
||||
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
|
||||
onGround = readBoolean(0);
|
||||
|
||||
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
|
||||
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
isPosition = readBoolean(1);
|
||||
isLook = readBoolean(2);
|
||||
}
|
||||
|
||||
public final double getX() {
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public final double getY() {
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public final double getZ() {
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public final float getYaw() {
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public final float getPitch() {
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public final boolean isOnGround() {
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
|
||||
@@ -99,81 +94,111 @@ public class WrappedPacketInFlying extends WrappedPacket {
|
||||
return isLook;
|
||||
}
|
||||
|
||||
public static class WrappedPacketInPosition extends WrappedPacketInFlying {
|
||||
|
||||
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() {
|
||||
try {
|
||||
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
|
||||
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
|
||||
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
|
||||
x = readDouble(0);
|
||||
y = readDouble(1);
|
||||
z = readDouble(2);
|
||||
onGround = readBoolean(0);
|
||||
}
|
||||
|
||||
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
|
||||
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
|
||||
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WrappedPacketInPosition_Look extends WrappedPacketInFlying {
|
||||
|
||||
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() {
|
||||
try {
|
||||
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
|
||||
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
|
||||
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
|
||||
x = readDouble(0);
|
||||
y = readDouble(1);
|
||||
z = readDouble(2);
|
||||
yaw = readFloat(0);
|
||||
pitch = readFloat(1);
|
||||
onGround = readBoolean(0);
|
||||
}
|
||||
|
||||
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
|
||||
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
|
||||
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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() {
|
||||
try {
|
||||
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
|
||||
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
|
||||
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
|
||||
yaw = readFloat(0);
|
||||
pitch = readFloat(1);
|
||||
onGround = readBoolean(0);
|
||||
}
|
||||
|
||||
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
|
||||
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
|
||||
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.helditemslot;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInHeldItemSlot extends WrappedPacket {
|
||||
@@ -43,7 +43,7 @@ public final class WrappedPacketInHeldItemSlot extends WrappedPacket {
|
||||
@Override
|
||||
public void setup() {
|
||||
try {
|
||||
itemInHandIndex = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
itemInHandIndex = readInt(0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+3
-11
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.keepalive;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInKeepAlive extends WrappedPacket {
|
||||
@@ -45,17 +45,9 @@ public final class WrappedPacketInKeepAlive extends WrappedPacket {
|
||||
@Override
|
||||
protected void setup() {
|
||||
if (!integerPresentInIndex0) {
|
||||
try {
|
||||
this.id = Reflection.getField(packetClass, long.class, 0).getLong(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.id = readLong(0);
|
||||
} else {
|
||||
try {
|
||||
this.id = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.id = readInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-11
@@ -27,7 +27,7 @@ package io.github.retrooper.packetevents.packetwrappers.in.settings;
|
||||
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.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
|
||||
@@ -39,10 +39,11 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
|
||||
private static boolean isLowerThan_v_1_8;
|
||||
private String locale;
|
||||
private byte viewDistance;
|
||||
private int viewDistance;
|
||||
private ChatVisibility chatVisibility;
|
||||
private boolean chatColors;
|
||||
private HashMap<DisplayedSkinPart, Boolean> displayedSkinParts;
|
||||
|
||||
public WrappedPacketInSettings(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
@@ -69,12 +70,12 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
protected void setup() {
|
||||
try {
|
||||
//LOCALE
|
||||
this.locale = Reflection.getField(packetClass, String.class, 0).get(packet).toString();
|
||||
this.locale = readString(0);
|
||||
//VIEW DISTANCE
|
||||
this.viewDistance = (byte) Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
this.viewDistance = readInt(0);
|
||||
|
||||
//CHAT VISIBILITY
|
||||
Object chatVisibilityEnumObject = Reflection.getField(packetClass, chatVisibilityEnumClass, 0).get(packet);
|
||||
Object chatVisibilityEnumObject = readObject(0, chatVisibilityEnumClass);
|
||||
String enumValueAsString = chatVisibilityEnumObject.toString();
|
||||
if (enumValueAsString.equals("FULL")) {
|
||||
chatVisibility = ChatVisibility.ENABLED;
|
||||
@@ -85,18 +86,18 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
}
|
||||
|
||||
//CHAT COLORS
|
||||
this.chatColors = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
|
||||
this.chatColors = readBoolean(0);
|
||||
|
||||
//DISPLAYED SKIN PARTS
|
||||
this.displayedSkinParts = new HashMap<DisplayedSkinPart, Boolean>();
|
||||
|
||||
if (isLowerThan_v_1_8) {
|
||||
//in 1.7.10 only the cape display skin part is sent
|
||||
boolean capeEnabled = Reflection.getField(packetClass, boolean.class, 1).getBoolean(packet);
|
||||
boolean capeEnabled = readBoolean(1);
|
||||
displayedSkinParts.put(DisplayedSkinPart.CAPE, capeEnabled);
|
||||
} else {
|
||||
//in 1.8, all the skin parts are sent
|
||||
int skinPartFlags = Reflection.getField(packetClass, int.class, 1).getInt(packet);
|
||||
int skinPartFlags = readInt(1);
|
||||
displayedSkinParts.put(DisplayedSkinPart.CAPE, (skinPartFlags & 0x01) != 0);
|
||||
displayedSkinParts.put(DisplayedSkinPart.JACKET, (skinPartFlags & 0x02) != 0);
|
||||
displayedSkinParts.put(DisplayedSkinPart.LEFT_SLEEVE, (skinPartFlags & 0x04) != 0);
|
||||
@@ -114,6 +115,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get language client setting
|
||||
*
|
||||
* @return String Locale
|
||||
*/
|
||||
public String getLocale() {
|
||||
@@ -122,14 +124,16 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get client view distance.
|
||||
*
|
||||
* @return View Distance
|
||||
*/
|
||||
public byte getViewDistance() {
|
||||
public int getViewDistance() {
|
||||
return viewDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Chat Visibility
|
||||
*
|
||||
* @return Chat Visibility
|
||||
*/
|
||||
public ChatVisibility getChatVisibility() {
|
||||
@@ -138,6 +142,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Is chat colors
|
||||
*
|
||||
* @return Chat Colors
|
||||
*/
|
||||
public boolean isChatColors() {
|
||||
@@ -146,7 +151,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get Displayed skin parts.
|
||||
*
|
||||
* <p>
|
||||
* It is possible for some keys to not exist.
|
||||
* If that is the case, the server version is 1.7.10.
|
||||
* 1.7.10 only sends the cape skin part.
|
||||
@@ -160,7 +165,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Is the skin part enabled.
|
||||
*
|
||||
* <p>
|
||||
* On 1.7.10, some skin parts will default to 'false' as 1.7.10
|
||||
* only sends the 'cape' skin part.
|
||||
*
|
||||
|
||||
+5
-9
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.steervehicle;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public class WrappedPacketInSteerVehicle extends WrappedPacket {
|
||||
@@ -42,15 +42,11 @@ public class WrappedPacketInSteerVehicle extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.side = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
|
||||
this.forward = Reflection.getField(packetClass, float.class, 1).getFloat(packet);
|
||||
this.side = readFloat(0);
|
||||
this.forward = readFloat(1);
|
||||
|
||||
this.jump = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
|
||||
this.unmount = Reflection.getField(packetClass, boolean.class, 1).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.jump = readBoolean(0);
|
||||
this.unmount = readBoolean(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-9
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.transaction;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketInTransaction extends WrappedPacket {
|
||||
@@ -43,14 +43,9 @@ public final class WrappedPacketInTransaction extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.windowId = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
this.actionNumber = Reflection.getField(packetClass, short.class, 0).getShort(packet);
|
||||
this.accepted = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.windowId = readInt(0);
|
||||
this.actionNumber = readShort(0);
|
||||
this.accepted = readBoolean(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
-9
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.useentity;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -33,6 +33,7 @@ import org.bukkit.entity.Entity;
|
||||
public final class WrappedPacketInUseEntity extends WrappedPacket {
|
||||
private static Class<?> useEntityClass;
|
||||
private static Class<?> enumEntityUseActionClass;
|
||||
private Entity entity;
|
||||
private int entityID;
|
||||
private EntityUseAction action;
|
||||
public WrappedPacketInUseEntity(final Object packet) {
|
||||
@@ -52,13 +53,9 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.entityID = Reflection.getField(useEntityClass, int.class, 0).getInt(packet);
|
||||
final Object useActionEnum = Reflection.getField(useEntityClass, enumEntityUseActionClass, 0).get(packet);
|
||||
this.action = EntityUseAction.valueOf(useActionEnum.toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.entityID = readInt(0);
|
||||
final Object useActionEnum = readObject(0, enumEntityUseActionClass);
|
||||
this.action = EntityUseAction.valueOf(useActionEnum.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +63,10 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return NMSUtils.getEntityById(this.entityID);
|
||||
if(entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-17
@@ -24,9 +24,8 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.windowclick;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -114,22 +113,18 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.id = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
this.slot = Reflection.getField(packetClass, int.class, 1).getInt(packet);
|
||||
this.button = Reflection.getField(packetClass, int.class, 2).getInt(packet);
|
||||
this.actionNumber = Reflection.getField(packetClass, short.class, 0).getShort(packet);
|
||||
Object nmsItemStack = Reflection.getField(packetClass, NMSUtils.nmsItemStackClass, 0).get(packet);
|
||||
this.clickedItem = NMSUtils.toBukkitItemStack(nmsItemStack);
|
||||
Object clickMode = Reflection.getField(packetClass, 5).get(packet);
|
||||
this.id = readInt(0);
|
||||
this.slot = readInt(1);
|
||||
this.button = readInt(2);
|
||||
this.actionNumber = readShort(0);
|
||||
Object nmsItemStack = readObject(0, NMSUtils.nmsItemStackClass);
|
||||
this.clickedItem = NMSUtils.toBukkitItemStack(nmsItemStack);
|
||||
Object clickMode = readAnyObject(5);
|
||||
|
||||
if (isClickModePrimitive) {
|
||||
mode = (int) clickMode;
|
||||
} else {
|
||||
mode = invClickTypeMapCache.get(clickMode.toString());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
if (isClickModePrimitive) {
|
||||
mode = (int) clickMode;
|
||||
} else {
|
||||
mode = invClickTypeMapCache.get(clickMode.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-14
@@ -25,14 +25,14 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.abilities;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
|
||||
public final class WrappedPacketOutAbilities extends WrappedPacket implements Sendable {
|
||||
public final class WrappedPacketOutAbilities extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private boolean vulnerable, flying, allowFlight, instantBuild;
|
||||
@@ -64,18 +64,13 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.vulnerable = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
|
||||
this.flying = Reflection.getField(packetClass, boolean.class, 1).getBoolean(packet);
|
||||
this.allowFlight = Reflection.getField(packetClass, boolean.class, 2).getBoolean(packet);
|
||||
this.instantBuild = Reflection.getField(packetClass, boolean.class, 3).getBoolean(packet);
|
||||
|
||||
this.flySpeed = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
|
||||
this.walkSpeed = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.vulnerable = readBoolean(0);
|
||||
this.flying = readBoolean(1);
|
||||
this.allowFlight = readBoolean(2);
|
||||
this.instantBuild = readBoolean(3);
|
||||
|
||||
this.flySpeed = readFloat(0);
|
||||
this.walkSpeed = readFloat(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-13
@@ -25,8 +25,8 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.animation;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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 org.bukkit.entity.Entity;
|
||||
@@ -35,7 +35,7 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class WrappedPacketOutAnimation extends WrappedPacket implements Sendable {
|
||||
public final class WrappedPacketOutAnimation extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> animationClass, nmsEntityClass;
|
||||
private static Constructor<?> animationConstructor;
|
||||
|
||||
@@ -85,16 +85,9 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
//a - ID
|
||||
//b - TYPE
|
||||
this.entityID = Reflection.getField(animationClass, int.class, 0).getInt(packet);
|
||||
int animationID = Reflection.getField(animationClass, int.class, 1).getInt(packet);
|
||||
this.type = cachedAnimationIDS.get(animationID);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.entityID = readInt(0);
|
||||
int animationID = readInt(1);
|
||||
this.type = cachedAnimationIDS.get(animationID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+16
-9
@@ -25,9 +25,10 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.chat;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Beta;
|
||||
import io.github.retrooper.packetevents.annotations.NotNull;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
|
||||
@@ -41,7 +42,7 @@ import java.util.UUID;
|
||||
* This wrapper MIGHT not be stable
|
||||
*/
|
||||
@Beta
|
||||
public final class WrappedPacketOutChat extends WrappedPacket implements Sendable {
|
||||
public final class WrappedPacketOutChat extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> chatClassConstructor;
|
||||
private static Class<?> packetClass, iChatBaseComponentClass, chatSerializerClass, chatMessageTypeEnum;
|
||||
private static Method chatMessageTypeCreatorMethod;
|
||||
@@ -61,6 +62,12 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
private ChatPosition chatPosition;
|
||||
private UUID uuid;
|
||||
|
||||
|
||||
@Deprecated
|
||||
public WrappedPacketOutChat(String message) {
|
||||
this(message, null);
|
||||
}
|
||||
|
||||
public WrappedPacketOutChat(final Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
@@ -70,7 +77,6 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
}
|
||||
|
||||
public WrappedPacketOutChat(String message, ChatPosition chatPosition, UUID uuid) {
|
||||
super();
|
||||
this.uuid = uuid;
|
||||
this.message = message;
|
||||
this.chatPosition = chatPosition;
|
||||
@@ -152,7 +158,7 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
}
|
||||
|
||||
public static String fromStringToJSON(String message) {
|
||||
return "{\"text\": \"" + "use entity action name: " + message + "\"}";
|
||||
return "{\"text\": \"" + message + "\"}";
|
||||
}
|
||||
|
||||
public static String toStringFromIChatBaseComponent(Object obj) {
|
||||
@@ -177,7 +183,7 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
final Object iChatBaseObj = Reflection.getField(packetClass, iChatBaseComponentClass, 0).get(packet);
|
||||
final Object iChatBaseObj = readObject(0, iChatBaseComponentClass);
|
||||
|
||||
final Object contentString = Reflection.getMethod(iChatBaseComponentClass, String.class, 0).invoke(iChatBaseObj);
|
||||
|
||||
@@ -186,14 +192,14 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
byte chatPosInteger = 0;
|
||||
switch (constructorMode) {
|
||||
case 0:
|
||||
chatPosInteger = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
|
||||
chatPosInteger = readByte(0);
|
||||
break;
|
||||
case 1:
|
||||
chatPosInteger = (byte) Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
chatPosInteger = (byte) readInt(0);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
Object chatTypeEnumInstance = Reflection.getField(packetClass, chatMessageTypeEnum, 0).get(packet);
|
||||
Object chatTypeEnumInstance = readObject(0, chatMessageTypeEnum);
|
||||
chatPosInteger = cachedChatMessageTypeIntegers.get(chatTypeEnumInstance.toString());
|
||||
break;
|
||||
}
|
||||
@@ -270,6 +276,7 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
* If an invalid chat position is sent, it will be defaulted it to CHAT.
|
||||
* @return ChatPosition
|
||||
*/
|
||||
@NotNull
|
||||
public ChatPosition getChatPosition() {
|
||||
if(this.chatPosition == null) {
|
||||
this.chatPosition = ChatPosition.CHAT;
|
||||
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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.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 java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
class WrappedPacketOutCustomPayload extends WrappedPacket implements SendableWrapper {
|
||||
//TODO load the outcustompayload wrapper
|
||||
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> constructor;
|
||||
private static Constructor<?> packetDataSerializerConstructor;
|
||||
private static Constructor<?> minecraftKeyConstructor;
|
||||
private static Class<?> byteBufClass;
|
||||
private static Class<?> unpooledClass;
|
||||
private static Class<?> packetDataSerializerClass;
|
||||
private static Class<?> minecraftKeyClass;
|
||||
|
||||
private static byte constructorMode = 1;
|
||||
|
||||
public static void load() {
|
||||
packetClass = PacketTypeClasses.Server.CUSTOM_PAYLOAD;
|
||||
packetDataSerializerClass = NMSUtils.getNMSClassWithoutException("PacketDataSerializer");
|
||||
minecraftKeyClass = NMSUtils.getNMSClassWithoutException("MinecraftKey");
|
||||
|
||||
try {
|
||||
unpooledClass = NMSUtils.getNettyClass("buffer.Unpooled");
|
||||
byteBufClass = NMSUtils.getNettyClass("buffer.ByteBuf");
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
}
|
||||
try {
|
||||
packetDataSerializerConstructor = packetDataSerializerClass.getConstructor(NMSUtils.getNettyClass("ByteBuf"));
|
||||
} catch (NullPointerException e) {
|
||||
//Nothing
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
//also nothing
|
||||
}
|
||||
|
||||
try {
|
||||
minecraftKeyConstructor = minecraftKeyClass.getConstructor(String.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
//Nothing
|
||||
}
|
||||
|
||||
//Constructors:
|
||||
|
||||
//String, byte[]
|
||||
|
||||
//String, PacketDataSerializer
|
||||
|
||||
//MinecraftKey, PacketDataSerializer
|
||||
try {
|
||||
//1.7 constructor
|
||||
constructor = packetClass.getConstructor(String.class, byte[].class);
|
||||
constructorMode = 0;
|
||||
} catch (NoSuchMethodException e) {
|
||||
//That's fine, just a newer version
|
||||
try {
|
||||
constructor = packetClass.getConstructor(String.class, packetDataSerializerClass);
|
||||
constructorMode = 1;
|
||||
} catch (NoSuchMethodException e2) {
|
||||
//That's fine, just an even newer version
|
||||
try {
|
||||
constructor = packetClass.getConstructor(minecraftKeyClass, packetDataSerializerClass);
|
||||
constructorMode = 2;
|
||||
} catch (NoSuchMethodException e3) {
|
||||
throw new IllegalStateException("PacketEvents is unable to resolve the PacketPlayOutCustomPayload constructor.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String tag;
|
||||
private byte[] data;
|
||||
|
||||
public WrappedPacketOutCustomPayload(String tag, byte[] data) {
|
||||
this.tag = tag;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
/* public WrappedPacketOutCustomPayload(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
|
||||
}
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() {
|
||||
Object byteBufObject = null;
|
||||
try {
|
||||
byteBufObject = Reflection.getMethod(unpooledClass, "copiedBuffer", 0).invoke(null, data);
|
||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
switch (constructorMode) {
|
||||
case 0:
|
||||
try {
|
||||
return constructor.newInstance(tag, data);
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
try {
|
||||
Object dataSerializer = packetDataSerializerConstructor.newInstance(byteBufObject);
|
||||
return constructor.newInstance(tag, dataSerializer);
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
|
||||
try {
|
||||
Object minecraftKey = minecraftKeyConstructor.newInstance(tag);
|
||||
Object dataSerializer = packetDataSerializerConstructor.newInstance(byteBufObject);
|
||||
return constructor.newInstance(minecraftKey, dataSerializer);
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+338
-34
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.entity;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -37,10 +37,12 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
//Byte = 1.7.10->1.8.8, Int = 1.9->1.15.x, Short = 1.16.x
|
||||
private static byte mode = 0; //byte = 0, int = 1, short = 2
|
||||
private static double dXYZDivisor = 0.0;
|
||||
private Entity entity;
|
||||
private int entityID;
|
||||
private double deltaX, deltaY, deltaZ;
|
||||
private byte yaw, pitch;
|
||||
private boolean onGround;
|
||||
|
||||
public WrappedPacketOutEntity(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
@@ -68,43 +70,40 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.entityID = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
this.onGround = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
|
||||
int dX = 1, dY = 1, dZ = 1;
|
||||
switch (mode) {
|
||||
case 0:
|
||||
dX = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
|
||||
dY = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
|
||||
dZ = Reflection.getField(packetClass, byte.class, 2).getByte(packet);
|
||||
this.yaw = Reflection.getField(packetClass, byte.class, 3).getByte(packet);
|
||||
this.pitch = Reflection.getField(packetClass, byte.class, 4).getByte(packet);
|
||||
break;
|
||||
case 1:
|
||||
dX = Reflection.getField(packetClass, int.class, 1).getInt(packet);
|
||||
dY = Reflection.getField(packetClass, int.class, 2).getInt(packet);
|
||||
dZ = Reflection.getField(packetClass, int.class, 3).getInt(packet);
|
||||
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
|
||||
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
|
||||
break;
|
||||
case 2:
|
||||
dX = Reflection.getField(packetClass, short.class, 0).getShort(packet);
|
||||
dY = Reflection.getField(packetClass, short.class, 1).getShort(packet);
|
||||
dZ = Reflection.getField(packetClass, short.class, 2).getShort(packet);
|
||||
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
|
||||
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
|
||||
break;
|
||||
}
|
||||
this.deltaX = dX / dXYZDivisor;
|
||||
this.deltaY = dY / dXYZDivisor;
|
||||
this.deltaZ = dZ / dXYZDivisor;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
this.entityID = readInt(0);
|
||||
this.onGround = readBoolean(0);
|
||||
int dX = 1, dY = 1, dZ = 1;
|
||||
switch (mode) {
|
||||
case 0:
|
||||
dX = readByte(0);
|
||||
dY = readByte(1);
|
||||
dZ = readByte(2);
|
||||
this.yaw = readByte(3);
|
||||
this.pitch = readByte(4);
|
||||
break;
|
||||
case 1:
|
||||
dX = readInt(1);
|
||||
dY = readInt(2);
|
||||
dZ = readInt(3);
|
||||
this.yaw = readByte(0);
|
||||
this.pitch = readByte(1);
|
||||
break;
|
||||
case 2:
|
||||
dX = readShort(0);
|
||||
dY = readShort(1);
|
||||
dZ = readShort(2);
|
||||
this.yaw = readByte(0);
|
||||
this.pitch = readByte(1);
|
||||
break;
|
||||
}
|
||||
this.deltaX = dX / dXYZDivisor;
|
||||
this.deltaY = dY / dXYZDivisor;
|
||||
this.deltaZ = dZ / dXYZDivisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pitch.
|
||||
*
|
||||
* @return Get Byte Pitch
|
||||
*/
|
||||
public byte getPitch() {
|
||||
@@ -113,6 +112,7 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get the Yaw.
|
||||
*
|
||||
* @return Get Byte Yaw
|
||||
*/
|
||||
public byte getYaw() {
|
||||
@@ -121,6 +121,7 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get the Delta X
|
||||
*
|
||||
* @return Delta X
|
||||
*/
|
||||
public double getDeltaX() {
|
||||
@@ -129,6 +130,7 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get the Delta Y
|
||||
*
|
||||
* @return Delta Y
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
@@ -137,6 +139,7 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Get the Delta Z
|
||||
*
|
||||
* @return Delta Z
|
||||
*/
|
||||
public double getDeltaZ() {
|
||||
@@ -145,16 +148,21 @@ public class WrappedPacketOutEntity 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;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
@@ -163,9 +171,305 @@ public class WrappedPacketOutEntity extends WrappedPacket {
|
||||
|
||||
/**
|
||||
* Is the entity on the ground?
|
||||
*
|
||||
* @return On Ground
|
||||
*/
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
|
||||
public static class WrappedPacketOutRelEntityMove extends WrappedPacket {
|
||||
private int entityID;
|
||||
private Entity entity;
|
||||
private double deltaX, deltaY, deltaZ;
|
||||
private boolean onGround;
|
||||
|
||||
public WrappedPacketOutRelEntityMove(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
int dX = 1, dY = 1, dZ = 1;
|
||||
switch (mode) {
|
||||
case 0:
|
||||
dX = readByte(0);
|
||||
dY = readByte(1);
|
||||
dZ = readByte(2);
|
||||
break;
|
||||
case 1:
|
||||
dX = readInt(1);
|
||||
dY = readInt(2);
|
||||
dZ = readInt(3);
|
||||
break;
|
||||
case 2:
|
||||
dX = readShort(0);
|
||||
dY = readShort(1);
|
||||
dZ = readShort(2);
|
||||
break;
|
||||
}
|
||||
deltaX = dX / dXYZDivisor;
|
||||
deltaY = dY / dXYZDivisor;
|
||||
deltaZ = dZ / dXYZDivisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Delta X
|
||||
*
|
||||
* @return Delta X
|
||||
*/
|
||||
public double getDeltaX() {
|
||||
return deltaX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Delta Y
|
||||
*
|
||||
* @return Delta Y
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
return deltaY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Delta Z
|
||||
*
|
||||
* @return Delta Z
|
||||
*/
|
||||
public double getDeltaZ() {
|
||||
return deltaZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup the associated entity by the ID that was sent in the packet.
|
||||
*
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return entityID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the entity on the ground?
|
||||
*
|
||||
* @return On Ground
|
||||
*/
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WrappedPacketOutRelEntityMoveLook extends WrappedPacket {
|
||||
private int entityID;
|
||||
private Entity entity;
|
||||
private double deltaX, deltaY, deltaZ;
|
||||
private byte yaw, pitch;
|
||||
private boolean onGround;
|
||||
|
||||
public WrappedPacketOutRelEntityMoveLook(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
entityID = readInt(0);
|
||||
onGround = readBoolean(0);
|
||||
int dX = 1, dY = 1, dZ = 1;
|
||||
switch (mode) {
|
||||
case 0:
|
||||
dX = readByte(0);
|
||||
dY = readByte(1);
|
||||
dZ = readByte(2);
|
||||
yaw = readByte(3);
|
||||
pitch = readByte(4);
|
||||
break;
|
||||
case 1:
|
||||
dX = readInt(1);
|
||||
dY = readInt(2);
|
||||
dZ = readInt(3);
|
||||
yaw = readByte(0);
|
||||
pitch = readByte(1);
|
||||
break;
|
||||
case 2:
|
||||
dX = readShort(0);
|
||||
dY = readShort(1);
|
||||
dZ = readShort(2);
|
||||
yaw = readByte(0);
|
||||
pitch = readByte(1);
|
||||
break;
|
||||
}
|
||||
deltaX = dX / dXYZDivisor;
|
||||
deltaY = dY / dXYZDivisor;
|
||||
deltaZ = dZ / dXYZDivisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pitch.
|
||||
*
|
||||
* @return Get Byte Pitch
|
||||
*/
|
||||
public byte getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Yaw.
|
||||
*
|
||||
* @return Get Byte Yaw
|
||||
*/
|
||||
public byte getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Delta X
|
||||
*
|
||||
* @return Delta X
|
||||
*/
|
||||
public double getDeltaX() {
|
||||
return deltaX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Delta Y
|
||||
*
|
||||
* @return Delta Y
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
return deltaY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Delta Z
|
||||
*
|
||||
* @return Delta Z
|
||||
*/
|
||||
public double getDeltaZ() {
|
||||
return deltaZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup the associated entity by the ID that was sent in the packet.
|
||||
*
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return entityID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the entity on the ground?
|
||||
*
|
||||
* @return On Ground
|
||||
*/
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WrappedPacketOutRelEntityLook extends WrappedPacket {
|
||||
private int entityID;
|
||||
private Entity entity;
|
||||
private byte yaw, pitch;
|
||||
private boolean onGround;
|
||||
|
||||
public WrappedPacketOutRelEntityLook(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
entityID = readInt(0);
|
||||
onGround = readBoolean(0);
|
||||
switch (mode) {
|
||||
case 0:
|
||||
yaw = readByte(3);
|
||||
pitch = readByte(4);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
yaw = readByte(0);
|
||||
pitch = readByte(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pitch.
|
||||
*
|
||||
* @return Get Byte Pitch
|
||||
*/
|
||||
public byte getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Yaw.
|
||||
*
|
||||
* @return Get Byte Yaw
|
||||
*/
|
||||
public byte getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the entity on the ground?
|
||||
*
|
||||
* @return On Ground
|
||||
*/
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup the associated entity by the ID that was sent in the packet.
|
||||
*
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return entityID;
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-17
@@ -26,8 +26,8 @@ package io.github.retrooper.packetevents.packetwrappers.out.entityvelocity;
|
||||
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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 org.bukkit.entity.Entity;
|
||||
@@ -35,7 +35,7 @@ import org.bukkit.entity.Entity;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketOutEntityVelocity extends WrappedPacket implements Sendable {
|
||||
public final class WrappedPacketOutEntityVelocity extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> velocityConstructor, vec3dConstructor;
|
||||
private static Class<?> velocityClass, vec3dClass;
|
||||
private static boolean isVec3dPresent;
|
||||
@@ -88,21 +88,17 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
//ENTITY ID
|
||||
this.entityId = Reflection.getField(velocityClass, int.class, 0).getInt(packet);
|
||||
//ENTITY ID
|
||||
this.entityId = readInt(0);
|
||||
|
||||
int x = Reflection.getField(velocityClass, int.class, 1).getInt(packet);
|
||||
int y = Reflection.getField(velocityClass, int.class, 2).getInt(packet);
|
||||
int z = Reflection.getField(velocityClass, int.class, 3).getInt(packet);
|
||||
int x = readInt(1);
|
||||
int y = readInt(2);
|
||||
int z = readInt(3);
|
||||
|
||||
//VELOCITY XYZ
|
||||
this.velocityX = x / 8000.0D;
|
||||
this.velocityY = y / 8000.0D;
|
||||
this.velocityZ = z / 8000.0D;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//VELOCITY XYZ
|
||||
this.velocityX = x / 8000.0D;
|
||||
this.velocityY = y / 8000.0D;
|
||||
this.velocityZ = z / 8000.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +106,10 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return NMSUtils.getEntityById(this.entityId);
|
||||
if(entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(this.entityId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
-15
@@ -25,14 +25,14 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.keepalive;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
|
||||
public class WrappedPacketOutKeepAlive extends WrappedPacket implements Sendable {
|
||||
public class WrappedPacketOutKeepAlive extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> keepAliveConstructor;
|
||||
private static boolean integerMode;
|
||||
@@ -67,18 +67,11 @@ public class WrappedPacketOutKeepAlive extends WrappedPacket implements Sendable
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
if (!integerMode) {
|
||||
try {
|
||||
this.id = Reflection.getField(packetClass, long.class, 0).getLong(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
this.id = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(integerMode) {
|
||||
this.id = readInt(0);
|
||||
}
|
||||
else {
|
||||
this.id = readLong(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-9
@@ -25,8 +25,8 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.kickdisconnect;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
@@ -34,7 +34,7 @@ import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class WrappedPacketOutKickDisconnect extends WrappedPacket implements Sendable {
|
||||
public final class WrappedPacketOutKickDisconnect extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass, iChatBaseComponentClass;
|
||||
private static Constructor<?> kickDisconnectConstructor;
|
||||
private String kickMessage;
|
||||
@@ -65,11 +65,8 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.kickMessage = WrappedPacketOutChat.toStringFromIChatBaseComponent(Reflection.getField(packetClass, iChatBaseComponentClass, 0).get(packet));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Object ichatbaseComponentoObject = readObject(0, iChatBaseComponentClass);
|
||||
this.kickMessage = WrappedPacketOutChat.toStringFromIChatBaseComponent(ichatbaseComponentoObject);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +80,7 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
|
||||
@Override
|
||||
public Object asNMSPacket() {
|
||||
try {
|
||||
return kickDisconnectConstructor.newInstance(WrappedPacketOutChat.toIChatBaseComponent("{\"text\": \"" + kickMessage + "\"}"));
|
||||
return kickDisconnectConstructor.newInstance(WrappedPacketOutChat.toIChatBaseComponent(WrappedPacketOutChat.fromStringToJSON(kickMessage)));
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+6
-10
@@ -25,7 +25,7 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.position;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
|
||||
public final class WrappedPacketOutPosition extends WrappedPacket {
|
||||
@@ -47,16 +47,12 @@ public final class WrappedPacketOutPosition extends WrappedPacket {
|
||||
@Override
|
||||
protected void setup() {
|
||||
//TODO boolean onGround and flags
|
||||
try {
|
||||
this.x = Reflection.getField(packetClass, double.class, 0).getDouble(packet);
|
||||
this.y = Reflection.getField(packetClass, double.class, 1).getDouble(packet);
|
||||
this.z = Reflection.getField(packetClass, double.class, 2).getDouble(packet);
|
||||
this.x = readDouble(0);
|
||||
this.y = readDouble(1);
|
||||
this.z = readDouble(2);
|
||||
|
||||
this.yaw = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
|
||||
this.pitch = Reflection.getField(packetClass, float.class, 1).getFloat(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.yaw = readFloat(0);
|
||||
this.pitch = readFloat(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-10
@@ -25,14 +25,14 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.transaction;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
|
||||
public class WrappedPacketOutTransaction extends WrappedPacket implements Sendable {
|
||||
public class WrappedPacketOutTransaction extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int windowId;
|
||||
@@ -61,13 +61,9 @@ public class WrappedPacketOutTransaction extends WrappedPacket implements Sendab
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.windowId = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
this.actionNumber = Reflection.getField(packetClass, short.class, 0).getShort(packet);
|
||||
this.accepted = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.windowId = readInt(0);
|
||||
this.actionNumber = readShort(0);
|
||||
this.accepted = readBoolean(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -25,14 +25,14 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.updatehealth;
|
||||
|
||||
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
|
||||
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;
|
||||
|
||||
public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements Sendable {
|
||||
public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements SendableWrapper {
|
||||
private static Class<?> packetClass;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private float health, foodSaturation;
|
||||
@@ -68,8 +68,8 @@ public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements
|
||||
@Override
|
||||
protected void setup() {
|
||||
try {
|
||||
this.health = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
|
||||
this.foodSaturation = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
|
||||
this.health = readFloat(0);
|
||||
this.foodSaturation = readFloat(1);
|
||||
this.food = Reflection.getField(packetClass, int.class, 0).getInt(packet);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -26,7 +26,7 @@ package io.github.retrooper.packetevents.utils;
|
||||
|
||||
import io.github.retrooper.packetevents.annotations.Nullable;
|
||||
import io.github.retrooper.packetevents.enums.ServerVersion;
|
||||
import io.github.retrooper.packetevents.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.reflectionutils.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.nms_entityfinder.EntityFinderUtils;
|
||||
import org.bukkit.World;
|
||||
@@ -219,8 +219,8 @@ public final class NMSUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void sendSendableWrapper(final Player player, final Sendable sendable) {
|
||||
NMSUtils.sendNMSPacket(player, sendable.asNMSPacket());
|
||||
public static void sendSendableWrapper(final Player player, final SendableWrapper sendableWrapper) {
|
||||
NMSUtils.sendNMSPacket(player, sendableWrapper.asNMSPacket());
|
||||
}
|
||||
|
||||
public static void sendNMSPacket(final Player player, final Object nmsPacket) {
|
||||
|
||||
@@ -27,7 +27,7 @@ package io.github.retrooper.packetevents.utils.api;
|
||||
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.packetwrappers.Sendable;
|
||||
import io.github.retrooper.packetevents.packetwrappers.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.utils.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -119,12 +119,12 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link Sendable} wrapper to a player.
|
||||
* Send a {@link SendableWrapper} wrapper to a player.
|
||||
* @param player
|
||||
* @param sendable
|
||||
* @param sendableWrapper
|
||||
*/
|
||||
public void sendPacket(final Player player, final Sendable sendable) {
|
||||
NMSUtils.sendSendableWrapper(player, sendable);
|
||||
public void sendPacket(final Player player, final SendableWrapper sendableWrapper) {
|
||||
NMSUtils.sendSendableWrapper(player, sendableWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.protocollib;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import org.bukkit.entity.Player;
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.protocollib;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.annotations.PacketHandler;
|
||||
import io.github.retrooper.packetevents.enums.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.event.PacketListener;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class ProtocolLibListener {
|
||||
|
||||
public static void registerProtocolLibListener(PacketListener listener, ConcurrentLinkedQueue<Method> methods) {
|
||||
if (ProtocolLibUtils.isAvailable()) {
|
||||
for (Method m : methods) {
|
||||
if (m.getParameterTypes()[0].equals(PacketReceiveEvent.class)) {
|
||||
PacketHandler annot = m.getAnnotation(PacketHandler.class);
|
||||
ListenerPriority priority;
|
||||
switch (annot.priority()) {
|
||||
case PacketEventPriority.LOWEST:
|
||||
priority = ListenerPriority.LOWEST;
|
||||
break;
|
||||
case PacketEventPriority.LOW:
|
||||
priority = ListenerPriority.LOW;
|
||||
break;
|
||||
case PacketEventPriority.HIGH:
|
||||
priority = ListenerPriority.HIGH;
|
||||
break;
|
||||
case PacketEventPriority.HIGHEST:
|
||||
priority = ListenerPriority.HIGHEST;
|
||||
break;
|
||||
case PacketEventPriority.MONITOR:
|
||||
priority = ListenerPriority.MONITOR;
|
||||
break;
|
||||
default:
|
||||
priority = ListenerPriority.NORMAL;
|
||||
break;
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().
|
||||
addPacketListener(new PacketAdapter(PacketEvents.getPlugins().get(0),
|
||||
priority, PacketType.Play.Client.getInstance().values()) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
event.setReadOnly(false);
|
||||
PacketReceiveEvent receiveEvent = new PacketReceiveEvent(event.getPlayer(), event.getPacket().getHandle());
|
||||
try {
|
||||
m.invoke(listener, receiveEvent);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
event.setCancelled(receiveEvent.isCancelled());
|
||||
}
|
||||
});
|
||||
} else if (m.getParameterTypes()[0].equals(PacketSendEvent.class)) {
|
||||
PacketHandler annot = m.getAnnotation(PacketHandler.class);
|
||||
ListenerPriority priority;
|
||||
switch (annot.priority()) {
|
||||
case PacketEventPriority.LOWEST:
|
||||
priority = ListenerPriority.LOWEST;
|
||||
break;
|
||||
case PacketEventPriority.LOW:
|
||||
priority = ListenerPriority.LOW;
|
||||
break;
|
||||
case PacketEventPriority.HIGH:
|
||||
priority = ListenerPriority.HIGH;
|
||||
break;
|
||||
case PacketEventPriority.HIGHEST:
|
||||
priority = ListenerPriority.HIGHEST;
|
||||
break;
|
||||
case PacketEventPriority.MONITOR:
|
||||
priority = ListenerPriority.MONITOR;
|
||||
break;
|
||||
default:
|
||||
priority = ListenerPriority.NORMAL;
|
||||
break;
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().
|
||||
addPacketListener(new PacketAdapter(PacketEvents.getPlugins().get(0),
|
||||
priority, PacketType.Play.Server.getInstance().values()) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
event.setReadOnly(false);
|
||||
PacketSendEvent sendEvent = new PacketSendEvent(event.getPlayer(), event.getPacket().getHandle());
|
||||
try {
|
||||
m.invoke(listener, sendEvent);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
event.setCancelled(sendEvent.isCancelled());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.protocollib;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.protocolsupport;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import protocolsupport.api.ProtocolSupportAPI;
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.protocolsupport;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
+3
@@ -26,6 +26,9 @@ package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
|
||||
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.viaversion.ViaUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class VersionLookupUtils {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.viaversion;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
package io.github.retrooper.packetevents.utils.viaversion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
Reference in new issue
Block a user