Compare commits

..
82 Commits
Author SHA1 Message Date
retrooper 825b61a24e Updated to 1.8.2 (Support latest ProtocolLib snapshots & supposed to support future 5.0.0 release of protocollib) 2022-03-08 19:23:30 +01:00
retrooper dc5d15ba85 We now support latest ProtocolLib snapshots. I'm sort of perplexed why this works, but seems like our initializer is wrapping itself somehow? Well it works 2022-03-08 19:20:14 +01:00
retrooper 0b458c2e4c Older versions of packetevents' update checker will break. We never followed version semantics till now. 2022-03-07 22:33:09 +01:00
retrooper bb9fe18a76 1.8.1 releasing. 2022-03-07 22:28:51 +01:00
retrooper 73420efbb7 Following semantic versioning. Release version: 1.8.0 2022-03-07 21:09:01 +01:00
retrooper c3bc1906b1 Merge remote-tracking branch 'origin/master' 2022-03-07 20:49:46 +01:00
retrooper 3c4a7323a0 Minor change to metrics. 2022-03-07 20:49:31 +01:00
retrooper 0a4fedff09 Finally releasing packetevents 1.8. 2022-03-07 20:42:41 +01:00
retrooper d1fb535ca7 WrappedPacketOutEntityEffect bug fix for 1.18.2 2022-03-05 17:43:43 +01:00
retrooper 5865e056d8 WrappedPacketOutEntity and WrappedPacketOutEntityHeadRotation now accept(support) floats for yaw and pitch, not that weird encoded byte angle.
NPC relative movement hopefully fixed.
2022-02-28 23:02:48 +01:00
retrooper eb561b98b2 Updated to 1.18.2. 2022-02-28 22:50:17 +01:00
retrooper 13b3ac7107 Bug fix in injecting players. 2022-02-04 19:22:58 +01:00
retrooper 1943ba2da1 Removed debug. 2022-02-04 15:22:03 +01:00
retrooper f90925e09b GeyserUtils fixed, now supports 2.0 Geyser API.
We now only inject into real socket channels.
2022-02-04 15:21:13 +01:00
retrooper e2ecb21892 Updated to Geyser 2.0 API 2022-02-02 21:33:39 +01:00
retrooper 80bc492370 Fixed broken ProtocolLib compatibility. 2022-01-31 21:30:14 +01:00
retrooper 691e8eb070 Little comment added 2022-01-21 22:48:58 +01:00
retrooper a83c3bac2a I know this isn't a perfect solution, but we want to process outgoing packets after ProtocolLib. So I went out of my way to for now only process the PLAY packets after them. We adjust our handler when protocollib is available.
PacketEventsSettings#compatInjector deprecated
2022-01-18 19:35:58 +01:00
retrooper 60a5357c34 PacketEvents v1.8 now sends the API Version to bStats. 2022-01-16 22:39:35 +01:00
retrooper af477f8479 Merge pull request #190 from retrooper/dev
1.18 support and more bug fixes merged to master branch
2022-01-06 12:40:29 +01:00
retrooper 6b82b38b59 Fixed javadocs and added plugin.yml to repository 2022-01-04 20:26:57 +01:00
retrooper 77918bb771 Minor change to a debug 2021-12-25 21:22:21 +01:00
retrooper c200b8fe35 1.8-pre-19 launching 2021-12-25 19:25:20 +01:00
DefineOutside 01cac8ded9 Merge pull request #177 from LIWKK/patch-30 2021-12-23 10:45:33 -06:00
Johannes d7a0d89d8e Fix WindowClick 1.9-1.16.5 2021-12-23 18:44:08 +02:00
retrooper 90ec7560b7 Merge remote-tracking branch 'origin/dev' into dev 2021-12-12 15:10:50 +01:00
retrooper eb96c5216b Fixed NMSUtils#getEffectId and NMSUtils#getMobEffectListById (Used in WrappedPacketOutRemoveEntityEffect) on 1.18 2021-12-12 15:10:34 +01:00
DefineOutside 176f2f7895 Merge remote-tracking branch 'origin/dev' into dev 2021-12-11 14:26:36 -06:00
DefineOutside 2489b7651b Fix 1.17.1+ support on set slot 2021-12-11 14:26:23 -06:00
retrooper 30981f8283 Merge remote-tracking branch 'origin/dev' into dev 2021-12-10 21:04:52 +01:00
retrooper 4537ac2d29 Added 1.18.1 support 2021-12-10 21:04:28 +01:00
retrooper 577d3476bb Merge pull request #171 from AlessioGr/master
Add Github actions to packetevents 1.8
2021-12-08 23:26:38 +01:00
DefineOutside 7adb2c2ecd Remove incorrect window click reflection to support 1.17 2021-12-07 16:33:23 -06:00
DefineOutside 1f02892284 1.17 support for the window click packet 2021-12-07 16:19:17 -06:00
DefineOutside 590e94ffc0 Add 1.17 support for the section position class 2021-12-06 17:16:20 -06:00
DefineOutside d5c2619bb3 Try fixing window items packet on 1.17.1 and 1.18 2021-12-06 17:15:05 -06:00
retrooper 935c9782a1 Fixed WrappedPacket#readGameMode and WrappedPacket#writeGameMode 2021-12-06 20:21:11 +01:00
retrooper 33b92f59d5 Small correction to WrappedPacket#writeAnyObject 2021-12-04 19:05:24 +01:00
MWHunter 6d7a06b93f Add support for SectionPosition in 1.18 2021-12-02 16:53:47 -06:00
MWHunter 0e42d7d14f Fix blockpos reflection on 1.18 2021-12-02 16:43:20 -06:00
Alessio Gravili 5cbdcc4158 JDK 8 2021-12-02 17:07:21 +01:00
Alessio Gravili db8f291475 Update gradle-publish.yml 2021-12-02 10:28:50 +01:00
Alessio Gravili 187084dca1 Update gradle-publish.yml 2021-12-02 10:26:52 +01:00
Alessio Gravili 316bc8070a Update gradle-publish.yml 2021-12-02 10:23:58 +01:00
Alessio Gravili 62685e9330 Create gradle-publish.yml 2021-12-02 10:22:58 +01:00
DefineOutside 169105af78 Update gradle-wrapper.properties 2021-12-01 10:44:51 -06:00
DefineOutside 398bb4b6db Update gradle-wrapper.properties 2021-12-01 10:43:56 -06:00
retrooper df56ea0aa6 Merge remote-tracking branch 'origin/dev' into dev 2021-12-01 17:25:32 +01:00
retrooper 95e73c775c Another minor bug fix in settings packet. 2021-12-01 17:25:23 +01:00
DefineOutside b8823ce00f Try fixing the map chunk packet for 1.18 2021-11-30 21:00:43 -06:00
DefineOutside 01658ce3c9 Add 1.18 support for WrappedPacketOutMapChunk 2021-11-30 18:29:57 -06:00
DefineOutside 934c181753 Support for reading 1.18 block positions 2021-11-30 17:11:20 -06:00
retrooper 0e3099e751 We should now work on 1.18 servers 2021-11-30 18:24:21 +01:00
retrooper 43ea7737ec Minor WrappedPacketInSettings change 2021-11-28 22:59:01 +01:00
retrooper 905dd43a0d Minor bug fix 2021-11-28 22:48:39 +01:00
retrooper 17f7c69b11 WrappedPacketInSettings updated to 1.18 2021-11-28 20:29:07 +01:00
retrooper 13965a4517 Added support for 1.18-rc3 2021-11-28 20:08:50 +01:00
retrooper 679d0ba037 One more minor change 2021-11-28 19:37:58 +01:00
retrooper 67e82e6d25 Merge remote-tracking branch 'origin/dev' 2021-11-28 19:32:55 +01:00
retrooper 9e58db6cb1 Minor optimizations by removing redundant/abandoned files;
ClientVersion and ServerVersion enums updated;
build.gradle optimized to remove unnecessary files;
2021-11-28 19:31:52 +01:00
retrooper e1fe2b9d99 Merge pull request #170 from byteful/unregister-listeners
Added methods to unregister PacketListenerAbstract(s).
2021-11-10 00:16:52 +01:00
byteful fd3b42ef6e Cleaned up the code a bit more. 2021-11-06 22:17:22 -05:00
byteful cf708adf55 Removed unnecessary code. 2021-11-06 22:03:36 -05:00
byteful 9f8a14b58a Added methods to unregister PacketListenerAbstract. 2021-11-06 21:39:55 -05:00
DefineOutside 1d31e06679 Merge pull request #169 from retrooper/MWHunter-patch-1
Try to fix build by updating geyser connector
2021-10-23 14:44:32 -05:00
DefineOutside a94e72ccd0 Revert to previous geyser api version 2021-10-23 14:37:34 -05:00
DefineOutside 35bd312ecf Try to fix build by updating geyser connector 2021-10-23 14:27:28 -05:00
DefineOutside 362d021745 Partially revert https://github.com/retrooper/packetevents/commit/5d1371c479c9811b87cc87a225063498654c96fe 2021-10-15 09:31:58 -05:00
DefineOutside 9d98af54e6 Data watcher takes NMS entity as argument, not bukkit entity 2021-10-13 20:30:07 -05:00
retrooper cb1438c86f Fixed WrappedPacketOutEntityVelocity#setVelocity 2021-10-10 18:23:45 +02:00
retrooper 75512add39 Fixed WrappedPacketOutWindowItems for 1.17.1 2021-10-09 20:40:43 +02:00
retrooper db1c913a3e Fixed WrappedPacketOutWindowItems for 1.17 2021-10-03 20:17:20 +02:00
DefineOutside 9c2609f4ee Vector3f should return Vector3f when cloned 2021-09-29 13:50:13 -05:00
DefineOutside 8336017bb9 Fix cloning vectors 2021-09-29 13:46:57 -05:00
retrooper 1ea4880ded Merge remote-tracking branch 'origin/dev' into dev 2021-09-26 15:52:26 +02:00
retrooper f54b8d7138 We now read the channel in network manager correctly 2021-09-26 15:52:19 +02:00
DefineOutside 52e7385864 Fix WrappedPacketOutSetCooldown 2021-09-24 22:20:09 -05:00
DefineOutside 5d1371c479 Optimize ServerVersion 2021-09-21 15:02:20 -05:00
DefineOutside 91916d0eaf Clean up WrappedPacketOutMapChunk 2021-09-20 16:44:53 -05:00
DefineOutside 73505209bc Use bitsets for WrappedPacketOutMapChunk 2021-09-20 16:35:49 -05:00
DefineOutside 934d5378e5 If a version lookup failed, try to resolve the client version again 2021-09-15 23:37:04 -05:00
retrooper 0595fb6e03 Merge pull request #160 from retrooper/dev
Update master branch to a more stable build of PacketEvents.
2021-08-31 20:33:11 +02:00
56 changed files with 714 additions and 613 deletions

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
name: Gradle Package
on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Gradle
run: gradle :clean :build
- name: Upload build artifacts
uses: actions/upload-artifact@v1
with:
name: packetevents-dev-build.jar
path: build/libs
+1 -1
View File
@@ -21,7 +21,7 @@ Our discord server has a role for contributors and forkers.
[![](https://www.ej-technologies.com/images/product_banners/jprofiler_small.png)](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.
+4 -13
View File
@@ -49,33 +49,24 @@ 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.2.1-SNAPSHOT'
compileOnly 'com.viaversion:viaversion-api:4.0.1'
compileOnly 'com.github.ProtocolSupport:ProtocolSupport:3d24efeda6'
/*compileOnly 'org.github.spigot:1.16.2:1.16.2'
compileOnly 'org.github.spigot:1.8.8:1.8.8'
compileOnly 'org.github.spigot:1.7.10:1.7.10'*/
compileOnly 'org.github.spigot:1.16.2:1.16.2'
compileOnly 'org.github.spigot:1.13.2:1.13.2'
compileOnly 'org.github.spigot:1.13:1.13'
compileOnly 'org.github.spigot:1.12.2:1.12.2'
compileOnly 'org.github.spigot:1.9.4:1.9.4'
compileOnly 'org.github.spigot:1.9:1.9'
compileOnly 'org.github.spigot:1.8.8:1.8.8'
compileOnly 'org.github.spigot:1.7.10:1.7.10'
}
group = 'io.github.retrooper'
version = '1.8-pre-18'
version = '1.8.2'
description = 'packetevents'
java.sourceCompatibility = JavaVersion.VERSION_1_8
@@ -89,4 +80,4 @@ publishing {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
@@ -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, 18);
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.
@@ -27,7 +27,7 @@ public class PacketEventsPlugin extends JavaPlugin {
public void onLoad() {
PacketEventsSettings settings = PacketEvents.create(this).getSettings();
settings
.fallbackServerVersion(ServerVersion.v_1_7_10)
.fallbackServerVersion(ServerVersion.getLatest())
.compatInjector(false)
.checkForUpdates(true)
.bStats(true);
@@ -156,6 +156,30 @@ public interface EventManager {
return this;
}
/**
* Unregister a PacketListenerAbstract listener.
*
* @param listener {@link PacketListenerAbstract}
* @return Same event manager instance.
*/
default EventManager unregisterListener(PacketListenerAbstract listener) {
if (listener != null) {
PEEventManager.EVENT_MANAGER_MODERN.unregisterListener(listener);
}
return this;
}
/**
* Unregister multiple PacketListenerAbstract listeners.
*
* @param listeners {@link PacketListenerAbstract}
* @return Same event manager instance.
*/
default EventManager unregisterListeners(PacketListenerAbstract... listeners) {
PEEventManager.EVENT_MANAGER_MODERN.unregisterListeners(listeners);
return this;
}
/**
* Unregister all registered event listeners.
* All the deprecated and the dynamic listeners will be unregistered.
@@ -94,6 +94,30 @@ class EventManagerModern {
}
}
/**
* Unregister the dynamic packet event listener.
*
* @param listener {@link PacketListenerAbstract}
*/
public synchronized void unregisterListener(final PacketListenerAbstract listener) {
byte priority = listener.getPriority().getId();
HashSet<PacketListenerAbstract> listenerSet = listenersMap.get(priority);
if (listenerSet != null) {
listenerSet.remove(listener);
}
}
/**
* Unregister multiple dynamic packet event listeners with one method.
*
* @param listeners {@link PacketListenerAbstract}
*/
public synchronized void unregisterListeners(PacketListenerAbstract... listeners) {
for (PacketListenerAbstract listener : listeners) {
unregisterListener(listener);
}
}
/**
* Unregister all dynamic packet event listeners.
*/
@@ -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.
@@ -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;
@@ -125,9 +127,11 @@ public class EarlyChannelInjectorLegacy implements EarlyInjector {
List<Object> networkManagers = NMSUtils.getNetworkManagers();
synchronized (networkManagers) {
for (Object networkManager : networkManagers) {
WrappedPacket networkManagerWrapper = new WrappedPacket(new NMSPacket(networkManager));
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;
}
@@ -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);
}
}
}
}
@@ -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
@@ -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.
@@ -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);
@@ -128,9 +130,11 @@ public class EarlyChannelInjectorModern implements EarlyInjector {
List<Object> networkManagers = NMSUtils.getNetworkManagers();
synchronized (networkManagers) {
for (Object networkManager : networkManagers) {
WrappedPacket networkManagerWrapper = new WrappedPacket(new NMSPacket(networkManager));
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();
@@ -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);
}
}
}
}
@@ -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;
}
}
}
@@ -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
@@ -39,6 +39,7 @@ public class PacketType {
*/
public static final byte INVALID = -128;
public static final Map<Class<?>, Byte> packetIDMap = new IdentityHashMap<>();
private static final boolean isNine = ServerVersion.getVersion().isNewerThanOrEquals(ServerVersion.v_1_9);
private static void insertPacketID(Class<?> cls, byte packetID) {
if (cls != null) {
@@ -286,10 +287,7 @@ public class PacketType {
* @return Has the client placed a block?
*/
public static boolean isBlockPlace(final byte packetID) {
final ServerVersion version = PacketEvents.get().getServerUtils().getVersion();
return version.isNewerThan(ServerVersion.v_1_8_8) ?
packetID == PacketType.Play.Client.USE_ITEM
: packetID == PacketType.Play.Client.BLOCK_PLACE;
return isNine ? packetID == PacketType.Play.Client.USE_ITEM : packetID == PacketType.Play.Client.BLOCK_PLACE;
}
}
}
@@ -399,8 +399,12 @@ public class PacketTypeClasses {
SET_SUBTITLE_TEXT = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetSubtitleTextPacket");
SET_TITLES_ANIMATION = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetTitlesAnimationPacket");
SET_TITLE_TEXT = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetTitleTextPacket");
// 1.18+ only, doesn't follow the naming convention
if (MAP_CHUNK == null) {
MAP_CHUNK = Reflection.getClassByNameWithoutException("net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket");
}
}
}
}
}
@@ -34,6 +34,7 @@ import io.github.retrooper.packetevents.utils.vector.Vector3i;
import io.github.retrooper.packetevents.utils.world.Difficulty;
import io.github.retrooper.packetevents.utils.world.Dimension;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -50,7 +51,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
private static final Map<Class<? extends WrappedPacket>, Boolean> LOADED_WRAPPERS = new ConcurrentHashMap<>();
private static final Map<Class<?>, Map<Class<?>, Field[]>> FIELD_CACHE = new ConcurrentHashMap<>();
private static final Field[] EMPTY_FIELD_ARRAY = new Field[0];
@@ -383,6 +383,9 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
public void writeAnyObject(int index, Object value) {
try {
Field f = packetClass.getDeclaredFields()[index];
if (!f.isAccessible()) {
f.setAccessible(true);
}
f.set(packet.getRawNMSPacket(), value);
} catch (Exception e) {
throw new WrapperFieldNotFoundException("PacketEvents failed to find any field indexed " + index + " in the " + ClassUtil.getClassSimpleName(packetClass) + " class!");
@@ -393,8 +396,7 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
public void writeEnumConstant(int index, Enum<?> enumConstant) {
try {
write(enumConstant.getClass(), index, enumConstant);
}
catch (WrapperFieldNotFoundException ex) {
} catch (WrapperFieldNotFoundException ex) {
write(enumConstant.getDeclaringClass(), index, enumConstant);
}
}
@@ -414,9 +416,22 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
public Vector3i readBlockPosition(int index) {
Object blockPosObj = readObject(index, NMSUtils.blockPosClass);
try {
int x = (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
int y = (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
int z = (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
int x = (Integer) NMSUtils.getBlockPosX.invoke(blockPosObj);
int y = (Integer) NMSUtils.getBlockPosY.invoke(blockPosObj);
int z = (Integer) NMSUtils.getBlockPosZ.invoke(blockPosObj);
return new Vector3i(x, y, z);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
public Vector3i readSectionPosition(int index) {
Object blockPosObj = readObject(index, NMSUtils.sectionPositionClass);
try {
int x = (Integer) NMSUtils.getBlockPosX.invoke(blockPosObj);
int y = (Integer) NMSUtils.getBlockPosY.invoke(blockPosObj);
int z = (Integer) NMSUtils.getBlockPosZ.invoke(blockPosObj);
return new Vector3i(x, y, z);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
@@ -439,13 +454,19 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
write(NMSUtils.nmsItemStackClass, index, nmsItemStack);
}
@Nullable
public GameMode readGameMode(int index) {
Enum<?> enumConst = readEnumConstant(index, NMSUtils.enumGameModeClass);
return GameMode.values()[enumConst.ordinal() - 1];
int targetIndex = enumConst.ordinal() - 1;
if (targetIndex == -1) {
return null;
}
return GameMode.values()[targetIndex];
}
public void writeGameMode(int index, GameMode gameMode) {
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumGameModeClass, gameMode.ordinal() + 1);
public void writeGameMode(int index, @Nullable GameMode gameMode) {
int i = gameMode != null ? (gameMode.ordinal() + 1) : (0);
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumGameModeClass, i);
writeEnumConstant(index, enumConst);
}
@@ -37,9 +37,8 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
@Override
protected void load() {
v_1_16 = version.isNewerThanOrEquals(ServerVersion.v_1_16);
try {
enumClientCommandClass = NMSUtils.getNMSEnumClass("EnumClientCommand");
} catch (ClassNotFoundException e) {
enumClientCommandClass = NMSUtils.getNMSEnumClassWithoutException("EnumClientCommand");
if (enumClientCommandClass == null) {
//Probably a subclass
enumClientCommandClass = SubclassUtil.getEnumSubClass(PacketTypeClasses.Play.Client.CLIENT_COMMAND, "EnumClientCommand");
}
@@ -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 {
@@ -32,7 +32,7 @@ import java.util.Set;
public class WrappedPacketInSettings extends WrappedPacket {
private static Class<? extends Enum<?>> chatVisibilityEnumClass;
private static boolean isLowerThan_v_1_8, v_1_17;
private static boolean isLowerThan_v_1_8, v_1_17, v_1_18;
public WrappedPacketInSettings(final NMSPacket packet) {
super(packet);
@@ -42,6 +42,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
protected void load() {
isLowerThan_v_1_8 = version.isOlderThan(ServerVersion.v_1_8);
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
v_1_18 = version.isNewerThanOrEquals(ServerVersion.v_1_18);
chatVisibilityEnumClass = NMSUtils.getNMSEnumClassWithoutException("EnumChatVisibility");
if (chatVisibilityEnumClass == null) {
//They are on 1.17+
@@ -62,11 +63,11 @@ public class WrappedPacketInSettings extends WrappedPacket {
}
public int getViewDistance() {
return readInt(v_1_17 ? 1 : 0);
return readInt((v_1_17 && !v_1_18) ? 1 : 0);
}
public void setViewDistance(int viewDistance) {
writeInt(v_1_17 ? 1 : 0, viewDistance);
writeInt((v_1_17 && !v_1_18) ? 1 : 0, viewDistance);
}
public ChatVisibility getChatVisibility() {
@@ -87,19 +88,37 @@ public class WrappedPacketInSettings extends WrappedPacket {
writeBoolean(0, chatColors);
}
public Optional<Boolean> isTextFilteringEnabled() {
if (!v_1_17) {
return Optional.empty();
//Added in 1.17
public boolean isTextFilteringEnabled() {
if (v_1_17) {
return readBoolean(1);
}
return Optional.of(!readBoolean(1));
return false;
}
public void setTextFilteringEnabled(boolean textFilteringEnabled) {
//Added in 1.17
public void setTextFilteringEnabled(boolean enabled) {
if (v_1_17) {
writeBoolean(1, !textFilteringEnabled);
writeBoolean(1, enabled);
}
}
//Added in 1.18
public boolean isServerListingsAllowed() {
if (v_1_18) {
return readBoolean(2);
}
return true;
}
//Added in 1.18
public void setServerListingsAllowed(boolean allowed) {
if (v_1_18) {
writeBoolean(2, allowed);
}
}
public byte getDisplaySkinPartsMask() {
byte mask = 0;
if (isLowerThan_v_1_8) {
@@ -108,7 +127,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
mask |= 0x01;
}
} else {
mask = (byte) readInt(v_1_17 ? 2 : 1);
mask = (byte) readInt((v_1_17 && !v_1_18) ? 2 : 1);
}
return mask;
}
@@ -118,7 +137,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
boolean capeEnabled = (mask & 0x01) == 0x01;
writeBoolean(1, capeEnabled);
} else {
writeInt(v_1_17 ? 2 : 1, mask);
writeInt((v_1_17 && !v_1_18) ? 2 : 1, mask);
}
}
@@ -133,11 +133,12 @@ public final class WrappedPacketInUseEntity extends WrappedPacketEntityAbstracti
return action;
}
//TODO Finish this
protected void setAction(EntityUseAction action) {
this.action = action;
Enum<?> enumConst = EnumUtil.valueByIndex((Class<? extends Enum<?>>) enumEntityUseActionClass, action.ordinal());
if (v_1_17) {
//TODO Add 1.17 support
//TODO Add 1.17+ support
}
else {
writeEnumConstant(0, enumConst);
@@ -37,7 +37,6 @@ public class WrappedPacketInVehicleMove extends WrappedPacket {
writeDouble(2, position.z);
}
//TODO Cut off at 1.8.1
@Deprecated
public double getX() {
return readDouble(0);
@@ -18,25 +18,16 @@
package io.github.retrooper.packetevents.packetwrappers.play.in.windowclick;
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.utils.enums.EnumUtil;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.reflection.Reflection;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
public class WrappedPacketInWindowClick extends WrappedPacket {
private static boolean v_1_17;
private static boolean legacy, v_1_17;
private static Class<? extends Enum<?>> invClickTypeClass;
private static boolean isClickModePrimitive;
public WrappedPacketInWindowClick(NMSPacket packet) {
super(packet);
@@ -44,53 +35,60 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
@Override
protected void load() {
legacy = version.isOlderThanOrEquals(ServerVersion.v_1_8_8);
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
invClickTypeClass = NMSUtils.getNMSEnumClassWithoutException("InventoryClickType");
if (invClickTypeClass == null) {
invClickTypeClass = NMSUtils.getNMEnumClassWithoutException("world.inventory.InventoryClickType");
}
isClickModePrimitive = Reflection.getField(PacketTypeClasses.Play.Client.WINDOW_CLICK, int.class, 3) != null;
}
// Unique ID for the inventory, 0 for player's inventory
public int getWindowId() {
return readInt(0);
return readInt(v_1_17 ? 1 : 0);
}
public void setWindowId(int windowID) {
writeInt(0, windowID);
writeInt(v_1_17 ? 1 : 0, windowID);
}
// Id of clicked slot
public int getWindowSlot() {
return readInt(1);
return readInt(v_1_17 ? 3 : 1);
}
public void setWindowSlot(int slot) {
writeInt(1, slot);
writeInt(v_1_17 ? 3 : 1, slot);
}
// Left or right click
public int getWindowButton() {
return readInt(2);
return readInt(v_1_17 ? 4 : 2);
}
public void setWindowButton(int button) {
writeInt(2, button);
writeInt(v_1_17 ? 4 : 2, button);
}
public Optional<Short> getActionNumber() {
// Used to sync together client and server
public int getActionNumber() {
if (v_1_17) {
return Optional.empty();
return readInt(2);
}
return Optional.of(readShort(0));
return readShort(0);
}
public void setActionNumber(short actionNumber) {
if (!v_1_17) {
writeShort(0, actionNumber);
public void setActionNumber(int actionNumber) {
if (v_1_17) {
writeInt(2, actionNumber);
} else {
writeShort(0, (short) actionNumber);
}
}
// Type of click - shift clicking, hotbar, drag, pickup...
public int getMode() {
if (isClickModePrimitive) {
if(legacy) {
return readInt(3);
} else {
Enum<?> enumConst = readEnumConstant(0, invClickTypeClass);
@@ -99,7 +97,7 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
}
public void setMode(int mode) {
if (isClickModePrimitive) {
if(legacy) {
writeInt(3, mode);
} else {
Enum<?> enumConst = EnumUtil.valueByIndex(invClickTypeClass, mode);
@@ -117,6 +115,6 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
}
public void setClickedItemStack(ItemStack stack) {
writeItemStack(0, stack);
writeItemStack(0, stack);
}
}
@@ -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;
@@ -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 {
@@ -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();
@@ -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());
}
}
@@ -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();
@@ -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;
}
@@ -84,9 +84,9 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacketEntityAbs
public void setVelocity(Vector3d velocity) {
if (packet != null) {
writeInt(1, (int) (velocity.x));
writeInt(2, (int) (velocity.y));
writeInt(3, (int) (velocity.z));
writeInt(1, (int) (velocity.x * 8000.0));
writeInt(2, (int) (velocity.y * 8000.0));
writeInt(3, (int) (velocity.z * 8000.0));
}
else {
this.velocityX = velocity.x;
@@ -95,7 +95,6 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacketEntityAbs
}
}
//TODO Cut off at 1.8.1 and optimize the methods above.
@Deprecated
public double getVelocityX() {
if (packet != null) {
@@ -238,7 +238,6 @@ public class WrappedPacketOutExplosion extends WrappedPacket implements Sendable
}
}
//TODO Cut off at 1.8.1, and once you cut off, you can optimize the methods above. Also optimize the position part.
@Deprecated
public float getPlayerMotionX() {
if (packet != null) {
@@ -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 {
@@ -21,6 +21,7 @@ package io.github.retrooper.packetevents.packetwrappers.play.out.mapchunk;
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.utils.reflection.Reflection;
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
@@ -31,8 +32,8 @@ import java.util.Optional;
//TODO finish wrapper
public class WrappedPacketOutMapChunk extends WrappedPacket {
private static boolean v_1_8_x, v_1_17;
private static Class<?> chunkMapClass;
private static boolean v_1_8_x, v_1_17, v_1_18;
private static Class<?> chunkMapClass, chunkPacketDataClass;
private Constructor<?> chunkMapConstructor;
private Object nmsChunkMap;
@@ -44,6 +45,7 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
protected void load() {
v_1_8_x = version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9);
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
v_1_18 = version.isNewerThanOrEquals(ServerVersion.v_1_18);
if (v_1_8_x) {
chunkMapClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.MAP_CHUNK, 0);
try {
@@ -52,69 +54,68 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
e.printStackTrace();
}
}
chunkPacketDataClass = Reflection.getClassByNameWithoutException("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData");
}
public int getChunkX() {
return readInt(v_1_17 ? 1 : 0);
return readInt(v_1_17 && !v_1_18 ? 1 : 0);
}
public void setChunkX(int chunkX) {
writeInt(v_1_17 ? 1: 0, chunkX);
writeInt(v_1_17 && !v_1_18 ? 1 : 0, chunkX);
}
public int getChunkZ() {
return readInt(v_1_17 ? 2: 1);
return readInt(v_1_17 && !v_1_18 ? 2 : 1);
}
public void setChunkZ(int chunkZ) {
writeInt(v_1_17 ? 2: 1, chunkZ);
writeInt(v_1_17 && !v_1_18 ? 2 : 1, chunkZ);
}
public Optional<BitSet> getPrimaryBitMaskBitSet() {
public Optional<BitSet> getBitSet() {
if (v_1_18) { // Bitsets were removed in 1.18
return Optional.empty();
}
if (v_1_17) {
return Optional.of(readObject(0, BitSet.class));
}
else {
return Optional.empty();
}
}
public void setPrimaryBitMaskBitSet(BitSet bitMaskBitSet) {
if (v_1_17) {
writeObject(0, bitMaskBitSet);
}
}
@Deprecated
public Optional<Integer> getPrimaryBitMap() {
return getPrimaryBitMask();
}
@Deprecated
public void setPrimaryBitMap(int primaryBitMask) {
setPrimaryBitMask(primaryBitMask);
}
public Optional<Integer> getPrimaryBitMask() {
if (v_1_17) {
long[] bitset = readObject(0, BitSet.class).toLongArray();
return Optional.of(bitset.length == 0 ? 0 : (int) bitset[0]);
}
if (v_1_8_x) {
if (nmsChunkMap == null) {
nmsChunkMap = readObject(0, chunkMapClass);
}
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
return Optional.of(nmsChunkMapWrapper.readInt(0));
return Optional.of(BitSet.valueOf(new long[]{nmsChunkMapWrapper.readInt(0)}));
} else {
return Optional.of(readInt(2));
return Optional.of(BitSet.valueOf(new long[]{readInt(2)}));
}
}
public void setPrimaryBitMask(int primaryBitMask) {
/**
* @param bitSet Bitset that can hold multiple integer values to support the expanded world height on
* 1.17 and newer servers. This is due to 1.17 needing to support up to 127 chunk sections
* (2032 blocks) and an integer only being able to hold 32 bits to represent 32 chunk sections
*/
public void setPrimaryBitMask(BitSet bitSet) {
if (v_1_18) return; // Bitsets were removed in 1.18
if (v_1_17) {
writeObject(0, BitSet.valueOf(new long[] {primaryBitMask}));
writeObject(0, bitSet);
return;
}
setPrimaryBitMask((int) bitSet.toLongArray()[0]);
}
/**
* @param primaryBitMask Integer that determines which chunk sections the server is sending
* @deprecated Possible lossy conversion on 1.17 servers that could result in the client only reading 32
* out of the total possible 127 chunk sections. Safe to use on 1.16 and below servers
*/
@Deprecated
public void setPrimaryBitMask(int primaryBitMask) {
if (v_1_18) return; // Bitsets were removed in 1.18
if (v_1_17) {
writeObject(0, BitSet.valueOf(new long[]{primaryBitMask}));
return;
}
if (v_1_8_x) {
@@ -134,7 +135,9 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
}
}
//TODO Confirm if 1.17 support is possible
/**
* @return Whether the packet overwrites the entire chunk column or just the sections being sent
*/
public Optional<Boolean> isGroundUpContinuous() {
if (v_1_17) {
return Optional.empty();
@@ -142,7 +145,9 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
return Optional.of(readBoolean(0));
}
//TODO Confirm if 1.17 support is possible
/**
* @param groundUpContinuous Whether the packet overwrites the entire chunk column or just the sections being sent
*/
public void setGroundUpContinuous(boolean groundUpContinuous) {
if (v_1_17) {
return;
@@ -157,6 +162,8 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
}
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
return nmsChunkMapWrapper.readByteArray(0);
} else if (v_1_18) {
return new WrappedPacket(new NMSPacket(readObject(0, chunkPacketDataClass))).readByteArray(0);
} else {
return readByteArray(0);
}
@@ -174,6 +181,8 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
nmsChunkMapWrapper.writeByteArray(0, data);
write(chunkMapClass, 0, nmsChunkMap);
} else if (v_1_18) {
new WrappedPacket(new NMSPacket(readObject(0, chunkPacketDataClass))).writeByteArray(0, data);
} else {
writeByteArray(0, data);
}
@@ -1,43 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper 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.packetwrappers.play.out.multiblockchange;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
//TODO finish this wrapper
class WrappedPacketOutMultiBlockChange extends WrappedPacket {
public WrappedPacketOutMultiBlockChange(NMSPacket packet) {
super(packet);
}
@Override
protected void load() {
net.minecraft.server.v1_7_R4.PacketPlayOutMultiBlockChange a0;
net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange a1;
net.minecraft.server.v1_9_R1.PacketPlayOutMultiBlockChange a2;
net.minecraft.server.v1_9_R2.PacketPlayOutMultiBlockChange a3;
net.minecraft.server.v1_12_R1.PacketPlayOutMultiBlockChange a4;
net.minecraft.server.v1_13_R1.PacketPlayOutMultiBlockChange a5;
net.minecraft.server.v1_13_R2.PacketPlayOutMultiBlockChange a6;
net.minecraft.server.v1_16_R2.PacketPlayOutMultiBlockChange a7;
}
}
@@ -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);
}
@@ -1,107 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper 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.packetwrappers.play.out.scoreboardteam;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.utils.enums.EnumUtil;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import org.bukkit.ChatColor;
//TODO FINISH WRAPPER
class WrappedPacketOutScoreboardTeam extends WrappedPacket {
private static Class<? extends Enum<?>> enumChatFormat;
public WrappedPacketOutScoreboardTeam(NMSPacket packet) {
super(packet);
}
@Override
protected void load() {
enumChatFormat = NMSUtils.getNMSEnumClassWithoutException("EnumChatFormat");
if (enumChatFormat == null) {
enumChatFormat= NMSUtils.getNMEnumClassWithoutException("EnumChatFormat");
}
net.minecraft.server.v1_7_R4.PacketPlayOutScoreboardTeam a0;
net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardTeam a1;
net.minecraft.server.v1_9_R1.PacketPlayOutScoreboardTeam a2;
net.minecraft.server.v1_9_R2.PacketPlayOutScoreboardTeam a3;
net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam a4;
net.minecraft.server.v1_13_R1.PacketPlayOutScoreboardTeam a5;
net.minecraft.server.v1_13_R2.PacketPlayOutScoreboardTeam a6;
net.minecraft.server.v1_16_R2.PacketPlayOutScoreboardTeam a7;
//Add 1.17 support, its very diff
//net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam a8;
}
public String getTeamName() {
return readString(0);
}
public void setTeamName(String name) {
writeString(0, name);
}
public String getTeamPrefix() {
if (version.isNewerThanOrEquals(ServerVersion.v_1_13)) {
return readIChatBaseComponent(0);
}
else {
return readString(1);
}
}
public void setTeamPrefix(String teamPrefix) {
if (version.isNewerThanOrEquals(ServerVersion.v_1_13)) {
writeIChatBaseComponent(0, teamPrefix);
}
else {
writeString(1, teamPrefix);
}
}
public String getTeamSuffix() {
if (version.isNewerThanOrEquals(ServerVersion.v_1_13)) {
return readIChatBaseComponent(1);
}
else {
return readString(2);
}
}
public void setTeamSuffix(String teamSuffix) {
if (version.isNewerThanOrEquals(ServerVersion.v_1_13)) {
writeIChatBaseComponent(1, teamSuffix);
}
else {
writeString(2, teamSuffix);
}
}
public ChatColor getTeamColor() {
Enum<?> enumChatFormatConstant = readEnumConstant(0, enumChatFormat);
return ChatColor.values()[enumChatFormatConstant.ordinal()];
}
public void setTeamColor(ChatColor color) {
Enum<?> enumChatFormatConstant = EnumUtil.valueByIndex(enumChatFormat, color.ordinal());
writeEnumConstant(0, enumChatFormatConstant);
}
}
@@ -19,33 +19,33 @@
package io.github.retrooper.packetevents.packetwrappers.play.out.setcooldown;
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.packetwrappers.api.SendableWrapper;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import org.bukkit.entity.EntityType;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Constructor;
import java.util.IdentityHashMap;
import java.util.Map;
import java.lang.reflect.InvocationTargetException;
//TODO TEST
public class WrappedPacketOutSetCooldown extends WrappedPacket implements SendableWrapper {
private static final Map<Short, EntityType> ID_MAP = new IdentityHashMap<>();
private static Constructor<?> packetConstructor;
private EntityType type;
private Object nmsItem;
private int cooldownTicks;
public WrappedPacketOutSetCooldown(EntityType type, int cooldownTicks) {
this.type = type;
public WrappedPacketOutSetCooldown(NMSPacket packet) {
super(packet);
}
public WrappedPacketOutSetCooldown(Object nmsItem, int cooldownTicks) {
this.nmsItem = nmsItem;
this.cooldownTicks = cooldownTicks;
}
@Override
protected void load() {
for (EntityType type : EntityType.values()) {
ID_MAP.put(type.getTypeId(), type);
}
try {
packetConstructor = PacketTypeClasses.Play.Server.SET_COOLDOWN.getConstructor(NMSUtils.nmsItemClass, int.class);
} catch (NoSuchMethodException e) {
@@ -53,23 +53,38 @@ public class WrappedPacketOutSetCooldown extends WrappedPacket implements Sendab
}
}
public EntityType getType() {
if (packet != null) {
@Override
public boolean isSupported() {
return version.isNewerThan(ServerVersion.v_1_8_8);
}
public ItemStack getItemStack() {
try {
Object nmsItem = readObject(0, NMSUtils.nmsItemClass);
short nmsItemID = (short) NMSUtils.getNMSItemId(nmsItem);
return ID_MAP.get(nmsItemID);
Object nmsItemStack = NMSUtils.itemStackConstructor.newInstance(nmsItem);
return NMSUtils.toBukkitItemStack(nmsItemStack);
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
return new ItemStack(Material.AIR);
}
public Object getNmsItem() {
return nmsItem;
}
public void setNMSItemStack(Object type) {
if (packet != null) {
write(NMSUtils.nmsItemClass, 0, type);
} else {
return type;
this.nmsItem = type;
}
}
public void setType(EntityType type) {
if (packet != null) {
Object nmsItem = NMSUtils.getNMSItemById(type.getTypeId());
write(NMSUtils.nmsItemClass, 0, nmsItem);
} else {
this.type = type;
}
@Override
public Object asNMSPacket() throws Exception {
return packetConstructor.newInstance(nmsItem, getCooldownTicks());
}
public int getCooldownTicks() {
@@ -87,15 +102,4 @@ public class WrappedPacketOutSetCooldown extends WrappedPacket implements Sendab
this.cooldownTicks = cooldownTicks;
}
}
@Override
public boolean isSupported() {
return version.isNewerThan(ServerVersion.v_1_8_8);
}
@Override
public Object asNMSPacket() throws Exception {
Object nmsItem = NMSUtils.getNMSItemById(getType().getTypeId());
return packetConstructor.newInstance(nmsItem, getCooldownTicks());
}
}
@@ -80,7 +80,7 @@ public class WrappedPacketOutSetSlot extends WrappedPacket implements SendableWr
public int getWindowId() {
if (packet != null) {
int index = v_1_17_1 ? 3 : v_1_17 ? 2 : 0;
int index = v_1_17 ? 2 : 0;
return readInt(index);
} else {
return windowID;
@@ -89,7 +89,7 @@ public class WrappedPacketOutSetSlot extends WrappedPacket implements SendableWr
public void setWindowId(int windowID) {
if (packet != null) {
int index = v_1_17_1 ? 3 : v_1_17 ? 2 : 0;
int index = v_1_17 ? 2 : 0;
writeInt(index, windowID);
} else {
this.windowID = windowID;
@@ -23,7 +23,6 @@ import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.packetwrappers.api.SendableWrapper;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.reflection.Reflection;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import org.bukkit.inventory.ItemStack;
@@ -31,36 +30,49 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
//TODO Test wrapper
public class WrappedPacketOutWindowItems extends WrappedPacket implements SendableWrapper {
private static boolean v_1_17;
private static boolean v_1_17, v_1_17_1;
private static Object nonNullListInstance;
private static Class<?> nonNullListClass;
private static Constructor<?> packetConstructor;
private int windowID;
private int stateID;
private List<ItemStack> slotData;
private ItemStack heldItem;
public WrappedPacketOutWindowItems(NMSPacket packet) {
super(packet);
}
public WrappedPacketOutWindowItems(int windowID, List<ItemStack> slots) {
public WrappedPacketOutWindowItems(int windowID, int stateID, List<ItemStack> slots, ItemStack heldItem) {
this.windowID = windowID;
this.stateID = stateID;
this.slotData = slots;
this.heldItem = heldItem;
}
@Override
protected void load() {
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
v_1_17_1 = version.isNewerThanOrEquals(ServerVersion.v_1_17_1);
try {
if (v_1_17) {
nonNullListClass = NMSUtils.getNMClassWithoutException("core.NonNullList");
Constructor<?> nonNullListConstructor = nonNullListClass.getConstructor();
nonNullListConstructor.setAccessible(true);
nonNullListInstance = nonNullListConstructor.newInstance();
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor(int.class, nonNullListClass);
}
else {
if (v_1_17_1) {
Constructor<?> nonNullListConstructor = nonNullListClass.getDeclaredConstructors()[0];
nonNullListConstructor.setAccessible(true);
nonNullListInstance = nonNullListConstructor.newInstance(new ArrayList<>(), null);
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor(int.class, int.class, nonNullListClass, NMSUtils.nmsItemStackClass);
} else {
Constructor<?> nonNullListConstructor = nonNullListClass.getDeclaredConstructor();
nonNullListConstructor.setAccessible(true);
nonNullListInstance = nonNullListConstructor.newInstance();
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor(int.class, nonNullListClass);
}
} else {
packetConstructor = PacketTypeClasses.Play.Server.WINDOW_ITEMS.getConstructor();
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
@@ -84,6 +96,22 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
}
}
public int getStateId() {
if (packet != null) {
return readInt(1);
} else {
return stateID;
}
}
public void setStateId(int stateID) {
if (packet != null) {
writeInt(1, stateID);
} else {
this.stateID = stateID;
}
}
public List<ItemStack> getSlots() {
if (packet != null) {
List<ItemStack> slots = new ArrayList<>();
@@ -99,8 +127,7 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
}
}
return slots;
}
else {
} else {
return slotData;
}
}
@@ -120,21 +147,50 @@ public class WrappedPacketOutWindowItems extends WrappedPacket implements Sendab
}
writeAnyObject(1, nmsItemStacks);
}
}
else {
} else {
this.slotData = slots;
}
}
public Optional<ItemStack> getHeldItem() {
if (!v_1_17_1) return Optional.empty();
if (packet != null) {
return Optional.ofNullable(NMSUtils.toBukkitItemStack(readObject(0, NMSUtils.nmsItemStackClass)));
} else {
return Optional.of(heldItem);
}
}
public void setHeldItem(ItemStack heldItem) {
if (packet != null) {
writeObject(0, NMSUtils.toNMSItemStack(heldItem));
} else {
this.heldItem = heldItem;
}
}
private Object getNMSItemHeld() {
if (packet != null) {
return readObject(0, NMSUtils.nmsItemStackClass);
} else {
return NMSUtils.toNMSItemStack(heldItem);
}
}
@Override
public Object asNMSPacket() throws Exception {
Object packetInstance;
if (v_1_17) {
if (v_1_17_1) {
packetInstance = packetConstructor.newInstance(getWindowId(), stateID, nonNullListInstance, getNMSItemHeld());
WrappedPacketOutWindowItems wrappedPacketOutWindowItems = new WrappedPacketOutWindowItems(new NMSPacket(packetInstance));
wrappedPacketOutWindowItems.setSlots(getSlots());
} else if (v_1_17) {
packetInstance = packetConstructor.newInstance(getWindowId(), nonNullListInstance);
WrappedPacketOutWindowItems wrappedPacketOutWindowItems = new WrappedPacketOutWindowItems(new NMSPacket(packetInstance));
wrappedPacketOutWindowItems.setSlots(getSlots());
}
else {
} else {
packetInstance = packetConstructor.newInstance();
WrappedPacketOutWindowItems wrappedPacketOutWindowItems = new WrappedPacketOutWindowItems(new NMSPacket(packetInstance));
wrappedPacketOutWindowItems.setWindowId(getWindowId());
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -50,9 +50,7 @@ public final class EntityFinderUtils {
try {
craftWorldGetHandle = NMSUtils.craftWorldClass.getMethod("getHandle");
String getEntityByIdMethodName = (version.getProtocolVersion() == (short) 47)
? "a" : "getEntity";
getEntityByIdMethod = worldServerClass.getMethod(getEntityByIdMethodName, int.class);
getEntityByIdMethod = worldServerClass.getMethod("a", int.class);
} catch (NoSuchMethodException e) {
try {
getEntityByIdMethod = worldServerClass.getMethod("getEntity", int.class);
@@ -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;
}
}
@@ -27,10 +27,7 @@ import io.github.retrooper.packetevents.utils.server.ServerVersion;
import io.github.retrooper.packetevents.utils.vector.Vector3d;
import io.github.retrooper.packetevents.utils.vector.Vector3f;
import io.github.retrooper.packetevents.utils.vector.Vector3i;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -51,13 +48,13 @@ public final class NMSUtils {
private static final ThreadLocal<Random> randomThreadLocal = ThreadLocal.withInitial(Random::new);
public static boolean legacyNettyImportMode;
public static ServerVersion version;
public static Constructor<?> blockPosConstructor, minecraftKeyConstructor, vec3DConstructor, dataWatcherConstructor, packetDataSerializerConstructor;
public static Constructor<?> blockPosConstructor, minecraftKeyConstructor, vec3DConstructor, dataWatcherConstructor, packetDataSerializerConstructor, itemStackConstructor;
public static Class<?> mobEffectListClass, nmsEntityClass, minecraftServerClass, craftWorldClass, playerInteractManagerClass, entityPlayerClass, playerConnectionClass, craftServerClass,
craftPlayerClass, serverConnectionClass, craftEntityClass, nmsItemStackClass, networkManagerClass, nettyChannelClass, gameProfileClass, iChatBaseComponentClass,
blockPosClass, vec3DClass, channelFutureClass, blockClass, iBlockDataClass, nmsWorldClass, craftItemStackClass,
blockPosClass, sectionPositionClass, vec3DClass, channelFutureClass, blockClass, iBlockDataClass, nmsWorldClass, craftItemStackClass,
soundEffectClass, minecraftKeyClass, chatSerializerClass, craftMagicNumbersClass, worldSettingsClass, worldServerClass, dataWatcherClass,
dedicatedServerClass, entityHumanClass, packetDataSerializerClass, byteBufClass, dimensionManagerClass, nmsItemClass, movingObjectPositionBlockClass, boundingBoxClass,
tileEntityCommandClass;
dedicatedServerClass, entityHumanClass, packetDataSerializerClass, byteBufClass, dimensionManagerClass, nmsItemClass, iMaterialClass, movingObjectPositionBlockClass, boundingBoxClass,
tileEntityCommandClass;
public static Class<? extends Enum<?>> enumDirectionClass, enumHandClass, enumGameModeClass, enumDifficultyClass, tileEntityCommandTypeClass;
public static Method getBlockPosX, getBlockPosY, getBlockPosZ;
private static String nettyPrefix;
@@ -82,7 +79,7 @@ public final class NMSUtils {
//Test if the selected netty location is valid
getNettyClass("channel.Channel");
} catch (Exception ex) {
System.err.println("[packetevents] Failed to locate the netty package location for your server version. Searching...");
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[packetevents] Failed to locate the netty package location for your server version. Searching...");
//Time to correct the netty location
if (legacyNettyImportMode) {
legacyNettyImportMode = false;
@@ -190,6 +187,10 @@ public final class NMSUtils {
if (nmsItemClass == null) {
nmsItemClass = getNMClassWithoutException("world.item.Item");
}
iMaterialClass = getNMSClassWithoutException("IMaterial");
if (iMaterialClass == null) {
iMaterialClass = getNMClassWithoutException("world.level.IMaterial");
}
dedicatedServerClass = getNMSClassWithoutException("DedicatedServer");
if (dedicatedServerClass == null) {
dedicatedServerClass = getNMClassWithoutException("server.dedicated.DedicatedServer");
@@ -242,6 +243,11 @@ public final class NMSUtils {
}
}
sectionPositionClass = getNMSClassWithoutException("SectionPosition");
if (sectionPositionClass == null) {
sectionPositionClass = getNMClassWithoutException("core.SectionPosition");
}
if (version.isNewerThanOrEquals(ServerVersion.v_1_14)) {
movingObjectPositionBlockClass = NMSUtils.getNMSClassWithoutException("MovingObjectPositionBlock");
@@ -262,6 +268,10 @@ public final class NMSUtils {
if (dataWatcherClass != null) {
dataWatcherConstructor = dataWatcherClass.getConstructor(nmsEntityClass);
}
if (nmsItemStackClass != null && iMaterialClass != null) {
itemStackConstructor = nmsItemStackClass.getDeclaredConstructor(iMaterialClass);
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
@@ -316,11 +326,11 @@ public final class NMSUtils {
try {
if (mobEffectListClass != null) {
getMobEffectListId = mobEffectListClass.getMethod("getId", mobEffectListClass);
getMobEffectListById = mobEffectListClass.getMethod("fromId", int.class);
getMobEffectListId = Reflection.getMethod(mobEffectListClass, 0, mobEffectListClass);
getMobEffectListById = Reflection.getMethod(mobEffectListClass, 0, int.class);
}
} catch (Exception ignored) {
} catch (Exception ex) {
ex.printStackTrace();
}
try {
entityPlayerPingField = entityPlayerClass.getField("ping");
@@ -329,9 +339,19 @@ public final class NMSUtils {
}
//In case its null, these methods are not needed and would cause errors
if (blockPosClass != null) {
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getX", 0);
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getY", 0);
getBlockPosZ = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getZ", 0);
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass, "getX", int.class);
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass, "getY", int.class);
getBlockPosZ = Reflection.getMethod(NMSUtils.blockPosClass, "getZ", int.class);
// Mappings changed with 1.18
if (getBlockPosX == null) {
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass, "u", int.class);
}
if (getBlockPosY == null) {
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass, "v", int.class);
}
if (getBlockPosZ == null) {
getBlockPosZ = Reflection.getMethod(NMSUtils.blockPosClass, "w", int.class);
}
}
worldSettingsClass = NMSUtils.getNMSClassWithoutException("WorldSettings");
if (worldServerClass == null) {
@@ -380,7 +400,10 @@ public final class NMSUtils {
}
public static double[] recentTPS() {
return new WrappedPacket(new NMSPacket(getMinecraftServerInstance(Bukkit.getServer())), minecraftServerClass).readDoubleArray(0);
WrappedPacket minecraftServerInstanceReader = new WrappedPacket(
new NMSPacket(getMinecraftServerInstance(Bukkit.getServer())),
minecraftServerClass);
return minecraftServerInstanceReader.readDoubleArray(0);
}
public static Class<?> getNMSClass(String name) throws ClassNotFoundException {
@@ -439,7 +462,7 @@ public final class NMSUtils {
@Nullable
@Deprecated
public static Entity getEntityById(@Nullable World world, int id) {
return PacketEvents.get().getServerUtils().getEntityById(world, id);
return PacketEvents.get().getServerUtils().getEntityById(world, id);
}
public static Entity getBukkitEntity(Object nmsEntity) {
@@ -526,7 +549,7 @@ public final class NMSUtils {
if (networkManager == null) {
return null;
}
WrappedPacket wrapper = new WrappedPacket(new NMSPacket(networkManager));
WrappedPacket wrapper = new WrappedPacket(new NMSPacket(networkManager), networkManagerClass);
return wrapper.readObject(0, nettyChannelClass);
}
@@ -719,9 +742,9 @@ public final class NMSUtils {
return null;
}
public static Object generateDataWatcher(Entity entity) {
public static Object generateDataWatcher(Object nmsEntity) {
try {
return dataWatcherConstructor.newInstance(entity);
return dataWatcherConstructor.newInstance(nmsEntity);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
@@ -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;
@@ -87,11 +87,18 @@ public enum ClientVersion {
v_1_17_1(756),
/**
* 1.18 or 1.18.1 as they have the same protocol version.
*/
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_17_1.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.
* This constant assures you they are on a pre-release.
*/
ANY_PRE_RELEASE_VERSION(0),
@@ -102,16 +109,17 @@ public enum ClientVersion {
UNKNOWN(-1);
private static final short LOWEST_SUPPORTED_PROTOCOL_VERSION = (short) (LOWER_THAN_SUPPORTED_VERSIONS.protocolVersion + 1);
private static final short HIGHEST_SUPPORTED_PROTOCOL_VERSION = (short) (HIGHER_THAN_SUPPORTED_VERSIONS.protocolVersion - 1);
private static final int LOWEST_SUPPORTED_PROTOCOL_VERSION = LOWER_THAN_SUPPORTED_VERSIONS.protocolVersion + 1;
private static final int HIGHEST_SUPPORTED_PROTOCOL_VERSION = HIGHER_THAN_SUPPORTED_VERSIONS.protocolVersion - 1;
private static final Map<Short, ClientVersion> CLIENT_VERSION_CACHE = new IdentityHashMap<>();
private static final short[] CLIENT_VERSIONS = new short[]{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};
private short protocolVersion;
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, 758};
private int protocolVersion;
ClientVersion(int protocolVersion) {
this.protocolVersion = (short) protocolVersion;
this.protocolVersion = protocolVersion;
}
/**
@@ -129,19 +137,19 @@ public enum ClientVersion {
} else if (protocolVersion > HIGHEST_SUPPORTED_PROTOCOL_VERSION) {
return HIGHER_THAN_SUPPORTED_VERSIONS;
} else {
ClientVersion cached = CLIENT_VERSION_CACHE.get((short) protocolVersion);
ClientVersion cached = CLIENT_VERSION_CACHE.get(protocolVersion);
if (cached == null) {
for (ClientVersion version : values()) {
if (version.protocolVersion > protocolVersion) {
break;
} else if (version.protocolVersion == protocolVersion) {
//Cache for next time
CLIENT_VERSION_CACHE.put((short) protocolVersion, version);
CLIENT_VERSION_CACHE.put(protocolVersion, version);
return version;
}
}
cached = UNKNOWN;
cached.protocolVersion = (short) protocolVersion;
cached.protocolVersion = protocolVersion;
}
return cached;
}
@@ -152,7 +160,7 @@ public enum ClientVersion {
*
* @return Protocol version.
*/
public short getProtocolVersion() {
public int getProtocolVersion() {
return protocolVersion;
}
@@ -275,7 +283,7 @@ public enum ClientVersion {
*
* @return Is resolved
*/
public boolean isResoled() {
public boolean isResolved() {
return this != TEMP_UNRESOLVED && this != UNRESOLVED;
}
}
@@ -151,7 +151,8 @@ public final class PlayerUtils {
return ClientVersion.UNKNOWN;
}
ClientVersion version = clientVersionsMap.get(player.getAddress());
if (version == null) {
// If a player's version didn't resolve, we should try and resolve it again
if (version == null || !version.isResolved()) {
//Prioritize asking ViaVersion and ProtocolSupport as they modify the protocol version in the packet we access it from.
if (VersionLookupUtils.isDependencyAvailable()) {
try {
@@ -167,10 +168,10 @@ public final class PlayerUtils {
version = tempClientVersionMap.get(player.getAddress());
if (version == null) {
//We couldn't snatch that version from the packet.
short protocolVersion;
int protocolVersion;
//Handle 1.7.10, luckily 1.7.10 provides a method for us to access a player's protocol version(because 1.7.10 servers support 1.8 clients too)
if (PacketEvents.get().getServerUtils().getVersion().isOlderThan(ServerVersion.v_1_8)) {
protocolVersion = (short) SpigotVersionLookup_1_7.getProtocolVersion(player);
protocolVersion = SpigotVersionLookup_1_7.getProtocolVersion(player);
} else {
//No dependency available, couldn't snatch the version from the packet AND server version is not 1.7.10
//We are pretty safe to assume the version is the same as the server, as ViaVersion AND ProtocolSupport could not be found.
@@ -269,30 +270,6 @@ public final class PlayerUtils {
GameProfileUtil.setGameProfileSkin(gameProfile, skin);
}
//TODO FINISH APPLY SKIN. ITS NOT WORKING?
private void applySkinChangeAsync(Player player) {
Plugin plugin = PacketEvents.get().getPlugin();
CompletableFuture.runAsync(() -> {
System.out.println("STARTING");
}).thenRunAsync(() -> {
WrappedPacketOutEntityDestroy destroyPacket = new WrappedPacketOutEntityDestroy(player.getEntityId());
WrappedPacketOutNamedEntitySpawn spawnPacket = new WrappedPacketOutNamedEntitySpawn(player);
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getEntityId() != player.getEntityId()) {
PacketEvents.get().getPlayerUtils().sendPacket(p, destroyPacket);
PacketEvents.get().getPlayerUtils().sendPacket(p, spawnPacket);
Bukkit.getServer().getScheduler().runTask(plugin, () -> p.hidePlayer(plugin, player));
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> p.showPlayer(plugin, player), 4L);
}
}
}).thenRunAsync(() -> {
System.out.println("DONE");
});
}
public Skin getSkin(Player player) {
Object gameProfile = NMSUtils.getGameProfile(player);
return GameProfileUtil.getGameProfileSkin(gameProfile);
@@ -31,28 +31,29 @@ import org.bukkit.Bukkit;
* @since 1.6.9
*/
public enum ServerVersion {
v_1_7_10((short) 5),
v_1_8((short) 47), v_1_8_3((short) 47), v_1_8_8((short) 47),
v_1_9((short) 107), v_1_9_2((short) 109), v_1_9_4((short) 110),
v_1_7_10(5),
v_1_8(47), v_1_8_3(47), v_1_8_8(47),
v_1_9(107), v_1_9_2(109), v_1_9_4(110),
//1.10 and 1.10.1 are redundant
v_1_10((short) 210), v_1_10_1((short) 210), v_1_10_2((short) 210),
v_1_11((short) 315), v_1_11_2((short) 316),
v_1_12((short) 335), v_1_12_1((short) 338), v_1_12_2((short) 340),
v_1_13((short) 393), v_1_13_1((short) 401), v_1_13_2((short) 404),
v_1_14((short) 477), v_1_14_1((short) 480), v_1_14_2((short) 485), v_1_14_3((short) 490), v_1_14_4((short) 498),
v_1_15((short) 573), v_1_15_1((short) 575), v_1_15_2((short) 578),
v_1_16((short) 735), v_1_16_1((short) 736), v_1_16_2((short) 751), v_1_16_3((short) 753), v_1_16_4((short) 754), v_1_16_5((short) 754),
v_1_17((short) 755), v_1_17_1((short) 756),
ERROR((short) -1);
v_1_10(210), v_1_10_1(210), v_1_10_2(210),
v_1_11(315), v_1_11_2(316),
v_1_12(335), v_1_12_1(338), v_1_12_2(340),
v_1_13(393), v_1_13_1(401), v_1_13_2(404),
v_1_14(477), v_1_14_1(480), v_1_14_2(485), v_1_14_3(490), v_1_14_4(498),
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_2(758),
ERROR(-1);
private static final String NMS_VERSION_SUFFIX = Bukkit.getServer().getClass().getPackage().getName()
.replace(".", ",").split(",")[3];
private static final ServerVersion[] VALUES = values();
public static ServerVersion[] reversedValues = new ServerVersion[VALUES.length];
private static ServerVersion cachedVersion;
private final short protocolVersion;
private final int protocolVersion;
ServerVersion(short protocolId) {
ServerVersion(int protocolId) {
this.protocolVersion = protocolId;
}
@@ -60,9 +61,6 @@ public enum ServerVersion {
if (reversedValues[0] == null) {
reversedValues = ServerVersion.reverse();
}
if (reversedValues == null) {
throw new IllegalStateException("Failed to reverse the ServerVersion enum constant values.");
}
for (final ServerVersion val : reversedValues) {
String valName = val.name().substring(2).replace("_", ".");
if (Bukkit.getBukkitVersion().contains(valName)) {
@@ -74,13 +72,12 @@ public enum ServerVersion {
if (fallbackVersion == ServerVersion.v_1_7_10) {
try {
Class.forName("net.minecraft.util.io.netty.buffer.ByteBuf");
}
catch (Exception ex) {
} catch (Exception ex) {
//We will assume its 1.8.8
fallbackVersion = ServerVersion.v_1_8_8;
}
}
PacketEvents.get().getPlugin().getLogger().warning("[packetevents] Your server software is preventing us from checking the server version. We will assume the server version is " + fallbackVersion.name() + "...");
PacketEvents.get().getPlugin().getLogger().warning("[packetevents] Your server software is preventing us from checking the server version. This is what we found: " + Bukkit.getBukkitVersion() + ". We will assume the server version is " + fallbackVersion.name() + "...");
return fallbackVersion;
}
return ERROR;
@@ -91,7 +88,7 @@ public enum ServerVersion {
* If PacketEvents has already attempted resolving, return the cached version.
* If PacketEvents hasn't already attempted resolving, it will resolve it, cache it and return the version.
*
* @return Server Version. (possibly cached)
* @return Server Version. (always cached)
*/
public static ServerVersion getVersion() {
if (cachedVersion == null) {
@@ -143,7 +140,7 @@ public enum ServerVersion {
*
* @return Protocol version.
*/
public short getProtocolVersion() {
public int getProtocolVersion() {
return protocolVersion;
}
@@ -178,7 +175,6 @@ public enum ServerVersion {
return false;
}
if (version == this) return true;
if (version == target) return false;
}
return false;
@@ -160,12 +160,7 @@ public class Vector3d {
*/
@Override
public Vector3d clone() {
try {
super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
return new Vector3d(getX(), getY(), getZ());
}
public Vector3d add(Vector3d target) {
@@ -151,13 +151,8 @@ public class Vector3f {
* @return Clone.
*/
@Override
public Vector3d clone() {
try {
super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
public Vector3f clone() {
return new Vector3f(getX(), getY(), getZ());
}
@Override
@@ -161,12 +161,7 @@ public class Vector3i {
*/
@Override
public Vector3i clone() {
try {
super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
return new Vector3i(getX(), getY(), getZ());
}
@Override
+9
View File
@@ -0,0 +1,9 @@
name: packetevents
version: 1.8.2
main: io.github.retrooper.packetevents.PacketEventsPlugin
author: retrooper
softdepend:
- ProtocolLib
- ProtocolSupport
- ViaVersion
- Geyser-Spigot