Compare commits

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

No files matched your search

+18 -15
View File
@@ -1,7 +1,7 @@
---
name: Bug report
about: Report bugs to help us improve our software.
title: ""
about: Report a bug to help us fix
title: "[BUG REPORT]"
labels: bug
assignees: ''
@@ -10,21 +10,11 @@ assignees: ''
**Describe the bug**
A clear and concise description of what the bug is.
**Software brand**
Please let us know what software you are using.
Eg. Spigot 1.18.2, Paper 1.18.2, Tuinity 1.18.2, Pufferfish 1.18.2, etc...
Make sure to mention the version of the software.
**Plugins**
Please give us a list of your plugins. Sometimes we run into incompatibilities. Having an overview of the plugins on your server can really help identify the problem quicker.
Eg. ViaVersion, ProtocolLib, HolographicDisplays
You may also provide a screenshot.
**How To Reproduce**
**To Reproduce**
Steps to reproduce the behavior:
*Example:*
1. Join with the 1.18.2 vanilla minecraft client.
2. Spam
1. Login on the 1.16.4 minecraft client.
2. Join the server while it is still starting up.
3. ....
4. See error
@@ -34,5 +24,18 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**About your server (please complete the following information):**
- Spigot: [eg. Paper or Tuinity]
We only accept reports that are reproducible
on one of the supported spigots.
- Server Version: [eg. 1.16.4]
Feel free to report bugs for versions newer than 1.7.10, even if we
don’t support them yet, but be aware that we might have already
found the bug and fixed it in a dev build, just before you reported it.
Please don’t get frustrated in such cases.
- Plugins List if possible: [eg. ViaVersion, ProtocolLib, HolographicDisplays]
**Additional context**
Add any other context about the problem here.
+18 -39
View File
@@ -1,3 +1,6 @@
# 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 ]
@@ -11,44 +14,20 @@ jobs:
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
- 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 shadowJar
- name: Build with Gradle
run: gradle :clean :build
- name: Upload build artifacts api
uses: actions/upload-artifact@v1
with:
name: api-build
path: api/build/libs
- name: Upload build artifacts spigot
uses: actions/upload-artifact@v1
with:
name: spigot-build
path: spigot/build/libs
- name: Upload build artifacts netty-common
uses: actions/upload-artifact@v1
with:
name: netty-common-build
path: netty-common/build/libs
- name: Upload build artifacts bungeecord
uses: actions/upload-artifact@v1
with:
name: bungeecord-build
path: bungeecord/build/libs
- name: Upload build artifacts velocity
uses: actions/upload-artifact@v1
with:
name: velocity-build
path: velocity/build/libs
- name: Upload build artifacts
uses: actions/upload-artifact@v1
with:
name: packetevents-dev-build.jar
path: build/libs
+86 -89
View File
@@ -1,18 +1,78 @@
# User-specific stuff
/.idea
#
# JetBrains
#
*.iml
*.ipr
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
#
# Java
#
# Compiled class file
*.class
@@ -22,6 +82,9 @@ atlassian-ide-plugin.xml
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
@@ -34,87 +97,21 @@ atlassian-ide-plugin.xml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Cache of project
.gradletasknamecache
**/build/
# Common working directory
run/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
/src/main/resources/plugin.yml
#
# Maven
#
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
/src/main/resources/
/.gradle/
/.idea/
/build/
+9 -15
View File
@@ -3,31 +3,25 @@
[![](https://img.shields.io/badge/License-GPLv3-yellow.svg)](https://github.com/retrooper/packetevents/blob/dev/LICENSE)
[![](https://jitpack.io/v/retrooper/packetevents.svg)](https://jitpack.io/#retrooper/packetevents)
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. With our API, you can write code that runs on many platforms including Spigot, BungeeCord, Velocity, and even client-sided Fabric!
PacketEvents is an open-source Packet API. It has many cross-version packet-wrappers. You can process incoming and outgoing packets on the server. You can even send packets with our packet-wrappers. We are here to save you a ton of time.
### Resources
* [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
* [JavaDocs](https://packetevents.github.io/javadocs)
* [JavaDoc](https://packetevents.github.io/javadocs)
* [Discord](https://discord.me/packetevents)
### Setup
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup)
[Learn more](https://github.com/retrooper/packetevents/wiki/1.-Setup)
### Contributing
[Learn more](https://github.com/retrooper/packetevents/wiki/Contributing)
### Contributing/Forking
[Learn more](https://github.com/retrooper/packetevents/wiki/2.-Contributing-and-Forking)\
Our discord server has a role for contributors and forkers.
### Sponsorships
[![](https://www.ej-technologies.com/images/product_banners/jprofiler_small.png)](https://www.ej-technologies.com/products/jprofiler/overview.html)
### Statistics
PacketEvents optionally collects statistics using [bStats](https://bstats.org/)\
Check out our [bStats page](https://bstats.org/plugin/bukkit/packetevents/11327)
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 to
[wiki.vg/Protocol](https://wiki.vg/Protocol)
[adventure](https://github.com/KyoriPowered/adventure)
[gson](https://github.com/google/gson)
[ViaVersion](https://github.com/ViaVersion/ViaVersion)
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)
[MCProtocolLib](https://github.com/GeyserMC/MCProtocolLib/)
[netty](https://github.com/netty/netty)
### Credit
PacketEvents uses an injector that is extremely similar to ViaVersion's injector. I have included license and copyright holder notice in the files taken from ViaVersion. Thank you ViaVersion.
-3
View File
@@ -1,3 +0,0 @@
dependencies {
compileOnly(adventureDependencies)
}
@@ -1,87 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents;
import com.github.retrooper.packetevents.event.EventManager;
import com.github.retrooper.packetevents.injector.ChannelInjector;
import com.github.retrooper.packetevents.manager.player.PlayerManager;
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
import com.github.retrooper.packetevents.manager.server.ServerManager;
import com.github.retrooper.packetevents.netty.NettyManager;
import com.github.retrooper.packetevents.settings.PacketEventsSettings;
import com.github.retrooper.packetevents.util.LogManager;
import com.github.retrooper.packetevents.util.PEVersion;
import com.github.retrooper.packetevents.util.updatechecker.UpdateChecker;
import java.util.logging.Logger;
public abstract class PacketEventsAPI<T> {
private static final EventManager EVENT_MANAGER = new EventManager();
private static final PacketEventsSettings SETTINGS = new PacketEventsSettings();
private static final UpdateChecker UPDATE_CHECKER = new UpdateChecker();
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
private static final LogManager LOG_MANAGER = new LogManager();
private static final PEVersion VERSION = new PEVersion(2, 0, 0);
public EventManager getEventManager() {
return EVENT_MANAGER;
}
public PacketEventsSettings getSettings() {
return SETTINGS;
}
public UpdateChecker getUpdateChecker() {
return UPDATE_CHECKER;
}
public PEVersion getVersion() {
return VERSION;
}
public Logger getLogger() {
return LOGGER;
}
public LogManager getLogManager() {
return LOG_MANAGER;
}
public abstract void load();
public abstract boolean isLoaded();
public abstract void init();
public abstract boolean isInitialized();
public abstract void terminate();
public abstract T getPlugin();
public abstract ServerManager getServerManager();
public abstract ProtocolManager getProtocolManager();
public abstract PlayerManager getPlayerManager();
public abstract NettyManager getNettyManager();
public abstract ChannelInjector getInjector();
}
@@ -1,119 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.PacketEvents;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
public class EventManager {
private final Map<Byte, HashSet<PacketListenerCommon>> listenersMap = new ConcurrentHashMap<>();
/**
* Call the PacketEvent.
* This method processes the event on all the registered dynamic packet event listeners.
* The {@link PacketListenerPriority#LOWEST} prioritized listeners will be processing first,
* the {@link PacketListenerPriority#MONITOR} will be processing last and can
* be the final decider whether the event has been cancelled or not.
*
* @param event {@link PacketEvent}
*/
public void callEvent(PacketEvent event) {
callEvent(event, null);
}
public void callEvent(PacketEvent event, @Nullable Runnable postCallListenerAction) {
for (byte priority = PacketListenerPriority.LOWEST.getId(); priority <= PacketListenerPriority.MONITOR.getId(); priority++) {
HashSet<PacketListenerCommon> listeners = listenersMap.get(priority);
if (listeners != null) {
for (PacketListenerCommon listener : listeners) {
try {
event.call(listener);
} catch (Throwable t) {
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
}
if (postCallListenerAction != null) {
postCallListenerAction.run();
}
}
}
}
if (event instanceof ProtocolPacketEvent && PacketEvents.getAPI().getSettings().shouldListenersReadOnly()) {
((ProtocolPacketEvent<?>) event).setLastUsedWrapper(null);
}
}
public PacketListenerCommon registerListener(PacketListener listener, PacketListenerPriority priority) {
PacketListenerCommon packetListenerAbstract = listener.asAbstract(priority);
return registerListener(packetListenerAbstract);
}
/**
* Register the dynamic packet event listener.
*
* @param listener {@link PacketListenerCommon}
*/
public PacketListenerCommon registerListener(PacketListenerCommon listener) {
byte priority = listener.getPriority().getId();
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(priority);
if (listenerSet == null) {
listenerSet = new HashSet<>();
}
listenerSet.add(listener);
listenersMap.put(priority, listenerSet);
return listener;
}
/**
* Register multiple dynamic packet event listeners with one method.
*
* @param listeners {@link PacketListenerCommon}
*/
public PacketListenerCommon[] registerListeners(PacketListenerCommon... listeners) {
for (PacketListenerCommon listener : listeners) {
registerListener(listener);
}
return listeners;
}
public void unregisterListener(PacketListenerCommon listener) {
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority().getId());
if (listenerSet == null) return;
listenerSet.remove(listener);
}
public void unregisterListeners(PacketListenerCommon... listeners) {
for (PacketListenerCommon listener : listeners) {
unregisterListener(listener);
}
}
/**
* Unregister all dynamic packet event listeners.
*/
public void unregisterAllListeners() {
listenersMap.clear();
}
}
@@ -1,73 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
public interface PacketListener {
default PacketListenerAbstract asAbstract(PacketListenerPriority priority) {
return new PacketListenerAbstract(priority) {
@Override
public void onUserConnect(UserConnectEvent event) {
PacketListener.this.onUserConnect(event);
}
@Override
public void onUserLogin(UserLoginEvent event) {
PacketListener.this.onUserLogin(event);
}
@Override
public void onUserDisconnect(UserDisconnectEvent event) {
PacketListener.this.onUserDisconnect(event);
}
@Override
public void onPacketReceive(PacketReceiveEvent event) {
PacketListener.this.onPacketReceive(event);
}
@Override
public void onPacketSend(PacketSendEvent event) {
PacketListener.this.onPacketSend(event);
}
@Override
public void onPacketEventExternal(PacketEvent event) {
PacketListener.this.onPacketEventExternal(event);
}
};
}
default void onUserConnect(UserConnectEvent event) {
}
default void onUserLogin(UserLoginEvent event) {
}
default void onUserDisconnect(UserDisconnectEvent event) {
}
default void onPacketReceive(PacketReceiveEvent event) {
}
default void onPacketSend(PacketSendEvent event) {
}
default void onPacketEventExternal(PacketEvent event) {
}
}
@@ -1,64 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
/**
* Abstract packet listener.
*
* @author retrooper
* @since 1.8
*/
public abstract class PacketListenerCommon {
private final PacketListenerPriority priority;
public PacketListenerCommon(PacketListenerPriority priority) {
this.priority = priority;
}
public PacketListenerCommon() {
this.priority = PacketListenerPriority.NORMAL;
}
public PacketListenerPriority getPriority() {
return priority;
}
public void onUserConnect(UserConnectEvent event) {
}
public void onUserLogin(UserLoginEvent event) {
}
public void onUserDisconnect(UserDisconnectEvent event) {
}
void onPacketReceive(PacketReceiveEvent event) {
}
void onPacketSend(PacketSendEvent event) {
}
public void onPacketEventExternal(PacketEvent event) {
}
}
@@ -1,66 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.*;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketReceiveEvent extends ProtocolPacketEvent<Object> {
protected PacketReceiveEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(PacketSide.CLIENT, channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketReceiveEvent(int packetID, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel, User user, Object player,
Object byteBuf) throws PacketProcessException {
super(packetID, packetType, serverVersion,
channel, user, player, byteBuf);
}
@Override
public void call(PacketListenerCommon listener) {
listener.onPacketReceive(this);
}
@Override
public PacketReceiveEvent clone() {
if (this instanceof PacketHandshakeReceiveEvent) {
return ((PacketHandshakeReceiveEvent)this).clone();
}
else if (this instanceof PacketStatusReceiveEvent) {
return ((PacketStatusReceiveEvent)this).clone();
}
else if (this instanceof PacketLoginReceiveEvent) {
return ((PacketLoginReceiveEvent)this).clone();
}
else if (this instanceof PacketPlayReceiveEvent) {
return ((PacketPlayReceiveEvent)this).clone();
}
else {
return null;
}
}
}
@@ -1,66 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.PacketLoginSendEvent;
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
import com.github.retrooper.packetevents.event.simple.PacketStatusSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketSendEvent extends ProtocolPacketEvent<Object> {
protected PacketSendEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(PacketSide.SERVER, channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketSendEvent(int packetID, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel, User user,
Object player, Object byteBuf) throws PacketProcessException {
super(packetID, packetType,
serverVersion,
channel, user, player, byteBuf);
}
@Override
public void call(PacketListenerCommon listener) {
listener.onPacketSend(this);
}
@Override
public PacketSendEvent clone() {
if (this instanceof PacketStatusSendEvent) {
return ((PacketStatusSendEvent)this).clone();
}
else if (this instanceof PacketLoginSendEvent) {
return ((PacketLoginSendEvent)this).clone();
}
else if (this instanceof PacketPlaySendEvent) {
return ((PacketPlaySendEvent)this).clone();
}
else {
return null;
}
}
}
@@ -1,209 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
public abstract class ProtocolPacketEvent<T> extends PacketEvent implements PlayerEvent<T>, CancellableEvent, UserEvent {
private final Object channel;
private final ConnectionState connectionState;
private final User user;
private final T player;
private Object byteBuf;
private final int packetID;
private final PacketTypeCommon packetType;
private ServerVersion serverVersion;
private boolean cancel;
private PacketWrapper<?> lastUsedWrapper;
private List<Runnable> postTasks = null;
private boolean cloned;
public ProtocolPacketEvent(PacketSide packetSide, Object channel,
User user, T player, Object byteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
this.channel = channel;
this.user = user;
this.player = player;
if (autoProtocolTranslation || user.getClientVersion() == null) {
this.serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
}
else {
//TODO Optimize
this.serverVersion = user.getClientVersion().toServerVersion();
}
this.byteBuf = byteBuf;
int size = ByteBufHelper.readableBytes(byteBuf);
if (size == 0) {
throw new PacketProcessException("Trying to process a packet, but it has no content. (Size=0)");
}
try {
this.packetID = ByteBufHelper.readVarInt(byteBuf);
} catch (Exception e) {
throw new PacketProcessException("Failed to read the Packet ID of a packet. (Size: " + size + ")");
}
ClientVersion version = serverVersion.toClientVersion();
this.packetType = PacketType.getById(packetSide, user.getConnectionState(),
version, packetID);
if (this.packetType == null) {
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
}
this.connectionState = user.getConnectionState();
}
public ProtocolPacketEvent(int packetID, PacketTypeCommon packetType, ServerVersion serverVersion, Object channel,
User user, T player, Object byteBuf) {
this.channel = channel;
this.user = user;
this.player = player;
this.serverVersion = serverVersion;
this.byteBuf = byteBuf;
this.packetID = packetID;
this.packetType = packetType;
this.connectionState = user.getConnectionState();
cloned = true;
}
public boolean isClone() {
return cloned;
}
public Object getChannel() {
return channel;
}
public InetSocketAddress getSocketAddress() {
return (InetSocketAddress) ChannelHelper.remoteAddress(channel);
}
@Override
public User getUser() {
return user;
}
@Override
public T getPlayer() {
return player;
}
public ConnectionState getConnectionState() {
return connectionState;
}
//TODO Possibly put clientversion inside User class and remove here
@Deprecated
public ClientVersion getClientVersion() {
return user.getClientVersion();
}
@Deprecated
public void setClientVersion(@NotNull ClientVersion clientVersion) {
PacketEvents.getAPI().getLogManager().debug("Setting client version with deprecated method " + clientVersion.getReleaseName());
user.setClientVersion(clientVersion);
}
public ServerVersion getServerVersion() {
return serverVersion;
}
public void setServerVersion(@NotNull ServerVersion serverVersion) {
this.serverVersion = serverVersion;
}
public Object getByteBuf() {
return byteBuf;
}
public void setByteBuf(Object byteBuf) {
this.byteBuf = byteBuf;
}
@Deprecated
public int getPacketId() {
return packetID;
}
public PacketTypeCommon getPacketType() {
return packetType;
}
@Deprecated
public String getPacketName() {
return ((Enum<?>) packetType).name();
}
@Override
public boolean isCancelled() {
return this.cancel;
}
@Override
public void setCancelled(boolean val) {
this.cancel = val;
}
@Nullable
public PacketWrapper<?> getLastUsedWrapper() {
return lastUsedWrapper;
}
public void setLastUsedWrapper(@Nullable PacketWrapper<?> lastUsedWrapper) {
this.lastUsedWrapper = lastUsedWrapper;
}
public List<Runnable> getPostTasks() {
if (postTasks == null) {
postTasks = new ArrayList<>();
}
return postTasks;
}
public boolean hasPostTasks() {
return postTasks != null && !postTasks.isEmpty();
}
@Override
public ProtocolPacketEvent<?> clone() {
return this instanceof PacketReceiveEvent ? ((PacketReceiveEvent) this).clone()
: ((PacketSendEvent) this).clone();
}
public void cleanUp() {
if (isClone()) {
ByteBufHelper.release(byteBuf);
}
}
}
@@ -1,80 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.*;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
public abstract class SimplePacketListenerAbstract extends PacketListenerCommon {
public SimplePacketListenerAbstract(PacketListenerPriority priority) {
super(priority);
}
public SimplePacketListenerAbstract() {
super();
}
@Override
void onPacketReceive(PacketReceiveEvent event) {
if (event instanceof PacketHandshakeReceiveEvent) {
onPacketHandshakeReceive((PacketHandshakeReceiveEvent) event);
} else if (event instanceof PacketStatusReceiveEvent) {
onPacketStatusReceive((PacketStatusReceiveEvent) event);
} else if (event instanceof PacketLoginReceiveEvent) {
onPacketLoginReceive((PacketLoginReceiveEvent) event);
} else if (event instanceof PacketPlayReceiveEvent) {
onPacketPlayReceive((PacketPlayReceiveEvent) event);
}
}
@Override
void onPacketSend(PacketSendEvent event) {
if (event instanceof PacketStatusSendEvent) {
onPacketStatusSend((PacketStatusSendEvent) event);
} else if (event instanceof PacketLoginSendEvent) {
onPacketLoginSend((PacketLoginSendEvent) event);
} else if (event instanceof PacketPlaySendEvent) {
onPacketPlaySend((PacketPlaySendEvent) event);
}
}
public void onPacketHandshakeReceive(PacketHandshakeReceiveEvent event) {
}
public void onPacketStatusReceive(PacketStatusReceiveEvent event) {
}
public void onPacketStatusSend(PacketStatusSendEvent event) {
}
public void onPacketLoginReceive(PacketLoginReceiveEvent event) {
}
public void onPacketLoginSend(PacketLoginSendEvent event) {
}
public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
}
public void onPacketPlaySend(PacketPlaySendEvent event) {
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketHandshakeReceiveEvent extends PacketReceiveEvent {
public PacketHandshakeReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketHandshakeReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketHandshakeReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketHandshakeReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Handshaking.Client getPacketType() {
return (PacketType.Handshaking.Client) super.getPacketType();
}
}
@@ -1,59 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketLoginReceiveEvent extends PacketReceiveEvent {
public PacketLoginReceiveEvent(Object channel, User user, Object player,
Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketLoginReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketLoginReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketLoginReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Login.Client getPacketType() {
return (PacketType.Login.Client) super.getPacketType();
}
}
@@ -1,57 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketLoginSendEvent extends PacketSendEvent {
public PacketLoginSendEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketLoginSendEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketLoginSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketLoginSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Login.Server getPacketType() {
return (PacketType.Login.Server) super.getPacketType();
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketPlayReceiveEvent extends PacketReceiveEvent {
public PacketPlayReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketPlayReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketPlayReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketPlayReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Play.Client getPacketType() {
return (PacketType.Play.Client) super.getPacketType();
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketPlaySendEvent extends PacketSendEvent {
public PacketPlaySendEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketPlaySendEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketPlaySendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketPlaySendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Play.Server getPacketType() {
return (PacketType.Play.Server) super.getPacketType();
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketStatusReceiveEvent extends PacketReceiveEvent {
public PacketStatusReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketStatusReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketStatusReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketStatusReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Status.Client getPacketType() {
return (PacketType.Status.Client) super.getPacketType();
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketStatusSendEvent extends PacketSendEvent {
public PacketStatusSendEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketStatusSendEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketStatusSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketStatusSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Status.Server getPacketType() {
return (PacketType.Status.Server) super.getPacketType();
}
}
@@ -1,43 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.injector;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.player.User;
import org.jetbrains.annotations.Nullable;
public interface ChannelInjector {
default boolean isServerBound() {
return true;
}
void inject();
void uninject();
User getUser(Object channel);
void changeConnectionState(Object channel, @Nullable ConnectionState connectionState);
void updateUser(Object channel, User user);
void setPlayer(Object channel, Object player);
boolean hasPlayer(Object player);
}
@@ -1,137 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.manager;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.wrapper.handshaking.client.WrapperHandshakingClientHandshake;
import com.github.retrooper.packetevents.wrapper.login.server.WrapperLoginServerLoginSuccess;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRespawn;
import java.net.InetSocketAddress;
public class InternalPacketListener extends PacketListenerAbstract {
public InternalPacketListener() {
this(PacketListenerPriority.LOWEST);
}
public InternalPacketListener(PacketListenerPriority priority) {
super(priority);
}
@Override
public void onPacketSend(PacketSendEvent event) {
User user = event.getUser();
if (event.getPacketType() == PacketType.Login.Server.LOGIN_SUCCESS) {
Object channel = event.getChannel();
//Process outgoing login success packet
WrapperLoginServerLoginSuccess loginSuccess = new WrapperLoginServerLoginSuccess(event);
UserProfile profile = loginSuccess.getUserProfile();
//Update user profile
user.getProfile().setUUID(profile.getUUID());
user.getProfile().setName(profile.getName());
//Map username with channel
ProtocolManager.CHANNELS.put(profile.getName(), channel);
PacketEvents.getAPI().getLogManager().debug("Mapped player username with their channel.");
//Update connection state(injectors might do some adjustments when we transition into PLAY state)
//This also updates it for the user instance
event.getPostTasks().add(() -> {
PacketEvents.getAPI().getInjector().changeConnectionState(channel, ConnectionState.PLAY);
PacketEvents.getAPI().getLogManager().debug("Transitioned " + profile.getName() + " into the PLAY state!");
});
}
// Join game can be used to update world height, and sets dimension data
if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
user.setEntityId(joinGame.getEntityId());
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
// Store world height
NBTList<NBTCompound> list = joinGame.getDimensionCodec()
.getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
user.setWorldNBT(list);
// Update world height
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getType().getName()).getCompoundTagOrNull("element");
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
}
// Respawn is used to switch dimensions
if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
if (event.getServerVersion()
.isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getType().getName()).getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
}
}
@Override
public void onPacketReceive(PacketReceiveEvent event) {
User user = event.getUser();
if (event.getPacketType() == PacketType.Handshaking.Client.HANDSHAKE) {
Object channel = event.getChannel();
InetSocketAddress address = event.getSocketAddress();
WrapperHandshakingClientHandshake handshake;
try {
handshake = new WrapperHandshakingClientHandshake(event);
} catch (ArrayIndexOutOfBoundsException exception) {
user.closeConnection();
PacketEvents.getAPI().getLogManager().debug("Disconnected " + address.getHostString() + ":" + address.getPort() + " for sending an invalid handshaking packet. They might be on an outdated client.");
return;
}
ConnectionState nextState = handshake.getNextConnectionState();
ClientVersion clientVersion = handshake.getClientVersion();
//Update client version for this event call(and user)
user.setClientVersion(clientVersion);
PacketEvents.getAPI().getLogManager().debug("Processed " + address.getHostString() + ":" + address.getPort() + "'s client version. Client Version: " + clientVersion.getReleaseName());
event.getPostTasks().add(() -> {
//Transition into the LOGIN OR STATUS connection state
PacketEvents.getAPI().getInjector().changeConnectionState(channel, nextState);
PacketEvents.getAPI().getLogManager().debug("Transitioned " + address.getHostString() + ":" + address.getPort() + " into the " + nextState + " state!");
});
}
}
}
@@ -1,136 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.manager.player;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
public interface PlayerManager {
int getPing(@NotNull Object player);
@NotNull ClientVersion getClientVersion(@NotNull Object player);
Object getChannel(@NotNull Object player);
@NotNull User getUser(@NotNull Object player);
default ConnectionState getConnectionState(@NotNull Object player) {
return getUser(player).getConnectionState();
}
default void sendPacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), byteBuf);
}
default void sendPacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), byteBuf);
}
default void sendPacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), wrapper);
}
default void sendPacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), wrapper);
}
default void sendPacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), byteBuf);
}
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), byteBuf);
}
default void sendPacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), wrapper);
}
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), wrapper);
}
default void writePacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), byteBuf);
}
default void writePacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), byteBuf);
}
default void writePacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), wrapper);
}
default void writePacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), wrapper);
}
default void writePacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), byteBuf);
}
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), byteBuf);
}
default void writePacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), wrapper);
}
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), wrapper);
}
default void receivePacket(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), byteBuf);
}
default void receivePacketAsync(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), byteBuf);
}
default void receivePacket(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), wrapper);
}
default void receivePacketAsync(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), wrapper);
}
default void receivePacketSilently(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), byteBuf);
}
default void receivePacketSilentlyAsync(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), byteBuf);
}
default void receivePacketSilently(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), wrapper);
}
default void receivePacketSilentlyAsync(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), wrapper);
}
}
@@ -1,209 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.manager.protocol;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.ProtocolVersion;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public interface ProtocolManager {
Map<String, Object> CHANNELS = new ConcurrentHashMap<>();
Map<Object, User> USERS = new ConcurrentHashMap<>();
default Collection<User> getUsers() {
return USERS.values();
}
default Collection<Object> getChannels() {
return CHANNELS.values();
}
//Methods to implement
ProtocolVersion getPlatformVersion();
void sendPacket(Object channel, Object packet);
void sendPacketSilently(Object channel, Object packet);
void writePacket(Object channel, Object packet);
void writePacketSilently(Object channel, Object packet);
void receivePacket(Object channel, Object packet);
void receivePacketSilently(Object channel, Object packet);
ClientVersion getClientVersion(Object channel);
default void sendPacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacket(channel, byteBuf);
});
}
default void sendPacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacketSilently(channel, byteBuf);
});
}
default void writePacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacket(channel, byteBuf);
});
}
default void writePacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacketSilently(channel, byteBuf);
});
}
default void receivePacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacket(channel, byteBuf);
});
}
default void receivePacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacketSilently(channel, byteBuf);
});
}
//TODO Make it clear that this only updates the connection state in our user.
//Sometimes you should use getInjector().changeConnectionState because that can allow the injector to make adjustments.
//This is very important, especially on Spigot.
//As soon as we switch to the play state on spigot, our injector makes some adjustments.
default void changeConnectionState(Object channel, ConnectionState connectionState) {
getUser(channel).setConnectionState(connectionState);
}
default void setClientVersion(Object channel, ClientVersion version) {
getUser(channel).setClientVersion(version);
}
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
sendPacket(channel, packet.buffer);
}
}
default void sendPacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacket(channel, wrapper);
});
}
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
sendPacketSilently(channel, packet.buffer);
}
}
default void sendPacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacketSilently(channel, wrapper);
});
}
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
writePacket(channel, packet.buffer);
}
}
default void writePacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacket(channel, wrapper);
});
}
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
writePacketSilently(channel, packet.buffer);
}
}
default void writePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacketSilently(channel, wrapper);
});
}
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
receivePacket(channel, packet.buffer);
}
}
default void receivePacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacket(channel, wrapper);
});
}
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
receivePacketSilently(channel, packet.buffer);
}
}
default void receivePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacketSilently(channel, wrapper);
});
}
default User getUser(Object channel) {
return USERS.get(channel);
}
default void setUser(Object channel, User user) {
USERS.put(channel, user);
PacketEvents.getAPI().getInjector().updateUser(channel, user);
}
default Object getChannel(String username) {
return CHANNELS.get(username);
}
}
@@ -1,31 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty;
import com.github.retrooper.packetevents.netty.buffer.ByteBufAllocationOperator;
import com.github.retrooper.packetevents.netty.buffer.ByteBufOperator;
import com.github.retrooper.packetevents.netty.channel.ChannelOperator;
public interface NettyManager {
ChannelOperator getChannelOperator();
ByteBufOperator getByteBufOperator();
ByteBufAllocationOperator getByteBufAllocationOperator();
}
@@ -1,257 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import com.github.retrooper.packetevents.PacketEvents;
import java.nio.charset.Charset;
public class ByteBufHelper {
public static int readerIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer);
}
public static Object readerIndex(Object buffer, int readerIndex) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer, readerIndex);
}
public static int writerIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writerIndex(buffer);
}
public static Object writerIndex(Object buffer, int writerIndex) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writerIndex(buffer, writerIndex);
}
public static int readableBytes(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readableBytes(buffer);
}
public static int writableBytes(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writableBytes(buffer);
}
public static Object clear(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().clear(buffer);
}
public static String toString(Object buffer, int index, int length, Charset charset) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().toString(buffer, index, length, charset);
}
public static byte readByte(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readByte(buffer);
}
public static void writeByte(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeByte(buffer, value);
}
public static boolean readBoolean(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBoolean(buffer);
}
public static void writeBoolean(Object buffer, boolean value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBoolean(buffer, value);
}
public static short readUnsignedByte(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedByte(buffer);
}
public static char readChar(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readChar(buffer);
}
public static void writeChar(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeChar(buffer, value);
}
public static short readShort(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readShort(buffer);
}
public static int readUnsignedShort(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedShort(buffer);
}
public static void writeShort(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeShort(buffer, value);
}
public static int readInt(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readInt(buffer);
}
public static void writeInt(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeInt(buffer, value);
}
public static long readUnsignedInt(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedInt(buffer);
}
public static long readLong(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readLong(buffer);
}
public static void writeLong(Object buffer, long value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeLong(buffer, value);
}
public static float readFloat(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readFloat(buffer);
}
public static void writeFloat(Object buffer, float value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeFloat(buffer, value);
}
public static double readDouble(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readDouble(buffer);
}
public static void writeDouble(Object buffer, double value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeDouble(buffer, value);
}
public static Object getBytes(Object buffer, int index, byte[] destination) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().getBytes(buffer, index, destination);
}
public static short getUnsignedByte(Object buffer, int index) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().getUnsignedByte(buffer, index);
}
public static boolean isReadable(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().isReadable(buffer);
}
public static Object copy(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().copy(buffer);
}
public static Object duplicate(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().duplicate(buffer);
}
public static boolean hasArray(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().hasArray(buffer);
}
public static byte[] array(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().array(buffer);
}
public static Object retain(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().retain(buffer);
}
public static Object retainedDuplicate(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().retainedDuplicate(buffer);
}
public static Object readSlice(Object buffer, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readSlice(buffer, length);
}
public static Object readBytes(Object buffer, byte[] destination, int destinationIndex, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, destination, destinationIndex, length);
}
public static Object readBytes(Object buffer, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, length);
}
public static Object writeBytes(Object buffer, Object src) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, src);
}
public static void readBytes(Object buffer, byte[] bytes) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, bytes);
}
public static void writeBytes(Object buffer, byte[] bytes) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, bytes);
}
public static void writeBytes(Object buffer, byte[] bytes, int offset, int length) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, bytes, offset, length);
}
public static boolean release(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().release(buffer);
}
public static int refCnt(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().refCnt(buffer);
}
public static Object skipBytes(Object buffer, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().skipBytes(buffer, length);
}
public static Object markReaderIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().markReaderIndex(buffer);
}
public static Object resetReaderIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetReaderIndex(buffer);
}
public static Object markWriterIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().markWriterIndex(buffer);
}
public static Object resetWriterIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetWriterIndex(buffer);
}
public static int readVarInt(Object buffer) {
int value = 0;
int length = 0;
byte currentByte;
do {
currentByte = readByte(buffer);
value |= (currentByte & 0x7F) << (length * 7);
length++;
if (length > 5) {
throw new RuntimeException("VarInt is too large. Must be smaller than 5 bytes.");
}
} while ((currentByte & 0x80) == 0x80);
return value;
}
public static void writeVarInt(Object buffer, int value) {
while (true) {
if ((value & ~0x7F) == 0) {
writeByte(buffer, value);
return;
}
writeByte(buffer, (value & 0x7F) | 0x80);
value >>>= 7;
}
}
public static byte[] copyBytes(Object buffer) {
byte[] bytes = new byte[readableBytes(buffer)];
getBytes(buffer, readerIndex(buffer), bytes);
return bytes;
}
}
@@ -1,232 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import java.io.*;
//TODO give netty credit
public class ByteBufInputStream extends InputStream implements DataInput {
private final Object buffer;
private final int startIndex;
private final int endIndex;
private final boolean releaseOnClose;
private final StringBuilder lineBuf;
private boolean closed;
public ByteBufInputStream(Object buffer) {
this(buffer, ByteBufHelper.readableBytes(buffer));
}
public ByteBufInputStream(Object buffer, int length) {
this(buffer, length, false);
}
public ByteBufInputStream(Object buffer, boolean releaseOnClose) {
this(buffer, ByteBufHelper.readableBytes(buffer), releaseOnClose);
}
public ByteBufInputStream(Object buffer, int length, boolean releaseOnClose) {
this.lineBuf = new StringBuilder();
if (buffer == null) {
throw new NullPointerException("buffer");
} else if (length < 0) {
if (releaseOnClose) {
ByteBufHelper.release(buffer);
}
throw new IllegalArgumentException("length: " + length);
} else if (length > ByteBufHelper.readableBytes(buffer)) {
if (releaseOnClose) {
ByteBufHelper.release(buffer);
}
throw new IndexOutOfBoundsException("Too many bytes to be read - Needs " + length + ", maximum is " + ByteBufHelper.readableBytes(buffer));
} else {
this.releaseOnClose = releaseOnClose;
this.buffer = buffer;
this.startIndex = ByteBufHelper.readerIndex(buffer);
this.endIndex = this.startIndex + length;
ByteBufHelper.markReaderIndex(buffer);
}
}
public int readBytes() {
return ByteBufHelper.readerIndex(buffer) - this.startIndex;
}
public void close() throws IOException {
try {
super.close();
} finally {
if (this.releaseOnClose && !this.closed) {
this.closed = true;
ByteBufHelper.release(buffer);
}
}
}
public int available() throws IOException {
return this.endIndex - ByteBufHelper.readerIndex(buffer);
}
public void mark(int readlimit) {
ByteBufHelper.markReaderIndex(buffer);
}
public boolean markSupported() {
return true;
}
public int read() throws IOException {
return !(ByteBufHelper.isReadable(buffer)) ? -1 : ByteBufHelper.readByte(buffer) & 255;
}
public int read(byte[] b, int off, int len) throws IOException {
int available = this.available();
if (available == 0) {
return -1;
} else {
len = Math.min(available, len);
ByteBufHelper.readBytes(buffer, b, off, len);
return len;
}
}
public void reset() throws IOException {
ByteBufHelper.resetReaderIndex(buffer);
}
public long skip(long n) throws IOException {
return n > 2147483647L ? (long) this.skipBytes(2147483647) : (long) this.skipBytes((int) n);
}
public boolean readBoolean() throws IOException {
this.checkAvailable(1);
return this.read() != 0;
}
public byte[] readBytes(int len) {
byte[] bytes = new byte[len];
ByteBufHelper.readBytes(buffer, bytes);
return bytes;
}
public byte readByte() throws IOException {
if (!(ByteBufHelper.isReadable(buffer))) {
throw new EOFException();
} else {
return ByteBufHelper.readByte(buffer);
}
}
public char readChar() throws IOException {
return (char) this.readShort();
}
public double readDouble() throws IOException {
return Double.longBitsToDouble(this.readLong());
}
public float readFloat() throws IOException {
return Float.intBitsToFloat(this.readInt());
}
public void readFully(byte[] b) throws IOException {
this.readFully(b, 0, b.length);
}
public void readFully(byte[] b, int off, int len) throws IOException {
this.checkAvailable(len);
ByteBufHelper.readBytes(buffer, b, off, len);
}
public int readInt() throws IOException {
this.checkAvailable(4);
return ByteBufHelper.readInt(buffer);
}
public String readLine() throws IOException {
this.lineBuf.setLength(0);
while (ByteBufHelper.isReadable(buffer)) {
int c = ByteBufHelper.readUnsignedByte(buffer);
switch (c) {
case 13:
if (ByteBufHelper.isReadable(buffer)
&& (char) ByteBufHelper.getUnsignedByte(buffer, ByteBufHelper.readerIndex(buffer)) == '\n') {
ByteBufHelper.skipBytes(buffer, 1);
}
case 10:
return this.lineBuf.toString();
default:
this.lineBuf.append((char) c);
}
}
return this.lineBuf.length() > 0 ? this.lineBuf.toString() : null;
}
public long readLong() throws IOException {
this.checkAvailable(8);
return ByteBufHelper.readLong(buffer);
}
public long[] readLongs(int size) throws IOException {
long[] array = new long[size];
for (int i = 0; i < array.length; i++) {
array[i] = readLong();
}
return array;
}
public short readShort() throws IOException {
this.checkAvailable(2);
return ByteBufHelper.readShort(buffer);
}
public String readUTF() throws IOException {
return DataInputStream.readUTF(this);
}
public int readUnsignedByte() throws IOException {
return this.readByte() & 255;
}
public int readUnsignedShort() throws IOException {
return this.readShort() & '\uffff';
}
public int skipBytes(int n) throws IOException {
int nBytes = Math.min(this.available(), n);
ByteBufHelper.skipBytes(buffer, nBytes);
return nBytes;
}
private void checkAvailable(int fieldSize) throws IOException {
if (fieldSize < 0) {
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
} else if (fieldSize > this.available()) {
throw new EOFException("fieldSize is too long! Length is " + fieldSize + ", but maximum is " + this.available());
}
}
}
@@ -1,114 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import java.nio.charset.Charset;
public interface ByteBufOperator {
int readerIndex(Object buffer);
Object readerIndex(Object buffer, int readerIndex);
int writerIndex(Object buffer);
Object writerIndex(Object buffer, int writerIndex);
int readableBytes(Object buffer);
int writableBytes(Object buffer);
Object clear(Object buffer);
byte readByte(Object buffer);
short readShort(Object buffer);
int readInt(Object buffer);
long readUnsignedInt(Object buffer);
long readLong(Object buffer);
void writeByte(Object buffer, int value);
void writeShort(Object buffer, int value);
void writeInt(Object buffer, int value);
void writeLong(Object buffer, long value);
Object getBytes(Object buffer, int index, byte[] destination);
short getUnsignedByte(Object buffer, int index);
boolean isReadable(Object buffer);
Object copy(Object buffer);
Object duplicate(Object buffer);
boolean hasArray(Object buffer);
byte[] array(Object buffer);
Object retain(Object buffer);
Object retainedDuplicate(Object buffer);
Object readSlice(Object buffer, int length);
Object readBytes(Object buffer, byte[] destination, int destinationIndex, int length);
Object readBytes(Object buffer, int length);
void readBytes(Object buffer, byte[] bytes);
Object writeBytes(Object buffer, Object src);
Object writeBytes(Object buffer, byte[] bytes);
Object writeBytes(Object buffer, byte[] bytes, int offset, int length);
boolean release(Object buffer);
int refCnt(Object buffer);
Object skipBytes(Object buffer, int length);
String toString(Object buffer, int index, int length, Charset charset);
Object markReaderIndex(Object buffer);
Object resetReaderIndex(Object buffer);
Object markWriterIndex(Object buffer);
Object resetWriterIndex(Object buffer);
default float readFloat(Object buffer) {
return Float.intBitsToFloat(readInt(buffer));
}
default void writeFloat(Object buffer, float value) {
writeInt(buffer, Float.floatToIntBits(value));
}
default double readDouble(Object buffer) {
return Double.longBitsToDouble(readLong(buffer));
}
default void writeDouble(Object buffer, double value) {
writeLong(buffer, Double.doubleToLongBits(value));
}
default char readChar(Object buffer) {
return (char) readShort(buffer);
}
default void writeChar(Object buffer, int value) {
writeShort(buffer, value);
}
//Use writeShort to write
default int readUnsignedShort(Object buffer) {
return readShort(buffer) & '\uffff';
}
//Use writeByte to write
default short readUnsignedByte(Object buffer) {
return (short) (this.readByte(buffer) & 255);
}
default boolean readBoolean(Object buffer) {
return readByte(buffer) != 0;
}
default void writeBoolean(Object buffer, boolean value) {
writeByte(buffer, value ? 1 : 0);
}
}
@@ -1,114 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//TODO Give netty credit
package com.github.retrooper.packetevents.netty.buffer;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class ByteBufOutputStream extends OutputStream implements DataOutput {
private final Object buffer;
private final int startIndex;
private final DataOutputStream utf8out = new DataOutputStream(this);
public ByteBufOutputStream(Object buffer) {
if (buffer == null) {
throw new NullPointerException("buffer");
} else {
this.buffer = buffer;
this.startIndex = ByteBufHelper.writerIndex(buffer);
}
}
public int writtenBytes() {
return ByteBufHelper.writerIndex(buffer) - this.startIndex;
}
public void write(byte[] b, int off, int len) throws IOException {
if (len != 0) {
ByteBufHelper.writeBytes(buffer, b, off, len);
}
}
public void write(byte[] b) throws IOException {
ByteBufHelper.writeBytes(buffer, b);
}
public void write(int b) throws IOException {
ByteBufHelper.writeByte(buffer, b);
}
public void writeBoolean(boolean v) throws IOException {
ByteBufHelper.writeBoolean(buffer, v);
}
public void writeByte(int v) throws IOException {
ByteBufHelper.writeByte(buffer, v);
}
@Deprecated
public void writeBytes(String s) throws IOException {
throw new IllegalStateException("This operation is not supported!");
}
public void writeChar(int v) throws IOException {
ByteBufHelper.writeChar(buffer, v);
}
public void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0; i < len; ++i) {
ByteBufHelper.writeChar(buffer, s.charAt(i));
}
}
public void writeDouble(double v) throws IOException {
ByteBufHelper.writeDouble(buffer, v);
}
public void writeFloat(float v) throws IOException {
ByteBufHelper.writeFloat(buffer, v);
}
public void writeInt(int v) throws IOException {
ByteBufHelper.writeInt(buffer, v);
}
public void writeLong(long v) throws IOException {
ByteBufHelper.writeLong(buffer, v);
}
public void writeShort(int v) throws IOException {
ByteBufHelper.writeShort(buffer, v);
}
public void writeUTF(String s) throws IOException {
this.utf8out.writeUTF(s);
}
public Object buffer() {
return this.buffer;
}
}
@@ -1,43 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import com.github.retrooper.packetevents.PacketEvents;
public class UnpooledByteBufAllocationHelper {
public static Object wrappedBuffer(byte[] bytes) {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().wrappedBuffer(bytes);
}
public static Object copiedBuffer(byte[] bytes) {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().copiedBuffer(bytes);
}
public static Object buffer() {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().buffer();
}
public static Object directBuffer() {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().directBuffer();
}
public static Object compositeBuffer() {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().compositeBuffer();
}
}
@@ -1,95 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.channel;
import com.github.retrooper.packetevents.PacketEvents;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.List;
public class ChannelHelper {
public static SocketAddress remoteAddress(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().remoteAddress(channel);
}
public static SocketAddress localAddress(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().localAddress(channel);
}
public static boolean isOpen(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().isOpen(channel);
}
public static Object close(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().close(channel);
}
public static Object write(Object channel, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().write(channel, buffer);
}
public static Object flush(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().flush(channel);
}
public static Object writeAndFlush(Object channel, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeAndFlush(channel, buffer);
}
public static Object fireChannelRead(Object channel, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().fireChannelRead(channel, buffer);
}
public static Object writeInContext(Object channel, String ctx, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeInContext(channel, ctx, buffer);
}
public static Object flushInContext(Object channel, String ctx) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().flushInContext(channel, ctx);
}
public static Object writeAndFlushInContext(Object channel, String ctx, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeAndFlushInContext(channel, ctx, buffer);
}
public static Object fireChannelReadInContext(Object channel, String ctx, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().fireChannelReadInContext(channel, ctx, buffer);
}
public static List<String> pipelineHandlerNames(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().pipelineHandlerNames(channel);
}
public static String pipelineHandlerNamesAsString(Object channel) {
return Arrays.toString(pipelineHandlerNames(channel).toArray(new String[0]));
}
public static Object getPipelineHandler(Object channel, String name) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineHandler(channel, name);
}
public static Object getPipelineContext(Object channel, String handlerName) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineContext(channel, handlerName);
}
public static void runInEventLoop(Object channel, Runnable runnable) {
PacketEvents.getAPI().getNettyManager().getChannelOperator().runInEventLoop(channel, runnable);
}
}
@@ -1,45 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.channel;
import java.net.SocketAddress;
import java.util.List;
import java.util.Set;
public interface ChannelOperator {
Set<Class<? extends Throwable>> getIgnoredHandlerExceptions();
SocketAddress remoteAddress(Object channel);
SocketAddress localAddress(Object channel);
boolean isOpen(Object channel);
Object close(Object channel);
Object write(Object channel, Object buffer);
Object flush(Object channel);
Object writeAndFlush(Object channel, Object buffer);
Object fireChannelRead(Object channel, Object buffer);
Object writeInContext(Object channel, String ctx, Object buffer);
Object flushInContext(Object channel, String ctx);
Object writeAndFlushInContext(Object channel, String ctx, Object buffer);
Object fireChannelReadInContext(Object channel, String ctx, Object buffer);
List<String> pipelineHandlerNames(Object channel);
Object getPipelineHandler(Object channel, String name);
Object getPipelineContext(Object channel, String name);
void runInEventLoop(Object channel, Runnable runnable);
}
@@ -1,24 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol;
//TODO
public enum ProtocolVersion {
UNKNOWN
}
@@ -1,55 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data;
public class EntityData {
private int index;
private EntityDataType<?> type;
private Object value;
public EntityData(int index, EntityDataType<?> type, Object value) {
this.index = index;
this.type = type;
this.value = value;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public EntityDataType<?> getType() {
return type;
}
public void setType(EntityDataType<?> type) {
this.type = type;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
@@ -1,56 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class EntityDataType<T> {
private final String name;
private final int[] ids;
private final Function<PacketWrapper<?>, T> dataDeserializer;
private final BiConsumer<PacketWrapper<?>, Object> dataSerializer;
public EntityDataType(String name, int[] ids, Function<PacketWrapper<?>, T> dataDeserializer, BiConsumer<PacketWrapper<?>, Object> dataSerializer) {
this.name = name;
this.ids = ids;
this.dataDeserializer = dataDeserializer;
this.dataSerializer = dataSerializer;
}
public String getName() {
return name;
}
public int getId(ClientVersion version) {
int index = EntityDataTypes.TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
public Function<PacketWrapper<?>, T> getDataDeserializer() {
return dataDeserializer;
}
public BiConsumer<PacketWrapper<?>, Object> getDataSerializer() {
return dataSerializer;
}
}
@@ -1,276 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.util.*;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.google.gson.JsonObject;
import net.kyori.adventure.text.Component;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class EntityDataTypes {
//1.7 -> 1.18 block_position is just 3 ints, not serialized with a long
//short was removed in 1.9+
//boolean was added in 1.9
//nbt was added in 1.12
private static final Map<String, EntityDataType<?>> ENTITY_DATA_TYPE_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, EntityDataType<?>>> ENTITY_DATA_TYPE_ID_MAP = new HashMap<>();
protected static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_data_type_mappings",
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_11,
ClientVersion.V_1_13, //Fix? Why did we not acknoledge 1.13
ClientVersion.V_1_16);
public static final EntityDataType<Byte> BYTE = define("byte", PacketWrapper::readByte, PacketWrapper::writeByte);
public static final EntityDataType<Integer> INT = define("int", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Float> FLOAT = define("float", PacketWrapper::readFloat, PacketWrapper::writeFloat);
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
public static final EntityDataType<Component> COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
public static final EntityDataType<Optional<Component>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
public static final EntityDataType<ItemStack> ITEMSTACK = define("itemstack", PacketWrapper::readItemStack, PacketWrapper::writeItemStack);
public static final EntityDataType<Optional<Object>> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Boolean> BOOLEAN = define("boolean", PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
public static final EntityDataType<Integer> PARTICLE = define("particle", PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final EntityDataType<Vector3f> ROTATION = define("rotation",
(PacketWrapper<?> wrapper) -> new Vector3f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
(PacketWrapper<?> wrapper, Vector3f value) -> {
wrapper.writeFloat(value.x);
wrapper.writeFloat(value.y);
wrapper.writeFloat(value.z);
});
public static final EntityDataType<Vector3i> BLOCK_POSITION = define("block_position", readBlockPositionDeserializer(), writeBlockPositionSerializer());
public static final EntityDataType<Optional<Vector3i>> OPTIONAL_BLOCK_POSITION = define("optional_block_position", readOptionalBlockPositionDeserializer(), writeOptionalBlockPositionSerializer());
public static final EntityDataType<BlockFace> BLOCK_FACE = define("block_face", (PacketWrapper<?> wrapper) -> {
int id = wrapper.readVarInt();
return BlockFace.getBlockFaceByValue(id);
},
(PacketWrapper<?> wrapper, BlockFace value) -> wrapper.writeVarInt(value.getFaceValue()));
public static final EntityDataType<Optional<UUID>> OPTIONAL_UUID = define("optional_uuid", (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return Optional.of(wrapper.readUUID());
} else {
return Optional.empty();
}
},
(PacketWrapper<?> wrapper, Optional<UUID> value) -> {
if (value.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeUUID(value.get());
} else {
wrapper.writeBoolean(false);
}
});
public static final EntityDataType<NBTCompound> NBT = define("nbt", PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final EntityDataType<VillagerData> VILLAGER_DATA = define("villager_data", PacketWrapper::readVillagerData, PacketWrapper::writeVillagerData);
public static final EntityDataType<Optional<Integer>> OPTIONAL_INT = define("optional_int", (PacketWrapper<?> wrapper) -> {
int i = wrapper.readVarInt();
return i == 0 ? Optional.empty() : Optional.of(i - 1);
}, (PacketWrapper<?> wrapper, Optional<Integer> value) -> {
wrapper.writeVarInt(value.orElse(-1) + 1);
});
public static final EntityDataType<EntityPose> ENTITY_POSE = define("entity_pose", (PacketWrapper<?> wrapper) -> {
int id = wrapper.readVarInt();
return EntityPose.getById(wrapper.getServerVersion().toClientVersion(), id);
}, (PacketWrapper<?> wrapper, EntityPose value) -> wrapper.writeVarInt(value.getId(wrapper.getServerVersion().toClientVersion())));
@Deprecated
public static final EntityDataType<Short> SHORT = define("short", PacketWrapper::readShort, PacketWrapper::writeShort);
public static EntityDataType<?> getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte)index);
return typeIdMap.get(id);
}
public static EntityDataType<?> getByName(String name) {
return ENTITY_DATA_TYPE_MAP.get(name);
}
public static <T> EntityDataType<T> define(String name, Function<PacketWrapper<?>, T> deserializer, BiConsumer<PacketWrapper<?>, T> serializer) {
TypesBuilderData data = TYPES_BUILDER.define(name);
EntityDataType<T> type = new EntityDataType<>(name, data.getData(), deserializer,
(BiConsumer<PacketWrapper<?>, Object>) serializer);
ENTITY_DATA_TYPE_MAP.put(type.getName(), type);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
if (index == -1) continue;
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP
.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(type.getId(version), type);
}
return type;
}
private static <T> Function<PacketWrapper<?>, T> readIntDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> (T) ((Object) wrapper.readVarInt());
} else {
return (PacketWrapper<?> wrapper) -> (T) ((Object) wrapper.readInt());
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeIntSerializer() {
return (PacketWrapper<?> wrapper, T value) -> {
int output = 0;
if (value instanceof Byte) {
output = ((Byte) value).intValue();
} else if (value instanceof Short) {
output = ((Short) value).intValue();
} else if (value instanceof Integer) {
output = (Integer) value;
} else if (value instanceof Long) {
output = ((Long) value).intValue();
}
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
wrapper.writeVarInt(output);
} else {
wrapper.writeInt(output);
}
};
}
private static <T> Function<PacketWrapper<?>, T> readOptionalComponentDeserializer() {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return (T) Optional.of(wrapper.readComponent());
} else {
return (T) Optional.empty();
}
};
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeOptionalComponentSerializer() {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<Component> optional = (Optional<Component>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeComponent(optional.get());
} else {
wrapper.writeBoolean(false);
}
} else {
wrapper.writeBoolean(false);
}
};
}
private static <T> Function<PacketWrapper<?>, T> readBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> (T) wrapper.readBlockPosition();
} else {
return (PacketWrapper<?> wrapper) -> {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return (T) new Vector3i(x, y, z);
};
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeBlockPositionSerializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper, T value) -> {
wrapper.writeBlockPosition((Vector3i) value);
};
} else {
return (PacketWrapper<?> wrapper, T value) -> {
Vector3i position = (Vector3i) value;
wrapper.writeInt(position.getX());
wrapper.writeInt(position.getY());
wrapper.writeInt(position.getZ());
};
}
}
private static <T> Function<PacketWrapper<?>, T> readOptionalBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return (T) Optional.of(wrapper.readBlockPosition());
} else {
return (T) Optional.empty();
}
};
} else {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return (T) Optional.of(new Vector3i(x, y, z));
} else {
return (T) Optional.empty();
}
};
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeOptionalBlockPositionSerializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<?> optional = (Optional<?>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeBlockPosition((Vector3i) optional.get());
} else {
wrapper.writeBoolean(false);
}
} else {
wrapper.writeBoolean(false);
}
};
} else {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<?> optional = (Optional<?>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
Vector3i position = (Vector3i) optional.get();
wrapper.writeInt(position.getX());
wrapper.writeInt(position.getY());
wrapper.writeInt(position.getZ());
} else {
wrapper.writeBoolean(false);
}
} else {
wrapper.writeBoolean(false);
}
};
}
}
}
@@ -1,28 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import java.util.List;
public interface DataProvider {
List<EntityData> encode();
void decode(List<EntityData> data);
}
@@ -1,343 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class EntityDataProvider implements DataProvider {
@Nullable
private Component customName;
private boolean customNameVisible;
private EntityPose pose = EntityPose.STANDING;
private int airTicks;
private int ticksFrozenInPowderedSnow = 0;
private boolean onFire;
private boolean crouching;
//Now unused
private boolean riding;
private boolean sprinting;
private boolean swimming;
private boolean invisible;
private boolean glowing;
private boolean flyingWithElytra;
private boolean silent;
private boolean hasGravity = true;
@Nullable
public Component getCustomName() {
return customName;
}
public void setCustomName(@Nullable Component customName) {
this.customName = customName;
}
public boolean isCustomNameVisible() {
return customNameVisible;
}
public void setCustomNameVisible(boolean customNameVisible) {
this.customNameVisible = customNameVisible;
}
public EntityPose getPose() {
return pose;
}
public void setPose(EntityPose pose) {
this.pose = pose;
}
public int getAirTicks() {
return airTicks;
}
public void setAirTicks(int airTicks) {
this.airTicks = airTicks;
}
public int getTicksFrozenInPowderedSnow() {
return ticksFrozenInPowderedSnow;
}
public void setTicksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
this.ticksFrozenInPowderedSnow = ticksFrozenInPowderedSnow;
}
public boolean isOnFire() {
return onFire;
}
public void setOnFire(boolean onFire) {
this.onFire = onFire;
}
public boolean isCrouching() {
return crouching;
}
public void setCrouching(boolean crouching) {
this.crouching = crouching;
}
public boolean isRiding() {
return riding;
}
public void setRiding(boolean riding) {
this.riding = riding;
}
public boolean isSprinting() {
return sprinting;
}
public void setSprinting(boolean sprinting) {
this.sprinting = sprinting;
}
public boolean isSwimming() {
return swimming;
}
public void setSwimming(boolean swimming) {
this.swimming = swimming;
}
public boolean isInvisible() {
return invisible;
}
public void setInvisible(boolean invisible) {
this.invisible = invisible;
}
public boolean isGlowing() {
return glowing;
}
public void setGlowing(boolean glowing) {
this.glowing = glowing;
}
public boolean isFlyingWithElytra() {
return flyingWithElytra;
}
public void setFlyingWithElytra(boolean flyingWithElytra) {
this.flyingWithElytra = flyingWithElytra;
}
public boolean isSilent() {
return silent;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isHasGravity() {
return hasGravity;
}
public void setHasGravity(boolean hasGravity) {
this.hasGravity = hasGravity;
}
@Override
public List<EntityData> encode() {
byte mask = 0x00;
if (onFire) {
mask |= 0x01;
}
if (crouching) {
mask |= 0x02;
}
//TODO Rethink, should we add this?
if (riding) {
mask |= 0x04;
}
if (sprinting) {
mask |= 0x08;
}
if (swimming) {
mask |= 0x10;
}
if (invisible) {
mask |= 0x20;
}
if (glowing) {
mask |= 0x40;
}
if (flyingWithElytra) {
mask |= 0x80;
}
List<EntityData> metadata = new ArrayList<>(8);
metadata.add(new EntityData(0, EntityDataTypes.BYTE, mask));
metadata.add(new EntityData(1, EntityDataTypes.INT, airTicks));
metadata.add(new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.ofNullable(customName)));
metadata.add(new EntityData(3, EntityDataTypes.BOOLEAN, customNameVisible));
metadata.add(new EntityData(4, EntityDataTypes.BOOLEAN, silent));
metadata.add(new EntityData(5, EntityDataTypes.BOOLEAN, !hasGravity));
metadata.add(new EntityData(6, EntityDataTypes.ENTITY_POSE, pose));
metadata.add(new EntityData(7, EntityDataTypes.INT, ticksFrozenInPowderedSnow));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 0:
byte mask = (byte) entityData.getValue();
onFire = (mask & 0x01) != 0;
crouching = (mask & 0x02) != 0;
riding = (mask & 0x04) != 0;
sprinting = (mask & 0x08) != 0;
swimming = (mask & 0x10) != 0;
invisible = (mask & 0x20) != 0;
glowing = (mask & 0x40) != 0;
flyingWithElytra = (mask & 0x80) != 0;
break;
case 1:
airTicks = (int) entityData.getValue();
break;
case 2:
customName = ((Optional<Component>) entityData.getValue()).orElse(null);
break;
case 3:
customNameVisible = (boolean) entityData.getValue();
break;
case 4:
silent = (boolean) entityData.getValue();
break;
case 5:
hasGravity = !(boolean) entityData.getValue();
break;
case 6:
pose = (EntityPose) entityData.getValue();
break;
case 7:
ticksFrozenInPowderedSnow = (int) entityData.getValue();
break;
}
}
}
public static EntityBuilder<EntityBuilder> builderEntity() {
return new EntityBuilder<>(new EntityDataProvider());
}
public static class EntityBuilder<T extends EntityBuilder> {
protected EntityDataProvider provider;
public EntityBuilder(EntityDataProvider provider) {
this.provider = provider;
}
public T customName(@Nullable Component customName) {
((EntityDataProvider) provider).setCustomName(customName);
return (T) this;
}
public T customNameVisible(boolean customNameVisible) {
((EntityDataProvider) provider).setCustomNameVisible(customNameVisible);
return (T) this;
}
public T pose(EntityPose pose) {
((EntityDataProvider) provider).setPose(pose);
return (T) this;
}
public T onFire(boolean onFire) {
((EntityDataProvider) provider).setOnFire(onFire);
return (T) this;
}
public T crouching(boolean crouching) {
((EntityDataProvider) provider).setCrouching(crouching);
return (T) this;
}
public T riding(boolean riding) {
((EntityDataProvider) provider).setRiding(riding);
return (T) this;
}
public T sprinting(boolean sprinting) {
((EntityDataProvider) provider).setSprinting(sprinting);
return (T) this;
}
public T swimming(boolean swimming) {
((EntityDataProvider) provider).setSwimming(swimming);
return (T) this;
}
public T invisible(boolean invisible) {
((EntityDataProvider) provider).setInvisible(invisible);
return (T) this;
}
public T glowing(boolean glowing) {
((EntityDataProvider) provider).setGlowing(glowing);
return (T) this;
}
public T flyingWithElytra(boolean flyingWithElytra) {
((EntityDataProvider) provider).setFlyingWithElytra(flyingWithElytra);
return (T) this;
}
public T silent(boolean silent) {
((EntityDataProvider) provider).setSilent(silent);
return (T) this;
}
public T hasGravity(boolean hasGravity) {
((EntityDataProvider) provider).setHasGravity(hasGravity);
return (T) this;
}
public T airTicks(int airTicks) {
((EntityDataProvider) provider).setAirTicks(airTicks);
return (T) this;
}
public T ticksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
((EntityDataProvider) provider).setTicksFrozenInPowderedSnow(ticksFrozenInPowderedSnow);
return (T) this;
}
public <K extends EntityDataProvider> K build() {
return (K) provider;
}
}
}
@@ -1,232 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.util.Vector3i;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class LivingEntityDataProvider extends EntityDataProvider {
private boolean handActive;
private InteractionHand hand = InteractionHand.MAIN_HAND;
private boolean isInRiptideSpinAttack;
private float health = 1.0f;
private int potionEffectColor;
private boolean potionEffectAmbient;
private int arrowInBodyCount;
private int beeStingsInBodyCount;
@Nullable
private Vector3i sleepingPosition;
public boolean isHandActive() {
return handActive;
}
public void setHandActive(boolean handActive) {
this.handActive = handActive;
}
public InteractionHand getHand() {
return hand;
}
public void setHand(InteractionHand hand) {
this.hand = hand;
}
public boolean isInRiptideSpinAttack() {
return isInRiptideSpinAttack;
}
public void setInRiptideSpinAttack(boolean inRiptideSpinAttack) {
isInRiptideSpinAttack = inRiptideSpinAttack;
}
public float getHealth() {
return health;
}
public void setHealth(float health) {
this.health = health;
}
public int getPotionEffectColor() {
return potionEffectColor;
}
public void setPotionEffectColor(int potionEffectColor) {
this.potionEffectColor = potionEffectColor;
}
public boolean isPotionEffectAmbient() {
return potionEffectAmbient;
}
public void setPotionEffectAmbient(boolean potionEffectAmbient) {
this.potionEffectAmbient = potionEffectAmbient;
}
public int getArrowInBodyCount() {
return arrowInBodyCount;
}
public void setArrowInBodyCount(int arrowInBodyCount) {
this.arrowInBodyCount = arrowInBodyCount;
}
public int getBeeStingsInBodyCount() {
return beeStingsInBodyCount;
}
public void setBeeStingsInBodyCount(int beeStingsInBodyCount) {
this.beeStingsInBodyCount = beeStingsInBodyCount;
}
@Nullable
public Vector3i getSleepingPosition() {
return sleepingPosition;
}
public void setSleepingPosition(@Nullable Vector3i sleepingPosition) {
this.sleepingPosition = sleepingPosition;
}
public static LivingEntityBuilder<LivingEntityBuilder> builderLivingEntity() {
return new LivingEntityBuilder<>(new LivingEntityDataProvider());
}
@Override
public List<EntityData> encode() {
List<EntityData> metadata = super.encode();
byte mask = 0x00;
if (handActive) {
mask |= 0x01;
}
//TODO Confirm
if (hand == InteractionHand.OFF_HAND) {
mask |= 0x02;
}
if (isInRiptideSpinAttack) {
mask |= 0x04;
}
metadata.add(new EntityData(8, EntityDataTypes.BYTE, mask));
metadata.add(new EntityData(9, EntityDataTypes.FLOAT, health));
metadata.add(new EntityData(10, EntityDataTypes.INT, potionEffectColor));
metadata.add(new EntityData(11, EntityDataTypes.BOOLEAN, potionEffectAmbient));
metadata.add(new EntityData(12, EntityDataTypes.INT, arrowInBodyCount));
metadata.add(new EntityData(13, EntityDataTypes.INT, beeStingsInBodyCount));
metadata.add(new EntityData(14, EntityDataTypes.OPTIONAL_BLOCK_POSITION, Optional.ofNullable(sleepingPosition)));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
super.decode(data);
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 8:
byte mask = (byte) entityData.getValue();
handActive = (mask & 0x01) != 0;
//TODO Test, look into
hand = (mask & 0x02) != 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
isInRiptideSpinAttack = (mask & 0x04) != 0;
break;
case 9:
health = (float) entityData.getValue();
break;
case 10:
potionEffectColor = (int) entityData.getValue();
break;
case 11:
potionEffectAmbient = (boolean) entityData.getValue();
break;
case 12:
arrowInBodyCount = (int) entityData.getValue();
break;
case 13:
beeStingsInBodyCount = (int) entityData.getValue();
break;
case 14:
sleepingPosition = ((Optional<Vector3i>) entityData.getValue()).orElse(null);
break;
}
}
}
public static class LivingEntityBuilder<T extends LivingEntityBuilder> extends EntityDataProvider.EntityBuilder<T> {
public LivingEntityBuilder(LivingEntityDataProvider livingEntityDataProvider) {
super(livingEntityDataProvider);
}
public T handActive(boolean handActive) {
((LivingEntityDataProvider) provider).setHandActive(handActive);
return (T) this;
}
public T hand(InteractionHand hand) {
((LivingEntityDataProvider) provider).setHand(hand);
return (T) this;
}
public T isInRiptideSpinAttack(boolean isInRiptideSpinAttack) {
((LivingEntityDataProvider) provider).setInRiptideSpinAttack(isInRiptideSpinAttack);
return (T) this;
}
public T health(float health) {
((LivingEntityDataProvider) provider).setHealth(health);
return (T) this;
}
public T potionEffectColor(int potionEffectColor) {
((LivingEntityDataProvider) provider).setPotionEffectColor(potionEffectColor);
return (T) this;
}
public T potionEffectAmbient(boolean potionEffectAmbient) {
((LivingEntityDataProvider) provider).setPotionEffectAmbient(potionEffectAmbient);
return (T) this;
}
public T arrowInBodyCount(int arrowInBodyCount) {
((LivingEntityDataProvider) provider).setArrowInBodyCount(arrowInBodyCount);
return (T) this;
}
public T beeStingsInBodyCount(int beeStingsInBodyCount) {
((LivingEntityDataProvider) provider).setBeeStingsInBodyCount(beeStingsInBodyCount);
return (T) this;
}
public T sleepingPosition(@Nullable Vector3i sleepingPosition) {
((LivingEntityDataProvider) provider).setSleepingPosition(sleepingPosition);
return (T) this;
}
}
}
@@ -1,169 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.HumanoidArm;
import com.github.retrooper.packetevents.protocol.player.SkinSection;
import java.util.List;
import java.util.Set;
public class PlayerDataProvider extends LivingEntityDataProvider {
private float additionalHealth;
private int score;
private byte skinPartsMask = SkinSection.getMaskBySections(SkinSection.getAllSections());
private HumanoidArm mainArm = HumanoidArm.RIGHT;
private NBTCompound leftShoulderNBT = new NBTCompound();
private NBTCompound rightShoulderNBT = new NBTCompound();
public float getAdditionalHealth() {
return additionalHealth;
}
public void setAdditionalHealth(float additionalHealth) {
this.additionalHealth = additionalHealth;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public byte getSkinPartsMask() {
return skinPartsMask;
}
public void setSkinPartsMask(byte skinPartsMask) {
this.skinPartsMask = skinPartsMask;
}
public HumanoidArm getMainArm() {
return mainArm;
}
public void setMainArm(HumanoidArm mainArm) {
this.mainArm = mainArm;
}
public NBTCompound getLeftShoulderNBT() {
return leftShoulderNBT;
}
public void setLeftShoulderNBT(NBTCompound leftShoulderNBT) {
this.leftShoulderNBT = leftShoulderNBT;
}
public NBTCompound getRightShoulderNBT() {
return rightShoulderNBT;
}
public void setRightShoulderNBT(NBTCompound rightShoulderNBT) {
this.rightShoulderNBT = rightShoulderNBT;
}
public static PlayerBuilder<PlayerBuilder> builderPlayer() {
return new PlayerBuilder<>(new PlayerDataProvider());
}
@Override
public List<EntityData> encode() {
List<EntityData> metadata = super.encode();
metadata.add(new EntityData(15, EntityDataTypes.FLOAT, additionalHealth));
metadata.add(new EntityData(16, EntityDataTypes.INT, score));
metadata.add(new EntityData(17, EntityDataTypes.BYTE, skinPartsMask));
metadata.add(new EntityData(18, EntityDataTypes.BYTE, (byte) mainArm.ordinal()));
metadata.add(new EntityData(19, EntityDataTypes.NBT, leftShoulderNBT));
metadata.add(new EntityData(20, EntityDataTypes.NBT, rightShoulderNBT));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
super.decode(data);
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 15:
additionalHealth = (float) entityData.getValue();
break;
case 16:
score = (int) entityData.getValue();
break;
case 17:
skinPartsMask = (byte) entityData.getValue();
break;
case 18:
mainArm = HumanoidArm.values()[(byte) entityData.getValue()];
break;
case 19:
leftShoulderNBT = (NBTCompound) entityData.getValue();
break;
case 20:
rightShoulderNBT = (NBTCompound) entityData.getValue();
break;
}
}
}
public static class PlayerBuilder<T extends PlayerBuilder> extends LivingEntityDataProvider.LivingEntityBuilder<T> {
public PlayerBuilder(PlayerDataProvider entityDataProvider) {
super(entityDataProvider);
}
public T additionalHealth(float additionalHealth) {
((PlayerDataProvider)provider).setAdditionalHealth(additionalHealth);
return (T) this;
}
public T score(int score) {
((PlayerDataProvider)provider).setScore(score);
return (T) this;
}
public T skinPartsMask(byte skinPartsMask) {
((PlayerDataProvider)provider).setSkinPartsMask(skinPartsMask);
return (T)this;
}
public T skinParts(Set<SkinSection> skinSections) {
((PlayerDataProvider)provider).setSkinPartsMask(SkinSection.getMaskBySections(skinSections));
return (T)this;
}
public T mainArm(HumanoidArm mainArm) {
((PlayerDataProvider)provider).setMainArm(mainArm);
return (T)this;
}
public T leftShoulderNBT(NBTCompound leftShoulderNBT) {
((PlayerDataProvider)provider).setLeftShoulderNBT(leftShoulderNBT);
return (T)this;
}
public T rightShoulderNBT(NBTCompound rightShoulderNBT) {
((PlayerDataProvider)provider).setRightShoulderNBT(rightShoulderNBT);
return (T)this;
}
}
}
@@ -1,47 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.pose;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
public enum EntityPose {
STANDING,
FALL_FLYING,
SLEEPING,
SWIMMING,
SPIN_ATTACK,
CROUCHING,
LONG_JUMPING,
DYING;
public int getId(ClientVersion version) {
if (this == DYING && version.isOlderThan(ClientVersion.V_1_17)) {
return 6;
}
return ordinal();
}
public static EntityPose getById(ClientVersion version, int id) {
// The LONG_JUMPING pose was added in 1.17, shifting things by 1
if (id == 6 && version.isOlderThan(ClientVersion.V_1_17)) {
return DYING;
}
return values()[id];
}
}
@@ -1,28 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.type;
import com.github.retrooper.packetevents.protocol.mapper.LegacyMappedEntity;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import java.util.Optional;
public interface EntityType extends MappedEntity, LegacyMappedEntity {
Optional<EntityType> getParent();
}
@@ -1,289 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.type;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.TypesBuilder;
import com.github.retrooper.packetevents.util.TypesBuilderData;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class EntityTypes {
private static final Map<String, EntityType> ENTITY_TYPE_MAP = new HashMap<>();
//Key - mappings version, value - map with entity type ids and entity types
private static final Map<Byte, Map<Integer, EntityType>> ENTITY_TYPE_ID_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, EntityType>> LEGACY_ENTITY_TYPE_ID_MAP = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_type_mappings",
ClientVersion.V_1_10,
ClientVersion.V_1_11,
ClientVersion.V_1_12,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_15,
ClientVersion.V_1_16,
ClientVersion.V_1_16_2,
ClientVersion.V_1_17);
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings",
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_10,
ClientVersion.V_1_11,
ClientVersion.V_1_12,
ClientVersion.V_1_13);
public static EntityType define(String key, @Nullable EntityType parent) {
TypesBuilderData data = TYPES_BUILDER.define(key);
TypesBuilderData legacyData = LEGACY_TYPES_BUILDER.define(key);
Optional<EntityType> optParent = Optional.ofNullable(parent);
EntityType entityType = new EntityType() {
private final int[] ids = data.getData();
private final int[] legacyIds = legacyData.getData();
@Override
public Optional<EntityType> getParent() {
return optParent;
}
@Override
public int getLegacyId(ClientVersion version) {
if (version.isNewerThanOrEquals(ClientVersion.V_1_14)) {
return -1;
}
int index = LEGACY_TYPES_BUILDER.getDataIndex(version);
return legacyIds[index];
}
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
int index = TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
};
ENTITY_TYPE_MAP.put(entityType.getName().toString(), entityType);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityType> typeIdMap = ENTITY_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(entityType.getId(version), entityType);
}
for (ClientVersion version : LEGACY_TYPES_BUILDER.getVersions()) {
int index = LEGACY_TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityType> legacyTypeIdMap = LEGACY_ENTITY_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
legacyTypeIdMap.put(entityType.getLegacyId(version), entityType);
}
return entityType;
}
public static boolean isTypeInstanceOf(EntityType type, EntityType parent) {
while (type != null) {
if (type == parent) {
return true;
}
if (type.getParent().isPresent()) {
type = type.getParent().get();
} else {
return false;
}
}
return false;
}
//with minecraft:key
public static EntityType getByName(String name) {
return ENTITY_TYPE_MAP.get(name);
}
public static EntityType getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
return ENTITY_TYPE_ID_MAP.get((byte) index).get(id);
}
public static EntityType getByLegacyId(ClientVersion version, int id) {
if (version.isNewerThanOrEquals(ClientVersion.V_1_14)) {
return null;
}
int index = LEGACY_TYPES_BUILDER.getDataIndex(version);
return LEGACY_ENTITY_TYPE_ID_MAP.get((byte) index).get(id);
}
// Credit to ViaVersion for these categories
public static final EntityType ENTITY = define("entity", null);
public static final EntityType LIVINGENTITY = define("livingentity", ENTITY);
public static final EntityType ABSTRACT_INSENTIENT = define("abstract_insentient", LIVINGENTITY);
public static final EntityType ABSTRACT_CREATURE = define("abstract_creature", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_AGEABLE = define("abstract_ageable", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_ANIMAL = define("abstract_animal", ABSTRACT_AGEABLE);
public static final EntityType ABSTRACT_TAMEABLE_ANIMAL = define("abstract_tameable_animal", ABSTRACT_ANIMAL);
public static final EntityType ABSTRACT_PARROT = define("abstract_parrot", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType ABSTRACT_HORSE = define("abstract_horse", ABSTRACT_ANIMAL);
public static final EntityType CHESTED_HORSE = define("chested_horse", ABSTRACT_HORSE);
public static final EntityType ABSTRACT_GOLEM = define("abstract_golem", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_FISHES = define("abstract_fishes", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_MONSTER = define("abstract_monster", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_PIGLIN = define("abstract_piglin", ABSTRACT_MONSTER);
public static final EntityType ABSTRACT_ILLAGER_BASE = define("abstract_illager_base", ABSTRACT_MONSTER);
public static final EntityType ABSTRACT_EVO_ILLU_ILLAGER = define("abstract_evo_illu_illager", ABSTRACT_ILLAGER_BASE);
public static final EntityType ABSTRACT_SKELETON = define("abstract_skeleton", ABSTRACT_MONSTER);
public static final EntityType ABSTRACT_FLYING = define("abstract_flying", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_AMBIENT = define("abstract_ambient", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_WATERMOB = define("abstract_watermob", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_HANGING = define("abstract_hanging", ENTITY);
public static final EntityType ABSTRACT_LIGHTNING = define("abstract_lightning", ENTITY);
public static final EntityType ABSTRACT_ARROW = define("abstract_arrow", ENTITY);
public static final EntityType ABSTRACT_FIREBALL = define("abstract_fireball", ENTITY);
public static final EntityType PROJECTILE_ABSTRACT = define("projectile_abstract", ENTITY);
public static final EntityType MINECART_ABSTRACT = define("minecart_abstract", ENTITY);
public static final EntityType CHESTED_MINECART_ABSTRACT = define("chested_minecart_abstract", MINECART_ABSTRACT);
public static final EntityType AREA_EFFECT_CLOUD = define("area_effect_cloud", ENTITY);
public static final EntityType ARMOR_STAND = define("armor_stand", LIVINGENTITY);
public static final EntityType ARROW = define("arrow", ABSTRACT_ARROW);
public static final EntityType AXOLOTL = define("axolotl", ABSTRACT_ANIMAL);
public static final EntityType BAT = define("bat", ABSTRACT_AMBIENT);
public static final EntityType BEE = define("bee", ABSTRACT_INSENTIENT);
public static final EntityType BLAZE = define("blaze", ABSTRACT_MONSTER);
public static final EntityType BOAT = define("boat", ENTITY);
public static final EntityType CAT = define("cat", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType SPIDER = define("spider", ABSTRACT_MONSTER);
public static final EntityType CAVE_SPIDER = define("cave_spider", SPIDER);
public static final EntityType CHICKEN = define("chicken", ABSTRACT_ANIMAL);
public static final EntityType COD = define("cod", ABSTRACT_FISHES);
public static final EntityType COW = define("cow", ABSTRACT_ANIMAL);
public static final EntityType CREEPER = define("creeper", ABSTRACT_MONSTER);
public static final EntityType DOLPHIN = define("dolphin", ABSTRACT_INSENTIENT);
public static final EntityType DONKEY = define("donkey", CHESTED_HORSE);
public static final EntityType DRAGON_FIREBALL = define("dragon_fireball", ABSTRACT_FIREBALL);
public static final EntityType ZOMBIE = define("zombie", ABSTRACT_MONSTER);
public static final EntityType DROWNED = define("drowned", ZOMBIE);
public static final EntityType GUARDIAN = define("guardian", ABSTRACT_MONSTER);
public static final EntityType ELDER_GUARDIAN = define("elder_guardian", GUARDIAN);
public static final EntityType END_CRYSTAL = define("end_crystal", ENTITY);
public static final EntityType ENDER_DRAGON = define("ender_dragon", ABSTRACT_INSENTIENT);
public static final EntityType ENDERMAN = define("enderman", ABSTRACT_MONSTER);
public static final EntityType ENDERMITE = define("endermite", ABSTRACT_MONSTER);
public static final EntityType EVOKER = define("evoker", ABSTRACT_EVO_ILLU_ILLAGER);
public static final EntityType EVOKER_FANGS = define("evoker_fangs", ENTITY);
public static final EntityType EXPERIENCE_ORB = define("experience_orb", ENTITY);
public static final EntityType EYE_OF_ENDER = define("eye_of_ender", ENTITY);
public static final EntityType FALLING_BLOCK = define("falling_block", ENTITY);
public static final EntityType FIREWORK_ROCKET = define("firework_rocket", ENTITY);
public static final EntityType FOX = define("fox", ABSTRACT_ANIMAL);
public static final EntityType GHAST = define("ghast", ABSTRACT_FLYING);
public static final EntityType GIANT = define("giant", ABSTRACT_MONSTER);
public static final EntityType ITEM_FRAME = define("item_frame", ABSTRACT_HANGING);
public static final EntityType GLOW_ITEM_FRAME = define("glow_item_frame", ITEM_FRAME);
public static final EntityType SQUID = define("squid", ABSTRACT_WATERMOB);
public static final EntityType GLOW_SQUID = define("glow_squid", SQUID);
public static final EntityType GOAT = define("goat", ABSTRACT_ANIMAL);
public static final EntityType HOGLIN = define("hoglin", ABSTRACT_ANIMAL);
public static final EntityType HORSE = define("horse", ABSTRACT_HORSE);
public static final EntityType HUSK = define("husk", ZOMBIE);
public static final EntityType ILLUSIONER = define("illusioner", ABSTRACT_EVO_ILLU_ILLAGER);
public static final EntityType IRON_GOLEM = define("iron_golem", ABSTRACT_GOLEM);
public static final EntityType ITEM = define("item", ENTITY);
public static final EntityType FIREBALL = define("fireball", ABSTRACT_FIREBALL);
public static final EntityType LEASH_KNOT = define("leash_knot", ABSTRACT_HANGING);
public static final EntityType LIGHTNING_BOLT = define("lightning_bolt", ABSTRACT_LIGHTNING);
public static final EntityType LLAMA = define("llama", CHESTED_HORSE);
public static final EntityType LLAMA_SPIT = define("llama_spit", ENTITY);
public static final EntityType SLIME = define("slime", ABSTRACT_INSENTIENT);
public static final EntityType MAGMA_CUBE = define("magma_cube", SLIME);
public static final EntityType MARKER = define("marker", ENTITY);
public static final EntityType MINECART = define("minecart", MINECART_ABSTRACT);
public static final EntityType CHEST_MINECART = define("chest_minecart", CHESTED_MINECART_ABSTRACT);
public static final EntityType COMMAND_BLOCK_MINECART = define("command_block_minecart", MINECART_ABSTRACT);
public static final EntityType FURNACE_MINECART = define("furnace_minecart", MINECART_ABSTRACT);
public static final EntityType HOPPER_MINECART = define("hopper_minecart", CHESTED_MINECART_ABSTRACT);
public static final EntityType SPAWNER_MINECART = define("spawner_minecart", MINECART_ABSTRACT);
public static final EntityType TNT_MINECART = define("tnt_minecart", MINECART_ABSTRACT);
public static final EntityType MULE = define("mule", CHESTED_HORSE);
public static final EntityType MOOSHROOM = define("mooshroom", COW);
public static final EntityType OCELOT = define("ocelot", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType PAINTING = define("painting", ABSTRACT_HANGING);
public static final EntityType PANDA = define("panda", ABSTRACT_INSENTIENT);
public static final EntityType PARROT = define("parrot", ABSTRACT_PARROT);
public static final EntityType PHANTOM = define("phantom", ABSTRACT_FLYING);
public static final EntityType PIG = define("pig", ABSTRACT_ANIMAL);
public static final EntityType PIGLIN = define("piglin", ABSTRACT_PIGLIN);
public static final EntityType PIGLIN_BRUTE = define("piglin_brute", ABSTRACT_PIGLIN);
public static final EntityType PILLAGER = define("pillager", ABSTRACT_ILLAGER_BASE);
public static final EntityType POLAR_BEAR = define("polar_bear", ABSTRACT_ANIMAL);
public static final EntityType TNT = define("tnt", ENTITY);
public static final EntityType PUFFERFISH = define("pufferfish", ABSTRACT_FISHES);
public static final EntityType RABBIT = define("rabbit", ABSTRACT_ANIMAL);
public static final EntityType RAVAGER = define("ravager", ABSTRACT_MONSTER);
public static final EntityType SALMON = define("salmon", ABSTRACT_FISHES);
public static final EntityType SHEEP = define("sheep", ABSTRACT_ANIMAL);
public static final EntityType SHULKER = define("shulker", ABSTRACT_GOLEM); // yes this is correct
public static final EntityType SHULKER_BULLET = define("shulker_bullet", ENTITY);
public static final EntityType SILVERFISH = define("silverfish", ABSTRACT_MONSTER);
public static final EntityType SKELETON = define("skeleton", ABSTRACT_SKELETON);
public static final EntityType SKELETON_HORSE = define("skeleton_horse", ABSTRACT_HORSE);
public static final EntityType SMALL_FIREBALL = define("small_fireball", ABSTRACT_FIREBALL);
public static final EntityType SNOW_GOLEM = define("snow_golem", ABSTRACT_GOLEM);
public static final EntityType SNOWBALL = define("snowball", PROJECTILE_ABSTRACT);
public static final EntityType SPECTRAL_ARROW = define("spectral_arrow", ABSTRACT_ARROW);
public static final EntityType STRAY = define("stray", ABSTRACT_SKELETON);
public static final EntityType STRIDER = define("strider", ABSTRACT_ANIMAL);
public static final EntityType EGG = define("egg", PROJECTILE_ABSTRACT);
public static final EntityType ENDER_PEARL = define("ender_pearl", PROJECTILE_ABSTRACT);
public static final EntityType EXPERIENCE_BOTTLE = define("experience_bottle", PROJECTILE_ABSTRACT);
public static final EntityType POTION = define("potion", PROJECTILE_ABSTRACT);
@Deprecated // Exists only in 1.9 and 1.10
public static final EntityType TIPPED_ARROW = define("tipped_arrow", ARROW);
public static final EntityType TRIDENT = define("trident", ABSTRACT_ARROW);
public static final EntityType TRADER_LLAMA = define("trader_llama", CHESTED_HORSE);
public static final EntityType TROPICAL_FISH = define("tropical_fish", ABSTRACT_FISHES);
public static final EntityType TURTLE = define("turtle", ABSTRACT_ANIMAL);
public static final EntityType VEX = define("vex", ABSTRACT_MONSTER);
public static final EntityType VILLAGER = define("villager", ABSTRACT_AGEABLE);
public static final EntityType VINDICATOR = define("vindicator", ABSTRACT_ILLAGER_BASE);
public static final EntityType WANDERING_TRADER = define("wandering_trader", ABSTRACT_AGEABLE);
public static final EntityType WITCH = define("witch", ABSTRACT_MONSTER);
public static final EntityType WITHER = define("wither", ABSTRACT_MONSTER);
public static final EntityType WITHER_SKELETON = define("wither_skeleton", ABSTRACT_SKELETON);
public static final EntityType WITHER_SKULL = define("wither_skull", ABSTRACT_FIREBALL);
public static final EntityType WOLF = define("wolf", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType ZOGLIN = define("zoglin", ABSTRACT_MONSTER);
public static final EntityType ZOMBIE_HORSE = define("zombie_horse", ABSTRACT_HORSE);
public static final EntityType ZOMBIE_VILLAGER = define("zombie_villager", ZOMBIE);
public static final EntityType ZOMBIFIED_PIGLIN = define("zombified_piglin", ZOMBIE);
public static final EntityType PLAYER = define("player", LIVINGENTITY);
public static final EntityType FISHING_BOBBER = define("fishing_bobber", ENTITY);
public static final EntityType ENDER_SIGNAL = define("ender_signal", ENTITY);
public static final EntityType THROWN_EXP_BOTTLE = define("thrown_exp_bottle", PROJECTILE_ABSTRACT);
public static final EntityType PRIMED_TNT = define("primed_tnt", ENTITY);
public static final EntityType FIREWORK = define("firework", ENTITY);
public static final EntityType MINECART_COMMAND = define("minecart_command", MINECART_ABSTRACT);
public static final EntityType MINECART_RIDEABLE = define("minecart_rideable", MINECART_ABSTRACT);
public static final EntityType MINECART_CHEST = define("minecart_chest", MINECART_ABSTRACT);
public static final EntityType MINECART_FURNACE = define("minecart_furnace", MINECART_ABSTRACT);
public static final EntityType MINECART_TNT = define("minecart_tnt", MINECART_ABSTRACT);
public static final EntityType MINECART_HOPPER = define("minecart_hopper", MINECART_ABSTRACT);
public static final EntityType MINECART_MOB_SPAWNER = define("minecart_mob_spawner", MINECART_ABSTRACT);
}
@@ -1,64 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager;
import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfession;
import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfessions;
import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerType;
import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerTypes;
public class VillagerData {
private VillagerType type;
private VillagerProfession profession;
private int level;
public VillagerData(VillagerType type, VillagerProfession profession, int level) {
this.type = type;
this.profession = profession;
this.level = level;
}
public VillagerData(int typeId, int professionId, int level) {
this(VillagerTypes.getById(typeId), VillagerProfessions.getById(professionId), level);
}
public VillagerType getType() {
return type;
}
public void setType(VillagerType type) {
this.type = type;
}
public VillagerProfession getProfession() {
return profession;
}
public void setProfession(VillagerProfession profession) {
this.profession = profession;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}
@@ -1,73 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.profession;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.TypesBuilder;
import java.util.HashMap;
import java.util.Map;
public class VillagerProfessions {
private static final Map<String, VillagerProfession> VILLAGER_PROFESSION_MAP = new HashMap<>();
private static final Map<Byte, VillagerProfession> VILLAGER_PROFESSION_ID_MAP = new HashMap<>();
public static VillagerProfession define(int id, String name) {
ResourceLocation location = new ResourceLocation(name);
VillagerProfession type = new VillagerProfession() {
@Override
public ResourceLocation getName() {
return location;
}
@Override
public int getId() {
return id;
}
};
VILLAGER_PROFESSION_MAP.put(type.getName().toString(), type);
VILLAGER_PROFESSION_ID_MAP.put((byte) type.getId(), type);
return type;
}
public static VillagerProfession getById(int id) {
return VILLAGER_PROFESSION_ID_MAP.get((byte)id);
}
public static VillagerProfession getByName(String name) {
return VILLAGER_PROFESSION_MAP.get(name);
}
public static final VillagerProfession NONE = define(0, "minecraft:none");
public static final VillagerProfession ARMORER = define(1, "minecraft:armorer");
public static final VillagerProfession BUTCHER = define(2, "minecraft:butcher");
public static final VillagerProfession CARTOGRAPHER = define(3, "minecraft:cartographer");
public static final VillagerProfession CLERIC = define(4, "minecraft:cleric");
public static final VillagerProfession FARMER = define(5, "minecraft:farmer");
public static final VillagerProfession FISHERMAN = define(6, "minecraft:fisherman");
public static final VillagerProfession FLETCHER = define(7, "minecraft:fletcher");
public static final VillagerProfession LEATHERWORKER = define(8, "minecraft:leatherworker");
public static final VillagerProfession LIBRARIAN = define(9, "minecraft:librarian");
public static final VillagerProfession MASON = define(10, "minecraft:mason");
public static final VillagerProfession NITWIT = define(11, "minecraft:nitwit");
public static final VillagerProfession SHEPHERD = define(12, "minecraft:shepherd");
public static final VillagerProfession TOOLSMITH = define(13, "minecraft:toolsmith");
public static final VillagerProfession WEAPONSMITH = define(14, "minecraft:weaponsmith");
}
@@ -1,25 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.type;
import com.github.retrooper.packetevents.protocol.mapper.StaticMappedEntity;
public interface VillagerType extends StaticMappedEntity {
}
@@ -1,65 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.type;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import java.util.HashMap;
import java.util.Map;
public class VillagerTypes {
private static final Map<String, VillagerType> VILLAGER_TYPE_MAP = new HashMap<>();
private static final Map<Byte, VillagerType> VILLAGER_TYPE_ID_MAP = new HashMap<>();
public static VillagerType define(int id, String name) {
ResourceLocation location = new ResourceLocation(name);
VillagerType type = new VillagerType() {
@Override
public ResourceLocation getName() {
return location;
}
@Override
public int getId() {
return id;
}
};
VILLAGER_TYPE_MAP.put(type.getName().toString(), type);
VILLAGER_TYPE_ID_MAP.put((byte)type.getId(), type);
return type;
}
public static VillagerType getById(int id) {
return VILLAGER_TYPE_ID_MAP.get((byte)id);
}
public static VillagerType getByName(String name) {
return VILLAGER_TYPE_MAP.get(name);
}
public static final VillagerType DESERT = define(0, "minecraft:desert");
public static final VillagerType JUNGLE = define(1, "minecraft:jungle");
public static final VillagerType PLAINS = define(2, "minecraft:plains");
public static final VillagerType SAVANNA = define(3, "minecraft:savanna");
public static final VillagerType SNOW = define(4, "minecraft:snow");
public static final VillagerType SWAMP = define(5, "minecraft:swamp");
public static final VillagerType TAIGA = define(6, "minecraft:taiga");
}
@@ -1,335 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.item;
import com.github.retrooper.packetevents.protocol.item.enchantment.Enchantment;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.nbt.*;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ItemStack {
public static final ItemStack EMPTY = new ItemStack(ItemTypes.AIR, 0, new NBTCompound(), 0);
private final ItemType type;
private int amount;
@Nullable
private NBTCompound nbt;
private int legacyData = -1;
private boolean cachedIsEmpty = false;
private ItemStack(ItemType type, int amount, @Nullable NBTCompound nbt, int legacyData) {
this.type = type;
this.amount = amount;
this.nbt = nbt;
this.legacyData = legacyData;
updateCachedEmptyStatus();
}
public int getMaxStackSize() {
return getType().getMaxAmount();
}
public boolean isStackable() {
return this.getMaxStackSize() > 1 && (!this.isDamageableItem() || !this.isDamaged());
}
public boolean isDamageableItem() {
if (!this.cachedIsEmpty && this.getType().getMaxDurability() > 0) {
NBTCompound tag = this.getNBT();
return tag == null || !tag.getBoolean("Unbreakable");
} else {
return false;
}
}
public boolean isDamaged() {
return this.isDamageableItem() && this.getDamageValue() > 0;
}
public int getDamageValue() {
if (nbt == null) return 0;
NBTInt damage = this.nbt.getTagOfTypeOrNull("Damage", NBTInt.class);
return damage == null ? 0 : damage.getAsInt();
}
public void setDamageValue(int damage) {
this.getOrCreateTag().setTag("Damage", new NBTInt(Math.max(0, damage)));
}
public int getMaxDamage() {
return this.getType().getMaxDurability();
}
public NBTCompound getOrCreateTag() {
if (this.nbt == null) {
this.nbt = new NBTCompound();
}
return this.nbt;
}
private void updateCachedEmptyStatus() {
cachedIsEmpty = isEmpty();
}
public ItemType getType() {
return cachedIsEmpty ? ItemTypes.AIR : type;
}
public int getAmount() {
return cachedIsEmpty ? 0 : amount;
}
public void shrink(int amount) {
this.setAmount(this.getAmount() - amount);
}
public void grow(int amount) {
this.setAmount(this.getAmount() + amount);
}
public void setAmount(int amount) {
this.amount = amount;
updateCachedEmptyStatus();
}
public ItemStack split(int toTake) {
int i = Math.min(toTake, getAmount());
ItemStack itemstack = this.copy();
itemstack.setAmount(i);
this.shrink(i);
return itemstack;
}
public ItemStack copy() {
return cachedIsEmpty ? EMPTY : new ItemStack(type, amount, nbt == null ? new NBTCompound() : nbt.copy(), legacyData);
}
@Nullable
public NBTCompound getNBT() {
return nbt;
}
public void setNBT(NBTCompound nbt) {
this.nbt = nbt;
}
public int getLegacyData() {
return legacyData;
}
public void setLegacyData(int legacyData) {
this.legacyData = legacyData;
}
public boolean isEnchantable() {
if (getType() == ItemTypes.BOOK) return getAmount() == 1;
if (getType() == ItemTypes.ENCHANTED_BOOK) return false;
return getMaxStackSize() == 1 && canBeDepleted() && !isEnchanted();
}
public boolean isEnchanted() {
if (!isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull("Enchantments") != null) {
return !this.nbt.getCompoundListTagOrNull("Enchantments").isEmpty();
} else {
return false;
}
}
private static List<Enchantment> getEnchantments(@Nullable NBTCompound nbt) {
if (nbt == null || nbt.getCompoundListTagOrNull("Enchantments") == null)
return new ArrayList<>(0);
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull("Enchantments");
List<NBTCompound> compounds = nbtList.getTags();
List<Enchantment> enchantments = new ArrayList<>(compounds.size());
for (NBTCompound compound : compounds) {
String id = compound.getStringTagValueOrNull("id");
EnchantmentType type = EnchantmentTypes.getByName(id);
if (type != null) {
NBTShort levelTag = compound.getTagOfTypeOrNull("lvl", NBTShort.class);
int level = levelTag.getAsInt();
Enchantment enchantment = Enchantment.builder().type(type).level(level).build();
enchantments.add(enchantment);
}
}
return enchantments;
}
public List<Enchantment> getEnchantments() {
return getEnchantments(this.nbt);
}
// TODO: Test on outdated versions
public int getEnchantmentLevel(EnchantmentType enchantment) {
if (isEnchanted()) {
// isEnchanted() is true, so we can assume that nbt is not null
assert nbt != null;
for (NBTCompound base : nbt.getCompoundListTagOrNull("Enchantments").getTags()) {
NBTString string = base.getTagOfTypeOrNull("id", NBTString.class);
if (string != null && enchantment == EnchantmentTypes.getByName(string.getValue())) {
return base.getTagOfTypeOrNull("lvl", NBTShort.class).getAsInt();
}
}
}
return 0;
}
public void setEnchantments(List<Enchantment> enchantments) {
nbt = getOrCreateTag(); // Create tag if null
if (enchantments.isEmpty()) {
//Let us clear the enchantments
if (nbt.getTagOrNull("Enchantments") != null) {
nbt.removeTag("Enchantments");
}
}
else {
List<NBTCompound> list = new ArrayList<>();
for (Enchantment enchantment : enchantments) {
NBTCompound compound = new NBTCompound();
compound.setTag("id", new NBTString(enchantment.getType().getName().toString()));
compound.setTag("lvl", new NBTShort((short) enchantment.getLevel()));
list.add(compound);
}
assert nbt != null; // NBT was created in getOrCreateTag()
nbt.setTag("Enchantments", new NBTList<>(NBTType.COMPOUND, list));
}
}
public boolean canBeDepleted() {
return this.getType().getMaxDurability() > 0;
}
public boolean is(ItemType type) {
return this.getType() == type;
}
public static boolean isSameItemSameTags(ItemStack stack, ItemStack otherStack) {
return stack.is(otherStack.getType()) && ItemStack.tagMatches(stack, otherStack);
}
public static boolean tagMatches(ItemStack left, ItemStack right) {
return left.isEmpty() && right.isEmpty() || (!left.isEmpty() && !right.isEmpty() && ((left.nbt != null || right.nbt == null) && (left.nbt == null || left.nbt.equals(right.nbt))));
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj instanceof ItemStack) {
ItemStack itemStack = (ItemStack) obj;
return getType().equals(itemStack.getType())
&& amount == itemStack.amount
&& Objects.equals(nbt, itemStack.nbt)
&& legacyData == itemStack.legacyData;
}
return false;
}
@Override
public String toString() {
if (cachedIsEmpty) {
return "ItemStack[null]";
} else {
String identifier = type == null ? "null" : type.getName().toString();
int maxAmount = getType().getMaxAmount();
return "ItemStack[type=" + identifier + ", amount=" + amount + "/" + maxAmount
+ ", nbt tag names: " + (nbt != null ? nbt.getTagNames() : "[null]") + ", legacyData=" + legacyData + "]";
}
}
public boolean isEmpty() {
return type == null || type == ItemTypes.AIR || amount <= 0;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private ItemType type;
private int amount = 1;
private NBTCompound nbt = null;
private int legacyData = -1;
private List<Enchantment> enchantments = null;
public Builder type(ItemType type) {
this.type = type;
return this;
}
public Builder amount(int amount) {
this.amount = amount;
return this;
}
public Builder nbt(NBTCompound nbt) {
this.nbt = nbt;
List<Enchantment> nbtEnchantments = getEnchantments(nbt);
// This assumes logically, if already set enchants before NBT, then they would still want the enchants
if (!nbtEnchantments.isEmpty()) {
this.enchantments = nbtEnchantments;
}
return this;
}
public Builder legacyData(int legacyData) {
this.legacyData = legacyData;
return this;
}
/**
* Side effect: This will cause NBT to be created if it is null
* This may affect some client sided inventory operations and may cause a desync
*
* @param enchantments The enchantments to set
* @return This builder
*/
public Builder enchantments(List<Enchantment> enchantments) {
this.enchantments = enchantments;
return this;
}
public Builder addEnchantment(Enchantment enchantment) {
if (enchantments == null) {
enchantments = new ArrayList<>();
}
this.enchantments.add(enchantment);
return this;
}
public ItemStack build() {
ItemStack stack = new ItemStack(type, amount, nbt, legacyData);
if (enchantments != null) {
stack.setEnchantments(enchantments);
}
return stack;
}
}
}
@@ -1,71 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.item.enchantment;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
public class Enchantment {
private EnchantmentType type;
private int level;
private Enchantment(EnchantmentType type, int level) {
this.type = type;
this.level = level;
}
public EnchantmentType getType() {
return type;
}
public void setType(EnchantmentType type) {
this.type = type;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private EnchantmentType type;
private int level;
public Builder type(EnchantmentType type) {
this.type = type;
return this;
}
public Builder level(int level) {
this.level = level;
return this;
}
public Enchantment build() {
return new Enchantment(type, level);
}
}
}
@@ -1,123 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.item.enchantment.type;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.TypesBuilder;
import com.github.retrooper.packetevents.util.TypesBuilderData;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class EnchantmentTypes {
private static final Map<String, EnchantmentType> ENCHANTMENT_TYPE_MAPPINGS = new HashMap<>();
private static final Map<Byte, Map<Integer, EnchantmentType>> ENCHANTMENT_TYPE_ID_MAPPINGS = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("enchantment/enchantment_type_mappings",
ClientVersion.V_1_12,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_16);
public static EnchantmentType define(String key) {
TypesBuilderData data = TYPES_BUILDER.define(key);
EnchantmentType enchantmentType = new EnchantmentType() {
private final int[] ids = data.getData();
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
int index = TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EnchantmentType) {
return getName() == ((EnchantmentType) obj).getName();
}
return false;
}
};
ENCHANTMENT_TYPE_MAPPINGS.put(enchantmentType.getName().toString(), enchantmentType);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EnchantmentType> typeIdMap = ENCHANTMENT_TYPE_ID_MAPPINGS.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(enchantmentType.getId(version), enchantmentType);
}
return enchantmentType;
}
@Nullable
public static EnchantmentType getByName(String name) {
return ENCHANTMENT_TYPE_MAPPINGS.get(name);
}
@Nullable
public static EnchantmentType getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EnchantmentType> typeIdMap = ENCHANTMENT_TYPE_ID_MAPPINGS.get((byte) index);
return typeIdMap.get(id);
}
public static final EnchantmentType ALL_DAMAGE_PROTECTION = define("protection");
public static final EnchantmentType FIRE_PROTECTION = define("fire_protection");
public static final EnchantmentType FALL_PROTECTION = define("feather_falling");
public static final EnchantmentType BLAST_PROTECTION = define("blast_protection");
public static final EnchantmentType PROJECTILE_PROTECTION = define("projectile_protection");
public static final EnchantmentType RESPIRATION = define("respiration");
public static final EnchantmentType AQUA_AFFINITY = define("aqua_affinity");
public static final EnchantmentType THORNS = define("thorns");
public static final EnchantmentType DEPTH_STRIDER = define("depth_strider");
public static final EnchantmentType FROST_WALKER = define("frost_walker");
public static final EnchantmentType BINDING_CURSE = define("binding_curse");
public static final EnchantmentType SOUL_SPEED = define("soul_speed");
public static final EnchantmentType SHARPNESS = define("sharpness");
public static final EnchantmentType SMITE = define("smite");
public static final EnchantmentType BANE_OF_ARTHROPODS = define("bane_of_arthropods");
public static final EnchantmentType KNOCKBACK = define("knockback");
public static final EnchantmentType FIRE_ASPECT = define("fire_aspect");
public static final EnchantmentType MOB_LOOTING = define("looting");
public static final EnchantmentType SWEEPING_EDGE = define("sweeping");
public static final EnchantmentType BLOCK_EFFICIENCY = define("efficiency");
public static final EnchantmentType SILK_TOUCH = define("silk_touch");
public static final EnchantmentType UNBREAKING = define("unbreaking");
public static final EnchantmentType BLOCK_FORTUNE = define("fortune");
public static final EnchantmentType POWER_ARROWS = define("power");
public static final EnchantmentType PUNCH_ARROWS = define("punch");
public static final EnchantmentType FLAMING_ARROWS = define("flame");
public static final EnchantmentType INFINITY_ARROWS = define("infinity");
public static final EnchantmentType FISHING_LUCK = define("luck_of_the_sea");
public static final EnchantmentType FISHING_SPEED = define("lure");
public static final EnchantmentType LOYALTY = define("loyalty");
public static final EnchantmentType IMPALING = define("impaling");
public static final EnchantmentType RIPTIDE = define("riptide");
public static final EnchantmentType CHANNELING = define("channeling");
public static final EnchantmentType MULTISHOT = define("multishot");
public static final EnchantmentType QUICK_CHARGE = define("quick_charge");
public static final EnchantmentType PIERCING = define("piercing");
public static final EnchantmentType MENDING = define("mending");
public static final EnchantmentType VANISHING_CURSE = define("vanishing_curse");
}
@@ -1,12 +0,0 @@
package com.github.retrooper.packetevents.protocol.mapper;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
public interface LegacyMappedEntity {
ResourceLocation getName();
int getLegacyId(ClientVersion version);
}
@@ -1,28 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.mapper;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
public interface MappedEntity {
ResourceLocation getName();
int getId(ClientVersion version);
}
@@ -1,37 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public abstract class NBT {
public abstract NBTType<?> getType();
@Override
public abstract boolean equals(Object other);
@Override
public abstract int hashCode();
@Override
public String toString() {
return "nbt";
}
public abstract NBT copy();
}
@@ -1,92 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTByte extends NBTNumber {
protected final byte value;
public NBTByte(byte value) {
this.value = value;
}
public NBTByte(boolean value) {
this((byte) (value ? 1 : 0));
}
@Override
public NBTType<NBTByte> getType() {
return NBTType.BYTE;
}
@Override
public byte getAsByte() {
return value;
}
@Override
public short getAsShort() {
return value;
}
@Override
public int getAsInt() {
return value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public int hashCode() {
return Byte.hashCode(value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTByte other = (NBTByte) obj;
return value == other.value;
}
@Override
public NBTByte copy() {
return this;
}
}
@@ -1,65 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Arrays;
public class NBTByteArray extends NBT {
protected final byte[] array;
public NBTByteArray(byte[] array) {
this.array = array;
}
@Override
public NBTType<NBTByteArray> getType() {
return NBTType.BYTE_ARRAY;
}
public byte[] getValue() {
return array;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTByteArray other = (NBTByteArray) obj;
return Arrays.equals(array, other.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
public NBTByteArray copy() {
byte[] abyte = new byte[this.array.length];
System.arraycopy(this.array, 0, abyte, 0, this.array.length);
return new NBTByteArray(abyte);
}
}
@@ -1,226 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class NBTCompound extends NBT {
protected final Map<String, NBT> tags = new LinkedHashMap<>();
@Override
public NBTType<NBTCompound> getType() {
return NBTType.COMPOUND;
}
public boolean isEmpty() {
return tags.isEmpty();
}
public Set<String> getTagNames() {
return Collections.unmodifiableSet(tags.keySet());
}
public Map<String, NBT> getTags() {
return Collections.unmodifiableMap(tags);
}
public NBT getTagOrThrow(String key) {
NBT tag = getTagOrNull(key);
if (tag == null) {
throw new IllegalStateException(MessageFormat.format("NBT {0} does not exist", key));
}
return tag;
}
public NBT getTagOrNull(String key) {
return tags.get(key);
}
@SuppressWarnings("unchecked")
public <T extends NBT> T getTagOfTypeOrThrow(String key, Class<T> type) {
NBT tag = getTagOrThrow(key);
if (type.isInstance(tag)) {
return (T) tag;
} else {
throw new IllegalStateException(MessageFormat.format("NBT {0} has unexpected type, expected {1}, but got {2}", key, type, tag.getClass()));
}
}
@SuppressWarnings("unchecked")
public <T extends NBT> T getTagOfTypeOrNull(String key, Class<T> type) {
NBT tag = getTagOrNull(key);
if (type.isInstance(tag)) {
return (T) tag;
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends NBT> NBTList<T> getTagListOfTypeOrThrow(String key, Class<T> type) {
NBTList<? extends NBT> list = getTagOfTypeOrThrow(key, NBTList.class);
if (!type.isAssignableFrom(list.getTagsType().getNBTClass())) {
throw new IllegalStateException(MessageFormat.format("NBTList {0} tags type has unexpected type, expected {1}, but got {2}", key, type, list.getTagsType().getNBTClass()));
}
return (NBTList<T>) list;
}
@SuppressWarnings("unchecked")
public <T extends NBT> NBTList<T> getTagListOfTypeOrNull(String key, Class<T> type) {
NBTList<? extends NBT> list = getTagOfTypeOrNull(key, NBTList.class);
if ((list != null) && type.isAssignableFrom(list.getTagsType().getNBTClass())) {
return (NBTList<T>) list;
}
return null;
}
public NBTCompound getCompoundTagOrThrow(String key) {
return getTagOfTypeOrThrow(key, NBTCompound.class);
}
public NBTCompound getCompoundTagOrNull(String key) {
return getTagOfTypeOrNull(key, NBTCompound.class);
}
public NBTNumber getNumberTagOrThrow(String key) {
return getTagOfTypeOrThrow(key, NBTNumber.class);
}
public NBTNumber getNumberTagOrNull(String key) {
return getTagOfTypeOrNull(key, NBTNumber.class);
}
public NBTString getStringTagOrThrow(String key) {
return getTagOfTypeOrThrow(key, NBTString.class);
}
public NBTString getStringTagOrNull(String key) {
return getTagOfTypeOrNull(key, NBTString.class);
}
public NBTList<NBTCompound> getCompoundListTagOrThrow(String key) {
return getTagListOfTypeOrThrow(key, NBTCompound.class);
}
public NBTList<NBTCompound> getCompoundListTagOrNull(String key) {
return getTagListOfTypeOrNull(key, NBTCompound.class);
}
public NBTList<NBTNumber> getNumberTagListTagOrThrow(String key) {
return getTagListOfTypeOrThrow(key, NBTNumber.class);
}
public NBTList<NBTNumber> getNumberListTagOrNull(String key) {
return getTagListOfTypeOrNull(key, NBTNumber.class);
}
public NBTList<NBTString> getStringListTagOrThrow(String key) {
return getTagListOfTypeOrThrow(key, NBTString.class);
}
public NBTList<NBTString> getStringListTagOrNull(String key) {
return getTagListOfTypeOrNull(key, NBTString.class);
}
public String getStringTagValueOrThrow(String key) {
return getStringTagOrThrow(key).getValue();
}
public String getStringTagValueOrNull(String key) {
NBT tag = getTagOrNull(key);
if (tag instanceof NBTString) {
return ((NBTString) tag).getValue();
}
return null;
}
public String getStringTagValueOrDefault(String key, String defaultValue) {
NBT tag = getTagOrNull(key);
if (tag instanceof NBTString) {
return ((NBTString) tag).getValue();
}
return defaultValue;
}
public NBT removeTag(String key) {
return tags.remove(key);
}
@SuppressWarnings("unchecked")
public <T extends NBT> T removeTagAndReturnIfType(String key, Class<T> type) {
NBT tag = removeTag(key);
if (type.isInstance(tag)) {
return (T) tag;
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends NBT> NBTList<T> removeTagAndReturnIfListType(String key, Class<T> type) {
NBTList<?> list = removeTagAndReturnIfType(key, NBTList.class);
if ((list != null) && type.isAssignableFrom(list.getTagsType().getNBTClass())) {
return (NBTList<T>) list;
}
return null;
}
public void setTag(String key, NBT tag) {
if (tag != null) {
tags.put(key, tag);
} else {
tags.remove(key);
}
}
public NBTCompound copy() {
NBTCompound clone = new NBTCompound();
for (Map.Entry<String, NBT> entry : tags.entrySet()) {
clone.setTag(entry.getKey(), entry.getValue().copy());
}
return clone;
}
public boolean getBoolean(String string) {
NBTByte nbtByte = this.getTagOfTypeOrNull(string, NBTByte.class);
// Empty byte tags are considered 0
byte byteValue = nbtByte == null ? 0 : nbtByte.getAsByte();
return byteValue != 0;
}
@Override
public boolean equals(Object other) {
if (other instanceof NBTCompound) {
if (isEmpty() && ((NBTCompound) other).isEmpty()) {
return true;
}
return tags.equals(((NBTCompound) other).tags);
}
return false;
}
@Override
public int hashCode() {
return tags.hashCode();
}
}
@@ -1,88 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTDouble extends NBTNumber {
protected final double value;
public NBTDouble(double value) {
this.value = value;
}
@Override
public NBTType<NBTDouble> getType() {
return NBTType.DOUBLE;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return (int) value;
}
@Override
public long getAsLong() {
return (long) value;
}
@Override
public float getAsFloat() {
return (float) value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public int hashCode() {
return Double.hashCode(value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTDouble other = (NBTDouble) obj;
return Double.doubleToLongBits(value) == Double.doubleToLongBits(other.value);
}
@Override
public NBTDouble copy() {
return this;
}
}
@@ -1,50 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTEnd extends NBT {
public static final NBTEnd INSTANCE = new NBTEnd();
@Override
public NBTType<NBTEnd> getType() {
return NBTType.END;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return getClass() == obj.getClass();
}
@Override
public int hashCode() {
return 0;
}
@Override
public NBTEnd copy() {
return this;
}
}
@@ -1,88 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTFloat extends NBTNumber {
protected final float value;
public NBTFloat(float value) {
this.value = value;
}
@Override
public NBTType<NBTFloat> getType() {
return NBTType.FLOAT;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return (int) value;
}
@Override
public long getAsLong() {
return (long) value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTFloat other = (NBTFloat) obj;
return Float.floatToIntBits(value) == Float.floatToIntBits(other.value);
}
@Override
public int hashCode() {
return Float.hashCode(value);
}
@Override
public NBTFloat copy() {
return this;
}
}
@@ -1,88 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTInt extends NBTNumber {
protected final int value;
public NBTInt(int value) {
this.value = value;
}
@Override
public NBTType<NBTInt> getType() {
return NBTType.INT;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTInt other = (NBTInt) obj;
return value == other.value;
}
@Override
public int hashCode() {
return Integer.hashCode(value);
}
@Override
public NBTInt copy() {
return this;
}
}
@@ -1,66 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Arrays;
public class NBTIntArray extends NBT {
protected final int[] array;
public NBTIntArray(int[] array) {
this.array = array;
}
@Override
public NBTType<NBTIntArray> getType() {
return NBTType.INT_ARRAY;
}
public int[] getValue() {
return array;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTIntArray other = (NBTIntArray) obj;
return Arrays.equals(array, other.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
@Override
public NBTIntArray copy() {
int[] aint = new int[this.array.length];
System.arraycopy(this.array, 0, aint, 0, this.array.length);
return new NBTIntArray(aint);
}
}
@@ -1,125 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class NBTList<T extends NBT> extends NBT {
protected final NBTType<T> type;
protected final List<T> tags = new ArrayList<>();
public NBTList(NBTType<T> type) {
this.type = type;
}
public NBTList(NBTType<T> type, List<T> tags) {
this.type = type;
this.tags.addAll(tags);
}
public static NBTList<NBTCompound> createCompoundList() {
return new NBTList<>(NBTType.COMPOUND);
}
public static NBTList<NBTString> createStringList() {
return new NBTList<>(NBTType.STRING);
}
@Override
@SuppressWarnings("rawtypes")
public NBTType<NBTList> getType() {
return NBTType.LIST;
}
public NBTType<T> getTagsType() {
return type;
}
public boolean isEmpty() {
return tags.isEmpty();
}
public int size() {
return tags.size();
}
public List<T> getTags() {
return Collections.unmodifiableList(tags);
}
public T getTag(int index) {
return tags.get(index);
}
public void setTag(int index, T tag) {
validateAddTag(tag);
tags.set(index, tag);
}
public void addTag(int index, T tag) {
validateAddTag(tag);
tags.add(index, tag);
}
public void addTag(T tag) {
validateAddTag(tag);
tags.add(tag);
}
protected void validateAddTag(T tag) {
if (type != tag.getType()) {
throw new IllegalArgumentException(MessageFormat.format("Invalid tag type. Expected {0}, got {1}.", type.getNBTClass(), tag.getClass()));
}
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTList<T> other = (NBTList<T>) obj;
return Objects.equals(type, other.type) && Objects.equals(tags, other.tags);
}
@Override
public int hashCode() {
return Objects.hash(type, tags);
}
@Override
public NBTList<T> copy() {
List<T> newTags = new ArrayList<>();
for (T tag : this.tags) {
newTags.add((T) tag.copy());
}
return new NBTList<>(type, newTags);
}
}
@@ -1,88 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTLong extends NBTNumber {
protected final long value;
public NBTLong(long value) {
this.value = value;
}
@Override
public NBTType<NBTLong> getType() {
return NBTType.LONG;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return (int) value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTLong other = (NBTLong) obj;
return value == other.value;
}
@Override
public int hashCode() {
return Long.hashCode(value);
}
@Override
public NBTLong copy() {
return this;
}
}
@@ -1,66 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Arrays;
public class NBTLongArray extends NBT {
protected final long[] array;
public NBTLongArray(long[] array) {
this.array = array;
}
@Override
public NBTType<NBTLongArray> getType() {
return NBTType.LONG_ARRAY;
}
public long[] getValue() {
return array;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTLongArray other = (NBTLongArray) obj;
return Arrays.equals(array, other.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
@Override
public NBTLongArray copy() {
long[] along = new long[this.array.length];
System.arraycopy(this.array, 0, along, 0, this.array.length);
return new NBTLongArray(along);
}
}
@@ -1,35 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public abstract class NBTNumber extends NBT {
public abstract byte getAsByte();
public abstract short getAsShort();
public abstract int getAsInt();
public abstract long getAsLong();
public abstract float getAsFloat();
public abstract double getAsDouble();
}
@@ -1,87 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTShort extends NBTNumber {
protected final short value;
public NBTShort(short value) {
this.value = value;
}
@Override
public NBTType<NBTShort> getType() {
return NBTType.SHORT;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return value;
}
@Override
public int getAsInt() {
return value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTShort other = (NBTShort) obj;
return value == other.value;
}
@Override
public int hashCode() {
return Short.hashCode(value);
}
@Override
public NBTShort copy() {
return this;
}
}
@@ -1,64 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Objects;
public class NBTString extends NBT {
protected final String string;
public NBTString(String string) {
this.string = string;
}
@Override
public NBTType<NBTString> getType() {
return NBTType.STRING;
}
public String getValue() {
return string;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTString other = (NBTString) obj;
return Objects.equals(string, other.string);
}
@Override
public int hashCode() {
return Objects.hash(string);
}
@Override
public NBTString copy() {
return this;
}
}
@@ -1,76 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Objects;
public class NBTType<T extends NBT> {
public static final NBTType<NBTEnd> END = new NBTType<>(NBTEnd.class);
public static final NBTType<NBTByte> BYTE = new NBTType<>(NBTByte.class);
public static final NBTType<NBTShort> SHORT = new NBTType<>(NBTShort.class);
public static final NBTType<NBTInt> INT = new NBTType<>(NBTInt.class);
public static final NBTType<NBTLong> LONG = new NBTType<>(NBTLong.class);
public static final NBTType<NBTFloat> FLOAT = new NBTType<>(NBTFloat.class);
public static final NBTType<NBTDouble> DOUBLE = new NBTType<>(NBTDouble.class);
public static final NBTType<NBTByteArray> BYTE_ARRAY = new NBTType<>(NBTByteArray.class);
public static final NBTType<NBTString> STRING = new NBTType<>(NBTString.class);
@SuppressWarnings("rawtypes")
public static final NBTType<NBTList> LIST = new NBTType<>(NBTList.class);
public static final NBTType<NBTCompound> COMPOUND = new NBTType<>(NBTCompound.class);
public static final NBTType<NBTIntArray> INT_ARRAY = new NBTType<>(NBTIntArray.class);
public static final NBTType<NBTLongArray> LONG_ARRAY = new NBTType<>(NBTLongArray.class);
protected final Class<T> clazz;
protected NBTType(Class<T> clazz) {
this.clazz = clazz;
}
public Class<T> getNBTClass() {
return clazz;
}
@Override
public String toString() {
return clazz.getSimpleName();
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTType<T> other = (NBTType<T>) obj;
return Objects.equals(clazz, other.clazz);
}
@Override
public int hashCode() {
return clazz.hashCode();
}
}
@@ -1,95 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt.codec;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufInputStream;
import com.github.retrooper.packetevents.netty.buffer.ByteBufOutputStream;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTEnd;
import com.github.retrooper.packetevents.protocol.nbt.serializer.DefaultNBTSerializer;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class NBTCodec {
public static NBTCompound readNBT(Object byteBuf, ServerVersion serverVersion) {
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8)) {
try {
return (NBTCompound) DefaultNBTSerializer.INSTANCE.deserializeTag(
new ByteBufInputStream(byteBuf));
} catch (IOException e) {
e.printStackTrace();
}
}
else {
try {
final short length = ByteBufHelper.readShort(byteBuf);
if (length < 0) {
return null;
}
Object slicedBuffer = ByteBufHelper.readSlice(byteBuf, length);
try (DataInputStream stream = new DataInputStream(
new GZIPInputStream(new ByteBufInputStream(slicedBuffer)))) {
return (NBTCompound) DefaultNBTSerializer.INSTANCE.deserializeTag(stream);
}
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
return null;
}
public static void writeNBT(Object byteBuf, ServerVersion serverVersion, NBTCompound tag) {
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8)) {
try (ByteBufOutputStream outputStream = new ByteBufOutputStream(byteBuf)) {
if (tag != null) {
DefaultNBTSerializer.INSTANCE.serializeTag(outputStream, tag);
} else {
DefaultNBTSerializer.INSTANCE.serializeTag(outputStream, NBTEnd.INSTANCE);
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
else {
if (tag == null) {
ByteBufHelper.writeShort(byteBuf, -1);
} else {
int lengthWriterIndex = ByteBufHelper.writerIndex(byteBuf);
ByteBufHelper.writeShort(byteBuf, 0);
int writerIndexDataStart = ByteBufHelper.writerIndex(byteBuf);
try (DataOutputStream outputstream = new DataOutputStream(new GZIPOutputStream(new ByteBufOutputStream(byteBuf)))) {
DefaultNBTSerializer.INSTANCE.serializeTag(outputstream, tag);
} catch (Exception e) {
throw new IllegalStateException(e);
}
int writerIndexDataEnd = ByteBufHelper.writerIndex(byteBuf);
ByteBufHelper.writerIndex(byteBuf, lengthWriterIndex);
ByteBufHelper.writeShort(byteBuf, writerIndexDataEnd - writerIndexDataStart);
ByteBufHelper.writerIndex(byteBuf, writerIndexDataEnd);
}
}
}
}
@@ -1,135 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt.serializer;
import com.github.retrooper.packetevents.protocol.nbt.*;
import java.io.DataInput;
import java.io.DataOutput;
import java.util.List;
import java.util.Map.Entry;
public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
public static final DefaultNBTSerializer INSTANCE = new DefaultNBTSerializer();
@SuppressWarnings("unchecked")
public DefaultNBTSerializer() {
super(DataInput::readByte, DataOutput::writeByte, DataInput::readUTF, DataOutput::writeUTF);
registerType(NBTType.END, 0, stream -> NBTEnd.INSTANCE, (stream, tag) -> {
});
registerType(NBTType.BYTE, 1, stream -> new NBTByte(stream.readByte()), (stream, tag) -> stream.writeByte(tag.getAsByte()));
registerType(NBTType.SHORT, 2, stream -> new NBTShort(stream.readShort()), (stream, tag) -> stream.writeShort(tag.getAsShort()));
registerType(NBTType.INT, 3, stream -> new NBTInt(stream.readInt()), (stream, tag) -> stream.writeInt(tag.getAsInt()));
registerType(NBTType.LONG, 4, stream -> new NBTLong(stream.readLong()), (stream, tag) -> stream.writeLong(tag.getAsLong()));
registerType(NBTType.FLOAT, 5, stream -> new NBTFloat(stream.readFloat()), (stream, tag) -> stream.writeFloat(tag.getAsFloat()));
registerType(NBTType.DOUBLE, 6, stream -> new NBTDouble(stream.readDouble()), (stream, tag) -> stream.writeDouble(tag.getAsDouble()));
registerType(NBTType.STRING, 8, stream -> new NBTString(stream.readUTF()), (stream, tag) -> stream.writeUTF(tag.getValue()));
registerType(
NBTType.BYTE_ARRAY, 7,
stream -> {
byte[] array = new byte[stream.readInt()];
stream.readFully(array);
return new NBTByteArray(array);
},
(stream, tag) -> {
byte[] array = tag.getValue();
stream.writeInt(array.length);
stream.write(array);
}
);
registerType(
NBTType.INT_ARRAY, 11,
stream -> {
int[] array = new int[stream.readInt()];
for (int i = 0; i < array.length; i++) {
array[i] = stream.readInt();
}
return new NBTIntArray(array);
},
(stream, tag) -> {
int[] array = tag.getValue();
stream.writeInt(array.length);
for (int i : array) {
stream.writeInt(i);
}
}
);
registerType(
NBTType.LONG_ARRAY, 12,
stream -> {
long[] array = new long[stream.readInt()];
for (int i = 0; i < array.length; i++) {
array[i] = stream.readLong();
}
return new NBTLongArray(array);
},
(stream, tag) -> {
long[] array = tag.getValue();
stream.writeInt(array.length);
for (long i : array) {
stream.writeLong(i);
}
}
);
registerType(
NBTType.COMPOUND, 10,
stream -> {
NBTCompound compound = new NBTCompound();
NBTType<?> valueType = null;
while ((valueType = readTagType(stream)) != NBTType.END) {
compound.setTag(readTagName(stream), readTag(stream, valueType));
}
return compound;
},
(stream, tag) -> {
for (Entry<String, NBT> entry : tag.getTags().entrySet()) {
NBT value = entry.getValue();
writeTagType(stream, value.getType());
writeTagName(stream, entry.getKey());
writeTag(stream, value);
}
writeTagType(stream, NBTType.END);
}
);
registerType(
NBTType.LIST, 9,
stream -> {
NBTType<? extends NBT> valueType = readTagType(stream);
int size = stream.readInt();
if ((valueType == NBTType.END) && (size > 0)) {
throw new IllegalStateException("Missing nbt list values tag type");
}
NBTList<NBT> list = new NBTList<>((NBTType<NBT>) valueType);
for (int i = 0; i < size; i++) {
list.addTag(readTag(stream, valueType));
}
return list;
},
(stream, tag) -> {
writeTagType(stream, tag.getTagsType());
stream.writeInt(tag.size());
for (NBT value : ((List<NBT>) tag.getTags())) {
writeTag(stream, value);
}
}
);
}
}
@@ -1,157 +0,0 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt.serializer;
import com.github.retrooper.packetevents.protocol.nbt.NBT;
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
public class NBTSerializer<IN, OUT> {
protected final IdReader<IN> idReader;
protected final IdWriter<OUT> idWriter;
protected final NameReader<IN> nameReader;
protected final NameWriter<OUT> nameWriter;
protected final Map<Integer, NBTType<? extends NBT>> idToType = new HashMap<>();
protected final Map<NBTType<? extends NBT>, Integer> typeToId = new HashMap<>();
protected final Map<NBTType<? extends NBT>, TagReader<IN, ? extends NBT>> typeReaders = new HashMap<>();
protected final Map<NBTType<? extends NBT>, TagWriter<OUT, ? extends NBT>> typeWriters = new HashMap<>();
public NBTSerializer(
IdReader<IN> idReader, IdWriter<OUT> idWriter,
NameReader<IN> nameReader, NameWriter<OUT> nameWriter
) {
this.idReader = idReader;
this.idWriter = idWriter;
this.nameReader = nameReader;
this.nameWriter = nameWriter;
}
public NBT deserializeTag(IN from) throws IOException {
NBTType<?> type = readTagType(from);
if (type == NBTType.END) {
return null;
}
readTagName(from);
return readTag(from, type);
}
public void serializeTag(OUT to, NBT tag) throws IOException {
NBTType<?> type = tag.getType();
writeTagType(to, type);
if (tag.getType() == NBTType.END) {
return;
}
writeTagName(to, "");
writeTag(to, tag);
}
protected <T extends NBT> void registerType(
NBTType<T> type, int id,
TagReader<IN, T> typeReader,
TagWriter<OUT, T> typeWriter
) {
if (typeToId.containsKey(type)) {
throw new IllegalArgumentException(MessageFormat.format("Nbt type {0} is already registered", type));
}
if (idToType.containsKey(id)) {
throw new IllegalArgumentException(MessageFormat.format("Nbt type id {0} is already registered", id));
}
idToType.put(id, type);
typeToId.put(type, id);
typeReaders.put(type, typeReader);
typeWriters.put(type, typeWriter);
}
protected NBTType<?> readTagType(IN from) throws IOException {
int id = idReader.readId(from);
NBTType<?> type = idToType.get(id);
if (type == null) {
throw new IOException(MessageFormat.format("Unknown nbt type id {0}", id));
}
return type;
}
protected String readTagName(IN from) throws IOException {
return nameReader.readName(from);
}
protected NBT readTag(IN from, NBTType<?> type) throws IOException {
TagReader<IN, ? extends NBT> f = typeReaders.get(type);
if (f == null) {
throw new IOException(MessageFormat.format("No reader registered for nbt type {0}", type));
}
return f.readTag(from);
}
protected void writeTagType(OUT stream, NBTType<?> type) throws IOException {
int id = typeToId.getOrDefault(type, -1);
if (id == -1) {
throw new IOException(MessageFormat.format("Unknown nbt type {0}", type));
}
idWriter.writeId(stream, id);
}
protected void writeTagName(OUT stream, String name) throws IOException {
nameWriter.writeName(stream, name);
}
@SuppressWarnings("unchecked")
protected void writeTag(OUT stream, NBT tag) throws IOException {
TagWriter<OUT, NBT> f = (TagWriter<OUT, NBT>) typeWriters.get(tag.getType());
if (f == null) {
throw new IOException(MessageFormat.format("No writer registered for nbt type {0}", tag.getType()));
}
f.writeTag(stream, tag);
}
@FunctionalInterface
protected interface IdReader<T> {
int readId(T from) throws IOException;
}
@FunctionalInterface
protected interface IdWriter<T> {
void writeId(T to, int id) throws IOException;
}
@FunctionalInterface
protected interface NameReader<T> {
String readName(T from) throws IOException;
}
@FunctionalInterface
protected interface NameWriter<T> {
void writeName(T to, String name) throws IOException;
}
@FunctionalInterface
protected interface TagReader<IN, T extends NBT> {
T readTag(IN from) throws IOException;
}
@FunctionalInterface
public interface TagWriter<OUT, T extends NBT> {
void writeTag(OUT to, T tag) throws IOException;
}
}
@@ -1,407 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.npc;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.player.*;
import com.github.retrooper.packetevents.protocol.world.Location;
import com.github.retrooper.packetevents.wrapper.play.server.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.jetbrains.annotations.Nullable;
import java.util.*;
public class NPC {
private final int id;
private final UserProfile profile;
private Component tabName;
private NamedTextColor nameColor;
private Component prefixName;
private Component suffixName;
private int displayPing = 0;
private Location location = new Location(0.0, 0.0, 0.0, 0.0f, 0.0f);
private ItemStack mainHand = null;
private ItemStack offHand = null;
private ItemStack helmet = null;
private ItemStack chestPlate = null;
private ItemStack leggings = null;
private ItemStack boots = null;
private final Set<Object> channels = new HashSet<>();
public NPC(UserProfile profile, int entityId, @Nullable Component tabName, @Nullable NamedTextColor nameColor,
@Nullable Component prefixName, @Nullable Component suffixName) {
this.profile = profile;
this.id = entityId;
this.tabName = tabName;
this.nameColor = nameColor;
this.prefixName = prefixName;
this.suffixName = suffixName;
}
public NPC(UserProfile profile, int entityId, @Nullable Component tabName) {
this(profile, entityId, tabName, null, null, null);
}
public NPC(UserProfile profile, int entityId) {
this(profile, entityId, null);
}
public boolean hasSpawned(Object channel) {
return channels.contains(channel);
}
public void spawn(Object channel) {
if (hasSpawned(channel)) return;
WrapperPlayServerPlayerInfo playerInfoPacket =
new WrapperPlayServerPlayerInfo(WrapperPlayServerPlayerInfo.Action.ADD_PLAYER, getPlayerInfoData());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, playerInfoPacket);
//TODO Later if we want entity metadata, its not supported on newer server versions though(confirm if its mandatory on older versions)
WrapperPlayServerSpawnPlayer spawnPlayer = new WrapperPlayServerSpawnPlayer(getId(),
getProfile().getUUID(),
getLocation());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, spawnPlayer);
//Create team
if (getNameColor() != null || getPrefixName() != null
|| getSuffixName() != null) {
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, generateTeamsData());
}
channels.add(channel);
}
public void despawn(Object channel) {
if (!hasSpawned(channel)) return;
//TODO Confirm if we need to destroy the team too
WrapperPlayServerDestroyEntities destroyEntities = new WrapperPlayServerDestroyEntities(getId());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, destroyEntities);
channels.remove(channel);
}
public void despawnAll() {
for (Object channel : channels) {
WrapperPlayServerDestroyEntities destroyEntities = new WrapperPlayServerDestroyEntities(getId());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, destroyEntities);
}
}
public void teleport(Location to) {
setLocation(to);
for (Object channel : channels) {
WrapperPlayServerEntityTeleport entityTeleport = new WrapperPlayServerEntityTeleport(getId(), to, true);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, entityTeleport);
}
}
public void updateLocation(Location to) {
Location from = getLocation();
setLocation(to);
double distXAbs = Math.abs(to.getPosition().getX() - from.getPosition().getX());
double distYAbs = Math.abs(to.getPosition().getY() - from.getPosition().getY());
double distZAbs = Math.abs(to.getPosition().getZ() - from.getPosition().getZ());
boolean shouldUseEntityTeleport = distXAbs > 8 ||
distYAbs > 8 ||
distZAbs > 8;
for (Object channel : channels) {
if (shouldUseEntityTeleport) {
WrapperPlayServerEntityTeleport entityTeleport =
new WrapperPlayServerEntityTeleport(getId(), to, true);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, entityTeleport);
} else {
boolean rotationChanged =
to.getYaw() != from.getYaw() || to.getPitch() != from.getPitch();
boolean positionChanged =
to.getPosition().getX() != from.getPosition().getX() ||
to.getPosition().getY() != from.getPosition().getY() ||
to.getPosition().getZ() != from.getPosition().getZ();
double deltaX = positionChanged ? (to.getPosition().getX() - from.getPosition().getX()) : 0;
double deltaY = positionChanged ? (to.getPosition().getY() - from.getPosition().getY()) : 0;
double deltaZ = positionChanged ? (to.getPosition().getZ() - from.getPosition().getZ()) : 0;
if (positionChanged && rotationChanged) {
WrapperPlayServerEntityRelativeMoveAndRotation entityRelativeMoveAndRotation =
new WrapperPlayServerEntityRelativeMoveAndRotation(getId(), deltaX, deltaY, deltaZ,
to.getYaw(), to.getPitch(), true);
PacketEvents.getAPI().getProtocolManager()
.sendPacket(channel, entityRelativeMoveAndRotation);
WrapperPlayServerEntityHeadLook headYaw =
new WrapperPlayServerEntityHeadLook(getId(), to.getYaw());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, headYaw);
} else if (positionChanged) {
WrapperPlayServerEntityRelativeMove entityRelativeMove =
new WrapperPlayServerEntityRelativeMove(getId(), deltaX, deltaY, deltaZ, true);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, entityRelativeMove);
} else if (rotationChanged) {
WrapperPlayServerEntityRotation entityRotation =
new WrapperPlayServerEntityRotation(getId(), to.getYaw(), to.getPitch(), true);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, entityRotation);
WrapperPlayServerEntityHeadLook headYaw =
new WrapperPlayServerEntityHeadLook(getId(), to.getYaw());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, headYaw);
}
}
}
}
public void updateRotation(float yaw, float pitch) {
getLocation().setYaw(yaw);
getLocation().setPitch(pitch);
for (Object channel : channels) {
WrapperPlayServerEntityRotation entityRotation =
new WrapperPlayServerEntityRotation(getId(), yaw, pitch, true);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, entityRotation);
WrapperPlayServerEntityHeadLook headYaw =
new WrapperPlayServerEntityHeadLook(getId(), yaw);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, headYaw);
}
}
public void updateTabPing(int ping) {
setDisplayPing(ping);
for (Object channel : channels) {
WrapperPlayServerPlayerInfo playerInfo =
new WrapperPlayServerPlayerInfo(WrapperPlayServerPlayerInfo.Action.UPDATE_LATENCY, getPlayerInfoData());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, playerInfo);
}
}
public void changeSkin(UUID skinUUID, List<TextureProperty> skinTextureProperties) {
for (Object channel : channels) {
WrapperPlayServerPlayerInfo playerInfoRemove =
new WrapperPlayServerPlayerInfo(WrapperPlayServerPlayerInfo.Action.REMOVE_PLAYER, getPlayerInfoData());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, playerInfoRemove);
WrapperPlayServerDestroyEntities destroyEntities =
new WrapperPlayServerDestroyEntities(getId());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, destroyEntities);
getProfile().setTextureProperties(skinTextureProperties);
getProfile().setUUID(skinUUID);
WrapperPlayServerPlayerInfo playerInfoAdd =
new WrapperPlayServerPlayerInfo(WrapperPlayServerPlayerInfo.Action.ADD_PLAYER, getPlayerInfoData());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, playerInfoAdd);
WrapperPlayServerSpawnPlayer spawnPlayer =
new WrapperPlayServerSpawnPlayer(getId(), getProfile().getUUID(), getLocation());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, spawnPlayer);
}
}
public void updateNameTag(NPC npc) {
for (Object channel : channels) {
//Destroy team
WrapperPlayServerTeams removeTeam =
new WrapperPlayServerTeams("custom_name_team",
WrapperPlayServerTeams.TeamMode.REMOVE,
Optional.empty());
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, removeTeam);
if (npc.getNameColor() != null || npc.getPrefixName() != null
|| npc.getSuffixName() != null) {
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, generateTeamsData());
}
}
}
public void updateEquipment() {
for (Object channel : channels) {
List<Equipment> equipmentList = new ArrayList<>();
ItemStack handItem = getMainHand();
if (handItem == null) {
handItem = ItemStack.EMPTY;
}
equipmentList.add(new Equipment(EquipmentSlot.MAINHAND,
handItem));
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
ItemStack offHandItem = getOffHand();
if (offHandItem == null) {
offHandItem = ItemStack.EMPTY;
}
equipmentList.add(new Equipment(EquipmentSlot.OFFHAND,
offHandItem));
}
ItemStack helmetItem = getHelmet();
if (helmetItem == null) {
helmetItem = ItemStack.EMPTY;
}
equipmentList.add(new Equipment(EquipmentSlot.HELMET,
helmetItem));
ItemStack chestPlateItem = getChestplate();
if (chestPlateItem == null) {
chestPlateItem = ItemStack.EMPTY;
}
equipmentList.add(new Equipment(EquipmentSlot.CHESTPLATE,
chestPlateItem));
ItemStack leggingsItem = getLeggings();
if (leggingsItem == null) {
leggingsItem = ItemStack.EMPTY;
}
equipmentList.add(new Equipment(EquipmentSlot.LEGGINGS,
leggingsItem));
ItemStack bootsItem = getBoots();
if (bootsItem == null) {
bootsItem = ItemStack.EMPTY;
}
equipmentList.add(new Equipment(EquipmentSlot.BOOTS,
bootsItem));
WrapperPlayServerEntityEquipment equipmentPacket
= new WrapperPlayServerEntityEquipment(getId(),
equipmentList);
PacketEvents.getAPI().getProtocolManager().sendPacket(channel, equipmentPacket);
}
}
public ItemStack getMainHand() {
return mainHand;
}
public void setMainHand(ItemStack mainHand) {
this.mainHand = mainHand;
}
public ItemStack getOffHand() {
return offHand;
}
public void setOffHand(ItemStack offHand) {
this.offHand = offHand;
}
public ItemStack getHelmet() {
return helmet;
}
public void setHelmet(ItemStack helmet) {
this.helmet = helmet;
}
public ItemStack getChestplate() {
return chestPlate;
}
public void setChestplate(ItemStack chestPlate) {
this.chestPlate = chestPlate;
}
public ItemStack getLeggings() {
return leggings;
}
public void setLeggings(ItemStack leggings) {
this.leggings = leggings;
}
public ItemStack getBoots() {
return boots;
}
public void setBoots(ItemStack boots) {
this.boots = boots;
}
@Nullable
public NamedTextColor getNameColor() {
return nameColor;
}
public void setNameColor(@Nullable NamedTextColor nameColor) {
this.nameColor = nameColor;
}
@Nullable
public Component getPrefixName() {
return prefixName;
}
public void setPrefixName(@Nullable Component namePrefix) {
this.prefixName = namePrefix;
}
@Nullable
public Component getSuffixName() {
return suffixName;
}
public void setSuffixName(@Nullable Component nameSuffix) {
this.suffixName = nameSuffix;
}
@Nullable
public Component getTabName() {
return tabName;
}
public void setTabName(@Nullable Component tabName) {
this.tabName = tabName;
}
public int getId() {
return id;
}
public UserProfile getProfile() {
return profile;
}
private WrapperPlayServerTeams generateTeamsData() {
return new WrapperPlayServerTeams("custom_name_team",
WrapperPlayServerTeams.TeamMode.CREATE,
Optional.of(
new WrapperPlayServerTeams.ScoreBoardTeamInfo(
Component.text("custom_name_team"),
prefixName,
suffixName,
WrapperPlayServerTeams.NameTagVisibility.ALWAYS,
WrapperPlayServerTeams.CollisionRule.ALWAYS,
nameColor,
WrapperPlayServerTeams.OptionData.NONE
)),
getProfile().getName());
}
public WrapperPlayServerPlayerInfo.PlayerData getPlayerInfoData() {
return new WrapperPlayServerPlayerInfo.PlayerData(getTabName(),
getProfile(), GameMode.SURVIVAL,
getDisplayPing());
}
public int getDisplayPing() {
return displayPing;
}
public void setDisplayPing(int ping) {
this.displayPing = ping;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
}
@@ -1,538 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.clientbound.*;
import com.github.retrooper.packetevents.protocol.packettype.serverbound.*;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.util.VersionMapper;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
public final class PacketType {
private static boolean PREPARED = false;
//TODO UPDATE Update packet type mappings (clientbound pt. 1)
private static final VersionMapper CLIENTBOUND_PLAY_VERSION_MAPPER = new VersionMapper(
ClientVersion.V_1_7_10,
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_10,
ClientVersion.V_1_12,
ClientVersion.V_1_12_1,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_14_4,
ClientVersion.V_1_15,
ClientVersion.V_1_15_2,
ClientVersion.V_1_16,
ClientVersion.V_1_16_2,
ClientVersion.V_1_17,
ClientVersion.V_1_18);
//TODO UPDATE Update packet type mappings (serverbound pt. 1)
private static final VersionMapper SERVERBOUND_PLAY_VERSION_MAPPER = new VersionMapper(
ClientVersion.V_1_7_10,
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_12,
ClientVersion.V_1_12_1,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_15_2,
ClientVersion.V_1_16,
ClientVersion.V_1_16_2,
ClientVersion.V_1_17);
public static void prepare() {
PacketType.Play.Client.load();
PacketType.Play.Server.load();
PREPARED = true;
}
public static boolean isPrepared() {
return PREPARED;
}
public static PacketTypeCommon getById(PacketSide side, ConnectionState state, ClientVersion version, int packetID) {
switch (state) {
case HANDSHAKING:
return Handshaking.Client.getById(packetID);
case STATUS:
if (side == PacketSide.CLIENT) {
return Status.Client.getById(packetID);
} else {
return Status.Server.getById(packetID);
}
case LOGIN:
if (side == PacketSide.CLIENT) {
return Login.Client.getById(packetID);
} else {
return Login.Server.getById(packetID);
}
case PLAY:
if (side == PacketSide.CLIENT) {
return Play.Client.getById(version, packetID);
} else {
return Play.Server.getById(version, packetID);
}
default:
return null;
}
}
public static class Handshaking {
public enum Client implements PacketTypeConstant {
HANDSHAKE(0),
/**
* Technically not part of the current protocol, but clients older than 1.7 will send this to initiate Server List Ping.
* 1.8 and newer servers will handle it correctly though.
*/
LEGACY_SERVER_LIST_PING(254);//0xFE in hex
private final int id;
Client(int id) {
this.id = id;
}
@Nullable
public static PacketTypeCommon getById(int packetID) {
if (packetID == 0) {
return HANDSHAKE;
} else if (packetID == 254) {
return LEGACY_SERVER_LIST_PING;
} else {
return null;
}
}
public int getId() {
return id;
}
}
}
public static class Status {
public enum Client implements PacketTypeConstant {
REQUEST(0),
PING(1);
private final int id;
Client(int id) {
this.id = id;
}
@Nullable
public static PacketTypeCommon getById(int packetId) {
if (packetId == 0) {
return REQUEST;
} else if (packetId == 1) {
return PING;
} else {
return null;
}
}
public int getId() {
return id;
}
}
public enum Server implements PacketTypeConstant {
RESPONSE(0),
PONG(1);
private final int id;
Server(int id) {
this.id = id;
}
@Nullable
public static PacketTypeCommon getById(int packetID) {
if (packetID == 0) {
return RESPONSE;
} else if (packetID == 1) {
return PONG;
} else {
return null;
}
}
public int getId() {
return id;
}
}
}
public static class Login {
public enum Client implements PacketTypeConstant {
LOGIN_START(0),
ENCRYPTION_RESPONSE(1),
///Added in 1.13
LOGIN_PLUGIN_RESPONSE(2);
private final int id;
Client(int id) {
this.id = id;
}
@Nullable
public static PacketTypeCommon getById(int packetID) {
if (packetID == 0) {
return LOGIN_START;
} else if (packetID == 1) {
return ENCRYPTION_RESPONSE;
} else if (packetID == 2) {
return LOGIN_PLUGIN_RESPONSE;
} else {
return null;
}
}
public int getId() {
return id;
}
}
public enum Server implements PacketTypeConstant {
DISCONNECT(0),
ENCRYPTION_REQUEST(1),
LOGIN_SUCCESS(2),
//Added in 1.8
SET_COMPRESSION(3),
///Added in 1.13
LOGIN_PLUGIN_REQUEST(4);
private final int id;
Server(int id) {
this.id = id;
}
@Nullable
public static PacketTypeCommon getById(int packetID) {
switch (packetID) {
case 0:
return DISCONNECT;
case 1:
return ENCRYPTION_REQUEST;
case 2:
return LOGIN_SUCCESS;
case 3:
return SET_COMPRESSION;
case 4:
return LOGIN_PLUGIN_REQUEST;
default:
return null;
}
}
public int getId() {
return id;
}
}
}
public static class Play {
public enum Client implements PacketTypeCommon {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
SET_DIFFICULTY,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
GENERATE_STRUCTURE,
KEEP_ALIVE,
LOCK_DIFFICULTY,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
PLAYER_FLYING,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
PONG,
RECIPE_BOOK_DATA,
SET_DISPLAYED_RECIPE,
SET_RECIPE_BOOK_STATE,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_JIGSAW_BLOCK,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM;
private static int INDEX = 0;
private static final Map<Byte, Map<Integer, PacketTypeCommon>> PACKET_TYPE_ID_MAP = new HashMap<>();
private final int[] ids = new int[SERVERBOUND_PLAY_VERSION_MAPPER.getVersions().length];
@Nullable
public static PacketTypeCommon getById(ClientVersion version, int packetId) {
if (!PREPARED) {
PacketType.prepare();
}
int index = SERVERBOUND_PLAY_VERSION_MAPPER.getIndex(version);
Map<Integer, PacketTypeCommon> packetIdMap = PACKET_TYPE_ID_MAP.computeIfAbsent((byte)index, k -> new HashMap<>());
return packetIdMap.get(packetId);
}
private static void loadPacketIds(Enum<?>[] enumConstants) {
int index = INDEX;
for (Enum<?> constant : enumConstants) {
int id = constant.ordinal();
Client value = Client.valueOf(constant.name());
value.ids[index] = id;
Map<Integer, PacketTypeCommon> packetIdMap = PACKET_TYPE_ID_MAP.computeIfAbsent((byte) index,
k -> new HashMap<>());
packetIdMap.put(id, value);
}
INDEX++;
}
public static void load() {
INDEX = 0;
loadPacketIds(ServerboundPacketType_1_7_10.values());
loadPacketIds(ServerboundPacketType_1_8.values());
loadPacketIds(ServerboundPacketType_1_9.values());
loadPacketIds(ServerboundPacketType_1_12.values());
loadPacketIds(ServerboundPacketType_1_12_1.values());
loadPacketIds(ServerboundPacketType_1_13.values());
loadPacketIds(ServerboundPacketType_1_14.values());
loadPacketIds(ServerboundPacketType_1_15_2.values());
loadPacketIds(ServerboundPacketType_1_16.values());
loadPacketIds(ServerboundPacketType_1_16_2.values());
loadPacketIds(ServerboundPacketType_1_17.values());
//TODO UPDATE Update packet type mappings (serverbound pt. 2)
}
public int getId(ClientVersion version) {
if (!PREPARED) {
PacketType.prepare();
}
int index = SERVERBOUND_PLAY_VERSION_MAPPER.getIndex(version);
return ids[index];
}
}
public enum Server implements PacketTypeCommon {
//Packets that are no longer present on latest version
SET_COMPRESSION,
MAP_CHUNK_BULK,
UPDATE_ENTITY_NBT,
UPDATE_SIGN,
USE_BED,
SPAWN_WEATHER_ENTITY,
TITLE,
WORLD_BORDER,
COMBAT_EVENT,
ENTITY_MOVEMENT,
//Okay these are normal ones
WINDOW_CONFIRMATION,
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
SCULK_VIBRATION_SIGNAL,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
CLEAR_TITLES,
TAB_COMPLETE,
MULTI_BLOCK_CHANGE,
DECLARE_COMMANDS,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
INITIALIZE_WORLD_BORDER,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
PING,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
END_COMBAT_EVENT,
ENTER_COMBAT_EVENT,
DEATH_COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
ACTION_BAR,
WORLD_BORDER_CENTER,
WORLD_BORDER_LERP_SIZE,
WORLD_BORDER_SIZE,
WORLD_BORDER_WARNING_DELAY,
WORLD_BORDER_WARNING_REACH,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
SPAWN_POSITION,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
UPDATE_SIMULATION_DISTANCE,
SET_TITLE_SUBTITLE,
TIME_UPDATE,
SET_TITLE_TEXT,
SET_TITLE_TIMES,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS;
private static int INDEX = 0;
private static final Map<Byte, Map<Integer, PacketTypeCommon>> PACKET_TYPE_ID_MAP = new IdentityHashMap<>();
private final int[] ids = new int[CLIENTBOUND_PLAY_VERSION_MAPPER.getVersions().length];
public int getId(ClientVersion version) {
if (!PREPARED) {
PacketType.prepare();
}
int index = CLIENTBOUND_PLAY_VERSION_MAPPER.getIndex(version);
return ids[index];
}
@Nullable
public static PacketTypeCommon getById(ClientVersion version, int packetId) {
if (!PREPARED) {
PacketType.prepare();
}
int index = CLIENTBOUND_PLAY_VERSION_MAPPER.getIndex(version);
Map<Integer, PacketTypeCommon> map = PACKET_TYPE_ID_MAP.get((byte) index);
return map.get(packetId);
}
private static void loadPacketIds(Enum<?>[] enumConstants) {
int index = INDEX;
for (Enum<?> constant : enumConstants) {
int id = constant.ordinal();
Server value = Server.valueOf(constant.name());
value.ids[index] = id;
Map<Integer, PacketTypeCommon> packetIdMap = PACKET_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
packetIdMap.put(id, value);
}
INDEX++;
}
public static void load() {
INDEX = 0;
loadPacketIds(ClientboundPacketType_1_7_10.values());
loadPacketIds(ClientboundPacketType_1_8.values());
loadPacketIds(ClientboundPacketType_1_9.values());
loadPacketIds(ClientboundPacketType_1_9_3.values());
loadPacketIds(ClientboundPacketType_1_12.values());
loadPacketIds(ClientboundPacketType_1_12_1.values());
loadPacketIds(ClientboundPacketType_1_13.values());
loadPacketIds(ClientboundPacketType_1_14.values());
loadPacketIds(ClientboundPacketType_1_14_4.values());
loadPacketIds(ClientboundPacketType_1_15.values());
loadPacketIds(ClientboundPacketType_1_15_2.values());
loadPacketIds(ClientboundPacketType_1_16.values());
loadPacketIds(ClientboundPacketType_1_16_2.values());
loadPacketIds(ClientboundPacketType_1_17.values());
loadPacketIds(ClientboundPacketType_1_18.values());
//TODO UPDATE Update packet type mappings (clientbound pt. 2)
}
}
}
}
@@ -1,29 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
public interface PacketTypeConstant extends PacketTypeCommon{
default int getId(ClientVersion version) {
return getId();
}
int getId();
}
@@ -1,110 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_12 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
TAB_COMPLETE,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
OPEN_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
JOIN_GAME,
MAP_DATA,
ENTITY_MOVEMENT,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
VEHICLE_MOVE,
OPEN_SIGN_EDITOR,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
PLAYER_POSITION_AND_LOOK,
USE_BED,
//This packet was added
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
//This packet was added
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
SOUND_EFFECT,
PLAYER_LIST_HEADER_AND_FOOTER,
COLLECT_ITEM,
ENTITY_TELEPORT,
//This packet was added
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT
}
@@ -1,105 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_12_1 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
TAB_COMPLETE,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
OPEN_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
JOIN_GAME,
MAP_DATA,
ENTITY_MOVEMENT,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
VEHICLE_MOVE,
OPEN_SIGN_EDITOR,
//This packet was added
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
PLAYER_POSITION_AND_LOOK,
USE_BED,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
SOUND_EFFECT,
PLAYER_LIST_HEADER_AND_FOOTER,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT
}
@@ -1,122 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_13 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
TAB_COMPLETE,
//This packet was added
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
OPEN_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
//This packet was added
NBT_QUERY_RESPONSE,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
JOIN_GAME,
MAP_DATA,
ENTITY_MOVEMENT,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
VEHICLE_MOVE,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
//This packet was added
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
USE_BED,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
//This packet was added
STOP_SOUND,
SOUND_EFFECT,
PLAYER_LIST_HEADER_AND_FOOTER,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
//These two packets were added
DECLARE_RECIPES,
TAGS
}
@@ -1,132 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_14 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
TAB_COMPLETE,
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
//This packet was added
OPEN_HORSE_WINDOW,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
//This packet was just added
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
//This packet has been removed
//USE_BED,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
//This packet was just added
UPDATE_VIEW_POSITION,
//This packet was just added
UPDATE_VIEW_DISTANCE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
//This packet was just added
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,117 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_14_4 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
TAB_COMPLETE,
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS,
//This packet was added
ACKNOWLEDGE_PLAYER_DIGGING
}
@@ -1,115 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_15 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
TAB_COMPLETE,
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,120 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_15_2 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
//This packet was added
SPAWN_WEATHER_ENTITY,
//This packet was added
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
TAB_COMPLETE,
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,118 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_16 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
//This packet was removed.
//SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
TAB_COMPLETE,
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,114 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_16_2 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
TAB_COMPLETE,
DECLARE_COMMANDS,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
MULTI_BLOCK_CHANGE,
SELECT_ADVANCEMENT_TAB,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
SPAWN_POSITION,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
TIME_UPDATE,
TITLE,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,171 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_17 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
//This packet was added
SCULK_VIBRATION_SIGNAL,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
//This packet was added
CLEAR_TITLES,
TAB_COMPLETE,
DECLARE_COMMANDS,
//This packet was removed and replaced with the PING packet
//WINDOW_CONFIRMATION,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
//This packet was added
INITIALIZE_WORLD_BORDER,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
//This packet was removed
//ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
//This packet was added
PING,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
//This packet was removed and split up into 3 new packets
//COMBAT_EVENT,
//These 3 new packets were added
END_COMBAT_EVENT,
ENTER_COMBAT_EVENT,
DEATH_COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
//In 1.17 you can only destroy ONE ENTITY now
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
MULTI_BLOCK_CHANGE,
SELECT_ADVANCEMENT_TAB,
//These 5 new packets were added
ACTION_BAR,
WORLD_BORDER_CENTER,
WORLD_BORDER_LERP_SIZE,
WORLD_BORDER_SIZE,
WORLD_BORDER_WARNING_DELAY,
WORLD_BORDER_WARNING_REACH,
//This packet was removed
//WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
SPAWN_POSITION,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
//This new packet was added
SET_TITLE_SUBTITLE,
TIME_UPDATE,
//These 2 new packets were added
SET_TITLE_TEXT,
SET_TITLE_TIMES,
//This packet was removed and split up into 3 new packets
//TITLE,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,130 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_18 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
SCULK_VIBRATION_SIGNAL,
ENTITY_ANIMATION,
STATISTICS,
ACKNOWLEDGE_PLAYER_DIGGING,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
CHAT_MESSAGE,
CLEAR_TITLES,
TAB_COMPLETE,
DECLARE_COMMANDS,
CLOSE_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
OPEN_HORSE_WINDOW,
INITIALIZE_WORLD_BORDER,
KEEP_ALIVE,
//This is also used for lighting
CHUNK_DATA,
EFFECT,
PARTICLE,
UPDATE_LIGHT,
JOIN_GAME,
MAP_DATA,
TRADE_LIST,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
VEHICLE_MOVE,
OPEN_BOOK,
OPEN_WINDOW,
OPEN_SIGN_EDITOR,
PING,
CRAFT_RECIPE_RESPONSE,
PLAYER_ABILITIES,
END_COMBAT_EVENT,
ENTER_COMBAT_EVENT,
DEATH_COMBAT_EVENT,
PLAYER_INFO,
FACE_PLAYER,
PLAYER_POSITION_AND_LOOK,
UNLOCK_RECIPES,
//Since 1.17.1 you can destroy multiple entities again
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
MULTI_BLOCK_CHANGE,
SELECT_ADVANCEMENT_TAB,
ACTION_BAR,
WORLD_BORDER_CENTER,
WORLD_BORDER_LERP_SIZE,
WORLD_BORDER_SIZE,
WORLD_BORDER_WARNING_DELAY,
WORLD_BORDER_WARNING_REACH,
CAMERA,
HELD_ITEM_CHANGE,
UPDATE_VIEW_POSITION,
UPDATE_VIEW_DISTANCE,
SPAWN_POSITION,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
UPDATE_SIMULATION_DISTANCE,
SET_TITLE_SUBTITLE,
TIME_UPDATE,
SET_TITLE_TEXT,
SET_TITLE_TIMES,
ENTITY_SOUND_EFFECT,
SOUND_EFFECT,
STOP_SOUND,
PLAYER_LIST_HEADER_AND_FOOTER,
NBT_QUERY_RESPONSE,
COLLECT_ITEM,
ENTITY_TELEPORT,
ADVANCEMENTS,
ENTITY_PROPERTIES,
ENTITY_EFFECT,
DECLARE_RECIPES,
TAGS
}
@@ -1,87 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_7_10 {
KEEP_ALIVE,
JOIN_GAME,
CHAT_MESSAGE,
TIME_UPDATE,
ENTITY_EQUIPMENT,
SPAWN_POSITION,
UPDATE_HEALTH,
RESPAWN,
PLAYER_POSITION_AND_LOOK,
HELD_ITEM_CHANGE,
USE_BED,
ENTITY_ANIMATION,
SPAWN_PLAYER,
COLLECT_ITEM,
SPAWN_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_EXPERIENCE_ORB,
ENTITY_VELOCITY,
DESTROY_ENTITIES,
ENTITY_MOVEMENT,
ENTITY_RELATIVE_MOVE,
ENTITY_ROTATION,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_TELEPORT,
ENTITY_HEAD_LOOK,
ENTITY_STATUS,
ATTACH_ENTITY,
ENTITY_METADATA,
ENTITY_EFFECT,
REMOVE_ENTITY_EFFECT,
SET_EXPERIENCE,
ENTITY_PROPERTIES,
CHUNK_DATA,
MULTI_BLOCK_CHANGE,
BLOCK_CHANGE,
BLOCK_ACTION,
BLOCK_BREAK_ANIMATION,
MAP_CHUNK_BULK,
EXPLOSION,
EFFECT,
SOUND_EFFECT,
PARTICLE,
CHANGE_GAME_STATE,
SPAWN_WEATHER_ENTITY,
OPEN_WINDOW,
CLOSE_WINDOW,
SET_SLOT,
WINDOW_ITEMS,
WINDOW_PROPERTY,
WINDOW_CONFIRMATION,
UPDATE_SIGN,
MAP_DATA,
BLOCK_ENTITY_DATA,
OPEN_SIGN_EDITOR,
STATISTICS,
PLAYER_INFO,
PLAYER_ABILITIES,
TAB_COMPLETE,
SCOREBOARD_OBJECTIVE,
UPDATE_SCORE,
DISPLAY_SCOREBOARD,
TEAMS,
PLUGIN_MESSAGE,
DISCONNECT
}
@@ -1,98 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_8 {
KEEP_ALIVE,
JOIN_GAME,
CHAT_MESSAGE,
TIME_UPDATE,
ENTITY_EQUIPMENT,
SPAWN_POSITION,
UPDATE_HEALTH,
RESPAWN,
PLAYER_POSITION_AND_LOOK,
HELD_ITEM_CHANGE,
USE_BED,
ENTITY_ANIMATION,
SPAWN_PLAYER,
COLLECT_ITEM,
SPAWN_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_EXPERIENCE_ORB,
ENTITY_VELOCITY,
DESTROY_ENTITIES,
ENTITY_MOVEMENT,
ENTITY_RELATIVE_MOVE,
ENTITY_ROTATION,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_TELEPORT,
ENTITY_HEAD_LOOK,
ENTITY_STATUS,
ATTACH_ENTITY,
ENTITY_METADATA,
ENTITY_EFFECT,
REMOVE_ENTITY_EFFECT,
SET_EXPERIENCE,
ENTITY_PROPERTIES,
CHUNK_DATA,
MULTI_BLOCK_CHANGE,
BLOCK_CHANGE,
BLOCK_ACTION,
BLOCK_BREAK_ANIMATION,
MAP_CHUNK_BULK,
EXPLOSION,
EFFECT,
SOUND_EFFECT,
PARTICLE,
CHANGE_GAME_STATE,
SPAWN_WEATHER_ENTITY,
OPEN_WINDOW,
CLOSE_WINDOW,
SET_SLOT,
WINDOW_ITEMS,
WINDOW_PROPERTY,
WINDOW_CONFIRMATION,
UPDATE_SIGN,
MAP_DATA,
BLOCK_ENTITY_DATA,
OPEN_SIGN_EDITOR,
STATISTICS,
PLAYER_INFO,
PLAYER_ABILITIES,
TAB_COMPLETE,
SCOREBOARD_OBJECTIVE,
UPDATE_SCORE,
DISPLAY_SCOREBOARD,
TEAMS,
PLUGIN_MESSAGE,
DISCONNECT,
//1.8 added these new packets
SERVER_DIFFICULTY,
COMBAT_EVENT,
CAMERA,
WORLD_BORDER,
TITLE,
SET_COMPRESSION,
PLAYER_LIST_HEADER_AND_FOOTER,
RESOURCE_PACK_SEND,
UPDATE_ENTITY_NBT
}
@@ -1,109 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_9 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
TAB_COMPLETE,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
OPEN_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
JOIN_GAME,
MAP_DATA,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_SIGN_EDITOR,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
PLAYER_POSITION_AND_LOOK,
USE_BED,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
WORLD_BORDER,
//This packet has been removed. Its broken, you should send the packet during the login stage.
//SET_COMPRESSION,
//This packet was removed.
//MAP_CHUNK_BULK
//This packet was removed.
//UPDATE_ENTITY_NBT
CAMERA,
HELD_ITEM_CHANGE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
UPDATE_SIGN,
SOUND_EFFECT,
PLAYER_LIST_HEADER_AND_FOOTER,
COLLECT_ITEM,
ENTITY_TELEPORT,
ENTITY_PROPERTIES,
ENTITY_EFFECT
}
@@ -1,100 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.clientbound;
public enum ClientboundPacketType_1_9_3 {
SPAWN_ENTITY,
SPAWN_EXPERIENCE_ORB,
SPAWN_WEATHER_ENTITY,
SPAWN_LIVING_ENTITY,
SPAWN_PAINTING,
SPAWN_PLAYER,
ENTITY_ANIMATION,
STATISTICS,
BLOCK_BREAK_ANIMATION,
BLOCK_ENTITY_DATA,
BLOCK_ACTION,
BLOCK_CHANGE,
BOSS_BAR,
SERVER_DIFFICULTY,
TAB_COMPLETE,
CHAT_MESSAGE,
MULTI_BLOCK_CHANGE,
WINDOW_CONFIRMATION,
CLOSE_WINDOW,
OPEN_WINDOW,
WINDOW_ITEMS,
WINDOW_PROPERTY,
SET_SLOT,
SET_COOLDOWN,
PLUGIN_MESSAGE,
NAMED_SOUND_EFFECT,
DISCONNECT,
ENTITY_STATUS,
EXPLOSION,
UNLOAD_CHUNK,
CHANGE_GAME_STATE,
KEEP_ALIVE,
CHUNK_DATA,
EFFECT,
PARTICLE,
JOIN_GAME,
MAP_DATA,
ENTITY_RELATIVE_MOVE,
ENTITY_RELATIVE_MOVE_AND_ROTATION,
ENTITY_ROTATION,
ENTITY_MOVEMENT,
VEHICLE_MOVE,
OPEN_SIGN_EDITOR,
PLAYER_ABILITIES,
COMBAT_EVENT,
PLAYER_INFO,
PLAYER_POSITION_AND_LOOK,
USE_BED,
DESTROY_ENTITIES,
REMOVE_ENTITY_EFFECT,
RESOURCE_PACK_SEND,
RESPAWN,
ENTITY_HEAD_LOOK,
WORLD_BORDER,
CAMERA,
HELD_ITEM_CHANGE,
DISPLAY_SCOREBOARD,
ENTITY_METADATA,
ATTACH_ENTITY,
ENTITY_VELOCITY,
ENTITY_EQUIPMENT,
SET_EXPERIENCE,
UPDATE_HEALTH,
SCOREBOARD_OBJECTIVE,
SET_PASSENGERS,
TEAMS,
UPDATE_SCORE,
SPAWN_POSITION,
TIME_UPDATE,
TITLE,
//This packet has been removed.
//UPDATE_SIGN
SOUND_EFFECT,
PLAYER_LIST_HEADER_AND_FOOTER,
COLLECT_ITEM,
ENTITY_TELEPORT,
ENTITY_PROPERTIES,
ENTITY_EFFECT
}
@@ -1,55 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_12 {
TELEPORT_CONFIRM,
CRAFT_RECIPE_REQUEST,
TAB_COMPLETE,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
INTERACT_ENTITY,
KEEP_ALIVE,
PLAYER_FLYING,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
VEHICLE_MOVE,
STEER_BOAT,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
RECIPE_BOOK_DATA,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
HELD_ITEM_CHANGE,
CREATIVE_INVENTORY_ACTION,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,55 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_12_1 {
TELEPORT_CONFIRM,
TAB_COMPLETE,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
INTERACT_ENTITY,
KEEP_ALIVE,
PLAYER_FLYING,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
VEHICLE_MOVE,
STEER_BOAT,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
RECIPE_BOOK_DATA,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
HELD_ITEM_CHANGE,
CREATIVE_INVENTORY_ACTION,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,66 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_13 {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
//This packet was added
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
KEEP_ALIVE,
PLAYER_FLYING,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
RECIPE_BOOK_DATA,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,68 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_14 {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
SET_DIFFICULTY,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
KEEP_ALIVE,
LOCK_DIFFICULTY,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
PLAYER_FLYING,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
RECIPE_BOOK_DATA,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_JIGSAW_BLOCK,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,68 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_15_2 {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
SET_DIFFICULTY,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
KEEP_ALIVE,
LOCK_DIFFICULTY,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
PLAYER_FLYING,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
RECIPE_BOOK_DATA,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_JIGSAW_BLOCK,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,69 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_16 {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
SET_DIFFICULTY,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
GENERATE_STRUCTURE,
KEEP_ALIVE,
LOCK_DIFFICULTY,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
PLAYER_FLYING,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
RECIPE_BOOK_DATA,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_JIGSAW_BLOCK,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,72 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_16_2 {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
SET_DIFFICULTY,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
WINDOW_CONFIRMATION,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
GENERATE_STRUCTURE,
KEEP_ALIVE,
LOCK_DIFFICULTY,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
PLAYER_FLYING,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
//RECIPE_BOOK_DATA was deleted and has been split up into two new packets
//RECIPE_BOOK_DATA,
SET_RECIPE_BOOK_STATE,
SET_DISPLAYED_RECIPE,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_JIGSAW_BLOCK,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,71 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_17 {
TELEPORT_CONFIRM,
QUERY_BLOCK_NBT,
SET_DIFFICULTY,
CHAT_MESSAGE,
CLIENT_STATUS,
CLIENT_SETTINGS,
TAB_COMPLETE,
CLICK_WINDOW_BUTTON,
CLICK_WINDOW,
CLOSE_WINDOW,
PLUGIN_MESSAGE,
EDIT_BOOK,
QUERY_ENTITY_NBT,
INTERACT_ENTITY,
GENERATE_STRUCTURE,
KEEP_ALIVE,
LOCK_DIFFICULTY,
PLAYER_POSITION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_ROTATION,
PLAYER_FLYING,
VEHICLE_MOVE,
STEER_BOAT,
PICK_ITEM,
CRAFT_RECIPE_REQUEST,
PLAYER_ABILITIES,
PLAYER_DIGGING,
ENTITY_ACTION,
STEER_VEHICLE,
PONG,
//RECIPE_BOOK_DATA,
SET_RECIPE_BOOK_STATE,
SET_DISPLAYED_RECIPE,
NAME_ITEM,
RESOURCE_PACK_STATUS,
ADVANCEMENT_TAB,
SELECT_TRADE,
SET_BEACON_EFFECT,
HELD_ITEM_CHANGE,
UPDATE_COMMAND_BLOCK,
UPDATE_COMMAND_BLOCK_MINECART,
CREATIVE_INVENTORY_ACTION,
UPDATE_JIGSAW_BLOCK,
UPDATE_STRUCTURE_BLOCK,
UPDATE_SIGN,
ANIMATION,
SPECTATE,
PLAYER_BLOCK_PLACEMENT,
USE_ITEM
}
@@ -1,46 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_7_10 {
KEEP_ALIVE,
CHAT_MESSAGE,
INTERACT_ENTITY,
PLAYER_FLYING,
PLAYER_POSITION,
PLAYER_ROTATION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_DIGGING,
PLAYER_BLOCK_PLACEMENT,
HELD_ITEM_CHANGE,
ANIMATION,
ENTITY_ACTION,
STEER_VEHICLE,
CLOSE_WINDOW,
CLICK_WINDOW,
WINDOW_CONFIRMATION,
CREATIVE_INVENTORY_ACTION,
CLICK_WINDOW_BUTTON,
UPDATE_SIGN,
PLAYER_ABILITIES,
TAB_COMPLETE,
CLIENT_SETTINGS,
CLIENT_STATUS,
PLUGIN_MESSAGE
}
@@ -1,48 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.packettype.serverbound;
public enum ServerboundPacketType_1_8 {
KEEP_ALIVE,
CHAT_MESSAGE,
INTERACT_ENTITY,
PLAYER_FLYING,
PLAYER_POSITION,
PLAYER_ROTATION,
PLAYER_POSITION_AND_ROTATION,
PLAYER_DIGGING,
PLAYER_BLOCK_PLACEMENT,
HELD_ITEM_CHANGE,
ANIMATION,
ENTITY_ACTION,
STEER_VEHICLE,
CLOSE_WINDOW,
CLICK_WINDOW,
WINDOW_CONFIRMATION,
CREATIVE_INVENTORY_ACTION,
CLICK_WINDOW_BUTTON,
UPDATE_SIGN,
PLAYER_ABILITIES,
TAB_COMPLETE,
CLIENT_SETTINGS,
CLIENT_STATUS,
PLUGIN_MESSAGE,
SPECTATE,
RESOURCE_PACK_STATUS
}
Loaded 100 of 640 files, more files were not shown because too many files have changed in this diff. Show more