Compare commits

..
176 Commits
Author SHA1 Message Date
retrooper e3a984ca72 Merge remote-tracking branch 'origin/master' 2024-07-18 00:09:35 +02:00
retrooper f8fad9607b Really... 2024-07-18 00:09:14 +02:00
retrooper a9e40c2abc Genuinely last push now 2024-07-17 23:47:20 +02:00
retrooper da12521d0b Final commit to this... 2024-07-17 23:38:28 +02:00
retrooper de1f91104d Now really should be the last commit for this ancient version. 2024-06-23 12:46:10 +02:00
retrooper f02b77c0ba Probably last commit but silence trivial uninjection error. 2024-06-21 00:32:07 +02:00
retrooper bf2e88ed8f minimal update for pe 1.8 (likely one of the last) 2024-06-19 14:49:43 +02:00
retrooper f04a3c75a9 fixes to attribute snapshot 2024-06-03 05:20:22 +02:00
retrooper 80408424dd fixes to attribute snapshot 2024-06-02 20:52:09 +02:00
retrooper cb897dabe5 fixes to client command 2024-05-31 19:47:02 +02:00
retrooper 92cb0d024d fixes 2 2024-05-30 23:17:08 +02:00
retrooper 72e617624a fixes 2024-05-30 22:52:04 +02:00
retrooper 239d712b5f Fixes entity effect 2024-05-30 19:40:18 +02:00
retrooper 9b9ab1ade6 Fixes 2024-05-30 01:00:52 +02:00
retrooper 63383579b4 fixes 2024-05-30 00:42:30 +02:00
retrooper a2e19f7020 Fix WrappedPacketInCustomPayload 2024-05-28 20:32:15 +02:00
retrooper 7ff578e1c6 Fix Bukkit package access code. 2024-05-28 06:42:37 +02:00
retrooper 95952588f1 * Added version constants for 1.20.5 & 1.20.6
* Updated minecraft internals to adapt to 1.20.5/1.20.6 (tested on paper experimental builds)
* Adapt to further breaking changes introduced by paper
* Updated custom payload wrapper for 1.20.5/1.20.6
2024-04-28 23:22:07 +02:00
retrooper 8d4d89f049 Fix WrappedPacketOutExplosion for 1.20.4 2023-12-27 15:24:04 +01:00
retrooper 74ddbacff5 1.20.3/1.20.4 support 2023-12-08 14:44:48 +01:00
retrooper 2b1d6c636d Update build.gradle 2023-11-19 17:50:47 +01:00
retrooper e47c10966e Fix build errors for jitpack 2023-11-04 23:42:12 +01:00
retrooper 9153aa6945 Attempt to replace spigot pt 3 2023-11-04 23:39:25 +01:00
retrooper 34e4007f7d Attempt to replace spigot pt 2 2023-11-04 23:33:51 +01:00
retrooper 0528eb7035 Attempt to replace spigot 2023-11-04 23:31:47 +01:00
retrooper 3a25a933ff Attempt to replace spigot 2023-11-04 23:30:44 +01:00
retrooper efa694c8e1 Fix the way we access network manager (for 1.20.2) 2023-11-04 23:11:27 +01:00
retrooper 289a71106a Fix WrappedPacketInCustomPayload and added CONFIG packet event 2023-10-07 21:24:07 +02:00
retrooper 012bcae2d5 Fix WrappedPacketHandshakingInSetProtocol implementation for 1.20.2 2023-10-03 00:18:52 +02:00
retrooper c84641cc83 Fix EntityEffect ID processing 2023-10-02 22:05:26 +02:00
retrooper baf93f527c Attempt to fix 2023-10-02 00:46:15 +02:00
retrooper d95d5394eb Bug fix for entity effect 2023-10-02 00:36:30 +02:00
retrooper 2675b41c3e 1.20.2 fix for entity effects 2023-10-02 00:25:22 +02:00
retrooper 4d27d6e967 1.20.2 should be working 2023-09-27 17:11:31 +02:00
retrooper 9ecadae4f9 Fix NPE when sending packets to null channels. 2023-09-16 18:20:23 +02:00
retrooper 5939573ee3 Able to detect 1.20.1 servers 2023-06-14 23:24:25 +02:00
retrooper 1bbc2cba77 Minimal 1.20 update for v1.8 packetevents 2023-06-12 17:59:24 +02:00
retrooper 1c35fe3b92 Ignore modern spoof players 2023-04-23 23:03:17 +02:00
retrooper e6a7b7a3b1 Fix weird entity player classes 2023-04-07 22:40:54 +02:00
retrooper 3581e23923 Minimal 1.19.4 update 2023-04-02 17:25:52 +02:00
MWHunter 33c0d9d934 fix multiple exceptions with update checker and clean up code 2023-02-25 23:25:56 -06:00
retrooper 70eaec04c7 Merge pull request #514 from FlorianMichael/master
fixed ArrayIndexOutOfBoundsException
2023-01-02 19:13:36 +01:00
JesseUwU be7aca69ef fixed ArrayIndexOutOfBoundsException
make WrappedPacketOutPlayerInfo#getPlayerInfo playerInfoArray big enough
2023-01-01 22:37:13 +01:00
retrooper 6777809d1c Update WrappedPacketOutEntityMetadata for 1.19.3 2022-12-12 18:33:36 +01:00
retrooper 39ec3dc117 WrappedPacketOutPlayerInfo was removed in 1.19.3 2022-12-11 00:07:06 +01:00
retrooper d52a96722d Minimal 1.19.3 update 2022-12-10 23:42:13 +01:00
retrooper 7e76aaa2af trying to fix spoofmc errors once again... 2022-12-10 23:37:56 +01:00
retrooper 022c081527 Cache channels for logged in players. 2022-10-03 19:32:06 +02:00
retrooper 0b3f49cc53 Ignore fake connections. 2022-10-03 18:12:13 +02:00
AoElite 54a68013f8 fix chat exception (#476) 2022-09-07 23:45:36 +02:00
retrooper 3b947e7b9a 1.19.2 support is ready 2022-08-05 17:07:04 +02:00
retrooper 01b201cef9 Fix for injection desync on late injectors. 2022-08-04 18:33:12 +02:00
retrooper 8fdd8e5676 Preparing for 1.19.2 update. 2022-08-04 18:31:02 +02:00
retrooper 7fd4015b4f Added dependency 2022-08-02 17:33:00 +02:00
retrooper 4f2f355a98 Minor fix for WrappedPacketOutChat on 1.19+ when loading. 2022-08-02 17:28:31 +02:00
Julianandretrooper 62afe05c28 1.19.1 Update (PE 1.8) (#453)
* feat: add 1.19.1 version support to Client-/ & Server version

* feat: added 1.19.1 support to CLIENT_VERSIONS array

* feat: updated ChatPosition and added little TODO comment

* feat: added `getPlayerUUID` and `setPlayerUUID` to WrappedPacketLoginInStart (still needs SignatureData)

* Added minimal 1.19.1 support, only wrapper complete 1.19.1 support is PlayerInfo.

Won't add the newly 1.19.1 created wrappers as this version is slowly dying

Co-authored-by: retrooper <retrooperdev@gmail.com>
2022-08-02 06:12:34 +02:00
retrooper b910cd189f Merge remote-tracking branch 'origin/master' 2022-07-18 08:31:22 +02:00
retrooper 1692451244 Support multiple channel types now. (IO_URING fix for you guys) & Fix SpoofMC 2022-07-18 08:31:10 +02:00
retrooper 26fde1e9a3 Fix WrappedPacketOutEntityEffect for 1.19 2022-06-22 14:43:34 +02:00
retrooper 5e42bef488 Minor changes to Main class 2022-06-20 05:49:17 +02:00
retrooper f7aacf1ad6 WrappedPacketOutEntityEffect 1.19 support,
SystemChat relocated
2022-06-20 05:42:17 +02:00
retrooper 87aedb23fd WrappedPacketOutEntity 1.19 support 2022-06-20 05:23:31 +02:00
retrooper bf60cb0543 No debugs. 2022-06-18 20:38:51 +02:00
retrooper 367f561eb3 WrappedPacketOutSystemChat created along with its PacketType 2022-06-18 20:38:35 +02:00
retrooper bb9132a673 WrappedPacketOutChat now minimally supports 1.19 (atleast reading) 2022-06-18 20:10:16 +02:00
retrooper b843499ac6 WrappedPacketInChat now has the 1.19 features 2022-06-18 20:00:31 +02:00
retrooper 8809088b66 Since our game profiles don't support texture property reading we're going to make login success packet unsendable. (Which means packetevents plugins can't send it using our API, please update to 2.0 if you need this feature) 2022-06-18 19:50:47 +02:00
retrooper d5d4a9bffc Fixed WrappedPacketOutSetSlot for 1.17.1+
Fixed WrappedPacketLoginInEncryptionBegin for 1.19+
2022-06-18 19:44:00 +02:00
retrooper 14f3d26630 Minor progress 2022-06-16 22:00:46 +02:00
retrooper dacf44dc29 Merge remote-tracking branch 'origin/master' 2022-06-16 08:14:37 +02:00
retrooper b2d7219105 Working on 1.19 support but its not working? 2022-06-16 08:14:22 +02:00
retrooper 362bb8dbe7 Merge pull request #413 from Jaren8r/patch-1
Fix GPLv3 badge link
2022-05-30 13:54:09 +02:00
Jaren 59935293a6 Fix GPLv3 badge link
It was going to a blob on the dev branch, which no longer exists.
2022-05-30 07:52:42 -04:00
retrooper 1c0d932c48 Bump up version to 1.8.4;
Deprecated the "async" loading methods in PacketEvents.java
2022-04-27 19:25:59 +02:00
retrooper c43d992619 Removed debugs. 2022-04-27 19:22:32 +02:00
retrooper c2e0fe6b4c More changes to README 2022-04-17 22:49:08 +02:00
retrooper 14a783560c Removed currently deleted pages 2022-04-17 22:42:04 +02:00
retrooper 2767b99479 We now don't discard packets sent by bytebuf packet plugins (for example beta 2.0 version of packetevents) 2022-04-15 22:43:54 +02:00
retrooper 3d7a0d901f WrappedPacketOutBlockChange hopefully now supports 1.18.1+ 2022-03-31 23:05:25 +02:00
retrooper 177e9b7f4e Releasing 1.8.3 2022-03-24 20:07:23 +01:00
retrooper 4711ede9bc Merge remote-tracking branch 'origin/master' 2022-03-22 23:03:22 +01:00
retrooper 6bd531efc0 Fixed 1.7 injector noclassdefined errors. 2022-03-22 23:03:11 +01:00
retrooper d6f1bf972e Updated bug report template. 2022-03-22 21:00:14 +01:00
retrooper 3295b1fc89 Update feature_request.md 2022-03-10 23:28:36 +01:00
retrooper f620e45a9c Update feature_request.md 2022-03-10 23:27:10 +01:00
retrooper 825b61a24e Updated to 1.8.2 (Support latest ProtocolLib snapshots & supposed to support future 5.0.0 release of protocollib) 2022-03-08 19:23:30 +01:00
retrooper dc5d15ba85 We now support latest ProtocolLib snapshots. I'm sort of perplexed why this works, but seems like our initializer is wrapping itself somehow? Well it works 2022-03-08 19:20:14 +01:00
retrooper 0b458c2e4c Older versions of packetevents' update checker will break. We never followed version semantics till now. 2022-03-07 22:33:09 +01:00
retrooper bb9fe18a76 1.8.1 releasing. 2022-03-07 22:28:51 +01:00
retrooper 73420efbb7 Following semantic versioning. Release version: 1.8.0 2022-03-07 21:09:01 +01:00
retrooper c3bc1906b1 Merge remote-tracking branch 'origin/master' 2022-03-07 20:49:46 +01:00
retrooper 3c4a7323a0 Minor change to metrics. 2022-03-07 20:49:31 +01:00
retrooper 0a4fedff09 Finally releasing packetevents 1.8. 2022-03-07 20:42:41 +01:00
retrooper d1fb535ca7 WrappedPacketOutEntityEffect bug fix for 1.18.2 2022-03-05 17:43:43 +01:00
retrooper 5865e056d8 WrappedPacketOutEntity and WrappedPacketOutEntityHeadRotation now accept(support) floats for yaw and pitch, not that weird encoded byte angle.
NPC relative movement hopefully fixed.
2022-02-28 23:02:48 +01:00
retrooper eb561b98b2 Updated to 1.18.2. 2022-02-28 22:50:17 +01:00
retrooper 13b3ac7107 Bug fix in injecting players. 2022-02-04 19:22:58 +01:00
retrooper 1943ba2da1 Removed debug. 2022-02-04 15:22:03 +01:00
retrooper f90925e09b GeyserUtils fixed, now supports 2.0 Geyser API.
We now only inject into real socket channels.
2022-02-04 15:21:13 +01:00
retrooper e2ecb21892 Updated to Geyser 2.0 API 2022-02-02 21:33:39 +01:00
retrooper 80bc492370 Fixed broken ProtocolLib compatibility. 2022-01-31 21:30:14 +01:00
retrooper 691e8eb070 Little comment added 2022-01-21 22:48:58 +01:00
retrooper a83c3bac2a I know this isn't a perfect solution, but we want to process outgoing packets after ProtocolLib. So I went out of my way to for now only process the PLAY packets after them. We adjust our handler when protocollib is available.
PacketEventsSettings#compatInjector deprecated
2022-01-18 19:35:58 +01:00
retrooper 60a5357c34 PacketEvents v1.8 now sends the API Version to bStats. 2022-01-16 22:39:35 +01:00
retrooper af477f8479 Merge pull request #190 from retrooper/dev
1.18 support and more bug fixes merged to master branch
2022-01-06 12:40:29 +01:00
retrooper 6b82b38b59 Fixed javadocs and added plugin.yml to repository 2022-01-04 20:26:57 +01:00
retrooper 77918bb771 Minor change to a debug 2021-12-25 21:22:21 +01:00
retrooper c200b8fe35 1.8-pre-19 launching 2021-12-25 19:25:20 +01:00
DefineOutside 01cac8ded9 Merge pull request #177 from LIWKK/patch-30 2021-12-23 10:45:33 -06:00
Johannes d7a0d89d8e Fix WindowClick 1.9-1.16.5 2021-12-23 18:44:08 +02:00
retrooper 90ec7560b7 Merge remote-tracking branch 'origin/dev' into dev 2021-12-12 15:10:50 +01:00
retrooper eb96c5216b Fixed NMSUtils#getEffectId and NMSUtils#getMobEffectListById (Used in WrappedPacketOutRemoveEntityEffect) on 1.18 2021-12-12 15:10:34 +01:00
DefineOutside 176f2f7895 Merge remote-tracking branch 'origin/dev' into dev 2021-12-11 14:26:36 -06:00
DefineOutside 2489b7651b Fix 1.17.1+ support on set slot 2021-12-11 14:26:23 -06:00
retrooper 30981f8283 Merge remote-tracking branch 'origin/dev' into dev 2021-12-10 21:04:52 +01:00
retrooper 4537ac2d29 Added 1.18.1 support 2021-12-10 21:04:28 +01:00
retrooper 577d3476bb Merge pull request #171 from AlessioGr/master
Add Github actions to packetevents 1.8
2021-12-08 23:26:38 +01:00
DefineOutside 7adb2c2ecd Remove incorrect window click reflection to support 1.17 2021-12-07 16:33:23 -06:00
DefineOutside 1f02892284 1.17 support for the window click packet 2021-12-07 16:19:17 -06:00
DefineOutside 590e94ffc0 Add 1.17 support for the section position class 2021-12-06 17:16:20 -06:00
DefineOutside d5c2619bb3 Try fixing window items packet on 1.17.1 and 1.18 2021-12-06 17:15:05 -06:00
retrooper 935c9782a1 Fixed WrappedPacket#readGameMode and WrappedPacket#writeGameMode 2021-12-06 20:21:11 +01:00
retrooper 33b92f59d5 Small correction to WrappedPacket#writeAnyObject 2021-12-04 19:05:24 +01:00
MWHunter 6d7a06b93f Add support for SectionPosition in 1.18 2021-12-02 16:53:47 -06:00
MWHunter 0e42d7d14f Fix blockpos reflection on 1.18 2021-12-02 16:43:20 -06:00
Alessio Gravili 5cbdcc4158 JDK 8 2021-12-02 17:07:21 +01:00
Alessio Gravili db8f291475 Update gradle-publish.yml 2021-12-02 10:28:50 +01:00
Alessio Gravili 187084dca1 Update gradle-publish.yml 2021-12-02 10:26:52 +01:00
Alessio Gravili 316bc8070a Update gradle-publish.yml 2021-12-02 10:23:58 +01:00
Alessio Gravili 62685e9330 Create gradle-publish.yml 2021-12-02 10:22:58 +01:00
DefineOutside 169105af78 Update gradle-wrapper.properties 2021-12-01 10:44:51 -06:00
DefineOutside 398bb4b6db Update gradle-wrapper.properties 2021-12-01 10:43:56 -06:00
retrooper df56ea0aa6 Merge remote-tracking branch 'origin/dev' into dev 2021-12-01 17:25:32 +01:00
retrooper 95e73c775c Another minor bug fix in settings packet. 2021-12-01 17:25:23 +01:00
DefineOutside b8823ce00f Try fixing the map chunk packet for 1.18 2021-11-30 21:00:43 -06:00
DefineOutside 01658ce3c9 Add 1.18 support for WrappedPacketOutMapChunk 2021-11-30 18:29:57 -06:00
DefineOutside 934c181753 Support for reading 1.18 block positions 2021-11-30 17:11:20 -06:00
retrooper 0e3099e751 We should now work on 1.18 servers 2021-11-30 18:24:21 +01:00
retrooper 43ea7737ec Minor WrappedPacketInSettings change 2021-11-28 22:59:01 +01:00
retrooper 905dd43a0d Minor bug fix 2021-11-28 22:48:39 +01:00
retrooper 17f7c69b11 WrappedPacketInSettings updated to 1.18 2021-11-28 20:29:07 +01:00
retrooper 13965a4517 Added support for 1.18-rc3 2021-11-28 20:08:50 +01:00
retrooper 679d0ba037 One more minor change 2021-11-28 19:37:58 +01:00
retrooper 67e82e6d25 Merge remote-tracking branch 'origin/dev' 2021-11-28 19:32:55 +01:00
retrooper 9e58db6cb1 Minor optimizations by removing redundant/abandoned files;
ClientVersion and ServerVersion enums updated;
build.gradle optimized to remove unnecessary files;
2021-11-28 19:31:52 +01:00
retrooper e1fe2b9d99 Merge pull request #170 from byteful/unregister-listeners
Added methods to unregister PacketListenerAbstract(s).
2021-11-10 00:16:52 +01:00
byteful fd3b42ef6e Cleaned up the code a bit more. 2021-11-06 22:17:22 -05:00
byteful cf708adf55 Removed unnecessary code. 2021-11-06 22:03:36 -05:00
byteful 9f8a14b58a Added methods to unregister PacketListenerAbstract. 2021-11-06 21:39:55 -05:00
DefineOutside 1d31e06679 Merge pull request #169 from retrooper/MWHunter-patch-1
Try to fix build by updating geyser connector
2021-10-23 14:44:32 -05:00
DefineOutside a94e72ccd0 Revert to previous geyser api version 2021-10-23 14:37:34 -05:00
DefineOutside 35bd312ecf Try to fix build by updating geyser connector 2021-10-23 14:27:28 -05:00
DefineOutside 362d021745 Partially revert https://github.com/retrooper/packetevents/commit/5d1371c479c9811b87cc87a225063498654c96fe 2021-10-15 09:31:58 -05:00
DefineOutside 9d98af54e6 Data watcher takes NMS entity as argument, not bukkit entity 2021-10-13 20:30:07 -05:00
retrooper cb1438c86f Fixed WrappedPacketOutEntityVelocity#setVelocity 2021-10-10 18:23:45 +02:00
retrooper 75512add39 Fixed WrappedPacketOutWindowItems for 1.17.1 2021-10-09 20:40:43 +02:00
retrooper db1c913a3e Fixed WrappedPacketOutWindowItems for 1.17 2021-10-03 20:17:20 +02:00
DefineOutside 9c2609f4ee Vector3f should return Vector3f when cloned 2021-09-29 13:50:13 -05:00
DefineOutside 8336017bb9 Fix cloning vectors 2021-09-29 13:46:57 -05:00
retrooper 1ea4880ded Merge remote-tracking branch 'origin/dev' into dev 2021-09-26 15:52:26 +02:00
retrooper f54b8d7138 We now read the channel in network manager correctly 2021-09-26 15:52:19 +02:00
DefineOutside 52e7385864 Fix WrappedPacketOutSetCooldown 2021-09-24 22:20:09 -05:00
DefineOutside 5d1371c479 Optimize ServerVersion 2021-09-21 15:02:20 -05:00
DefineOutside 91916d0eaf Clean up WrappedPacketOutMapChunk 2021-09-20 16:44:53 -05:00
DefineOutside 73505209bc Use bitsets for WrappedPacketOutMapChunk 2021-09-20 16:35:49 -05:00
DefineOutside 934d5378e5 If a version lookup failed, try to resolve the client version again 2021-09-15 23:37:04 -05:00
retrooper 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
956 changed files with 24971 additions and 1893843 deletions

No files matched your search

+18 -46
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,51 +14,20 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v3
- 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: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Gradle
run: gradle :clean :build
- name: Build with Gradle
run: chmod +x gradlew && ./gradlew build
- name: Upload build artifacts api
uses: actions/upload-artifact@v3
with:
name: api-build
path: api/build/libs
- name: Upload build artifacts spigot
uses: actions/upload-artifact@v3
with:
name: spigot-build
path: spigot/build/libs
- name: Upload build artifacts netty-common
uses: actions/upload-artifact@v3
with:
name: netty-common-build
path: netty-common/build/libs
- name: Upload build artifacts bungeecord
uses: actions/upload-artifact@v3
with:
name: bungeecord-build
path: bungeecord/build/libs
- name: Upload build artifacts velocity
uses: actions/upload-artifact@v3
with:
name: velocity-build
path: velocity/build/libs
- name: Upload build artifacts fabric
uses: actions/upload-artifact@v3
with:
name: fabric-build
path: fabric/build/libs
- name: Upload build artifacts
uses: actions/upload-artifact@v1
with:
name: packetevents-dev-build.jar
path: build/libs
+86 -94
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,92 +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/
bin/
# 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/
.vscode/
.project
.settings/
.classpath
/build/
+11 -21
View File
@@ -1,33 +1,23 @@
# packetevents
[![](https://img.shields.io/badge/License-GPLv3-yellow.svg)](https://github.com/retrooper/packetevents/blob/2.0/LICENSE) [![](https://github.com/retrooper/packetevents/actions/workflows/build.yml/badge.svg)](https://github.com/retrooper/packetevents/actions) [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/prqzNg9tRU)
[![](https://img.shields.io/badge/License-GPLv3-yellow.svg)](https://github.com/retrooper/packetevents/blob/master/LICENSE)
[![](https://jitpack.io/v/retrooper/packetevents.svg)](https://jitpack.io/#retrooper/packetevents)
PacketEvents is a fast and efficient multi-platform packet processing library. Our packet wrappers are easy to use with multi-version support. With our API you can write code that runs on Spigot, BungeeCord, Velocity, and Fabric! Switch to PacketEvents today by joining \
our [Discord Server](https://discord.me/packetevents) for help.
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. We support many protocol versions. (1.8+)
### Links
* [Find release builds on Modrinth](https://modrinth.com/plugin/packetevents)
* [Find development builds on Jenkins](https://ci.codemc.io/job/retrooper/job/packetevents)
* [View documentation on our JavaDocs Page](https://packetevents.github.io/javadocs)
### Resources
* [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
* [JavaDoc](https://packetevents.github.io/javadocs)
* [Discord](https://discord.me/packetevents)
### Setup
[How to Setup PacketEvents](https://github.com/retrooper/packetevents/wiki/Depending-on-pre%E2%80%90built-PacketEvents)
### Examples / How to use PacketEvents
[Example repository](https://github.com/retrooper/packetevents-example)
[Learn more](https://github.com/retrooper/packetevents/wiki/1.-Setup)
### 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 these projects
[wiki.vg/Protocol](https://wiki.vg/Protocol)\
[netty](https://github.com/netty/netty)\
[gson](https://github.com/google/gson)\
[adventure](https://github.com/KyoriPowered/adventure)\
[ViaVersion](https://github.com/ViaVersion/ViaVersion)\
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)\
[MCProtocolLib](https://github.com/GeyserMC/MCProtocolLib/)
### 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.
-60
View File
@@ -1,60 +0,0 @@
import com.github.retrooper.MappingCompressionTask
// papermc repo + disableAutoTargetJvm needed for mockbukkit
repositories {
maven { url 'https://repo.papermc.io/repository/maven-public/' }
}
java {
disableAutoTargetJvm()
sourceSets {
main {
resources {
srcDirs += ["$buildDir.canonicalPath/mappings/generated"]
}
}
test {
resources {
srcDirs += ["$buildDir.canonicalPath/mappings/generated"]
}
}
}
}
dependencies {
compileOnly(adventureDependencies)
testImplementation(adventureDependencies)
testImplementation(project(":netty-common"))
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0")
testImplementation("org.slf4j:slf4j-simple:2.0.7")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}
test {
useJUnitPlatform()
}
task generateMapping(type: MappingCompressionTask) {
mappingsDir = rootDir.toPath().resolve("mappings")
outDir = project.buildDir.toPath().resolve("mappings/generated/assets/mappings")
outputs.upToDateWhen {
def gen_modified = project.buildDir.toPath().resolve("mappings/generated/assets/mappings").toFile().lastModified()
def list = []
project.rootProject.projectDir.toPath().resolve("mappings").toFile().eachFileRecurse(groovy.io.FileType.FILES) { file ->
list << file
}
for (File file : list) {
if (file.lastModified() > gen_modified) {
return false
}
}
return true
}
}
tasks.processResources.dependsOn(generateMapping)
@@ -1,38 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 org.jetbrains.annotations.ApiStatus;
public final class PacketEvents {
private static PacketEventsAPI<?> API;
//Put these variable names anywhere else, they are really only for the injectors
@ApiStatus.Internal
public static String IDENTIFIER, ENCODER_NAME, DECODER_NAME, CONNECTION_HANDLER_NAME, SERVER_CHANNEL_HANDLER_NAME,
TIMEOUT_HANDLER_NAME;
public static PacketEventsAPI<?> getAPI() {
return API;
}
public static void setAPI(PacketEventsAPI<?> api) {
API = api;
}
}
@@ -1,88 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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();
//TODO UPDATE
private static final PEVersion VERSION = new PEVersion(2, 3, 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,123 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.InvalidHandshakeException;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
public class EventManager {
private final Map<PacketListenerPriority, Set<PacketListenerCommon>> listenersMap =
Collections.synchronizedMap(new EnumMap<>(PacketListenerPriority.class));
/**
* 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 (PacketListenerPriority priority : PacketListenerPriority.values()) {
Set<PacketListenerCommon> listeners = listenersMap.get(priority);
if (listeners != null) {
for (PacketListenerCommon listener : listeners) {
try {
event.call(listener);
} catch (Exception t) {
// ignore handshake exceptions
if (t.getClass() != InvalidHandshakeException.class) {
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
}
}
if (postCallListenerAction != null) {
postCallListenerAction.run();
}
}
}
}
// For performance reasons, we don't want to re-encode the packet if it's not needed.
if (event instanceof ProtocolPacketEvent && !((ProtocolPacketEvent<?>) event).needsReEncode()) {
((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) {
Set<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority());
if (listenerSet == null) {
listenerSet = ConcurrentHashMap.newKeySet();
}
listenerSet.add(listener);
listenersMap.put(listener.getPriority(), 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) {
Set<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority());
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) 2022 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) 2022 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,59 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,77 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.PacketHandshakeSendEvent;
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;
import java.util.ArrayList;
import java.util.List;
public class PacketSendEvent extends ProtocolPacketEvent<Object> {
private List<Runnable> tasksAfterSend = null;
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);
}
public List<Runnable> getTasksAfterSend() {
if (tasksAfterSend == null) {
tasksAfterSend = new ArrayList<>();
}
return tasksAfterSend;
}
public boolean hasTasksAfterSend() {
return tasksAfterSend != null && !tasksAfterSend.isEmpty();
}
@Override
public PacketSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,234 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.InvalidDisconnectPacketSend;
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.buffer.UnpooledByteBufAllocationHelper;
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;
private boolean needsReEncode = PacketEvents.getAPI().getSettings().reEncodeByDefault();
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();
ConnectionState state = packetSide == PacketSide.CLIENT ? user.getDecoderState() : user.getEncoderState();
this.packetType = PacketType.getById(packetSide, state,
version, packetID);
if (this.packetType == null) {
// mojang messed up and keeps sending disconnect packets in the wrong protocol state
if (PacketType.getById(packetSide, ConnectionState.PLAY, version, packetID) == PacketType.Play.Server.DISCONNECT) {
throw new InvalidDisconnectPacketSend();
}
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getDecoderState() + ", Server version: " + serverVersion.getReleaseName());
}
this.connectionState = state;
}
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 = (packetType != null && packetType.getSide() == PacketSide.SERVER)
? user.getEncoderState() : user.getDecoderState();
cloned = true;
}
public void markForReEncode(boolean needsReEncode) {
this.needsReEncode = needsReEncode;
}
public boolean needsReEncode() {
return needsReEncode;
}
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;
}
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);
}
}
public Object getFullBufferClone() {
byte[] data = ByteBufHelper.copyBytes(getByteBuf());
Object buffer = UnpooledByteBufAllocationHelper.buffer();
ByteBufHelper.writeVarInt(buffer, getPacketId());
ByteBufHelper.writeBytes(buffer, data);
return buffer;
}
}
@@ -1,94 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 PacketConfigReceiveEvent) {
onPacketConfigReceive((PacketConfigReceiveEvent) 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 PacketConfigSendEvent) {
onPacketConfigSend((PacketConfigSendEvent) 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 onPacketConfigReceive(PacketConfigReceiveEvent event) {
}
public void onPacketConfigSend(PacketConfigSendEvent event) {
}
public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
}
public void onPacketPlaySend(PacketPlaySendEvent event) {
}
}
@@ -1,46 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.protocol.player.User;
public class UserLoginEvent extends PacketEvent implements CallableEvent, UserEvent, PlayerEvent<Object> {
private final User user;
private final Object player;
public UserLoginEvent(User user, Object player) {
this.user = user;
this.player = player;
}
@Override
public User getUser() {
return user;
}
@Override
public Object getPlayer() {
return player;
}
@Override
public void call(PacketListenerCommon listener) {
listener.onUserLogin(this);
}
}
@@ -1,59 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 PacketConfigReceiveEvent extends PacketReceiveEvent {
public PacketConfigReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketConfigReceiveEvent(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 PacketConfigReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketConfigReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Configuration.Client getPacketType() {
return (PacketType.Configuration.Client) super.getPacketType();
}
}
@@ -1,59 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 PacketConfigSendEvent extends PacketSendEvent {
public PacketConfigSendEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketConfigSendEvent(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 PacketConfigSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketConfigSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Configuration.Server getPacketType() {
return (PacketType.Configuration.Server) super.getPacketType();
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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,40 +0,0 @@
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 PacketHandshakeSendEvent extends PacketSendEvent {
public PacketHandshakeSendEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketHandshakeSendEvent(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 PacketHandshakeSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketHandshakeSendEvent(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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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,5 +0,0 @@
package com.github.retrooper.packetevents.exception;
public class CancelPacketException extends RuntimeException {
public static final CancelPacketException INSTANCE = new CancelPacketException();
}
@@ -1,4 +0,0 @@
package com.github.retrooper.packetevents.exception;
public class InvalidDisconnectPacketSend extends RuntimeException {
}
@@ -1,4 +0,0 @@
package com.github.retrooper.packetevents.exception;
public class InvalidHandshakeException extends RuntimeException {
}
@@ -1,188 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.NBTInt;
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
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.resources.ResourceLocation;
import com.github.retrooper.packetevents.wrapper.configuration.server.WrapperConfigServerRegistryData;
import com.github.retrooper.packetevents.wrapper.configuration.server.WrapperConfigServerRegistryData.RegistryElement;
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;
import java.util.List;
public class InternalPacketListener extends PacketListenerAbstract {
private static final ResourceLocation DIMENSION_TYPE_REGISTRY_KEY =
ResourceLocation.minecraft("dimension_type");
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());
//Texture properties are passed in login success on 1.19
user.getProfile().setTextureProperties(profile.getTextureProperties());
//Map username with channel
synchronized (channel) {
ProtocolManager.CHANNELS.put(profile.getUUID(), channel);
}
PacketEvents.getAPI().getLogManager().debug("Mapped player UUID with their channel.");
// Switch the user's connection state to new state, but the variable event.getConnectionState() remains LOGIN
// We switch user state immediately to remain in sync with vanilla, allowing you to encode packets immediately
boolean proxy = PacketEvents.getAPI().getInjector().isProxy();
if (proxy ? event.getUser().getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20_2)
: event.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20_2)) {
user.setEncoderState(ConnectionState.CONFIGURATION);
} else {
user.setConnectionState(ConnectionState.PLAY);
}
}
// The server sends dimension information in configuration phase >= 1.20.2
else if (event.getPacketType() == PacketType.Configuration.Server.REGISTRY_DATA) {
WrapperConfigServerRegistryData registryData = new WrapperConfigServerRegistryData(event);
// Store world data
NBTCompound registryDataTag = registryData.getRegistryData();
NBTList<NBTCompound> list = null;
if (registryDataTag != null) { // <1.20.5
list = registryDataTag
.getCompoundTagOrNull(DIMENSION_TYPE_REGISTRY_KEY.toString())
.getCompoundListTagOrNull("value");
} else if (DIMENSION_TYPE_REGISTRY_KEY.equals(registryData.getRegistryKey())) { // >=1.20.5
// remap to legacy format
list = new NBTList<>(NBTType.COMPOUND);
List<RegistryElement> elements = registryData.getElements();
if (elements != null) {
int i = 0;
for (RegistryElement element : elements) {
NBTCompound tag = new NBTCompound();
tag.setTag("name", new NBTString(element.getId().toString()));
tag.setTag("id", new NBTInt(i++));
if (element.getData() != null) { // may be null because of known packs not being sent
tag.setTag("element", element.getData());
}
list.addTag(tag);
}
}
}
if (list != null) {
user.setWorldNBT(list);
}
}
// The server sends dimension information in login packet for >= 1.17 and < 1.20.2
else if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
user.setEntityId(joinGame.getEntityId());
user.setDimension(joinGame.getDimension());
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
// Store world data
NBTCompound dimensionCodec = joinGame.getDimensionCodec();
if (dimensionCodec != null) {
NBTList<NBTCompound> list = dimensionCodec
.getCompoundTagOrNull(DIMENSION_TYPE_REGISTRY_KEY.toString())
.getCompoundListTagOrNull("value");
user.setWorldNBT(list);
}
// Update world height
user.switchDimensionType(joinGame.getServerVersion(), joinGame.getDimension());
}
// Respawn is used to switch dimensions
else if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
user.setDimension(respawn.getDimension());
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
user.switchDimensionType(respawn.getServerVersion(), respawn.getDimension());
} else if (event.getPacketType() == PacketType.Play.Server.CONFIGURATION_START) {
user.setEncoderState(ConnectionState.CONFIGURATION);
} else if (event.getPacketType() == PacketType.Configuration.Server.CONFIGURATION_END) {
user.setEncoderState(ConnectionState.PLAY);
}
}
@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 = new WrapperHandshakingClientHandshake(event);
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());
//Transition into LOGIN or STATUS connection state immediately, to remain in sync with vanilla
user.setConnectionState(nextState);
} else if (event.getPacketType() == PacketType.Login.Client.LOGIN_SUCCESS_ACK) {
user.setDecoderState(ConnectionState.CONFIGURATION);
} else if (event.getPacketType() == PacketType.Play.Client.CONFIGURATION_ACK) {
user.setDecoderState(ConnectionState.CONFIGURATION);
} else if (event.getPacketType() == PacketType.Configuration.Client.CONFIGURATION_END_ACK) {
user.setDecoderState(ConnectionState.PLAY);
}
}
}
@@ -1,87 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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);
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 sendPacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), wrapper);
}
default void sendPacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), byteBuf);
}
default void sendPacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), wrapper);
}
default void writePacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), byteBuf);
}
default void writePacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), wrapper);
}
default void writePacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), byteBuf);
}
default void writePacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), wrapper);
}
default void receivePacket(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), byteBuf);
}
default void receivePacket(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), wrapper);
}
default void receivePacketSilently(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), byteBuf);
}
default void receivePacketSilently(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), wrapper);
}
}
@@ -1,166 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.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.ApiStatus;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public interface ProtocolManager {
Map<UUID, Object> CHANNELS = new ConcurrentHashMap<>();
// Use SocketAddress because ProtocolLib wraps Channels with NettyChannelProxy class
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 byteBuf);
void sendPacketSilently(Object channel, Object byteBuf);
void writePacket(Object channel, Object byteBuf);
void writePacketSilently(Object channel, Object byteBuf);
void receivePacket(Object channel, Object byteBuf);
void receivePacketSilently(Object channel, Object byteBuf);
ClientVersion getClientVersion(Object channel);
//TODO Define method that accepts an array of channels/set/list of channels.
default void sendPackets(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
sendPacket(channel, buf);
}
}
default void sendPacketsSilently(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
sendPacketSilently(channel, buf);
}
}
default void writePackets(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
writePacket(channel, buf);
}
}
default void writePacketsSilently(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
writePacketSilently(channel, buf);
}
}
default void receivePackets(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
receivePacket(channel, buf);
}
}
default void receivePacketsSilently(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
receivePacketSilently(channel, buf);
}
}
default void setClientVersion(Object channel, ClientVersion version) {
getUser(channel).setClientVersion(version);
}
@ApiStatus.Internal
default Object[] transformWrappers(PacketWrapper<?> wrapper, Object channel, boolean outgoing) {
//It is possible that our packet transformer util decides to transform one wrapper into multiple packets.
//(Correcting some mistakes on your end)
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
Object[] buffers = new Object[wrappers.length];
for (int i = 0; i < wrappers.length; i++) {
wrappers[i].prepareForSend(channel, outgoing);
buffers[i] = wrappers[i].buffer;
// Fix race condition when sending packets to multiple people (due to when the buffer is freed)
wrappers[i].buffer = null;
}
return buffers;
}
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, true);
sendPackets(channel, transformed);
}
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, true);
sendPacketsSilently(channel, transformed);
}
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, true);
writePackets(channel, transformed);
}
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, true);
writePacketsSilently(channel, transformed);
}
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, false);
receivePackets(channel, transformed);
}
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, false);
receivePacketsSilently(channel, transformed);
}
default User getUser(Object channel) {
Object pipeline = ChannelHelper.getPipeline(channel);
return USERS.get(pipeline);
}
default User removeUser(Object channel) {
Object pipeline = ChannelHelper.getPipeline(channel);
return USERS.remove(pipeline);
}
default void setUser(Object channel, User user) {
synchronized (channel) {
Object pipeline = ChannelHelper.getPipeline(channel);
USERS.put(pipeline, user);
}
PacketEvents.getAPI().getInjector().updateUser(channel, user);
}
default Object getChannel(UUID uuid) {
return CHANNELS.get(uuid);
}
}
@@ -1,37 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.server;
public interface ServerManager {
/**
* Get the server version.
*
* @return Get Server Version
*/
ServerVersion getVersion();
/**
* Get the operating system of the local machine
*
* @return Get Operating System
*/
default SystemOS getOS() {
return SystemOS.getOS();
}
}
@@ -1,214 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.server;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import org.jetbrains.annotations.NotNull;
/**
* Server Version.
* This is a nice wrapper over minecraft's protocol versions.
* You won't have to memorize the protocol version, just memorize the server version you see in the launcher.
*
* @author retrooper
* @see <a href="https://wiki.vg/Protocol_version_numbers">https://wiki.vg/Protocol_version_numbers</a>
* @since 1.6.9
*/
public enum ServerVersion {
//TODO Rename to MinecraftVersion?
V_1_7_10(5),
V_1_8(47), V_1_8_3(47), V_1_8_8(47),
V_1_9(107), V_1_9_2(109), V_1_9_4(110),
//1.10 and 1.10.1 are redundant
V_1_10(210), V_1_10_1(210), V_1_10_2(210),
V_1_11(315), V_1_11_2(316),
V_1_12(335), V_1_12_1(338), V_1_12_2(340),
V_1_13(393), V_1_13_1(401), V_1_13_2(404),
V_1_14(477), V_1_14_1(480), V_1_14_2(485), V_1_14_3(490), V_1_14_4(498),
V_1_15(573), V_1_15_1(575), V_1_15_2(578),
V_1_16(735), V_1_16_1(736), V_1_16_2(751), V_1_16_3(753), V_1_16_4(754), V_1_16_5(754),
V_1_17(755), V_1_17_1(756),
V_1_18(757), V_1_18_1(757), V_1_18_2(758),
//1.19.1 and 1.19.2 have the same protocol version
V_1_19(759), V_1_19_1(760), V_1_19_2(760), V_1_19_3(761), V_1_19_4(762),
//1.20 and 1.20.1 have the same protocol version. 1.20.3 and 1.20.4 have the same protocol version. 1.20.5 and 1.20.6 have the same protocol version
V_1_20(763), V_1_20_1(763), V_1_20_2(764), V_1_20_3(765), V_1_20_4(765), V_1_20_5(766), V_1_20_6(766),
//TODO UPDATE Add server version constant
ERROR(-1, true);
private static final ServerVersion[] VALUES = values();
private static final ServerVersion[] REVERSED_VALUES;
static {
REVERSED_VALUES = values();
int i = 0;
int j = REVERSED_VALUES.length - 1;
ServerVersion tmp;
while (j > i) {
tmp = REVERSED_VALUES[j];
REVERSED_VALUES[j--] = REVERSED_VALUES[i];
REVERSED_VALUES[i++] = tmp;
}
}
private final int protocolVersion;
private final String name;
private ClientVersion toClientVersion;
ServerVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
this.name = name().substring(2).replace("_", ".");
}
ServerVersion(int protocolVersion, boolean isNotRelease) {
this.protocolVersion = protocolVersion;
if (isNotRelease) {
this.name = name();
} else {
this.name = name().substring(2).replace("_", ".");
}
}
public static ServerVersion[] reversedValues() {
return REVERSED_VALUES;
}
public static ServerVersion getLatest() {
return REVERSED_VALUES[1];
}
public static ServerVersion getOldest() {
return VALUES[0];
}
//TODO Optimize
@Deprecated
public static ServerVersion getById(int protocolVersion) {
for (ServerVersion version : VALUES) {
if (version.protocolVersion == protocolVersion) {
return version;
}
}
return null;
}
public ClientVersion toClientVersion() {
if (toClientVersion == null) {
toClientVersion = ClientVersion.getById(protocolVersion);
}
return toClientVersion;
}
/**
* Get the release name of this server version.
* For example, for the V_1_18 enum constant, it would return "1.18".
*
* @return Release name
*/
public String getReleaseName() {
return name;
}
/**
* Get this server version's protocol version.
*
* @return Protocol version.
*/
public int getProtocolVersion() {
return protocolVersion;
}
/**
* Is this server version newer than the compared server version?
* This method simply checks if this server version's protocol version is greater than
* the compared server version's protocol version.
*
* @param target Compared server version.
* @return Is this server version newer than the compared server version.
*/
public boolean isNewerThan(ServerVersion target) {
return this.ordinal() > target.ordinal();
}
/**
* Is this server version older than the compared server version?
* This method simply checks if this server version's protocol version is less than
* the compared server version's protocol version.
*
* @param target Compared server version.
* @return Is this server version older than the compared server version.
*/
public boolean isOlderThan(ServerVersion target) {
return this.ordinal() < target.ordinal();
}
/**
* Is this server version newer than or equal to the compared server version?
* This method simply checks if this server version's protocol version is greater than or equal to
* the compared server version's protocol version.
*
* @param target Compared server version.
* @return Is this server version newer than or equal to the compared server version.
*/
public boolean isNewerThanOrEquals(ServerVersion target) {
return this.ordinal() >= target.ordinal();
}
/**
* Is this server version older than or equal to the compared server version?
* This method simply checks if this server version's protocol version is older than or equal to
* the compared server version's protocol version.
*
* @param target Compared server version.
* @return Is this server version older than or equal to the compared server version.
*/
public boolean isOlderThanOrEquals(ServerVersion target) {
return this.ordinal() <= target.ordinal();
}
/**
* Is this server version newer than, older than or equal to the compared server version?
* This method simply checks if this server version's protocol version is greater than, less than or equal to
* the compared server version's protocol version.
*
* @param comparison Comparison type.
* @param targetVersion Compared server version.
* @return true or false, based on the comparison type.
* @see #isNewerThan(ServerVersion)
* @see #isNewerThanOrEquals(ServerVersion)
* @see #isOlderThan(ServerVersion)
* @see #isOlderThanOrEquals(ServerVersion)
*/
public boolean is(@NotNull VersionComparison comparison, @NotNull ServerVersion targetVersion) {
switch (comparison) {
case EQUALS:
return protocolVersion == targetVersion.protocolVersion;
case NEWER_THAN:
return isNewerThan(targetVersion);
case NEWER_THAN_OR_EQUALS:
return isNewerThanOrEquals(targetVersion);
case OLDER_THAN:
return isOlderThan(targetVersion);
case OLDER_THAN_OR_EQUALS:
return isOlderThanOrEquals(targetVersion);
default:
return false;
}
}
}
@@ -1,45 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.server;
/**
* This enum contains all possible comparison types for server versions.
*/
public enum VersionComparison {
/*
The server version equals the compared server version.
*/
EQUALS,
/*
The server version is newer than the compared server version.
*/
NEWER_THAN,
/*
The server version is newer than or equal to the compared server version.
*/
NEWER_THAN_OR_EQUALS,
/*
The server version is older than the compared server version.
*/
OLDER_THAN,
/*
The server version is older than or equal to the compared server version.
*/
OLDER_THAN_OR_EQUALS;
}
@@ -1,31 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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,265 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 capacity(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().capacity(buffer);
}
public static Object capacity(Object buffer, int capacity) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().capacity(buffer, capacity);
}
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,242 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.exception.PacketProcessException;
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 {
String text = DataInputStream.readUTF(this);
return text;
}
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()) {
int value = this.available();
String msg = "fieldSize is too long! Length is " + fieldSize + ", but maximum is " + value;
if (value == 0) {
throw new PacketProcessException(msg);
}
else {
throw new EOFException(msg);
}
}
}
}
@@ -1,116 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 capacity(Object buffer);
Object capacity(Object buffer, int capacity);
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) 2022 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) 2022 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,103 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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 getPipeline(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipeline(channel);
}
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 Object pooledByteBuf(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().pooledByteBuf(channel);
}
public static void runInEventLoop(Object channel, Runnable runnable) {
PacketEvents.getAPI().getNettyManager().getChannelOperator().runInEventLoop(channel, runnable);
}
}
@@ -1,60 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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;
public interface ChannelOperator {
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);
Object getPipeline(Object channel);
void runInEventLoop(Object channel, Runnable runnable);
Object pooledByteBuf(Object channel);
}
@@ -1,24 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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,25 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.attribute;
public enum AttributeOperation {
ADDITION,
MULTIPLY_BASE,
MULTIPLY_TOTAL,
}
@@ -1,106 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2023 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.attribute;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import org.jetbrains.annotations.ApiStatus;
import java.util.HashMap;
import java.util.Map;
public class Attributes {
private static final Map<String, Attribute> ATTRIBUTE_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, Attribute>> ATTRIBUTE_ID_MAP = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("attribute/attribute_mappings");
public static Attribute define(String key) {
TypesBuilderData data = TYPES_BUILDER.define(key);
Attribute attribute = new Attribute() {
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
return MappingHelper.getId(version, TYPES_BUILDER, data);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Attribute) {
return this.getName().equals(((Attribute) obj).getName());
}
return false;
}
};
MappingHelper.registerMapping(TYPES_BUILDER, ATTRIBUTE_MAP, ATTRIBUTE_ID_MAP, attribute);
return attribute;
}
// with minecraft:key
public static Attribute getByName(String name) {
return ATTRIBUTE_MAP.get(name);
}
public static Attribute getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, Attribute> idMap = ATTRIBUTE_ID_MAP.get((byte) index);
return idMap.get(id);
}
public static final Attribute GENERIC_ARMOR = define("generic.armor");
public static final Attribute GENERIC_ARMOR_TOUGHNESS = define("generic.armor_toughness");
public static final Attribute GENERIC_ATTACK_DAMAGE = define("generic.attack_damage");
public static final Attribute GENERIC_ATTACK_KNOCKBACK = define("generic.attack_knockback");
public static final Attribute GENERIC_ATTACK_SPEED = define("generic.attack_speed");
public static final Attribute GENERIC_FLYING_SPEED = define("generic.flying_speed");
public static final Attribute GENERIC_FOLLOW_RANGE = define("generic.follow_range");
@ApiStatus.Obsolete // renamed in 1.20.5
public static final Attribute HORSE_JUMP_STRENGTH = define("horse.jump_strength");
public static final Attribute GENERIC_KNOCKBACK_RESISTANCE = define("generic.knockback_resistance");
public static final Attribute GENERIC_LUCK = define("generic.luck");
public static final Attribute GENERIC_MAX_HEALTH = define("generic.max_health");
public static final Attribute GENERIC_MOVEMENT_SPEED = define("generic.movement_speed");
public static final Attribute ZOMBIE_SPAWN_REINFORCEMENTS = define("zombie.spawn_reinforcements");
// Added in 1.20.2
public static final Attribute GENERIC_MAX_ABSORPTION = define("generic.max_absorption");
// added in 1.20.5
public static final Attribute PLAYER_BLOCK_BREAK_SPEED = define("player.block_break_speed");
public static final Attribute PLAYER_BLOCK_INTERACTION_RANGE = define("player.block_interaction_range");
public static final Attribute PLAYER_ENTITY_INTERACTION_RANGE = define("player.entity_interaction_range");
public static final Attribute GENERIC_FALL_DAMAGE_MULTIPLIER = define("generic.fall_damage_multiplier");
public static final Attribute GENERIC_GRAVITY = define("generic.gravity");
public static final Attribute GENERIC_JUMP_STRENGTH = define("generic.jump_strength");
public static final Attribute GENERIC_SAFE_FALL_DISTANCE = define("generic.safe_fall_distance");
public static final Attribute GENERIC_SCALE = define("generic.scale");
public static final Attribute GENERIC_STEP_HEIGHT = define("generic.step_height");
static {
TYPES_BUILDER.unloadFileMappings();
}
}
@@ -1,13 +0,0 @@
package com.github.retrooper.packetevents.protocol.chat;
public enum ChatCompletionAction {
ADD,
REMOVE,
SET;
private static final ChatCompletionAction[] VALUES = values();
public static ChatCompletionAction fromId(int id) {
return VALUES[id];
}
}
@@ -1,84 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import java.util.HashMap;
import java.util.Map;
public class ChatTypes {
private static final Map<String, ChatType> CHAT_TYPE_MAP = new HashMap<>();
//Key - mappings version, value - map with chat type ids and chat types
private static final Map<Byte, Map<Integer, ChatType>> CHAT_TYPE_ID_MAP = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("chat/chat_type_mappings");
public static ChatType define(String key) {
TypesBuilderData data = TYPES_BUILDER.define(key);
ChatType chatType = new ChatType() {
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
return MappingHelper.getId(version, TYPES_BUILDER, data);
}
};
MappingHelper.registerMapping(TYPES_BUILDER, CHAT_TYPE_MAP, CHAT_TYPE_ID_MAP, chatType);
return chatType;
}
//with minecraft:key
public static ChatType getByName(String name) {
return CHAT_TYPE_MAP.get(name);
}
public static ChatType getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
return CHAT_TYPE_ID_MAP.get((byte) index).get(id);
}
public static final ChatType CHAT = define("chat");
public static final ChatType SAY_COMMAND = define("say_command");
public static final ChatType MSG_COMMAND_INCOMING = define("msg_command_incoming");
public static final ChatType MSG_COMMAND_OUTGOING = define("msg_command_outgoing");
public static final ChatType TEAM_MSG_COMMAND_INCOMING = define("team_msg_command_incoming");
public static final ChatType TEAM_MSG_COMMAND_OUTGOING = define("team_msg_command_outgoing");
public static final ChatType EMOTE_COMMAND = define("emote_command");
public static final ChatType RAW = define("raw");
@Deprecated
public static final ChatType SYSTEM = define("system");
@Deprecated
public static final ChatType GAME_INFO = define("game_info");
@Deprecated
public static final ChatType MSG_COMMAND = define("msg_command");
@Deprecated
public static final ChatType TEAM_MSG_COMMAND = define("team_msg_command");
static {
TYPES_BUILDER.unloadFileMappings();
}
}
@@ -1,105 +0,0 @@
package com.github.retrooper.packetevents.protocol.chat;
import org.jetbrains.annotations.Nullable;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.UUID;
public class LastSeenMessages {
public static final LastSeenMessages EMPTY = new LastSeenMessages(new ArrayList<>());
private final List<Entry> entries;
public LastSeenMessages(List<Entry> entries) {
this.entries = entries;
}
public void updateHash(DataOutput output) throws IOException {
for (Entry entry : this.entries) {
UUID uuid = entry.getUUID();
byte[] lastVerifier = entry.getLastVerifier();
output.writeByte(70);
output.writeLong(uuid.getMostSignificantBits());
output.writeLong(uuid.getLeastSignificantBits());
output.write(lastVerifier);
}
}
public List<Entry> getEntries() {
return entries;
}
public static class Packed {
private List<MessageSignature.Packed> packedMessageSignatures;
public Packed(List<MessageSignature.Packed> packedMessageSignatures) {
this.packedMessageSignatures = packedMessageSignatures;
}
public List<MessageSignature.Packed> getPackedMessageSignatures() {
return packedMessageSignatures;
}
public void setPackedMessageSignatures(List<MessageSignature.Packed> packedMessageSignatures) {
this.packedMessageSignatures = packedMessageSignatures;
}
}
public static class Entry {
private final UUID uuid;
private final byte[] signature;
public Entry(UUID uuid, byte[] lastVerifier) {
this.uuid = uuid;
this.signature = lastVerifier;
}
public UUID getUUID() {
return uuid;
}
public byte[] getLastVerifier() {
return signature;
}
}
public static class LegacyUpdate {
private final LastSeenMessages lastSeenMessages;
private final @Nullable Entry lastReceived;
public LegacyUpdate(LastSeenMessages lastSeenMessages, @Nullable Entry lastReceived) {
this.lastSeenMessages = lastSeenMessages;
this.lastReceived = lastReceived;
}
public LastSeenMessages getLastSeenMessages() {
return lastSeenMessages;
}
public @Nullable Entry getLastReceived() {
return lastReceived;
}
}
public static class Update {
private final int offset;
private final BitSet acknowledged;
public Update(int offset, BitSet acknowledged) {
this.offset = offset;
this.acknowledged = acknowledged;
}
public int getOffset() {
return offset;
}
public BitSet getAcknowledged() {
return acknowledged;
}
}
}
@@ -1,69 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class MessageSender {
private @NotNull UUID uuid;
private @Nullable Component displayName;
private @Nullable Component teamName;
public MessageSender(@NotNull UUID uuid, @Nullable Component displayName, @Nullable Component teamName) {
this.uuid = uuid;
this.displayName = displayName;
this.teamName = teamName;
}
public MessageSender(@Nullable Component displayName, @Nullable Component teamName) {
this(new UUID(0L, 0L), displayName, teamName);
}
public MessageSender() {
this(null, null);
}
public UUID getUUID() {
return uuid;
}
public void setUUID(@NotNull UUID uuid) {
this.uuid = uuid;
}
public @Nullable Component getDisplayName() {
return displayName;
}
public void setDisplayName(@Nullable Component displayName) {
this.displayName = displayName;
}
public @Nullable Component getTeamName() {
return teamName;
}
public void setTeamName(@Nullable Component teamName) {
this.teamName = teamName;
}
}
@@ -1,70 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2023 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.chat;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public class MessageSignature {
private byte[] bytes;
public MessageSignature(byte[] bytes) {
this.bytes = bytes;
}
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public static class Packed {
private int id;
private @Nullable MessageSignature fullSignature;
public Packed(@Nullable MessageSignature fullSignature) {
this.id = -1;
this.fullSignature = fullSignature;
}
public Packed(int id) {
this.id = id;
this.fullSignature = null;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Optional<MessageSignature> getFullSignature() {
return Optional.ofNullable(fullSignature);
}
public void setFullSignature(@Nullable MessageSignature fullSignature) {
this.fullSignature = fullSignature;
}
}
}
@@ -1,102 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class Node {
private byte flags;
private List<Integer> children;
private int redirectNodeIndex;
private Optional<String> name;
private Optional<Integer> parserID;
private Optional<List<Object>> properties;
private Optional<ResourceLocation> suggestionsType;
public Node(byte flags, List<Integer> children, int redirectNodeIndex, @Nullable String name, @Nullable Integer parserID, @Nullable List<Object> properties, @Nullable ResourceLocation suggestionsType) {
this.flags = flags;
this.children = children;
this.redirectNodeIndex = redirectNodeIndex;
this.name = Optional.ofNullable(name);
this.parserID = Optional.ofNullable(parserID);
this.properties = Optional.ofNullable(properties);
this.suggestionsType = Optional.ofNullable(suggestionsType);
}
public byte getFlags() {
return flags;
}
public void setFlags(byte flags) {
this.flags = flags;
}
public List<Integer> getChildren() {
return children;
}
public void setChildren(List<Integer> children) {
this.children = children;
}
public int getRedirectNodeIndex() {
return redirectNodeIndex;
}
public void setRedirectNodeIndex(int redirectNodeIndex) {
this.redirectNodeIndex = redirectNodeIndex;
}
public Optional<String> getName() {
return name;
}
public void setName(Optional<String> name) {
this.name = name;
}
public Optional<Integer> getParserID() {
return parserID;
}
public void setParserID(Optional<Integer> parserID) {
this.parserID = parserID;
}
public Optional<List<Object>> getProperties() {
return properties;
}
public void setProperties(Optional<List<Object>> properties) {
this.properties = properties;
}
public Optional<ResourceLocation> getSuggestionsType() {
return suggestionsType;
}
public void setSuggestionsType(Optional<ResourceLocation> suggestionsType) {
this.suggestionsType = suggestionsType;
}
}
@@ -1,275 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.chat;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class Parsers {
private static final List<Parser> ALL_PARSERS = new ArrayList<>(); // support for old methods
private static final Map<String, Parser> PARSER_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, Parser>> PARSER_ID_MAP = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("command/argument_parser_mappings");
public static Parser define(String key) {
return define(key, null, null);
}
public static Parser define(String key, @Nullable Reader reader, @Nullable Writer writer) {
TypesBuilderData data = TYPES_BUILDER.define(key);
Parser parser = new Parser(data, reader, writer);
ALL_PARSERS.add(parser);
MappingHelper.registerMapping(TYPES_BUILDER, PARSER_MAP, PARSER_ID_MAP, parser);
return parser;
}
// with key
public static Parser getByName(String name) {
return PARSER_MAP.get(name);
}
public static Parser getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, Parser> idMap = PARSER_ID_MAP.get((byte) index);
return idMap.get(id);
}
public static List<Parser> getParsers() {
return Collections.unmodifiableList(ALL_PARSERS);
}
public static final Parser BRIGADIER_BOOL = define("brigadier:bool", null, null);
public static final Parser BRIGADIER_FLOAT = define("brigadier:float",
packetWrapper -> {
byte flags = packetWrapper.readByte();
float min = (flags & 0x01) != 0 ? packetWrapper.readFloat() : -Float.MAX_VALUE;
float max = (flags & 0x02) != 0 ? packetWrapper.readFloat() : Float.MAX_VALUE;
return Arrays.asList(flags, min, max);
},
(packetWrapper, properties) -> {
byte flags = (byte) properties.get(0);
packetWrapper.writeByte(flags);
if ((flags & 0x01) != 0) packetWrapper.writeFloat((float) properties.get(1));
if ((flags & 0x02) != 0) packetWrapper.writeFloat((float) properties.get(2));
}
);
public static final Parser BRIGADIER_DOUBLE = define("brigadier:double",
packetWrapper -> {
byte flags = packetWrapper.readByte();
double min = (flags & 0x01) != 0 ? packetWrapper.readDouble() : -Double.MAX_VALUE;
double max = (flags & 0x02) != 0 ? packetWrapper.readDouble() : Double.MAX_VALUE;
return Arrays.asList(flags, min, max);
},
(packetWrapper, properties) -> {
byte flags = (byte) properties.get(0);
packetWrapper.writeByte(flags);
if ((flags & 0x01) != 0) packetWrapper.writeDouble((double) properties.get(1));
if ((flags & 0x02) != 0) packetWrapper.writeDouble((double) properties.get(2));
}
);
public static final Parser BRIGADIER_INTEGER = define("brigadier:integer",
packetWrapper -> {
byte flags = packetWrapper.readByte();
int min = (flags & 0x01) != 0 ? packetWrapper.readInt() : Integer.MIN_VALUE;
int max = (flags & 0x02) != 0 ? packetWrapper.readInt() : Integer.MAX_VALUE;
return Arrays.asList(flags, min, max);
},
(packetWrapper, properties) -> {
byte flags = (byte) properties.get(0);
packetWrapper.writeByte(flags);
if ((flags & 0x01) != 0) packetWrapper.writeInt((int) properties.get(1));
if ((flags & 0x02) != 0) packetWrapper.writeInt((int) properties.get(2));
}
);
public static final Parser BRIGADIER_LONG = define("brigadier:long",
packetWrapper -> {
byte flags = packetWrapper.readByte();
long min = (flags & 0x01) != 0 ? packetWrapper.readLong() : Long.MIN_VALUE;
long max = (flags & 0x02) != 0 ? packetWrapper.readLong() : Long.MAX_VALUE;
return Arrays.asList(flags, min, max);
},
(packetWrapper, properties) -> {
byte flags = (byte) properties.get(0);
packetWrapper.writeByte(flags);
if ((flags & 0x01) != 0) packetWrapper.writeLong((long) properties.get(1));
if ((flags & 0x02) != 0) packetWrapper.writeLong((long) properties.get(2));
}
);
public static final Parser BRIGADIER_STRING = define("brigadier:string",
packetWrapper -> Collections.singletonList(packetWrapper.readVarInt()),
(packetWrapper, properties) -> packetWrapper.writeVarInt((Integer) properties.get(0))
);
public static final Parser ENTITY = define("entity",
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
);
public static final Parser GAME_PROFILE = define("game_profile", null, null);
public static final Parser BLOCK_POS = define("block_pos", null, null);
public static final Parser COLUMN_POS = define("column_pos", null, null);
public static final Parser VEC3 = define("vec3", null, null);
public static final Parser VEC2 = define("vec2", null, null);
public static final Parser BLOCK_STATE = define("block_state", null, null);
public static final Parser BLOCK_PREDICATE = define("block_predicate", null, null);
public static final Parser ITEM_STACK = define("item_stack", null, null);
public static final Parser ITEM_PREDICATE = define("item_predicate", null, null);
public static final Parser COLOR = define("color", null, null);
public static final Parser COMPONENT = define("component", null, null);
public static final Parser STYLE = define("style", null, null);
public static final Parser MESSAGE = define("message", null, null);
public static final Parser NBT = define("nbt", null, null);
public static final Parser NBT_TAG = define("nbt_tag", null, null);
public static final Parser NBT_PATH = define("nbt_path", null, null);
public static final Parser OBJECTIVE = define("objective", null, null);
public static final Parser OBJECTIVE_CRITERIA = define("objective_criteria", null, null);
public static final Parser OPERATION = define("operation", null, null);
public static final Parser PARTICLE = define("particle", null, null);
public static final Parser ANGLE = define("angle", null, null);
public static final Parser ROTATION = define("rotation", null, null);
public static final Parser SCOREBOARD_SLOT = define("scoreboard_slot", null, null);
public static final Parser SCORE_HOLDER = define("score_holder",
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
);
public static final Parser SWIZZLE = define("swizzle", null, null);
public static final Parser TEAM = define("team", null, null);
public static final Parser ITEM_SLOT = define("item_slot", null, null);
public static final Parser ITEM_SLOTS = define("item_slots", null, null);
public static final Parser RESOURCE_LOCATION = define("resource_location", null, null);
public static final Parser FUNCTION = define("function", null, null);
public static final Parser ENTITY_ANCHOR = define("entity_anchor", null, null);
public static final Parser INT_RANGE = define("int_range", null, null);
public static final Parser FLOAT_RANGE = define("float_range", null, null);
public static final Parser DIMENSION = define("dimension", null, null);
public static final Parser GAMEMODE = define("gamemode", null, null);
public static final Parser TIME = define("time",
wrapper -> Collections.singletonList(wrapper.getServerVersion()
.isNewerThanOrEquals(ServerVersion.V_1_19_4) ? wrapper.readInt() : 0),
(wrapper, properties) -> {
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4)) {
wrapper.writeInt((int) properties.get(0));
}
}
);
public static final Parser RESOURCE_OR_TAG = define("resource_or_tag",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
);
public static final Parser RESOURCE_OR_TAG_KEY = define("resource_or_tag_key",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
);
public static final Parser RESOURCE = define("resource",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
);
public static final Parser RESOURCE_KEY = define("resource_key",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
);
public static final Parser TEMPLATE_MIRROR = define("template_mirror", null, null);
public static final Parser TEMPLATE_ROTATION = define("template_rotation", null, null);
public static final Parser HEIGHTMAP = define("heightmap", null, null);
public static final Parser LOOT_TABLE = define("loot_table", null, null);
public static final Parser LOOT_PREDICATE = define("loot_predicate", null, null);
public static final Parser LOOT_MODIFIER = define("loot_modifier", null, null);
public static final Parser UUID = define("uuid", null, null);
static {
TYPES_BUILDER.unloadFileMappings();
}
@FunctionalInterface
public interface Reader extends Function<PacketWrapper<?>, List<Object>> {}
@FunctionalInterface
public interface Writer extends BiConsumer<PacketWrapper<?>, List<Object>> {}
public static final class Parser implements MappedEntity {
private final TypesBuilderData data;
private final Reader reader;
private final Writer writer;
@Deprecated
public Parser(String name, @Nullable Function<PacketWrapper<?>, List<Object>> read, @Nullable BiConsumer<PacketWrapper<?>, List<Object>> write) {
this(
new TypesBuilderData(new ResourceLocation(name), new int[0]),
read == null ? null : read::apply,
write == null ? null : write::accept
);
}
private Parser(TypesBuilderData data, @Nullable Reader reader, Writer writer) {
this.data = data;
this.reader = reader;
this.writer = writer;
}
public Optional<List<Object>> readProperties(PacketWrapper<?> wrapper) {
if (this.reader != null) {
return Optional.of(this.reader.apply(wrapper));
}
return Optional.empty();
}
public void writeProperties(PacketWrapper<?> wrapper, List<Object> properties) {
if (this.writer != null) {
this.writer.accept(wrapper, properties);
}
}
@Override
public ResourceLocation getName() {
return this.data.getName();
}
@Override
public int getId(ClientVersion version) {
int index = TYPES_BUILDER.getDataIndex(version);
return this.data.getData()[index];
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Parser) {
return this.getName().equals(((Parser) obj).getName());
}
return false;
}
}
}
@@ -1,41 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat;
import com.github.retrooper.packetevents.protocol.player.PublicProfileKey;
import java.util.UUID;
public class RemoteChatSession {
private final UUID sessionId;
private final PublicProfileKey publicProfileKey;
public RemoteChatSession(UUID sessionId, PublicProfileKey publicProfileKey) {
this.sessionId = sessionId;
this.publicProfileKey = publicProfileKey;
}
public UUID getSessionId() {
return sessionId;
}
public PublicProfileKey getPublicProfileKey() {
return publicProfileKey;
}
}
@@ -1,27 +0,0 @@
package com.github.retrooper.packetevents.protocol.chat;
public class SignedCommandArgument {
private String argument;
private byte[] signature;
public SignedCommandArgument(String argument, byte[] signature) {
this.argument = argument;
this.signature = signature;
}
public String getArgument() {
return argument;
}
public void setArgument(String argument) {
this.argument = argument;
}
public byte[] getSignature() {
return signature;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
}
@@ -1,52 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.filter;
import java.util.BitSet;
public class FilterMask {
public static final FilterMask FULLY_FILTERED;
public static final FilterMask PASS_THROUGH;
static {
FULLY_FILTERED = new FilterMask(new BitSet(0), FilterMaskType.FULLY_FILTERED);
PASS_THROUGH = new FilterMask(new BitSet(0), FilterMaskType.PASS_THROUGH);
}
private final BitSet mask;
private final FilterMaskType type;
private FilterMask(BitSet mask, FilterMaskType type) {
this.type = type;
this.mask = mask;
}
public FilterMask(BitSet mask) {
this.type = FilterMaskType.PARTIALLY_FILTERED;
this.mask = mask;
}
public BitSet getMask() {
return mask;
}
public FilterMaskType getType() {
return type;
}
}
@@ -1,41 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import net.kyori.adventure.text.Component;
import java.util.UUID;
public class ChatMessage_v1_16 extends ChatMessage {
private UUID senderUUID;
public ChatMessage_v1_16(Component chatContent, ChatType type, UUID senderUUID) {
super(chatContent, type);
this.senderUUID = senderUUID;
}
public UUID getSenderUUID() {
return senderUUID;
}
public void setSenderUUID(UUID senderUUID) {
this.senderUUID = senderUUID;
}
}
@@ -1,95 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.UUID;
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
public class ChatMessage_v1_19 extends ChatMessage_v1_16 {
private @Nullable Component unsignedChatContent;
private Component senderDisplayName;
private @Nullable Component teamName;
private Instant timestamp;
private long salt;
private byte[] signature;
public ChatMessage_v1_19(Component chatContent, @Nullable Component unsignedChatContent, ChatType type,
UUID senderUUID, Component senderDisplayName, @Nullable Component teamName, Instant timestamp,
long salt, byte[] signature) {
super(chatContent, type, senderUUID);
this.unsignedChatContent = unsignedChatContent;
this.senderDisplayName = senderDisplayName;
this.teamName = teamName;
this.timestamp = timestamp;
this.salt = salt;
this.signature = signature;
}
public @Nullable Component getUnsignedChatContent() {
return unsignedChatContent;
}
public Component getSenderDisplayName() {
return senderDisplayName;
}
public @Nullable Component getTeamName() {
return teamName;
}
public Instant getTimestamp() {
return timestamp;
}
public long getSalt() {
return salt;
}
public byte[] getSignature() {
return signature;
}
public void setUnsignedChatContent(@Nullable Component unsignedChatContent) {
this.unsignedChatContent = unsignedChatContent;
}
public void setSenderDisplayName(Component senderDisplayName) {
this.senderDisplayName = senderDisplayName;
}
public void setTeamName(@Nullable Component teamName) {
this.teamName = teamName;
}
public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
public void setSalt(long salt) {
this.salt = salt;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
}
@@ -1,181 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.UUID;
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
public class ChatMessage_v1_19_1 extends ChatMessage_v1_16 {
private String plainContent;
private @Nullable Component unsignedChatContent;
private ChatTypeBoundNetwork chatType;
private byte @Nullable [] previousSignature;
private byte[] signature;
private Instant timestamp;
private long salt;
private LastSeenMessages lastSeenMessages;
private FilterMask filterMask;
public ChatMessage_v1_19_1(String plainContent, Component decoratedChatContent,
@Nullable Component unsignedChatContent,
UUID senderUUID, ChatTypeBoundNetwork chatType,
byte @Nullable [] previousSignature, byte[] signature,
Instant timestamp, long salt,
LastSeenMessages lastSeenMessages,
FilterMask filterMask) {
super(decoratedChatContent, chatType.getType(), senderUUID);
this.plainContent = plainContent;
this.unsignedChatContent = unsignedChatContent;
this.chatType = chatType;
this.previousSignature = previousSignature;
this.signature = signature;
this.timestamp = timestamp;
this.salt = salt;
this.lastSeenMessages = lastSeenMessages;
this.filterMask = filterMask;
}
public String getPlainContent() {
return plainContent;
}
public void setPlainContent(String plainContent) {
this.plainContent = plainContent;
}
public boolean isChatContentDecorated() {
return !getChatContent().equals(Component.text(plainContent));
}
public @Nullable Component getUnsignedChatContent() {
return unsignedChatContent;
}
public void setUnsignedChatContent(@Nullable Component unsignedChatContent) {
this.unsignedChatContent = unsignedChatContent;
}
@Override
public ChatType getType() {
return chatType.getType();
}
@Override
public void setType(ChatType type) {
chatType.setType(type);
}
public ChatTypeBoundNetwork getChatType() {
return chatType;
}
public void setChatType(ChatTypeBoundNetwork type) {
this.chatType = type;
}
public byte @Nullable [] getPreviousSignature() {
return previousSignature;
}
public void setPreviousSignature(byte @Nullable [] previousSignature) {
this.previousSignature = previousSignature;
}
public byte[] getSignature() {
return signature;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
public Instant getTimestamp() {
return timestamp;
}
public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
public long getSalt() {
return salt;
}
public void setSalt(long salt) {
this.salt = salt;
}
public LastSeenMessages getLastSeenMessages() {
return lastSeenMessages;
}
public void setLastSeenMessages(LastSeenMessages lastSeenMessages) {
this.lastSeenMessages = lastSeenMessages;
}
public FilterMask getFilterMask() {
return filterMask;
}
public void setFilterMask(FilterMask filterMask) {
this.filterMask = filterMask;
}
public static class ChatTypeBoundNetwork {
private ChatType type;
private Component name;
private @Nullable Component targetName;
public ChatTypeBoundNetwork(ChatType type, Component name, @Nullable Component targetName) {
this.type = type;
this.name = name;
this.targetName = targetName;
}
public ChatType getType() {
return type;
}
public void setType(ChatType type) {
this.type = type;
}
public Component getName() {
return name;
}
public void setName(Component name) {
this.name = name;
}
public @Nullable Component getTargetName() {
return targetName;
}
public void setTargetName(@Nullable Component targetName) {
this.targetName = targetName;
}
}
}
@@ -1,119 +0,0 @@
package com.github.retrooper.packetevents.protocol.chat.message;
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.Optional;
import java.util.UUID;
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
public class ChatMessage_v1_19_3 extends ChatMessage_v1_16 {
int index;
byte[] signature;
String plainContent;
Instant timestamp;
long salt;
LastSeenMessages.Packed lastSeenMessagesPacked;
@Nullable Component unsignedChatContent;
FilterMask filterMask;
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType;
public ChatMessage_v1_19_3(UUID senderUUID, int index, byte[] signature, String plainContent, Instant timestamp, long salt, LastSeenMessages.Packed lastSeenMessagesPacked, @Nullable Component unsignedChatContent, FilterMask filterMask, ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType) {
super(Component.text(plainContent), chatType.getType(), senderUUID);
this.index = index;
this.signature = signature;
this.plainContent = plainContent;
this.timestamp = timestamp;
this.salt = salt;
this.lastSeenMessagesPacked = lastSeenMessagesPacked;
this.unsignedChatContent = unsignedChatContent;
this.filterMask = filterMask;
this.chatType = chatType;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public byte[] getSignature() {
return signature;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
@Override
public Component getChatContent() {
return Component.text(plainContent);
}
@Deprecated
@Override
public void setChatContent(Component chatContent) {
throw new UnsupportedOperationException("PacketEvents is not able to serialize components to plain-text. Please use the #setPlainContent instead to update the content.");
}
public String getPlainContent() {
return plainContent;
}
public void setPlainContent(String plainContent) {
this.plainContent = plainContent;
}
public Instant getTimestamp() {
return timestamp;
}
public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
public long getSalt() {
return salt;
}
public void setSalt(long salt) {
this.salt = salt;
}
public LastSeenMessages.Packed getLastSeenMessagesPacked() {
return lastSeenMessagesPacked;
}
public void setLastSeenMessagesPacked(LastSeenMessages.Packed lastSeenMessagesPacked) {
this.lastSeenMessagesPacked = lastSeenMessagesPacked;
}
public Optional<Component> getUnsignedChatContent() {
return Optional.ofNullable(unsignedChatContent);
}
public void setUnsignedChatContent(@Nullable Component unsignedChatContent) {
this.unsignedChatContent = unsignedChatContent;
}
public FilterMask getFilterMask() {
return filterMask;
}
public void setFilterMask(FilterMask filterMask) {
this.filterMask = filterMask;
}
public ChatMessage_v1_19_1.ChatTypeBoundNetwork getChatType() {
return chatType;
}
public void setChatType(ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType) {
this.chatType = chatType;
}
}
@@ -1,29 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message.reader;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
public interface ChatMessageProcessor {
ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper);
void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data);
}
@@ -1,44 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message.reader.impl;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessageLegacy;
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
public class ChatMessageProcessorLegacy implements ChatMessageProcessor {
@Override
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
Component chatContent = wrapper.readComponent();
int id = wrapper.readByte();
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
return new ChatMessageLegacy(chatContent, type);
}
@Override
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
wrapper.writeComponent(data.getChatContent());
wrapper.writeByte(data.getType().getId(wrapper.getServerVersion().toClientVersion()));
}
}
@@ -1,48 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message.reader.impl;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_16;
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class ChatMessageProcessor_v1_16 implements ChatMessageProcessor {
@Override
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
Component chatContent = wrapper.readComponent();
int id = wrapper.readByte();
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
UUID senderUUID = wrapper.readUUID();
return new ChatMessage_v1_16(chatContent, type, senderUUID);
}
@Override
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
wrapper.writeComponent(data.getChatContent());
wrapper.writeByte(data.getType().getId(wrapper.getServerVersion().toClientVersion()));
wrapper.writeUUID(((ChatMessage_v1_16) data).getSenderUUID());
}
}
@@ -1,64 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message.reader.impl;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19;
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.UUID;
public class ChatMessageProcessor_v1_19 implements ChatMessageProcessor {
@Override
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
Component chatContent = wrapper.readComponent();
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
int id = wrapper.readVarInt();
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
UUID senderUUID = wrapper.readUUID();
Component senderDisplayName = wrapper.readComponent();
@Nullable Component teamName = wrapper.readOptional(PacketWrapper::readComponent);
Instant timestamp = wrapper.readTimestamp();
long salt = wrapper.readLong();
byte[] signature = wrapper.readByteArray();
return new ChatMessage_v1_19(chatContent, unsignedChatContent, type, senderUUID, senderDisplayName, teamName,
timestamp, salt, signature);
}
@Override
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
ChatMessage_v1_19 newData = (ChatMessage_v1_19) data;
wrapper.writeComponent(newData.getChatContent());
wrapper.writeOptional(newData.getUnsignedChatContent(), PacketWrapper::writeComponent);
wrapper.writeVarInt(newData.getType().getId(wrapper.getServerVersion().toClientVersion()));
wrapper.writeUUID(newData.getSenderUUID());
wrapper.writeComponent(newData.getSenderDisplayName());
wrapper.writeOptional(newData.getTeamName(), PacketWrapper::writeComponent);
wrapper.writeTimestamp(newData.getTimestamp());
wrapper.writeLong(newData.getSalt());
wrapper.writeByteArray(newData.getSignature());
}
}
@@ -1,73 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2022 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.chat.message.reader.impl;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
import java.util.UUID;
public class ChatMessageProcessor_v1_19_1 implements ChatMessageProcessor {
@Override
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
byte[] previousSignature = wrapper.readOptional(PacketWrapper::readByteArray);
UUID senderUUID = wrapper.readUUID();
byte[] signature = wrapper.readByteArray();
String plainContent = wrapper.readString(256);
Component chatContent = wrapper.readOptional(PacketWrapper::readComponent);
if (chatContent == null && plainContent.isEmpty()) {
chatContent = Component.empty();
} else if (chatContent == null) {
chatContent = Component.text(plainContent);
}
Instant timestamp = wrapper.readTimestamp();
long salt = wrapper.readLong();
LastSeenMessages lastSeenMessages = wrapper.readLastSeenMessages();
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
FilterMask filterMask = wrapper.readFilterMask();
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = wrapper.readChatTypeBoundNetwork();
return new ChatMessage_v1_19_1(plainContent, chatContent, unsignedChatContent, senderUUID, chatType,
previousSignature, signature, timestamp, salt, lastSeenMessages, filterMask);
}
@Override
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
ChatMessage_v1_19_1 newData = (ChatMessage_v1_19_1) data;
wrapper.writeOptional(newData.getPreviousSignature(), PacketWrapper::writeByteArray);
wrapper.writeUUID(newData.getSenderUUID());
wrapper.writeByteArray(newData.getSignature());
wrapper.writeString(newData.getPlainContent(), 256);
wrapper.writeOptional(newData.getChatContent(), PacketWrapper::writeComponent);
wrapper.writeTimestamp(newData.getTimestamp());
wrapper.writeLong(newData.getSalt());
wrapper.writeLastSeenMessages(newData.getLastSeenMessages());
wrapper.writeOptional(newData.getUnsignedChatContent(), PacketWrapper::writeComponent);
wrapper.writeFilterMask(newData.getFilterMask());
wrapper.writeChatTypeBoundNetwork(newData.getChatType());
}
}
@@ -1,47 +0,0 @@
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_3;
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
import java.util.UUID;
public class ChatMessageProcessor_v1_19_3 implements ChatMessageProcessor {
@Override
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
UUID senderUUID = wrapper.readUUID();
int index = wrapper.readVarInt();
byte[] signature = wrapper.readOptional((w) -> w.readBytes(256));
String plainContent = wrapper.readString(256);
Instant timestamp = wrapper.readTimestamp();
long salt = wrapper.readLong();
LastSeenMessages.Packed lastSeenMessagesPacked = wrapper.readLastSeenMessagesPacked();
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
FilterMask filterMask = wrapper.readFilterMask();
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = wrapper.readChatTypeBoundNetwork();
return new ChatMessage_v1_19_3(senderUUID, index, signature, plainContent, timestamp, salt, lastSeenMessagesPacked, unsignedChatContent, filterMask, chatType);
}
@Override
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
ChatMessage_v1_19_3 newData = (ChatMessage_v1_19_3) data;
wrapper.writeUUID(newData.getSenderUUID());
wrapper.writeVarInt(newData.getIndex());
wrapper.writeOptional(newData.getSignature(), PacketWrapper::writeBytes);
wrapper.writeString(newData.getPlainContent());
wrapper.writeTimestamp(newData.getTimestamp());
wrapper.writeLong(newData.getSalt());
wrapper.writeLastSeenMessagesPacked(newData.getLastSeenMessagesPacked());
wrapper.writeOptional(newData.getUnsignedChatContent().orElse(null), PacketWrapper::writeComponent);
wrapper.writeFilterMask(newData.getFilterMask());
wrapper.writeChatTypeBoundNetwork(newData.getChatType());
}
}
@@ -1,73 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.color;
import net.kyori.adventure.util.RGBLike;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
public final class Color implements RGBLike {
private static final int BIT_MASK = 0xFF;
private final int red, green, blue;
public Color(@Range(from = 0L, to = 255L) int red, @Range(from = 0L, to = 255L) int green, @Range(from = 0L, to = 255L) int blue) {
this.red = red;
this.green = green;
this.blue = blue;
}
public Color(int rgb) {
this((rgb >> 16) & BIT_MASK, (rgb >> 8) & BIT_MASK, rgb & BIT_MASK);
}
public @NotNull Color withRed(@Range(from = 0L, to = 255L) int red) {
return new Color(red, green, blue);
}
public @NotNull Color withGreen(@Range(from = 0L, to = 255L) int green) {
return new Color(red, green, blue);
}
public @NotNull Color withBlue(@Range(from = 0L, to = 255L) int blue) {
return new Color(red, green, blue);
}
public int asRGB() {
int rgb = red;
rgb = (rgb << 8) + green;
return (rgb << 8) + blue;
}
@Override
public @Range(from = 0L, to = 255L) int red() {
return red;
}
@Override
public @Range(from = 0L, to = 255L) int green() {
return green;
}
@Override
public @Range(from = 0L, to = 255L) int blue() {
return blue;
}
}
@@ -1,103 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.color;
import net.kyori.adventure.util.RGBLike;
import org.jetbrains.annotations.NotNull;
public enum DyeColor implements RGBLike {
WHITE(new Color(0xf9fffe), new Color(0xffffff), new Color(0xf0f0f0), 8),
ORANGE(new Color(0xf9801d), new Color(0xff681f), new Color(0xeb8844), 15),
MAGENTA(new Color(0xc74ebd), new Color(0xff00ff), new Color(0xc354cd), 16),
LIGHT_BLUE(new Color(0x3ab3da), new Color(0x9ac0cd), new Color(0x6689d3), 17),
YELLOW(new Color(0xfed83d), new Color(0xffff00), new Color(0xdecf2a), 18),
LIME(new Color(0x80c71f), new Color(0xbfff00), new Color(0x41cd34), 19),
PINK(new Color(0xf38baa), new Color(0xff69b4), new Color(0xd88198), 20),
GRAY(new Color(0x474f52), new Color(0x808080), new Color(0x434343), 21),
LIGHT_GRAY(new Color(0x9d9d97), new Color(0xd3d3d3), new Color(0xababab), 22),
CYAN(new Color(0x169c9c), new Color(0xffff), new Color(0x287697), 23),
PURPLE(new Color(0x8932b8), new Color(0xa020f0), new Color(0x7b2fbe), 24),
BLUE(new Color(0x3c44aa), new Color(0xff), new Color(0x253192), 25),
BROWN(new Color(0x835432), new Color(0x8b4513), new Color(0x51301a), 26),
GREEN(new Color(0x5e7c16), new Color(0xff00), new Color(0x3b511a), 27),
RED(new Color(0xb02e26), new Color(0xff0000), new Color(0xb3312c), 28),
BLACK(new Color(0x1d1d21), new Color(0x0), new Color(0x1e1b1b), 29);
private final Color textureDiffuseColor;
private final Color textColor;
private final Color fireworkColor;
private final int mapColorId;
DyeColor(@NotNull Color textureDiffuseColor, @NotNull Color textColor,
@NotNull Color fireworkColor, int mapColorId) {
this.textureDiffuseColor = textureDiffuseColor;
this.textColor = textColor;
this.fireworkColor = fireworkColor;
this.mapColorId = mapColorId;
}
public @NotNull Color color() {
return this.textureDiffuseColor;
}
public @NotNull Color textColor() {
return this.textColor;
}
public @NotNull Color fireworkColor() {
return this.fireworkColor;
}
@Override
public int red() {
return this.textureDiffuseColor.red();
}
@Override
public int green() {
return this.textureDiffuseColor.green();
}
@Override
public int blue() {
return this.textureDiffuseColor.blue();
}
public int mapColorId() {
return this.mapColorId;
}
}
@@ -1,91 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
public class ComponentPredicate implements Predicate<IComponentMap> {
private List<ComponentValue<?>> requiredComponents;
public ComponentPredicate(List<ComponentValue<?>> requiredComponents) {
this.requiredComponents = requiredComponents;
}
public static ComponentPredicate read(PacketWrapper<?> wrapper) {
List<ComponentValue<?>> components = wrapper.readList(ComponentValue::read);
return new ComponentPredicate(components);
}
public static void write(PacketWrapper<?> wrapper, ComponentPredicate predicate) {
wrapper.writeList(predicate.requiredComponents, ComponentValue::write);
}
public static ComponentPredicate emptyPredicate() {
return new ComponentPredicate(new ArrayList<>());
}
@SuppressWarnings("unchecked")
public static ComponentPredicate fromPatches(PatchableComponentMap components) {
Map<ComponentType<?>, Optional<?>> patches = components.getPatches();
List<ComponentValue<?>> values = new ArrayList<>(patches.size());
for (Map.Entry<ComponentType<?>, Optional<?>> patch : patches.entrySet()) {
if (patch.getValue().isPresent()) {
values.add(new ComponentValue<>(
(ComponentType<Object>) patch.getKey(),
patch.getValue().get()
));
}
}
return new ComponentPredicate(values);
}
public PatchableComponentMap asPatches(StaticComponentMap base) {
PatchableComponentMap patched = new PatchableComponentMap(base);
for (ComponentValue<?> component : this.requiredComponents) {
patched.set(component);
}
return patched;
}
@Override
public boolean test(IComponentMap components) {
for (ComponentValue<?> component : this.requiredComponents) {
Optional<?> value = components.getOptional(component.getType());
if (!value.isPresent() || !component.getValue().equals(value.get())) {
return false;
}
}
return true;
}
public List<ComponentValue<?>> getRequiredComponents() {
return this.requiredComponents;
}
public void setRequiredComponents(List<ComponentValue<?>> requiredComponents) {
this.requiredComponents = requiredComponents;
}
}
@@ -1,29 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
public interface ComponentType<T> extends MappedEntity {
T read(PacketWrapper<?> wrapper);
void write(PacketWrapper<?> wrapper, T content);
}
@@ -1,256 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import com.github.retrooper.packetevents.protocol.color.DyeColor;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ArmorTrim;
import com.github.retrooper.packetevents.protocol.component.builtin.item.BannerLayers;
import com.github.retrooper.packetevents.protocol.component.builtin.item.BundleContents;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ChargedProjectiles;
import com.github.retrooper.packetevents.protocol.component.builtin.item.DebugStickState;
import com.github.retrooper.packetevents.protocol.component.builtin.item.FireworkExplosion;
import com.github.retrooper.packetevents.protocol.component.builtin.item.FoodProperties;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAdventurePredicate;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAttributeModifiers;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemBees;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemBlockStateProperties;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemContainerContents;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemContainerLoot;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemDyeColor;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemFireworks;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemLock;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemLore;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemMapDecorations;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemMapPostProcessingState;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemPotionContents;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemProfile;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRarity;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRecipes;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemTool;
import com.github.retrooper.packetevents.protocol.component.builtin.item.LodestoneTracker;
import com.github.retrooper.packetevents.protocol.component.builtin.item.PotDecorations;
import com.github.retrooper.packetevents.protocol.component.builtin.item.SuspiciousStewEffects;
import com.github.retrooper.packetevents.protocol.component.builtin.item.WritableBookContent;
import com.github.retrooper.packetevents.protocol.component.builtin.item.WrittenBookContent;
import com.github.retrooper.packetevents.protocol.item.instrument.Instrument;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.Dummy;
import com.github.retrooper.packetevents.util.mappings.MappingHelper;
import com.github.retrooper.packetevents.util.mappings.TypesBuilder;
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class ComponentTypes {
private static final Map<String, ComponentType<?>> COMPONENT_TYPE_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, ComponentType<?>>> COMPONENT_TYPE_ID_MAP = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("item/item_component_mappings");
public static <T> ComponentType<T> define(String key) {
return define(key, null, null);
}
public static <T> ComponentType<T> define(String key, @Nullable Reader<T> reader, @Nullable Writer<T> writer) {
TypesBuilderData data = TYPES_BUILDER.define(key);
ComponentType<T> type = new ComponentType<T>() {
@Override
public T read(PacketWrapper<?> wrapper) {
return reader == null ? null : reader.apply(wrapper);
}
@Override
public void write(PacketWrapper<?> wrapper, T content) {
if (writer != null) {
writer.accept(wrapper, content);
}
}
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
return MappingHelper.getId(version, TYPES_BUILDER, data);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ComponentType<?>) {
return this.getName().equals(((ComponentType<?>) obj).getName());
}
return false;
}
@Override
public String toString() {
return "Component[" + this.getName() + "]";
}
};
MappingHelper.registerMapping(TYPES_BUILDER, COMPONENT_TYPE_MAP, COMPONENT_TYPE_ID_MAP, type);
return type;
}
// with key
public static ComponentType<?> getByName(String name) {
return COMPONENT_TYPE_MAP.get(name);
}
public static ComponentType<?> getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, ComponentType<?>> idMap = COMPONENT_TYPE_ID_MAP.get((byte) index);
return idMap.get(id);
}
// item component types
public static final ComponentType<NBTCompound> CUSTOM_DATA = define("custom_data",
PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final ComponentType<Integer> MAX_STACK_SIZE = define("max_stack_size",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<Integer> MAX_DAMAGE = define("max_damage",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<Integer> DAMAGE = define("damage",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<Boolean> UNBREAKABLE = define("unbreakable",
PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
public static final ComponentType<Component> CUSTOM_NAME = define("custom_name",
PacketWrapper::readComponent, PacketWrapper::writeComponent);
public static final ComponentType<Component> ITEM_NAME = define("item_name",
PacketWrapper::readComponent, PacketWrapper::writeComponent);
public static final ComponentType<ItemLore> LORE = define("lore",
ItemLore::read, ItemLore::write);
public static final ComponentType<ItemRarity> RARITY = define("rarity",
wrapper -> wrapper.readEnum(ItemRarity.values()), PacketWrapper::writeEnum);
public static final ComponentType<ItemEnchantments> ENCHANTMENTS = define("enchantments",
ItemEnchantments::read, ItemEnchantments::write);
public static final ComponentType<ItemAdventurePredicate> CAN_PLACE_ON = define("can_place_on",
ItemAdventurePredicate::read, ItemAdventurePredicate::write);
public static final ComponentType<ItemAdventurePredicate> CAN_BREAK = define("can_break",
ItemAdventurePredicate::read, ItemAdventurePredicate::write);
public static final ComponentType<ItemAttributeModifiers> ATTRIBUTE_MODIFIERS = define("attribute_modifiers",
ItemAttributeModifiers::read, ItemAttributeModifiers::write);
public static final ComponentType<Integer> CUSTOM_MODEL_DATA = define("custom_model_data",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<Dummy> HIDE_ADDITIONAL_TOOLTIP = define("hide_additional_tooltip",
Dummy::dummyRead, Dummy::dummyWrite);
public static final ComponentType<Dummy> HIDE_TOOLTIP = define("hide_tooltip",
Dummy::dummyRead, Dummy::dummyWrite);
public static final ComponentType<Integer> REPAIR_COST = define("repair_cost",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<Dummy> CREATIVE_SLOT_LOCK = define("creative_slot_lock",
Dummy::dummyRead, Dummy::dummyWrite);
public static final ComponentType<Boolean> ENCHANTMENT_GLINT_OVERRIDE = define("enchantment_glint_override",
PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
public static final ComponentType<Dummy> INTANGIBLE_PROJECTILE = define("intangible_projectile",
Dummy::dummyReadNbt, Dummy::dummyWriteNbt);
public static final ComponentType<FoodProperties> FOOD = define("food",
FoodProperties::read, FoodProperties::write);
public static final ComponentType<Dummy> FIRE_RESISTANT = define("fire_resistant",
Dummy::dummyRead, Dummy::dummyWrite);
public static final ComponentType<ItemTool> TOOL = define("tool",
ItemTool::read, ItemTool::write);
public static final ComponentType<ItemEnchantments> STORED_ENCHANTMENTS = define("stored_enchantments",
ItemEnchantments::read, ItemEnchantments::write);
public static final ComponentType<ItemDyeColor> DYED_COLOR = define("dyed_color",
ItemDyeColor::read, ItemDyeColor::write);
public static final ComponentType<Integer> MAP_COLOR = define("map_color",
PacketWrapper::readInt, PacketWrapper::writeInt);
public static final ComponentType<Integer> MAP_ID = define("map_id",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<ItemMapDecorations> MAP_DECORATIONS = define("map_decorations",
ItemMapDecorations::read, ItemMapDecorations::write);
public static final ComponentType<ItemMapPostProcessingState> MAP_POST_PROCESSING = define("map_post_processing",
wrapper -> wrapper.readEnum(ItemMapPostProcessingState.values()), PacketWrapper::writeEnum);
public static final ComponentType<ChargedProjectiles> CHARGED_PROJECTILES = define("charged_projectiles",
ChargedProjectiles::read, ChargedProjectiles::write);
public static final ComponentType<BundleContents> BUNDLE_CONTENTS = define("bundle_contents",
BundleContents::read, BundleContents::write);
public static final ComponentType<ItemPotionContents> POTION_CONTENTS = define("potion_contents",
ItemPotionContents::read, ItemPotionContents::write);
public static final ComponentType<SuspiciousStewEffects> SUSPICIOUS_STEW_EFFECTS = define("suspicious_stew_effects",
SuspiciousStewEffects::read, SuspiciousStewEffects::write);
public static final ComponentType<WritableBookContent> WRITABLE_BOOK_CONTENT = define("writable_book_content",
WritableBookContent::read, WritableBookContent::write);
public static final ComponentType<WrittenBookContent> WRITTEN_BOOK_CONTENT = define("written_book_content",
WrittenBookContent::read, WrittenBookContent::write);
public static final ComponentType<ArmorTrim> TRIM = define("trim",
ArmorTrim::read, ArmorTrim::write);
public static final ComponentType<DebugStickState> DEBUG_STICK_STATE = define("debug_stick_state",
DebugStickState::read, DebugStickState::write);
public static final ComponentType<NBTCompound> ENTITY_DATA = define("entity_data",
PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final ComponentType<NBTCompound> BUCKET_ENTITY_DATA = define("bucket_entity_data",
PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final ComponentType<NBTCompound> BLOCK_ENTITY_DATA = define("block_entity_data",
PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final ComponentType<Instrument> INSTRUMENT = define("instrument",
Instrument::read, Instrument::write);
public static final ComponentType<Integer> OMINOUS_BOTTLE_AMPLIFIER = define("ominous_bottle_amplifier",
PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final ComponentType<ItemRecipes> RECIPES = define("recipes",
ItemRecipes::read, ItemRecipes::write);
public static final ComponentType<LodestoneTracker> LODESTONE_TRACKER = define("lodestone_tracker",
LodestoneTracker::read, LodestoneTracker::write);
public static final ComponentType<FireworkExplosion> FIREWORK_EXPLOSION = define("firework_explosion",
FireworkExplosion::read, FireworkExplosion::write);
public static final ComponentType<ItemFireworks> FIREWORKS = define("fireworks",
ItemFireworks::read, ItemFireworks::write);
public static final ComponentType<ItemProfile> PROFILE = define("profile",
ItemProfile::read, ItemProfile::write);
public static final ComponentType<ResourceLocation> NOTE_BLOCK_SOUND = define("note_block_sound",
PacketWrapper::readIdentifier, PacketWrapper::writeIdentifier);
public static final ComponentType<BannerLayers> BANNER_PATTERNS = define("banner_patterns",
BannerLayers::read, BannerLayers::write);
public static final ComponentType<DyeColor> BASE_COLOR = define("base_color",
wrapper -> wrapper.readEnum(DyeColor.values()), PacketWrapper::writeEnum);
public static final ComponentType<PotDecorations> POT_DECORATIONS = define("pot_decorations",
PotDecorations::read, PotDecorations::write);
public static final ComponentType<ItemContainerContents> CONTAINER = define("container",
ItemContainerContents::read, ItemContainerContents::write);
public static final ComponentType<ItemBlockStateProperties> BLOCK_STATE = define("block_state",
ItemBlockStateProperties::read, ItemBlockStateProperties::write);
public static final ComponentType<ItemBees> BEES = define("bees",
ItemBees::read, ItemBees::write);
public static final ComponentType<ItemLock> LOCK = define("lock",
ItemLock::read, ItemLock::write);
public static final ComponentType<ItemContainerLoot> CONTAINER_LOOT = define("container_loot",
ItemContainerLoot::read, ItemContainerLoot::write);
static {
TYPES_BUILDER.unloadFileMappings();
}
@FunctionalInterface
public interface Reader<T> extends Function<PacketWrapper<?>, T> {}
@FunctionalInterface
public interface Writer<T> extends BiConsumer<PacketWrapper<?>, T> {}
}
@@ -1,76 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Objects;
public final class ComponentValue<T> {
private final ComponentType<T> type;
private final T value;
public ComponentValue(ComponentType<T> type, T value) {
this.type = type;
this.value = value;
}
public static ComponentValue<?> read(PacketWrapper<?> wrapper) {
ComponentType<?> type = wrapper.readMappedEntity(ComponentTypes::getById);
return read0(wrapper, type);
}
private static <T> ComponentValue<T> read0(PacketWrapper<?> wrapper, ComponentType<T> type) {
// additional method required here for proper handling because of how generics work
return new ComponentValue<>(type, type.read(wrapper));
}
public static <T> void write(PacketWrapper<?> wrapper, ComponentValue<T> value) {
wrapper.writeMappedEntity(value.type);
value.type.write(wrapper, value.value);
}
public ComponentType<T> getType() {
return this.type;
}
public T getValue() {
return this.value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ComponentValue)) return false;
ComponentValue<?> that = (ComponentValue<?>) obj;
if (!this.type.equals(that.type)) return false;
return this.value.equals(that.value);
}
@Override
public int hashCode() {
return Objects.hash(this.type, this.value);
}
@Override
public String toString() {
return "ComponentValue{type=" + this.type + ", value=" + this.value + '}';
}
}
@@ -1,58 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public interface IComponentMap {
default <T> Optional<T> getOptional(ComponentType<T> type) {
return Optional.ofNullable(this.get(type));
}
boolean has(ComponentType<?> type);
@Contract("_, !null -> !null")
default <T> @Nullable T getOr(ComponentType<T> type, @Nullable T otherValue) {
T value = this.get(type);
if (value != null) {
return value;
}
return otherValue;
}
<T> @Nullable T get(ComponentType<T> type);
default <T> void set(ComponentValue<T> component) {
this.set(component.getType(), component.getValue());
}
default <T> void set(ComponentType<T> type, @Nullable T value) {
this.set(type, Optional.ofNullable(value));
}
default <T> void unset(ComponentType<T> type) {
this.set(type, Optional.empty());
}
<T> void set(ComponentType<T> type, Optional<T> value);
}
@@ -1,103 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
public class PatchableComponentMap implements IComponentMap {
public static final PatchableComponentMap EMPTY = new PatchableComponentMap(
Collections.emptyMap(), Collections.emptyMap());
private final Map<ComponentType<?>, ?> base;
private final Map<ComponentType<?>, Optional<?>> patches;
public PatchableComponentMap(StaticComponentMap base) {
this(base.getDelegate(), new HashMap<>());
}
public PatchableComponentMap(Map<ComponentType<?>, ?> base) {
this(base, new HashMap<>());
}
public PatchableComponentMap(
StaticComponentMap base,
Map<ComponentType<?>, Optional<?>> patches
) {
this(base.getDelegate(), patches);
}
public PatchableComponentMap(
Map<ComponentType<?>, ?> base,
Map<ComponentType<?>, Optional<?>> patches
) {
this.base = Collections.unmodifiableMap(new HashMap<>(base));
this.patches = patches;
}
@SuppressWarnings("unchecked") // no
@Override
public <T> @Nullable T get(ComponentType<T> type) {
Optional<?> patched = this.patches.get(type);
if (patched != null) {
return (T) patched.orElse(null);
}
return (T) this.base.get(type);
}
@Override
public <T> void set(ComponentType<T> type, Optional<T> value) {
Object baseVal = this.base.get(type);
T newVal = value.orElse(null);
if (Objects.equals(baseVal, newVal)) {
this.patches.remove(type); // fallback to base
} else {
this.patches.put(type, value);
}
}
@Override
public boolean has(ComponentType<?> type) {
Optional<?> patched = this.patches.get(type);
return patched != null ? patched.isPresent() : this.base.containsKey(type);
}
public PatchableComponentMap copy() {
return new PatchableComponentMap(this.base, new HashMap<>(this.patches));
}
public Map<ComponentType<?>, ?> getBase() {
return this.base;
}
public Map<ComponentType<?>, Optional<?>> getPatches() {
return this.patches;
}
@Override
public String toString() {
return "PatchableComponentMap{base=" + this.base + ", patches=" + this.patches + '}';
}
}
@@ -1,121 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAttributeModifiers;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemLore;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRarity;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class StaticComponentMap implements IComponentMap {
public static final StaticComponentMap EMPTY = new StaticComponentMap(Collections.emptyMap());
public static final StaticComponentMap SHARED_ITEM_COMPONENTS = builder()
.set(ComponentTypes.MAX_STACK_SIZE, 64)
.set(ComponentTypes.LORE, ItemLore.EMPTY)
.set(ComponentTypes.ENCHANTMENTS, ItemEnchantments.EMPTY)
.set(ComponentTypes.REPAIR_COST, 0)
.set(ComponentTypes.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY)
.set(ComponentTypes.RARITY, ItemRarity.COMMON)
.build();
private final boolean empty;
private final Map<ComponentType<?>, ?> delegate;
public StaticComponentMap(Map<ComponentType<?>, ?> delegate) {
this.empty = delegate.isEmpty();
this.delegate = this.empty ? Collections.emptyMap()
: Collections.unmodifiableMap(new HashMap<>(delegate));
}
public static Builder builder() {
return new Builder();
}
@Override
public boolean has(ComponentType<?> type) {
return !this.empty && this.delegate.containsKey(type);
}
@SuppressWarnings("unchecked") // no
@Override
public <T> @Nullable T get(ComponentType<T> type) {
return this.empty ? null : (T) this.delegate.get(type);
}
@Override
public <T> void set(ComponentType<T> type, Optional<T> value) {
throw new UnsupportedOperationException();
}
public StaticComponentMap merge(StaticComponentMap prioritizedMap) {
return builder().setAll(this).setAll(prioritizedMap).build();
}
public Map<ComponentType<?>, ?> getDelegate() {
return this.delegate;
}
public boolean isEmpty() {
return this.empty;
}
public static class Builder {
private final Map<ComponentType<?>, Object> map = new HashMap<>();
public Builder() {
}
public StaticComponentMap build() {
return new StaticComponentMap(this.map);
}
public Builder setAll(StaticComponentMap map) {
return this.setAll(map.getDelegate());
}
@SuppressWarnings("unchecked")
public Builder setAll(Map<ComponentType<?>, ?> map) {
for (Map.Entry<ComponentType<?>, ?> entry : map.entrySet()) {
this.set((ComponentType<Object>) entry.getKey(), entry.getValue());
}
return this;
}
public <T> Builder set(ComponentType<T> type, Optional<T> value) {
return this.set(type, value.orElse(null));
}
public <T> Builder set(ComponentType<T> type, @Nullable T value) {
if (value == null) {
this.map.remove(type);
} else {
this.map.put(type, value);
}
return this;
}
}
}
@@ -1,90 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.item.trimmaterial.TrimMaterial;
import com.github.retrooper.packetevents.protocol.item.trimpattern.TrimPattern;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Objects;
public class ArmorTrim {
private TrimMaterial material;
private TrimPattern pattern;
private boolean showInTooltip;
public ArmorTrim(TrimMaterial material, TrimPattern pattern, boolean showInTooltip) {
this.material = material;
this.pattern = pattern;
this.showInTooltip = showInTooltip;
}
public static ArmorTrim read(PacketWrapper<?> wrapper) {
TrimMaterial material = TrimMaterial.read(wrapper);
TrimPattern pattern = TrimPattern.read(wrapper);
boolean showInTooltip = wrapper.readBoolean();
return new ArmorTrim(material, pattern, showInTooltip);
}
public static void write(PacketWrapper<?> wrapper, ArmorTrim trim) {
TrimMaterial.write(wrapper, trim.material);
TrimPattern.write(wrapper, trim.pattern);
wrapper.writeBoolean(trim.showInTooltip);
}
public TrimMaterial getMaterial() {
return this.material;
}
public void setMaterial(TrimMaterial material) {
this.material = material;
}
public TrimPattern getPattern() {
return this.pattern;
}
public void setPattern(TrimPattern pattern) {
this.pattern = pattern;
}
public boolean isShowInTooltip() {
return this.showInTooltip;
}
public void setShowInTooltip(boolean showInTooltip) {
this.showInTooltip = showInTooltip;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ArmorTrim)) return false;
ArmorTrim armorTrim = (ArmorTrim) obj;
if (this.showInTooltip != armorTrim.showInTooltip) return false;
if (!this.material.equals(armorTrim.material)) return false;
return this.pattern.equals(armorTrim.pattern);
}
@Override
public int hashCode() {
return Objects.hash(this.material, this.pattern, this.showInTooltip);
}
}
@@ -1,123 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.color.DyeColor;
import com.github.retrooper.packetevents.protocol.item.banner.BannerPattern;
import com.github.retrooper.packetevents.protocol.item.banner.BannerPatterns;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class BannerLayers {
private List<Layer> layers;
public BannerLayers(List<Layer> layers) {
this.layers = layers;
}
public static BannerLayers read(PacketWrapper<?> wrapper) {
List<Layer> layers = wrapper.readList(Layer::read);
return new BannerLayers(layers);
}
public static void write(PacketWrapper<?> wrapper, BannerLayers patterns) {
wrapper.writeList(patterns.layers, Layer::write);
}
public void addLayer(Layer layer) {
this.layers.add(layer);
}
public List<Layer> getLayers() {
return this.layers;
}
public void setLayers(List<Layer> layers) {
this.layers = layers;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BannerLayers)) return false;
BannerLayers that = (BannerLayers) obj;
return this.layers.equals(that.layers);
}
@Override
public int hashCode() {
return Objects.hashCode(this.layers);
}
public static class Layer {
private BannerPattern pattern;
private DyeColor color;
public Layer(BannerPattern pattern, DyeColor color) {
this.pattern = pattern;
this.color = color;
}
public static Layer read(PacketWrapper<?> wrapper) {
BannerPattern pattern = wrapper.readMappedEntityOrDirect(
BannerPatterns::getById, BannerPattern::readDirect);
DyeColor color = wrapper.readEnum(DyeColor.values());
return new Layer(pattern, color);
}
public static void write(PacketWrapper<?> wrapper, Layer layer) {
wrapper.writeMappedEntityOrDirect(layer.pattern, BannerPattern::writeDirect);
wrapper.writeEnum(layer.color);
}
public BannerPattern getPattern() {
return this.pattern;
}
public void setPattern(BannerPattern pattern) {
this.pattern = pattern;
}
public DyeColor getColor() {
return this.color;
}
public void setColor(DyeColor color) {
this.color = color;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Layer)) return false;
Layer layer = (Layer) obj;
if (!this.pattern.equals(layer.pattern)) return false;
return this.color == layer.color;
}
@Override
public int hashCode() {
return Objects.hash(this.pattern, this.color);
}
}
}
@@ -1,68 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class BundleContents {
private List<ItemStack> items;
public BundleContents(List<ItemStack> items) {
this.items = items;
}
public static BundleContents read(PacketWrapper<?> wrapper) {
List<ItemStack> items = wrapper.readList(PacketWrapper::readPresentItemStack);
return new BundleContents(items);
}
public static void write(PacketWrapper<?> wrapper, BundleContents projectiles) {
wrapper.writeList(projectiles.items, PacketWrapper::writePresentItemStack);
}
public void addItem(ItemStack itemStack) {
this.items.add(itemStack);
}
public List<ItemStack> getItems() {
return this.items;
}
public void setItems(List<ItemStack> items) {
this.items = items;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BundleContents)) return false;
BundleContents that = (BundleContents) obj;
return this.items.equals(that.items);
}
@Override
public int hashCode() {
return Objects.hashCode(this.items);
}
}
@@ -1,68 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class ChargedProjectiles {
private List<ItemStack> items;
public ChargedProjectiles(List<ItemStack> items) {
this.items = items;
}
public static ChargedProjectiles read(PacketWrapper<?> wrapper) {
List<ItemStack> items = wrapper.readList(PacketWrapper::readPresentItemStack);
return new ChargedProjectiles(items);
}
public static void write(PacketWrapper<?> wrapper, ChargedProjectiles projectiles) {
wrapper.writeList(projectiles.items, PacketWrapper::writePresentItemStack);
}
public void addItem(ItemStack itemStack) {
this.items.add(itemStack);
}
public List<ItemStack> getItems() {
return this.items;
}
public void setItems(List<ItemStack> items) {
this.items = items;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ChargedProjectiles)) return false;
ChargedProjectiles that = (ChargedProjectiles) obj;
return this.items.equals(that.items);
}
@Override
public int hashCode() {
return Objects.hashCode(this.items);
}
}
@@ -1,93 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.nbt.NBT;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class DebugStickState {
private Map<StateType, String> properties;
public DebugStickState(Map<StateType, String> properties) {
this.properties = properties;
}
public static DebugStickState read(PacketWrapper<?> wrapper) {
NBTCompound compound = wrapper.readNBT();
Map<StateType, String> properties = new HashMap<>(compound.size());
for (Map.Entry<String, NBT> tag : compound.getTags().entrySet()) {
StateType stateType = StateTypes.getByName(tag.getKey());
String property = ((NBTString) tag.getValue()).getValue();
properties.put(stateType, property);
}
return new DebugStickState(properties);
}
public static void write(PacketWrapper<?> wrapper, DebugStickState state) {
NBTCompound compound = new NBTCompound();
for (Map.Entry<StateType, String> property : state.properties.entrySet()) {
compound.setTag(property.getKey().getName(),
new NBTString(property.getValue()));
}
wrapper.writeNBT(compound);
}
public @Nullable String getProperty(StateType stateType) {
return this.properties.get(stateType);
}
public void setProperty(StateType stateType, @Nullable String property) {
if (property != null) {
this.properties.put(stateType, property);
} else {
this.properties.remove(stateType);
}
}
public Map<StateType, String> getProperties() {
return this.properties;
}
public void setProperties(Map<StateType, String> properties) {
this.properties = properties;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DebugStickState)) return false;
DebugStickState that = (DebugStickState) o;
return this.properties.equals(that.properties);
}
@Override
public int hashCode() {
return Objects.hashCode(this.properties);
}
}
@@ -1,134 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class FireworkExplosion {
private Shape shape;
private List<Integer> colors;
private List<Integer> fadeColors;
private boolean hasTrail;
private boolean hasTwinkle;
public FireworkExplosion(
Shape shape, List<Integer> colors, List<Integer> fadeColors,
boolean hasTrail, boolean hasTwinkle
) {
this.shape = shape;
this.colors = colors;
this.fadeColors = fadeColors;
this.hasTrail = hasTrail;
this.hasTwinkle = hasTwinkle;
}
public static FireworkExplosion read(PacketWrapper<?> wrapper) {
Shape shape = wrapper.readEnum(Shape.values());
List<Integer> colors = wrapper.readList(PacketWrapper::readInt);
List<Integer> fadeColors = wrapper.readList(PacketWrapper::readInt);
boolean hasTrail = wrapper.readBoolean();
boolean hasTwinkle = wrapper.readBoolean();
return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle);
}
public static void write(PacketWrapper<?> wrapper, FireworkExplosion explosion) {
wrapper.writeEnum(explosion.shape);
wrapper.writeList(explosion.colors, PacketWrapper::writeInt);
wrapper.writeList(explosion.fadeColors, PacketWrapper::writeInt);
wrapper.writeBoolean(explosion.hasTrail);
wrapper.writeBoolean(explosion.hasTwinkle);
}
public Shape getShape() {
return this.shape;
}
public void setShape(Shape shape) {
this.shape = shape;
}
public void addColor(int color) {
this.colors.add(color);
}
public List<Integer> getColors() {
return this.colors;
}
public void setColors(List<Integer> colors) {
this.colors = colors;
}
public void addFadeColor(int color) {
this.fadeColors.add(color);
}
public List<Integer> getFadeColors() {
return this.fadeColors;
}
public void setFadeColors(List<Integer> fadeColors) {
this.fadeColors = fadeColors;
}
public boolean isHasTrail() {
return this.hasTrail;
}
public void setHasTrail(boolean hasTrail) {
this.hasTrail = hasTrail;
}
public boolean isHasTwinkle() {
return this.hasTwinkle;
}
public void setHasTwinkle(boolean hasTwinkle) {
this.hasTwinkle = hasTwinkle;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof FireworkExplosion)) return false;
FireworkExplosion that = (FireworkExplosion) obj;
if (this.hasTrail != that.hasTrail) return false;
if (this.hasTwinkle != that.hasTwinkle) return false;
if (this.shape != that.shape) return false;
if (!this.colors.equals(that.colors)) return false;
return this.fadeColors.equals(that.fadeColors);
}
@Override
public int hashCode() {
return Objects.hash(this.shape, this.colors, this.fadeColors, this.hasTrail, this.hasTwinkle);
}
public enum Shape {
SMALL_BALL,
LARGE_BALL,
STAR,
CREEPER,
BURST,
}
}
@@ -1,174 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.potion.PotionEffect;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class FoodProperties {
private int nutrition;
private float saturation;
private boolean canAlwaysEat;
private float eatSeconds;
private List<PossibleEffect> effects;
public FoodProperties(int nutrition, float saturation, boolean canAlwaysEat, float eatSeconds, List<PossibleEffect> effects) {
this.nutrition = nutrition;
this.saturation = saturation;
this.canAlwaysEat = canAlwaysEat;
this.eatSeconds = eatSeconds;
this.effects = effects;
}
public static FoodProperties read(PacketWrapper<?> wrapper) {
int nutrition = wrapper.readVarInt();
float saturation = wrapper.readFloat();
boolean canAlwaysEat = wrapper.readBoolean();
float eatSeconds = wrapper.readFloat();
List<PossibleEffect> effects = wrapper.readList(PossibleEffect::read);
return new FoodProperties(nutrition, saturation, canAlwaysEat, eatSeconds, effects);
}
public static void write(PacketWrapper<?> wrapper, FoodProperties props) {
wrapper.writeVarInt(props.nutrition);
wrapper.writeFloat(props.saturation);
wrapper.writeBoolean(props.canAlwaysEat);
wrapper.writeFloat(props.eatSeconds);
wrapper.writeList(props.effects, PossibleEffect::write);
}
public int getNutrition() {
return this.nutrition;
}
public void setNutrition(int nutrition) {
this.nutrition = nutrition;
}
public float getSaturation() {
return this.saturation;
}
public void setSaturation(float saturation) {
this.saturation = saturation;
}
public boolean isCanAlwaysEat() {
return this.canAlwaysEat;
}
public void setCanAlwaysEat(boolean canAlwaysEat) {
this.canAlwaysEat = canAlwaysEat;
}
public float getEatSeconds() {
return this.eatSeconds;
}
public void setEatSeconds(float eatSeconds) {
this.eatSeconds = eatSeconds;
}
public void addEffect(PossibleEffect effect) {
this.effects.add(effect);
}
public List<PossibleEffect> getEffects() {
return this.effects;
}
public void setEffects(List<PossibleEffect> effects) {
this.effects = effects;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof FoodProperties)) return false;
FoodProperties that = (FoodProperties) obj;
if (this.nutrition != that.nutrition) return false;
if (Float.compare(that.saturation, this.saturation) != 0) return false;
if (this.canAlwaysEat != that.canAlwaysEat) return false;
if (Float.compare(that.eatSeconds, this.eatSeconds) != 0) return false;
return this.effects.equals(that.effects);
}
@Override
public int hashCode() {
return Objects.hash(this.nutrition, this.saturation, this.canAlwaysEat, this.eatSeconds, this.effects);
}
public static class PossibleEffect {
private PotionEffect effect;
private float probability;
public PossibleEffect(PotionEffect effect, float probability) {
this.effect = effect;
this.probability = probability;
}
public static PossibleEffect read(PacketWrapper<?> wrapper) {
PotionEffect effect = PotionEffect.read(wrapper);
float probability = wrapper.readFloat();
return new PossibleEffect(effect, probability);
}
public static void write(PacketWrapper<?> wrapper, PossibleEffect effect) {
PotionEffect.write(wrapper, effect.effect);
wrapper.writeFloat(effect.probability);
}
public PotionEffect getEffect() {
return this.effect;
}
public void setEffect(PotionEffect effect) {
this.effect = effect;
}
public float getProbability() {
return this.probability;
}
public void setProbability(float probability) {
this.probability = probability;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof PossibleEffect)) return false;
PossibleEffect that = (PossibleEffect) obj;
if (Float.compare(that.probability, this.probability) != 0) return false;
return this.effect.equals(that.effect);
}
@Override
public int hashCode() {
return Objects.hash(this.effect, this.probability);
}
}
}
@@ -1,329 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
// why do I have to implement this mess, I just want to deserialize items
public class ItemAdventurePredicate {
private List<BlockPredicate> predicates;
private boolean showInTooltip;
public ItemAdventurePredicate(List<BlockPredicate> predicates, boolean showInTooltip) {
this.predicates = predicates;
this.showInTooltip = showInTooltip;
}
public static ItemAdventurePredicate read(PacketWrapper<?> wrapper) {
List<BlockPredicate> predicates = wrapper.readList(BlockPredicate::read);
boolean showInTooltip = wrapper.readBoolean();
return new ItemAdventurePredicate(predicates, showInTooltip);
}
public static void write(PacketWrapper<?> wrapper, ItemAdventurePredicate predicate) {
wrapper.writeList(predicate.predicates, BlockPredicate::write);
wrapper.writeBoolean(predicate.showInTooltip);
}
public void addPredicate(BlockPredicate predicate) {
this.predicates.add(predicate);
}
public List<BlockPredicate> getPredicates() {
return this.predicates;
}
public void setPredicates(List<BlockPredicate> predicates) {
this.predicates = predicates;
}
public boolean isShowInTooltip() {
return this.showInTooltip;
}
public void setShowInTooltip(boolean showInTooltip) {
this.showInTooltip = showInTooltip;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemAdventurePredicate)) return false;
ItemAdventurePredicate that = (ItemAdventurePredicate) obj;
if (this.showInTooltip != that.showInTooltip) return false;
return this.predicates.equals(that.predicates);
}
@Override
public int hashCode() {
return Objects.hash(this.predicates, this.showInTooltip);
}
public static class BlockPredicate {
private @Nullable MappedEntitySet<StateType.Mapped> blocks;
private @Nullable List<PropertyMatcher> properties;
private @Nullable NBTCompound nbt;
public BlockPredicate(
@Nullable MappedEntitySet<StateType.Mapped> blocks,
@Nullable List<PropertyMatcher> properties,
@Nullable NBTCompound nbt
) {
this.blocks = blocks;
this.properties = properties;
this.nbt = nbt;
}
public static BlockPredicate read(PacketWrapper<?> wrapper) {
MappedEntitySet<StateType.Mapped> blocks = wrapper.readOptional(
ew -> MappedEntitySet.read(ew, StateTypes::getMappedById));
List<PropertyMatcher> properties = wrapper.readList(PropertyMatcher::read);
NBTCompound nbt = wrapper.readNBT();
return new BlockPredicate(blocks, properties, nbt);
}
public static void write(PacketWrapper<?> wrapper, BlockPredicate predicate) {
wrapper.writeOptional(predicate.blocks, MappedEntitySet::write);
wrapper.writeOptional(predicate.properties,
(ew, val) -> ew.writeList(val, PropertyMatcher::write));
wrapper.writeOptional(predicate.nbt, PacketWrapper::writeNBT);
}
public @Nullable MappedEntitySet<StateType.Mapped> getBlocks() {
return this.blocks;
}
public void setBlocks(@Nullable MappedEntitySet<StateType.Mapped> blocks) {
this.blocks = blocks;
}
public void addProperty(PropertyMatcher propertyMatcher) {
if (this.properties == null) {
this.properties = new ArrayList<>(4);
}
this.properties.add(propertyMatcher);
}
public @Nullable List<PropertyMatcher> getProperties() {
return this.properties;
}
public void setProperties(@Nullable List<PropertyMatcher> properties) {
this.properties = properties;
}
public @Nullable NBTCompound getNbt() {
return this.nbt;
}
public void setNbt(@Nullable NBTCompound nbt) {
this.nbt = nbt;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BlockPredicate)) return false;
BlockPredicate that = (BlockPredicate) obj;
if (!Objects.equals(this.blocks, that.blocks)) return false;
if (!Objects.equals(this.properties, that.properties)) return false;
return Objects.equals(this.nbt, that.nbt);
}
@Override
public int hashCode() {
return Objects.hash(this.blocks, this.properties, this.nbt);
}
}
public static class PropertyMatcher {
private String name;
private ValueMatcher matcher;
public PropertyMatcher(String name, ValueMatcher matcher) {
this.name = name;
this.matcher = matcher;
}
public static PropertyMatcher read(PacketWrapper<?> wrapper) {
String name = wrapper.readString();
ValueMatcher matcher = ValueMatcher.read(wrapper);
return new PropertyMatcher(name, matcher);
}
public static void write(PacketWrapper<?> wrapper, PropertyMatcher matcher) {
wrapper.writeString(matcher.name);
ValueMatcher.write(wrapper, matcher.matcher);
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public ValueMatcher getMatcher() {
return this.matcher;
}
public void setMatcher(ValueMatcher matcher) {
this.matcher = matcher;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof PropertyMatcher)) return false;
PropertyMatcher that = (PropertyMatcher) obj;
if (!this.name.equals(that.name)) return false;
return this.matcher.equals(that.matcher);
}
@Override
public int hashCode() {
return Objects.hash(this.name, this.matcher);
}
}
public interface ValueMatcher {
static ValueMatcher read(PacketWrapper<?> wrapper) {
if (wrapper.readBoolean()) {
return ExactValueMatcher.read(wrapper);
}
return RangedValueMatcher.read(wrapper);
}
static void write(PacketWrapper<?> wrapper, ValueMatcher matcher) {
if (matcher instanceof ExactValueMatcher) {
wrapper.writeBoolean(true);
ExactValueMatcher.write(wrapper, (ExactValueMatcher) matcher);
} else if (matcher instanceof RangedValueMatcher) {
wrapper.writeBoolean(false);
RangedValueMatcher.write(wrapper, (RangedValueMatcher) matcher);
} else {
throw new IllegalArgumentException("Illegal matcher implementation: " + matcher);
}
}
}
public static class ExactValueMatcher implements ValueMatcher {
private String value;
public ExactValueMatcher(String value) {
this.value = value;
}
public static ExactValueMatcher read(PacketWrapper<?> wrapper) {
return new ExactValueMatcher(wrapper.readString());
}
public static void write(PacketWrapper<?> wrapper, ExactValueMatcher matcher) {
wrapper.writeString(matcher.value);
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ExactValueMatcher)) return false;
ExactValueMatcher that = (ExactValueMatcher) obj;
return this.value.equals(that.value);
}
@Override
public int hashCode() {
return Objects.hashCode(this.value);
}
}
public static class RangedValueMatcher implements ValueMatcher {
private @Nullable String minValue;
private @Nullable String maxValue;
public RangedValueMatcher(@Nullable String minValue, @Nullable String maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
}
public static RangedValueMatcher read(PacketWrapper<?> wrapper) {
String minValue = wrapper.readOptional(PacketWrapper::readString);
String maxValue = wrapper.readOptional(PacketWrapper::readString);
return new RangedValueMatcher(minValue, maxValue);
}
public static void write(PacketWrapper<?> wrapper, RangedValueMatcher matcher) {
wrapper.writeOptional(matcher.minValue, PacketWrapper::writeString);
wrapper.writeOptional(matcher.maxValue, PacketWrapper::writeString);
}
public @Nullable String getMinValue() {
return this.minValue;
}
public void setMinValue(@Nullable String minValue) {
this.minValue = minValue;
}
public @Nullable String getMaxValue() {
return this.maxValue;
}
public void setMaxValue(@Nullable String maxValue) {
this.maxValue = maxValue;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof RangedValueMatcher)) return false;
RangedValueMatcher that = (RangedValueMatcher) obj;
if (!Objects.equals(this.minValue, that.minValue)) return false;
return Objects.equals(this.maxValue, that.maxValue);
}
@Override
public int hashCode() {
return Objects.hash(this.minValue, this.maxValue);
}
}
}
@@ -1,264 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.attribute.Attribute;
import com.github.retrooper.packetevents.protocol.attribute.AttributeOperation;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
public class ItemAttributeModifiers {
public static final ItemAttributeModifiers EMPTY = new ItemAttributeModifiers(
Collections.emptyList(), true) {
@Override
public void setShowInTooltip(boolean showInTooltip) {
throw new UnsupportedOperationException();
}
};
private List<ModifierEntry> modifiers;
private boolean showInTooltip;
public ItemAttributeModifiers(List<ModifierEntry> modifiers, boolean showInTooltip) {
this.modifiers = modifiers;
this.showInTooltip = showInTooltip;
}
public static ItemAttributeModifiers read(PacketWrapper<?> wrapper) {
List<ModifierEntry> modifiers = wrapper.readList(ModifierEntry::read);
boolean showInTooltip = wrapper.readBoolean();
return new ItemAttributeModifiers(modifiers, showInTooltip);
}
public static void write(PacketWrapper<?> wrapper, ItemAttributeModifiers modifiers) {
wrapper.writeList(modifiers.modifiers, ModifierEntry::write);
wrapper.writeBoolean(modifiers.showInTooltip);
}
public void addModifier(ModifierEntry modifier) {
this.modifiers.add(modifier);
}
public List<ModifierEntry> getModifiers() {
return this.modifiers;
}
public void setModifiers(List<ModifierEntry> modifiers) {
this.modifiers = modifiers;
}
public boolean isShowInTooltip() {
return this.showInTooltip;
}
public void setShowInTooltip(boolean showInTooltip) {
this.showInTooltip = showInTooltip;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemAttributeModifiers)) return false;
ItemAttributeModifiers that = (ItemAttributeModifiers) obj;
if (this.showInTooltip != that.showInTooltip) return false;
return this.modifiers.equals(that.modifiers);
}
@Override
public int hashCode() {
return Objects.hash(this.modifiers, this.showInTooltip);
}
@Override
public String toString() {
return "ItemAttributeModifiers{modifiers=" + this.modifiers + ", showInTooltip=" + this.showInTooltip + '}';
}
public static class ModifierEntry {
private Attribute attribute;
private Modifier modifier;
private EquipmentSlotGroup slotGroup;
public ModifierEntry(Attribute attribute, Modifier modifier, EquipmentSlotGroup slotGroup) {
this.attribute = attribute;
this.modifier = modifier;
this.slotGroup = slotGroup;
}
public static ModifierEntry read(PacketWrapper<?> wrapper) {
Attribute attribute = wrapper.readMappedEntity(Attributes::getById);
Modifier modifier = Modifier.read(wrapper);
EquipmentSlotGroup slot = wrapper.readEnum(EquipmentSlotGroup.values());
return new ModifierEntry(attribute, modifier, slot);
}
public static void write(PacketWrapper<?> wrapper, ModifierEntry entry) {
wrapper.writeMappedEntity(entry.attribute);
Modifier.write(wrapper, entry.modifier);
wrapper.writeEnum(entry.slotGroup);
}
public Attribute getAttribute() {
return this.attribute;
}
public void setAttribute(Attribute attribute) {
this.attribute = attribute;
}
public Modifier getModifier() {
return this.modifier;
}
public void setModifier(Modifier modifier) {
this.modifier = modifier;
}
public EquipmentSlotGroup getSlotGroup() {
return this.slotGroup;
}
public void setSlotGroup(EquipmentSlotGroup slotGroup) {
this.slotGroup = slotGroup;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ModifierEntry)) return false;
ModifierEntry that = (ModifierEntry) obj;
if (!this.attribute.equals(that.attribute)) return false;
if (!this.modifier.equals(that.modifier)) return false;
return this.slotGroup == that.slotGroup;
}
@Override
public int hashCode() {
return Objects.hash(this.attribute, this.modifier, this.slotGroup);
}
@Override
public String toString() {
return "ModifierEntry{attribute=" + this.attribute + ", modifier=" + this.modifier + ", slotGroup=" + this.slotGroup + '}';
}
}
public static class Modifier {
private UUID id;
private String name;
private double value;
private AttributeOperation operation;
public Modifier(UUID id, String name, double value, AttributeOperation operation) {
this.id = id;
this.name = name;
this.value = value;
this.operation = operation;
}
public static Modifier read(PacketWrapper<?> wrapper) {
UUID id = wrapper.readUUID();
String name = wrapper.readString();
double value = wrapper.readDouble();
AttributeOperation operation = wrapper.readEnum(AttributeOperation.values());
return new Modifier(id, name, value, operation);
}
public static void write(PacketWrapper<?> wrapper, Modifier modifier) {
wrapper.writeUUID(modifier.id);
wrapper.writeString(modifier.name);
wrapper.writeDouble(modifier.value);
wrapper.writeEnum(modifier.operation);
}
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public double getValue() {
return this.value;
}
public void setValue(double value) {
this.value = value;
}
public AttributeOperation getOperation() {
return this.operation;
}
public void setOperation(AttributeOperation operation) {
this.operation = operation;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Modifier)) return false;
Modifier modifier = (Modifier) obj;
if (Double.compare(modifier.value, this.value) != 0) return false;
if (!this.id.equals(modifier.id)) return false;
if (!this.name.equals(modifier.name)) return false;
return this.operation == modifier.operation;
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.name, this.value, this.operation);
}
@Override
public String toString() {
return "Modifier{id=" + this.id + ", name='" + this.name + '\'' + ", value=" + this.value + ", operation=" + this.operation + '}';
}
}
public enum EquipmentSlotGroup {
ANY,
MAINHAND,
OFFHAND,
HAND,
FEET,
LEGS,
CHEST,
HEAD,
ARMOR,
BODY,
}
}
@@ -1,133 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class ItemBees {
private List<BeeEntry> bees;
public ItemBees(List<BeeEntry> bees) {
this.bees = bees;
}
public static ItemBees read(PacketWrapper<?> wrapper) {
List<BeeEntry> bees = wrapper.readList(BeeEntry::read);
return new ItemBees(bees);
}
public static void write(PacketWrapper<?> wrapper, ItemBees bees) {
wrapper.writeList(bees.bees, BeeEntry::write);
}
public void addBee(BeeEntry bee) {
this.bees.add(bee);
}
public List<BeeEntry> getBees() {
return this.bees;
}
public void setBees(List<BeeEntry> bees) {
this.bees = bees;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemBees)) return false;
ItemBees itemBees = (ItemBees) obj;
return this.bees.equals(itemBees.bees);
}
@Override
public int hashCode() {
return Objects.hashCode(this.bees);
}
public static class BeeEntry {
private NBTCompound entityData;
private int ticksInHive;
private int minTicksInHive;
public BeeEntry(NBTCompound entityData, int ticksInHive, int minTicksInHive) {
this.entityData = entityData;
this.ticksInHive = ticksInHive;
this.minTicksInHive = minTicksInHive;
}
public static BeeEntry read(PacketWrapper<?> wrapper) {
NBTCompound entityData = wrapper.readNBT();
int ticksInHive = wrapper.readVarInt();
int minTicksInHive = wrapper.readVarInt();
return new BeeEntry(entityData, ticksInHive, minTicksInHive);
}
public static void write(PacketWrapper<?> wrapper, BeeEntry bee) {
wrapper.writeNBT(bee.entityData);
wrapper.writeVarInt(bee.ticksInHive);
wrapper.writeVarInt(bee.minTicksInHive);
}
public NBTCompound getEntityData() {
return this.entityData;
}
public void setEntityData(NBTCompound entityData) {
this.entityData = entityData;
}
public int getTicksInHive() {
return this.ticksInHive;
}
public void setTicksInHive(int ticksInHive) {
this.ticksInHive = ticksInHive;
}
public int getMinTicksInHive() {
return this.minTicksInHive;
}
public void setMinTicksInHive(int minTicksInHive) {
this.minTicksInHive = minTicksInHive;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BeeEntry)) return false;
BeeEntry beeEntry = (BeeEntry) obj;
if (this.ticksInHive != beeEntry.ticksInHive) return false;
if (this.minTicksInHive != beeEntry.minTicksInHive) return false;
return this.entityData.equals(beeEntry.entityData);
}
@Override
public int hashCode() {
return Objects.hash(this.entityData, this.ticksInHive, this.minTicksInHive);
}
}
}
@@ -1,100 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.world.states.type.StateValue;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Objects;
public class ItemBlockStateProperties {
private Map<String, String> properties;
public ItemBlockStateProperties(Map<String, String> properties) {
this.properties = properties;
}
public static ItemBlockStateProperties read(PacketWrapper<?> wrapper) {
Map<String, String> properties = wrapper.readMap(
PacketWrapper::readString, PacketWrapper::readString);
return new ItemBlockStateProperties(properties);
}
public static void write(PacketWrapper<?> wrapper, ItemBlockStateProperties props) {
wrapper.writeMap(props.properties,
PacketWrapper::writeString,
PacketWrapper::writeString);
}
public @Nullable Object getProperty(StateValue stateValue) {
String value = this.getProperty(stateValue.getName());
if (value != null) {
return stateValue.getParser().apply(value);
}
return null;
}
public @Nullable String getProperty(String key) {
return this.properties.get(key);
}
public void setProperty(StateValue stateValue, @Nullable Object value) {
this.setProperty(stateValue.getName(), value == null ? null : value.toString());
}
public void setProperty(String key, @Nullable String value) {
if (value == null) {
this.properties.remove(key);
} else {
this.properties.put(key, value);
}
}
public void unsetProperty(StateValue stateValue) {
this.unsetProperty(stateValue.getName());
}
public void unsetProperty(String key) {
this.setProperty(key, null);
}
public Map<String, String> getProperties() {
return this.properties;
}
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemBlockStateProperties)) return false;
ItemBlockStateProperties that = (ItemBlockStateProperties) obj;
return this.properties.equals(that.properties);
}
@Override
public int hashCode() {
return Objects.hashCode(this.properties);
}
}
@@ -1,68 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class ItemContainerContents {
private List<ItemStack> items;
public ItemContainerContents(List<ItemStack> items) {
this.items = items;
}
public static ItemContainerContents read(PacketWrapper<?> wrapper) {
List<ItemStack> items = wrapper.readList(PacketWrapper::readItemStack);
return new ItemContainerContents(items);
}
public static void write(PacketWrapper<?> wrapper, ItemContainerContents contents) {
wrapper.writeList(contents.items, PacketWrapper::writeItemStack);
}
public void addItem(ItemStack itemStack) {
this.items.add(itemStack);
}
public List<ItemStack> getItems() {
return this.items;
}
public void setItems(List<ItemStack> items) {
this.items = items;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemContainerContents)) return false;
ItemContainerContents that = (ItemContainerContents) obj;
return this.items.equals(that.items);
}
@Override
public int hashCode() {
return Objects.hashCode(this.items);
}
}
@@ -1,86 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTLong;
import com.github.retrooper.packetevents.protocol.nbt.NBTNumber;
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Objects;
public class ItemContainerLoot {
private ResourceLocation lootTable;
private long seed;
public ItemContainerLoot(ResourceLocation lootTable, long seed) {
this.lootTable = lootTable;
this.seed = seed;
}
public static ItemContainerLoot read(PacketWrapper<?> wrapper) {
NBTCompound compound = wrapper.readNBT();
ResourceLocation lootTable = new ResourceLocation(compound.getStringTagValueOrThrow("loot_table"));
NBTNumber seedTag = compound.getNumberTagOrNull("seed");
long seed = seedTag == null ? 0L : seedTag.getAsLong();
return new ItemContainerLoot(lootTable, seed);
}
public static void write(PacketWrapper<?> wrapper, ItemContainerLoot loot) {
NBTCompound compound = new NBTCompound();
compound.setTag("loot_table", new NBTString(loot.lootTable.toString()));
if (loot.seed != 0L) {
compound.setTag("seed", new NBTLong(loot.seed));
}
wrapper.writeNBT(compound);
}
public ResourceLocation getLootTable() {
return this.lootTable;
}
public void setLootTable(ResourceLocation lootTable) {
this.lootTable = lootTable;
}
public long getSeed() {
return this.seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemContainerLoot)) return false;
ItemContainerLoot that = (ItemContainerLoot) obj;
if (this.seed != that.seed) return false;
return this.lootTable.equals(that.lootTable);
}
@Override
public int hashCode() {
return Objects.hash(this.lootTable, this.seed);
}
}
@@ -1,75 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Objects;
public class ItemDyeColor {
private int rgb;
private boolean showInTooltip;
public ItemDyeColor(int rgb, boolean showInTooltip) {
this.rgb = rgb;
this.showInTooltip = showInTooltip;
}
public static ItemDyeColor read(PacketWrapper<?> wrapper) {
int rgb = wrapper.readInt();
boolean showInTooltip = wrapper.readBoolean();
return new ItemDyeColor(rgb, showInTooltip);
}
public static void write(PacketWrapper<?> wrapper, ItemDyeColor color) {
wrapper.writeInt(color.rgb);
wrapper.writeBoolean(color.showInTooltip);
}
public int getRgb() {
return this.rgb;
}
public void setRgb(int rgb) {
this.rgb = rgb;
}
public boolean isShowInTooltip() {
return this.showInTooltip;
}
public void setShowInTooltip(boolean showInTooltip) {
this.showInTooltip = showInTooltip;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemDyeColor)) return false;
ItemDyeColor that = (ItemDyeColor) obj;
if (this.rgb != that.rgb) return false;
return this.showInTooltip == that.showInTooltip;
}
@Override
public int hashCode() {
return Objects.hash(this.rgb, this.showInTooltip);
}
}
@@ -1,127 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
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.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
public class ItemEnchantments implements Iterable<Map.Entry<EnchantmentType, Integer>> {
public static final ItemEnchantments EMPTY = new ItemEnchantments(
Collections.emptyMap(), true) {
@Override
public void setShowInTooltip(boolean showInTooltip) {
throw new UnsupportedOperationException();
}
};
private Map<EnchantmentType, Integer> enchantments;
private boolean showInTooltip;
public ItemEnchantments(Map<EnchantmentType, Integer> enchantments, boolean showInTooltip) {
this.enchantments = Collections.unmodifiableMap(enchantments);
this.showInTooltip = showInTooltip;
}
public static ItemEnchantments read(PacketWrapper<?> wrapper) {
ClientVersion version = wrapper.getServerVersion().toClientVersion();
Map<EnchantmentType, Integer> enchantments = wrapper.readMap(
ew -> EnchantmentTypes.getById(version, ew.readVarInt()),
PacketWrapper::readVarInt
);
boolean showInTooltip = wrapper.readBoolean();
return new ItemEnchantments(enchantments, showInTooltip);
}
public static void write(PacketWrapper<?> wrapper, ItemEnchantments enchantments) {
ClientVersion version = wrapper.getServerVersion().toClientVersion();
wrapper.writeMap(enchantments.getEnchantments(),
(ew, enchantment) -> ew.writeVarInt(enchantment.getId(version)),
PacketWrapper::writeVarInt
);
wrapper.writeBoolean(enchantments.isShowInTooltip());
}
public int getEnchantmentLevel(EnchantmentType enchantment) {
return this.enchantments.getOrDefault(enchantment, 0);
}
public void setEnchantmentLevel(EnchantmentType enchantment, int level) {
if (level == 0) {
this.enchantments.remove(enchantment);
} else {
this.enchantments.put(enchantment, level);
}
}
public boolean isEmpty() {
return this.getEnchantmentCount() < 1;
}
public int getEnchantmentCount() {
return this.enchantments.size();
}
public Map<EnchantmentType, Integer> getEnchantments() {
return this.enchantments;
}
public void setEnchantments(Map<EnchantmentType, Integer> enchantments) {
this.enchantments = enchantments;
}
public boolean isShowInTooltip() {
return this.showInTooltip;
}
public void setShowInTooltip(boolean showInTooltip) {
this.showInTooltip = showInTooltip;
}
@Override
public Iterator<Map.Entry<EnchantmentType, Integer>> iterator() {
return this.enchantments.entrySet().iterator();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemEnchantments)) return false;
ItemEnchantments that = (ItemEnchantments) obj;
if (this.showInTooltip != that.showInTooltip) return false;
return this.enchantments.equals(that.enchantments);
}
@Override
public int hashCode() {
return Objects.hash(this.enchantments, this.showInTooltip);
}
@Override
public String toString() {
return "ItemEnchantments{enchantments=" + this.enchantments + ", showInTooltip=" + this.showInTooltip + '}';
}
}
@@ -1,80 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class ItemFireworks {
private int flightDuration;
private List<FireworkExplosion> explosions;
public ItemFireworks(int flightDuration, List<FireworkExplosion> explosions) {
this.flightDuration = flightDuration;
this.explosions = explosions;
}
public static ItemFireworks read(PacketWrapper<?> wrapper) {
int flightDuration = wrapper.readVarInt();
List<FireworkExplosion> explosions = wrapper.readList(FireworkExplosion::read);
return new ItemFireworks(flightDuration, explosions);
}
public static void write(PacketWrapper<?> wrapper, ItemFireworks fireworks) {
wrapper.writeVarInt(fireworks.flightDuration);
wrapper.writeList(fireworks.explosions, FireworkExplosion::write);
}
public int getFlightDuration() {
return this.flightDuration;
}
public void setFlightDuration(int flightDuration) {
this.flightDuration = flightDuration;
}
public void addExplosion(FireworkExplosion explosion) {
this.explosions.add(explosion);
}
public List<FireworkExplosion> getExplosions() {
return this.explosions;
}
public void setExplosions(List<FireworkExplosion> explosions) {
this.explosions = explosions;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemFireworks)) return false;
ItemFireworks that = (ItemFireworks) obj;
if (this.flightDuration != that.flightDuration) return false;
return this.explosions.equals(that.explosions);
}
@Override
public int hashCode() {
return Objects.hash(this.flightDuration, this.explosions);
}
}
@@ -1,63 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.Objects;
public class ItemLock {
private String code;
public ItemLock(String code) {
this.code = code;
}
public static ItemLock read(PacketWrapper<?> wrapper) {
NBTString codeTag = (NBTString) wrapper.readNBTRaw();
return new ItemLock(codeTag.getValue());
}
public static void write(PacketWrapper<?> wrapper, ItemLock lock) {
wrapper.writeNBTRaw(new NBTString(lock.code));
}
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemLock)) return false;
ItemLock itemLock = (ItemLock) obj;
return this.code.equals(itemLock.code);
}
@Override
public int hashCode() {
return Objects.hashCode(this.code);
}
}
@@ -1,76 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import net.kyori.adventure.text.Component;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class ItemLore {
public static final ItemLore EMPTY = new ItemLore(Collections.emptyList());
private List<Component> lines;
public ItemLore(List<Component> lines) {
this.lines = lines;
}
public static ItemLore read(PacketWrapper<?> wrapper) {
List<Component> lines = wrapper.readList(PacketWrapper::readComponent);
return new ItemLore(lines);
}
public static void write(PacketWrapper<?> wrapper, ItemLore lore) {
wrapper.writeList(lore.lines, PacketWrapper::writeComponent);
}
public void addLine(Component line) {
this.lines.add(line);
}
public List<Component> getLines() {
return this.lines;
}
public void setLines(List<Component> lines) {
this.lines = lines;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemLore)) return false;
ItemLore itemLore = (ItemLore) obj;
return this.lines.equals(itemLore.lines);
}
@Override
public int hashCode() {
return Objects.hash(this.lines);
}
@Override
public String toString() {
return "ItemLore{lines=" + this.lines + '}';
}
}
@@ -1,176 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.item.mapdecoration.MapDecorationType;
import com.github.retrooper.packetevents.protocol.item.mapdecoration.MapDecorationTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBT;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTDouble;
import com.github.retrooper.packetevents.protocol.nbt.NBTFloat;
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class ItemMapDecorations {
private Map<String, Decoration> decorations;
public ItemMapDecorations(Map<String, Decoration> decorations) {
this.decorations = decorations;
}
public static ItemMapDecorations read(PacketWrapper<?> wrapper) {
NBTCompound compound = wrapper.readNBT();
Map<String, Decoration> decorations = new HashMap<>(compound.size());
for (Map.Entry<String, NBT> tag : compound.getTags().entrySet()) {
Decoration decoration = Decoration.readCompound((NBTCompound) tag.getValue());
decorations.put(tag.getKey(), decoration);
}
return new ItemMapDecorations(decorations);
}
public static void write(PacketWrapper<?> wrapper, ItemMapDecorations decorations) {
NBTCompound compound = new NBTCompound();
for (Map.Entry<String, Decoration> decoration : decorations.decorations.entrySet()) {
NBTCompound entry = new NBTCompound();
Decoration.writeCompound(entry, decoration.getValue());
compound.setTag(decoration.getKey(), entry);
}
wrapper.writeNBT(compound);
}
public @Nullable Decoration getDecoration(String key) {
return this.decorations.get(key);
}
public void setDecoration(String key, @Nullable Decoration decoration) {
if (decoration != null) {
this.decorations.put(key, decoration);
} else {
this.decorations.remove(key);
}
}
public Map<String, Decoration> getDecorations() {
return this.decorations;
}
public void setDecorations(Map<String, Decoration> decorations) {
this.decorations = decorations;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemMapDecorations)) return false;
ItemMapDecorations that = (ItemMapDecorations) obj;
return this.decorations.equals(that.decorations);
}
@Override
public int hashCode() {
return Objects.hashCode(this.decorations);
}
public static final class Decoration {
private MapDecorationType type;
private double x;
private double z;
private float rotation;
public Decoration(MapDecorationType type, double x, double z, float rotation) {
this.type = type;
this.x = x;
this.z = z;
this.rotation = rotation;
}
@ApiStatus.Internal
public static Decoration readCompound(NBTCompound compound) {
MapDecorationType type = MapDecorationTypes.getByName(compound.getStringTagValueOrThrow("type"));
double x = compound.getNumberTagOrThrow("x").getAsDouble();
double z = compound.getNumberTagOrThrow("z").getAsDouble();
float rotation = compound.getNumberTagOrThrow("rotation").getAsFloat();
return new Decoration(type, x, z, rotation);
}
@ApiStatus.Internal
public static void writeCompound(NBTCompound compound, Decoration decoration) {
compound.setTag("type", new NBTString(decoration.type.getName().toString()));
compound.setTag("x", new NBTDouble(decoration.x));
compound.setTag("z", new NBTDouble(decoration.z));
compound.setTag("float", new NBTFloat(decoration.rotation));
}
public MapDecorationType getType() {
return this.type;
}
public void setType(MapDecorationType type) {
this.type = type;
}
public double getX() {
return this.x;
}
public void setX(double x) {
this.x = x;
}
public double getZ() {
return this.z;
}
public void setZ(double z) {
this.z = z;
}
public float getRotation() {
return this.rotation;
}
public void setRotation(float rotation) {
this.rotation = rotation;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Decoration)) return false;
Decoration that = (Decoration) obj;
if (Double.compare(that.x, this.x) != 0) return false;
if (Double.compare(that.z, this.z) != 0) return false;
if (Float.compare(that.rotation, this.rotation) != 0) return false;
return this.type.equals(that.type);
}
@Override
public int hashCode() {
return Objects.hash(this.type, this.x, this.z, this.rotation);
}
}
}
@@ -1,101 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.potion.Potion;
import com.github.retrooper.packetevents.protocol.potion.PotionEffect;
import com.github.retrooper.packetevents.protocol.potion.Potions;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
public class ItemPotionContents {
private @Nullable Potion potion;
private @Nullable Integer customColor;
private List<PotionEffect> customEffects;
public ItemPotionContents(
@Nullable Potion potion,
@Nullable Integer customColor,
List<PotionEffect> customEffects
) {
this.potion = potion;
this.customColor = customColor;
this.customEffects = customEffects;
}
public static ItemPotionContents read(PacketWrapper<?> wrapper) {
Potion potionId = wrapper.readOptional(ew -> ew.readMappedEntity(Potions::getById));
Integer customColor = wrapper.readOptional(PacketWrapper::readInt);
List<PotionEffect> customEffects = wrapper.readList(PotionEffect::read);
return new ItemPotionContents(potionId, customColor, customEffects);
}
public static void write(PacketWrapper<?> wrapper, ItemPotionContents contents) {
wrapper.writeOptional(contents.potion, PacketWrapper::writeMappedEntity);
wrapper.writeOptional(contents.customColor, PacketWrapper::writeInt);
wrapper.writeList(contents.customEffects, PotionEffect::write);
}
public @Nullable Potion getPotion() {
return this.potion;
}
public void setPotion(@Nullable Potion potion) {
this.potion = potion;
}
public @Nullable Integer getCustomColor() {
return this.customColor;
}
public void setCustomColor(@Nullable Integer customColor) {
this.customColor = customColor;
}
private void addCustomEffect(PotionEffect effect) {
this.customEffects.add(effect);
}
public List<PotionEffect> getCustomEffects() {
return this.customEffects;
}
public void setCustomEffects(List<PotionEffect> customEffects) {
this.customEffects = customEffects;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemPotionContents)) return false;
ItemPotionContents that = (ItemPotionContents) obj;
if (!Objects.equals(this.potion, that.potion)) return false;
if (!Objects.equals(this.customColor, that.customColor)) return false;
return this.customEffects.equals(that.customEffects);
}
@Override
public int hashCode() {
return Objects.hash(this.potion, this.customColor, this.customEffects);
}
}
@@ -1,165 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
public class ItemProfile {
private @Nullable String name;
private @Nullable UUID id;
private List<Property> properties;
public ItemProfile(
@Nullable String name,
@Nullable UUID id,
List<Property> properties
) {
this.name = name;
this.id = id;
this.properties = properties;
}
public static ItemProfile read(PacketWrapper<?> wrapper) {
String name = wrapper.readOptional(ew -> ew.readString(16));
UUID id = wrapper.readOptional(PacketWrapper::readUUID);
List<Property> properties = wrapper.readList(Property::read);
return new ItemProfile(name, id, properties);
}
public static void write(PacketWrapper<?> wrapper, ItemProfile profile) {
wrapper.writeOptional(profile.name, (ew, name) -> ew.writeString(name, 16));
wrapper.writeOptional(profile.id, PacketWrapper::writeUUID);
wrapper.writeList(profile.properties, Property::write);
}
public @Nullable String getName() {
return this.name;
}
public void setName(@Nullable String name) {
this.name = name;
}
public @Nullable UUID getId() {
return this.id;
}
public void setId(@Nullable UUID id) {
this.id = id;
}
public void addProperty(Property property) {
this.properties.add(property);
}
public List<Property> getProperties() {
return this.properties;
}
public void setProperties(List<Property> properties) {
this.properties = properties;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemProfile)) return false;
ItemProfile that = (ItemProfile) obj;
if (!Objects.equals(this.name, that.name)) return false;
if (!Objects.equals(this.id, that.id)) return false;
return this.properties.equals(that.properties);
}
@Override
public int hashCode() {
return Objects.hash(this.name, this.id, this.properties);
}
public static class Property {
private String name;
private String value;
private @Nullable String signature;
public Property(String name, String value, @Nullable String signature) {
this.name = name;
this.value = value;
this.signature = signature;
}
public static Property read(PacketWrapper<?> wrapper) {
String name = wrapper.readString(64);
String value = wrapper.readString(32767);
String signature = wrapper.readOptional(ew -> ew.readString(1024));
return new Property(name, value, signature);
}
public static void write(PacketWrapper<?> wrapper, Property property) {
wrapper.writeString(property.name, 64);
wrapper.writeString(property.value, 32767);
wrapper.writeOptional(property.signature,
(ew, signature) -> ew.writeString(signature, 1024));
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public @Nullable String getSignature() {
return this.signature;
}
public void setSignature(@Nullable String signature) {
this.signature = signature;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Property)) return false;
Property property = (Property) obj;
if (!this.name.equals(property.name)) return false;
if (!this.value.equals(property.value)) return false;
return Objects.equals(this.signature, property.signature);
}
@Override
public int hashCode() {
return Objects.hash(this.name, this.value, this.signature);
}
}
}
@@ -1,26 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
public enum ItemRarity {
COMMON,
UNCOMMON,
RARE,
EPIC,
}
@@ -1,72 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class ItemRecipes {
private List<ResourceLocation> recipes;
public ItemRecipes(List<ResourceLocation> recipes) {
this.recipes = recipes;
}
public static ItemRecipes read(PacketWrapper<?> wrapper) {
List<ResourceLocation> recipes = wrapper.readList(PacketWrapper::readIdentifier);
return new ItemRecipes(recipes);
}
public static void write(PacketWrapper<?> wrapper, ItemRecipes recipes) {
wrapper.writeList(recipes.recipes, PacketWrapper::writeIdentifier);
}
public void addRecipe(ResourceLocation recipeKey) {
this.recipes.add(recipeKey);
}
public void removeRecipe(ResourceLocation recipeKey) {
this.recipes.remove(recipeKey);
}
public List<ResourceLocation> getRecipes() {
return this.recipes;
}
public void setRecipes(List<ResourceLocation> recipes) {
this.recipes = recipes;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemRecipes)) return false;
ItemRecipes that = (ItemRecipes) obj;
return this.recipes.equals(that.recipes);
}
@Override
public int hashCode() {
return Objects.hashCode(this.recipes);
}
}
@@ -1,166 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
public class ItemTool {
private List<Rule> rules;
private float defaultMiningSpeed;
private int damagePerBlock;
public ItemTool(List<Rule> rules, float defaultMiningSpeed, int damagePerBlock) {
this.rules = rules;
this.defaultMiningSpeed = defaultMiningSpeed;
this.damagePerBlock = damagePerBlock;
}
public static ItemTool read(PacketWrapper<?> wrapper) {
List<Rule> rules = wrapper.readList(Rule::read);
float defaultMiningSpeed = wrapper.readFloat();
int damagePerBlock = wrapper.readVarInt();
return new ItemTool(rules, defaultMiningSpeed, damagePerBlock);
}
public static void write(PacketWrapper<?> wrapper, ItemTool tool) {
wrapper.writeList(tool.rules, Rule::write);
wrapper.writeFloat(tool.defaultMiningSpeed);
wrapper.writeVarInt(tool.damagePerBlock);
}
public void addRule(Rule rule) {
this.rules.add(rule);
}
public List<Rule> getRules() {
return this.rules;
}
public void setRules(List<Rule> rules) {
this.rules = rules;
}
public float getDefaultMiningSpeed() {
return this.defaultMiningSpeed;
}
public void setDefaultMiningSpeed(float defaultMiningSpeed) {
this.defaultMiningSpeed = defaultMiningSpeed;
}
public int getDamagePerBlock() {
return this.damagePerBlock;
}
public void setDamagePerBlock(int damagePerBlock) {
this.damagePerBlock = damagePerBlock;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemTool)) return false;
ItemTool itemTool = (ItemTool) obj;
if (Float.compare(itemTool.defaultMiningSpeed, this.defaultMiningSpeed) != 0) return false;
if (this.damagePerBlock != itemTool.damagePerBlock) return false;
return this.rules.equals(itemTool.rules);
}
@Override
public int hashCode() {
return Objects.hash(this.rules, this.defaultMiningSpeed, this.damagePerBlock);
}
public static class Rule {
private MappedEntitySet<StateType.Mapped> blocks;
private @Nullable Float speed;
private @Nullable Boolean correctForDrops;
public Rule(
MappedEntitySet<StateType.Mapped> blocks,
@Nullable Float speed,
@Nullable Boolean correctForDrops
) {
this.blocks = blocks;
this.speed = speed;
this.correctForDrops = correctForDrops;
}
public static Rule read(PacketWrapper<?> wrapper) {
MappedEntitySet<StateType.Mapped> blocks = MappedEntitySet.read(wrapper, StateTypes::getMappedById);
Float speed = wrapper.readOptional(PacketWrapper::readFloat);
Boolean correctForDrops = wrapper.readOptional(PacketWrapper::readBoolean);
return new Rule(blocks, speed, correctForDrops);
}
public static void write(PacketWrapper<?> wrapper, Rule rule) {
MappedEntitySet.write(wrapper, rule.blocks);
wrapper.writeOptional(rule.speed, PacketWrapper::writeFloat);
wrapper.writeOptional(rule.correctForDrops, PacketWrapper::writeBoolean);
}
public MappedEntitySet<StateType.Mapped> getBlocks() {
return this.blocks;
}
public void setBlocks(MappedEntitySet<StateType.Mapped> blocks) {
this.blocks = blocks;
}
public @Nullable Float getSpeed() {
return this.speed;
}
public void setSpeed(@Nullable Float speed) {
this.speed = speed;
}
public @Nullable Boolean getCorrectForDrops() {
return this.correctForDrops;
}
public void setCorrectForDrops(@Nullable Boolean correctForDrops) {
this.correctForDrops = correctForDrops;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Rule)) return false;
Rule rule = (Rule) obj;
if (!this.blocks.equals(rule.blocks)) return false;
if (!Objects.equals(this.speed, rule.speed)) return false;
return Objects.equals(this.correctForDrops, rule.correctForDrops);
}
@Override
public int hashCode() {
return Objects.hash(this.blocks, this.speed, this.correctForDrops);
}
}
}
@@ -1,77 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class LodestoneTracker {
private @Nullable WorldBlockPosition target;
private boolean tracked;
public LodestoneTracker(@Nullable WorldBlockPosition target, boolean tracked) {
this.target = target;
this.tracked = tracked;
}
public static LodestoneTracker read(PacketWrapper<?> wrapper) {
WorldBlockPosition target = wrapper.readOptional(PacketWrapper::readWorldBlockPosition);
boolean tracked = wrapper.readBoolean();
return new LodestoneTracker(target, tracked);
}
public static void write(PacketWrapper<?> wrapper, LodestoneTracker tracker) {
wrapper.writeOptional(tracker.target, PacketWrapper::writeWorldBlockPosition);
wrapper.writeBoolean(tracker.tracked);
}
public @Nullable WorldBlockPosition getTarget() {
return this.target;
}
public void setTarget(@Nullable WorldBlockPosition target) {
this.target = target;
}
public boolean isTracked() {
return this.tracked;
}
public void setTracked(boolean tracked) {
this.tracked = tracked;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof LodestoneTracker)) return false;
LodestoneTracker that = (LodestoneTracker) obj;
if (this.tracked != that.tracked) return false;
return Objects.equals(this.target, that.target);
}
@Override
public int hashCode() {
return Objects.hash(this.target, this.tracked);
}
}
@@ -1,125 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Queue;
public class PotDecorations {
private @Nullable ItemType back;
private @Nullable ItemType left;
private @Nullable ItemType right;
private @Nullable ItemType front;
private PotDecorations(Queue<ItemType> items) {
this(items.poll(), items.poll(), items.poll(), items.poll());
}
public PotDecorations(
@Nullable ItemType back,
@Nullable ItemType left,
@Nullable ItemType right,
@Nullable ItemType front
) {
this.back = back;
this.left = left;
this.right = right;
this.front = front;
}
private List<ItemType> asList() {
return Arrays.asList(this.back, this.left, this.right, this.front);
}
private static @Nullable ItemType readItem(PacketWrapper<?> wrapper) {
ItemType type = wrapper.readMappedEntity(ItemTypes::getById);
return type == ItemTypes.BRICK ? null : type;
}
public static PotDecorations read(PacketWrapper<?> wrapper) {
Queue<ItemType> items = wrapper.<ItemType, Queue<ItemType>>readCollection(
ArrayDeque::new, PotDecorations::readItem);
return new PotDecorations(items);
}
private static void writeItem(PacketWrapper<?> wrapper, @Nullable ItemType type) {
wrapper.writeMappedEntity(type == null ? ItemTypes.BRICK : type);
}
public static void write(PacketWrapper<?> wrapper, PotDecorations decorations) {
wrapper.writeList(decorations.asList(), PotDecorations::writeItem);
}
public @Nullable ItemType getBack() {
return this.back;
}
public void setBack(@Nullable ItemType back) {
this.back = back;
}
public @Nullable ItemType getLeft() {
return this.left;
}
public void setLeft(@Nullable ItemType left) {
this.left = left;
}
public @Nullable ItemType getRight() {
return this.right;
}
public void setRight(@Nullable ItemType right) {
this.right = right;
}
public @Nullable ItemType getFront() {
return this.front;
}
public void setFront(@Nullable ItemType front) {
this.front = front;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof PotDecorations)) return false;
PotDecorations that = (PotDecorations) obj;
if (!Objects.equals(this.back, that.back)) return false;
if (!Objects.equals(this.left, that.left)) return false;
if (!Objects.equals(this.right, that.right)) return false;
return Objects.equals(this.front, that.front);
}
@Override
public int hashCode() {
return Objects.hash(this.back, this.left, this.right, this.front);
}
}
@@ -1,121 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 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.component.builtin.item;
import com.github.retrooper.packetevents.protocol.potion.PotionType;
import com.github.retrooper.packetevents.protocol.potion.PotionTypes;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.List;
import java.util.Objects;
public class SuspiciousStewEffects {
private List<EffectEntry> effects;
public SuspiciousStewEffects(List<EffectEntry> effects) {
this.effects = effects;
}
public static SuspiciousStewEffects read(PacketWrapper<?> wrapper) {
List<EffectEntry> effects = wrapper.readList(EffectEntry::read);
return new SuspiciousStewEffects(effects);
}
public static void write(PacketWrapper<?> wrapper, SuspiciousStewEffects effects) {
wrapper.writeList(effects.effects, EffectEntry::write);
}
public void addEffect(EffectEntry effect) {
this.effects.add(effect);
}
public List<EffectEntry> getEffects() {
return this.effects;
}
public void setEffects(List<EffectEntry> effects) {
this.effects = effects;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof SuspiciousStewEffects)) return false;
SuspiciousStewEffects that = (SuspiciousStewEffects) obj;
return this.effects.equals(that.effects);
}
@Override
public int hashCode() {
return Objects.hashCode(this.effects);
}
public static class EffectEntry {
private PotionType type;
private int duration;
public EffectEntry(PotionType type, int duration) {
this.type = type;
this.duration = duration;
}
public static EffectEntry read(PacketWrapper<?> wrapper) {
PotionType type = wrapper.readMappedEntity(PotionTypes::getById);
int duration = wrapper.readVarInt();
return new EffectEntry(type, duration);
}
public static void write(PacketWrapper<?> wrapper, EffectEntry effect) {
wrapper.writeMappedEntity(effect.type);
wrapper.writeVarInt(effect.duration);
}
public PotionType getType() {
return this.type;
}
public void setType(PotionType type) {
this.type = type;
}
public int getDuration() {
return this.duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof EffectEntry)) return false;
EffectEntry that = (EffectEntry) obj;
if (this.duration != that.duration) return false;
return this.type.equals(that.type);
}
@Override
public int hashCode() {
return Objects.hash(this.type, this.duration);
}
}
}
Loaded 100 of 956 files, more files were not shown because too many files have changed in this diff. Show more