forked from upstream/packetevents
Compare commits
172
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
825b61a24e | ||
|
|
dc5d15ba85 | ||
|
|
0b458c2e4c | ||
|
|
bb9fe18a76 | ||
|
|
73420efbb7 | ||
|
|
c3bc1906b1 | ||
|
|
3c4a7323a0 | ||
|
|
0a4fedff09 | ||
|
|
d1fb535ca7 | ||
|
|
5865e056d8 | ||
|
|
eb561b98b2 | ||
|
|
13b3ac7107 | ||
|
|
1943ba2da1 | ||
|
|
f90925e09b | ||
|
|
e2ecb21892 | ||
|
|
80bc492370 | ||
|
|
691e8eb070 | ||
|
|
a83c3bac2a | ||
|
|
60a5357c34 | ||
|
|
af477f8479 | ||
|
|
6b82b38b59 | ||
|
|
77918bb771 | ||
|
|
c200b8fe35 | ||
|
|
01cac8ded9 | ||
|
|
d7a0d89d8e | ||
|
|
90ec7560b7 | ||
|
|
eb96c5216b | ||
|
|
176f2f7895 | ||
|
|
2489b7651b | ||
|
|
30981f8283 | ||
|
|
4537ac2d29 | ||
|
|
577d3476bb | ||
|
|
7adb2c2ecd | ||
|
|
1f02892284 | ||
|
|
590e94ffc0 | ||
|
|
d5c2619bb3 | ||
|
|
935c9782a1 | ||
|
|
33b92f59d5 | ||
|
|
6d7a06b93f | ||
|
|
0e42d7d14f | ||
|
|
5cbdcc4158 | ||
|
|
db8f291475 | ||
|
|
187084dca1 | ||
|
|
316bc8070a | ||
|
|
62685e9330 | ||
|
|
169105af78 | ||
|
|
398bb4b6db | ||
|
|
df56ea0aa6 | ||
|
|
95e73c775c | ||
|
|
b8823ce00f | ||
|
|
01658ce3c9 | ||
|
|
934c181753 | ||
|
|
0e3099e751 | ||
|
|
43ea7737ec | ||
|
|
905dd43a0d | ||
|
|
17f7c69b11 | ||
|
|
13965a4517 | ||
|
|
679d0ba037 | ||
|
|
67e82e6d25 | ||
|
|
9e58db6cb1 | ||
|
|
e1fe2b9d99 | ||
|
|
fd3b42ef6e | ||
|
|
cf708adf55 | ||
|
|
9f8a14b58a | ||
|
|
1d31e06679 | ||
|
|
a94e72ccd0 | ||
|
|
35bd312ecf | ||
|
|
362d021745 | ||
|
|
9d98af54e6 | ||
|
|
cb1438c86f | ||
|
|
75512add39 | ||
|
|
db1c913a3e | ||
|
|
9c2609f4ee | ||
|
|
8336017bb9 | ||
|
|
1ea4880ded | ||
|
|
f54b8d7138 | ||
|
|
52e7385864 | ||
|
|
5d1371c479 | ||
|
|
91916d0eaf | ||
|
|
73505209bc | ||
|
|
934d5378e5 | ||
|
|
1ac55ffd50 | ||
|
|
9f265ef9ee | ||
|
|
0595fb6e03 | ||
|
|
9172cd3c91 | ||
|
|
7f655ad54b | ||
|
|
51af277d48 | ||
|
|
8f566032aa | ||
|
|
d01fdce16a | ||
|
|
b956ca966b | ||
|
|
4887d040ed | ||
|
|
341f6632f5 | ||
|
|
2cf93d6e17 | ||
|
|
4bbf43e83e | ||
|
|
bcd60977f5 | ||
|
|
3c899e41b5 | ||
|
|
3653c9b07a | ||
|
|
c667980997 | ||
|
|
df29b947a6 | ||
|
|
55c3b9a446 | ||
|
|
76ad95c63a | ||
|
|
e7235f1ef7 | ||
|
|
1e26293c51 | ||
|
|
84f9bbf207 | ||
|
|
40e13755ff | ||
|
|
093c45609c | ||
|
|
06d4333524 | ||
|
|
78773c3a7b | ||
|
|
bd36cae8d0 | ||
|
|
2babb1ac44 | ||
|
|
e29a15db7e | ||
|
|
bb87ce9e77 | ||
|
|
b2b7687b33 | ||
|
|
d182f9bd5b | ||
|
|
ab4dba254d | ||
|
|
380b1e9a73 | ||
|
|
395cb6a6b7 | ||
|
|
e3a6bec0ae | ||
|
|
8cd52c4f4d | ||
|
|
ef758b4ee3 | ||
|
|
a75ad0e58e | ||
|
|
2d282bee8e | ||
|
|
4b30678d6b | ||
|
|
70ae66df17 | ||
|
|
0a98140a1c | ||
|
|
2ce25c24ee | ||
|
|
f27688c89f | ||
|
|
e287e63c58 | ||
|
|
6a44c3edbf | ||
|
|
cd28ced0c7 | ||
|
|
b05496db09 | ||
|
|
c914ccbb90 | ||
|
|
a236fb5523 | ||
|
|
1768ea518e | ||
|
|
0c7f185174 | ||
|
|
2d8cf55985 | ||
|
|
15e746687a | ||
|
|
ee9a870144 | ||
|
|
932ef480b5 | ||
|
|
41125cee92 | ||
|
|
a9585a1117 | ||
|
|
5aaee6fb63 | ||
|
|
8722dd0c34 | ||
|
|
267468f731 | ||
|
|
610975b957 | ||
|
|
f09617b2c2 | ||
|
|
96a3de9744 | ||
|
|
78f88fcede | ||
|
|
612a9c318f | ||
|
|
d1bf9a09ae | ||
|
|
6e01c76e24 | ||
|
|
ccf401ff6d | ||
|
|
6b86d7fdc6 | ||
|
|
de3988ca29 | ||
|
|
0b35e5ae5f | ||
|
|
007f1030a9 | ||
|
|
938f9184b2 | ||
|
|
4c0c57ace6 | ||
|
|
af4906396b | ||
|
|
3a68338da4 | ||
|
|
bb195f28ec | ||
|
|
bd0d9cc528 | ||
|
|
39756e4490 | ||
|
|
d406506189 | ||
|
|
9de94b79be | ||
|
|
5cded7923a | ||
|
|
8c6adafebc | ||
|
|
39cd41a2d3 | ||
|
|
37feadb421 | ||
|
|
34c079d757 | ||
|
|
bd52d59801 | ||
|
|
015038c9b6 |
No files matched your search
@@ -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
|
||||
+5
-1
@@ -110,4 +110,8 @@ dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
/src/main/resources/
|
||||
/.gradle/
|
||||
/.idea/
|
||||
/build/
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,13 +8,11 @@ PacketEvents is an open-source Packet API. It has many cross-version packet-wrap
|
||||
### Resources
|
||||
* [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
|
||||
* [JavaDoc](https://packetevents.github.io/javadocs)
|
||||
* [Discord](https://discord.me/packetevents)
|
||||
|
||||
### Setup
|
||||
[Learn more](https://github.com/retrooper/packetevents/wiki/1.-Setup)
|
||||
|
||||
### Discord
|
||||
[Learn more](https://discord.me/packetevents)
|
||||
|
||||
### Contributing/Forking
|
||||
[Learn more](https://github.com/retrooper/packetevents/wiki/2.-Contributing-and-Forking)\
|
||||
Our discord server has a role for contributors and forkers.
|
||||
@@ -23,7 +21,7 @@ Our discord server has a role for contributors and forkers.
|
||||
[](https://www.ej-technologies.com/products/jprofiler/overview.html)
|
||||
|
||||
### Statistics
|
||||
PacketEvents collects statistics anonymously through bStats. Participation is completely optional and you can opt-out at any time, although it is really helpful in figuring out what environments the plugin is running in (i.e. versions of Spigot, Java), so I can adjust development accordingly.
|
||||
PacketEvents collects statistics anonymously using bStats. It helps give us an overview of what platforms use our project. If you really don't like, you can turn it off.
|
||||
|
||||
### Credit
|
||||
PacketEvents uses an injector that is extremely similar to ViaVersion's injector. I have included license and copyright holder notice in the files taken from ViaVersion. Thank you ViaVersion.
|
||||
+10
-17
@@ -49,31 +49,24 @@ repositories {
|
||||
maven {
|
||||
url = uri('https://repo.maven.apache.org/maven2/')
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.jetbrains:annotations:20.1.0'
|
||||
/*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'*/
|
||||
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 '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.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'
|
||||
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.geysermc:connector:1.2.1-SNAPSHOT'
|
||||
compileOnly 'us.myles:viaversion:3.2.0'
|
||||
compileOnly 'com.github.ProtocolSupport:ProtocolSupport:3d24efeda6'
|
||||
}
|
||||
|
||||
group = 'io.github.retrooper'
|
||||
version = '1.8-pre-16'
|
||||
version = '1.8.2'
|
||||
description = 'packetevents'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
@@ -87,4 +80,4 @@ publishing {
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
@@ -1,21 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
|
||||
@@ -27,11 +27,13 @@ import io.github.retrooper.packetevents.injector.GlobalChannelInjector;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.play.out.entityequipment.WrappedPacketOutEntityEquipment;
|
||||
import io.github.retrooper.packetevents.processor.BukkitEventProcessorInternal;
|
||||
import io.github.retrooper.packetevents.processor.PacketProcessorInternal;
|
||||
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import io.github.retrooper.packetevents.updatechecker.UpdateChecker;
|
||||
import io.github.retrooper.packetevents.utils.entityfinder.EntityFinderUtils;
|
||||
import io.github.retrooper.packetevents.utils.guava.GuavaUtils;
|
||||
import io.github.retrooper.packetevents.utils.netty.bytebuf.ByteBufUtil;
|
||||
import io.github.retrooper.packetevents.utils.netty.bytebuf.ByteBufUtil_7;
|
||||
import io.github.retrooper.packetevents.utils.netty.bytebuf.ByteBufUtil_8;
|
||||
@@ -41,6 +43,8 @@ import io.github.retrooper.packetevents.utils.server.ServerUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.version.PEVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -53,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, 16);
|
||||
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();
|
||||
@@ -120,6 +124,21 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
PacketType.load();
|
||||
|
||||
EntityFinderUtils.load();
|
||||
|
||||
getServerUtils().entityCache = GuavaUtils.makeMap();
|
||||
|
||||
if (version.isNewerThanOrEquals(ServerVersion.v_1_9)) {
|
||||
for (WrappedPacketOutEntityEquipment.EquipmentSlot slot : WrappedPacketOutEntityEquipment.EquipmentSlot.values()) {
|
||||
slot.id = (byte) slot.ordinal();
|
||||
}
|
||||
} else {
|
||||
WrappedPacketOutEntityEquipment.EquipmentSlot.MAINHAND.id = 0;
|
||||
WrappedPacketOutEntityEquipment.EquipmentSlot.OFFHAND.id = -1; //Invalid
|
||||
WrappedPacketOutEntityEquipment.EquipmentSlot.BOOTS.id = 1;
|
||||
WrappedPacketOutEntityEquipment.EquipmentSlot.LEGGINGS.id = 2;
|
||||
WrappedPacketOutEntityEquipment.EquipmentSlot.CHESTPLATE.id = 3;
|
||||
WrappedPacketOutEntityEquipment.EquipmentSlot.HELMET.id = 4;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
loading = false;
|
||||
throw new PacketEventsLoadFailureException(ex);
|
||||
@@ -172,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.
|
||||
@@ -179,12 +202,13 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
//Wait for the injector to be ready.
|
||||
while (!injectorReady.get()) {
|
||||
}
|
||||
|
||||
Runnable postInjectTask = () -> {
|
||||
Bukkit.getPluginManager().registerEvents(bukkitEventProcessorInternal, plugin);
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
injector.injectPlayer(p);
|
||||
PacketEvents.get().getEventManager().callEvent(new PostPlayerInjectEvent(p, false));
|
||||
getEventManager().callEvent(new PostPlayerInjectEvent(p, false));
|
||||
} catch (Exception ex) {
|
||||
p.kickPlayer("Failed to inject... Please rejoin!");
|
||||
}
|
||||
@@ -199,7 +223,6 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
postInjectTask.run();
|
||||
}
|
||||
|
||||
|
||||
initialized = true;
|
||||
initializing = false;
|
||||
}
|
||||
@@ -310,8 +333,11 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
}
|
||||
|
||||
private void handleUpdateCheck() {
|
||||
if (updateChecker == null) {
|
||||
updateChecker = new UpdateChecker();
|
||||
}
|
||||
Thread thread = new Thread(() -> {
|
||||
PacketEvents.get().getPlugin().getLogger().info("[packetevents] Checking for an update, please wait...");
|
||||
getPlugin().getLogger().info("[packetevents] Checking for an update, please wait...");
|
||||
UpdateChecker.UpdateCheckerStatus status = updateChecker.checkForUpdate();
|
||||
int seconds = 5;
|
||||
int retryCount = 5;
|
||||
@@ -319,7 +345,7 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
if (status != UpdateChecker.UpdateCheckerStatus.FAILED) {
|
||||
break;
|
||||
}
|
||||
PacketEvents.get().getPlugin().getLogger().severe("[packetevents] Checking for an update again in " + seconds + " seconds...");
|
||||
getPlugin().getLogger().severe("[packetevents] Checking for an update again in " + seconds + " seconds...");
|
||||
try {
|
||||
Thread.sleep(seconds * 1000L);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -331,7 +357,7 @@ public final class PacketEvents implements Listener, EventManager {
|
||||
status = updateChecker.checkForUpdate();
|
||||
|
||||
if (i == (retryCount - 1)) {
|
||||
PacketEvents.get().getPlugin().getLogger().severe("[packetevents] PacketEvents failed to check for an update. No longer retrying.");
|
||||
getPlugin().getLogger().severe("[packetevents] PacketEvents failed to check for an update. No longer retrying.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,11 @@ import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class PacketEventsPlugin extends JavaPlugin {
|
||||
//TODO finish remaining wrappers
|
||||
//1.8.1 - PacketListener will have all listener methods, packetlistenerabstract will implement it with filter system additionally.
|
||||
@Override
|
||||
public void onLoad() {
|
||||
//Return value of create is your PacketEvents instance.
|
||||
PacketEvents.create(this);
|
||||
PacketEventsSettings settings = PacketEvents.get().getSettings();
|
||||
PacketEventsSettings settings = PacketEvents.create(this).getSettings();
|
||||
settings
|
||||
.fallbackServerVersion(ServerVersion.v_1_7_10)
|
||||
.fallbackServerVersion(ServerVersion.getLatest())
|
||||
.compatInjector(false)
|
||||
.checkForUpdates(true)
|
||||
.bStats(true);
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
*
|
||||
* * This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* * Copyright (C) 2016-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/>.
|
||||
* 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.event;
|
||||
|
||||
-4
@@ -29,10 +29,6 @@ public abstract class CancellableNMSPacketEvent extends NMSPacketEvent implement
|
||||
super(channel, packet);
|
||||
}
|
||||
|
||||
public CancellableNMSPacketEvent(InetSocketAddress address, NMSPacket packet) {
|
||||
super(address, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
||||
+11
-6
@@ -35,17 +35,14 @@ import java.net.InetSocketAddress;
|
||||
* @since 1.8
|
||||
*/
|
||||
public abstract class NMSPacketEvent extends PacketEvent implements CallableEvent {
|
||||
private final Object channel;
|
||||
private final InetSocketAddress socketAddress;
|
||||
private final byte packetID;
|
||||
protected NMSPacket packet;
|
||||
protected boolean cancelled;
|
||||
|
||||
public NMSPacketEvent(Object channel, NMSPacket packet) {
|
||||
this(ChannelUtils.getSocketAddress(channel), packet);//Call the constructor below
|
||||
}
|
||||
|
||||
public NMSPacketEvent(InetSocketAddress address, NMSPacket packet) {
|
||||
this.socketAddress = address;
|
||||
this.channel = channel;
|
||||
this.socketAddress = ChannelUtils.getSocketAddress(channel);
|
||||
this.packet = packet;
|
||||
packetID = PacketType.packetIDMap.getOrDefault(packet.getRawNMSPacket().getClass(), PacketType.INVALID);
|
||||
}
|
||||
@@ -59,6 +56,14 @@ public abstract class NMSPacketEvent extends PacketEvent implements CallableEven
|
||||
return socketAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated player's netty channel.
|
||||
* @return Netty channel
|
||||
*/
|
||||
public Object getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the NMS name of the packet.
|
||||
* To get the name of the packet we get the class of the packet and then the simple name of the class.
|
||||
|
||||
+13
-15
@@ -1,21 +1,19 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
*
|
||||
* * This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* * Copyright (C) 2016-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/>.
|
||||
* 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.event.eventtypes;
|
||||
|
||||
+1
-5
@@ -34,14 +34,10 @@ import java.net.InetSocketAddress;
|
||||
* @since 1.8
|
||||
*/
|
||||
public class PacketHandshakeReceiveEvent extends CancellableNMSPacketEvent {
|
||||
public PacketHandshakeReceiveEvent(final Object channel, final NMSPacket packet) {
|
||||
public PacketHandshakeReceiveEvent(Object channel, NMSPacket packet) {
|
||||
super(channel, packet);
|
||||
}
|
||||
|
||||
public PacketHandshakeReceiveEvent(final InetSocketAddress socketAddress, final NMSPacket packet) {
|
||||
super(socketAddress, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerAbstract listener) {
|
||||
if (listener.clientSidedLoginAllowance == null || listener.clientSidedLoginAllowance.contains(getPacketId())) {
|
||||
|
||||
+1
-5
@@ -34,14 +34,10 @@ import java.net.InetSocketAddress;
|
||||
* @since 1.8
|
||||
*/
|
||||
public class PacketLoginReceiveEvent extends CancellableNMSPacketEvent {
|
||||
public PacketLoginReceiveEvent(final Object channel, final NMSPacket packet) {
|
||||
public PacketLoginReceiveEvent(Object channel, NMSPacket packet) {
|
||||
super(channel, packet);
|
||||
}
|
||||
|
||||
public PacketLoginReceiveEvent(final InetSocketAddress socketAddress, final NMSPacket packet) {
|
||||
super(socketAddress, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerAbstract listener) {
|
||||
if (listener.clientSidedLoginAllowance == null || listener.clientSidedLoginAllowance.contains(getPacketId())) {
|
||||
|
||||
@@ -41,10 +41,6 @@ public class PacketLoginSendEvent extends CancellableNMSPacketEvent implements P
|
||||
super(channel, packet);
|
||||
}
|
||||
|
||||
public PacketLoginSendEvent(InetSocketAddress address, NMSPacket packet) {
|
||||
super(address, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPostTaskAvailable() {
|
||||
return postTask != null;
|
||||
|
||||
-4
@@ -38,10 +38,6 @@ public class PacketStatusReceiveEvent extends CancellableNMSPacketEvent {
|
||||
super(channel, packet);
|
||||
}
|
||||
|
||||
public PacketStatusReceiveEvent(final InetSocketAddress socketAddress, final NMSPacket packet) {
|
||||
super(socketAddress, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerAbstract listener) {
|
||||
if (listener.clientSidedStatusAllowance == null || listener.clientSidedStatusAllowance.contains(getPacketId())) {
|
||||
|
||||
@@ -44,10 +44,6 @@ public class PacketStatusSendEvent extends CancellableNMSPacketEvent implements
|
||||
super(channel, packet);
|
||||
}
|
||||
|
||||
public PacketStatusSendEvent(InetSocketAddress address, NMSPacket packet) {
|
||||
super(address, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPostTaskAvailable() {
|
||||
return postTask != null;
|
||||
|
||||
@@ -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.
|
||||
|
||||
+24
-11
@@ -45,10 +45,6 @@ class EventManagerModern {
|
||||
* @see EventManagerLegacy#callEvent(PacketEvent, byte)
|
||||
*/
|
||||
public void callEvent(final PacketEvent event) {
|
||||
boolean cancel = false;
|
||||
if (event instanceof CancellableEvent) {
|
||||
cancel = ((CancellableEvent) event).isCancelled();
|
||||
}
|
||||
byte highestReachedPriority = (byte) (PacketListenerPriority.LOWEST.getId() - 1);
|
||||
for (byte priority = PacketListenerPriority.LOWEST.getId(); priority <= PacketListenerPriority.MONITOR.getId(); priority++) {
|
||||
HashSet<PacketListenerAbstract> listeners = listenersMap.get(priority);
|
||||
@@ -63,17 +59,10 @@ class EventManagerModern {
|
||||
//TODO Remove, because its redundant. We are only keeping it for compatibility with the legacy event manager.
|
||||
if (event instanceof CancellableEvent) {
|
||||
if (priority > highestReachedPriority) {
|
||||
CancellableEvent ce = (CancellableEvent) event;
|
||||
cancel = ce.isCancelled();
|
||||
highestReachedPriority = priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO Remove. This is also redundant. The listeners are always called in order, the event is always being modified by each listener. The last listener therefore has the last decision on the cancellation.
|
||||
if (event instanceof CancellableEvent) {
|
||||
CancellableEvent ce = (CancellableEvent) event;
|
||||
ce.setCancelled(cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
PEEventManager.EVENT_MANAGER_LEGACY.callEvent(event, highestReachedPriority);
|
||||
@@ -105,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.
|
||||
*/
|
||||
|
||||
@@ -35,5 +35,9 @@ public interface ChannelInjector {
|
||||
|
||||
boolean hasInjected(Player player);
|
||||
|
||||
void writePacket(Object channel, Object rawNMSPacket);
|
||||
|
||||
void flushPackets(Object channel);
|
||||
|
||||
void sendPacket(Object channel, Object rawNMSPacket);
|
||||
}
|
||||
@@ -84,6 +84,14 @@ public class GlobalChannelInjector {
|
||||
return injector.hasInjected(player);
|
||||
}
|
||||
|
||||
public void writePacket(Object ch, Object rawNMSPacket) {
|
||||
injector.writePacket(ch, rawNMSPacket);
|
||||
}
|
||||
|
||||
public void flushPackets(Object ch) {
|
||||
injector.flushPackets(ch);
|
||||
}
|
||||
|
||||
public void sendPacket(Object ch, Object rawNMSPacket) {
|
||||
injector.sendPacket(ch, rawNMSPacket);
|
||||
}
|
||||
|
||||
+17
-26
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* 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
|
||||
@@ -21,12 +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;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class PlayerChannelHandlerLegacy extends ChannelDuplexHandler {
|
||||
/**
|
||||
* Associated player.
|
||||
@@ -36,32 +35,24 @@ public class PlayerChannelHandlerLegacy extends ChannelDuplexHandler {
|
||||
|
||||
@Override
|
||||
public void channelRead(final ChannelHandlerContext ctx, Object packet) throws Exception {
|
||||
try {
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().read(player, ctx.channel(), packet);
|
||||
if (data.packet != null) {
|
||||
super.channelRead(ctx, data.packet);
|
||||
PacketEvents.get().getInternalPacketProcessor().postRead(player, ctx.channel(), data.packet);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
PacketEvents.get().getPlugin().getLogger().log(Level.SEVERE, "Unable to handle an incoming packet ", t.getMessage());
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().read(player, ctx.channel(), packet);
|
||||
if (data.packet != null) {
|
||||
super.channelRead(ctx, data.packet);
|
||||
PacketEvents.get().getInternalPacketProcessor().postRead(player, ctx.channel(), data.packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ChannelHandlerContext ctx, Object packet, final ChannelPromise promise) throws Exception {
|
||||
try {
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().write(player, ctx.channel(), packet);
|
||||
if (data.postAction != null) {
|
||||
promise.addListener(f -> {
|
||||
data.postAction.run();
|
||||
});
|
||||
}
|
||||
if (data.packet != null) {
|
||||
super.write(ctx, data.packet, promise);
|
||||
PacketEvents.get().getInternalPacketProcessor().postWrite(player, ctx.channel(), data.packet);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
PacketEvents.get().getPlugin().getLogger().log(Level.SEVERE, "Unable to handle an outgoing packet ", t.getMessage());
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().write(player, ctx.channel(), packet);
|
||||
if (data.postAction != null) {
|
||||
promise.addListener(f -> {
|
||||
data.postAction.run();
|
||||
});
|
||||
}
|
||||
if (data.packet != null) {
|
||||
super.write(ctx, data.packet, promise);
|
||||
PacketEvents.get().getInternalPacketProcessor().postWrite(player, ctx.channel(), data.packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-2
@@ -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,12 +127,18 @@ 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;
|
||||
}
|
||||
|
||||
if (channel.pipeline().get(PacketEvents.get().getHandlerName()) != null) {
|
||||
channel.pipeline().remove(PacketEvents.get().getHandlerName());
|
||||
}
|
||||
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), new PlayerChannelHandlerLegacy());
|
||||
}
|
||||
@@ -275,6 +283,18 @@ public class EarlyChannelInjectorLegacy implements EarlyInjector {
|
||||
return handler != null && handler.player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(Object ch, Object rawNMSPacket) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.write(rawNMSPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushPackets(Object ch) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Object ch, Object rawNMSPacket) {
|
||||
Channel channel = (Channel) ch;
|
||||
|
||||
+13
-8
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* 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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-1
@@ -21,7 +21,9 @@ package io.github.retrooper.packetevents.injector.legacy.late;
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.injector.LateInjector;
|
||||
import io.github.retrooper.packetevents.injector.legacy.PlayerChannelHandlerLegacy;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LateChannelInjectorLegacy implements LateInjector {
|
||||
@@ -40,7 +42,10 @@ public class LateChannelInjectorLegacy implements LateInjector {
|
||||
PlayerChannelHandlerLegacy playerChannelHandlerLegacy = new PlayerChannelHandlerLegacy();
|
||||
playerChannelHandlerLegacy.player = player;
|
||||
Channel channel = (Channel) PacketEvents.get().getPlayerUtils().getChannel(player);
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerLegacy);
|
||||
if (channel.getClass().equals(NioSocketChannel.class)
|
||||
|| channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerLegacy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,6 +66,18 @@ public class LateChannelInjectorLegacy implements LateInjector {
|
||||
return channel.pipeline().get(PacketEvents.get().getHandlerName()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(Object ch, Object rawNMSPacket) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.write(rawNMSPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushPackets(Object ch) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Object rawChannel, Object packet) {
|
||||
Channel channel = (Channel) rawChannel;
|
||||
|
||||
+17
-26
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* 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
|
||||
@@ -21,12 +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;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class PlayerChannelHandlerModern extends ChannelDuplexHandler {
|
||||
/**
|
||||
* Associated player.
|
||||
@@ -36,32 +35,24 @@ public class PlayerChannelHandlerModern extends ChannelDuplexHandler {
|
||||
|
||||
@Override
|
||||
public void channelRead(final ChannelHandlerContext ctx, Object packet) throws Exception {
|
||||
try {
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().read(player, ctx.channel(), packet);
|
||||
if (data.packet != null) {
|
||||
super.channelRead(ctx, data.packet);
|
||||
PacketEvents.get().getInternalPacketProcessor().postRead(player, ctx.channel(), data.packet);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
PacketEvents.get().getPlugin().getLogger().log(Level.SEVERE, "Unable to handle an incoming packet ", t.getMessage());
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().read(player, ctx.channel(), packet);
|
||||
if (data.packet != null) {
|
||||
super.channelRead(ctx, data.packet);
|
||||
PacketEvents.get().getInternalPacketProcessor().postRead(player, ctx.channel(), data.packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ChannelHandlerContext ctx, Object packet, final ChannelPromise promise) throws Exception {
|
||||
try {
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().write(player, ctx.channel(), packet);
|
||||
if (data.postAction != null) {
|
||||
promise.addListener(f -> {
|
||||
data.postAction.run();
|
||||
});
|
||||
}
|
||||
if (data.packet != null) {
|
||||
super.write(ctx, data.packet, promise);
|
||||
PacketEvents.get().getInternalPacketProcessor().postWrite(player, ctx.channel(), data.packet);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
PacketEvents.get().getPlugin().getLogger().log(Level.SEVERE, "Unable to handle an outgoing packet ", t.getMessage());
|
||||
PacketProcessorInternal.PacketData data = PacketEvents.get().getInternalPacketProcessor().write(player, ctx.channel(), packet);
|
||||
if (data.postAction != null) {
|
||||
promise.addListener(f -> {
|
||||
data.postAction.run();
|
||||
});
|
||||
}
|
||||
if (data.packet != null) {
|
||||
super.write(ctx, data.packet, promise);
|
||||
PacketEvents.get().getInternalPacketProcessor().postWrite(player, ctx.channel(), data.packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-6
@@ -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,12 +130,18 @@ 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;
|
||||
}
|
||||
|
||||
if (channel.pipeline().get(PacketEvents.get().getHandlerName()) != null) {
|
||||
channel.pipeline().remove(PacketEvents.get().getHandlerName());
|
||||
}
|
||||
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), new PlayerChannelHandlerModern());
|
||||
}
|
||||
@@ -191,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();
|
||||
@@ -284,6 +292,18 @@ public class EarlyChannelInjectorModern implements EarlyInjector {
|
||||
return handler != null && handler.player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(Object ch, Object rawNMSPacket) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.write(rawNMSPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushPackets(Object ch) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Object ch, Object rawNMSPacket) {
|
||||
Channel channel = (Channel) ch;
|
||||
|
||||
+15
-9
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* 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
|
||||
@@ -23,6 +23,8 @@ import io.github.retrooper.packetevents.injector.modern.PlayerChannelHandlerMode
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -36,13 +38,17 @@ public class PEChannelInitializerModern extends ChannelInitializer<Channel> {
|
||||
}
|
||||
|
||||
public static void postInitChannel(Channel channel) {
|
||||
PlayerChannelHandlerModern channelHandler = new PlayerChannelHandlerModern();
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
String handlerName = PacketEvents.get().getHandlerName();
|
||||
if (channel.pipeline().get(handlerName) != null) {
|
||||
PacketEvents.get().getPlugin().getLogger().warning("[PacketEvents] Attempted to initialize a channel twice!");
|
||||
} else {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, channelHandler);
|
||||
if (channel.getClass().equals(NioSocketChannel.class)
|
||||
|| channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
PlayerChannelHandlerModern channelHandler = new PlayerChannelHandlerModern();
|
||||
if (channel.pipeline().get("packet_handler") != null) {
|
||||
String handlerName = PacketEvents.get().getHandlerName();
|
||||
if (channel.pipeline().get(handlerName) != null) {
|
||||
//Just ignore this to support latest ProtocolLib snapshots.
|
||||
//PacketEvents.get().getPlugin().getLogger().warning("[PacketEvents] Attempted to initialize a channel twice!");
|
||||
} else {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, channelHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.injector.modern.early;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.netty.channel.Channel;
|
||||
import net.kyori.adventure.key.Key;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
public class PaperChannelInjector {
|
||||
public static final boolean PAPER_INJECTION_METHOD = hasPaperInjectionMethod();
|
||||
|
||||
private PaperChannelInjector() {
|
||||
}
|
||||
|
||||
public static void setPaperChannelInitializeListener() throws ReflectiveOperationException {
|
||||
// Call io.papermc.paper.network.ChannelInitializeListenerHolder.addListener(net.kyori.adventure.key.Key, io.papermc.paper.network.ChannelInitializeListener)
|
||||
// Create an interface proxy of ChannelInitializeListener
|
||||
Class<?> listenerClass = Class.forName("io.papermc.paper.network.ChannelInitializeListener");
|
||||
Object channelInitializeListener = Proxy.newProxyInstance(EarlyChannelInjectorModern.class.getClassLoader(), new Class[]{listenerClass}, (proxy, method, args) -> {
|
||||
if (method.getName().equals("afterInitChannel")) {
|
||||
PEChannelInitializerModern.postInitChannel((Channel) args[0]);
|
||||
return null;
|
||||
}
|
||||
return method.invoke(proxy, args);
|
||||
});
|
||||
|
||||
Class<?> holderClass = Class.forName("io.papermc.paper.network.ChannelInitializeListenerHolder");
|
||||
Method addListenerMethod = holderClass.getDeclaredMethod("addListener", Key.class, listenerClass);
|
||||
Key key = Key.key(PacketEvents.get().getHandlerName().toLowerCase(), "injector");
|
||||
addListenerMethod.invoke(null, key, channelInitializeListener);
|
||||
}
|
||||
|
||||
public static void removePaperChannelInitializeListener() throws ReflectiveOperationException {
|
||||
Class<?> holderClass = Class.forName("io.papermc.paper.network.ChannelInitializeListenerHolder");
|
||||
Method addListenerMethod = holderClass.getDeclaredMethod("removeListener", Key.class);
|
||||
Key key = Key.key(PacketEvents.get().getHandlerName().toLowerCase(), "injector");
|
||||
addListenerMethod.invoke(null, key);
|
||||
}
|
||||
|
||||
private static boolean hasPaperInjectionMethod() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.network.ChannelInitializeListener");
|
||||
return true;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-1
@@ -22,6 +22,8 @@ import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.injector.LateInjector;
|
||||
import io.github.retrooper.packetevents.injector.modern.PlayerChannelHandlerModern;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LateChannelInjectorModern implements LateInjector {
|
||||
@@ -40,7 +42,10 @@ public class LateChannelInjectorModern implements LateInjector {
|
||||
PlayerChannelHandlerModern playerChannelHandlerModern = new PlayerChannelHandlerModern();
|
||||
playerChannelHandlerModern.player = player;
|
||||
Channel channel = (Channel) PacketEvents.get().getPlayerUtils().getChannel(player);
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerModern);
|
||||
if (channel.getClass().equals(NioSocketChannel.class) ||
|
||||
channel.getClass().equals(EpollSocketChannel.class)) {
|
||||
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerModern);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,6 +67,18 @@ public class LateChannelInjectorModern implements LateInjector {
|
||||
return channel.pipeline().get(PacketEvents.get().getHandlerName()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(Object ch, Object rawNMSPacket) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.write(rawNMSPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushPackets(Object ch) {
|
||||
Channel channel = (Channel) ch;
|
||||
channel.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Object rawChannel, Object packet) {
|
||||
Channel channel = (Channel) rawChannel;
|
||||
|
||||
@@ -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) {
|
||||
@@ -196,7 +197,7 @@ public class PacketType {
|
||||
ADVANCEMENTS = -81, TR_SEL = -80, BEACON = -79, HELD_ITEM_SLOT = -78,
|
||||
SET_COMMAND_BLOCK = -77, SET_COMMAND_MINECART = -76, SET_CREATIVE_SLOT = -75, SET_JIGSAW = -74,
|
||||
STRUCT = -73, UPDATE_SIGN = -72, ARM_ANIMATION = -71, SPECTATE = -70,
|
||||
USE_ITEM = -69, BLOCK_PLACE = -68;
|
||||
USE_ITEM = -69, BLOCK_PLACE = -68, PONG = 28;
|
||||
|
||||
private static void load() {
|
||||
insertPacketID(PacketTypeClasses.Play.Client.TELEPORT_ACCEPT, TELEPORT_ACCEPT);
|
||||
@@ -220,7 +221,7 @@ public class PacketType {
|
||||
insertPacketID(PacketTypeClasses.Play.Client.POSITION, POSITION);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.POSITION_LOOK, POSITION_LOOK);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.LOOK, LOOK);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.FLYING, FLYING);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.GROUND, FLYING);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.VEHICLE_MOVE, VEHICLE_MOVE);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.BOAT_MOVE, BOAT_MOVE);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.PICK_ITEM, PICK_ITEM);
|
||||
@@ -246,6 +247,7 @@ public class PacketType {
|
||||
insertPacketID(PacketTypeClasses.Play.Client.SPECTATE, SPECTATE);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.USE_ITEM, USE_ITEM);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.BLOCK_PLACE, BLOCK_PLACE);
|
||||
insertPacketID(PacketTypeClasses.Play.Client.PONG, PONG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,7 +322,11 @@ public class PacketType {
|
||||
SCOREBOARD_SCORE = 10, SPAWN_POSITION = 11, UPDATE_TIME = 12, TITLE = 13,
|
||||
ENTITY_SOUND = 14, NAMED_SOUND_EFFECT = 15, STOP_SOUND = 16, PLAYER_LIST_HEADER_FOOTER = 17,
|
||||
NBT_QUERY = 18, COLLECT = 19, ENTITY_TELEPORT = 20, ADVANCEMENTS = 21, UPDATE_ATTRIBUTES = 22,
|
||||
ENTITY_EFFECT = 23, RECIPE_UPDATE = 24, TAGS = 25, MAP_CHUNK_BULK = 26, NAMED_ENTITY_SPAWN = 27;
|
||||
ENTITY_EFFECT = 23, RECIPE_UPDATE = 24, TAGS = 25, MAP_CHUNK_BULK = 26, NAMED_ENTITY_SPAWN = 27, PING = 29,
|
||||
ADD_VIBRATION_SIGNAL = 30, CLEAR_TITLES = 31, INITIALIZE_BORDER = 32, PLAYER_COMBAT_END = 33,
|
||||
PLAYER_COMBAT_ENTER = 34, PLAYER_COMBAT_KILL = 35, SET_ACTIONBAR_TEXT = 36, SET_BORDER_CENTER = 37,
|
||||
SET_BORDER_LERP_SIZE = 38, SET_BORDER_SIZE = 39, SET_BORDER_WARNING_DELAY = 40, SET_BORDER_WARNING_DISTANCE = 41,
|
||||
SET_SUBTITLE_TEXT = 42, SET_TITLES_ANIMATION = 43, SET_TITLE_TEXT = 44;
|
||||
|
||||
private static void load() {
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SPAWN_ENTITY, SPAWN_ENTITY);
|
||||
@@ -340,7 +343,6 @@ public class PacketType {
|
||||
insertPacketID(PacketTypeClasses.Play.Server.BLOCK_ACTION, BLOCK_ACTION);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.BLOCK_CHANGE, BLOCK_CHANGE);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.BOSS, BOSS);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SPAWN_ENTITY, SPAWN_ENTITY);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SERVER_DIFFICULTY, SERVER_DIFFICULTY);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.CHAT, CHAT);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.MULTI_BLOCK_CHANGE, MULTI_BLOCK_CHANGE);
|
||||
@@ -363,7 +365,6 @@ public class PacketType {
|
||||
insertPacketID(PacketTypeClasses.Play.Server.KEEP_ALIVE, KEEP_ALIVE);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.MAP_CHUNK, MAP_CHUNK);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.WORLD_EVENT, WORLD_EVENT);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.WORLD_EVENT, SPAWN_ENTITY);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.WORLD_PARTICLES, WORLD_PARTICLES);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.LIGHT_UPDATE, LIGHT_UPDATE);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.LOGIN, LOGIN);
|
||||
@@ -423,6 +424,22 @@ public class PacketType {
|
||||
insertPacketID(PacketTypeClasses.Play.Server.TAGS, TAGS);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.MAP_CHUNK_BULK, MAP_CHUNK_BULK);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.NAMED_ENTITY_SPAWN, NAMED_ENTITY_SPAWN);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.PING, PING);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.ADD_VIBRATION_SIGNAL, ADD_VIBRATION_SIGNAL);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.CLEAR_TITLES, CLEAR_TITLES );
|
||||
insertPacketID(PacketTypeClasses.Play.Server.INITIALIZE_BORDER, INITIALIZE_BORDER);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.PLAYER_COMBAT_END, PLAYER_COMBAT_END);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.PLAYER_COMBAT_ENTER, PLAYER_COMBAT_ENTER);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.PLAYER_COMBAT_KILL, PLAYER_COMBAT_KILL);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_ACTIONBAR_TEXT, SET_ACTIONBAR_TEXT);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_BORDER_CENTER, SET_BORDER_CENTER);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_BORDER_LERP_SIZE, SET_BORDER_LERP_SIZE);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_BORDER_SIZE, SET_BORDER_SIZE);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_BORDER_WARNING_DELAY, SET_BORDER_WARNING_DELAY);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_BORDER_WARNING_DISTANCE, SET_BORDER_WARNING_DISTANCE);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_SUBTITLE_TEXT, SET_SUBTITLE_TEXT);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_TITLES_ANIMATION, SET_TITLES_ANIMATION);
|
||||
insertPacketID(PacketTypeClasses.Play.Server.SET_TITLE_TEXT, SET_TITLE_TEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+254
-171
@@ -19,7 +19,7 @@
|
||||
package io.github.retrooper.packetevents.packettype;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
@@ -40,61 +40,96 @@ public class PacketTypeClasses {
|
||||
|
||||
public static class Status {
|
||||
public static class Client {
|
||||
private static String PREFIX;
|
||||
public static Class<?> START, PING;
|
||||
|
||||
public static void load() {
|
||||
Client.START = NMSUtils.getNMSClassWithoutException("PacketStatusInStart");
|
||||
Client.PING = NMSUtils.getNMSClassWithoutException("PacketStatusInPing");
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.status.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
Client.START = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusInStart");
|
||||
Client.PING = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusInPing");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Server {
|
||||
private static String PREFIX;
|
||||
public static Class<?> PONG, SERVER_INFO;
|
||||
|
||||
public static void load() {
|
||||
Server.PONG = NMSUtils.getNMSClassWithoutException("PacketStatusOutPong");
|
||||
Server.SERVER_INFO = NMSUtils.getNMSClassWithoutException("PacketStatusOutServerInfo");
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.status.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
Server.PONG = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusOutPong");
|
||||
Server.SERVER_INFO = Reflection.getClassByNameWithoutException(PREFIX + "PacketStatusOutServerInfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handshaking {
|
||||
public static class Client {
|
||||
private static String PREFIX;
|
||||
public static Class<?> SET_PROTOCOL;
|
||||
|
||||
public static void load() {
|
||||
Handshaking.Client.SET_PROTOCOL = NMSUtils.getNMSClassWithoutException("PacketHandshakingInSetProtocol");
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.handshake.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
Handshaking.Client.SET_PROTOCOL = Reflection.getClassByNameWithoutException(PREFIX + "PacketHandshakingInSetProtocol");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Login {
|
||||
public static class Client {
|
||||
private static String PREFIX;
|
||||
public static Class<?> CUSTOM_PAYLOAD, START, ENCRYPTION_BEGIN;
|
||||
|
||||
public static void load() {
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.login.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
//In and Out custom payload login packets have been here since 1.13
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_13)) {
|
||||
Client.CUSTOM_PAYLOAD = NMSUtils.getNMSClassWithoutException("PacketLoginInCustomPayload");
|
||||
Client.CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginInCustomPayload");
|
||||
}
|
||||
Client.START = NMSUtils.getNMSClassWithoutException("PacketLoginInStart");
|
||||
Client.ENCRYPTION_BEGIN = NMSUtils.getNMSClassWithoutException("PacketLoginInEncryptionBegin");
|
||||
Client.START = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginInStart");
|
||||
Client.ENCRYPTION_BEGIN = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginInEncryptionBegin");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Server {
|
||||
private static String PREFIX;
|
||||
public static Class<?> CUSTOM_PAYLOAD, DISCONNECT, ENCRYPTION_BEGIN, SUCCESS, SET_COMPRESSION;
|
||||
|
||||
public static void load() {
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.login.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
//In and Out custom payload login packets have been here since 1.13
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_13)) {
|
||||
Server.CUSTOM_PAYLOAD = NMSUtils.getNMSClassWithoutException("PacketLoginOutCustomPayload");
|
||||
Server.CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginOutCustomPayload");
|
||||
}
|
||||
Server.DISCONNECT = NMSUtils.getNMSClassWithoutException("PacketLoginOutDisconnect");
|
||||
Server.ENCRYPTION_BEGIN = NMSUtils.getNMSClassWithoutException("PacketLoginOutEncryptionBegin");
|
||||
Server.SUCCESS = NMSUtils.getNMSClassWithoutException("PacketLoginOutSuccess");
|
||||
Server.DISCONNECT = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginOutDisconnect");
|
||||
Server.ENCRYPTION_BEGIN = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginOutEncryptionBegin");
|
||||
Server.SUCCESS = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginOutSuccess");
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThan(ServerVersion.v_1_7_10)) {
|
||||
Server.SET_COMPRESSION = NMSUtils.getNMSClassWithoutException("PacketLoginOutSetCompression");
|
||||
Server.SET_COMPRESSION = Reflection.getClassByNameWithoutException(PREFIX + "PacketLoginOutSetCompression");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,8 +137,9 @@ public class PacketTypeClasses {
|
||||
|
||||
public static class Play {
|
||||
public static class Client {
|
||||
private static final String PREFIX = "PacketPlayIn";
|
||||
public static Class<?> FLYING, POSITION, POSITION_LOOK, LOOK, CLIENT_COMMAND,
|
||||
private static String COMMON_PREFIX;
|
||||
private static String PREFIX;
|
||||
public static Class<?> FLYING, POSITION, POSITION_LOOK, LOOK, GROUND, CLIENT_COMMAND,
|
||||
TRANSACTION, BLOCK_DIG, ENTITY_ACTION, USE_ENTITY,
|
||||
WINDOW_CLICK, STEER_VEHICLE, CUSTOM_PAYLOAD, ARM_ANIMATION,
|
||||
BLOCK_PLACE, USE_ITEM, ABILITIES, HELD_ITEM_SLOT,
|
||||
@@ -113,76 +149,91 @@ public class PacketTypeClasses {
|
||||
JIGSAW_GENERATE, DIFFICULTY_LOCK, VEHICLE_MOVE, BOAT_MOVE, PICK_ITEM,
|
||||
AUTO_RECIPE, RECIPE_DISPLAYED, ITEM_NAME, RESOURCE_PACK_STATUS,
|
||||
ADVANCEMENTS, TR_SEL, BEACON, SET_COMMAND_BLOCK,
|
||||
SET_COMMAND_MINECART, SET_JIGSAW, STRUCT, UPDATE_SIGN, SPECTATE;
|
||||
SET_COMMAND_MINECART, SET_JIGSAW, STRUCT, UPDATE_SIGN, SPECTATE, PONG;
|
||||
|
||||
/**
|
||||
* Initiate all server-bound play packet classes.
|
||||
*/
|
||||
public static void load() {
|
||||
FLYING = NMSUtils.getNMSClassWithoutException(PREFIX + "Flying");
|
||||
try {
|
||||
POSITION = NMSUtils.getNMSClass(PREFIX + "Position");
|
||||
POSITION_LOOK = NMSUtils.getNMSClass(PREFIX + "PositionLook");
|
||||
LOOK = NMSUtils.getNMSClass(PREFIX + "Look");
|
||||
} catch (Exception e) {
|
||||
POSITION = SubclassUtil.getSubClass(FLYING, PREFIX + "Position");
|
||||
POSITION_LOOK = SubclassUtil.getSubClass(FLYING, PREFIX + "PositionLook");
|
||||
LOOK = SubclassUtil.getSubClass(FLYING, PREFIX + "Look");
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.game.";
|
||||
}
|
||||
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
COMMON_PREFIX = PREFIX + "PacketPlayIn";
|
||||
FLYING = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Flying");
|
||||
try {
|
||||
SETTINGS = NMSUtils.getNMSClass(PREFIX + "Settings");
|
||||
ENCHANT_ITEM = NMSUtils.getNMSClass(PREFIX + "EnchantItem");
|
||||
POSITION = Class.forName(COMMON_PREFIX + "Position");
|
||||
POSITION_LOOK = Class.forName(COMMON_PREFIX + "PositionLook");
|
||||
LOOK = Class.forName(COMMON_PREFIX + "Look");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
POSITION = SubclassUtil.getSubClass(FLYING,"PacketPlayInPosition");
|
||||
POSITION_LOOK = SubclassUtil.getSubClass(FLYING, "PacketPlayInPositionLook");
|
||||
LOOK = SubclassUtil.getSubClass(FLYING, "PacketPlayInLook");
|
||||
}
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
GROUND = SubclassUtil.getSubClass(FLYING, "d");
|
||||
}
|
||||
else {
|
||||
GROUND = FLYING;
|
||||
}
|
||||
//This packet does not exist in the 1.17+ protocol
|
||||
TRANSACTION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Transaction");
|
||||
//This packet was added in 1.17 protocol
|
||||
PONG = Reflection.getClassByNameWithoutException(PREFIX + "ServerboundPongPacket");
|
||||
try {
|
||||
SETTINGS = Class.forName(COMMON_PREFIX + "Settings");
|
||||
ENCHANT_ITEM = Class.forName(COMMON_PREFIX + "EnchantItem");
|
||||
|
||||
CLIENT_COMMAND = NMSUtils.getNMSClass(PREFIX + "ClientCommand");
|
||||
TRANSACTION = NMSUtils.getNMSClass(PREFIX + "Transaction");
|
||||
BLOCK_DIG = NMSUtils.getNMSClass(PREFIX + "BlockDig");
|
||||
ENTITY_ACTION = NMSUtils.getNMSClass(PREFIX + "EntityAction");
|
||||
USE_ENTITY = NMSUtils.getNMSClass(PREFIX + "UseEntity");
|
||||
WINDOW_CLICK = NMSUtils.getNMSClass(PREFIX + "WindowClick");
|
||||
STEER_VEHICLE = NMSUtils.getNMSClass(PREFIX + "SteerVehicle");
|
||||
CUSTOM_PAYLOAD = NMSUtils.getNMSClass(PREFIX + "CustomPayload");
|
||||
ARM_ANIMATION = NMSUtils.getNMSClass(PREFIX + "ArmAnimation");
|
||||
ABILITIES = NMSUtils.getNMSClass(PREFIX + "Abilities");
|
||||
HELD_ITEM_SLOT = NMSUtils.getNMSClass(PREFIX + "HeldItemSlot");
|
||||
CLOSE_WINDOW = NMSUtils.getNMSClass(PREFIX + "CloseWindow");
|
||||
TAB_COMPLETE = NMSUtils.getNMSClass(PREFIX + "TabComplete");
|
||||
CHAT = NMSUtils.getNMSClass(PREFIX + "Chat");
|
||||
SET_CREATIVE_SLOT = NMSUtils.getNMSClass(PREFIX + "SetCreativeSlot");
|
||||
KEEP_ALIVE = NMSUtils.getNMSClass(PREFIX + "KeepAlive");
|
||||
UPDATE_SIGN = NMSUtils.getNMSClassWithoutException(PREFIX + "UpdateSign");
|
||||
CLIENT_COMMAND = Class.forName(COMMON_PREFIX + "ClientCommand");
|
||||
BLOCK_DIG = Class.forName(COMMON_PREFIX + "BlockDig");
|
||||
ENTITY_ACTION = Class.forName(COMMON_PREFIX + "EntityAction");
|
||||
USE_ENTITY = Class.forName(COMMON_PREFIX + "UseEntity");
|
||||
WINDOW_CLICK = Class.forName(COMMON_PREFIX + "WindowClick");
|
||||
STEER_VEHICLE = Class.forName(COMMON_PREFIX + "SteerVehicle");
|
||||
CUSTOM_PAYLOAD = Class.forName(COMMON_PREFIX + "CustomPayload");
|
||||
ARM_ANIMATION = Class.forName(COMMON_PREFIX + "ArmAnimation");
|
||||
ABILITIES = Class.forName(COMMON_PREFIX + "Abilities");
|
||||
HELD_ITEM_SLOT = Class.forName(COMMON_PREFIX + "HeldItemSlot");
|
||||
CLOSE_WINDOW = Class.forName(COMMON_PREFIX + "CloseWindow");
|
||||
TAB_COMPLETE = Class.forName(COMMON_PREFIX + "TabComplete");
|
||||
CHAT = Class.forName(COMMON_PREFIX + "Chat");
|
||||
SET_CREATIVE_SLOT = Class.forName(COMMON_PREFIX + "SetCreativeSlot");
|
||||
KEEP_ALIVE = Class.forName(COMMON_PREFIX + "KeepAlive");
|
||||
UPDATE_SIGN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UpdateSign");
|
||||
|
||||
TELEPORT_ACCEPT = NMSUtils.getNMSClassWithoutException(PREFIX + "TeleportAccept");
|
||||
TILE_NBT_QUERY = NMSUtils.getNMSClassWithoutException(PREFIX + "TileNBTQuery");
|
||||
DIFFICULTY_CHANGE = NMSUtils.getNMSClassWithoutException(PREFIX + "DifficultyChange");
|
||||
B_EDIT = NMSUtils.getNMSClassWithoutException(PREFIX + "BEdit");
|
||||
ENTITY_NBT_QUERY = NMSUtils.getNMSClassWithoutException(PREFIX + "EntityNBTQuery");
|
||||
JIGSAW_GENERATE = NMSUtils.getNMSClassWithoutException(PREFIX + "JigsawGenerate");
|
||||
DIFFICULTY_LOCK = NMSUtils.getNMSClassWithoutException(PREFIX + "DifficultyLock");
|
||||
VEHICLE_MOVE = NMSUtils.getNMSClassWithoutException(PREFIX + "VehicleMove");
|
||||
BOAT_MOVE = NMSUtils.getNMSClassWithoutException(PREFIX + "BoatMove");
|
||||
PICK_ITEM = NMSUtils.getNMSClassWithoutException(PREFIX + "PickItem");
|
||||
AUTO_RECIPE = NMSUtils.getNMSClassWithoutException(PREFIX + "AutoRecipe");
|
||||
RECIPE_DISPLAYED = NMSUtils.getNMSClassWithoutException(PREFIX + "RecipeDisplayed");
|
||||
ITEM_NAME = NMSUtils.getNMSClassWithoutException(PREFIX + "ItemName");
|
||||
TELEPORT_ACCEPT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "TeleportAccept");
|
||||
TILE_NBT_QUERY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "TileNBTQuery");
|
||||
DIFFICULTY_CHANGE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "DifficultyChange");
|
||||
B_EDIT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "BEdit");
|
||||
ENTITY_NBT_QUERY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityNBTQuery");
|
||||
JIGSAW_GENERATE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "JigsawGenerate");
|
||||
DIFFICULTY_LOCK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "DifficultyLock");
|
||||
VEHICLE_MOVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "VehicleMove");
|
||||
BOAT_MOVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "BoatMove");
|
||||
PICK_ITEM = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "PickItem");
|
||||
AUTO_RECIPE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "AutoRecipe");
|
||||
RECIPE_DISPLAYED = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "RecipeDisplayed");
|
||||
ITEM_NAME = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ItemName");
|
||||
//1.8+
|
||||
RESOURCE_PACK_STATUS = NMSUtils.getNMSClassWithoutException(PREFIX + "ResourcePackStatus");
|
||||
RESOURCE_PACK_STATUS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ResourcePackStatus");
|
||||
|
||||
ADVANCEMENTS = NMSUtils.getNMSClassWithoutException(PREFIX + "Advancements");
|
||||
TR_SEL = NMSUtils.getNMSClassWithoutException(PREFIX + "TrSel");
|
||||
BEACON = NMSUtils.getNMSClassWithoutException(PREFIX + "Beacon");
|
||||
SET_COMMAND_BLOCK = NMSUtils.getNMSClassWithoutException(PREFIX + "SetCommandBlock");
|
||||
SET_COMMAND_MINECART = NMSUtils.getNMSClassWithoutException(PREFIX + "SetCommandMinecart");
|
||||
SET_JIGSAW = NMSUtils.getNMSClassWithoutException(PREFIX + "SetJigsaw");
|
||||
STRUCT = NMSUtils.getNMSClassWithoutException(PREFIX + "Struct");
|
||||
SPECTATE = NMSUtils.getNMSClassWithoutException(PREFIX + "Spectate");
|
||||
ADVANCEMENTS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Advancements");
|
||||
TR_SEL = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "TrSel");
|
||||
BEACON = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Beacon");
|
||||
SET_COMMAND_BLOCK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetCommandBlock");
|
||||
SET_COMMAND_MINECART = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetCommandMinecart");
|
||||
SET_JIGSAW = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetJigsaw");
|
||||
STRUCT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Struct");
|
||||
SPECTATE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Spectate");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
BLOCK_PLACE = NMSUtils.getNMSClass(PREFIX + "BlockPlace");
|
||||
USE_ITEM = NMSUtils.getNMSClass(PREFIX + "UseItem");
|
||||
BLOCK_PLACE = Class.forName(COMMON_PREFIX + "BlockPlace");
|
||||
USE_ITEM = Class.forName(COMMON_PREFIX + "UseItem");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
@@ -190,7 +241,7 @@ public class PacketTypeClasses {
|
||||
}
|
||||
|
||||
public static class Server {
|
||||
private static final String s = "PacketPlayOut";
|
||||
private static String COMMON_PREFIX, PREFIX;
|
||||
public static Class<?> SPAWN_ENTITY, SPAWN_ENTITY_EXPERIENCE_ORB, SPAWN_ENTITY_WEATHER, SPAWN_ENTITY_LIVING,
|
||||
SPAWN_ENTITY_PAINTING, SPAWN_ENTITY_SPAWN, ANIMATION, STATISTIC,
|
||||
BLOCK_BREAK, BLOCK_BREAK_ANIMATION, TILE_ENTITY_DATA, BLOCK_ACTION,
|
||||
@@ -213,115 +264,147 @@ public class PacketTypeClasses {
|
||||
SCOREBOARD_SCORE, SPAWN_POSITION, UPDATE_TIME, TITLE,
|
||||
ENTITY_SOUND, NAMED_SOUND_EFFECT, STOP_SOUND, PLAYER_LIST_HEADER_FOOTER,
|
||||
NBT_QUERY, COLLECT, ENTITY_TELEPORT, ADVANCEMENTS, UPDATE_ATTRIBUTES,
|
||||
ENTITY_EFFECT, RECIPE_UPDATE, TAGS, MAP_CHUNK_BULK, NAMED_ENTITY_SPAWN;
|
||||
ENTITY_EFFECT, RECIPE_UPDATE, TAGS, MAP_CHUNK_BULK, NAMED_ENTITY_SPAWN, PING, ADD_VIBRATION_SIGNAL,
|
||||
CLEAR_TITLES, INITIALIZE_BORDER, PLAYER_COMBAT_END, PLAYER_COMBAT_ENTER, PLAYER_COMBAT_KILL,
|
||||
SET_ACTIONBAR_TEXT, SET_BORDER_CENTER, SET_BORDER_LERP_SIZE, SET_BORDER_SIZE, SET_BORDER_WARNING_DELAY,
|
||||
SET_BORDER_WARNING_DISTANCE, SET_SUBTITLE_TEXT, SET_TITLES_ANIMATION, SET_TITLE_TEXT;
|
||||
|
||||
/**
|
||||
* Initiate all client-bound packet classes.
|
||||
*/
|
||||
public static void load() {
|
||||
SPAWN_ENTITY = NMSUtils.getNMSClassWithoutException(s + "SpawnEntity");
|
||||
SPAWN_ENTITY_EXPERIENCE_ORB = NMSUtils.getNMSClassWithoutException(s + "SpawnEntityExperienceOrb");
|
||||
SPAWN_ENTITY_WEATHER = NMSUtils.getNMSClassWithoutException(s + "SpawnEntityWeather");
|
||||
SPAWN_ENTITY_LIVING = NMSUtils.getNMSClassWithoutException(s + "SpawnEntityLiving");
|
||||
SPAWN_ENTITY_PAINTING = NMSUtils.getNMSClassWithoutException(s + "SpawnEntityPainting");
|
||||
SPAWN_ENTITY_SPAWN = NMSUtils.getNMSClassWithoutException(s + "SpawnEntitySpawn");
|
||||
ANIMATION = NMSUtils.getNMSClassWithoutException(s + "Animation");
|
||||
STATISTIC = NMSUtils.getNMSClassWithoutException(s + "Statistic");
|
||||
BLOCK_BREAK = NMSUtils.getNMSClassWithoutException(s + "BlockBreak");
|
||||
BLOCK_BREAK_ANIMATION = NMSUtils.getNMSClassWithoutException(s + "BlockBreakAnimation");
|
||||
TILE_ENTITY_DATA = NMSUtils.getNMSClassWithoutException(s + "TileEntityData");
|
||||
BLOCK_ACTION = NMSUtils.getNMSClassWithoutException(s + "BlockAction");
|
||||
BLOCK_CHANGE = NMSUtils.getNMSClassWithoutException(s + "BlockChange");
|
||||
BOSS = NMSUtils.getNMSClassWithoutException(s + "Boss");
|
||||
SERVER_DIFFICULTY = NMSUtils.getNMSClassWithoutException(s + "ServerDifficulty");
|
||||
CHAT = NMSUtils.getNMSClassWithoutException(s + "Chat");
|
||||
MULTI_BLOCK_CHANGE = NMSUtils.getNMSClassWithoutException(s + "MultiBlockChange");
|
||||
TAB_COMPLETE = NMSUtils.getNMSClassWithoutException(s + "TabComplete");
|
||||
COMMANDS = NMSUtils.getNMSClassWithoutException(s + "Commands");
|
||||
TRANSACTION = NMSUtils.getNMSClassWithoutException(s + "Transaction");
|
||||
CLOSE_WINDOW = NMSUtils.getNMSClassWithoutException(s + "CloseWindow");
|
||||
WINDOW_ITEMS = NMSUtils.getNMSClassWithoutException(s + "WindowItems");
|
||||
WINDOW_DATA = NMSUtils.getNMSClassWithoutException(s + "WindowData");
|
||||
SET_SLOT = NMSUtils.getNMSClassWithoutException(s + "SetSlot");
|
||||
SET_COOLDOWN = NMSUtils.getNMSClassWithoutException(s + "SetCooldown");
|
||||
CUSTOM_PAYLOAD = NMSUtils.getNMSClassWithoutException(s + "CustomPayload");
|
||||
CUSTOM_SOUND_EFFECT = NMSUtils.getNMSClassWithoutException(s + "CustomSoundEffect");
|
||||
KICK_DISCONNECT = NMSUtils.getNMSClassWithoutException(s + "KickDisconnect");
|
||||
ENTITY_STATUS = NMSUtils.getNMSClassWithoutException(s + "EntityStatus");
|
||||
EXPLOSION = NMSUtils.getNMSClassWithoutException(s + "Explosion");
|
||||
UNLOAD_CHUNK = NMSUtils.getNMSClassWithoutException(s + "UnloadChunk");
|
||||
GAME_STATE_CHANGE = NMSUtils.getNMSClassWithoutException(s + "GameStateChange");
|
||||
OPEN_WINDOW_HORSE = NMSUtils.getNMSClassWithoutException(s + "OpenWindowHorse");
|
||||
KEEP_ALIVE = NMSUtils.getNMSClassWithoutException(s + "KeepAlive");
|
||||
MAP_CHUNK = NMSUtils.getNMSClassWithoutException(s + "MapChunk");
|
||||
WORLD_EVENT = NMSUtils.getNMSClassWithoutException(s + "WorldEvent");
|
||||
WORLD_PARTICLES = NMSUtils.getNMSClassWithoutException(s + "WorldParticles");
|
||||
LIGHT_UPDATE = NMSUtils.getNMSClassWithoutException(s + "LightUpdate");
|
||||
LOGIN = NMSUtils.getNMSClassWithoutException(s + "Login");
|
||||
MAP = NMSUtils.getNMSClassWithoutException(s + "Map");
|
||||
OPEN_WINDOW_MERCHANT = NMSUtils.getNMSClassWithoutException(s + "OpenWindowMerchant");
|
||||
ENTITY = NMSUtils.getNMSClassWithoutException(s + "Entity");
|
||||
REL_ENTITY_MOVE = SubclassUtil.getSubClass(ENTITY, s + "RelEntityMove");
|
||||
REL_ENTITY_MOVE_LOOK = SubclassUtil.getSubClass(ENTITY, s + "RelEntityMoveLook");
|
||||
ENTITY_LOOK = SubclassUtil.getSubClass(ENTITY, s + "EntityLook");
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_17)) {
|
||||
PREFIX = "net.minecraft.network.protocol.game.";
|
||||
}
|
||||
else {
|
||||
PREFIX = ServerVersion.getNMSDirectory() + ".";
|
||||
}
|
||||
COMMON_PREFIX = PREFIX + "PacketPlayOut";
|
||||
SPAWN_ENTITY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntity");
|
||||
SPAWN_ENTITY_EXPERIENCE_ORB = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntityExperienceOrb");
|
||||
SPAWN_ENTITY_WEATHER = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntityWeather");
|
||||
SPAWN_ENTITY_LIVING = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntityLiving");
|
||||
SPAWN_ENTITY_PAINTING = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntityPainting");
|
||||
SPAWN_ENTITY_SPAWN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnEntitySpawn");
|
||||
ANIMATION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Animation");
|
||||
STATISTIC = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Statistic");
|
||||
BLOCK_BREAK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "BlockBreak");
|
||||
BLOCK_BREAK_ANIMATION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "BlockBreakAnimation");
|
||||
TILE_ENTITY_DATA = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "TileEntityData");
|
||||
BLOCK_ACTION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "BlockAction");
|
||||
BLOCK_CHANGE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "BlockChange");
|
||||
BOSS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Boss");
|
||||
SERVER_DIFFICULTY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ServerDifficulty");
|
||||
CHAT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Chat");
|
||||
MULTI_BLOCK_CHANGE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "MultiBlockChange");
|
||||
TAB_COMPLETE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "TabComplete");
|
||||
COMMANDS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Commands");
|
||||
TRANSACTION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Transaction");
|
||||
CLOSE_WINDOW = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CloseWindow");
|
||||
WINDOW_ITEMS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WindowItems");
|
||||
WINDOW_DATA = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WindowData");
|
||||
SET_SLOT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetSlot");
|
||||
SET_COOLDOWN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SetCooldown");
|
||||
CUSTOM_PAYLOAD = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CustomPayload");
|
||||
CUSTOM_SOUND_EFFECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CustomSoundEffect");
|
||||
KICK_DISCONNECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "KickDisconnect");
|
||||
ENTITY_STATUS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityStatus");
|
||||
EXPLOSION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Explosion");
|
||||
UNLOAD_CHUNK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UnloadChunk");
|
||||
GAME_STATE_CHANGE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "GameStateChange");
|
||||
OPEN_WINDOW_HORSE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "OpenWindowHorse");
|
||||
KEEP_ALIVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "KeepAlive");
|
||||
MAP_CHUNK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "MapChunk");
|
||||
WORLD_EVENT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WorldEvent");
|
||||
WORLD_PARTICLES = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WorldParticles");
|
||||
LIGHT_UPDATE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "LightUpdate");
|
||||
LOGIN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Login");
|
||||
MAP = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Map");
|
||||
OPEN_WINDOW_MERCHANT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "OpenWindowMerchant");
|
||||
ENTITY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Entity");
|
||||
REL_ENTITY_MOVE = SubclassUtil.getSubClass(ENTITY, "PacketPlayOutRelEntityMove");
|
||||
REL_ENTITY_MOVE_LOOK = SubclassUtil.getSubClass(ENTITY, "PacketPlayOutRelEntityMoveLook");
|
||||
ENTITY_LOOK = SubclassUtil.getSubClass(ENTITY, "PacketPlayOutEntityLook");
|
||||
if (REL_ENTITY_MOVE == null) {
|
||||
//is not a subclass and should be accessed normally
|
||||
REL_ENTITY_MOVE = NMSUtils.getNMSClassWithoutException(s + "RelEntityMove");
|
||||
REL_ENTITY_MOVE_LOOK = NMSUtils.getNMSClassWithoutException(s + "RelEntityMoveLook");
|
||||
ENTITY_LOOK = NMSUtils.getNMSClassWithoutException(s + "RelEntityLook");
|
||||
REL_ENTITY_MOVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "RelEntityMove");
|
||||
REL_ENTITY_MOVE_LOOK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "RelEntityMoveLook");
|
||||
ENTITY_LOOK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "RelEntityLook");
|
||||
}
|
||||
VEHICLE_MOVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "VehicleMove");
|
||||
OPEN_BOOK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "OpenBook");
|
||||
OPEN_WINDOW = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "OpenWindow");
|
||||
OPEN_SIGN_EDITOR = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "OpenSignEditor");
|
||||
AUTO_RECIPE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "AutoRecipe");
|
||||
ABILITIES = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Abilities");
|
||||
COMBAT_EVENT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "CombatEvent");
|
||||
PLAYER_INFO = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "PlayerInfo");
|
||||
LOOK_AT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "LookAt");
|
||||
POSITION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Position");
|
||||
RECIPES = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Recipes");
|
||||
ENTITY_DESTROY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityDestroy");
|
||||
REMOVE_ENTITY_EFFECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "RemoveEntityEffect");
|
||||
RESOURCE_PACK_SEND = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ResourcePackSend");
|
||||
RESPAWN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Respawn");
|
||||
ENTITY_HEAD_ROTATION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityHeadRotation");
|
||||
SELECT_ADVANCEMENT_TAB = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SelectAdvancementTab");
|
||||
WORLD_BORDER = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "WorldBorder");
|
||||
CAMERA = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Camera");
|
||||
HELD_ITEM_SLOT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "HeldItemSlot");
|
||||
VIEW_CENTRE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ViewCentre");
|
||||
VIEW_DISTANCE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ViewDistance");
|
||||
SCOREBOARD_DISPLAY_OBJECTIVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ScoreboardDisplayObjective");
|
||||
ENTITY_METADATA = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityMetadata");
|
||||
ATTACH_ENTITY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "AttachEntity");
|
||||
ENTITY_VELOCITY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityVelocity");
|
||||
ENTITY_EQUIPMENT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityEquipment");
|
||||
EXPERIENCE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Experience");
|
||||
UPDATE_HEALTH = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UpdateHealth");
|
||||
SCOREBOARD_OBJECTIVE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ScoreboardObjective");
|
||||
MOUNT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Mount");
|
||||
SCOREBOARD_TEAM = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ScoreboardTeam");
|
||||
SCOREBOARD_SCORE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "ScoreboardScore");
|
||||
SPAWN_POSITION = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "SpawnPosition");
|
||||
UPDATE_TIME = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UpdateTime");
|
||||
TITLE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Title");
|
||||
ENTITY_SOUND = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntitySound");
|
||||
NAMED_SOUND_EFFECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "NamedSoundEffect");
|
||||
STOP_SOUND = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "StopSound");
|
||||
PLAYER_LIST_HEADER_FOOTER = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "PlayerListHeaderFooter");
|
||||
NBT_QUERY = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "NBTQuery");
|
||||
COLLECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Collect");
|
||||
ENTITY_TELEPORT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityTeleport");
|
||||
ADVANCEMENTS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Advancements");
|
||||
UPDATE_ATTRIBUTES = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "UpdateAttributes");
|
||||
ENTITY_EFFECT = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "EntityEffect");
|
||||
RECIPE_UPDATE = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "RecipeUpdate");
|
||||
TAGS = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "Tags");
|
||||
MAP_CHUNK_BULK = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "MapChunkBulk");
|
||||
NAMED_ENTITY_SPAWN = Reflection.getClassByNameWithoutException(COMMON_PREFIX + "NamedEntitySpawn");
|
||||
|
||||
//These packets were added in 1.17
|
||||
PING = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundPingPacket");
|
||||
ADD_VIBRATION_SIGNAL = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundAddVibrationSignalPacket");
|
||||
CLEAR_TITLES = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundClearTitlesPacket");
|
||||
INITIALIZE_BORDER = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundInitializeBorderPacket");
|
||||
PLAYER_COMBAT_END = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundPlayerCombatEndPacket");
|
||||
PLAYER_COMBAT_ENTER = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundPlayerCombatEnterPacket");
|
||||
PLAYER_COMBAT_KILL = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundPlayerCombatKillPacket");
|
||||
SET_ACTIONBAR_TEXT = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetActionBarTextPacket");
|
||||
SET_BORDER_CENTER = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetBorderCenterPacket");
|
||||
SET_BORDER_LERP_SIZE = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetBorderLerpSizePacket");
|
||||
SET_BORDER_SIZE = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetBorderSizePacket");
|
||||
SET_BORDER_WARNING_DELAY = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetBorderWarningDelayPacket");
|
||||
SET_BORDER_WARNING_DISTANCE = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetBorderWarningDistancePacket");
|
||||
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");
|
||||
}
|
||||
VEHICLE_MOVE = NMSUtils.getNMSClassWithoutException(s + "VehicleMove");
|
||||
OPEN_BOOK = NMSUtils.getNMSClassWithoutException(s + "OpenBook");
|
||||
OPEN_WINDOW = NMSUtils.getNMSClassWithoutException(s + "OpenWindow");
|
||||
OPEN_SIGN_EDITOR = NMSUtils.getNMSClassWithoutException(s + "OpenSignEditor");
|
||||
AUTO_RECIPE = NMSUtils.getNMSClassWithoutException(s + "AutoRecipe");
|
||||
ABILITIES = NMSUtils.getNMSClassWithoutException(s + "Abilities");
|
||||
COMBAT_EVENT = NMSUtils.getNMSClassWithoutException(s + "CombatEvent");
|
||||
PLAYER_INFO = NMSUtils.getNMSClassWithoutException(s + "PlayerInfo");
|
||||
LOOK_AT = NMSUtils.getNMSClassWithoutException(s + "LookAt");
|
||||
POSITION = NMSUtils.getNMSClassWithoutException(s + "Position");
|
||||
RECIPES = NMSUtils.getNMSClassWithoutException(s + "Recipes");
|
||||
ENTITY_DESTROY = NMSUtils.getNMSClassWithoutException(s + "EntityDestroy");
|
||||
REMOVE_ENTITY_EFFECT = NMSUtils.getNMSClassWithoutException(s + "RemoveEntityEffect");
|
||||
RESOURCE_PACK_SEND = NMSUtils.getNMSClassWithoutException(s + "ResourcePackSend");
|
||||
RESPAWN = NMSUtils.getNMSClassWithoutException(s + "Respawn");
|
||||
ENTITY_HEAD_ROTATION = NMSUtils.getNMSClassWithoutException(s + "EntityHeadRotation");
|
||||
SELECT_ADVANCEMENT_TAB = NMSUtils.getNMSClassWithoutException(s + "SelectAdvancementTab");
|
||||
WORLD_BORDER = NMSUtils.getNMSClassWithoutException(s + "WorldBorder");
|
||||
CAMERA = NMSUtils.getNMSClassWithoutException(s + "Camera");
|
||||
HELD_ITEM_SLOT = NMSUtils.getNMSClassWithoutException(s + "HeldItemSlot");
|
||||
VIEW_CENTRE = NMSUtils.getNMSClassWithoutException(s + "ViewCentre");
|
||||
VIEW_DISTANCE = NMSUtils.getNMSClassWithoutException(s + "ViewDistance");
|
||||
SCOREBOARD_DISPLAY_OBJECTIVE = NMSUtils.getNMSClassWithoutException(s + "ScoreboardDisplayObjective");
|
||||
ENTITY_METADATA = NMSUtils.getNMSClassWithoutException(s + "EntityMetadata");
|
||||
ATTACH_ENTITY = NMSUtils.getNMSClassWithoutException(s + "AttachEntity");
|
||||
ENTITY_VELOCITY = NMSUtils.getNMSClassWithoutException(s + "EntityVelocity");
|
||||
ENTITY_EQUIPMENT = NMSUtils.getNMSClassWithoutException(s + "EntityEquipment");
|
||||
EXPERIENCE = NMSUtils.getNMSClassWithoutException(s + "Experience");
|
||||
UPDATE_HEALTH = NMSUtils.getNMSClassWithoutException(s + "UpdateHealth");
|
||||
SCOREBOARD_OBJECTIVE = NMSUtils.getNMSClassWithoutException(s + "ScoreboardObjective");
|
||||
MOUNT = NMSUtils.getNMSClassWithoutException(s + "Mount");
|
||||
SCOREBOARD_TEAM = NMSUtils.getNMSClassWithoutException(s + "ScoreboardTeam");
|
||||
SCOREBOARD_SCORE = NMSUtils.getNMSClassWithoutException(s + "ScoreboardScore");
|
||||
SPAWN_POSITION = NMSUtils.getNMSClassWithoutException(s + "SpawnPosition");
|
||||
UPDATE_TIME = NMSUtils.getNMSClassWithoutException(s + "UpdateTime");
|
||||
TITLE = NMSUtils.getNMSClassWithoutException(s + "Title");
|
||||
ENTITY_SOUND = NMSUtils.getNMSClassWithoutException(s + "EntitySound");
|
||||
NAMED_SOUND_EFFECT = NMSUtils.getNMSClassWithoutException(s + "NamedSoundEffect");
|
||||
STOP_SOUND = NMSUtils.getNMSClassWithoutException(s + "StopSound");
|
||||
PLAYER_LIST_HEADER_FOOTER = NMSUtils.getNMSClassWithoutException(s + "PlayerListHeaderFooter");
|
||||
NBT_QUERY = NMSUtils.getNMSClassWithoutException(s + "NBTQuery");
|
||||
COLLECT = NMSUtils.getNMSClassWithoutException(s + "Collect");
|
||||
ENTITY_TELEPORT = NMSUtils.getNMSClassWithoutException(s + "EntityTeleport");
|
||||
ADVANCEMENTS = NMSUtils.getNMSClassWithoutException(s + "Advancements");
|
||||
UPDATE_ATTRIBUTES = NMSUtils.getNMSClassWithoutException(s + "UpdateAttributes");
|
||||
ENTITY_EFFECT = NMSUtils.getNMSClassWithoutException(s + "EntityEffect");
|
||||
RECIPE_UPDATE = NMSUtils.getNMSClassWithoutException(s + "RecipeUpdate");
|
||||
TAGS = NMSUtils.getNMSClassWithoutException(s + "Tags");
|
||||
MAP_CHUNK_BULK = NMSUtils.getNMSClassWithoutException(s + "MapChunkBulk");
|
||||
NAMED_ENTITY_SPAWN = NMSUtils.getNMSClassWithoutException(s + "NamedEntitySpawn");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,10 +51,10 @@ 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];
|
||||
private static byte isVersion_1_17 = -1;
|
||||
public static ServerVersion version;
|
||||
protected final NMSPacket packet;
|
||||
private final Class<?> packetClass;
|
||||
@@ -80,15 +81,15 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
}
|
||||
|
||||
private void load0() {
|
||||
if (!isSupported()) {
|
||||
throw new WrapperUnsupportedUsageException(getClass());
|
||||
}
|
||||
final Class<? extends WrappedPacket> clazz = getClass();
|
||||
if (!LOADED_WRAPPERS.containsKey(clazz)) {
|
||||
if (!isSupported()) {
|
||||
throw new WrapperUnsupportedUsageException(getClass());
|
||||
}
|
||||
try {
|
||||
load();
|
||||
} catch (Exception ex) {
|
||||
String wrapperName = ClassUtil.getClassSimpleName(getClass());
|
||||
String wrapperName = ClassUtil.getClassSimpleName(clazz);
|
||||
PacketEvents.get().getPlugin().getLogger()
|
||||
.log(Level.SEVERE, "PacketEvents found an exception while loading the " + wrapperName + " packet wrapper. Please report this bug! Tell us about your server version, spigot and code(of you using the wrapper)", ex);
|
||||
LOADED_WRAPPERS.put(clazz, false);
|
||||
@@ -382,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!");
|
||||
@@ -390,12 +394,15 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
|
||||
@Override
|
||||
public void writeEnumConstant(int index, Enum<?> enumConstant) {
|
||||
write(enumConstant.getClass(), index, enumConstant);
|
||||
try {
|
||||
write(enumConstant.getClass(), index, enumConstant);
|
||||
} catch (WrapperFieldNotFoundException ex) {
|
||||
write(enumConstant.getDeclaringClass(), index, enumConstant);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(Class<?> type, int index, Object value) throws WrapperFieldNotFoundException {
|
||||
Field field = getField(type, index);
|
||||
//Reflection.getFieldWithoutFinalModifier(field);
|
||||
if (field == null) {
|
||||
throw new WrapperFieldNotFoundException(packetClass, type, index);
|
||||
}
|
||||
@@ -409,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();
|
||||
@@ -434,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.valueOf(enumConst.name());
|
||||
int targetIndex = enumConst.ordinal() - 1;
|
||||
if (targetIndex == -1) {
|
||||
return null;
|
||||
}
|
||||
return GameMode.values()[targetIndex];
|
||||
}
|
||||
|
||||
public void writeGameMode(int index, GameMode gameMode) {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(NMSUtils.enumGameModeClass, gameMode.name());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -487,6 +513,27 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
|
||||
write(NMSUtils.iChatBaseComponentClass, index, iChatBaseComponent);
|
||||
}
|
||||
|
||||
public String readMinecraftKey(int index) {
|
||||
if (isVersion_1_17 == -1) {
|
||||
isVersion_1_17 = (byte) (version.isNewerThanOrEquals(ServerVersion.v_1_17) ? 1 : 0);
|
||||
}
|
||||
int namespaceIndex = isVersion_1_17 == 1 ? 2 : 0;
|
||||
int keyIndex = isVersion_1_17 == 1 ? 3 : 1;
|
||||
Object minecraftKey = readObject(index, NMSUtils.minecraftKeyClass);
|
||||
WrappedPacket minecraftKeyWrapper = new WrappedPacket(new NMSPacket(minecraftKey));
|
||||
return minecraftKeyWrapper.readString(namespaceIndex) + ":" + minecraftKeyWrapper.readString(keyIndex);
|
||||
}
|
||||
|
||||
public void writeMinecraftKey(int index, String content) {
|
||||
Object minecraftKey = null;
|
||||
try {
|
||||
minecraftKey = NMSUtils.minecraftKeyConstructor.newInstance(content);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
write(NMSUtils.minecraftKeyClass, index, minecraftKey);
|
||||
}
|
||||
|
||||
public List<Object> readList(int index) {
|
||||
return read(index, List.class);
|
||||
}
|
||||
|
||||
+7
-2
@@ -18,6 +18,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.api.helper;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
@@ -72,11 +73,15 @@ public abstract class WrappedPacketEntityAbstraction extends WrappedPacket {
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return entity = NMSUtils.getEntityById(world, getEntityId());
|
||||
return PacketEvents.get().getServerUtils().getEntityById(world, getEntityId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Entity getEntity() {
|
||||
return getEntity(null);
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
return PacketEvents.get().getServerUtils().getEntityById(getEntityId());
|
||||
}
|
||||
|
||||
public void setEntity(@NotNull Entity entity) {
|
||||
|
||||
+11
-5
@@ -20,27 +20,33 @@ package io.github.retrooper.packetevents.packetwrappers.handshaking.setprotocol;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
public class WrappedPacketHandshakingInSetProtocol extends WrappedPacket {
|
||||
|
||||
private static boolean v_1_17;
|
||||
public WrappedPacketHandshakingInSetProtocol(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return readInt(0);
|
||||
return readInt(v_1_17 ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setProtocolVersion(int protocolVersion) {
|
||||
writeInt(0, protocolVersion);
|
||||
writeInt(v_1_17 ? 1 : 0, protocolVersion);
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return readInt(1);
|
||||
return readInt(v_1_17 ? 2 : 1);
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
writeInt(1, port);
|
||||
writeInt(v_1_17 ? 2 : 1, port);
|
||||
}
|
||||
|
||||
public String getHostName() {
|
||||
|
||||
+8
-2
@@ -25,16 +25,22 @@ import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
public class WrappedPacketLoginInCustomPayload extends WrappedPacket {
|
||||
private static boolean v_1_17;
|
||||
public WrappedPacketLoginInCustomPayload(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
|
||||
public int getMessageId() {
|
||||
return readInt(0);
|
||||
return readInt(v_1_17 ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setMessageId(int id) {
|
||||
writeInt(0, id);
|
||||
writeInt(v_1_17 ? 1 : 0, id);
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
|
||||
+2
@@ -30,10 +30,12 @@ public class WrappedPacketLoginInStart extends WrappedPacket {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
//TODO Allow accessing game profile property
|
||||
public WrappedGameProfile getGameProfile() {
|
||||
return GameProfileUtil.getWrappedGameProfile(readObject(0, NMSUtils.gameProfileClass));
|
||||
}
|
||||
|
||||
//TODO Add support for game profile property
|
||||
public void setGameProfile(WrappedGameProfile wrappedGameProfile) {
|
||||
Object gameProfile = GameProfileUtil.getGameProfile(wrappedGameProfile.getId(), wrappedGameProfile.getName());
|
||||
write(NMSUtils.gameProfileClass, 0, gameProfile);
|
||||
|
||||
+27
-24
@@ -24,11 +24,12 @@ 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 java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> constructor;
|
||||
private static Constructor<?> packetDataSerializerConstructor;
|
||||
private int messageID;
|
||||
@@ -39,8 +40,15 @@ public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketLoginOutCustomPayload(int messageID, String channelName, byte[] data) {
|
||||
this.messageID = messageID;
|
||||
this.channelName = channelName;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
Class<?> packetClass = PacketTypeClasses.Login.Server.CUSTOM_PAYLOAD;
|
||||
if (packetClass != null) {
|
||||
try {
|
||||
@@ -52,7 +60,7 @@ public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements
|
||||
}
|
||||
|
||||
try {
|
||||
constructor = packetClass.getConstructor();
|
||||
constructor = packetClass.getConstructor(int.class, NMSUtils.minecraftKeyClass, NMSUtils.packetDataSerializerClass);
|
||||
} catch (NoSuchMethodException e3) {
|
||||
throw new IllegalStateException("PacketEvents is unable to resolve the PacketPlayOutCustomPayload constructor.");
|
||||
}
|
||||
@@ -61,14 +69,14 @@ public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements
|
||||
|
||||
public int getMessageId() {
|
||||
if (packet != null) {
|
||||
return readInt(0);
|
||||
return readInt(v_1_17 ? 1 : 0);
|
||||
}
|
||||
return messageID;
|
||||
}
|
||||
|
||||
public void setMessageId(int messageID) {
|
||||
if (packet != null) {
|
||||
writeInt(0, messageID);
|
||||
writeInt(v_1_17 ? 1 : 0, messageID);
|
||||
} else {
|
||||
this.messageID = messageID;
|
||||
}
|
||||
@@ -76,16 +84,16 @@ public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements
|
||||
|
||||
public String getChannelName() {
|
||||
if (packet != null) {
|
||||
Object minecraftKey = readObject(0, NMSUtils.minecraftKeyClass);
|
||||
return NMSUtils.getStringFromMinecraftKey(minecraftKey);
|
||||
return readMinecraftKey(0);
|
||||
}
|
||||
else {
|
||||
return channelName;
|
||||
}
|
||||
return channelName;
|
||||
}
|
||||
|
||||
public void setChannelName(String channelName) {
|
||||
if (packet != null) {
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKey(channelName);
|
||||
writeObject(0, minecraftKey);
|
||||
writeMinecraftKey(0, channelName);
|
||||
} else {
|
||||
this.channelName = channelName;
|
||||
}
|
||||
@@ -97,12 +105,17 @@ public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements
|
||||
WrappedPacket byteBufWrapper = new WrappedPacket(new NMSPacket(dataSerializer));
|
||||
Object byteBuf = byteBufWrapper.readObject(0, NMSUtils.byteBufClass);
|
||||
return PacketEvents.get().getByteBufUtil().getBytes(byteBuf);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(byte[] data) {
|
||||
PacketEvents.get().getByteBufUtil().setBytes(getBuffer(), data);
|
||||
if (packet != null) {
|
||||
PacketEvents.get().getByteBufUtil().setBytes(getBuffer(), data);
|
||||
} else {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
private Object getBuffer() {
|
||||
@@ -114,19 +127,9 @@ public class WrappedPacketLoginOutCustomPayload extends WrappedPacket implements
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object byteBufObject = PacketEvents.get().getByteBufUtil().newByteBuf(data);
|
||||
try {
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKey(channelName);
|
||||
Object dataSerializer = packetDataSerializerConstructor.newInstance(byteBufObject);
|
||||
Object packetInstance = constructor.newInstance();
|
||||
WrappedPacket packetWrapper = new WrappedPacket(new NMSPacket(packetInstance));
|
||||
packetWrapper.writeInt(0, messageID);
|
||||
packetWrapper.writeObject(0, minecraftKey);
|
||||
packetWrapper.writeObject(0, dataSerializer);
|
||||
return packetInstance;
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKeyNew(channelName);
|
||||
Object dataSerializer = packetDataSerializerConstructor.newInstance(byteBufObject);
|
||||
return constructor.newInstance(getMessageId(), minecraftKey, dataSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-8
@@ -27,23 +27,22 @@ import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketLoginOutDisconnect extends WrappedPacket implements SendableWrapper {
|
||||
|
||||
private static Constructor<?> packetConstructor;
|
||||
private String reason;
|
||||
|
||||
public WrappedPacketLoginOutDisconnect(final NMSPacket packet) {
|
||||
public WrappedPacketLoginOutDisconnect(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketLoginOutDisconnect(final String reason) {
|
||||
public WrappedPacketLoginOutDisconnect(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Login.Server.DISCONNECT.getConstructors()[1];
|
||||
} catch (final Exception e) {
|
||||
packetConstructor = PacketTypeClasses.Login.Server.DISCONNECT.getConstructor(NMSUtils.iChatBaseComponentClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -66,9 +65,7 @@ public class WrappedPacketLoginOutDisconnect extends WrappedPacket implements Se
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
return packetConstructor.newInstance(
|
||||
NMSUtils.generateIChatBaseComponent(getReason())
|
||||
);
|
||||
return packetConstructor.newInstance(NMSUtils.generateIChatBaseComponent(getReason()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+29
-4
@@ -21,14 +21,24 @@ package io.github.retrooper.packetevents.packetwrappers.login.out.encryptionbegi
|
||||
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.server.ServerVersion;
|
||||
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PublicKey;
|
||||
import java.security.spec.EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
|
||||
public class WrappedPacketLoginOutEncryptionBegin extends WrappedPacket {
|
||||
private static boolean v_1_17;
|
||||
public WrappedPacketLoginOutEncryptionBegin(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
|
||||
public String getEncodedString() {
|
||||
return readString(0);
|
||||
}
|
||||
@@ -38,19 +48,34 @@ public class WrappedPacketLoginOutEncryptionBegin extends WrappedPacket {
|
||||
}
|
||||
|
||||
public PublicKey getPublicKey() {
|
||||
return readObject(1, PublicKey.class);
|
||||
return v_1_17 ? encrypt(readByteArray(0)) : readObject(0, PublicKey.class);
|
||||
}
|
||||
|
||||
public void setPublicKey(PublicKey key) {
|
||||
writeObject(0, key);
|
||||
if (v_1_17) {
|
||||
writeByteArray(0, key.getEncoded());
|
||||
} else {
|
||||
writeObject(0, key);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getVerifyToken() {
|
||||
return readByteArray(0);
|
||||
return readByteArray(v_1_17 ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setVerifyToken(byte[] verifyToken) {
|
||||
writeByteArray(0, verifyToken);
|
||||
writeByteArray(v_1_17 ? 1 : 0, verifyToken);
|
||||
}
|
||||
|
||||
private PublicKey encrypt(byte[] bytes) {
|
||||
try {
|
||||
EncodedKeySpec encodedKeySpec = new X509EncodedKeySpec(bytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
return keyFactory.generatePublic(encodedKeySpec);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-8
@@ -25,9 +25,7 @@ import io.github.retrooper.packetevents.packetwrappers.api.SendableWrapper;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
//This packet does not exist on 1.7.10
|
||||
public class WrappedPacketLoginOutSetCompression extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> constructor;
|
||||
private int threshold;
|
||||
@@ -73,12 +71,7 @@ public class WrappedPacketLoginOutSetCompression extends WrappedPacket implement
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
try {
|
||||
return constructor.newInstance(getThreshold());
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return constructor.newInstance(getThreshold());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -29,7 +29,6 @@ import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketLoginOutSuccess extends WrappedPacket implements SendableWrapper {
|
||||
|
||||
private static Constructor<?> packetConstructor;
|
||||
private WrappedGameProfile wrappedGameProfile;
|
||||
|
||||
@@ -50,6 +49,7 @@ public class WrappedPacketLoginOutSuccess extends WrappedPacket implements Senda
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Support property reading in wrapped game profile
|
||||
public WrappedGameProfile getGameProfile() {
|
||||
if (packet != null) {
|
||||
return GameProfileUtil.getWrappedGameProfile(readObject(0, NMSUtils.gameProfileClass));
|
||||
@@ -58,6 +58,7 @@ public class WrappedPacketLoginOutSuccess extends WrappedPacket implements Senda
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Support writing property in wrapped game profile
|
||||
public void setGameProfile(final WrappedGameProfile wrappedGameProfile) {
|
||||
if (packet != null) {
|
||||
final Object gameProfile = GameProfileUtil.getGameProfile(wrappedGameProfile.getId(), wrappedGameProfile.getName());
|
||||
@@ -70,9 +71,8 @@ public class WrappedPacketLoginOutSuccess extends WrappedPacket implements Senda
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
WrappedGameProfile gp = getGameProfile();
|
||||
return packetConstructor.newInstance(
|
||||
GameProfileUtil.getGameProfile(gp.getId(), gp.getName())
|
||||
);
|
||||
//TODO Support writing property in wrapped game profile
|
||||
return packetConstructor.newInstance(GameProfileUtil.getGameProfile(gp.getId(), gp.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+13
-6
@@ -26,23 +26,30 @@ import io.github.retrooper.packetevents.utils.player.Hand;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
public class WrappedPacketInArmAnimation extends WrappedPacket {
|
||||
private static boolean v_1_9;
|
||||
public WrappedPacketInArmAnimation(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_9 = version.isNewerThanOrEquals(ServerVersion.v_1_9);
|
||||
}
|
||||
|
||||
public Hand getHand() {
|
||||
if (version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
return Hand.MAIN_HAND;
|
||||
} else {
|
||||
if (v_1_9) {
|
||||
Enum<?> enumConst = readEnumConstant(0, NMSUtils.enumHandClass);
|
||||
return Hand.valueOf(enumConst.name());
|
||||
return Hand.values()[enumConst.ordinal()];
|
||||
}
|
||||
else {
|
||||
return Hand.MAIN_HAND;
|
||||
}
|
||||
}
|
||||
|
||||
public void setHand(Hand hand) {
|
||||
//Optimize to do nothing on legacy versions. The protocol of the legacy versions only support one hand, the main hand.
|
||||
if (version.isNewerThan(ServerVersion.v_1_8_8)) {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(NMSUtils.enumHandClass, hand.name());
|
||||
if (v_1_9) {
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumHandClass, hand.ordinal());
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-14
@@ -82,7 +82,7 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
return Direction.getDirection(readInt(3));
|
||||
} else {
|
||||
Enum<?> enumDir = readEnumConstant(0, NMSUtils.enumDirectionClass);
|
||||
return Direction.valueOf(enumDir.name());
|
||||
return Direction.values()[enumDir.ordinal()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
if (isVersionLowerThan_v_1_8) {
|
||||
writeInt(3, direction.getFaceValue());
|
||||
} else {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(NMSUtils.enumDirectionClass, direction.name());
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumDirectionClass, direction.ordinal());
|
||||
write(NMSUtils.enumDirectionClass, 0, enumConst);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
if (isVersionLowerThan_v_1_8) {
|
||||
return PlayerDigType.values()[readInt(4)];
|
||||
} else {
|
||||
return PlayerDigType.valueOf(readObject(0, digTypeClass).name());
|
||||
return PlayerDigType.values()[readEnumConstant(0, digTypeClass).ordinal()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
if (isVersionLowerThan_v_1_8) {
|
||||
writeInt(4, type.ordinal());
|
||||
} else {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(digTypeClass, type.name());
|
||||
write(digTypeClass, 0, enumConst);
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(digTypeClass, type.ordinal());
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,14 +124,6 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
|
||||
DROP_ALL_ITEMS,
|
||||
DROP_ITEM,
|
||||
RELEASE_USE_ITEM,
|
||||
|
||||
/**
|
||||
* Doesn't exist on the newest versions.
|
||||
*/
|
||||
@Deprecated
|
||||
SWAP_HELD_ITEMS,
|
||||
|
||||
SWAP_ITEM_WITH_OFFHAND,
|
||||
UNKNOWN
|
||||
SWAP_ITEM_WITH_OFFHAND
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -53,19 +53,20 @@ public final class WrappedPacketInBlockPlace extends WrappedPacket {
|
||||
}
|
||||
|
||||
public Hand getHand() {
|
||||
if (version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
return Hand.MAIN_HAND;
|
||||
} else {
|
||||
if (newerThan_v_1_8_8) {
|
||||
Enum<?> enumConst = readEnumConstant(handEnumIndex, NMSUtils.enumHandClass);
|
||||
return Hand.valueOf(enumConst.name());
|
||||
return Hand.values()[enumConst.ordinal()];
|
||||
}
|
||||
else {
|
||||
return Hand.MAIN_HAND;
|
||||
}
|
||||
}
|
||||
|
||||
public void setHand(Hand hand) {
|
||||
//Optimize to do nothing on legacy versions. The protocol of the legacy versions only support one hand, the main hand.
|
||||
if (version.isNewerThan(ServerVersion.v_1_8_8)) {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(NMSUtils.enumHandClass, hand.name());
|
||||
write(NMSUtils.enumHandClass, handEnumIndex, enumConst);
|
||||
if (newerThan_v_1_8_8) {
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumHandClass, hand.ordinal());
|
||||
writeEnumConstant(handEnumIndex, enumConst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +150,7 @@ public final class WrappedPacketInBlockPlace extends WrappedPacket {
|
||||
|
||||
public void setItemStack(ItemStack stack) {
|
||||
if (newerThan_v_1_8_8) {
|
||||
|
||||
//Newer versions do not contain an itemstack
|
||||
} else if (newerThan_v_1_7_10) {
|
||||
WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
|
||||
blockPlace_1_8.setItemStack(stack);
|
||||
|
||||
-1
@@ -34,7 +34,6 @@ final class WrappedPacketInBlockPlace_1_7_10 extends WrappedPacket {
|
||||
}
|
||||
|
||||
public void setBlockPosition(Vector3i blockPos) {
|
||||
Vector3i currentBlockPos = getBlockPosition();
|
||||
writeInt(0, blockPos.x);
|
||||
writeInt(1, blockPos.y);
|
||||
writeInt(2, blockPos.z);
|
||||
|
||||
+14
-31
@@ -29,74 +29,57 @@ import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
final class WrappedPacketInBlockPlace_1_9 extends WrappedPacket {
|
||||
private static Class<?> movingObjectPositionBlockClass;
|
||||
private Object movingObjPos;
|
||||
|
||||
public WrappedPacketInBlockPlace_1_9(final NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
movingObjectPositionBlockClass = NMSUtils.getNMSClassWithoutException("MovingObjectPositionBlock");
|
||||
}
|
||||
|
||||
public Vector3i getBlockPosition() {
|
||||
Vector3i blockPos = new Vector3i();
|
||||
Object blockPosObj;
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
blockPosObj = readObject(0, NMSUtils.blockPosClass);
|
||||
if (NMSUtils.movingObjectPositionBlockClass == null) {
|
||||
return readBlockPosition(0);
|
||||
} else {
|
||||
if (movingObjPos == null) {
|
||||
movingObjPos = readObject(0, movingObjectPositionBlockClass);
|
||||
movingObjPos = readObject(0, NMSUtils.movingObjectPositionBlockClass);
|
||||
}
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(new NMSPacket(movingObjPos));
|
||||
blockPosObj = movingObjectPosWrapper.readObject(0, NMSUtils.blockPosClass);
|
||||
return movingObjectPosWrapper.readBlockPosition(0);
|
||||
}
|
||||
try {
|
||||
blockPos.x = (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
|
||||
blockPos.y = (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
|
||||
blockPos.z = (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return blockPos;
|
||||
}
|
||||
|
||||
public void setBlockPosition(Vector3i blockPos) {
|
||||
Object blockPosObj = NMSUtils.generateNMSBlockPos(blockPos);
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
write(NMSUtils.blockPosClass, 0, blockPosObj);
|
||||
if (NMSUtils.movingObjectPositionBlockClass == null) {
|
||||
writeBlockPosition(0, blockPos);
|
||||
} else {
|
||||
if (movingObjPos == null) {
|
||||
movingObjPos = readObject(0, movingObjectPositionBlockClass);
|
||||
movingObjPos = readObject(0, NMSUtils.movingObjectPositionBlockClass);
|
||||
}
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(new NMSPacket(movingObjPos));
|
||||
movingObjectPosWrapper.write(NMSUtils.blockPosClass, 0, blockPos);
|
||||
movingObjectPosWrapper.writeBlockPosition(0, blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
public Direction getDirection() {
|
||||
Enum<?> enumConst;
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
if (NMSUtils.movingObjectPositionBlockClass == null) {
|
||||
enumConst = readEnumConstant(0, NMSUtils.enumDirectionClass);
|
||||
} else {
|
||||
if (movingObjPos == null) {
|
||||
movingObjPos = readObject(0, movingObjectPositionBlockClass);
|
||||
movingObjPos = readObject(0, NMSUtils.movingObjectPositionBlockClass);
|
||||
}
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(new NMSPacket(movingObjPos));
|
||||
enumConst = movingObjectPosWrapper.readEnumConstant(0, NMSUtils.enumDirectionClass);
|
||||
}
|
||||
return Direction.valueOf(enumConst.name());
|
||||
return Direction.values()[enumConst.ordinal()];
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(NMSUtils.enumDirectionClass, direction.name());
|
||||
if (movingObjectPositionBlockClass == null) {
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumDirectionClass, direction.ordinal());
|
||||
if (NMSUtils.movingObjectPositionBlockClass == null) {
|
||||
writeEnumConstant(0, enumConst);
|
||||
} else {
|
||||
if (movingObjPos == null) {
|
||||
movingObjPos = readObject(0, movingObjectPositionBlockClass);
|
||||
movingObjPos = readObject(0, NMSUtils.movingObjectPositionBlockClass);
|
||||
}
|
||||
WrappedPacket movingObjectPosWrapper = new WrappedPacket(new NMSPacket(movingObjPos));
|
||||
movingObjectPosWrapper.writeEnumConstant(0, enumConst);
|
||||
|
||||
+1
-7
@@ -22,21 +22,15 @@ import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
public final class WrappedPacketInChat extends WrappedPacket {
|
||||
private String message = null;
|
||||
|
||||
public WrappedPacketInChat(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
return message = readString(0);
|
||||
return readString(0);
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
writeString(0, message);
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -27,6 +27,7 @@ import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
public final class WrappedPacketInClientCommand extends WrappedPacket {
|
||||
private static boolean v_1_16;
|
||||
private static Class<? extends Enum<?>> enumClientCommandClass;
|
||||
|
||||
public WrappedPacketInClientCommand(NMSPacket packet) {
|
||||
@@ -35,26 +36,25 @@ public final class WrappedPacketInClientCommand extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Client.CLIENT_COMMAND;
|
||||
try {
|
||||
enumClientCommandClass = NMSUtils.getNMSEnumClass("EnumClientCommand");
|
||||
} catch (ClassNotFoundException e) {
|
||||
v_1_16 = version.isNewerThanOrEquals(ServerVersion.v_1_16);
|
||||
enumClientCommandClass = NMSUtils.getNMSEnumClassWithoutException("EnumClientCommand");
|
||||
if (enumClientCommandClass == null) {
|
||||
//Probably a subclass
|
||||
enumClientCommandClass = SubclassUtil.getEnumSubClass(packetClass, "EnumClientCommand");
|
||||
enumClientCommandClass = SubclassUtil.getEnumSubClass(PacketTypeClasses.Play.Client.CLIENT_COMMAND, "EnumClientCommand");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ClientCommand getClientCommand() {
|
||||
Enum<?> emumConst = readEnumConstant(0, enumClientCommandClass);
|
||||
return ClientCommand.valueOf(emumConst.name());
|
||||
Enum<?> enumConst = readEnumConstant(0, enumClientCommandClass);
|
||||
return ClientCommand.values()[enumConst.ordinal()];
|
||||
}
|
||||
|
||||
public void setClientCommand(ClientCommand command) throws UnsupportedOperationException {
|
||||
if (command == ClientCommand.OPEN_INVENTORY_ACHIEVEMENT && version.isNewerThan(ServerVersion.v_1_16)) {
|
||||
if (command == ClientCommand.OPEN_INVENTORY_ACHIEVEMENT && v_1_16) {
|
||||
throwUnsupportedOperation(command);
|
||||
}
|
||||
Enum<?> enumConst = EnumUtil.valueOf(enumClientCommandClass, command.name());
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(enumClientCommandClass, command.ordinal());
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
|
||||
|
||||
+11
-12
@@ -24,6 +24,8 @@ import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
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.entity.Player;
|
||||
|
||||
public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
private static boolean strPresent, byteArrayPresent;
|
||||
@@ -34,26 +36,23 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Client.CUSTOM_PAYLOAD;
|
||||
strPresent = Reflection.getField(packetClass, String.class, 0) != null;
|
||||
byteArrayPresent = Reflection.getField(packetClass, byte[].class, 0) != null;
|
||||
strPresent = Reflection.getField(PacketTypeClasses.Play.Client.CUSTOM_PAYLOAD, String.class, 0) != null;
|
||||
byteArrayPresent = Reflection.getField(PacketTypeClasses.Play.Client.CUSTOM_PAYLOAD, byte[].class, 0) != null;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
public String getChannelName() {
|
||||
if (strPresent) {
|
||||
return readString(0);
|
||||
} else {
|
||||
Object minecraftKey = readObject(0, NMSUtils.minecraftKeyClass);
|
||||
return NMSUtils.getStringFromMinecraftKey(minecraftKey);
|
||||
return readMinecraftKey(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
public void setChannelName(String channelName) {
|
||||
if (strPresent) {
|
||||
writeString(0, tag);
|
||||
writeString(0, channelName);
|
||||
} else {
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKey(tag);
|
||||
write(NMSUtils.minecraftKeyClass, 0, minecraftKey);
|
||||
writeMinecraftKey(1, channelName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +80,13 @@ public final class WrappedPacketInCustomPayload extends WrappedPacket {
|
||||
}
|
||||
|
||||
public void retain() {
|
||||
if (!byteArrayPresent) {
|
||||
if (packet != null && !byteArrayPresent) {
|
||||
PacketEvents.get().getByteBufUtil().retain(getBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
if (!byteArrayPresent) {
|
||||
if (packet != null && !byteArrayPresent) {
|
||||
PacketEvents.get().getByteBufUtil().release(getBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -21,13 +21,14 @@ package io.github.retrooper.packetevents.packetwrappers.play.in.entityaction;
|
||||
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.helper.WrappedPacketEntityAbstraction;
|
||||
import io.github.retrooper.packetevents.utils.enums.EnumUtil;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
public final class WrappedPacketInEntityAction extends WrappedPacketEntityAbstraction {
|
||||
private static Class<? extends Enum<?>> enumPlayerActionClass;
|
||||
private static boolean newerThan_v_1_8_8;
|
||||
|
||||
@@ -51,6 +52,9 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
return PlayerAction.getByActionValue((byte) (animationIndex));
|
||||
} else {
|
||||
Enum<?> enumConst = readEnumConstant(0, enumPlayerActionClass);
|
||||
if (newerThan_v_1_8_8) {
|
||||
return PlayerAction.getByActionValue((byte) enumConst.ordinal());
|
||||
}
|
||||
return PlayerAction.getByName(enumConst.name());
|
||||
}
|
||||
}
|
||||
@@ -65,7 +69,7 @@ public final class WrappedPacketInEntityAction extends WrappedPacket {
|
||||
if (action == PlayerAction.RIDING_JUMP) {
|
||||
throwUnsupportedOperation(action);
|
||||
}
|
||||
enumConst = EnumUtil.valueByIndex(enumPlayerActionClass, action.ordinal());
|
||||
enumConst = EnumUtil.valueByIndex(enumPlayerActionClass, action.getActionValue());
|
||||
|
||||
} else {
|
||||
enumConst = EnumUtil.valueOf(enumPlayerActionClass, action.name());
|
||||
|
||||
+46
-26
@@ -58,6 +58,46 @@ public class WrappedPacketInFlying extends WrappedPacket {
|
||||
writeDouble(2, z);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isPosition() {
|
||||
return readBoolean(1);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setIsPosition(boolean isPosition) {
|
||||
writeBoolean(1, isPosition);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isLook() {
|
||||
return readBoolean(2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setIsLook(boolean isLook) {
|
||||
writeBoolean(2, isLook);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasPositionChanged() {
|
||||
return readBoolean(1);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setPositionChanged(boolean positionChanged) {
|
||||
writeBoolean(1, positionChanged);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasRotationChanged() {
|
||||
return readBoolean(2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setRotationChanged(boolean rotationChanged) {
|
||||
writeBoolean(2, rotationChanged);
|
||||
}
|
||||
|
||||
public Vector3d getPosition() {
|
||||
return new Vector3d(readDouble(0), readDouble(1), readDouble(2));
|
||||
}
|
||||
@@ -92,39 +132,19 @@ public class WrappedPacketInFlying extends WrappedPacket {
|
||||
writeBoolean(0, onGround);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isPosition() {
|
||||
public boolean isMoving() {
|
||||
return readBoolean(1);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setIsPosition(boolean isPosition) {
|
||||
writeBoolean(1, isPosition);
|
||||
public void setMoving(boolean moving) {
|
||||
writeBoolean(1, moving);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isLook() {
|
||||
public boolean isRotating() {
|
||||
return readBoolean(2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setIsLook(boolean isLook) {
|
||||
writeBoolean(2, isLook);
|
||||
}
|
||||
|
||||
public boolean hasPositionChanged() {
|
||||
return readBoolean(1);
|
||||
}
|
||||
|
||||
public void setPositionChanged(boolean positionChanged) {
|
||||
writeBoolean(1, positionChanged);
|
||||
}
|
||||
|
||||
public boolean hasRotationChanged() {
|
||||
return readBoolean(2);
|
||||
}
|
||||
|
||||
public void setRotationChanged(boolean rotationChanged) {
|
||||
writeBoolean(2, rotationChanged);
|
||||
public void setRotating(boolean rotating) {
|
||||
writeBoolean(2, rotating);
|
||||
}
|
||||
}
|
||||
+19
-2
@@ -1,4 +1,22 @@
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.jigsawgenerate;
|
||||
/*
|
||||
* 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.in.jigsawgenerate;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
@@ -8,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 {
|
||||
|
||||
+27
-14
@@ -16,28 +16,41 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.multiblockchange;
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.in.pong;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
//TODO finish this wrapper
|
||||
class WrappedPacketOutMultiBlockChange extends WrappedPacket {
|
||||
public class WrappedPacketInPong extends WrappedPacket {
|
||||
private int id;
|
||||
|
||||
public WrappedPacketOutMultiBlockChange(NMSPacket packet) {
|
||||
public WrappedPacketInPong(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;
|
||||
public WrappedPacketInPong(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
if (packet != null) {
|
||||
return readInt(0);
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
if (packet != null) {
|
||||
writeInt(0, id);
|
||||
} else {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -39,11 +39,11 @@ public class WrappedPacketInResourcePackStatus extends WrappedPacket {
|
||||
|
||||
public ResourcePackStatus getStatus() {
|
||||
Enum<?> enumConst = readEnumConstant(0, enumResourcePackStatusClass);
|
||||
return ResourcePackStatus.valueOf(enumConst.name());
|
||||
return ResourcePackStatus.values()[enumConst.ordinal()];
|
||||
}
|
||||
|
||||
public void setStatus(ResourcePackStatus status) {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(enumResourcePackStatusClass, status.name());
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(enumResourcePackStatusClass, status.ordinal());
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
|
||||
|
||||
+49
-15
@@ -26,13 +26,13 @@ import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class WrappedPacketInSettings extends WrappedPacket {
|
||||
private static Class<? extends Enum<?>> chatVisibilityEnumClass;
|
||||
|
||||
private static boolean isLowerThan_v_1_8;
|
||||
private Object chatVisibilityEnumObj;
|
||||
private static boolean isLowerThan_v_1_8, v_1_17, v_1_18;
|
||||
|
||||
public WrappedPacketInSettings(final NMSPacket packet) {
|
||||
super(packet);
|
||||
@@ -41,13 +41,16 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
@Override
|
||||
protected void load() {
|
||||
isLowerThan_v_1_8 = version.isOlderThan(ServerVersion.v_1_8);
|
||||
|
||||
try {
|
||||
chatVisibilityEnumClass = NMSUtils.getNMSEnumClass("EnumChatVisibility");
|
||||
} catch (ClassNotFoundException e) {
|
||||
Class<?> entityHumanClass = NMSUtils.getNMSClassWithoutException("EntityHuman");
|
||||
//They are just on an outdated version
|
||||
chatVisibilityEnumClass = SubclassUtil.getEnumSubClass(entityHumanClass, "EnumChatVisibility");
|
||||
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+
|
||||
chatVisibilityEnumClass = NMSUtils.getNMEnumClassWithoutException("world.entity.player.EnumChatVisibility");
|
||||
if (chatVisibilityEnumClass == null) {
|
||||
//They are just on an outdated version
|
||||
chatVisibilityEnumClass = SubclassUtil.getEnumSubClass(NMSUtils.entityHumanClass, "EnumChatVisibility");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,20 +63,20 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
}
|
||||
|
||||
public int getViewDistance() {
|
||||
return readInt(0);
|
||||
return readInt((v_1_17 && !v_1_18) ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setViewDistance(int viewDistance) {
|
||||
writeInt(0, viewDistance);
|
||||
writeInt((v_1_17 && !v_1_18) ? 1 : 0, viewDistance);
|
||||
}
|
||||
|
||||
public ChatVisibility getChatVisibility() {
|
||||
Enum<?> enumConst = readEnumConstant(0, chatVisibilityEnumClass);
|
||||
return ChatVisibility.valueOf(enumConst.name());
|
||||
return ChatVisibility.values()[enumConst.ordinal()];
|
||||
}
|
||||
|
||||
public void setChatVisibility(ChatVisibility visibility) {
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(chatVisibilityEnumClass, visibility.ordinal()); //Ordinal is faster than name comparison.
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(chatVisibilityEnumClass, visibility.ordinal());
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
|
||||
@@ -85,6 +88,37 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
writeBoolean(0, chatColors);
|
||||
}
|
||||
|
||||
//Added in 1.17
|
||||
public boolean isTextFilteringEnabled() {
|
||||
if (v_1_17) {
|
||||
return readBoolean(1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Added in 1.17
|
||||
public void setTextFilteringEnabled(boolean enabled) {
|
||||
if (v_1_17) {
|
||||
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) {
|
||||
@@ -93,7 +127,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
mask |= 0x01;
|
||||
}
|
||||
} else {
|
||||
mask = (byte) readInt(1);
|
||||
mask = (byte) readInt((v_1_17 && !v_1_18) ? 2 : 1);
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
@@ -103,7 +137,7 @@ public class WrappedPacketInSettings extends WrappedPacket {
|
||||
boolean capeEnabled = (mask & 0x01) == 0x01;
|
||||
writeBoolean(1, capeEnabled);
|
||||
} else {
|
||||
writeInt(1, mask);
|
||||
writeInt((v_1_17 && !v_1_18) ? 2 : 1, mask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -18,6 +18,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.in.transaction;
|
||||
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
@@ -49,4 +50,10 @@ public final class WrappedPacketInTransaction extends WrappedPacket {
|
||||
public void setAccepted(boolean isAccepted) {
|
||||
writeBoolean(0, isAccepted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
//1.7.10 -> 1.16.5, removed at 1.17
|
||||
return PacketTypeClasses.Play.Client.TRANSACTION != null;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -61,10 +61,10 @@ public class WrappedPacketInUpdateSign extends WrappedPacket {
|
||||
|
||||
public String[] getTextLines() {
|
||||
if (strArrayMode) {
|
||||
//1.7.10
|
||||
//1.7.10 and 1.17+
|
||||
return readStringArray(0);
|
||||
} else {
|
||||
//1.8 and above
|
||||
//1.8 -> 1.16.5
|
||||
Object[] iChatComponents = (Object[]) readAnyObject(1);
|
||||
return NMSUtils.readIChatBaseComponents(iChatComponents);
|
||||
}
|
||||
|
||||
+119
-37
@@ -18,23 +18,29 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.in.useentity;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.helper.WrappedPacketEntityAbstraction;
|
||||
import io.github.retrooper.packetevents.utils.enums.EnumUtil;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.player.Hand;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3d;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class WrappedPacketInUseEntity extends WrappedPacketEntityAbstraction {
|
||||
private static Class<? extends Enum<?>> enumEntityUseActionClass, enumHandClass;
|
||||
private static Class<? extends Enum<?>> enumEntityUseActionClass;
|
||||
private static Class<?> obfuscatedDataInterface, obfuscatedHandContainerClass, obfuscatedTargetAndHandContainerClass;
|
||||
private static Method getObfuscatedEntityUseActionMethod;
|
||||
private static boolean v_1_7_10, v_1_9, v_1_17;
|
||||
private EntityUseAction action;
|
||||
private Object obfuscatedDataObj;
|
||||
|
||||
public WrappedPacketInUseEntity(final NMSPacket packet) {
|
||||
super(packet);
|
||||
@@ -42,33 +48,61 @@ public final class WrappedPacketInUseEntity extends WrappedPacketEntityAbstracti
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> useEntityClass = NMSUtils.getNMSClassWithoutException("PacketPlayInUseEntity");
|
||||
try {
|
||||
enumHandClass = NMSUtils.getNMSEnumClass("EnumHand");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//Probably a 1.7.10 or 1.8.x server
|
||||
}
|
||||
v_1_7_10 = version.isOlderThan(ServerVersion.v_1_8);
|
||||
v_1_9 = version.isNewerThanOrEquals(ServerVersion.v_1_9);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
enumEntityUseActionClass = NMSUtils.getNMSEnumClass("EnumEntityUseAction");
|
||||
} catch (ClassNotFoundException e) {
|
||||
//That is fine, it is probably a subclass
|
||||
enumEntityUseActionClass = SubclassUtil.getEnumSubClass(useEntityClass, "EnumEntityUseAction");
|
||||
if (v_1_17) {
|
||||
enumEntityUseActionClass = SubclassUtil.getEnumSubClass(PacketTypeClasses.Play.Client.USE_ENTITY, "b");
|
||||
obfuscatedDataInterface = SubclassUtil.getSubClass(PacketTypeClasses.Play.Client.USE_ENTITY, "EnumEntityUseAction");
|
||||
obfuscatedHandContainerClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Client.USE_ENTITY, "d");
|
||||
obfuscatedTargetAndHandContainerClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Client.USE_ENTITY, "e");
|
||||
getObfuscatedEntityUseActionMethod = Reflection.getMethod(obfuscatedDataInterface, enumEntityUseActionClass, 0);
|
||||
} else {
|
||||
enumEntityUseActionClass = SubclassUtil.getEnumSubClass(PacketTypeClasses.Play.Client.USE_ENTITY, "EnumEntityUseAction");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Vector3d> getTarget() {
|
||||
if (PacketEvents.get().getServerUtils().getVersion() == ServerVersion.v_1_7_10
|
||||
|| getAction() != EntityUseAction.INTERACT_AT) {
|
||||
if (v_1_7_10 || getAction() != EntityUseAction.INTERACT_AT) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Object vec3DObj = readObject(0, NMSUtils.vec3DClass);
|
||||
Object vec3DObj;
|
||||
if (v_1_17) {
|
||||
if (obfuscatedDataObj == null) {
|
||||
obfuscatedDataObj = readObject(0, obfuscatedDataInterface);
|
||||
}
|
||||
if (obfuscatedTargetAndHandContainerClass.isInstance(obfuscatedDataObj)) {
|
||||
Object obfuscatedTargetAndHandContainerObj = obfuscatedTargetAndHandContainerClass.cast(obfuscatedDataObj);
|
||||
WrappedPacket wrappedTargetAndHandContainer = new WrappedPacket(new NMSPacket(obfuscatedTargetAndHandContainerObj));
|
||||
vec3DObj = wrappedTargetAndHandContainer.readObject(0, NMSUtils.vec3DClass);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
} else {
|
||||
vec3DObj = readObject(0, NMSUtils.vec3DClass);
|
||||
}
|
||||
WrappedPacket vec3DWrapper = new WrappedPacket(new NMSPacket(vec3DObj));
|
||||
return Optional.of(new Vector3d(vec3DWrapper.readDouble(0), vec3DWrapper.readDouble(1), vec3DWrapper.readDouble(2)));
|
||||
}
|
||||
|
||||
public void setTarget(Vector3d target) {
|
||||
if (PacketEvents.get().getServerUtils().getVersion() != ServerVersion.v_1_7_10
|
||||
&& getAction() == EntityUseAction.INTERACT_AT) {
|
||||
if (v_1_17) {
|
||||
Object vec3DObj = NMSUtils.generateVec3D(target.x, target.y, target.z);
|
||||
if (obfuscatedDataObj == null) {
|
||||
obfuscatedDataObj = readObject(0, obfuscatedDataInterface);
|
||||
}
|
||||
if (obfuscatedTargetAndHandContainerClass.isInstance(obfuscatedDataObj)) {
|
||||
Object obfuscatedTargetAndHandContainerObj = obfuscatedTargetAndHandContainerClass.cast(obfuscatedDataObj);
|
||||
WrappedPacket wrappedTargetAndHandContainer = new WrappedPacket(new NMSPacket(obfuscatedTargetAndHandContainerObj));
|
||||
wrappedTargetAndHandContainer.write(NMSUtils.vec3DClass, 0, vec3DObj);
|
||||
}
|
||||
}
|
||||
else if (v_1_7_10 && getAction() == EntityUseAction.INTERACT_AT) {
|
||||
Object vec3DObj = NMSUtils.generateVec3D(target.x, target.y, target.z);
|
||||
write(NMSUtils.vec3DClass, 0, vec3DObj);
|
||||
}
|
||||
@@ -76,45 +110,93 @@ public final class WrappedPacketInUseEntity extends WrappedPacketEntityAbstracti
|
||||
|
||||
public EntityUseAction getAction() {
|
||||
if (action == null) {
|
||||
Enum<?> useActionEnum = readEnumConstant(0, enumEntityUseActionClass);
|
||||
if (useActionEnum == null) {
|
||||
//This happens on some weird spigots apparently? Not sure why this field is null.
|
||||
return EntityUseAction.INTERACT;
|
||||
Enum<?> useActionEnum;
|
||||
if (v_1_17) {
|
||||
if (obfuscatedDataObj == null) {
|
||||
obfuscatedDataObj = readObject(0, obfuscatedDataInterface);
|
||||
}
|
||||
try {
|
||||
useActionEnum = (Enum<?>) getObfuscatedEntityUseActionMethod.invoke(obfuscatedDataObj);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
useActionEnum = readEnumConstant(0, (Class<? extends Enum<?>>) enumEntityUseActionClass);
|
||||
if (useActionEnum == null) {
|
||||
//This happens on some weird spigots apparently? Not sure why this is null.
|
||||
return action = EntityUseAction.INTERACT;
|
||||
}
|
||||
}
|
||||
return action = EntityUseAction.valueOf(useActionEnum.name());
|
||||
return action = EntityUseAction.values()[useActionEnum.ordinal()];
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(EntityUseAction action) {
|
||||
//TODO Finish this
|
||||
protected void setAction(EntityUseAction action) {
|
||||
this.action = action;
|
||||
Enum<?> enumConst = EnumUtil.valueOf(enumEntityUseActionClass, action.name());
|
||||
writeEnumConstant(0, enumConst);
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex((Class<? extends Enum<?>>) enumEntityUseActionClass, action.ordinal());
|
||||
if (v_1_17) {
|
||||
//TODO Add 1.17+ support
|
||||
}
|
||||
else {
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
}
|
||||
|
||||
public Hand getHand() {
|
||||
if ((getAction() == EntityUseAction.INTERACT || getAction() == EntityUseAction.INTERACT_AT)
|
||||
&& PacketEvents.get().getServerUtils().getVersion().isNewerThan(ServerVersion.v_1_8_8)) {
|
||||
Object enumHandObj = readObject(0, enumHandClass);
|
||||
//Should actually never be null, but we will handle such a case
|
||||
if (enumHandObj == null) {
|
||||
return Hand.MAIN_HAND;
|
||||
public Optional<Hand> getHand() {
|
||||
if (v_1_9 && (getAction() == EntityUseAction.INTERACT || getAction() == EntityUseAction.INTERACT_AT)) {
|
||||
Enum<?> enumHandConst;
|
||||
if (v_1_17) {
|
||||
if (obfuscatedDataObj == null) {
|
||||
obfuscatedDataObj = readObject(0, obfuscatedDataInterface);
|
||||
}
|
||||
if (obfuscatedHandContainerClass.isInstance(obfuscatedDataObj)) {
|
||||
Object obfuscatedHandContainerObj = obfuscatedHandContainerClass.cast(obfuscatedDataObj);
|
||||
WrappedPacket wrappedHandContainer = new WrappedPacket(new NMSPacket(obfuscatedHandContainerObj));
|
||||
enumHandConst = wrappedHandContainer.readEnumConstant(0, NMSUtils.enumHandClass);
|
||||
} else if (obfuscatedTargetAndHandContainerClass.isInstance(obfuscatedDataObj)) {
|
||||
Object obfuscatedTargetAndHandContainerObj = obfuscatedTargetAndHandContainerClass.cast(obfuscatedDataObj);
|
||||
WrappedPacket wrappedTargetAndHandContainer = new WrappedPacket(new NMSPacket(obfuscatedTargetAndHandContainerObj));
|
||||
enumHandConst = wrappedTargetAndHandContainer.readEnumConstant(0, NMSUtils.enumHandClass);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
} else {
|
||||
enumHandConst = readEnumConstant(0, NMSUtils.enumHandClass);
|
||||
}
|
||||
return Hand.valueOf(Objects.requireNonNull(enumHandObj).toString());
|
||||
//Should actually never be null, but we will handle such a case
|
||||
if (enumHandConst == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(Hand.values()[enumHandConst.ordinal()]);
|
||||
}
|
||||
return Hand.MAIN_HAND;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void setHand(Hand hand) {
|
||||
if (PacketEvents.get().getServerUtils().getVersion().isNewerThanOrEquals(ServerVersion.v_1_9) &&
|
||||
(getAction() == EntityUseAction.INTERACT || getAction() == EntityUseAction.INTERACT_AT)) {
|
||||
|
||||
Enum<?> enumConst = EnumUtil.valueOf(enumHandClass, hand.name());
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(NMSUtils.enumHandClass, hand.ordinal());
|
||||
if (v_1_17) {
|
||||
if (obfuscatedDataObj == null) {
|
||||
obfuscatedDataObj = readObject(0, obfuscatedDataInterface);
|
||||
}
|
||||
if (obfuscatedHandContainerClass.isInstance(obfuscatedDataObj)) {
|
||||
Object obfuscatedHandContainerObj = obfuscatedHandContainerClass.cast(obfuscatedDataObj);
|
||||
WrappedPacket wrappedHandContainer = new WrappedPacket(new NMSPacket(obfuscatedHandContainerObj));
|
||||
wrappedHandContainer.writeEnumConstant(0, enumConst);
|
||||
} else if (obfuscatedTargetAndHandContainerClass.isInstance(obfuscatedDataObj)) {
|
||||
Object obfuscatedTargetAndHandContainerObj = obfuscatedTargetAndHandContainerClass.cast(obfuscatedDataObj);
|
||||
WrappedPacket wrappedTargetAndHandContainer = new WrappedPacket(new NMSPacket(obfuscatedTargetAndHandContainerObj));
|
||||
wrappedTargetAndHandContainer.writeEnumConstant(0, enumConst);
|
||||
}
|
||||
}
|
||||
else if (v_1_9 && (getAction() == EntityUseAction.INTERACT || getAction() == EntityUseAction.INTERACT_AT)) {
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
}
|
||||
|
||||
public enum EntityUseAction {
|
||||
INTERACT, INTERACT_AT, ATTACK
|
||||
INTERACT, ATTACK, INTERACT_AT
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.in.useitem;
|
||||
|
||||
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.player.Hand;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3i;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class WrappedPacketInUseItem extends WrappedPacket {
|
||||
|
||||
private static boolean v_1_14;
|
||||
|
||||
public WrappedPacketInUseItem(final NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_14 = version.isNewerThanOrEquals(ServerVersion.v_1_14);
|
||||
}
|
||||
|
||||
public Hand getHand() {
|
||||
return Hand.values()[readEnumConstant(0, NMSUtils.enumHandClass).ordinal()];
|
||||
}
|
||||
|
||||
public void setHand(Hand hand) {
|
||||
Enum<?> enumConstant = EnumUtil.valueByIndex(NMSUtils.enumHandClass, hand.ordinal());
|
||||
writeEnumConstant(0, enumConstant);
|
||||
}
|
||||
|
||||
public Vector3i getBlockPosition() {
|
||||
if (v_1_14) {
|
||||
Object movingBlockPosition = readObject(0, NMSUtils.movingObjectPositionBlockClass);
|
||||
WrappedPacket movingBlockPositionWrapper = new WrappedPacket(new NMSPacket(movingBlockPosition));
|
||||
return movingBlockPositionWrapper.readBlockPosition(0);
|
||||
}
|
||||
else {
|
||||
return readBlockPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockPosition(Vector3i blockPosition) {
|
||||
if (v_1_14) {
|
||||
Object movingBlockPosition = readObject(0, NMSUtils.movingObjectPositionBlockClass);
|
||||
WrappedPacket movingBlockPositionWrapper = new WrappedPacket(new NMSPacket(movingBlockPosition));
|
||||
movingBlockPositionWrapper.writeBlockPosition(0, blockPosition);
|
||||
}
|
||||
else {
|
||||
writeBlockPosition(0, blockPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return version.isNewerThanOrEquals(ServerVersion.v_1_9);
|
||||
}
|
||||
}
|
||||
-1
@@ -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);
|
||||
|
||||
+32
-127
@@ -18,140 +18,77 @@
|
||||
|
||||
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;
|
||||
|
||||
public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
private static final HashMap<Integer, ArrayList<WindowClickType>> WINDOW_CLICK_TYPE_CACHE = new HashMap<>();
|
||||
private static boolean legacy, v_1_17;
|
||||
private static Class<? extends Enum<?>> invClickTypeClass;
|
||||
private static boolean isClickModePrimitive;
|
||||
|
||||
|
||||
public WrappedPacketInWindowClick(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
private static ArrayList<WindowClickType> getArrayListOfWindowClickTypes(WindowClickType... types) {
|
||||
ArrayList<WindowClickType> arrayList = new ArrayList<>(types.length);
|
||||
arrayList.addAll(Arrays.asList(types));
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Client.WINDOW_CLICK;
|
||||
legacy = version.isOlderThanOrEquals(ServerVersion.v_1_8_8);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
invClickTypeClass = NMSUtils.getNMSEnumClassWithoutException("InventoryClickType");
|
||||
|
||||
//MODE 0
|
||||
WINDOW_CLICK_TYPE_CACHE.put(0, getArrayListOfWindowClickTypes(WindowClickType.LEFT_MOUSE_CLICK,
|
||||
WindowClickType.RIGHT_MOUSE_CLICK));
|
||||
|
||||
//MODE 1
|
||||
WINDOW_CLICK_TYPE_CACHE.put(1, getArrayListOfWindowClickTypes(WindowClickType.SHIFT_LEFT_MOUSE_CLICK,
|
||||
WindowClickType.SHIFT_RIGHT_MOUSE_CLICK));
|
||||
|
||||
//MODE 2
|
||||
WINDOW_CLICK_TYPE_CACHE.put(2, getArrayListOfWindowClickTypes(
|
||||
WindowClickType.KEY_NUMBER1,
|
||||
WindowClickType.KEY_NUMBER2,
|
||||
WindowClickType.KEY_NUMBER3,
|
||||
WindowClickType.KEY_NUMBER4,
|
||||
WindowClickType.KEY_NUMBER5,
|
||||
WindowClickType.KEY_NUMBER6,
|
||||
WindowClickType.KEY_NUMBER7,
|
||||
WindowClickType.KEY_NUMBER8,
|
||||
WindowClickType.KEY_NUMBER9));
|
||||
|
||||
//MODE 3
|
||||
WINDOW_CLICK_TYPE_CACHE.put(3, getArrayListOfWindowClickTypes(WindowClickType.UNKNOWN, WindowClickType.UNKNOWN, WindowClickType.CREATIVE_MIDDLE_CLICK));
|
||||
|
||||
//MODE 4
|
||||
WINDOW_CLICK_TYPE_CACHE.put(4, getArrayListOfWindowClickTypes(WindowClickType.KEY_DROP,
|
||||
WindowClickType.KEY_DROP_STACK));
|
||||
|
||||
//MODE 5
|
||||
WINDOW_CLICK_TYPE_CACHE.put(5, getArrayListOfWindowClickTypes(
|
||||
WindowClickType.STARTING_LEFT_MOUSE_DRAG,
|
||||
WindowClickType.ADD_SLOT_LEFT_MOUSE_DRAG,
|
||||
WindowClickType.ENDING_LEFT_MOUSE_DRAG,
|
||||
WindowClickType.UNKNOWN,
|
||||
WindowClickType.STARTING_RIGHT_MOUSE_DRAG,
|
||||
WindowClickType.ADD_SLOT_RIGHT_MOUSE_DRAG,
|
||||
WindowClickType.CREATIVE_STARTING_MIDDLE_MOUSE_DRAG,
|
||||
WindowClickType.ADD_SLOT_MIDDLE_MOUSE_DRAG,
|
||||
WindowClickType.ENDING_MIDDLE_MOUSE_DRAG));
|
||||
|
||||
WINDOW_CLICK_TYPE_CACHE.put(6, getArrayListOfWindowClickTypes(WindowClickType.DOUBLE_CLICK));
|
||||
isClickModePrimitive = Reflection.getField(packetClass, int.class, 3) != null;
|
||||
if (invClickTypeClass == null) {
|
||||
invClickTypeClass = NMSUtils.getNMEnumClassWithoutException("world.inventory.InventoryClickType");
|
||||
}
|
||||
}
|
||||
|
||||
// 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 short getActionNumber() {
|
||||
// Used to sync together client and server
|
||||
public int getActionNumber() {
|
||||
if (v_1_17) {
|
||||
return readInt(2);
|
||||
}
|
||||
return readShort(0);
|
||||
}
|
||||
|
||||
public void setActionNumber(short actionNumber) {
|
||||
writeShort(0, actionNumber);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public WindowClickType getWindowClickType() {
|
||||
int mode = getMode();
|
||||
if (WINDOW_CLICK_TYPE_CACHE.get(mode) == null) {
|
||||
return WindowClickType.UNKNOWN;
|
||||
}
|
||||
int windowButton = getWindowButton();
|
||||
if (windowButton + 1 > WINDOW_CLICK_TYPE_CACHE.size()) {
|
||||
return WindowClickType.UNKNOWN;
|
||||
}
|
||||
|
||||
if (mode == 4) {
|
||||
int windowSlot = getWindowSlot();
|
||||
if (windowSlot == -999) {
|
||||
if (windowButton == 0) {
|
||||
return WindowClickType.LEFT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING;
|
||||
} else if (windowButton == 1) {
|
||||
return WindowClickType.RIGHT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING;
|
||||
}
|
||||
}
|
||||
}
|
||||
return WINDOW_CLICK_TYPE_CACHE.get(mode).get(windowButton);
|
||||
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);
|
||||
@@ -160,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);
|
||||
@@ -174,42 +111,10 @@ public class WrappedPacketInWindowClick extends WrappedPacket {
|
||||
* @return Get Clicked ItemStack
|
||||
*/
|
||||
public ItemStack getClickedItemStack() {
|
||||
Object nmsItemStack = readObject(0, NMSUtils.nmsItemStackClass);
|
||||
return NMSUtils.toBukkitItemStack(nmsItemStack);
|
||||
return readItemStack(0);
|
||||
}
|
||||
|
||||
public void setClickedItemStack(ItemStack stack) {
|
||||
Object nmsItemStack = NMSUtils.toNMSItemStack(stack);
|
||||
write(NMSUtils.nmsItemStackClass, 0, nmsItemStack);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public enum WindowClickType {
|
||||
LEFT_MOUSE_CLICK, RIGHT_MOUSE_CLICK,
|
||||
SHIFT_LEFT_MOUSE_CLICK, SHIFT_RIGHT_MOUSE_CLICK,
|
||||
|
||||
CREATIVE_MIDDLE_CLICK, CREATIVE_STARTING_MIDDLE_MOUSE_DRAG,
|
||||
|
||||
KEY_NUMBER1, KEY_NUMBER2, KEY_NUMBER3, KEY_NUMBER4,
|
||||
KEY_NUMBER5, KEY_NUMBER6, KEY_NUMBER7, KEY_NUMBER8,
|
||||
KEY_NUMBER9, KEY_DROP, KEY_DROP_STACK,
|
||||
|
||||
LEFT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING,
|
||||
RIGHT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING,
|
||||
|
||||
STARTING_LEFT_MOUSE_DRAG,
|
||||
STARTING_RIGHT_MOUSE_DRAG,
|
||||
|
||||
ADD_SLOT_LEFT_MOUSE_DRAG,
|
||||
ADD_SLOT_RIGHT_MOUSE_DRAG,
|
||||
ADD_SLOT_MIDDLE_MOUSE_DRAG,
|
||||
|
||||
ENDING_LEFT_MOUSE_DRAG,
|
||||
ENDING_RIGHT_MOUSE_DRAG,
|
||||
ENDING_MIDDLE_MOUSE_DRAG,
|
||||
|
||||
DOUBLE_CLICK,
|
||||
|
||||
UNKNOWN
|
||||
writeItemStack(0, stack);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -49,11 +49,10 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Server.ABILITIES;
|
||||
try {
|
||||
playerAbilitiesClass = NMSUtils.getNMSClass("PlayerAbilities");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
playerAbilitiesClass = NMSUtils.getNMClassWithoutException("world.entity.player.PlayerAbilities");
|
||||
}
|
||||
|
||||
if (playerAbilitiesClass != null) {
|
||||
@@ -65,7 +64,7 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
|
||||
}
|
||||
|
||||
try {
|
||||
packetConstructor = packetClass.getConstructor(playerAbilitiesClass);
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ABILITIES.getConstructor(playerAbilitiesClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+31
-20
@@ -18,30 +18,35 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.animation;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public final class WrappedPacketOutAnimation extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static Constructor<?> animationConstructor;
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private EntityAnimationType type;
|
||||
|
||||
public WrappedPacketOutAnimation(final NMSPacket packet) {
|
||||
super(packet);
|
||||
super(packet, v_1_17 ? 6 : 0);
|
||||
}
|
||||
|
||||
public WrappedPacketOutAnimation(final Entity target, final EntityAnimationType type) {
|
||||
super(v_1_17 ? 6 : 0);
|
||||
this.entityID = target.getEntityId();
|
||||
this.entity = target;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public WrappedPacketOutAnimation(final int entityID, final EntityAnimationType type) {
|
||||
super(v_1_17 ? 6 : 0);
|
||||
this.entityID = entityID;
|
||||
this.entity = null;
|
||||
this.type = type;
|
||||
@@ -49,10 +54,14 @@ public final class WrappedPacketOutAnimation extends WrappedPacketEntityAbstract
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> animationClass = PacketTypeClasses.Play.Server.ANIMATION;
|
||||
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
animationConstructor = animationClass.getConstructor(NMSUtils.nmsEntityClass, int.class);
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ANIMATION.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
}
|
||||
else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ANIMATION.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -60,8 +69,8 @@ public final class WrappedPacketOutAnimation extends WrappedPacketEntityAbstract
|
||||
|
||||
public EntityAnimationType getAnimationType() {
|
||||
if (packet != null) {
|
||||
byte id = (byte) readInt(1);
|
||||
return EntityAnimationType.getById(id);
|
||||
byte id = (byte) readInt(v_1_17 ? 7 : 1);
|
||||
return EntityAnimationType.values()[id];
|
||||
} else {
|
||||
return type;
|
||||
}
|
||||
@@ -69,7 +78,7 @@ public final class WrappedPacketOutAnimation extends WrappedPacketEntityAbstract
|
||||
|
||||
public void setAnimationType(EntityAnimationType type) {
|
||||
if (packet != null) {
|
||||
writeInt(1, type.ordinal());
|
||||
writeInt(v_1_17 ? 7 : 1, type.ordinal());
|
||||
} else {
|
||||
this.type = type;
|
||||
}
|
||||
@@ -77,21 +86,23 @@ public final class WrappedPacketOutAnimation extends WrappedPacketEntityAbstract
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
final Object nmsEntity = NMSUtils.getNMSEntity(getEntity());
|
||||
final int index = getAnimationType().ordinal();
|
||||
return animationConstructor.newInstance(nmsEntity, index);
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(PacketEvents.get().getByteBufUtil().newByteBuf(
|
||||
new byte[] {0, 0, 0, 0, 0, 0, 0, 0}));
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
}
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
WrappedPacketOutAnimation animation = new WrappedPacketOutAnimation(new NMSPacket(packetInstance));
|
||||
animation.setEntityId(getEntityId());
|
||||
animation.setAnimationType(getAnimationType());
|
||||
return packetInstance;
|
||||
}
|
||||
|
||||
public enum EntityAnimationType {
|
||||
SWING_MAIN_ARM, TAKE_DAMAGE, LEAVE_BED,
|
||||
SWING_OFFHAND, CRITICAL_EFFECT, MAGIC_CRITICAL_EFFECT;
|
||||
|
||||
EntityAnimationType() {
|
||||
|
||||
}
|
||||
|
||||
public static EntityAnimationType getById(byte id) {
|
||||
return values()[id]; //id is at the same time the index
|
||||
}
|
||||
SWING_OFFHAND, CRITICAL_EFFECT, MAGIC_CRITICAL_EFFECT
|
||||
}
|
||||
}
|
||||
+33
-5
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.bedit;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
@@ -12,14 +30,20 @@ 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;
|
||||
|
||||
public WrappedPacketInBEdit(final NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_13 = version.isNewerThanOrEquals(ServerVersion.v_1_13);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return readItemStack(0);
|
||||
}
|
||||
@@ -36,9 +60,11 @@ public class WrappedPacketInBEdit extends WrappedPacket {
|
||||
writeBoolean(0, signing);
|
||||
}
|
||||
|
||||
@SupportedVersions(ranges = {ServerVersion.v_1_13, ServerVersion.v_1_16_5})
|
||||
@SupportedVersions(ranges = {ServerVersion.v_1_13, ServerVersion.ERROR})
|
||||
public Optional<Hand> getHand() {
|
||||
if (version.isNewerThanOrEquals(ServerVersion.v_1_13)) {
|
||||
if (v_1_17) {
|
||||
return Optional.of(Hand.values()[readInt(0)]);
|
||||
} else if (v_1_13) {
|
||||
final Enum<?> enumConst = readEnumConstant(0, NMSUtils.enumHandClass);
|
||||
return Optional.of(Hand.valueOf(enumConst.name()));
|
||||
}
|
||||
@@ -46,9 +72,11 @@ public class WrappedPacketInBEdit extends WrappedPacket {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@SupportedVersions(ranges = {ServerVersion.v_1_13, ServerVersion.v_1_16_5})
|
||||
@SupportedVersions(ranges = {ServerVersion.v_1_13, ServerVersion.ERROR})
|
||||
public void setHand(final Hand hand) {
|
||||
if (version.isNewerThanOrEquals(ServerVersion.v_1_13)) {
|
||||
if (v_1_17) {
|
||||
writeInt(0, hand.ordinal());
|
||||
} else if (v_1_13) {
|
||||
final Enum<?> enumConst = EnumUtil.valueOf(NMSUtils.enumHandClass, hand.name());
|
||||
writeEnumConstant(0, enumConst);
|
||||
}
|
||||
|
||||
+37
-44
@@ -32,59 +32,45 @@ 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 {
|
||||
|
||||
private static Constructor<?> packetConstructor;
|
||||
private Vector3i blockPos;
|
||||
private int action, actionParam;
|
||||
private Material material;
|
||||
private int actionID, actionData;
|
||||
private Material blockType;
|
||||
|
||||
public WrappedPacketOutBlockAction(final NMSPacket packet) {
|
||||
public WrappedPacketOutBlockAction(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutBlockAction(final Vector3i blockPos, final int action, final int actionParam, final Material material) {
|
||||
public WrappedPacketOutBlockAction(Vector3i blockPos, int actionID, int actionData, Material blockType) {
|
||||
this.blockPos = blockPos;
|
||||
this.action = action;
|
||||
this.actionParam = actionParam;
|
||||
this.material = material;
|
||||
this.actionID = actionID;
|
||||
this.actionData = actionData;
|
||||
this.blockType = blockType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.BLOCK_ACTION.getConstructors()[1];
|
||||
} catch (final Exception e) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.BLOCK_ACTION.getConstructor(NMSUtils.blockPosClass, NMSUtils.blockClass, int.class, int.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3i getBlockPosition() {
|
||||
if (packet != null) {
|
||||
final Vector3i blockPos = new Vector3i();
|
||||
|
||||
final Object blockPosObj = readObject(0, NMSUtils.blockPosClass);
|
||||
|
||||
try {
|
||||
blockPos.x = (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
|
||||
blockPos.y = (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
|
||||
blockPos.z = (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return blockPos;
|
||||
return readBlockPosition(0);
|
||||
} else {
|
||||
return this.blockPos;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockPosition(final Vector3i blockPos) {
|
||||
public void setBlockPosition(Vector3i blockPos) {
|
||||
if (packet != null) {
|
||||
final Object nmsBlockPos = NMSUtils.generateNMSBlockPos(blockPos);
|
||||
write(NMSUtils.blockPosClass, 0, nmsBlockPos);
|
||||
writeBlockPosition(0, blockPos);
|
||||
} else {
|
||||
this.blockPos = blockPos;
|
||||
}
|
||||
@@ -94,31 +80,41 @@ public class WrappedPacketOutBlockAction extends WrappedPacket implements Sendab
|
||||
if (packet != null) {
|
||||
return readInt(0);
|
||||
} else {
|
||||
return this.action;
|
||||
return this.actionID;
|
||||
}
|
||||
}
|
||||
|
||||
public void setActionId(final int actionId) {
|
||||
public void setActionId(int actionID) {
|
||||
if (packet != null) {
|
||||
writeInt(0, actionId);
|
||||
writeInt(0, actionID);
|
||||
} else {
|
||||
this.action = actionId;
|
||||
this.actionID = actionID;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getActionParam() {
|
||||
return getActionData();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setActionParam(int actionParam) {
|
||||
setActionData(actionParam);
|
||||
}
|
||||
|
||||
public int getActionData() {
|
||||
if (packet != null) {
|
||||
return readInt(1);
|
||||
} else {
|
||||
return this.actionParam;
|
||||
return this.actionData;
|
||||
}
|
||||
}
|
||||
|
||||
public void setActionParam(final int actionParam) {
|
||||
public void setActionData(int actionData) {
|
||||
if (packet != null) {
|
||||
writeInt(1, actionParam);
|
||||
writeInt(1, actionData);
|
||||
} else {
|
||||
this.actionParam = actionParam;
|
||||
this.actionData = actionData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,26 +122,23 @@ public class WrappedPacketOutBlockAction extends WrappedPacket implements Sendab
|
||||
if (packet != null) {
|
||||
return NMSUtils.getMaterialFromNMSBlock(readObject(0, NMSUtils.blockClass));
|
||||
} else {
|
||||
return this.material;
|
||||
return this.blockType;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockType(final Material material) {
|
||||
public void setBlockType(Material blockType) {
|
||||
if (packet != null) {
|
||||
final Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(material);
|
||||
final Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(blockType);
|
||||
write(NMSUtils.blockClass, 0, nmsBlock);
|
||||
} else {
|
||||
this.material = material;
|
||||
this.blockType = blockType;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
final Object nmsBlockPos = NMSUtils.generateNMSBlockPos(blockPos);
|
||||
final Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(material);
|
||||
|
||||
return packetConstructor.newInstance(
|
||||
nmsBlockPos, nmsBlock, action, actionParam
|
||||
);
|
||||
Object nmsBlockPos = NMSUtils.generateNMSBlockPos(getBlockPosition());
|
||||
Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(getBlockType());
|
||||
return packetConstructor.newInstance(nmsBlockPos, nmsBlock, getActionId(), getActionData());
|
||||
}
|
||||
}
|
||||
+7
-5
@@ -31,6 +31,7 @@ import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static Constructor<?> packetConstructor;
|
||||
private static boolean v_1_7_10;
|
||||
private Vector3i blockPosition;
|
||||
private int destroyStage;
|
||||
|
||||
@@ -53,6 +54,7 @@ public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbst
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_7_10 = version.isOlderThan(ServerVersion.v_1_8);
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.BLOCK_BREAK_ANIMATION.getConstructor(int.class, int.class, int.class, int.class, int.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
@@ -66,7 +68,7 @@ public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbst
|
||||
|
||||
public Vector3i getBlockPosition() {
|
||||
if (packet != null) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
int x = readInt(1);
|
||||
int y = readInt(2);
|
||||
int z = readInt(3);
|
||||
@@ -81,7 +83,7 @@ public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbst
|
||||
|
||||
public void setBlockPosition(Vector3i blockPosition) {
|
||||
if (packet != null) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
writeInt(1, blockPosition.x);
|
||||
writeInt(2, blockPosition.y);
|
||||
writeInt(3, blockPosition.z);
|
||||
@@ -95,7 +97,7 @@ public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbst
|
||||
|
||||
public int getDestroyStage() {
|
||||
if (packet != null) {
|
||||
int index = version.isOlderThan(ServerVersion.v_1_8) ? 4 : 1;
|
||||
int index = v_1_7_10 ? 4 : 1;
|
||||
return readInt(index);
|
||||
} else {
|
||||
return this.destroyStage;
|
||||
@@ -104,7 +106,7 @@ public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbst
|
||||
|
||||
public void setDestroyStage(int destroyStage) {
|
||||
if (packet != null) {
|
||||
int index = version.isOlderThan(ServerVersion.v_1_8) ? 4 : 1;
|
||||
int index = v_1_7_10 ? 4 : 1;
|
||||
writeInt(index, destroyStage);
|
||||
} else {
|
||||
this.destroyStage = destroyStage;
|
||||
@@ -114,7 +116,7 @@ public class WrappedPacketOutBlockBreakAnimation extends WrappedPacketEntityAbst
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Vector3i blockPosition = getBlockPosition();
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
return packetConstructor.newInstance(getEntityId(), blockPosition.x, blockPosition.y, blockPosition.z, getDestroyStage());
|
||||
} else {
|
||||
Object nmsBlockPos = NMSUtils.generateNMSBlockPos(blockPosition);
|
||||
|
||||
+46
-19
@@ -35,13 +35,14 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class WrappedPacketOutBlockChange extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean v_1_7_10, v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private static Method getNMSBlockMethodCache = null;
|
||||
private static Method getNMSWorldTypeMethodCache = null;
|
||||
|
||||
private Vector3i blockPos;
|
||||
private World world;
|
||||
private Material material;
|
||||
private Material blockType;
|
||||
|
||||
public WrappedPacketOutBlockChange(NMSPacket packet) {
|
||||
super(packet);
|
||||
@@ -57,21 +58,29 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
this.world = location.getWorld();
|
||||
}
|
||||
|
||||
public WrappedPacketOutBlockChange(World world, Vector3i blockPos, Material material) {
|
||||
public WrappedPacketOutBlockChange(World world, Vector3i blockPos, Material blockType) {
|
||||
this(world, blockPos);
|
||||
this.material = material;
|
||||
this.blockType = blockType;
|
||||
}
|
||||
|
||||
public WrappedPacketOutBlockChange(Location location, Material material) {
|
||||
public WrappedPacketOutBlockChange(Location location, Material blockType) {
|
||||
this(location);
|
||||
this.material = material;
|
||||
this.blockType = blockType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
getNMSBlockMethodCache = Reflection.getMethod(NMSUtils.iBlockDataClass, "getBlock", 0);
|
||||
getNMSWorldTypeMethodCache = Reflection.getMethod(NMSUtils.nmsWorldClass, "getType", 0);
|
||||
if (version.equals(ServerVersion.v_1_7_10)) {
|
||||
v_1_7_10 = version.isOlderThan(ServerVersion.v_1_8);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
if (v_1_17) {
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.BLOCK_CHANGE.getConstructor(NMSUtils.blockPosClass, NMSUtils.iBlockDataClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (v_1_7_10) {
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.BLOCK_CHANGE.getConstructor(int.class, int.class, int.class, NMSUtils.nmsWorldClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
@@ -88,7 +97,7 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
|
||||
public Vector3i getBlockPosition() {
|
||||
if (packet != null) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
int x = readInt(0);
|
||||
int y = readInt(1);
|
||||
int z = readInt(2);
|
||||
@@ -104,7 +113,7 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
|
||||
public void setBlockPosition(Vector3i blockPos) {
|
||||
if (packet != null) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
writeInt(0, blockPos.x);
|
||||
writeInt(1, blockPos.y);
|
||||
writeInt(2, blockPos.z);
|
||||
@@ -116,10 +125,20 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Material getMaterial() {
|
||||
return getBlockType();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMaterial(Material material) {
|
||||
setBlockType(material);
|
||||
}
|
||||
|
||||
public Material getBlockType() {
|
||||
if (packet != null) {
|
||||
Object nmsBlock = null;
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
nmsBlock = readObject(0, NMSUtils.blockClass);
|
||||
} else {
|
||||
Object iBlockDataObj = readObject(0, NMSUtils.iBlockDataClass);
|
||||
@@ -131,14 +150,14 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
}
|
||||
return NMSUtils.getMaterialFromNMSBlock(nmsBlock);
|
||||
} else {
|
||||
return material;
|
||||
return blockType;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
public void setBlockType(Material blockType) {
|
||||
if (packet != null) {
|
||||
Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(material);
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(blockType);
|
||||
if (v_1_7_10) {
|
||||
write(NMSUtils.blockClass, 0, nmsBlock);
|
||||
} else {
|
||||
WrappedPacket nmsBlockWrapper = new WrappedPacket(new NMSPacket(nmsBlock), NMSUtils.blockClass);
|
||||
@@ -146,7 +165,7 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
write(NMSUtils.iBlockDataClass, 0, iBlockData);
|
||||
}
|
||||
} else {
|
||||
this.material = material;
|
||||
this.blockType = blockType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,19 +174,27 @@ public class WrappedPacketOutBlockChange extends WrappedPacket implements Sendab
|
||||
Object packetPlayOutBlockChangeInstance;
|
||||
WrappedPacketOutBlockChange blockChange;
|
||||
Vector3i blockPosition = getBlockPosition();
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_17) {
|
||||
Object nmsBlockPos = NMSUtils.generateNMSBlockPos(blockPosition);
|
||||
Object nmsBlock = NMSUtils.getNMSBlockFromMaterial(getBlockType());
|
||||
WrappedPacket nmsBlockWrapper = new WrappedPacket(new NMSPacket(nmsBlock), NMSUtils.blockClass);
|
||||
Object nmsIBlockData = nmsBlockWrapper.readObject(0, NMSUtils.iBlockDataClass);
|
||||
packetPlayOutBlockChangeInstance = packetConstructor.newInstance(nmsBlockPos, nmsIBlockData);
|
||||
} else if (v_1_7_10) {
|
||||
Object nmsWorld = NMSUtils.convertBukkitWorldToWorldServer(world);
|
||||
packetPlayOutBlockChangeInstance = packetConstructor.newInstance(blockPosition.x, blockPosition.y, blockPosition.z, nmsWorld);
|
||||
blockChange = new WrappedPacketOutBlockChange(new NMSPacket(packetPlayOutBlockChangeInstance));
|
||||
if (getMaterial() != null) {
|
||||
blockChange.setMaterial(getMaterial());
|
||||
Material bt = getBlockType();
|
||||
if (bt != null) {
|
||||
blockChange.setBlockType(bt);
|
||||
}
|
||||
|
||||
} else {
|
||||
packetPlayOutBlockChangeInstance = packetConstructor.newInstance();
|
||||
blockChange = new WrappedPacketOutBlockChange(new NMSPacket(packetPlayOutBlockChangeInstance));
|
||||
if (getMaterial() != null) {
|
||||
blockChange.setMaterial(getMaterial());
|
||||
Material bt = getBlockType();
|
||||
if (bt != null) {
|
||||
blockChange.setBlockType(bt);
|
||||
} else {
|
||||
Object nmsBlockPos = NMSUtils.generateNMSBlockPos(blockPosition);
|
||||
Object worldServer = NMSUtils.convertBukkitWorldToWorldServer(world);
|
||||
|
||||
+27
-16
@@ -18,55 +18,66 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.camera;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.packetwrappers.api.helper.WrappedPacketEntityAbstraction;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketOutCamera extends WrappedPacket implements SendableWrapper {
|
||||
public class WrappedPacketOutCamera extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int cameraID;
|
||||
|
||||
public WrappedPacketOutCamera(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutCamera(int cameraID) {
|
||||
this.cameraID = cameraID;
|
||||
public WrappedPacketOutCamera(int entityID) {
|
||||
setEntityId(entityID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.CAMERA.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.CAMERA.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
} else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.CAMERA.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getCameraId() {
|
||||
if (packet != null) {
|
||||
return readInt(0);
|
||||
}
|
||||
return cameraID;
|
||||
return getEntityId();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCameraId(int cameraID) {
|
||||
if (packet != null) {
|
||||
writeInt(0, cameraID);
|
||||
} else {
|
||||
this.cameraID = cameraID;
|
||||
}
|
||||
setEntityId(cameraID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = packetConstructor.newInstance();
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
//You call it lazy, I call it smart
|
||||
Object byteBuf = PacketEvents.get().getByteBufUtil().newByteBuf(new byte[]{1});
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(byteBuf);
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
} else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
WrappedPacket packetWrapper = new WrappedPacket(new NMSPacket(packetInstance));
|
||||
packetWrapper.writeInt(0, getCameraId());
|
||||
packetWrapper.writeInt(0, getEntityId());
|
||||
return packetInstance;
|
||||
}
|
||||
|
||||
|
||||
+48
-39
@@ -22,6 +22,7 @@ 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.enums.EnumUtil;
|
||||
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@@ -33,8 +34,7 @@ import java.util.UUID;
|
||||
|
||||
public final class WrappedPacketOutChat extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> chatClassConstructor;
|
||||
private static Class<?> packetClass, iChatBaseComponentClass, chatMessageTypeEnum;
|
||||
private static Method chatMessageTypeCreatorMethod;
|
||||
private static Class<? extends Enum<?>> chatMessageTypeEnum;
|
||||
//0 = IChatBaseComponent, Byte
|
||||
//1 = IChatBaseComponent, Int
|
||||
//2 = IChatBaseComponent, ChatMessageType
|
||||
@@ -68,30 +68,19 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
try {
|
||||
packetClass = PacketTypeClasses.Play.Server.CHAT;
|
||||
iChatBaseComponentClass = NMSUtils.getNMSClass("IChatBaseComponent");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Server.CHAT;
|
||||
chatMessageTypeEnum = NMSUtils.getNMSEnumClassWithoutException("ChatMessageType");
|
||||
if (chatMessageTypeEnum == null) {
|
||||
chatMessageTypeEnum = NMSUtils.getNMEnumClassWithoutException("network.chat.ChatMessageType");
|
||||
}
|
||||
|
||||
boolean isVeryOutdated = false;
|
||||
try {
|
||||
chatMessageTypeEnum = NMSUtils.getNMSClass("ChatMessageType");
|
||||
} catch (ClassNotFoundException e) {
|
||||
isVeryOutdated = true;
|
||||
}
|
||||
|
||||
if (!isVeryOutdated) {
|
||||
chatMessageTypeCreatorMethod = Reflection.getMethod(chatMessageTypeEnum, 0, byte.class);
|
||||
|
||||
if (chatMessageTypeEnum != null) {
|
||||
try {
|
||||
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, chatMessageTypeEnum);
|
||||
chatClassConstructor = packetClass.getConstructor(NMSUtils.iChatBaseComponentClass, chatMessageTypeEnum);
|
||||
constructorMode = 2;
|
||||
} catch (NoSuchMethodException e) {
|
||||
//Just a much newer version(1.16.x and above right now)
|
||||
try {
|
||||
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, chatMessageTypeEnum, UUID.class);
|
||||
chatClassConstructor = packetClass.getConstructor(NMSUtils.iChatBaseComponentClass, chatMessageTypeEnum, UUID.class);
|
||||
constructorMode = 3;
|
||||
} catch (NoSuchMethodException e2) {
|
||||
//Failed to resolve the constructor
|
||||
@@ -100,21 +89,21 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, byte.class);
|
||||
chatClassConstructor = packetClass.getConstructor(NMSUtils.iChatBaseComponentClass, byte.class);
|
||||
constructorMode = 0;
|
||||
} catch (NoSuchMethodException e) {
|
||||
//That is fine, they are most likely on an older version.
|
||||
try {
|
||||
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, int.class);
|
||||
chatClassConstructor = packetClass.getConstructor(NMSUtils.iChatBaseComponentClass, int.class);
|
||||
constructorMode = 1;
|
||||
} catch (NoSuchMethodException e2) {
|
||||
try {
|
||||
//Some weird 1.7.10 spigots remove that int parameter for no reason, I won't keep adding support for any more spigots and might stop
|
||||
//accepting pull requests for support for spigots breaking things that normal spigot has.
|
||||
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass);
|
||||
chatClassConstructor = packetClass.getConstructor(NMSUtils.iChatBaseComponentClass);
|
||||
constructorMode = -1;
|
||||
} catch (NoSuchMethodException noSuchMethodException) {
|
||||
noSuchMethodException.printStackTrace();
|
||||
} catch (NoSuchMethodException e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,9 +114,9 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
byte chatPos = (byte) getChatPosition().ordinal();
|
||||
Object chatMessageTypeInstance = null;
|
||||
Enum<?> chatMessageTypeInstance = null;
|
||||
if (chatMessageTypeEnum != null) {
|
||||
chatMessageTypeInstance = chatMessageTypeCreatorMethod.invoke(null, chatPos);
|
||||
chatMessageTypeInstance = EnumUtil.valueByIndex(chatMessageTypeEnum, chatPos);
|
||||
}
|
||||
switch (constructorMode) {
|
||||
case -1:
|
||||
@@ -152,13 +141,20 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
*/
|
||||
public String getMessage() {
|
||||
if (packet != null) {
|
||||
final Object iChatBaseObj = readObject(0, iChatBaseComponentClass);
|
||||
return NMSUtils.readIChatBaseComponent(iChatBaseObj);
|
||||
return readIChatBaseComponent(0);
|
||||
} else {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
if (packet != null) {
|
||||
writeIChatBaseComponent(0, message);
|
||||
} else {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chat position.
|
||||
* <p>
|
||||
@@ -182,28 +178,41 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
Object chatTypeEnumInstance = readObject(0, chatMessageTypeEnum);
|
||||
return ChatPosition.valueOf(chatTypeEnumInstance.toString());
|
||||
Enum<?> chatTypeEnumInstance = readEnumConstant(0, chatMessageTypeEnum);
|
||||
return ChatPosition.values()[chatTypeEnumInstance.ordinal()];
|
||||
default:
|
||||
chatPositionValue = 0;
|
||||
break;
|
||||
}
|
||||
return ChatPosition.getByPositionValue(chatPositionValue);
|
||||
return ChatPosition.values()[chatPositionValue];
|
||||
} else {
|
||||
return chatPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public void setChatPosition(ChatPosition chatPosition) {
|
||||
if (packet != null) {
|
||||
switch (constructorMode) {
|
||||
case 0:
|
||||
writeByte(0, (byte) chatPosition.ordinal());
|
||||
break;
|
||||
case 1:
|
||||
writeInt(0, chatPosition.ordinal());
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
Enum<?> chatTypeEnumInstance = EnumUtil.valueByIndex(chatMessageTypeEnum, chatPosition.ordinal());
|
||||
writeEnumConstant(0, chatTypeEnumInstance);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
this.chatPosition = chatPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ChatPosition {
|
||||
CHAT,
|
||||
SYSTEM_MESSAGE,
|
||||
GAME_INFO;
|
||||
|
||||
ChatPosition() {
|
||||
}
|
||||
|
||||
public static ChatPosition getByPositionValue(byte position) {
|
||||
return values()[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.collect;
|
||||
|
||||
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.server.ServerVersion;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WrappedPacketOutCollect extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean v_1_11;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int collectedEntityId, collectorEntityId, itemCount;
|
||||
|
||||
public WrappedPacketOutCollect(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutCollect(int collectedEntityId, int collectorEntityId, int itemCount) {
|
||||
this.collectedEntityId = collectedEntityId;
|
||||
this.collectorEntityId = collectorEntityId;
|
||||
this.itemCount = itemCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_11 = version.isNewerThanOrEquals(ServerVersion.v_1_11);
|
||||
try {
|
||||
if (v_1_11) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.COLLECT.getConstructor(int.class, int.class, int.class);
|
||||
} else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.COLLECT.getConstructor(int.class, int.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCollectedEntityId() {
|
||||
if (packet != null) {
|
||||
return readInt(0);
|
||||
} else {
|
||||
return this.collectedEntityId;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCollectedEntityId(int id) {
|
||||
if (packet != null) {
|
||||
writeInt(0, id);
|
||||
} else {
|
||||
this.collectedEntityId = id;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCollectorEntityId() {
|
||||
if (packet != null) {
|
||||
return readInt(1);
|
||||
} else {
|
||||
return this.collectorEntityId;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCollectorEntityId(int id) {
|
||||
if (packet != null) {
|
||||
writeInt(1, id);
|
||||
} else {
|
||||
this.collectorEntityId = id;
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Integer> getItemCount() {
|
||||
if (!v_1_11) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (packet != null) {
|
||||
return Optional.of(readInt(2));
|
||||
} else {
|
||||
return Optional.of(this.itemCount);
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemCount(int count) {
|
||||
if (v_1_11) {
|
||||
if (packet != null) {
|
||||
writeInt(2, count);
|
||||
} else {
|
||||
this.itemCount = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
/*
|
||||
* On newer versions the packet has an extra field which is the picked up item count.
|
||||
*/
|
||||
return v_1_11
|
||||
? packetConstructor.newInstance(getCollectedEntityId(), getCollectorEntityId(), (int) (getItemCount().get()))
|
||||
: packetConstructor.newInstance(getCollectedEntityId(), getCollectorEntityId());
|
||||
}
|
||||
}
|
||||
+30
-24
@@ -35,11 +35,11 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
private static int minecraftKeyIndexInClass;
|
||||
|
||||
private static byte constructorMode;
|
||||
private String tag;
|
||||
private String channelName;
|
||||
private byte[] data;
|
||||
|
||||
public WrappedPacketOutCustomPayload(String tag, byte[] data) {
|
||||
this.tag = tag;
|
||||
public WrappedPacketOutCustomPayload(String channelName, byte[] data) {
|
||||
this.channelName = channelName;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
try {
|
||||
packetDataSerializerConstructor = NMSUtils.packetDataSerializerClass.getConstructor(NMSUtils.byteBufClass);
|
||||
} catch (NullPointerException | NoSuchMethodException e) {
|
||||
//For some reason some 1.7.10 spigots don't have this constructor although its on normal spigot 1.7.10???
|
||||
//For some reason some annoying 1.7.10 spigot forks don't have this constructor?
|
||||
}
|
||||
|
||||
//Constructors:
|
||||
@@ -92,33 +92,35 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
}
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
public String getChannelName() {
|
||||
if (packet != null) {
|
||||
switch (constructorMode) {
|
||||
case 0:
|
||||
case 1:
|
||||
return readString(0);
|
||||
case 2:
|
||||
Object minecraftKey = readObject(minecraftKeyIndexInClass, NMSUtils.minecraftKeyClass);
|
||||
return NMSUtils.getStringFromMinecraftKey(minecraftKey);
|
||||
return readMinecraftKey(minecraftKeyIndexInClass);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return tag;
|
||||
else {
|
||||
return channelName;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
public void setChannelName(String channelName) {
|
||||
if (packet != null) {
|
||||
switch (constructorMode) {
|
||||
case 0:
|
||||
case 1:
|
||||
writeString(0, tag);
|
||||
writeString(0, channelName);
|
||||
case 2:
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKey(tag);
|
||||
write(NMSUtils.minecraftKeyClass, minecraftKeyIndexInClass, minecraftKey);
|
||||
writeMinecraftKey(0, channelName);
|
||||
}
|
||||
} else {
|
||||
this.tag = tag;
|
||||
}
|
||||
else {
|
||||
this.channelName = channelName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +132,9 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
case 1:
|
||||
case 2:
|
||||
return PacketEvents.get().getByteBufUtil().getBytes(getBuffer());
|
||||
default:
|
||||
return new byte[0];
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -156,19 +159,22 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
private Object getBuffer() {
|
||||
Object dataSerializer = readObject(0, NMSUtils.packetDataSerializerClass);
|
||||
WrappedPacket dataSerializerWrapper = new WrappedPacket(new NMSPacket(dataSerializer));
|
||||
|
||||
return dataSerializerWrapper.readObject(0, NMSUtils.byteBufClass);
|
||||
}
|
||||
|
||||
public void retain() {
|
||||
if (constructorMode != 0) {
|
||||
PacketEvents.get().getByteBufUtil().retain(getBuffer());
|
||||
if (packet != null) {
|
||||
if (constructorMode != 0) {
|
||||
PacketEvents.get().getByteBufUtil().retain(getBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
if (constructorMode != 0) {
|
||||
PacketEvents.get().getByteBufUtil().release(getBuffer());
|
||||
if (packet != null) {
|
||||
if (constructorMode != 0) {
|
||||
PacketEvents.get().getByteBufUtil().release(getBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,12 +184,12 @@ public class WrappedPacketOutCustomPayload extends WrappedPacket implements Send
|
||||
Object dataSerializer;
|
||||
switch (constructorMode) {
|
||||
case 0:
|
||||
return constructor.newInstance(getTag(), data);
|
||||
return constructor.newInstance(getChannelName(), data);
|
||||
case 1:
|
||||
dataSerializer = packetDataSerializerConstructor.newInstance(PacketEvents.get().getByteBufUtil().newByteBuf(data));
|
||||
return constructor.newInstance(getTag(), dataSerializer);
|
||||
return constructor.newInstance(getChannelName(), dataSerializer);
|
||||
case 2:
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKey(getTag());
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKeyNew(getChannelName());
|
||||
dataSerializer = packetDataSerializerConstructor.newInstance(PacketEvents.get().getByteBufUtil().newByteBuf(data));
|
||||
return constructor.newInstance(minecraftKey, dataSerializer);
|
||||
default:
|
||||
|
||||
+169
-71
@@ -23,23 +23,25 @@ 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 org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Objects;
|
||||
|
||||
import java.util.Optional;
|
||||
public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_8, v_1_15, v_1_17;
|
||||
//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 int yawByteIndex;
|
||||
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 boolean onGround, isLook;
|
||||
private float pitch, yaw;
|
||||
private boolean onGround, rotating, moving;
|
||||
|
||||
public WrappedPacketOutEntity(NMSPacket packet) {
|
||||
super(packet);
|
||||
@@ -47,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 isLook) {
|
||||
float yaw, float pitch, boolean onGround, boolean rotating, boolean moving) {
|
||||
this.entityID = entityID;
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
@@ -55,36 +57,38 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.onGround = onGround;
|
||||
this.isLook = isLook;
|
||||
this.rotating = rotating;
|
||||
this.moving = moving;
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntity(int entityID, double deltaX, double deltaY, double deltaZ,
|
||||
byte yaw, byte pitch, boolean onGround) {
|
||||
this.entityID = entityID;
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
this.deltaZ = deltaZ;
|
||||
this.pitch = pitch;
|
||||
this.yaw = yaw;
|
||||
this.onGround = onGround;
|
||||
this.isLook = false;
|
||||
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,
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_8 = version.isNewerThanOrEquals(ServerVersion.v_1_8);
|
||||
v_1_15 = version.isNewerThanOrEquals(ServerVersion.v_1_15);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Server.ENTITY;
|
||||
|
||||
Field dxField = Reflection.getField(packetClass, 1);
|
||||
Field dxField = Reflection.getField(packetClass, v_1_17 ? 2 : 1);
|
||||
if (Objects.requireNonNull(dxField).equals(Reflection.getField(packetClass, byte.class, 0))) {
|
||||
mode = 0;
|
||||
yawByteIndex = 3;
|
||||
@@ -94,47 +98,52 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
} else if (dxField.equals(Reflection.getField(packetClass, short.class, 0))) {
|
||||
mode = 2;
|
||||
}
|
||||
|
||||
if (mode == 0) {
|
||||
dXYZDivisor = 32.0;
|
||||
} else {
|
||||
dXYZDivisor = 4096.0;
|
||||
}
|
||||
try {
|
||||
entityPacketConstructor = packetClass.getConstructor(int.class);
|
||||
if (v_1_17) {
|
||||
entityPacketConstructor = packetClass.getDeclaredConstructor(int.class, short.class, short.class, short.class,
|
||||
byte.class, byte.class, boolean.class, boolean.class, boolean.class);
|
||||
entityPacketConstructor.setAccessible(true);
|
||||
} else {
|
||||
entityPacketConstructor = packetClass.getConstructor(int.class);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,25 +271,58 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLook() {
|
||||
public Optional<Boolean> isRotating() {
|
||||
if (!v_1_8) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (packet != null) {
|
||||
return readBoolean(1);
|
||||
return Optional.of(readBoolean(1));
|
||||
} else {
|
||||
return isLook;
|
||||
return Optional.of(rotating);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLook(boolean isLook) {
|
||||
public void setRotating(boolean rotating) {
|
||||
if (v_1_8) {
|
||||
if (packet != null) {
|
||||
writeBoolean(1, rotating);
|
||||
} else {
|
||||
this.rotating = rotating;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Boolean> isMoving() {
|
||||
if (!v_1_15) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (packet != null) {
|
||||
writeBoolean(1, isLook);
|
||||
return Optional.of(readBoolean(2));
|
||||
} else {
|
||||
this.isLook = isLook;
|
||||
return Optional.of(moving);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMoving(boolean moving) {
|
||||
if (v_1_15) {
|
||||
if (packet != null) {
|
||||
writeBoolean(2, moving);
|
||||
} else {
|
||||
this.moving = moving;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
try {
|
||||
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),
|
||||
angleYaw, anglePitch, isOnGround(), isRotating().get(), isMoving().get());
|
||||
} else {
|
||||
Object packetInstance = entityPacketConstructor.newInstance(getEntityId());
|
||||
WrappedPacketOutEntity wrapper = new WrappedPacketOutEntity(new NMSPacket(packetInstance));
|
||||
wrapper.setDeltaX(getDeltaX());
|
||||
@@ -289,12 +331,14 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
wrapper.setYaw(getYaw());
|
||||
wrapper.setPitch(getPitch());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
wrapper.setLook(isLook());
|
||||
if (v_1_8) {
|
||||
wrapper.setRotating(isRotating().get());
|
||||
/*if (v_1_16) {
|
||||
wrapper.setMoving(isMoving().get());
|
||||
}*/
|
||||
}
|
||||
return packetInstance;
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class WrappedPacketOutEntityLook extends WrappedPacketOutEntity {
|
||||
@@ -302,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);
|
||||
}
|
||||
|
||||
@@ -310,7 +354,12 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
protected void load() {
|
||||
super.load();
|
||||
try {
|
||||
entityLookConstructor = PacketTypeClasses.Play.Server.ENTITY_LOOK.getConstructor();
|
||||
if (v_1_17) {
|
||||
entityLookConstructor = PacketTypeClasses.Play.Server.ENTITY_LOOK.getConstructor(int.class, byte.class, byte.class, boolean.class);
|
||||
}
|
||||
else {
|
||||
entityLookConstructor = PacketTypeClasses.Play.Server.ENTITY_LOOK.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -318,13 +367,23 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = entityLookConstructor.newInstance();
|
||||
WrappedPacketOutEntityLook wrapper = new WrappedPacketOutEntityLook(new NMSPacket(packetInstance));
|
||||
wrapper.setEntityId(getEntityId());
|
||||
wrapper.setYaw(getYaw());
|
||||
wrapper.setPitch(getPitch());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
wrapper.setLook(true);
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
byte angleYaw = (byte) (getYaw() * ROTATION_FACTOR);
|
||||
byte anglePitch = (byte) (getPitch() * ROTATION_FACTOR);
|
||||
packetInstance = entityLookConstructor.newInstance(getEntityId(), angleYaw, anglePitch, isOnGround());
|
||||
}
|
||||
else {
|
||||
packetInstance = entityLookConstructor.newInstance();
|
||||
WrappedPacketOutEntityLook wrapper = new WrappedPacketOutEntityLook(new NMSPacket(packetInstance));
|
||||
wrapper.setEntityId(getEntityId());
|
||||
wrapper.setYaw(getYaw());
|
||||
wrapper.setPitch(getPitch());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
if (v_1_8) {
|
||||
wrapper.setRotating(true);
|
||||
}
|
||||
}
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
@@ -335,14 +394,19 @@ 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
|
||||
protected void load() {
|
||||
super.load();
|
||||
try {
|
||||
entityRelMovePacketConstructor = PacketTypeClasses.Play.Server.REL_ENTITY_MOVE.getConstructor();
|
||||
if (v_1_17) {
|
||||
entityRelMovePacketConstructor = PacketTypeClasses.Play.Server.REL_ENTITY_MOVE.getConstructor(int.class, short.class, short.class, short.class, boolean.class);
|
||||
}
|
||||
else {
|
||||
entityRelMovePacketConstructor = PacketTypeClasses.Play.Server.REL_ENTITY_MOVE.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -350,14 +414,26 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = entityRelMovePacketConstructor.newInstance();
|
||||
WrappedPacketOutRelEntityMove wrapper = new WrappedPacketOutRelEntityMove(new NMSPacket(packetInstance));
|
||||
wrapper.setEntityId(getEntityId());
|
||||
wrapper.setDeltaX(getDeltaX());
|
||||
wrapper.setDeltaY(getDeltaY());
|
||||
wrapper.setDeltaZ(getDeltaZ());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
wrapper.setLook(false);
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
short dx = (short) (getDeltaX() * dXYZDivisor);
|
||||
short dy = (short) (getDeltaY() * dXYZDivisor);
|
||||
short dz = (short) (getDeltaZ() * dXYZDivisor);
|
||||
packetInstance = entityRelMovePacketConstructor.newInstance(getEntityId(), dx, dy, dz, isOnGround());
|
||||
}
|
||||
else {
|
||||
packetInstance = entityRelMovePacketConstructor.newInstance();
|
||||
|
||||
WrappedPacketOutRelEntityMove wrapper = new WrappedPacketOutRelEntityMove(new NMSPacket(packetInstance));
|
||||
wrapper.setEntityId(getEntityId());
|
||||
wrapper.setDeltaX(getDeltaX());
|
||||
wrapper.setDeltaY(getDeltaY());
|
||||
wrapper.setDeltaZ(getDeltaZ());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
if (v_1_15) {
|
||||
wrapper.setMoving(true);
|
||||
}
|
||||
}
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
@@ -367,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);
|
||||
}
|
||||
|
||||
@@ -375,7 +452,12 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
protected void load() {
|
||||
super.load();
|
||||
try {
|
||||
entityRelMoveLookConstructor = PacketTypeClasses.Play.Server.REL_ENTITY_MOVE_LOOK.getConstructor();
|
||||
if (v_1_17) {
|
||||
entityRelMoveLookConstructor = PacketTypeClasses.Play.Server.REL_ENTITY_MOVE_LOOK.getConstructor(int.class, short.class, short.class, short.class, byte.class, byte.class, boolean.class);
|
||||
}
|
||||
else {
|
||||
entityRelMoveLookConstructor = PacketTypeClasses.Play.Server.REL_ENTITY_MOVE_LOOK.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -383,16 +465,32 @@ public class WrappedPacketOutEntity extends WrappedPacketEntityAbstraction imple
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = entityRelMoveLookConstructor.newInstance();
|
||||
WrappedPacketOutRelEntityMoveLook wrapper = new WrappedPacketOutRelEntityMoveLook(new NMSPacket(packetInstance));
|
||||
wrapper.setEntityId(getEntityId());
|
||||
wrapper.setDeltaX(getDeltaX());
|
||||
wrapper.setDeltaY(getDeltaY());
|
||||
wrapper.setDeltaZ(getDeltaZ());
|
||||
wrapper.setYaw(getYaw());
|
||||
wrapper.setPitch(getPitch());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
wrapper.setLook(true);
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
short dx = (short) (getDeltaX() * dXYZDivisor);
|
||||
short dy = (short) (getDeltaY() * dXYZDivisor);
|
||||
short dz = (short) (getDeltaZ() * dXYZDivisor);
|
||||
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();
|
||||
WrappedPacketOutRelEntityMoveLook wrapper = new WrappedPacketOutRelEntityMoveLook(new NMSPacket(packetInstance));
|
||||
wrapper.setEntityId(getEntityId());
|
||||
wrapper.setDeltaX(getDeltaX());
|
||||
wrapper.setDeltaY(getDeltaY());
|
||||
wrapper.setDeltaZ(getDeltaZ());
|
||||
wrapper.setYaw(getYaw());
|
||||
wrapper.setPitch(getPitch());
|
||||
wrapper.setOnGround(isOnGround());
|
||||
if (v_1_8) {
|
||||
wrapper.setRotating(true);
|
||||
if (v_1_15) {
|
||||
wrapper.setMoving(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
|
||||
+151
-45
@@ -20,91 +20,197 @@ package io.github.retrooper.packetevents.packetwrappers.play.out.entitydestroy;
|
||||
|
||||
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 org.bukkit.World;
|
||||
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 org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author yanjulang
|
||||
* @author yanjulang, MWHunter
|
||||
* @since 1.8
|
||||
*/
|
||||
public class WrappedPacketOutEntityDestroy extends WrappedPacket implements SendableWrapper {
|
||||
|
||||
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;
|
||||
private int[] entityIds;
|
||||
private Entity[] entities;
|
||||
private int[] entityIds = new int[0];
|
||||
|
||||
public WrappedPacketOutEntityDestroy(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public WrappedPacketOutEntityDestroy(int... entityIds) {
|
||||
this.entityIds = entityIds;
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityDestroy(Entity... entities) {
|
||||
setEntities(entities);
|
||||
public WrappedPacketOutEntityDestroy(int entityID) {
|
||||
setEntityId(entityID);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityDestroy(Entity entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
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 {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_DESTROY.getConstructor(int[].class);
|
||||
if (v_1_17) {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_DESTROY.getConstructor(int.class);
|
||||
} else {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_DESTROY.getConstructor(int[].class);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getEntityIds() {
|
||||
if (packet != null && entityIds == null) {
|
||||
return entityIds = readIntArray(0);
|
||||
@Override
|
||||
public int getEntityId() {
|
||||
if (entityID != -1 || entityIds.length > 0 || packet == null) {
|
||||
if (v_1_17) {
|
||||
return entityID;
|
||||
} else {
|
||||
return entityIds[0];
|
||||
}
|
||||
} else {
|
||||
return entityIds;
|
||||
if (v_1_17_1) {
|
||||
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);
|
||||
} else {
|
||||
entityIds = readIntArray(0);
|
||||
return entityIds[0];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntityId(int entityID) {
|
||||
if (packet != null) {
|
||||
if (v_1_17) {
|
||||
writeInt(0, this.entityID = entityID);
|
||||
} else {
|
||||
this.entityIds = new int[]{entityID};
|
||||
if (v_1_17_1) {
|
||||
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};
|
||||
}
|
||||
}
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public int[] getEntityIds() {
|
||||
if (packet != null) {
|
||||
if (v_1_17) {
|
||||
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 {
|
||||
return entityIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEntityIds(int... entityIds) {
|
||||
this.entityIds = entityIds;
|
||||
if (packet != null) {
|
||||
writeIntArray(0, entityIds);
|
||||
}
|
||||
}
|
||||
|
||||
public Entity[] getEntities(@Nullable World world) {
|
||||
if (packet != null && entities == null) {
|
||||
int[] entityIDs = getEntityIds();
|
||||
entities = new Entity[entityIDs.length];
|
||||
for (int i = 0; i < entityIDs.length; i++) {
|
||||
entities[i] = NMSUtils.getEntityById(world, entityIDs[i]);
|
||||
if (v_1_17) {
|
||||
setEntityId(entityIds[0]);
|
||||
} 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 {
|
||||
if (v_1_17) {
|
||||
this.entityID = entityIds[0];
|
||||
} else {
|
||||
this.entityIds = entityIds;
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
public Entity[] getEntities() {
|
||||
return getEntities(null);
|
||||
}
|
||||
|
||||
public void setEntities(Entity... entities) {
|
||||
this.entityIds = new int[entities.length];
|
||||
this.entities = entities;
|
||||
for (int i = 0; i < entities.length; i++) {
|
||||
Entity entity = entities[i];
|
||||
entityIds[i] = entity.getEntityId();
|
||||
}
|
||||
if (packet != null) {
|
||||
writeIntArray(0, entityIds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
return packetConstructor.newInstance(entityIds);
|
||||
if (v_1_17) {
|
||||
return packetConstructor.newInstance(getEntityId());
|
||||
} else {
|
||||
return packetConstructor.newInstance(getEntityIds());
|
||||
}
|
||||
}
|
||||
}
|
||||
+85
-33
@@ -18,29 +18,35 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.entityeffect;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static Constructor<?> packetDefaultConstructor;
|
||||
private int effectID = -1;
|
||||
private int amplifier = -1;
|
||||
private int duration = -1;
|
||||
private static boolean v_1_7_10, v_1_17, v_1_18_2;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int effectID;
|
||||
private int amplifier;
|
||||
private int duration;
|
||||
private byte byteMask;
|
||||
private boolean byteMaskInitialized = false;
|
||||
|
||||
public WrappedPacketOutEntityEffect(NMSPacket packet) {
|
||||
super(packet);
|
||||
super(packet, v_1_17 ? 3 : 0);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityEffect(Entity entity, int effectID, int amplifier, int duration) {
|
||||
super(v_1_17 ? 3 : 0);
|
||||
this.entityID = entity.getEntityId();
|
||||
this.entity = entity;
|
||||
this.effectID = effectID;
|
||||
@@ -50,6 +56,7 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityEffect(int entityID, int effectID, int amplifier, int duration, boolean hideParticles, boolean ambient, boolean showIcon) {
|
||||
super(v_1_17 ? 3 : 0);
|
||||
this.entityID = entityID;
|
||||
this.effectID = effectID;
|
||||
this.amplifier = amplifier;
|
||||
@@ -77,21 +84,46 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
}
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityEffect(Entity entity, PotionEffectType effectType, int amplifier, int duration) {
|
||||
this(entity, effectType.getId(), amplifier, duration);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityEffect(int entityID, PotionEffectType effectType, int amplifier, int duration, boolean hideParticles, boolean ambient, boolean showIcon) {
|
||||
this(entityID, effectType.getId(), amplifier, duration, hideParticles, ambient, showIcon);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityEffect(Entity entity, Effect effect, int amplifier, int duration) {
|
||||
this(entity, effect.getId(), amplifier, duration);
|
||||
}
|
||||
|
||||
public WrappedPacketOutEntityEffect(int entityID, Effect effect, int amplifier, int duration, boolean hideParticles, boolean ambient, boolean showIcon) {
|
||||
this(entityID, effect.getId(), amplifier, duration, hideParticles, ambient, showIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.ENTITY_EFFECT.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_EFFECT.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
} else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_EFFECT.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getEffectId() {
|
||||
if (effectID != -1) {
|
||||
return effectID;
|
||||
}
|
||||
if (packet != null) {
|
||||
return effectID = readByte(0);
|
||||
if (v_1_18_2) {
|
||||
return readInt(4);
|
||||
}
|
||||
else {
|
||||
return readByte(0);
|
||||
}
|
||||
} else {
|
||||
return effectID;
|
||||
}
|
||||
@@ -99,18 +131,20 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public void setEffectId(int effectID) {
|
||||
if (packet != null) {
|
||||
writeByte(0, (byte) (this.effectID = effectID));
|
||||
if (v_1_18_2) {
|
||||
writeInt(4, effectID);
|
||||
}
|
||||
else {
|
||||
writeByte(0, (byte) effectID);
|
||||
}
|
||||
} else {
|
||||
this.effectID = effectID;
|
||||
}
|
||||
}
|
||||
|
||||
public int getAmplifier() {
|
||||
if (amplifier != -1) {
|
||||
return amplifier;
|
||||
}
|
||||
if (packet != null) {
|
||||
return amplifier = readByte(1);
|
||||
return readByte(v_1_18_2 ? 0 : 1);
|
||||
} else {
|
||||
return amplifier;
|
||||
}
|
||||
@@ -118,21 +152,25 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
public void setAmplifier(int amplifier) {
|
||||
if (packet != null) {
|
||||
writeByte(1, (byte) (this.amplifier = amplifier));
|
||||
writeByte(v_1_18_2 ? 0 : 1, (byte) amplifier);
|
||||
} else {
|
||||
this.amplifier = amplifier;
|
||||
}
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
if (duration != -1) {
|
||||
return duration;
|
||||
}
|
||||
if (packet != null) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
return duration = readShort(1);
|
||||
} else {
|
||||
return duration = readInt(1);
|
||||
//1.7 and only 1.7
|
||||
if (v_1_7_10) {
|
||||
return readShort(1);
|
||||
}
|
||||
//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 {
|
||||
return duration;
|
||||
@@ -142,15 +180,19 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
public void setDuration(int duration) {
|
||||
if (packet != null) {
|
||||
this.duration = duration;
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
if (duration > Short.MAX_VALUE) {
|
||||
duration = Short.MAX_VALUE;
|
||||
} else if (duration < Short.MIN_VALUE) {
|
||||
duration = Short.MIN_VALUE;
|
||||
}
|
||||
writeShort(0, (short) duration);
|
||||
} else {
|
||||
writeInt(1, duration);
|
||||
}
|
||||
else if (v_1_18_2) {
|
||||
writeInt(5, duration);
|
||||
}
|
||||
else {
|
||||
writeInt(v_1_17 ? 4 : 1, duration);
|
||||
}
|
||||
} else {
|
||||
this.duration = duration;
|
||||
@@ -158,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,15 +313,25 @@ public class WrappedPacketOutEntityEffect extends WrappedPacketEntityAbstraction
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetPlayOutEntityEffectInstance = packetDefaultConstructor.newInstance();
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
//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();
|
||||
|
||||
}
|
||||
WrappedPacketOutEntityEffect wrappedPacketOutEntityEffect =
|
||||
new WrappedPacketOutEntityEffect(new NMSPacket(packetPlayOutEntityEffectInstance));
|
||||
new WrappedPacketOutEntityEffect(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutEntityEffect.setEntityId(getEntityId());
|
||||
wrappedPacketOutEntityEffect.setEffectId(getEffectId());
|
||||
wrappedPacketOutEntityEffect.setAmplifier(getAmplifier());
|
||||
wrappedPacketOutEntityEffect.setDuration(getDuration());
|
||||
Optional<Byte> optionalByteMask = getByteMask();
|
||||
optionalByteMask.ifPresent(wrappedPacketOutEntityEffect::setByteMask);
|
||||
return packetPlayOutEntityEffectInstance;
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
+20
-15
@@ -18,6 +18,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.entityequipment;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.api.SendableWrapper;
|
||||
@@ -36,8 +37,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WrappedPacketOutEntityEquipment extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_17;
|
||||
private static Class<? extends Enum<?>> enumItemSlotClass;
|
||||
private static Constructor<?> packetDefaultConstructor;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private List<Pair<EquipmentSlot, ItemStack>> equipment;
|
||||
private EquipmentSlot legacySlot;
|
||||
private ItemStack legacyItemStack;
|
||||
@@ -82,23 +84,19 @@ public class WrappedPacketOutEntityEquipment extends WrappedPacketEntityAbstract
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.ENTITY_EQUIPMENT.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_EQUIPMENT.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
} else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_EQUIPMENT.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
enumItemSlotClass = NMSUtils.getNMSEnumClassWithoutException("EnumItemSlot");
|
||||
if (version.isNewerThan(ServerVersion.v_1_8_8)) {
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
slot.id = (byte) slot.ordinal();
|
||||
}
|
||||
} else {
|
||||
EquipmentSlot.MAINHAND.id = 0;
|
||||
EquipmentSlot.OFFHAND.id = -1; //Invalid
|
||||
EquipmentSlot.BOOTS.id = 1;
|
||||
EquipmentSlot.LEGGINGS.id = 2;
|
||||
EquipmentSlot.CHESTPLATE.id = 3;
|
||||
EquipmentSlot.HELMET.id = 4;
|
||||
if (enumItemSlotClass == null) {
|
||||
enumItemSlotClass = NMSUtils.getNMEnumClassWithoutException("world.entity.EnumItemSlot");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +208,14 @@ public class WrappedPacketOutEntityEquipment extends WrappedPacketEntityAbstract
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = packetDefaultConstructor.newInstance();
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(PacketEvents.get().getByteBufUtil().newByteBuf(new byte[] {0, 0, 0, 0}));
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
}
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
WrappedPacketOutEntityEquipment wrappedPacketOutEntityEquipment = new WrappedPacketOutEntityEquipment(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutEntityEquipment.setEntityId(getEntityId());
|
||||
wrappedPacketOutEntityEquipment.setEquipment(getEquipment());
|
||||
@@ -225,7 +230,7 @@ public class WrappedPacketOutEntityEquipment extends WrappedPacketEntityAbstract
|
||||
CHESTPLATE,
|
||||
HELMET;
|
||||
|
||||
private byte id;
|
||||
public byte id;
|
||||
|
||||
@Nullable
|
||||
public static EquipmentSlot getById(byte id) {
|
||||
|
||||
+29
-11
@@ -18,28 +18,33 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.entityheadrotation;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketOutEntityHeadRotation extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static Constructor<?> packetDefaultConstructor;
|
||||
private byte yaw;
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
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;
|
||||
@@ -47,24 +52,30 @@ public class WrappedPacketOutEntityHeadRotation extends WrappedPacketEntityAbstr
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.ENTITY_HEAD_ROTATION.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_HEAD_ROTATION.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
}
|
||||
else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_HEAD_ROTATION.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -72,10 +83,17 @@ public class WrappedPacketOutEntityHeadRotation extends WrappedPacketEntityAbstr
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = packetDefaultConstructor.newInstance();
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(PacketEvents.get().getByteBufUtil().newByteBuf(new byte[] {0, 0}));
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
}
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
WrappedPacketOutEntityHeadRotation wrappedPacketOutEntityHeadRotation = new WrappedPacketOutEntityHeadRotation(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutEntityHeadRotation.setYaw(getYaw());
|
||||
wrappedPacketOutEntityHeadRotation.setEntityId(getEntityId());
|
||||
wrappedPacketOutEntityHeadRotation.setYaw(getYaw());
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
+4
@@ -37,6 +37,10 @@ public class WrappedPacketOutEntityMetadata extends WrappedPacketEntityAbstracti
|
||||
|
||||
public List<WrappedWatchableObject> getWatchableObjects() {
|
||||
List<Object> nmsWatchableObjectList = readList(0);
|
||||
//Its annotated as nullable on 1.17 NMS, so lets just handle it being null
|
||||
if (nmsWatchableObjectList == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<WrappedWatchableObject> wrappedWatchableObjects = new ArrayList<>(nmsWatchableObjectList.size());
|
||||
for (Object watchableObject : nmsWatchableObjectList) {
|
||||
wrappedWatchableObjects.add(new WrappedWatchableObject(new NMSPacket(watchableObject)));
|
||||
|
||||
+23
-4
@@ -18,16 +18,19 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.entitystatus;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketOutEntityStatus extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private byte status;
|
||||
|
||||
@@ -48,9 +51,15 @@ public class WrappedPacketOutEntityStatus extends WrappedPacketEntityAbstraction
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_STATUS.getConstructor(NMSUtils.nmsEntityClass, byte.class);
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.ENTITY_STATUS.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
}
|
||||
else {
|
||||
packetConstructor =
|
||||
PacketTypeClasses.Play.Server.ENTITY_STATUS.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -74,7 +83,17 @@ public class WrappedPacketOutEntityStatus extends WrappedPacketEntityAbstraction
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object nmsEntity = NMSUtils.getNMSEntity(getEntity());
|
||||
return packetConstructor.newInstance(nmsEntity, getEntityStatus());
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(PacketEvents.get().getByteBufUtil().newByteBuf(new byte[] {0, 0, 0, 0, 0}));
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
}
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
WrappedPacketOutEntityStatus entityStatus = new WrappedPacketOutEntityStatus(new NMSPacket(packetInstance));
|
||||
entityStatus.setEntityId(getEntityId());
|
||||
entityStatus.setEntityStatus(getEntityStatus());
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
+26
-3
@@ -18,10 +18,13 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.entityteleport;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3d;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -30,6 +33,7 @@ import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketOutEntityTeleport extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static final float rotationMultiplier = 256.0F / 360.0F;
|
||||
private static boolean v_1_17;
|
||||
private static boolean legacyVersionMode;
|
||||
private static boolean ultraLegacyVersionMode;
|
||||
private static Constructor<?> constructor;
|
||||
@@ -90,6 +94,7 @@ public class WrappedPacketOutEntityTeleport extends WrappedPacketEntityAbstracti
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Server.ENTITY_TELEPORT;
|
||||
try {
|
||||
constructor = packetClass.getConstructor(int.class, int.class, int.class, int.class, byte.class, byte.class, boolean.class, boolean.class);
|
||||
@@ -102,7 +107,11 @@ public class WrappedPacketOutEntityTeleport extends WrappedPacketEntityAbstracti
|
||||
legacyVersionMode = true;
|
||||
} catch (NoSuchMethodException e2) {
|
||||
try {
|
||||
constructor = packetClass.getConstructor();
|
||||
if (v_1_17) {
|
||||
constructor = packetClass.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
} else {
|
||||
constructor = packetClass.getConstructor();
|
||||
}
|
||||
ultraLegacyVersionMode = false;
|
||||
legacyVersionMode = false;
|
||||
} catch (NoSuchMethodException e3) {
|
||||
@@ -208,8 +217,22 @@ public class WrappedPacketOutEntityTeleport extends WrappedPacketEntityAbstracti
|
||||
(byte) ((int) getYaw() * rotationMultiplier), (byte) (int) (getPitch() * rotationMultiplier), false);
|
||||
} else {
|
||||
//newer versions
|
||||
Object instance = constructor.newInstance();
|
||||
|
||||
Object instance;
|
||||
if (v_1_17) {
|
||||
Object byteBuf = PacketEvents.get().getByteBufUtil().newByteBuf(new byte[]{
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0});
|
||||
//4 bytes per bytebuf field
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(byteBuf);
|
||||
instance = constructor.newInstance(packetDataSerializer);
|
||||
} else {
|
||||
instance = constructor.newInstance();
|
||||
}
|
||||
WrappedPacketOutEntityTeleport instanceWrapper = new WrappedPacketOutEntityTeleport(new NMSPacket(instance));
|
||||
instanceWrapper.setEntityId(getEntityId());
|
||||
instanceWrapper.setPosition(pos);
|
||||
|
||||
+3
-4
@@ -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) {
|
||||
|
||||
+11
-23
@@ -18,6 +18,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.explosion;
|
||||
|
||||
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;
|
||||
@@ -33,7 +34,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WrappedPacketOutExplosion extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> chunkPosConstructor, blockPosConstructor, packetConstructor, vec3dConstructor;
|
||||
private static boolean v_1_8;
|
||||
private static Constructor<?> chunkPosConstructor, packetConstructor;
|
||||
|
||||
private double x, y, z;
|
||||
private float strength;
|
||||
@@ -70,25 +72,14 @@ public class WrappedPacketOutExplosion extends WrappedPacket implements Sendable
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> chunkPosClass = NMSUtils.getNMSClassWithoutException("ChunkPosition");
|
||||
Class<?> blockPosClass = NMSUtils.getNMSClassWithoutException("BlockPosition");
|
||||
Class<?> packetClass = NMSUtils.getNMSClassWithoutException("PacketPlayOutExplosion");
|
||||
Class<?> vec3DClass = NMSUtils.getNMSClassWithoutException("Vec3D");
|
||||
v_1_8 = version.isNewerThanOrEquals(ServerVersion.v_1_8);
|
||||
|
||||
try {
|
||||
packetConstructor = packetClass.getConstructor(double.class, double.class, double.class, float.class, List.class, vec3DClass);
|
||||
vec3dConstructor = vec3DClass.getDeclaredConstructor(double.class, double.class, double.class);
|
||||
Class<?> chunkPosClass = NMSUtils.getNMSClassWithoutException("ChunkPosition");
|
||||
packetConstructor = PacketTypeClasses.Play.Server.EXPLOSION.getConstructor(double.class, double.class, double.class, float.class, List.class, NMSUtils.vec3DClass);
|
||||
if (chunkPosClass != null) {
|
||||
chunkPosConstructor = chunkPosClass.getConstructor(int.class, int.class, int.class);
|
||||
}
|
||||
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (blockPosClass != null) {
|
||||
blockPosConstructor = blockPosClass.getConstructor(int.class, int.class, int.class);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -211,10 +202,9 @@ public class WrappedPacketOutExplosion extends WrappedPacket implements Sendable
|
||||
if (packet != null) {
|
||||
List<Object> nmsRecordsList = new ArrayList<>();
|
||||
for (Vector3i record : records) {
|
||||
Object[] arguments = {record.x, record.y, record.z};
|
||||
Object position = null; //construct position
|
||||
try {
|
||||
position = version.isNewerThan(ServerVersion.v_1_7_10) ? blockPosConstructor.newInstance(arguments) : chunkPosConstructor.newInstance(arguments);
|
||||
position = v_1_8 ? NMSUtils.generateNMSBlockPos(record) : chunkPosConstructor.newInstance(record.x, record.y, record.z);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -248,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) {
|
||||
@@ -307,14 +296,13 @@ public class WrappedPacketOutExplosion extends WrappedPacket implements Sendable
|
||||
public Object asNMSPacket() throws Exception {
|
||||
List<Object> positions = new ArrayList<>();
|
||||
for (Vector3i record : getRecords()) {
|
||||
Object[] arguments = {record.x, record.y, record.z};
|
||||
Object position = version.isNewerThan(ServerVersion.v_1_7_10) ? blockPosConstructor.newInstance(arguments)
|
||||
: chunkPosConstructor.newInstance(arguments);
|
||||
Object position = v_1_8 ? NMSUtils.generateNMSBlockPos(record)
|
||||
: chunkPosConstructor.newInstance(record.x, record.y, record.z);
|
||||
positions.add(position);
|
||||
}
|
||||
Vector3f velocity = getPlayerVelocity();
|
||||
Vector3f pos = getPlayerVelocity();
|
||||
Object vec = vec3dConstructor.newInstance(velocity.x, velocity.y, velocity.z);
|
||||
Object vec = NMSUtils.generateVec3D(velocity);
|
||||
return packetConstructor.newInstance(pos.x, pos.y, pos.z, getStrength(), positions, vec);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -54,6 +54,7 @@ public class WrappedPacketOutGameStateChange extends WrappedPacket implements Se
|
||||
@Override
|
||||
protected void load() {
|
||||
reasonClassType = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.GAME_STATE_CHANGE, 0);
|
||||
net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange gsc;
|
||||
if (reasonClassType != null) {
|
||||
try {
|
||||
reasonClassConstructor = reasonClassType.getConstructor(int.class);
|
||||
@@ -140,7 +141,7 @@ public class WrappedPacketOutGameStateChange extends WrappedPacket implements Se
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
if (reasonClassType == null) {
|
||||
if (reasonIntMode) {
|
||||
if (valueFloatMode) {
|
||||
return packetConstructor.newInstance(getReason(), (float) getValue());
|
||||
} else {
|
||||
|
||||
+1
-3
@@ -42,10 +42,8 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
Class<?> packetClass = PacketTypeClasses.Play.Server.KICK_DISCONNECT;
|
||||
|
||||
try {
|
||||
kickDisconnectConstructor = packetClass.getConstructor(NMSUtils.iChatBaseComponentClass);
|
||||
kickDisconnectConstructor = PacketTypeClasses.Play.Server.KICK_DISCONNECT.getConstructor(NMSUtils.iChatBaseComponentClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+6
-6
@@ -25,13 +25,16 @@ import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
|
||||
//TODO Make sendable and finish
|
||||
public class WrappedPacketOutLogin extends WrappedPacketEntityAbstraction {
|
||||
private static boolean v_1_13_2, v_1_17;
|
||||
|
||||
public WrappedPacketOutLogin(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
|
||||
v_1_13_2 = version.isNewerThanOrEquals(ServerVersion.v_1_13_2);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
|
||||
public boolean isHardcore() {
|
||||
@@ -70,11 +73,8 @@ public class WrappedPacketOutLogin extends WrappedPacketEntityAbstraction {
|
||||
|
||||
public int getMaxPlayers() {
|
||||
if (packet != null) {
|
||||
if (version.isNewerThan(ServerVersion.v_1_13_1)) {
|
||||
return readInt(1);
|
||||
} else {
|
||||
return readInt(2);
|
||||
}
|
||||
int index = v_1_13_2 && !v_1_17 ? 1 : 2;
|
||||
return readInt(index);
|
||||
} else {
|
||||
//TODO Finish
|
||||
return -1;
|
||||
|
||||
+75
-29
@@ -21,15 +21,19 @@ 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;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.BitSet;
|
||||
import java.util.Optional;
|
||||
|
||||
//TODO finish wrapper
|
||||
public class WrappedPacketOutMapChunk extends WrappedPacket {
|
||||
private 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;
|
||||
|
||||
@@ -39,55 +43,82 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
chunkMapClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.MAP_CHUNK, "ChunkMap");
|
||||
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 {
|
||||
chunkMapConstructor = chunkMapClass.getConstructor();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
net.minecraft.server.v1_7_R4.PacketPlayOutMapChunk a0;
|
||||
net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk a1;
|
||||
net.minecraft.server.v1_9_R1.PacketPlayOutMapChunk a2;
|
||||
net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk a3;
|
||||
net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk a4;
|
||||
net.minecraft.server.v1_13_R1.PacketPlayOutMapChunk a5;
|
||||
net.minecraft.server.v1_13_R2.PacketPlayOutMapChunk a6;
|
||||
net.minecraft.server.v1_16_R2.PacketPlayOutMapChunk a7;
|
||||
chunkPacketDataClass = Reflection.getClassByNameWithoutException("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData");
|
||||
}
|
||||
|
||||
|
||||
public int getChunkX() {
|
||||
return readInt(0);
|
||||
return readInt(v_1_17 && !v_1_18 ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setChunkX(int chunkX) {
|
||||
writeInt(0, chunkX);
|
||||
writeInt(v_1_17 && !v_1_18 ? 1 : 0, chunkX);
|
||||
}
|
||||
|
||||
public int getChunkZ() {
|
||||
return readInt(1);
|
||||
return readInt(v_1_17 && !v_1_18 ? 2 : 1);
|
||||
}
|
||||
|
||||
public void setChunkZ(int chunkZ) {
|
||||
writeInt(1, chunkZ);
|
||||
writeInt(v_1_17 && !v_1_18 ? 2 : 1, chunkZ);
|
||||
}
|
||||
|
||||
public int getPrimaryBitMap() {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
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));
|
||||
}
|
||||
|
||||
if (v_1_8_x) {
|
||||
if (nmsChunkMap == null) {
|
||||
nmsChunkMap = readObject(0, chunkMapClass);
|
||||
}
|
||||
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
|
||||
return nmsChunkMapWrapper.readInt(0);
|
||||
return Optional.of(BitSet.valueOf(new long[]{nmsChunkMapWrapper.readInt(0)}));
|
||||
} else {
|
||||
return readInt(2);
|
||||
return Optional.of(BitSet.valueOf(new long[]{readInt(2)}));
|
||||
}
|
||||
}
|
||||
|
||||
public void setPrimaryBitMap(int primaryBitMap) {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
/**
|
||||
* @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);
|
||||
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) {
|
||||
if (nmsChunkMap == null) {
|
||||
try {
|
||||
nmsChunkMap = chunkMapConstructor.newInstance();
|
||||
@@ -96,36 +127,50 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
|
||||
}
|
||||
}
|
||||
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
|
||||
nmsChunkMapWrapper.writeInt(0, primaryBitMap);
|
||||
nmsChunkMapWrapper.writeInt(0, primaryBitMask);
|
||||
write(chunkMapClass, 0, nmsChunkMap);
|
||||
|
||||
} else {
|
||||
writeInt(2, primaryBitMap);
|
||||
writeInt(2, primaryBitMask);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGroundUpContinuous() {
|
||||
return readBoolean(0);
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
return Optional.of(readBoolean(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
writeBoolean(0, groundUpContinuous);
|
||||
}
|
||||
|
||||
public byte[] getCompressedData() {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
if (v_1_8_x) {
|
||||
if (nmsChunkMap == null) {
|
||||
nmsChunkMap = readObject(0, chunkMapClass);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompressedData(byte[] data) {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
if (v_1_8_x) {
|
||||
if (nmsChunkMap == null) {
|
||||
try {
|
||||
nmsChunkMap = chunkMapConstructor.newInstance();
|
||||
@@ -136,9 +181,10 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+22
-5
@@ -18,18 +18,20 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.mount;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
//TODO Test sending this wrapper on 1.17
|
||||
public class WrappedPacketOutMount extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static Constructor<?> packetDefaultConstructor;
|
||||
|
||||
private static boolean v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int[] passengerIDs;
|
||||
|
||||
public WrappedPacketOutMount(NMSPacket packet) {
|
||||
@@ -48,8 +50,14 @@ public class WrappedPacketOutMount extends WrappedPacketEntityAbstraction implem
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
try {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.MOUNT.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.MOUNT.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
}
|
||||
else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.MOUNT.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -78,8 +86,17 @@ public class WrappedPacketOutMount extends WrappedPacketEntityAbstraction implem
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetInstance = packetDefaultConstructor.newInstance();
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object byteBuf = PacketEvents.get().getByteBufUtil().newByteBuf(new byte[] {0, 0, 0, 0, 0, 0, 0, 0});
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(byteBuf);
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
}
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
WrappedPacketOutMount wrappedPacketOutMount = new WrappedPacketOutMount(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutMount.setEntityId(getEntityId());
|
||||
wrappedPacketOutMount.setPassengerIds(getPassengerIds());
|
||||
return packetInstance;
|
||||
}
|
||||
|
||||
+25
-5
@@ -18,12 +18,14 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.namedentityspawn;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.reflection.Reflection;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.vector.Vector3d;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -32,9 +34,10 @@ import java.lang.reflect.Constructor;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WrappedPacketOutNamedEntitySpawn extends WrappedPacketEntityAbstraction implements SendableWrapper {
|
||||
private static boolean v_1_17;
|
||||
private static final float rotationDividend = 256.0F / 360.0F;
|
||||
private static boolean doublesPresent, dataWatcherPresent;
|
||||
private static Constructor<?> packetDefaultConstructor;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private UUID uuid;
|
||||
private Vector3d position;
|
||||
private float yaw, pitch;
|
||||
@@ -99,10 +102,16 @@ public class WrappedPacketOutNamedEntitySpawn extends WrappedPacketEntityAbstrac
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
doublesPresent = Reflection.getField(PacketTypeClasses.Play.Server.NAMED_ENTITY_SPAWN, double.class, 1) != null;
|
||||
dataWatcherPresent = Reflection.getField(PacketTypeClasses.Play.Server.NAMED_ENTITY_SPAWN, NMSUtils.dataWatcherClass, 0) != null;
|
||||
try {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.NAMED_ENTITY_SPAWN.getConstructor();
|
||||
if (v_1_17){
|
||||
packetConstructor = PacketTypeClasses.Play.Server.NAMED_ENTITY_SPAWN.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
}
|
||||
else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.NAMED_ENTITY_SPAWN.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -196,8 +205,19 @@ public class WrappedPacketOutNamedEntitySpawn extends WrappedPacketEntityAbstrac
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetPlayOutNamedEntitySpawnInstance = packetDefaultConstructor.newInstance();
|
||||
WrappedPacketOutNamedEntitySpawn wrappedPacketOutNamedEntitySpawn = new WrappedPacketOutNamedEntitySpawn(new NMSPacket(packetPlayOutNamedEntitySpawnInstance));
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
//we were at 40
|
||||
byte[] bytes = new byte[60];
|
||||
Object byteBuf = PacketEvents.get().getByteBufUtil().newByteBuf(bytes);
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(byteBuf);
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
}
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
|
||||
WrappedPacketOutNamedEntitySpawn wrappedPacketOutNamedEntitySpawn = new WrappedPacketOutNamedEntitySpawn(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutNamedEntitySpawn.setEntityId(getEntityId());
|
||||
wrappedPacketOutNamedEntitySpawn.setUUID(getUUID());
|
||||
wrappedPacketOutNamedEntitySpawn.setPosition(getPosition());
|
||||
@@ -207,6 +227,6 @@ public class WrappedPacketOutNamedEntitySpawn extends WrappedPacketEntityAbstrac
|
||||
wrappedPacketOutNamedEntitySpawn.write(NMSUtils.dataWatcherClass, 0, NMSUtils.generateDataWatcher(null));
|
||||
}
|
||||
|
||||
return packetPlayOutNamedEntitySpawnInstance;
|
||||
return packetInstance;
|
||||
}
|
||||
}
|
||||
+52
-40
@@ -33,7 +33,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> packetDefaultConstructor, soundEffectConstructor;
|
||||
private static boolean v_1_9, v_1_17;
|
||||
private static Constructor<?> packetConstructor, soundEffectConstructor;
|
||||
private static Class<? extends Enum<?>> enumSoundCategoryClass;
|
||||
private static boolean soundEffectVarExists;
|
||||
private static float pitchMultiplier = 63.0F;
|
||||
@@ -64,9 +65,14 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_9 = version.isNewerThanOrEquals(ServerVersion.v_1_9);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
soundEffectVarExists = NMSUtils.soundEffectClass != null;
|
||||
if (soundEffectVarExists) {
|
||||
enumSoundCategoryClass = NMSUtils.getNMSEnumClassWithoutException("SoundCategory");
|
||||
if (enumSoundCategoryClass == null) {
|
||||
enumSoundCategoryClass = NMSUtils.getNMEnumClassWithoutException("sounds.SoundCategory");
|
||||
}
|
||||
try {
|
||||
soundEffectConstructor = NMSUtils.soundEffectClass.getConstructor(NMSUtils.minecraftKeyClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
@@ -75,7 +81,13 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
}
|
||||
pitchMultiplier = version.isNewerThan(ServerVersion.v_1_9_4) ? 1 : version.isNewerThan(ServerVersion.v_1_8_8) ? 63.5F : 63.0F;
|
||||
try {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.NAMED_SOUND_EFFECT.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.NAMED_SOUND_EFFECT.getConstructor(NMSUtils.soundEffectClass,
|
||||
enumSoundCategoryClass, double.class, double.class, double.class, float.class, float.class);
|
||||
}
|
||||
else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.NAMED_SOUND_EFFECT.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -86,8 +98,7 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
if (soundEffectVarExists) {
|
||||
Object soundEffect = readObject(0, NMSUtils.soundEffectClass);
|
||||
WrappedPacket soundEffectWrapper = new WrappedPacket(new NMSPacket(soundEffect));
|
||||
Object minecraftKey = soundEffectWrapper.readObject(0, NMSUtils.minecraftKeyClass);
|
||||
return NMSUtils.getStringFromMinecraftKey(minecraftKey);
|
||||
return soundEffectWrapper.readMinecraftKey(0);
|
||||
} else {
|
||||
return readString(0);
|
||||
}
|
||||
@@ -99,7 +110,7 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
public void setSoundEffectName(String name) {
|
||||
if (packet != null) {
|
||||
if (soundEffectVarExists) {
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKey(name);
|
||||
Object minecraftKey = NMSUtils.generateMinecraftKeyNew(name);
|
||||
Object soundEffect = null;
|
||||
try {
|
||||
soundEffect = soundEffectConstructor.newInstance(minecraftKey);
|
||||
@@ -116,23 +127,25 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
}
|
||||
|
||||
public Optional<SoundCategory> getSoundCategory() {
|
||||
if (version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (packet != null) {
|
||||
Enum<?> enumConst = readEnumConstant(0, enumSoundCategoryClass);
|
||||
return Optional.ofNullable(SoundCategory.getByName(enumConst.name()));
|
||||
} else {
|
||||
return Optional.of(soundCategory);
|
||||
}
|
||||
if (v_1_9) {
|
||||
if (packet != null) {
|
||||
Enum<?> enumConst = readEnumConstant(0, enumSoundCategoryClass);
|
||||
return Optional.ofNullable(SoundCategory.values()[enumConst.ordinal()]);
|
||||
} else {
|
||||
return Optional.of(soundCategory);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSoundCategory(SoundCategory soundCategory) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_9)) {
|
||||
if (!v_1_9) {
|
||||
return;
|
||||
}
|
||||
if (packet != null) {
|
||||
Enum<?> enumConst = EnumUtil.valueOf(enumSoundCategoryClass, soundCategory.name());
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(enumSoundCategoryClass, soundCategory.ordinal());
|
||||
writeEnumConstant(0, enumConst);
|
||||
} else {
|
||||
this.soundCategory = soundCategory;
|
||||
@@ -163,7 +176,7 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
//Might be more than 1.0 on some older versions. 1 is 100%
|
||||
public float getVolume() {
|
||||
if (packet != null) {
|
||||
return readFloat(0);
|
||||
return readFloat(v_1_17 ? 1 : 0);
|
||||
} else {
|
||||
return volume;
|
||||
}
|
||||
@@ -171,7 +184,7 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
|
||||
public void setVolume(float volume) {
|
||||
if (packet != null) {
|
||||
writeFloat(0, volume);
|
||||
writeFloat(v_1_17 ? 1 : 0, volume);
|
||||
} else {
|
||||
this.volume = volume;
|
||||
}
|
||||
@@ -182,7 +195,7 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
if (version.isOlderThan(ServerVersion.v_1_10)) {
|
||||
return readInt(3) / pitchMultiplier;
|
||||
} else {
|
||||
return readFloat(1);
|
||||
return readFloat(v_1_17 ? 2: 1);
|
||||
}
|
||||
} else {
|
||||
return pitch;
|
||||
@@ -194,7 +207,7 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
if (version.isOlderThan(ServerVersion.v_1_10)) {
|
||||
writeInt(1, (int) (pitch * pitchMultiplier));
|
||||
} else {
|
||||
writeFloat(1, pitch);
|
||||
writeFloat(v_1_17 ? 2 : 1, pitch);
|
||||
}
|
||||
} else {
|
||||
this.pitch = pitch;
|
||||
@@ -203,16 +216,25 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
Object packetPlayOutNamedSoundEffectInstance = packetDefaultConstructor.newInstance();
|
||||
WrappedPacketOutNamedSoundEffect wrappedPacketOutNamedSoundEffect = new WrappedPacketOutNamedSoundEffect(new NMSPacket(packetPlayOutNamedSoundEffectInstance));
|
||||
wrappedPacketOutNamedSoundEffect.setSoundEffectName(getSoundEffectName());
|
||||
if (soundEffectVarExists) {
|
||||
wrappedPacketOutNamedSoundEffect.setSoundCategory(getSoundCategory().get());
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object nmsSoundEffect = soundEffectConstructor.newInstance(NMSUtils.generateMinecraftKeyNew(getSoundEffectName()));
|
||||
Object nmsSoundCategory = EnumUtil.valueByIndex(enumSoundCategoryClass, getSoundCategory().get().ordinal());
|
||||
Vector3d effectPos = getEffectPosition();
|
||||
packetInstance = packetConstructor.newInstance(nmsSoundEffect, nmsSoundCategory, effectPos.x, effectPos.y, effectPos.z, getVolume(), getPitch());
|
||||
}
|
||||
wrappedPacketOutNamedSoundEffect.setEffectPosition(getEffectPosition());
|
||||
wrappedPacketOutNamedSoundEffect.setPitch(getPitch());
|
||||
wrappedPacketOutNamedSoundEffect.setVolume(getVolume());
|
||||
return packetPlayOutNamedSoundEffectInstance;
|
||||
else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
WrappedPacketOutNamedSoundEffect wrappedPacketOutNamedSoundEffect = new WrappedPacketOutNamedSoundEffect(new NMSPacket(packetInstance));
|
||||
wrappedPacketOutNamedSoundEffect.setSoundEffectName(getSoundEffectName());
|
||||
if (soundEffectVarExists) {
|
||||
wrappedPacketOutNamedSoundEffect.setSoundCategory(getSoundCategory().get());
|
||||
}
|
||||
wrappedPacketOutNamedSoundEffect.setEffectPosition(getEffectPosition());
|
||||
wrappedPacketOutNamedSoundEffect.setPitch(getPitch());
|
||||
wrappedPacketOutNamedSoundEffect.setVolume(getVolume());
|
||||
}
|
||||
return packetInstance;
|
||||
}
|
||||
|
||||
public enum SoundCategory {
|
||||
@@ -225,16 +247,6 @@ public class WrappedPacketOutNamedSoundEffect extends WrappedPacket implements S
|
||||
NEUTRAL,
|
||||
PLAYERS,
|
||||
AMBIENT,
|
||||
VOICE;
|
||||
|
||||
@Nullable
|
||||
public static SoundCategory getByName(String name) {
|
||||
for (SoundCategory value : values()) {
|
||||
if (value.name().equalsIgnoreCase(name)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
VOICE
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -103,8 +103,7 @@ public class WrappedPacketOutOpenWindow extends WrappedPacket {
|
||||
if (ultraLegacyMode) {
|
||||
return readString(0);
|
||||
}
|
||||
Object iChatBaseComp = readObject(0, NMSUtils.iChatBaseComponentClass);
|
||||
return NMSUtils.readIChatBaseComponent(iChatBaseComp);
|
||||
return readIChatBaseComponent(0);
|
||||
}
|
||||
return windowTitle;
|
||||
}
|
||||
@@ -114,8 +113,7 @@ public class WrappedPacketOutOpenWindow extends WrappedPacket {
|
||||
if (ultraLegacyMode) {
|
||||
writeString(0, title);
|
||||
} else {
|
||||
Object iChatBaseComponent = NMSUtils.generateIChatBaseComponent(title);
|
||||
write(NMSUtils.iChatBaseComponentClass, 0, iChatBaseComponent);
|
||||
writeIChatBaseComponent(0, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.ping;
|
||||
|
||||
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.server.ServerVersion;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class WrappedPacketOutPing extends WrappedPacket implements SendableWrapper {
|
||||
private static Constructor<?> packetConstructor;
|
||||
private int id;
|
||||
|
||||
public WrappedPacketOutPing(NMSPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public WrappedPacketOutPing(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.PING.getConstructor(int.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
if (packet != null) {
|
||||
return readInt(0);
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
if (packet != null) {
|
||||
writeInt(0, id);
|
||||
} else {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
return packetConstructor.newInstance(getId());
|
||||
}
|
||||
}
|
||||
+36
-34
@@ -18,6 +18,7 @@
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.play.out.playerinfo;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
|
||||
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
@@ -37,9 +38,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WrappedPacketOutPlayerInfo extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean v_1_7_10, v_1_17;
|
||||
private static Class<? extends Enum<?>> enumPlayerInfoActionClass;
|
||||
private static Class<?> playerInfoDataClass;
|
||||
private static Constructor<?> packetDefaultConstructor, playerInfoDataConstructor;
|
||||
private static Constructor<?> packetConstructor, playerInfoDataConstructor;
|
||||
private static byte constructorMode = 0;
|
||||
private PlayerInfoAction action;
|
||||
private PlayerInfo[] playerInfoArray = new PlayerInfo[0];
|
||||
@@ -55,13 +56,19 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_7_10 = version.isOlderThan(ServerVersion.v_1_8);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
enumPlayerInfoActionClass = SubclassUtil.getEnumSubClass(PacketTypeClasses.Play.Server.PLAYER_INFO, "EnumPlayerInfoAction");
|
||||
try {
|
||||
packetDefaultConstructor = PacketTypeClasses.Play.Server.PLAYER_INFO.getConstructor();
|
||||
if (v_1_17) {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.PLAYER_INFO.getConstructor(NMSUtils.packetDataSerializerClass);
|
||||
} else {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.PLAYER_INFO.getConstructor();
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
playerInfoDataClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.PLAYER_INFO, "PlayerInfoData");
|
||||
Class<?> playerInfoDataClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.PLAYER_INFO, "PlayerInfoData");
|
||||
if (playerInfoDataClass != null) {
|
||||
try {
|
||||
playerInfoDataConstructor = playerInfoDataClass.getConstructor(NMSUtils.gameProfileClass, int.class, NMSUtils.enumGameModeClass, NMSUtils.iChatBaseComponentClass);
|
||||
@@ -81,7 +88,7 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
public PlayerInfoAction getAction() {
|
||||
if (packet != null) {
|
||||
int index;
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
index = readInt(0);
|
||||
} else {
|
||||
Enum<?> enumConst = readEnumConstant(0, enumPlayerInfoActionClass);
|
||||
@@ -96,7 +103,7 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
public void setAction(PlayerInfoAction action) {
|
||||
if (packet != null) {
|
||||
int index = action.ordinal();
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
writeInt(0, index);
|
||||
} else {
|
||||
Enum<?> enumConst = EnumUtil.valueByIndex(enumPlayerInfoActionClass, action.ordinal());
|
||||
@@ -110,7 +117,7 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
public PlayerInfo[] getPlayerInfo() {
|
||||
if (packet != null) {
|
||||
PlayerInfo[] playerInfoArray = new PlayerInfo[1];
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
String username = readString(0);
|
||||
Object mojangGameProfile = readObject(0, NMSUtils.gameProfileClass);
|
||||
WrappedGameProfile gameProfile = GameProfileUtil.getWrappedGameProfile(mojangGameProfile);
|
||||
@@ -118,21 +125,14 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
int ping = readInt(2);
|
||||
playerInfoArray[0] = new PlayerInfo(username, gameProfile, gameMode, ping);
|
||||
} else {
|
||||
List<Object> nmsPlayerInfoDataList = readObject(0, List.class);
|
||||
List<Object> nmsPlayerInfoDataList = readList(0);
|
||||
for (int i = 0; i < nmsPlayerInfoDataList.size(); i++) {
|
||||
Object nmsPlayerInfoData = nmsPlayerInfoDataList.get(i);
|
||||
WrappedPacket nmsPlayerInfoDataWrapper = new WrappedPacket(new NMSPacket(nmsPlayerInfoData));
|
||||
Object iChatBaseComponentName = nmsPlayerInfoDataWrapper.readObject(0, NMSUtils.iChatBaseComponentClass);
|
||||
String username;
|
||||
if (iChatBaseComponentName == null) {
|
||||
username = null;
|
||||
} else {
|
||||
username = NMSUtils.readIChatBaseComponent(iChatBaseComponentName);
|
||||
}
|
||||
String username = nmsPlayerInfoDataWrapper.readIChatBaseComponent(0);
|
||||
Object mojangGameProfile = nmsPlayerInfoDataWrapper.readObject(0, NMSUtils.gameProfileClass);
|
||||
WrappedGameProfile gameProfile = GameProfileUtil.getWrappedGameProfile(mojangGameProfile);
|
||||
Enum<?> nmsGameModeEnumConstant = nmsPlayerInfoDataWrapper.readEnumConstant(0, NMSUtils.enumGameModeClass);
|
||||
GameMode gameMode = GameMode.valueOf(nmsGameModeEnumConstant.name());
|
||||
GameMode gameMode = nmsPlayerInfoDataWrapper.readGameMode(0);
|
||||
int ping = nmsPlayerInfoDataWrapper.readInt(0);
|
||||
playerInfoArray[i] = new PlayerInfo(username, gameProfile, gameMode, ping);
|
||||
}
|
||||
@@ -144,11 +144,11 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
}
|
||||
|
||||
public void setPlayerInfo(PlayerInfo... playerInfoArray) throws UnsupportedOperationException {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8) && playerInfoArray.length > 1) {
|
||||
throw new UnsupportedOperationException("The player info list size cannot be greater than 1 on 1.7.10 server versions!");
|
||||
if (v_1_7_10 && playerInfoArray.length > 1) {
|
||||
throw new UnsupportedOperationException("The player info list size cannot be greater than 1 on 1.7.10 servers!");
|
||||
}
|
||||
if (packet != null) {
|
||||
if (version.isOlderThan(ServerVersion.v_1_8)) {
|
||||
if (v_1_7_10) {
|
||||
PlayerInfo playerInfo = playerInfoArray[0];
|
||||
writeString(0, playerInfo.username);
|
||||
Object mojangGameProfile = GameProfileUtil.getGameProfile(playerInfo.gameProfile.getId(), playerInfo.gameProfile.getName());
|
||||
@@ -161,7 +161,7 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
for (PlayerInfo playerInfo : playerInfoArray) {
|
||||
Object usernameIChatBaseComponent = NMSUtils.generateIChatBaseComponent(NMSUtils.fromStringToJSON(playerInfo.username));
|
||||
Object mojangGameProfile = GameProfileUtil.getGameProfile(playerInfo.gameProfile.getId(), playerInfo.gameProfile.getName());
|
||||
Enum<?> nmsGameModeEnumConstant = EnumUtil.valueOf(NMSUtils.enumGameModeClass, playerInfo.gameMode.name());
|
||||
Enum<?> nmsGameModeEnumConstant = EnumUtil.valueByIndex(NMSUtils.enumGameModeClass, playerInfo.gameMode.ordinal());
|
||||
int ping = playerInfo.ping;
|
||||
try {
|
||||
if (constructorMode == 0) {
|
||||
@@ -174,7 +174,7 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
write(List.class, 0, nmsPlayerInfoList);
|
||||
writeList(0, nmsPlayerInfoList);
|
||||
}
|
||||
} else {
|
||||
this.playerInfoArray = playerInfoArray;
|
||||
@@ -183,19 +183,21 @@ public class WrappedPacketOutPlayerInfo extends WrappedPacket implements Sendabl
|
||||
|
||||
@Override
|
||||
public Object asNMSPacket() throws Exception {
|
||||
try {
|
||||
Object packetPlayOutPlayerInfoInstance = packetDefaultConstructor.newInstance();
|
||||
WrappedPacketOutPlayerInfo playerInfoWrapper = new WrappedPacketOutPlayerInfo(new NMSPacket(packetPlayOutPlayerInfoInstance));
|
||||
PlayerInfo[] playerInfos = getPlayerInfo();
|
||||
if (playerInfos.length != 0) {
|
||||
playerInfoWrapper.setPlayerInfo(playerInfos);
|
||||
}
|
||||
playerInfoWrapper.setAction(getAction());
|
||||
return packetPlayOutPlayerInfoInstance;
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
Object packetInstance;
|
||||
if (v_1_17) {
|
||||
Object byteBuf = PacketEvents.get().getByteBufUtil().newByteBuf(new byte[] {0, 0, 0, 0, 0, 0, 0, 0});
|
||||
Object packetDataSerializer = NMSUtils.generatePacketDataSerializer(byteBuf);
|
||||
packetInstance = packetConstructor.newInstance(packetDataSerializer);
|
||||
} else {
|
||||
packetInstance = packetConstructor.newInstance();
|
||||
}
|
||||
return null;
|
||||
WrappedPacketOutPlayerInfo playerInfoWrapper = new WrappedPacketOutPlayerInfo(new NMSPacket(packetInstance));
|
||||
PlayerInfo[] playerInfos = getPlayerInfo();
|
||||
if (playerInfos.length != 0) {
|
||||
playerInfoWrapper.setPlayerInfo(playerInfos);
|
||||
}
|
||||
playerInfoWrapper.setAction(getAction());
|
||||
return packetInstance;
|
||||
}
|
||||
|
||||
public enum PlayerInfoAction {
|
||||
|
||||
+30
-8
@@ -33,6 +33,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public final class WrappedPacketOutPosition extends WrappedPacket implements SendableWrapper {
|
||||
private static boolean v_1_8, v_1_17;
|
||||
private static Constructor<?> packetConstructor;
|
||||
private static byte constructorMode = 0;
|
||||
private static Class<? extends Enum<?>> enumPlayerTeleportFlagsClass;
|
||||
@@ -42,7 +43,6 @@ public final class WrappedPacketOutPosition extends WrappedPacket implements Sen
|
||||
private Set<PlayerTeleportFlags> relativeFlags;
|
||||
private int teleportID;
|
||||
|
||||
@Deprecated
|
||||
private boolean onGround;
|
||||
|
||||
public WrappedPacketOutPosition(NMSPacket packet) {
|
||||
@@ -83,8 +83,19 @@ public final class WrappedPacketOutPosition extends WrappedPacket implements Sen
|
||||
this.teleportID = teleportID;
|
||||
}
|
||||
|
||||
public WrappedPacketOutPosition(Vector3d position, float yaw, float pitch, Set<PlayerTeleportFlags> relativeFlags, int teleportID, boolean onGround) {
|
||||
this.position = position;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.relativeFlags = relativeFlags;
|
||||
this.teleportID = teleportID;
|
||||
this.onGround= onGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
v_1_8 = version.isNewerThanOrEquals(ServerVersion.v_1_8);
|
||||
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
|
||||
enumPlayerTeleportFlagsClass = SubclassUtil.getEnumSubClass(PacketTypeClasses.Play.Server.POSITION, "EnumPlayerTeleportFlags");
|
||||
try {
|
||||
//1.7.10
|
||||
@@ -96,21 +107,28 @@ public final class WrappedPacketOutPosition extends WrappedPacket implements Sen
|
||||
packetConstructor = PacketTypeClasses.Play.Server.POSITION.getConstructor(double.class, double.class, double.class, float.class, float.class, Set.class);
|
||||
} catch (NoSuchMethodException e2) {
|
||||
constructorMode = 2;
|
||||
//1.9 -> 1.16.5
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.POSITION.getConstructor(double.class, double.class, double.class, float.class, float.class, Set.class, int.class);
|
||||
} catch (NoSuchMethodException e3) {
|
||||
throw new IllegalStateException("Failed to locate a supported constructor of the PacketPlayOutPosition packet class.");
|
||||
constructorMode = 3;
|
||||
//1.17
|
||||
try {
|
||||
packetConstructor = PacketTypeClasses.Play.Server.POSITION.getConstructor(double.class, double.class, double.class, float.class, float.class, Set.class, int.class, boolean.class);
|
||||
} catch (NoSuchMethodException e4) {
|
||||
throw new IllegalStateException("Failed to locate a supported constructor of the PacketPlayOutPosition packet class.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Boolean> isOnGround() {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10)) {
|
||||
//1.7.10 and 1.17+ support this field
|
||||
if (v_1_8 && !v_1_17) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (packet != null) {
|
||||
|
||||
return Optional.of(readBoolean(0));
|
||||
} else {
|
||||
return Optional.of(onGround);
|
||||
@@ -118,11 +136,10 @@ public final class WrappedPacketOutPosition extends WrappedPacket implements Sen
|
||||
}
|
||||
|
||||
public void setOnGround(boolean onGround) {
|
||||
if (version.isNewerThan(ServerVersion.v_1_7_10)) {
|
||||
if (v_1_8 && !v_1_17) {
|
||||
return;
|
||||
}
|
||||
if (packet != null) {
|
||||
|
||||
writeBoolean(0, onGround);
|
||||
} else {
|
||||
this.onGround = onGround;
|
||||
@@ -308,9 +325,14 @@ public final class WrappedPacketOutPosition extends WrappedPacket implements Sen
|
||||
//1.8 -> 1.8.8
|
||||
return packetConstructor.newInstance(position.x, position.y, position.z, getYaw(), getPitch(), nmsRelativeFlags);
|
||||
case 2:
|
||||
return packetConstructor.newInstance(position.x, position.y, position.z, getYaw(), getPitch(), nmsRelativeFlags, getTeleportId());
|
||||
//1.9 -> 1.16.5
|
||||
return packetConstructor.newInstance(position.x, position.y, position.z, getYaw(), getPitch(), nmsRelativeFlags, getTeleportId().get());
|
||||
case 3:
|
||||
//1.17
|
||||
return packetConstructor.newInstance(position.x, position.y, position.z, getYaw(), getPitch(), nmsRelativeFlags, getTeleportId(), isOnGround().get());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum PlayerTeleportFlags {
|
||||
|
||||
Loaded 100 of 146 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user