forked from upstream/packetevents
Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
825b61a24e | ||
|
|
dc5d15ba85 | ||
|
|
0b458c2e4c | ||
|
|
bb9fe18a76 | ||
|
|
73420efbb7 | ||
|
|
c3bc1906b1 | ||
|
|
3c4a7323a0 | ||
|
|
0a4fedff09 | ||
|
|
d1fb535ca7 | ||
|
|
5865e056d8 | ||
|
|
eb561b98b2 | ||
|
|
13b3ac7107 | ||
|
|
1943ba2da1 | ||
|
|
f90925e09b | ||
|
|
e2ecb21892 | ||
|
|
80bc492370 | ||
|
|
691e8eb070 | ||
|
|
a83c3bac2a | ||
|
|
60a5357c34 | ||
|
|
af477f8479 | ||
|
|
6b82b38b59 |
No files matched your search
@@ -21,7 +21,7 @@ Our discord server has a role for contributors and forkers.
|
||||
[](https://www.ej-technologies.com/products/jprofiler/overview.html)
|
||||
|
||||
### Statistics
|
||||
PacketEvents collects statistics anonymously through bStats. Participation is completely optional and you can opt-out at any time, although it is really helpful in figuring out what environments the plugin is running in (i.e. versions of Spigot, Java), so I can adjust development accordingly.
|
||||
PacketEvents collects statistics anonymously using bStats. It helps give us an overview of what platforms use our project. If you really don't like, you can turn it off.
|
||||
|
||||
### Credit
|
||||
PacketEvents uses an injector that is extremely similar to ViaVersion's injector. I have included license and copyright holder notice in the files taken from ViaVersion. Thank you ViaVersion.
|
||||
+3
-3
@@ -49,14 +49,14 @@ repositories {
|
||||
maven {
|
||||
url = uri('https://repo.maven.apache.org/maven2/')
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.jetbrains:annotations:20.1.0'
|
||||
implementation 'org.jetbrains:annotations:22.0.0'
|
||||
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.geysermc:connector:1.4.2-SNAPSHOT'
|
||||
compileOnly 'com.viaversion:viaversion-api:4.0.1'
|
||||
compileOnly 'com.github.ProtocolSupport:ProtocolSupport:3d24efeda6'
|
||||
|
||||
@@ -66,7 +66,7 @@ dependencies {
|
||||
}
|
||||
|
||||
group = 'io.github.retrooper'
|
||||
version = '1.8-pre-19'
|
||||
version = '1.8.2'
|
||||
description = 'packetevents'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
public final class PacketEvents implements Listener, EventManager {
|
||||
private static PacketEvents instance;
|
||||
private static Plugin plugin;
|
||||
private final PEVersion version = new PEVersion(1, 7, 9, 19);
|
||||
private final PEVersion version = new PEVersion(1, 8, 2);
|
||||
private final EventManager eventManager = new PEEventManager();
|
||||
private final PlayerUtils playerUtils = new PlayerUtils();
|
||||
private final ServerUtils serverUtils = new ServerUtils();
|
||||
@@ -191,6 +191,10 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
|
||||
if (settings.isbStatsEnabled()) {
|
||||
Metrics metrics = new Metrics((JavaPlugin) getPlugin(), 11327);
|
||||
//Just to have an idea what versions of packetevents people use
|
||||
metrics.addCustomChart(new Metrics.SimplePie("packetevents_version", () -> {
|
||||
return getVersion().toString();
|
||||
}));
|
||||
}
|
||||
|
||||
//We must wait for the injector to initialize.
|
||||
|
||||
+2
-1
@@ -21,10 +21,11 @@ package io.github.retrooper.packetevents.injector.legacy;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.processor.PacketProcessorInternal;
|
||||
import net.minecraft.util.io.netty.channel.ChannelDuplexHandler;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.util.io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class PlayerChannelHandlerLegacy extends ChannelDuplexHandler {
|
||||
/**
|
||||
* Associated player.
|
||||
|
||||
+5
-1
@@ -25,10 +25,12 @@ import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.list.ListWrapper;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.ChannelFuture;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.util.io.netty.channel.ChannelInitializer;
|
||||
import net.minecraft.util.io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
@@ -127,7 +129,9 @@ public class EarlyChannelInjectorLegacy implements EarlyInjector {
|
||||
for (Object networkManager : networkManagers) {
|
||||
WrappedPacket networkManagerWrapper = new WrappedPacket(new NMSPacket(networkManager), NMSUtils.networkManagerClass);
|
||||
Channel channel = (Channel) networkManagerWrapper.readObject(0, NMSUtils.nettyChannelClass);
|
||||
if (channel == null) {
|
||||
if (channel == null ||
|
||||
(!(channel.getClass().equals(NioSocketChannel.class))) &&
|
||||
!(channel.getClass().equals(EpollSocketChannel.class))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+11
-6
@@ -21,8 +21,10 @@ package io.github.retrooper.packetevents.injector.legacy.early;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.injector.legacy.PlayerChannelHandlerLegacy;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.ChannelInitializer;
|
||||
import net.minecraft.util.io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -47,12 +49,15 @@ public class PEChannelInitializerLegacy extends ChannelInitializer<Channel> {
|
||||
protected void initChannel(Channel channel) throws Exception {
|
||||
initChannelMethod.invoke(oldChannelInitializer, channel);
|
||||
PlayerChannelHandlerLegacy channelHandler = new PlayerChannelHandlerLegacy();
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
String handlerName = PacketEvents.get().getHandlerName();
|
||||
if (channel.pipeline().get(handlerName) != null) {
|
||||
PacketEvents.get().getPlugin().getLogger().warning("[PacketEvents] Attempted to initialize a channel twice!");
|
||||
} else {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, channelHandler);
|
||||
if (channel.getClass().equals(NioSocketChannel.class)
|
||||
|| channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
String handlerName = PacketEvents.get().getHandlerName();
|
||||
if (channel.pipeline().get(handlerName) != null) {
|
||||
PacketEvents.get().getPlugin().getLogger().warning("[PacketEvents] Attempted to initialize a channel twice!");
|
||||
} else {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, channelHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -21,7 +21,9 @@ package io.github.retrooper.packetevents.injector.legacy.late;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.injector.LateInjector;
|
||||
import io.github.retrooper.packetevents.injector.legacy.PlayerChannelHandlerLegacy;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LateChannelInjectorLegacy implements LateInjector {
|
||||
@@ -40,7 +42,10 @@ public class LateChannelInjectorLegacy implements LateInjector {
|
||||
PlayerChannelHandlerLegacy playerChannelHandlerLegacy = new PlayerChannelHandlerLegacy();
|
||||
playerChannelHandlerLegacy.player = player;
|
||||
Channel channel = (Channel) PacketEvents.get().getPlayerUtils().getChannel(player);
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerLegacy);
|
||||
if (channel.getClass().equals(NioSocketChannel.class)
|
||||
|| channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerLegacy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -21,10 +21,11 @@ package io.github.retrooper.packetevents.injector.modern;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.processor.PacketProcessorInternal;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class PlayerChannelHandlerModern extends ChannelDuplexHandler {
|
||||
/**
|
||||
* Associated player.
|
||||
|
||||
+9
-5
@@ -29,6 +29,8 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
@@ -73,10 +75,10 @@ public class EarlyChannelInjectorModern implements EarlyInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
try {
|
||||
if (PaperChannelInjector.PAPER_INJECTION_METHOD) {
|
||||
/* if (PaperChannelInjector.PAPER_INJECTION_METHOD) {
|
||||
PaperChannelInjector.setPaperChannelInitializeListener();
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
Object serverConnection = NMSUtils.getMinecraftServerConnection();
|
||||
for (Field field : serverConnection.getClass().getDeclaredFields()) {
|
||||
field.setAccessible(true);
|
||||
@@ -130,7 +132,9 @@ public class EarlyChannelInjectorModern implements EarlyInjector {
|
||||
for (Object networkManager : networkManagers) {
|
||||
WrappedPacket networkManagerWrapper = new WrappedPacket(new NMSPacket(networkManager), NMSUtils.networkManagerClass);
|
||||
Channel channel = (Channel) networkManagerWrapper.readObject(0, NMSUtils.nettyChannelClass);
|
||||
if (channel == null) {
|
||||
if (channel == null ||
|
||||
(!(channel.getClass().equals(NioSocketChannel.class))) &&
|
||||
!(channel.getClass().equals(EpollSocketChannel.class))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -195,13 +199,13 @@ public class EarlyChannelInjectorModern implements EarlyInjector {
|
||||
@Override
|
||||
public void eject() {
|
||||
// TODO: Uninject from players currently online to prevent protocol lib issues.
|
||||
if (PaperChannelInjector.PAPER_INJECTION_METHOD) {
|
||||
/* if (PaperChannelInjector.PAPER_INJECTION_METHOD) {
|
||||
try {
|
||||
PaperChannelInjector.removePaperChannelInitializeListener();
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
Field childHandlerField = null;
|
||||
for (ChannelFuture future : injectedFutures) {
|
||||
List<String> names = future.channel().pipeline().names();
|
||||
|
||||
+13
-7
@@ -23,6 +23,8 @@ import io.github.retrooper.packetevents.injector.modern.PlayerChannelHandlerMode
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -36,13 +38,17 @@ public class PEChannelInitializerModern extends ChannelInitializer<Channel> {
|
||||
}
|
||||
|
||||
public static void postInitChannel(Channel channel) {
|
||||
PlayerChannelHandlerModern channelHandler = new PlayerChannelHandlerModern();
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
String handlerName = PacketEvents.get().getHandlerName();
|
||||
if (channel.pipeline().get(handlerName) != null) {
|
||||
PacketEvents.get().getPlugin().getLogger().warning("[PacketEvents] Attempted to initialize a channel twice!");
|
||||
} else {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, channelHandler);
|
||||
if (channel.getClass().equals(NioSocketChannel.class)
|
||||
|| channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
PlayerChannelHandlerModern channelHandler = new PlayerChannelHandlerModern();
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
String handlerName = PacketEvents.get().getHandlerName();
|
||||
if (channel.pipeline().get(handlerName) != null) {
|
||||
//Just ignore this to support latest ProtocolLib snapshots.
|
||||
//PacketEvents.get().getPlugin().getLogger().warning("[PacketEvents] Attempted to initialize a channel twice!");
|
||||
} else {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, channelHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.injector.modern.early;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.netty.channel.Channel;
|
||||
import net.kyori.adventure.key.Key;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
public class PaperChannelInjector {
|
||||
public static final boolean PAPER_INJECTION_METHOD = hasPaperInjectionMethod();
|
||||
|
||||
private PaperChannelInjector() {
|
||||
}
|
||||
|
||||
public static void setPaperChannelInitializeListener() throws ReflectiveOperationException {
|
||||
// Call io.papermc.paper.network.ChannelInitializeListenerHolder.addListener(net.kyori.adventure.key.Key, io.papermc.paper.network.ChannelInitializeListener)
|
||||
// Create an interface proxy of ChannelInitializeListener
|
||||
Class<?> listenerClass = Class.forName("io.papermc.paper.network.ChannelInitializeListener");
|
||||
Object channelInitializeListener = Proxy.newProxyInstance(EarlyChannelInjectorModern.class.getClassLoader(), new Class[]{listenerClass}, (proxy, method, args) -> {
|
||||
if (method.getName().equals("afterInitChannel")) {
|
||||
PEChannelInitializerModern.postInitChannel((Channel) args[0]);
|
||||
return null;
|
||||
}
|
||||
return method.invoke(proxy, args);
|
||||
});
|
||||
|
||||
Class<?> holderClass = Class.forName("io.papermc.paper.network.ChannelInitializeListenerHolder");
|
||||
Method addListenerMethod = holderClass.getDeclaredMethod("addListener", Key.class, listenerClass);
|
||||
Key key = Key.key(PacketEvents.get().getHandlerName().toLowerCase(), "injector");
|
||||
addListenerMethod.invoke(null, key, channelInitializeListener);
|
||||
}
|
||||
|
||||
public static void removePaperChannelInitializeListener() throws ReflectiveOperationException {
|
||||
Class<?> holderClass = Class.forName("io.papermc.paper.network.ChannelInitializeListenerHolder");
|
||||
Method addListenerMethod = holderClass.getDeclaredMethod("removeListener", Key.class);
|
||||
Key key = Key.key(PacketEvents.get().getHandlerName().toLowerCase(), "injector");
|
||||
addListenerMethod.invoke(null, key);
|
||||
}
|
||||
|
||||
private static boolean hasPaperInjectionMethod() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.network.ChannelInitializeListener");
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -22,6 +22,8 @@ import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.injector.LateInjector;
|
||||
import io.github.retrooper.packetevents.injector.modern.PlayerChannelHandlerModern;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LateChannelInjectorModern implements LateInjector {
|
||||
@@ -40,7 +42,10 @@ public class LateChannelInjectorModern implements LateInjector {
|
||||
PlayerChannelHandlerModern playerChannelHandlerModern = new PlayerChannelHandlerModern();
|
||||
playerChannelHandlerModern.player = player;
|
||||
Channel channel = (Channel) PacketEvents.get().getPlayerUtils().getChannel(player);
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerModern);
|
||||
if (channel.getClass().equals(NioSocketChannel.class) ||
|
||||
channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerModern);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
* Sent when Generate is pressed on the Jigsaw Block interface.
|
||||
*
|
||||
* @author Tecnio
|
||||
* @see <a href="https://wiki.vg/Protocol#Generate_Structure"</a>
|
||||
*/
|
||||
public class WrappedPacketInJigsawGenerate extends WrappedPacket {
|
||||
|
||||
|
||||
-1
@@ -30,7 +30,6 @@ import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Tecnio
|
||||
* @see <a href="https://wiki.vg/Protocol#Edit_Book"</a>
|
||||
*/
|
||||
public class WrappedPacketInBEdit extends WrappedPacket {
|
||||
private static boolean v_1_13, v_1_17;
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ import java.lang.reflect.Constructor;
|
||||
* This packet is used for a number of actions and animations performed by blocks, usually non-persistent.
|
||||
*
|
||||
* @author Tecnio
|
||||
* @see <a href="https://wiki.vg/Protocol#Block_Action"</a>
|
||||
*/
|
||||
public class WrappedPacketOutBlockAction extends WrappedPacket implements SendableWrapper {
|
||||
|
||||
|
||||
+28
-20
@@ -35,11 +35,12 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
//Byte = 1.7.10->1.8.8, Int = 1.9->1.15.x, Short = 1.16.x
|
||||
private static byte mode; //byte = 0, int = 1, short = 2
|
||||
private static double dXYZDivisor;
|
||||
private static final float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
private static int yawByteIndex = 0;
|
||||
private static int pitchByteIndex = 1;
|
||||
private static Constructor<?> entityPacketConstructor, entityRelMovePacketConstructor, entityLookConstructor, entityRelMoveLookConstructor;
|
||||
private double deltaX, deltaY, deltaZ;
|
||||
private byte pitch, yaw;
|
||||
private float pitch, yaw;
|
||||
private boolean onGround, rotating, moving;
|
||||
|
||||
public WrappedPacketOutEntity(NMSPacket packet) {
|
||||
@@ -48,7 +49,7 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntity(int entityID, double deltaX, double deltaY, double deltaZ,
|
||||
byte yaw, byte pitch, boolean onGround, boolean rotating, boolean moving) {
|
||||
float yaw, float pitch, boolean onGround, boolean rotating, boolean moving) {
|
||||
this.entityID = entityID;
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
@@ -61,22 +62,22 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntity(int entityID, double deltaX, double deltaY, double deltaZ,
|
||||
byte yaw, byte pitch, boolean onGround, boolean rotating) {
|
||||
float yaw, float pitch, boolean onGround, boolean rotating) {
|
||||
this(entityID, deltaX, deltaY, deltaZ, yaw, pitch, onGround, rotating, false);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntity(int entityID, double deltaX, double deltaY, double deltaZ,
|
||||
byte yaw, byte pitch, boolean onGround) {
|
||||
float yaw, float pitch, boolean onGround) {
|
||||
this(entityID, deltaX, deltaY, deltaZ, yaw, pitch, onGround, false, false);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntity(Entity entity, double deltaX, double deltaY, double deltaZ,
|
||||
byte yaw, byte pitch, boolean onGround, boolean isLook) {
|
||||
float yaw, float pitch, boolean onGround, boolean isLook) {
|
||||
this(entity.getEntityId(), deltaX, deltaY, deltaZ, yaw, pitch, onGround, isLook);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntity(Entity entity, double deltaX, double deltaY, double deltaZ,
|
||||
byte yaw, byte pitch, boolean onGround) {
|
||||
float yaw, float pitch, boolean onGround) {
|
||||
this(entity.getEntityId(), deltaX, deltaY, deltaZ, yaw, pitch, onGround, false);
|
||||
}
|
||||
|
||||
@@ -116,33 +117,33 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
|
||||
}
|
||||
|
||||
public byte getPitch() {
|
||||
public float getPitch() {
|
||||
if (packet != null) {
|
||||
return readByte(pitchByteIndex);
|
||||
return readByte(pitchByteIndex) / ROTATION_FACTOR;
|
||||
} else {
|
||||
return pitch;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPitch(byte pitch) {
|
||||
public void setPitch(float pitch) {
|
||||
if (packet != null) {
|
||||
writeByte(pitchByteIndex, pitch);
|
||||
writeByte(pitchByteIndex, (byte) (pitch * ROTATION_FACTOR));
|
||||
} else {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
}
|
||||
|
||||
public byte getYaw() {
|
||||
public float getYaw() {
|
||||
if (packet != null) {
|
||||
return readByte(yawByteIndex);
|
||||
return readByte(yawByteIndex) / ROTATION_FACTOR;
|
||||
} else {
|
||||
return yaw;
|
||||
}
|
||||
}
|
||||
|
||||
public void setYaw(byte yaw) {
|
||||
public void setYaw(float yaw) {
|
||||
if (packet != null) {
|
||||
writeByte(yawByteIndex, yaw);
|
||||
writeByte(yawByteIndex, (byte) (yaw * ROTATION_FACTOR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,10 +316,12 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
if (v_1_17) {
|
||||
byte angleYaw = (byte) (getYaw() * ROTATION_FACTOR);
|
||||
byte anglePitch = (byte) (getPitch() * ROTATION_FACTOR);
|
||||
return entityPacketConstructor.newInstance(getEntityId(),
|
||||
(short) (getDeltaX() * dXYZDivisor), (short) (getDeltaY() * dXYZDivisor),
|
||||
(short) (getDeltaZ() * dXYZDivisor),
|
||||
getYaw(), getPitch(), isOnGround(), isRotating().get(), isMoving().get());
|
||||
angleYaw, anglePitch, isOnGround(), isRotating().get(), isMoving().get());
|
||||
} else {
|
||||
Object packetInstance = entityPacketConstructor.newInstance(getEntityId());
|
||||
WrappedPacketOutEntity wrapper = new WrappedPacketOutEntity(new NMSPacket(packetInstance));
|
||||
@@ -343,7 +346,7 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityLook(int entityID, byte yaw, byte pitch, boolean onGround) {
|
||||
public WrappedPacketOutEntityLook(int entityID, float yaw, float pitch, boolean onGround) {
|
||||
super(entityID, 0, 0, 0, yaw, pitch, onGround, true);
|
||||
}
|
||||
|
||||
@@ -366,7 +369,9 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
packetInstance = entityLookConstructor.newInstance(getEntityId(), getYaw(), getPitch(), isOnGround());
|
||||
byte angleYaw = (byte) (getYaw() * ROTATION_FACTOR);
|
||||
byte anglePitch = (byte) (getPitch() * ROTATION_FACTOR);
|
||||
packetInstance = entityLookConstructor.newInstance(getEntityId(), angleYaw, anglePitch, isOnGround());
|
||||
}
|
||||
else {
|
||||
packetInstance = entityLookConstructor.newInstance();
|
||||
@@ -389,7 +394,7 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
}
|
||||
|
||||
public WrappedPacketOutRelEntityMove(int entityID, double deltaX, double deltaY, double deltaZ, boolean onGround) {
|
||||
super(entityID, deltaX, deltaY, deltaZ, (byte) 0, (byte) 0, onGround, false);
|
||||
super(entityID, deltaX, deltaY, deltaZ, 0, 0, onGround, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -438,7 +443,8 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutRelEntityMoveLook(int entityID, double deltaX, double deltaY, double deltaZ, byte yaw, byte pitch, boolean onGround) {
|
||||
public WrappedPacketOutRelEntityMoveLook(int entityID, double deltaX, double deltaY, double deltaZ,
|
||||
float yaw, float pitch, boolean onGround) {
|
||||
super(entityID, deltaX, deltaY, deltaZ, yaw, pitch, onGround, false);
|
||||
}
|
||||
|
||||
@@ -464,7 +470,9 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
short dx = (short) (getDeltaX() * dXYZDivisor);
|
||||
short dy = (short) (getDeltaY() * dXYZDivisor);
|
||||
short dz = (short) (getDeltaZ() * dXYZDivisor);
|
||||
packetInstance = entityRelMoveLookConstructor.newInstance(getEntityId(), dx, dy, dz, getYaw(), getPitch(), isOnGround());
|
||||
byte angleYaw = (byte) (getYaw() * ROTATION_FACTOR);
|
||||
byte anglePitch = (byte) (getPitch() * ROTATION_FACTOR);
|
||||
packetInstance = entityRelMoveLookConstructor.newInstance(getEntityId(), dx, dy, dz, angleYaw, anglePitch, isOnGround());
|
||||
}
|
||||
else {
|
||||
packetInstance = entityRelMoveLookConstructor.newInstance();
|
||||
|
||||
+74
-42
@@ -22,18 +22,24 @@ import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.helper.WrappedPacketEntityAbstraction;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author yanjulang, MWHunter
|
||||
* @since 1.8
|
||||
*/
|
||||
public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static Class<?> INT_COLLECTION_CLASS;
|
||||
private static Class<?> INT_LIST_CLASS;
|
||||
private static Class<?> INT_ARRAY_LIST_CLASS;
|
||||
private static Constructor<?> INT_ARRAY_LIST_CONSTRUCTOR;
|
||||
private static Method TO_INT_ARRAY_METHOD;
|
||||
private static boolean v_1_17;
|
||||
private static boolean v_1_17_1;
|
||||
private static Constructor<?> packetConstructor;
|
||||
@@ -61,12 +67,31 @@ public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstractio
|
||||
v_1_17_1 = version.isNewerThanOrEquals(ServerVersion.v_1_17_1);
|
||||
v_1_17 = version.equals(ServerVersion.v_1_17);
|
||||
|
||||
if (v_1_17_1) {
|
||||
if (INT_COLLECTION_CLASS == null) {
|
||||
INT_COLLECTION_CLASS = Reflection.getClassByNameWithoutException("it.unimi.dsi.fastutil.ints.IntCollection");
|
||||
INT_LIST_CLASS = Reflection.getClassByNameWithoutException("it.unimi.dsi.fastutil.ints.IntList");
|
||||
INT_ARRAY_LIST_CLASS = Reflection.getClassByNameWithoutException("it.unimi.dsi.fastutil.ints.IntArrayList");
|
||||
try {
|
||||
INT_ARRAY_LIST_CONSTRUCTOR = INT_ARRAY_LIST_CLASS.getConstructor(int[].class);
|
||||
INT_ARRAY_LIST_CONSTRUCTOR.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
TO_INT_ARRAY_METHOD = INT_COLLECTION_CLASS.getDeclaredMethod("toIntArray");
|
||||
TO_INT_ARRAY_METHOD.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (v_1_17) {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_DESTROY.getConstructor(int.class);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_DESTROY.getConstructor(int[].class);
|
||||
}
|
||||
@@ -80,15 +105,17 @@ public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstractio
|
||||
if (entityID != -1 || entityIds.length > 0 || packet == null) {
|
||||
if (v_1_17) {
|
||||
return entityID;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return entityIds[0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (v_1_17_1) {
|
||||
IntList list = readObject(0, IntList.class);
|
||||
entityIds = list.toIntArray();
|
||||
Object list = readObject(0, INT_LIST_CLASS);
|
||||
try {
|
||||
entityIds = (int[]) TO_INT_ARRAY_METHOD.invoke(list);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return entityIds[0];
|
||||
} else if (v_1_17) {
|
||||
return entityID = readInt(0);
|
||||
@@ -105,23 +132,25 @@ public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstractio
|
||||
if (packet != null) {
|
||||
if (v_1_17) {
|
||||
writeInt(0, this.entityID = entityID);
|
||||
}
|
||||
else {
|
||||
this.entityIds = new int[] {entityID};
|
||||
} else {
|
||||
this.entityIds = new int[]{entityID};
|
||||
if (v_1_17_1) {
|
||||
IntList intArrayList = new IntArrayList(this.entityIds);
|
||||
write(IntList.class, 0, intArrayList);
|
||||
}
|
||||
else {
|
||||
Object intArrayList = null;
|
||||
try {
|
||||
intArrayList = INT_ARRAY_LIST_CONSTRUCTOR.newInstance(this.entityIds);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
write(INT_LIST_CLASS, 0, intArrayList);
|
||||
} else {
|
||||
writeIntArray(0, new int[]{this.entityIds[0]});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (v_1_17) {
|
||||
this.entityID = entityID;
|
||||
}
|
||||
else {
|
||||
this.entityIds = new int[] {entityID};
|
||||
} else {
|
||||
this.entityIds = new int[]{entityID};
|
||||
}
|
||||
}
|
||||
this.entity = null;
|
||||
@@ -130,19 +159,22 @@ public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstractio
|
||||
public int[] getEntityIds() {
|
||||
if (packet != null) {
|
||||
if (v_1_17) {
|
||||
return new int[] {getEntityId()};
|
||||
}
|
||||
else if (v_1_17_1) {
|
||||
return readObject(0, IntList.class).toIntArray();
|
||||
}
|
||||
else {
|
||||
return new int[]{getEntityId()};
|
||||
} else if (v_1_17_1) {
|
||||
Object list = readObject(0, INT_LIST_CLASS);
|
||||
try {
|
||||
return (int[]) TO_INT_ARRAY_METHOD.invoke(list);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return readIntArray(0);
|
||||
}
|
||||
} else {
|
||||
if (v_1_17) {
|
||||
return new int[] {entityID};
|
||||
}
|
||||
else {
|
||||
if (v_1_17) {
|
||||
return new int[]{entityID};
|
||||
} else {
|
||||
return entityIds;
|
||||
}
|
||||
}
|
||||
@@ -152,20 +184,21 @@ public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstractio
|
||||
if (packet != null) {
|
||||
if (v_1_17) {
|
||||
setEntityId(entityIds[0]);
|
||||
}
|
||||
else if (v_1_17_1) {
|
||||
IntList intList = new IntArrayList(entityIds);
|
||||
write(IntList.class, 0, intList);
|
||||
}
|
||||
else {
|
||||
} else if (v_1_17_1) {
|
||||
Object intArrayList = null;
|
||||
try {
|
||||
intArrayList = INT_ARRAY_LIST_CONSTRUCTOR.newInstance(entityIds);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
write(INT_LIST_CLASS, 0, intArrayList);
|
||||
} else {
|
||||
writeIntArray(0, entityIds);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (v_1_17) {
|
||||
this.entityID = entityIds[0];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.entityIds = entityIds;
|
||||
}
|
||||
}
|
||||
@@ -176,8 +209,7 @@ public class WrappedPacketOutEntityDestroy extends WrappedPacketEntityAbstractio
|
||||
public Object asNMSPacket() throws Exception {
|
||||
if (v_1_17) {
|
||||
return packetConstructor.newInstance(getEntityId());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return packetConstructor.newInstance(getEntityIds());
|
||||
}
|
||||
}
|
||||
|
||||
+37
-13
@@ -33,7 +33,7 @@ import java.lang.reflect.Constructor;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_7_10, v_1_17;
|
||||
private static boolean v_1_7_10, v_1_17, v_1_18_2;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int effectID;
|
||||
private int amplifier;
|
||||
@@ -104,6 +104,7 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
protected void load() {
|
||||
v_1_7_10 = version.isOlderThan(ServerVersion.v_1_8);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
v_1_18_2 = version.isNewerThanOrEquals(ServerVersion.v_1_18_2);
|
||||
try {
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_EFFECT.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
@@ -117,7 +118,12 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public int getEffectId() {
|
||||
if (packet != null) {
|
||||
return readByte(0);
|
||||
if (v_1_18_2) {
|
||||
return readInt(4);
|
||||
}
|
||||
else {
|
||||
return readByte(0);
|
||||
}
|
||||
} else {
|
||||
return effectID;
|
||||
}
|
||||
@@ -125,7 +131,12 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public void setEffectId(int effectID) {
|
||||
if (packet != null) {
|
||||
writeByte(0, (byte) effectID);
|
||||
if (v_1_18_2) {
|
||||
writeInt(4, effectID);
|
||||
}
|
||||
else {
|
||||
writeByte(0, (byte) effectID);
|
||||
}
|
||||
} else {
|
||||
this.effectID = effectID;
|
||||
}
|
||||
@@ -133,7 +144,7 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public int getAmplifier() {
|
||||
if (packet != null) {
|
||||
return readByte(1);
|
||||
return readByte(v_1_18_2 ? 0 : 1);
|
||||
} else {
|
||||
return amplifier;
|
||||
}
|
||||
@@ -141,7 +152,7 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public void setAmplifier(int amplifier) {
|
||||
if (packet != null) {
|
||||
writeByte(1, (byte) amplifier);
|
||||
writeByte(v_1_18_2 ? 0 : 1, (byte) amplifier);
|
||||
} else {
|
||||
this.amplifier = amplifier;
|
||||
}
|
||||
@@ -149,9 +160,16 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public int getDuration() {
|
||||
if (packet != null) {
|
||||
//1.7 and only 1.7
|
||||
if (v_1_7_10) {
|
||||
return readShort(1);
|
||||
} else {
|
||||
}
|
||||
//1.18.2+
|
||||
else if (v_1_18_2) {
|
||||
return readInt(5);
|
||||
}
|
||||
//1.17 - 1.8
|
||||
else {
|
||||
return readInt(v_1_17 ? 4 : 1);
|
||||
}
|
||||
} else {
|
||||
@@ -169,7 +187,11 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
duration = Short.MIN_VALUE;
|
||||
}
|
||||
writeShort(0, (short) duration);
|
||||
} else {
|
||||
}
|
||||
else if (v_1_18_2) {
|
||||
writeInt(5, duration);
|
||||
}
|
||||
else {
|
||||
writeInt(v_1_17 ? 4 : 1, duration);
|
||||
}
|
||||
} else {
|
||||
@@ -178,21 +200,21 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
}
|
||||
|
||||
private Optional<Byte> getByteMask() {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (packet != null && !byteMaskInitialized) {
|
||||
return Optional.of(byteMask = readByte(2));
|
||||
return Optional.of(byteMask = readByte(v_1_18_2 ? 1 : 2));
|
||||
} else {
|
||||
return Optional.of(byteMask);
|
||||
}
|
||||
}
|
||||
|
||||
private void setByteMask(byte byteMask) {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10)) {
|
||||
if (!v_1_7_10) {
|
||||
this.byteMask = byteMask;
|
||||
if (packet != null) {
|
||||
writeByte(2, byteMask);
|
||||
writeByte(v_1_18_2 ? 1 : 2, byteMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,8 +315,10 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
//Lazy, but smart way :)
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(PacketEvents.get().getByteBufUtil().newByteBuf(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
|
||||
//Lazy and stupid way
|
||||
//was size 12
|
||||
byte[] buffer = new byte[30];
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(PacketEvents.get().getByteBufUtil().newByteBuf(buffer));
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
} else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
|
||||
+8
-7
@@ -32,18 +32,19 @@ import java.lang.reflect.Constructor;
|
||||
public class WrappedPacketOutEntityHeadRotation extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private byte yaw;
|
||||
private static final float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
private float yaw;
|
||||
|
||||
public WrappedPacketOutEntityHeadRotation(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityHeadRotation(int entityID, byte yaw) {
|
||||
public WrappedPacketOutEntityHeadRotation(int entityID, float yaw) {
|
||||
this.entityID = entityID;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityHeadRotation(Entity entity, byte yaw) {
|
||||
public WrappedPacketOutEntityHeadRotation(Entity entity, float yaw) {
|
||||
this.entityID = entity.getEntityId();
|
||||
this.entity = entity;
|
||||
this.yaw = yaw;
|
||||
@@ -64,17 +65,17 @@ public class WrappedPacketOutEntityHeadRotation extends WrappedPacketEntityAbstr
|
||||
}
|
||||
}
|
||||
|
||||
public byte getYaw() {
|
||||
public float getYaw() {
|
||||
if (packet != null) {
|
||||
return readByte(0);
|
||||
return readByte(0) / ROTATION_FACTOR;
|
||||
} else {
|
||||
return yaw;
|
||||
}
|
||||
}
|
||||
|
||||
public void setYaw(byte yaw) {
|
||||
public void setYaw(float yaw) {
|
||||
if (packet != null) {
|
||||
writeByte(0, yaw);
|
||||
writeByte(0, (byte) (yaw * ROTATION_FACTOR));
|
||||
} else {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
+2
-1
@@ -54,6 +54,7 @@ public class WrappedPacketOutGameStateChange extends WrappedPacket implements Se
|
||||
@Override
|
||||
protected void load() {
|
||||
reasonClassType = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.GAME_STATE_CHANGE, 0);
|
||||
net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange gsc;
|
||||
if (reasonClassType != null) {
|
||||
try {
|
||||
reasonClassConstructor = reasonClassType.getConstructor(int.class);
|
||||
@@ -140,7 +141,7 @@ public class WrappedPacketOutGameStateChange extends WrappedPacket implements Se
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
if (reasonClassType == null) {
|
||||
if (reasonIntMode) {
|
||||
if (valueFloatMode) {
|
||||
return packetConstructor.newInstance(getReason(), (float) getValue());
|
||||
} else {
|
||||
|
||||
+8
-2
@@ -66,9 +66,12 @@ public class WrappedPacketOutRemoveEntityEffect extends WrappedPacketEntityAbstr
|
||||
|
||||
public int getEffectId() {
|
||||
if (packet != null) {
|
||||
//1.7 and 1.8
|
||||
if (v_1_8_x) {
|
||||
return readInt(1);
|
||||
} else {
|
||||
}
|
||||
//1.9+
|
||||
else {
|
||||
Object nmsMobEffectList = readObject(0, NMSUtils.mobEffectListClass);
|
||||
return NMSUtils.getEffectId(nmsMobEffectList);
|
||||
}
|
||||
@@ -80,9 +83,12 @@ public class WrappedPacketOutRemoveEntityEffect extends WrappedPacketEntityAbstr
|
||||
|
||||
public void setEffectId(int effectID) {
|
||||
if (packet != null) {
|
||||
//1.7 and 1.8
|
||||
if (v_1_8_x) {
|
||||
writeInt(1, effectID);
|
||||
} else {
|
||||
}
|
||||
//1.9+
|
||||
else {
|
||||
Object nmsMobEffectList = NMSUtils.getMobEffectListById(effectID);
|
||||
write(NMSUtils.mobEffectListClass, 0, nmsMobEffectList);
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ public class PacketEventsSettings {
|
||||
* @param compatInjector Value
|
||||
* @return Settings instance.
|
||||
*/
|
||||
@Deprecated
|
||||
public PacketEventsSettings compatInjector(boolean compatInjector) {
|
||||
if (!locked) {
|
||||
this.compatInjector = compatInjector;
|
||||
@@ -175,6 +176,7 @@ public class PacketEventsSettings {
|
||||
*
|
||||
* @return Getter for {@link #compatInjector}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean shouldUseCompatibilityInjector() {
|
||||
return compatInjector;
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class LowLevelUpdateCheckerLegacy implements LowLevelUpdateChecker {
|
||||
JsonObject jsonObject = parser.parse(jsonResponse).getAsJsonObject();
|
||||
String versionName = null;
|
||||
if (jsonObject != null) {
|
||||
versionName = jsonObject.get("tag_name").getAsString();
|
||||
versionName = jsonObject.get("name").getAsString();
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class LowLevelUpdateCheckerModern implements LowLevelUpdateChecker {
|
||||
JsonObject jsonObject = parser.parse(jsonResponse).getAsJsonObject();
|
||||
String versionName = null;
|
||||
if (jsonObject != null) {
|
||||
versionName = jsonObject.get("tag_name").getAsString();
|
||||
versionName = jsonObject.get("name").getAsString();
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
|
||||
@@ -18,12 +18,50 @@
|
||||
|
||||
package io.github.retrooper.packetevents.utils.geyser;
|
||||
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GeyserUtils {
|
||||
private static Class<?> GEYSER_CLASS;
|
||||
private static Class<?> GEYSER_API_CLASS;
|
||||
private static Method GEYSER_API_METHOD;
|
||||
private static Method CONNECTION_BY_UUID_METHOD;
|
||||
|
||||
public static boolean isGeyserPlayer(UUID uuid) {
|
||||
return GeyserConnector.getInstance().getPlayerByUuid(uuid) != null;
|
||||
if (GEYSER_CLASS == null) {
|
||||
GEYSER_CLASS = Reflection.getClassByNameWithoutException("org.geysermc.api.Geyser");
|
||||
}
|
||||
if (GEYSER_CLASS == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GEYSER_API_CLASS == null) {
|
||||
GEYSER_API_CLASS = Reflection.getClassByNameWithoutException("org.geysermc.api.GeyserApiBase");
|
||||
}
|
||||
if (GEYSER_API_METHOD == null) {
|
||||
GEYSER_API_METHOD = Reflection.getMethod(GEYSER_CLASS, "api", null, new Class<?>[]{});
|
||||
}
|
||||
if (CONNECTION_BY_UUID_METHOD == null) {
|
||||
CONNECTION_BY_UUID_METHOD = Reflection.getMethod(GEYSER_API_CLASS, "connectionByUuid", 0);
|
||||
}
|
||||
Object apiInstance = null;
|
||||
try {
|
||||
apiInstance = GEYSER_API_METHOD.invoke(null);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Object connection = null;
|
||||
try {
|
||||
if (apiInstance != null) {
|
||||
connection = CONNECTION_BY_UUID_METHOD.invoke(apiInstance, uuid);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connection != null;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class NPC {
|
||||
if (dist > 8) {
|
||||
sentPacket = new WrappedPacketOutEntityTeleport(entityID, position, yaw, pitch, onGround);
|
||||
} else {
|
||||
sentPacket = new WrappedPacketOutEntity.WrappedPacketOutRelEntityMoveLook(entityID, distX, distY, distZ, (byte) yaw, (byte) pitch, onGround);
|
||||
sentPacket = new WrappedPacketOutEntity.WrappedPacketOutRelEntityMoveLook(entityID, distX, distY, distZ, yaw, pitch, onGround);
|
||||
}
|
||||
if (hasSpawned(player)) {
|
||||
PacketEvents.get().getPlayerUtils().sendPacket(player, sentPacket);
|
||||
@@ -256,7 +256,7 @@ public class NPC {
|
||||
if (dist > 8) {
|
||||
sentPacket = new WrappedPacketOutEntityTeleport(entityID, position, yaw, pitch, onGround);
|
||||
} else {
|
||||
sentPacket = new WrappedPacketOutEntity.WrappedPacketOutRelEntityMoveLook(entityID, distX, distY, distZ, (byte) yaw, (byte) pitch, onGround);
|
||||
sentPacket = new WrappedPacketOutEntity.WrappedPacketOutRelEntityMoveLook(entityID, distX, distY, distZ, yaw, pitch, onGround);
|
||||
}
|
||||
for (Player player : players) {
|
||||
if (hasSpawned(player)) {
|
||||
@@ -290,7 +290,7 @@ public class NPC {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void moveDeltaAndRotate(List<Player> players, Vector3d deltaPosition, byte yaw, byte pitch) {
|
||||
public void moveDeltaAndRotate(List<Player> players, Vector3d deltaPosition, float yaw, float pitch) {
|
||||
this.position = this.position.add(deltaPosition);
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
|
||||
@@ -92,8 +92,10 @@ public enum ClientVersion {
|
||||
*/
|
||||
v_1_18(757),
|
||||
|
||||
v_1_18_2(758),
|
||||
|
||||
LOWER_THAN_SUPPORTED_VERSIONS(v_1_7_10.protocolVersion - 1),
|
||||
HIGHER_THAN_SUPPORTED_VERSIONS(v_1_18.protocolVersion + 1),
|
||||
HIGHER_THAN_SUPPORTED_VERSIONS(v_1_18_2.protocolVersion + 1),
|
||||
/**
|
||||
* Pre releases just aren't supported, we would end up with so many enum constants.
|
||||
* This constant assures you they are on a pre-release.
|
||||
@@ -112,7 +114,8 @@ public enum ClientVersion {
|
||||
|
||||
private static final Map<Integer, ClientVersion> CLIENT_VERSION_CACHE = new IdentityHashMap<>();
|
||||
private static final int[] CLIENT_VERSIONS = new int[]{5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338,
|
||||
340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757};
|
||||
340, 393, 401, 404, 477, 480, 485, 490, 498, 573,
|
||||
575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758};
|
||||
private int protocolVersion;
|
||||
|
||||
ClientVersion(int protocolVersion) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public enum ServerVersion {
|
||||
v_1_15(573), v_1_15_1(575), v_1_15_2(578),
|
||||
v_1_16(735), v_1_16_1(736), v_1_16_2(751), v_1_16_3(753), v_1_16_4(754), v_1_16_5(754),
|
||||
v_1_17(755), v_1_17_1(756),
|
||||
v_1_18(757), v_1_18_1(757),
|
||||
v_1_18(757), v_1_18_1(757), v_1_18_2(758),
|
||||
ERROR(-1);
|
||||
|
||||
private static final String NMS_VERSION_SUFFIX = Bukkit.getServer().getClass().getPackage().getName()
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
name: packetevents
|
||||
version: 1.8.2
|
||||
main: io.github.retrooper.packetevents.PacketEventsPlugin
|
||||
author: retrooper
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
- ProtocolSupport
|
||||
- ViaVersion
|
||||
- Geyser-Spigot
|
||||
Reference in new issue
Block a user