Compare commits

..
785 Commits
Author SHA1 Message Date
retrooper 5f8efaaf0f Correction in documentation 2023-12-13 21:34:05 +01:00
retrooper 9b8de173e4 EntityMetadataProvider backwards compatibility 2023-12-13 21:30:24 +01:00
retrooper de4594fbdc EntityMetadataProvider abstraction has been completed (now provides a protocol version) 2023-12-13 21:26:09 +01:00
retrooper 5eae00ef0b Minor change to velocity module 2023-12-13 21:07:22 +01:00
retrooper 3c418473d8 Releasing 2.2.0
- Initialization Optimization on Spigot
- bStats support implemented for Velocity
- bStats support implemented for BungeeCord
2023-12-13 21:05:53 +01:00
retrooper 1e919053c6 Merge pull request #623 from booky10/dev/1.20.3
1.20.3/1.20.4 update
2023-12-12 22:39:15 +01:00
booky10 30ff648bad Add handling for unnamed simple components as serialized compounds 2023-12-09 00:57:17 +01:00
booky10 6c5d9beb76 Rewrite adventure nbt serialization
This will now skip building nbt objects and will directly build adventure components
2023-12-09 00:10:46 +01:00
retrooper 3e828ea9ee * Added 1.20.4 version constants
* GRASS -> SHORT_GRASS, but GRASS is deprecated.
* WrapperPlayServerTickingInfo -> WrapperPlayServerTickingState
* WrapperPlayServerTickingStep minor changes
2023-12-08 13:05:03 +01:00
booky10 4ef8b381d7 Fix NPE for adventure nbt deserialization if no translation args are present 2023-12-05 20:44:09 +01:00
booky10 24838cd7d9 Fix new particle type ids being ignored 2023-12-05 20:24:47 +01:00
booky10 e17b877b5f Add crafting and trial_spawner_state state values 2023-12-05 20:11:50 +01:00
booky10 8b85bc8d4d Some various fixes for packet wrappers 2023-12-05 20:03:35 +01:00
booky10 fca9ad22fe Fix wrong config packet type registration 2023-12-05 20:03:17 +01:00
retrooper 8f7ec3d38a PacketEvents 2.1.0 release 2023-11-27 19:18:01 +01:00
retrooper 41969994b2 EntityMetadataProvider has been added, to allow potential packetevents addons to add on to our metadata abstraction. 2023-11-27 19:01:12 +01:00
booky10 667652bfb8 Add new resourcepack status for 1.20.3-pre3 2023-11-27 17:29:40 +01:00
booky10 2da42185e8 Rename grass to short_grass for 1.20.3-pre1 2023-11-20 20:23:55 +01:00
booky10 fd1b918956 Update packet structures for 1.20.3-pre1 2023-11-20 20:22:53 +01:00
booky10 828013bf77 Update packet ids for 1.20.3-pre1 2023-11-20 20:22:37 +01:00
booky10 6e30fb393a Move new entitytypes to bottom 2023-11-17 19:13:52 +01:00
booky10 cbfca6c5fa Update block/item tags to 1.20.3
Also fixes incorrect ordering
2023-11-17 18:26:12 +01:00
booky10 945ca46491 Fix missing fields for state types 2023-11-17 16:47:26 +01:00
booky10 f7d5252bf0 WIP new state types 2023-11-16 23:24:07 +01:00
booky10 a624a76427 Add new item types 2023-11-16 22:57:27 +01:00
booky10 39f9ed008c Add new particle types 2023-11-16 22:36:31 +01:00
booky10 a0096b3032 Add breeze and wind charge entity types 2023-11-16 22:31:23 +01:00
booky10 ae1a0258fe Add new game state change "reasons" 2023-11-16 22:22:23 +01:00
booky10 f863ad026f Update explosion packet 2023-11-16 22:17:07 +01:00
booky10 abea90564f Update vibration particle data 2023-11-16 22:01:28 +01:00
booky10 3bdd110864 Fix blockstate registry index not being incremented 2023-11-16 21:47:00 +01:00
booky10 b2e47f48a5 Use nbt-based component read/write methods 2023-11-16 21:45:09 +01:00
booky10 513de88321 Update serverbound jigsaw block packet 2023-11-16 20:11:13 +01:00
retrooper 4a2146d16d Merge pull request #622 from rexlManu/2.0
Relocate only the gson and legacy
2023-11-16 20:02:18 +01:00
booky10 5a49cf2687 Implement packet wrappers for new serverbound packets 2023-11-16 18:49:29 +01:00
booky10 65fba0b83d Implement packet wrappers for new clientbound packets 2023-11-16 18:49:13 +01:00
booky10 5272557f58 Add dummy "style" command argument parser 2023-11-16 18:29:44 +01:00
booky10 51abf38d3f Fix names of command argument parsers 2023-11-16 18:28:55 +01:00
booky10 33abe17a2b Add block mappings for 1.20.3 2023-11-16 18:25:18 +01:00
booky10 593015dd0b Add new packet types 2023-11-16 18:21:29 +01:00
Emmanuel Lampe 079a2fcc53 Relocate kyori legacy and gson separate for bungeecord 2023-11-15 03:17:02 +01:00
Emmanuel Lampe b9d4ed6a60 Relocate kyori legacy and gson separate 2023-11-15 03:16:09 +01:00
retrooper aec45f19e4 Merge pull request #619 from KaspianDev/fix-merchantoffers
Fix merchant offers always being empty
2023-11-10 17:17:31 +01:00
KaspianDev 0aaa4f42b1 Fix merchant offers always being empty 2023-11-10 16:52:49 +01:00
retrooper 75dfc63d3b Merge pull request #618 from SoSeDiK/blockId
Expose block id to BaseChunk
2023-11-07 18:34:37 +01:00
retrooper ac501a26b2 Fix the way we access NetworkManager (recent server builds have changed it) 2023-11-04 23:03:23 +01:00
SoSeDiK 3ebf39d3bd Expose block id to BaseChunk 2023-11-03 21:17:20 +02:00
retrooper 363931875f Stop depending on funkemunky jars. 2023-11-01 11:11:55 +01:00
retrooper b1802fbc0c Merge pull request #613 from 4drian3d/velocity-changes
Some Velocity module improvements
2023-11-01 10:30:18 +01:00
retrooper 9f9cdca53a Fix connection state issues and casting issues with events 2023-11-01 10:29:27 +01:00
Adrian 00c85f3e41 Some Velocity module improvements
- Removed PostOrder LATE usage
- Use Injected PluginContainer
- Disabled debug mode by default
- Replace deprecated method
2023-10-17 10:36:18 -05:00
retrooper b48a91bcee PotionTypes.getById works now 2023-10-11 19:18:47 +02:00
retrooper 709edd8b21 Merge pull request #610 from AbhigyaKrishna/2.0
Retain backward compatibility with adventure 5.0.0
2023-10-11 18:57:45 +02:00
retrooper 90edf6002e PotionTypes now requires a version to work correctly. 2023-10-11 18:04:30 +02:00
retrooper 4e151f8dfb Pushing out 2.1.0 snapshot for 1.20.2 update 2023-10-07 17:14:07 +02:00
retrooper 0165e8a4ac Merge pull request #607 from booky10/dev/1.20.2
1.20.2 update
2023-10-06 23:48:39 +02:00
retrooper 385000b608 * Add full support for PacketConfigReceive & SendEvent
* WrapperConfigClientClientSettings renamed to WrapperConfigClientSettings
2023-10-06 23:42:54 +02:00
booky10 a1b7c947a0 Use ServerVersion instead of ClientVersion for potion effects 2023-10-03 14:58:31 +02:00
Abhigya ab5163bc66 Retain backward compatibility with adventure 5.0.0 2023-10-02 00:41:27 +05:30
booky10 38b25b6d48 Fix wrapper name for debug pong packet
It's not chunk related, just a copy-paste error
2023-09-27 22:42:25 +02:00
booky10 9d5d4858cf Fix blockstate mappings index 2023-09-23 00:48:32 +02:00
booky10 2e6c43ba06 Extract dimension information from registry data packet instead of login packet 2023-09-22 20:32:30 +02:00
booky10 f180a4a172 Fix packet wrapper constructor parameter types 2023-09-22 20:31:56 +02:00
booky10 5ce6b8bf9e Fix missing clientbound configuration packettype 2023-09-22 20:24:22 +02:00
booky10 b61602741b Rebase on latest changes 2023-09-22 20:24:08 +02:00
booky10 13ba9e7b81 Switch protocol after receiving signaling packet 2023-09-22 20:18:00 +02:00
booky10 d4c9444fd5 Separate encoder and decoder protocol state 2023-09-22 20:17:11 +02:00
booky10 b6c079af66 Add packet wrappers for nearly all new packets in 1.20.2
Only one missing is tags update, which already didn't have a wrapper before
2023-09-22 20:17:11 +02:00
booky10 a18d288079 Update packet structures for 1.20.2 2023-09-22 20:17:09 +02:00
booky10 c3d8f91e85 Update all mappings for 1.20.2 2023-09-22 20:16:37 +02:00
retrooper 0ca2f5c50a Minor tweaks to velocity (update api) 2023-09-22 15:21:47 +02:00
retrooper cdc7ed36e0 PacketEvents 2.0.2 update 2023-09-13 16:01:41 +02:00
retrooper 5d63308a22 Delete WrapperPlayServerChunkData default values 2023-09-13 15:36:20 +02:00
retrooper 214706dbb6 Fix update checker colors 2023-09-12 00:59:18 +02:00
retrooper fa3b563c70 2.0.1 release 2023-09-12 00:36:31 +02:00
retrooper 55e31483e7 Changes to naming of WrapperPlayServerHurtAnimation 2023-09-12 00:02:38 +02:00
retrooper aa34910468 Update User#getWorldNBT usages to handle a nullable value. 2023-09-11 23:35:11 +02:00
retrooper 5e44913a5e Sending packets on proxies is now supported!
* ChannelInjector#isProxy added to detect if our implementation is running on a proxy
2023-08-31 20:25:27 +02:00
retrooper b8dc964112 Add jenkins builds on README 2023-08-31 10:40:57 +02:00
retrooper 890844fb60 Fix broken link in README 2023-08-31 10:40:08 +02:00
retrooper fc57c9e077 Update README 2023-08-31 09:46:32 +02:00
retrooper f12ef113aa Fixed packet-modification on BungeeCord. 2023-08-26 22:35:29 +02:00
retrooper e8144ece97 Minor fix to 1.12 item type mappings. 2023-08-24 18:42:48 +02:00
retrooper b611ad5522 Update to 1.20 bungeecord API for packetevents 2.0.0 2023-08-22 19:47:15 +02:00
retrooper 53e1014c8d Cleanup to build.gradle for 2.0.0 rollout 2023-08-22 19:15:43 +02:00
retrooper 69f992a984 PacketEvents 2.0.0 release rollout 2023-08-22 19:12:53 +02:00
retrooper fde9db39b7 Update README 2023-08-22 18:19:26 +02:00
retrooper 6c6a2535c8 Don't think getEntityById is a function that can be fixed 2023-08-22 18:01:31 +02:00
retrooper 23d06075dd Fix BungeeCord injector, you may now listen to packets on proxies. 2023-08-22 17:39:19 +02:00
retrooper 926fd1ae50 Set default values for data inside ChunkData wrapper 2023-08-22 15:04:12 +02:00
AoElite 756add003f Catch exceptions not throwables for events 2023-08-17 18:48:14 -04:00
retrooper 800ffafb96 Update README.md 2023-07-15 19:16:11 +02:00
AoElite ba2d9ae9f0 Merge pull request #598 from clrxbl/fix/chest-block-attributes
Fix chest block attribute order
2023-07-04 18:20:33 -04:00
Michael 31d07e4a39 Fix chest block attribute order 2023-07-05 00:07:12 +02:00
retrooper ec36a5d1d8 Set reEncodeByDefault to true by default 2023-06-29 11:53:04 +02:00
retrooper 08ba59e1d9 Merge pull request #596 from SamB440/fix/mosaic
More block tag fixes
2023-06-28 19:47:51 +02:00
retrooper 851c74e827 Merge pull request #597 from SamB440/feat/item-tags-one-twenty
Update ItemTags to 1.20
2023-06-28 19:47:05 +02:00
SamB440 b31893e035 Update ItemTags to 1.20 2023-06-27 13:51:35 +01:00
SamB440 4718fb985d Might as well add all new 1.20 tags 2023-06-26 22:07:18 +01:00
SamB440 aed9bc14fa Add SWORD_EFFICIENT block tag 2023-06-26 21:56:30 +01:00
SamB440 1daad13da3 Mosaic + step sound blocks 2023-06-26 21:43:58 +01:00
retrooper 65a984e805 Fix NPC#updateTabPing 2023-06-26 22:15:30 +02:00
retrooper a923b950f6 Add getters for WrapperPlayServerBlockChange 2023-06-25 00:29:02 +02:00
retrooper ac5790411f MessageSignData is no longer an optional in chat message wrapper, but the signature bytes can be set to length 0, to indicate that it is not present, otherwise it is. 2023-06-25 00:25:07 +02:00
retrooper cd3449ade2 Newer chat message wrappers extend chat message_v_16 to simplify usage for users aiming 1.16+ 2023-06-23 20:27:25 +02:00
retrooper 75af221f77 Account for fake players that trigger onJoin event. 2023-06-19 17:48:36 +02:00
retrooper 6f9b2cf5e9 Deprecate ChatMessage_v1_19_3 2023-06-19 17:39:32 +02:00
retrooper 4b4dd492cf Fix ChatMessage_v1_19_3#setChatContent 2023-06-19 17:35:35 +02:00
retrooper 68471d32c8 Fix ChatMessage_v1_19_3#setChatContent to update the plainContent 2023-06-18 08:50:33 +02:00
retrooper b7d0ce9518 Make ChatMessage_v1_19_3#unsignedChatContent nullable, getter returns an optional 2023-06-17 23:35:46 +02:00
retrooper 58abfc0c1e Merge pull request #594 from AbhigyaKrishna/2.0
1.19.3 ChatMessage fix
2023-06-17 23:31:48 +02:00
AbhigyaKrishna a3f6adac2f More effective case check for 1.19.1 chat component 2023-06-18 02:53:39 +05:30
AbhigyaKrishna f0c9af4464 Revert "Fix ChatMessageProcessor_v1_19_3's unsignedChatContent being null"
This reverts commit f43fff899f.
2023-06-18 02:52:25 +05:30
retrooper f43fff899f Fix ChatMessageProcessor_v1_19_3's unsignedChatContent being null 2023-06-17 23:14:33 +02:00
AbhigyaKrishna 9291fd8953 1.19.3 ChatMessage fix 2023-06-18 02:34:48 +05:30
retrooper feb975010e Fix 1.19.3+ outgoing chat processing. LastSeenMessages -> LastSeenMessages.Packed 2023-06-16 22:47:15 +02:00
retrooper 5c34c8e6c3 Cleanup of Optional uses 2023-06-16 22:46:11 +02:00
retrooper 8aaf40fc74 Now able to detect 1.20.1 servers. 2023-06-14 23:21:10 +02:00
retrooper c6fcab2923 Merge remote-tracking branch 'origin/2.0' into 2.0 2023-06-14 17:55:27 +02:00
retrooper 64006b91a4 Fix particle importing on 1.8 2023-06-14 17:55:09 +02:00
DefineOutside 625a66f45a Merge pull request #592 from AoElite/2.0
Add cracked state value
2023-06-12 21:13:44 -05:00
AoElite 0c6208f931 add cracked state value 2023-06-12 22:11:37 -04:00
retrooper be32f464c5 Merge pull request #591 from SamB440/fix/block-tags
Fix missing block tag states
2023-06-12 22:13:12 +02:00
SamB440 3389baf40e More missing block tag states 2023-06-12 20:45:26 +01:00
retrooper edc85e68e8 Update copyright year 2023-06-12 20:14:05 +02:00
SamB440 3f9f093934 Fix missing block tag states 2023-06-12 19:09:25 +01:00
retrooper 31426cc69c Add WrapperPlayServerBundle wrapper. 2023-06-12 19:54:33 +02:00
retrooper cec8c9789f SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE fixed 2023-06-12 17:30:38 +02:00
retrooper f771e15ce0 * Added new StateTypes for 1.20 minecraft
* SUSPICIOUS_SAND now has an assigned tool(a shovel), and has been updated (since 1.20)
2023-06-12 17:04:28 +02:00
retrooper 68a3702cd6 ItemType key is always lowercased 2023-06-12 15:21:59 +02:00
retrooper 8f4f688fb8 Update WrappedBlockState mappings, still need to add new state types i believe 2023-06-12 00:35:54 +02:00
retrooper 0a380344c5 Updated particle type mappings to 1.20 minecraft 2023-06-11 23:16:46 +02:00
retrooper ab458ded62 Rename "var_long" to "long" in EntityDataTypes 2023-06-11 22:50:12 +02:00
retrooper 3bc78c1aec ItemType mappings updated, new item types added to API 2023-06-11 22:22:39 +02:00
retrooper 0feebb6819 Fix chat wrapper for 1.19.3+ 2023-06-11 12:34:52 +02:00
retrooper cdb48e0ab6 Fix chat & encryption wrapper (salt signature processing) 2023-06-11 12:20:41 +02:00
retrooper 85e819d72f Fix AdventureReflectionUtil 2023-06-11 10:50:10 +02:00
retrooper 10d44fe3cb Update adventure to 4.14.0 2023-06-11 10:31:34 +02:00
retrooper 6b5ada3c5d Update all wrappers for 1.20 minecraft 2023-06-11 10:08:45 +02:00
retrooper 2f0861c7b7 Update build.gradle to spigot 1.20 2023-06-11 09:45:17 +02:00
DefineOutside abc8695a29 Merge pull request #590 from AoElite/2.0
Add 1.20 protocol
2023-06-08 08:01:42 -05:00
AoElite c6577646ce remove _0 2023-06-08 07:50:12 -04:00
AoElite a6c68b2d0e minimal 1.20 update 2023-06-07 18:12:59 -04:00
DefineOutside 23e0861192 Merge pull request #585 from ammodev/2.0
fix: Block State 1.19.4
2023-06-01 08:49:51 -05:00
MWHunter 7539aa345c add better debug to entity metadata 2023-05-29 18:52:30 -05:00
Simon 2a076a61a0 fix: Accidental code deletion
Due to me not wanting to push my own sorting for imports and stuff I accidentally deleted some lines of code. Now fixed.
2023-05-27 00:54:12 +02:00
Simon bf0ec04cec fix: Block State 1.19.4
Fixed a bug in which the block state could not be mapped. Used in the new BlockDisplays
2023-05-27 00:47:55 +02:00
DefineOutside fea687bba9 Merge pull request #584 from Offenderify/fix/block_data_packet
Fix block entity data packet
2023-05-23 20:34:55 -05:00
DefineOutside 25e83d6181 Merge pull request #579 from minus1ms/2.0
Add WrapperPlayServerDeclareCommands
2023-05-23 20:32:53 -05:00
Offenderify 95a91bb1f2 fix: block entity data packet 2023-05-20 15:10:58 +03:00
MWHunter e1e057eabb fix some 1.8 errors and exceptions 2023-05-14 16:36:47 -05:00
retrooper f81120f8ed Merge pull request #575 from Aseeef/2.0
Added a Conversion Util to convert to/from PacketEvents to Bukkit Particles
2023-05-13 20:31:26 +02:00
minus1ms e44ad5edc2 better name of method
read is more self-explaining than get
2023-05-01 18:10:06 +02:00
minus1ms c35d0854bc Added nullable annotation where it should be 2023-05-01 18:01:47 +02:00
minus1ms 47dbb5e9c0 Add WrapperPlayServerDeclareCommands
added WrapperPlayServerDeclareCommands

im not sure if i did Parsers and Node in good way and im not sure if these are in good packages, everything works as intended
2023-04-30 18:47:55 +02:00
Aseeef 702894dd07 Merge branch 'retrooper:2.0' into 2.0 2023-04-26 17:05:54 -04:00
MWHunter 4801196942 move adventure serializer to adventure util package 2023-04-24 10:24:47 -05:00
retrooper c88a9c412c Ignore modern spoofed players 2023-04-23 22:42:13 +02:00
retrooper 4012472404 Merge pull request #564 from cheaterSK/2.0
Fix WrapperPlayClientChatCommand and WrapperPlayClientChatMessage
2023-04-23 22:39:03 +02:00
retrooper 54f3f3c221 Minor fixes to WrapperPlayClientChatCommand 2023-04-23 22:37:55 +02:00
cheaterSK 873557151b Merge branch 'retrooper:2.0' into 2.0 2023-04-23 17:34:10 +02:00
MWHunter 32e96f3f51 include other included non-latest gson versions 2023-04-22 18:09:41 -05:00
MWHunter cdffd10999 Update adventure to support new chat components 2023-04-22 17:49:38 -05:00
aseef 1524a546d8 Merge remote-tracking branch 'origin/2.0' into 2.0
# Conflicts:
#	spigot/src/main/java/io/github/retrooper/packetevents/util/SpigotReflectionUtil.java
2023-04-15 15:06:58 -04:00
aseef 40d7be6236 * added a conversion util to convert between bukkit and packet events particles 2023-04-15 15:03:08 -04:00
retrooper 98b2b7b631 Fix exceptions on Spigot 2023-04-09 07:21:49 +02:00
retrooper 54704811b3 Fix code duplication in spigot encoder 2023-04-07 20:02:53 +02:00
retrooper 54241497b5 fix imports 2023-04-07 19:41:27 +02:00
retrooper 99637743f5 I've made a severe and continuous lapse of my judgment. and I don't expect to be forgiven. I'm simply here to apologize. so what we came across that day in the woods was obviously unplanned.2 Jan 2018 2023-04-07 19:39:56 +02:00
retrooper 702452c3a1 Final fix for missing imports. 2023-04-07 19:38:11 +02:00
retrooper 7e424cd46b Bruh 2023-04-07 19:36:01 +02:00
retrooper 58401fc18e Fix import errors again.. 2023-04-07 19:34:41 +02:00
retrooper 7285eeff5a Fix missing import in PacketEventsImplHelper
Sorry, I'm editing this in GitHub website cause I'm working on different branches in parallel
2023-04-07 19:31:01 +02:00
retrooper cfb57e7a99 Add handleClientBoundPacket to PacketEventsImplHelper
This helps reduce code duplication when implementing encoders and decoders that have similar functionality on other platforms.
2023-04-07 19:27:22 +02:00
MWHunter 93cd6f39f9 fix isReplaceable() 2023-04-04 20:26:42 -05:00
MWHunter 9975706ba8 update statetypes, itemtypes, block tags to experimental datapack 2023-04-02 13:13:23 -05:00
retrooper 9b88a9ef98 Minor correction to EntityDataTypes 2023-04-02 18:55:33 +02:00
retrooper 548c6183a4 Added the EntityDataType registries, added in 1.19.4 2023-04-02 18:50:12 +02:00
DefineOutside 19d271881c Merge pull request #510 from UserNugget/1.20-experimental-features
'1.20 experimental features' support
2023-04-02 10:19:51 -05:00
MWHunter a64978cb0a delete unmaintained classes 2023-04-02 10:15:28 -05:00
MWHunter 527beda70f allow users to flag events as needing re-encoding, for performance reasons 2023-04-02 10:14:07 -05:00
MWHunter 127421a1d2 add sniffer 2023-04-02 09:53:34 -05:00
MWHunter 4a188bd116 don't eat exceptions 2023-04-02 09:50:59 -05:00
MWHunter cd6db40a0d add runTask() functionality to folia compat utils 2023-04-01 15:16:11 -05:00
MWHunter d050c10eab make isFolia() public 2023-04-01 15:09:57 -05:00
MWHunter 82e5b68119 update folia compat utility 2023-04-01 15:03:40 -05:00
MWHunter 3f00e1d817 more folia support utils 2023-04-01 14:50:47 -05:00
MWHunter 7296072bcb folia support 2023-04-01 14:41:39 -05:00
DefineOutside 132ae43496 Merge pull request #565 from LemonCaramel/fix/server-data
fix WrapperPlayServerData issue in 1.19.4
2023-03-28 08:38:49 -05:00
LemonCaramel 2465ba9306 fix WrapperPlayServerData issue in 1.19.4 2023-03-27 09:24:39 +09:00
cheaterSK 2e10b151c9 Fix WrapperPlayClientChatCommand and WrapperPlayClientChatMessage for 1.19 2023-03-26 17:12:22 +02:00
cheaterSK 9a338cd897 Fix WrapperPlayClientChatCommand 2023-03-26 16:32:12 +02:00
retrooper 7c0bac33df Fix WrapperLoginClientLoginStart for 1.19.4 2023-03-21 22:56:50 +01:00
MWHunter db8c4ce08d register new entity mappings 2023-03-18 21:10:03 -04:00
MWHunter af52640237 fix entity mappings 2023-03-18 20:59:42 -04:00
MWHunter b6d71a79a1 mark default block states 2023-03-17 19:26:02 -05:00
DefineOutside 407257c2ce Merge pull request #558 from MachineBreaker/pooled-bytebuffers
Use Pooled ByteBuffer in SpigotReflectionUtil for decoding/encoding ItemStacks
2023-03-17 17:44:30 -05:00
Alejandro Martinez 19e7bc6190 Use Pooled ByteBuffers in decodeBukkitItemStack & encodeBukkitItemStack 2023-03-17 16:15:23 -06:00
retrooper e0beccff4d Merge remote-tracking branch 'origin/2.0' into 2.0 2023-03-17 21:57:31 +01:00
retrooper 1728e667ea Push 2023-03-17 21:57:03 +01:00
retrooper c2cce6fac7 Merge pull request #550 from AbhigyaKrishna/2.0
Adventure Backward Compatibility (<4.9.0) support
2023-03-17 19:07:08 +01:00
retrooper 9cf38bc325 Merge pull request #556 from maximbreitman/2.0
Add accessors to WrapperPlayServerPlayerInfoUpdate.PlayerInfo
2023-03-17 19:06:00 +01:00
maximbreitman c0522d7836 Add accessors to WrapperPlayServerPlayerInfoUpdate.PlayerInfo 2023-03-17 17:31:47 +03:00
DefineOutside dc1ac3beb3 Merge pull request #555 from MachineBreaker/patch-2
Log getDefaultState in Config Level
2023-03-16 16:34:48 -05:00
MachineBreaker d59a11a340 Log getDefaultState in Config Level
Prevent spamming the console with:
[ac.grim.grimac.shaded.com.github.retrooper.packetevents.PacketEventsAPI] Default state for lantern is null. Returning AIR
2023-03-16 15:29:36 -06:00
MWHunter a8e95c23ac initial 1.19.4 support 2023-03-15 22:31:29 -05:00
DefineOutside 607b8dde56 Update LegacyFlexibleStorage.java 2023-03-14 12:06:06 -05:00
Abhigya a0ccfb4875 Legacy Adventure (<4.9.0) support 2023-03-13 16:02:35 +05:30
retrooper afcf98e2c8 Merge pull request #549 from Aseeef/2.0
Fixed Adventure API & Build Issues
2023-03-12 18:41:25 +01:00
aseef 51d74ae7ea * relocated adventure api
* fixed velocity repo url
2023-03-12 13:33:13 -04:00
retrooper 7b6308c4e0 Merge pull request #546 from jtJava/2.0
Expose NPC channels and remove unnecessary parameters
2023-03-09 22:14:50 +01:00
jtJava cdbe0df0f3 Expose NPC channels and remove unnecessary parameters 2023-03-08 16:29:58 -06:00
DefineOutside d799ba7190 Merge pull request #543 from Aseeef/2.0
Marker interfaces to packet types
2023-03-01 20:25:43 -06:00
aseef 8c03d2e3a0 Merge remote-tracking branch 'origin/2.0' into 2.0 2023-03-01 21:19:19 -05:00
aseef 7c2994e54d PacketTypes now implement a marker interface indicating whether the packets are client bound or server bound 2023-03-01 21:19:03 -05:00
aseef e1e61feebf reverted an accidental change 2023-03-01 21:18:46 -05:00
aseef e6fb117182 PacketTypes now implement a marker interface indicating whether the packets are client bound or server bound 2023-03-01 21:16:44 -05:00
retrooper a7aa3eae68 Merge pull request #540 from cheaterSK/2.0
feat: Add option in settings to disable color downsampling + fix actions/upgrade gradle
2023-02-20 16:20:20 +01:00
cheaterSK d38089a46a Upgrade gradle to 8.0.1, fix issues that came with it + freeze the version with ./gradlew in actions to avoid issues in future 2023-02-19 11:06:25 +01:00
cheaterSK e2a980adde Fix backwards compatibility 2023-02-18 10:09:09 +01:00
cheaterSK a4e116d34f Merge remote-tracking branch 'origin/2.0' into 2.0
# Conflicts:
#	api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerPlayerInfo.java
2023-02-18 10:02:37 +01:00
retrooper 6b61682fe4 Merge pull request #538 from Aseeef/2.0
NPE + ConcurrentModification Exception Fix
2023-02-15 23:37:53 +01:00
MWHunter 0c4709ac57 fix exception when mojang sends DISCONNECT in STATUS state, for some reason 2023-02-13 12:09:23 -06:00
DefineOutside c6a542d206 Merge pull request #529 from ammodev/2.0
Version not being chosen correctly
2023-02-13 11:58:48 -06:00
MWHunter d67028f568 don't enable debug by default 2023-02-12 17:08:39 -06:00
aseef af48ee3938 Now creating a set using concurrenthashmap 2023-02-12 13:00:48 -05:00
aseef 945919c1e0 Merge remote-tracking branch 'origin/2.0' into 2.0 2023-02-12 08:32:04 -05:00
aseef 38de7a4b94 should fix concurrent modification exception 2023-02-12 08:30:32 -05:00
Aseeef 419232a075 Merge branch 'retrooper:2.0' into 2.0 2023-02-12 07:47:12 -05:00
aseef e705b2725d fixed a npe 2023-02-12 07:46:10 -05:00
MWHunter 004702f642 remove more unused internal methods 2023-02-11 16:24:13 -06:00
MWHunter 4c29d39292 clean up unused internal methods 2023-02-11 16:11:46 -06:00
MWHunter 24e8ff4fb4 fix fix setting components in EntityDataProvider 2023-02-03 12:59:05 -06:00
MWHunter cf61f74ade fix setting components in EntityDataProvider 2023-02-03 09:13:19 -06:00
MWHunter 72ab24b419 disable debug listener and reset the class 2023-02-02 22:11:14 -06:00
MWHunter 8c8357bfbc avoid modifying backing array 2023-02-02 16:53:16 -06:00
MWHunter 59d36b6e55 Revert "ensure we have recovery logic for missing transition to PLAY state"
This reverts commit 647c05fe98.
2023-02-02 13:25:09 -06:00
MWHunter decf5579a3 reverse lists sanely 2023-02-01 21:18:22 -06:00
MWHunter 187f5a54c6 Why do we not set protocol to GAME state if client version is unknown??? 2023-02-01 20:54:46 -06:00
MWHunter 647c05fe98 ensure we have recovery logic for missing transition to PLAY state 2023-02-01 20:50:46 -06:00
MWHunter a089b98f6d warn instead of debug on late injection 2023-02-01 20:45:43 -06:00
MWHunter 9d21b834cc reverting bc356c6d - not setting to GAME state if client version unknown? what is retrooper doing? 2023-02-01 20:43:38 -06:00
MWHunter 069e872204 print more exceptions? 2023-02-01 20:39:02 -06:00
Simon e945c9c56f Update build.gradle
Revert the changes on the version to fit current standards
2023-01-31 22:09:12 +01:00
SimonandJulian b8058b57d8 Update bungeecord/src/main/java/io/github/retrooper/packetevents/bungee/factory/BungeePacketEventsBuilder.java
Updated code style

Co-authored-by: Julian <53055251+NoJokeFNA@users.noreply.github.com>
2023-01-31 09:33:17 +01:00
retrooper 7ce167157a Merge pull request #442 from NoJokeFNA/feat/bungeecord
Cleaned up BungeeCord module
2023-01-30 19:47:05 +01:00
DefineOutside 0503e99c50 Merge pull request #530 from DietrichPaul/patch-1
fixed 1.7 block placement
2023-01-30 12:04:17 -06:00
MWHunter 413d5e1eb5 add toString for StateType 2023-01-29 17:47:55 -06:00
MWHunter 51ebbb7914 ignore more types of invalid handshakes with the server 2023-01-29 12:36:47 -06:00
Paul Dietrich 2b98d5c90b fixed 1.7 block placement 2023-01-29 11:05:28 +01:00
MWHunter 099ea9b7e9 fix race condition when sending packets to multiple people 2023-01-28 17:53:05 -06:00
Simon ce703febc3 Fixed a bug where the version would not be chosen correctly 2023-01-29 00:16:00 +01:00
Simon dce59f99fd Changed git ignore to include vscode files 2023-01-29 00:09:03 +01:00
UserNugget 5ff498b6f0 1.20 experimental blocks/items/tags 2023-01-28 11:21:07 +03:00
MWHunter 32b85dce18 add more methods to avoid forcing people to use clientVersion 2023-01-27 23:13:57 -06:00
MWHunter 89b8d823c4 avoid forcing people to specify clientversions for block data 2023-01-27 23:11:53 -06:00
MWHunter fc0f1eec68 default block state to server version 2023-01-27 22:36:05 -06:00
MWHunter 765fb79321 add modern conversions for WrappedBlockState 2023-01-27 22:34:55 -06:00
MWHunter eb42c1b473 warn instead of error if someone else removes our handlers on reloads/shutdowns 2023-01-27 20:58:02 -06:00
MWHunter ce484ecac5 support reloads 2023-01-27 20:20:44 -06:00
MWHunter cb3e4d33a7 properly handle sending -1 (survival) gamemode in player info 2023-01-27 19:43:34 -06:00
MWHunter 12c01eb2fa update chat wrappers to 1.19.3 2023-01-27 19:25:31 -06:00
MWHunter c4b8a17437 fix project setup by not setting java source and target compat in the base build.gradle 2023-01-27 17:13:24 -06:00
MWHunter 5dde544e07 correct gradle specifying submodules 2023-01-27 16:19:39 -06:00
MWHunter d16ad2154d hack around bungeecord's inability to process empty buffers 2023-01-27 13:31:01 -06:00
MWHunter 245da7a870 ignore handshaking exceptions 2023-01-27 12:55:08 -06:00
MWHunter 2a0b217718 revert last change 2023-01-27 12:23:17 -06:00
MWHunter 582cfa7b57 fix cancelling outbound packet kicking people on bungeecord 2023-01-27 12:18:11 -06:00
retrooper 1b295dc827 Merge pull request #486 from vytskalt/2.0
Safely limit team display name, prefix and suffix to appropriate lengths
2023-01-11 19:31:42 +01:00
retrooper a83248f70d Correctly limit all data in the wrapper differently depending on the protocol version. 2023-01-11 19:29:28 +01:00
retrooper 42a1375c00 Merge pull request #516 from RotMC/2.0
Fix NPE caused by attempting to initialize user before channel
2023-01-11 18:32:30 +01:00
Ryan Jones fbe89306f5 Merge branch 'retrooper:2.0' into 2.0 2023-01-09 11:40:31 -05:00
retrooper faeb2f55d3 * Update NPC API for 1.19.3
* Improve WrapperPlayServerPlayerInfoUpdate & WrapperPlayServerPlayerInfoRemove for easier use
2023-01-08 00:27:58 +01:00
DefineOutside 239cc09c9f fix headYaw not being sent 2023-01-05 16:41:28 -06:00
retrooper 6aac1faac4 Merge pull request #517 from iTzLucky28/2.0
Add Itemstack to WrapperPlayClientPlayerBlockPlacement constructor and replace Optional by regular objects
2023-01-03 22:54:20 +01:00
iTz_Lucky ea4ab05bff Add Itemstack to constructor and replace Optional by regular objects
Also less error prone, especially if they send null as Optional instead of Optional containing null
2023-01-02 08:13:29 +01:00
wordandahalf d53f39bbc7 Fix NPE caused by attempting to initialize user before channel 2023-01-01 16:50:55 -05:00
cheaterSK 8f28b71ee2 Merge branch 'retrooper:2.0' into 2.0 2022-12-31 17:28:36 +01:00
DefineOutside 58df1fcc91 Merge pull request #512 from epserv/2.0
Add SITTING pose to EntityPose
2022-12-29 20:39:32 -06:00
l_MrBoom_l 060b919fa3 Add SITTING pose to EntityPose 2022-12-24 23:07:33 +05:00
MWHunter 7d0d4aa672 fix weird spigot 1.8 bug 2022-12-21 16:57:49 -06:00
MWHunter e3cde54ab2 Simplify encoder/decoder, avoid bytebuf allocations 2022-12-21 16:20:59 -06:00
MWHunter d681345e41 Fix optional component serializers 2022-12-15 14:54:08 -06:00
MWHunter 3939b534ad make entity json data lazy 2022-12-15 13:53:57 -06:00
MWHunter a8afbd2a0b pool bytebufs 2022-12-15 13:34:41 -06:00
MWHunter 7d7cbb4445 Don't annotate non-sharable encoders/decoders as sharable 2022-12-14 17:54:58 -06:00
MWHunter 1c5dceb47d Update explosion packet to 1.19.3 2022-12-14 14:59:58 -06:00
MWHunter 876fbf6fbf Fix creating a new NBT tag which can desync inventory 2022-12-13 14:00:23 -06:00
MWHunter b469ce2a69 fix compilation 2022-12-13 00:31:14 -06:00
MWHunter 6f7823e8cb Use pipeline instead of address for tracking connections 2022-12-13 00:21:00 -06:00
MWHunter 2619a4398d Clean up previous attempts to try to fix race condition 2022-12-12 20:23:27 -06:00
MWHunter d411fe44fe Fix race condition due to ProtocolLib wrapping a Channel screwing with our hashmaps 2022-12-12 20:19:07 -06:00
MWHunter 67af517510 Try synchronization to fix weird race condition 2022-12-12 19:41:39 -06:00
MWHunter cce862bc57 Refactor methods dealing with Bukkit and Users 2022-12-12 18:20:48 -06:00
MWHunter 319750e3f9 Fix tag matches for empty tags 2022-12-12 16:42:20 -06:00
MWHunter 78ccd8b2d5 fix last commit 2022-12-12 14:07:11 -06:00
MWHunter 50ef62f4fb Fix some reflection methods on some shitty MCM jar 2022-12-12 14:06:42 -06:00
MWHunter 05a5b5284b More debug 2022-12-12 12:41:48 -06:00
MWHunter 8c6865405d actually fix bad ordering (not race condition!) of post send tasks 2022-12-11 19:29:14 -06:00
retrooper a204b5d521 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-12-11 09:10:47 +01:00
retrooper da0128b330 Fixed user state transitioning to remain in sync with minecraft which should fix a bunch of errors where we do not recognize the packet id or properly read data of a packet, because our connection state is behind. We need to update the state as soon as we get the packet. 2022-12-11 09:10:15 +01:00
MWHunter 84b005a3b0 Handle vanilla now reading a fixed amount of bytes 2022-12-11 00:15:06 -06:00
MWHunter 38fd7eae6d Fix 1.19.3 chat messages not reading/writing chat type 2022-12-11 00:02:19 -06:00
MWHunter e3d08fa0de Try adding partial 1.19.3 chat packet support 2022-12-10 23:49:13 -06:00
retrooper 0da59c3585 Merge pull request #494 from iTzLucky28/2.0
Add getter/setter for WrapperPlayClientClickWindow
2022-12-11 00:31:35 +01:00
retrooper b4145fda44 Remove ClassUtil's unnecessary class simple name caching 2022-12-11 00:29:02 +01:00
retrooper 5df58a116d Fix race-condition in transitioning to PLAY state.
Post-tasks now run right after all listeners have processed the packet.

Tasks-after-send (only for outgoing packets) run after a packet has been sent

There's a difference so please make sure you're using the right one.
2022-12-10 21:21:22 +01:00
retrooper 7899d8cb46 Fix NBTCodec#nbtToJson 2022-12-10 21:03:51 +01:00
MWHunter b47e0f20ef More gracefully handle unknown block types 2022-12-09 18:16:28 -06:00
MWHunter 63a7121653 Update some mappings to 1.19.3 (Not everything is complete!) 2022-12-09 18:03:15 -06:00
MWHunter 7927c89ba2 Create a new bytebuf due to weird 1.8 bytebuf behavior 2022-12-09 15:10:08 -06:00
MWHunter db5c97a324 Protect against empty bytebuffers, remove large amount of decoder code 2022-12-09 00:35:44 -06:00
MWHunter d4b919430f Ignore via API if it returns -1 as player version 2022-12-08 19:16:39 -06:00
MWHunter d52df749fa Prevent bots scraping the internet from causing PE 2.0 error 2022-12-08 16:54:59 -06:00
MWHunter 63eac8f0f6 Prevent failed injection with multiple PacketEvents 2.0 plugins 2022-12-08 16:21:17 -06:00
cheaterSK 0d7a618d87 Merge branch 'retrooper:2.0' into 2.0 2022-12-08 22:38:15 +01:00
retrooper 7a8d440475 * Added WrapperPlayServerPlayerInfoUpdate (for minecraft 1.19.3+ versions)
* Minor optimization to WrapperPlayServerPlayerInfo (minecraft 1.19.2 and older can use this wrapper)
2022-12-08 19:27:41 +01:00
retrooper 89b63802ac Add WrapperPlayClientChatSessionUpdate 2022-12-08 18:24:27 +01:00
retrooper 17e8b51205 Add WrapperPlayServerUpdateEnabledFeatures 2022-12-08 17:11:51 +01:00
retrooper 8bb12b6913 Add WrapperPlayServerPlayerInfoRemove 2022-12-08 17:07:18 +01:00
retrooper 8a194d1ff6 Add WrapperPlayServerDisguisedChat (1.19.3 packet) 2022-12-08 17:01:31 +01:00
retrooper 45bc1e3d80 Map global 1.19.3 packet types 2022-12-08 16:54:10 +01:00
retrooper a812e22312 Map 1.19.3 packet types 2022-12-08 16:37:20 +01:00
DefineOutside b7c9015b39 Merge pull request #496 from ytnoos/2.0
Fix ViaVersion version check
2022-12-08 09:06:08 -06:00
Ytnoos 98c7c0d49c Fix ViaVersion version check 2022-12-08 11:35:56 +01:00
MWHunter dc10e3cca6 Support ViaBackwards on Paper servers 2022-12-07 17:01:48 -06:00
retrooper 54ae21fd5d Set autoProtocolTranslation to true 2022-12-07 23:45:21 +01:00
retrooper 5d851e849a Merge remote-tracking branch 'origin/2.0' into 2.0 2022-12-07 23:44:42 +01:00
retrooper 09ef7c2e80 Fix server-version detection issues & compression handling 2022-12-07 23:44:14 +01:00
MWHunter e8d7fc30a5 Don't try auto translating spigot protocol 2022-12-07 16:06:25 -06:00
MWHunter 5fbb6d7349 Refactor post tasks 2022-12-07 14:59:41 -06:00
MWHunter 28b67601c1 Fix concurrent modification exception 2022-12-07 14:47:26 -06:00
MWHunter ba02780727 Fix receive packet methods 2022-12-07 14:16:32 -06:00
MWHunter 2c756925a1 Injector rewrite for ViaVersion 4.5.0 2022-12-07 13:56:21 -06:00
iTz_Lucky ac37b708c0 Update WrapperPlayClientClickWindow
Getter and Setter for actionNumber in  WrapperPlayClientClickWindow
2022-12-03 04:03:25 +01:00
retrooper 6b92403dea Optimize ProtocolSupportUtil 2022-12-01 20:05:21 +01:00
cheaterSK f63da3d3d2 Fix Teams packet gamemode sometimes resulting in -1 2022-11-26 11:41:30 +01:00
cheaterSK de763c948c Fix legacy component parser 2022-11-26 10:52:55 +01:00
cheaterSK 4469b93ed9 feat: Add option in settings to disable color downsampling 2022-11-26 10:19:36 +01:00
DefineOutside 873c09d224 Merge pull request #474 from caoli5288/patch/user-dimension
Use User.dimension to improve ChunkReader_v1_9
2022-11-16 12:20:08 -06:00
DefineOutside 646b0a1050 Merge pull request #488 from AoElite/2.0
Allow NPC gamemode to be changable
2022-11-16 12:19:38 -06:00
AoElite 470975ca77 add method to update gamemode 2022-11-15 22:24:28 -05:00
AoElite 2005daa11f allow the gamemode of the npc to be changeable 2022-11-15 22:17:30 -05:00
VytskaLT e28f4e3993 Limit team display name, prefix and suffix to 16 characters 2022-11-06 18:11:19 +02:00
MWHunter 7509ecb971 Fix legacy blocks mappings 2022-10-27 15:03:17 -05:00
retrooper 738309506d Merge pull request #484 from wordandahalf/2.0
Ensure dimension's attributes is initialized to a non-null value
2022-10-09 11:04:41 +02:00
wordandahalf 5243d9f17d Initialize attributes in constructors 2022-10-06 17:43:31 -04:00
wordandahalf bd91ef1be1 Ensure dimension's attributes is initialized to a non-null value 2022-10-06 16:39:49 -04:00
retrooper 8a9338ae46 Merge pull request #482 from LeeGodSRC/bugfix/packet-teams
Fixed WrapperPlayServerTeams send incorrect color post 1.17
2022-10-05 21:43:32 +02:00
retrooper 9aa27103a0 Fix WrapperPlayServerBlockEntityData constructor 2022-10-05 21:41:13 +02:00
leegod af105f4add Fixed WrapperPlayServerTeams send incorrect color post 1.17 2022-10-05 11:22:37 +08:00
retrooper d2d3d84cbf Merge remote-tracking branch 'origin/2.0' into 2.0 2022-10-03 20:29:06 +02:00
retrooper e9a5c9315c receivePacket works fully with ViaVersion;
receivePacketSilently works with ViaVersion if there is only one packetevents instance (until ViaVersion fixes their injector)
2022-10-03 20:22:09 +02:00
Souvlakis 3a93098804 Forcibly close unhandled connections
* Forcibly close unhandled connections
2022-09-29 15:01:56 +02:00
Julian 0b404d04cd Added all combat wrapper classes (#379)
* feat: added WrapperPlayServerEndCombatEvent, WrapperPlayServerEnterCombatEvent, WrapperPlayServerDeathCombatEvent, WrapperPlayServerCombatEvent
Co-authored-by: retrooper <retrooperdev@gmail.com>
2022-09-11 22:04:43 +02:00
retrooper f7b6fc476f When server sends chat messages to large, it used to kick players instead of just throwing an error. We fixed that. 2022-09-11 20:23:54 +02:00
Souvlakis 0bcf58cf80 Added the ability to set a custom resourceProvider, which is used to retrieve files such as block mappings. (#477) 2022-09-11 19:02:13 +02:00
caoli5288 f9390aa69d fix #472 2022-08-26 20:27:26 +08:00
caoli5288 3f6bb1a03d Merge remote-tracking branch 'upstream/2.0' into patch/user-dimension 2022-08-26 20:26:23 +08:00
caoli5288 67eaa91252 Fix 1.12.2 chunk issues
* fix #472
2022-08-26 10:36:16 +02:00
caoli5288 911dffccc2 fix #472 2022-08-24 13:51:54 +08:00
caoli5288 3368b7fcc5 fix #472 2022-08-24 13:33:34 +08:00
Abhigya 1ad7cae303 Added WrapperPlayServerBlockEntityData, Dimension conversion fixes, Particle data fixes, EntityDataTypes fix
* Added WrapperPlayServerBlockEntityData and Dimension conversion
* Fixed serialization for Scoreboard Objective
* Updated Particle data system
* Updated EntityDataTypes for Particle and GlobalPos
Co-authored-by: retrooper
2022-08-23 18:36:57 +02:00
hinoobers b7d04384fb Fix for JSON -> NBT
Handle LazilyParsedNumber
2022-08-23 18:16:06 +02:00
retrooper ea32d28d0b Allow broken spigot forks not allowing us to detect server versions to load packetevents and assume server version is 1.8.8 (more common on older forks) 2022-08-23 18:10:32 +02:00
retrooper ad70e4b996 Correct WrapperStatusClientRequest constructor 2022-08-17 21:25:17 +02:00
retrooper c320ebce86 Update usage of blockface in digging wrapper 2022-08-17 21:24:43 +02:00
retrooper 01c81f5a0b Remove duplicate getter and setter in WrapperPlayClientPlayerDigging 2022-08-17 21:19:18 +02:00
retrooper 66c722ec00 We correctly handle users trying to run packetevents on server versions not yet supported. Sort of a hotfix for now 2022-08-17 18:08:25 +02:00
retrooper af38857d07 Correct link in error when loading with outdated ProtocolSupport 2022-08-17 17:53:14 +02:00
retrooper 5a1a02d212 Attempted to implement a NBTCodec.nbtToJson & NBTCodec.jsonToNBT 2022-08-17 10:41:41 +02:00
retrooper bc96b5cd3e remove 2022-08-16 21:19:30 +02:00
retrooper c44e834c01 WrapperPlayServerEntityProperties -> WrapperPlayServerUpdateAttributes
ENTITY_PROPERTIES -> UPDATE_ATTRIBUTES

Attempted to fix issues on legacy versions where keys are too long for some reason
2022-08-16 21:05:00 +02:00
retrooper 4273bf6587 Fix WrapperPlayClientTabComplete for 1.9->1.12.2 2022-08-16 20:30:20 +02:00
retrooper 3329a544a4 WrapperPlayServerTradeList -> WrapperPlayServerMerchantOffers
TRADE_LIST -> MERCHANT_OFFERS

Breaking changes to merchant offers wrapper and fixed bugs on 1.19+
2022-08-16 18:56:29 +02:00
retrooper 075784498c Update copyright year in files. 2022-08-16 17:48:35 +02:00
MWHunter 03b68a7f6f Fix 1.7 BlockFace exception 2022-08-07 17:36:17 -05:00
MWHunter dc614c96c3 Partially revert eae3d091f8 2022-08-07 16:16:10 -05:00
MWHunter f77f705942 Refactor ServerVersion 2022-08-06 18:13:26 -05:00
retrooper aa9cc58b49 1.19.2 support is ready. 2022-08-05 17:05:23 +02:00
retrooper 9de4dcf4b1 Fixed EntityMetadata 2022-08-05 15:24:49 +02:00
retrooper eae3d091f8 More optimizations to entitydatatypes 2022-08-05 13:24:26 +02:00
retrooper 5f499123df Some optimizing to EntityDataTypes 2022-08-05 13:04:18 +02:00
retrooper a6c16ab45a Preparing for 1.19.2 update. 2022-08-04 18:28:11 +02:00
retrooper c060a55740 Removed debugs. 2022-08-03 23:54:09 +02:00
retrooper 8447998ce6 Transformed ChatType from an enum to a registry. Use ChatTypes.CHAT for example;
Removed weird exception supression, working on seperating user exceptions and internal packet api exceptions.
2022-08-03 23:53:20 +02:00
retrooper 99bc0ffcb6 Hopefully fixed some decoder issues? 2022-08-03 20:23:05 +02:00
retrooper dea5feaa1e Added proper exceptions again, still looking for a better way to handle exceptions. 2022-08-03 20:19:07 +02:00
DefineOutside ebea88f60f Update entity_data_type_mappings.json 2022-08-03 09:51:23 -05:00
retrooper 5717b6050e User#sendPacketSilently added 2022-08-01 21:19:30 +02:00
retrooper 8eb60e9398 Exclude GSON from being shaded when shading adventure on the spigot module. 2022-08-01 20:33:05 +02:00
retrooper 4db2dc0592 SELECT_ADVANCEMENT_TAB renamed to SELECT_ADVANCEMENTS_TAB;
ADVANCEMENTS renamed to UPDATE_ADVANCEMENTS;
2022-08-01 20:32:24 +02:00
retrooper ba1daa4b17 Micro optimization to EntityDataTypes and its mappings. 2022-08-01 20:30:49 +02:00
retrooper 69700bce2a Fixed exception handling entirely. 2022-07-30 19:09:54 +02:00
retrooper 9dc0db4eae Minor fix attempt to exception handling. 2022-07-30 16:20:18 +02:00
retrooper 8aeef01bd4 Fixed packet type mappings for 1.19.1;
Fixed constructor event for WrapperPlayServerCustomChatCompletions & WrapperPlayServerPlayerChatHeader
2022-07-29 20:51:41 +02:00
retrooper 3fff3925b2 Remove debugs. 2022-07-28 19:18:54 +02:00
retrooper 72c0ecbc5d WrapperPlayClientPlayerDigging reads readByte() instead of readUnsignedByte() 2022-07-28 19:11:11 +02:00
retrooper 785c8056f9 WrapperPlayClientEntityAction now has 1.7.10 support 2022-07-28 18:50:02 +02:00
retrooper 48ef856d02 Fixed BlockFace index out of bounds 2022-07-28 18:35:44 +02:00
Julianandretrooper c052ecf8c0 1.19.1 Update (#448)
* feat: updated ClientVersion and ServerVersion

* feat updated WrapperPlayServerSystemChatMessage

* feat: WrapperLoginClientLoginStart

* feat: use our new methods

* WrapperPlayServerSystemChatMessage completed & fixed.

ClientVersion fixed HIGHER_THAN_SUPPORTED_VERSIONS field.

* change: fixed code-style

* fix: fixed `overlay` getter as it doesn't match its default getter

* * Updated ChatType as some constants were removed on 1.19.1

* Updated ChatMessage and SystemChatMessage again

* Updated User#sendMessage to work on 1.19.1

* feat: updated ChatType to 1.19.1-pre3
      -> `MSG_COMMAND` got replaced by `MSG_COMMAND_INCOMING` and `MSG_COMMAND_OUTGOING`
feat: added `CUSTOM_CHAT_COMPLETIONS` enum to new `ClientboundPacketType_1_19_1` class
feat: added WrapperPlayClientCustomChatCompletions & ChatCompletionAction classes

* feat: added `DELETE_CHAT` and `PLAYER_CHAT_HEADER` enums to `ClientboundPacketType_1_19_1` class
feat: added WrapperPlayClientDeleteChat & WrapperPlayClientPlayerChatHeader classes
change:
remove: removed unused import in WrapperPlayServerChatMessage

* change: change String[] to List<>

* remove: removed @Experimental annotation from readList and writeList method
change: renamed readVarIntList to readList and writeVarIntList to writeList
change: used our readList and writeList methods in WrapperPlayClientCustomChatCompletions

* feat: use our Writer and Reader functions instead of plain generic types

* Removed blanked line

* Update ChatType.java

* feat: improved readMap (especially for modern versions currently)

* Add ClientVersion.V_1_19_1 as a version map to allow it to use 1.19.1 clientbound packet mappings

* change: changed some naming stuff

* Fixed WrapperLoginClientLoginStart's SignatureData encoding.

* Fixed DeleteChat wrapper and mappings.

* Fixed WrapperPlayServerPlayerChatHeader for 1.19.1

* Fix WrapperPlayServerCustomChatCompletions

* Update api/src/main/java/com/github/retrooper/packetevents/protocol/packettype/PacketType.java

* feat: added `$readSignatureData` and `$writeSignatureData`

* fix: fix `$writeOptional` usage

* feat: first pre-5 update

* feat: some more progress

* feat: even more progress (might break some wrappers ATM)

* fix: fixed errors

* feat: pre-5 changes for ChatType

* change: changed `query` to `queryId`

* feat: *optimized* ChatType handling for modern versions (HashMap)

* * Removed write methods in LastSeenMessages and its inner classes.

* PacketWrapper#readLastSeenMessages and PacketWrapper#writeLastSeenMessages created.

WrapperPlayClientChatAck & WrapperPlayClientChatCommand & WrapperPlayClientChatMessage now use last seen messages.

Removed LastSeenMessagesTracker & LastSeenMessagesValidator, I don't see the need for it and we don't use it anywhere. Maybe later we might implement it ourself with inspiration from mojang but not just copy paste.

* remove: removed useless whitespace

* feat: improved docs in WrapperPlayServerChatMessage for `$getChatContent` and `$setChatContent`

* feat: added `EQUALS` to MultiVersion enum
  affected classes due to import changes:
   - PacketWrapper, ServerVersion, WrapperPlayWorldBorderWarningDelay

* change: changed copy order in WrapperPlayServerSystemChatMessage, it's not big of a deal, just looks cleaner this way

* feat: added rc-2 change; `boolean enforceSecureChat` has been added to WrapperPlayServerServerData
feat: created constructor for legacy versions in WrapperPlayServerServerData

* feat: added missing copyright text to WrapperPlayServerServerData

* feat: rc-2 -> added missing `enforceSecureChat` field to WrapperStatusServerResponse - thanks @derklaro

* remove: reverted WrapperStatusServerResponse as it just got added into the JSON message and not as a separate parameter

* feat: added pre6 change; the `chatContent` itself got changed from Component to a plain String, though we still provide the Component usage and just migrate it automatically to a String depends on the server version

* remove: removed TODO comment from WrapperPlayClientChatCommand and fixed `@Nullable` usage

* fix: fixed `@Nullable` usage in WrapperPlayClientChatMessage

* fix: fixed raw generic usage

* feat: added ClientVersion$is(MultiVersion version, ClientVersion target)

* fix: fixed JavaDocs for ServerVersion$is and ClientVersion$is

* feat: fixed code-style in ServerVersion

* feat: added missing DARKNESS PotionType

* feat: added missing EARTH, WIND, WATER and FIRE enums in PaintingType class
feat: added width and height values to PaintingType class

* feat: DARKNESS PotionType should use id 33 and not 32

* feat: renamed `MultiVersion` to `VersionComparison` as it's easier to understand this way

* feat: added missing JavaDoc to `setPreviousSignature` in `WrapperPlayServerPlayerChatHeader`

* WrapperPlayServerChatMessage had a lot of changes in 1.19.1 that we missed. Considering another way as it won't be too easy to abstract this all. Considering a similar approach to our chunk readers.

* To summarize this push, we rewrote the outgoing chat wrapper.

PacketWrapper appropriately named methods that have to do with readLastSeenMessages and added the true readLastSeenMessages;

WrapperPlayServerChatMessage had many changes in 1.19.1 so we decided to go with a different approach of implementing it and decided to go with a recode.
We have chat processors (readers & writers) which implement readers and writers for various versions. We have a chatmessage class which contains fields available on every single version and has subclasses which contain fields for their own version. Cast the chat message to get fields for specific versions. (Kinda like how BaseChunks are implemented)

* getMotd() -> getMOTD(), its sort of a convention to capitalize abbreviations here. Same we do for getUUID() and other stuff.

Also why not make the motd getter nullable, atleast as a response to the issue that complained about optionals?

* Little comment added to chat message, just to remind myself if I look back at it.

* Comment added to PaintingType to change it to a registry in the future.

* feat: cleaned up ChatMessage and its classes + ChatMessageProcessor and its implemented classes

* feat: added `getType` and `setType` and just removed the `@Deprecated` annotation

* Added missing FilterMask in 1.19.1 chat processor

* Minor additions to FilterMask

Co-authored-by: retrooper <retrooperdev@gmail.com>
2022-07-28 01:35:55 +02:00
retrooper 64ae9bfe27 Merge pull request #375 from NoJokeFNA/feat/update-jigsaw-block-wrapper
Added WrapperPlayClientUpdateJigsawBlock
2022-07-28 00:39:40 +02:00
retrooper 7b028f61d6 Optimized WrapperPlayClientUpdateJigsawBlock. It was added in 1.14, no point accounting for 1.7 protocol specialities? 2022-07-28 00:37:30 +02:00
retrooper 5d3f2105f0 Remove small debug 2022-07-27 16:13:05 +02:00
retrooper a4c57cf41c Made packetevents a snapshot version on nexus 2022-07-27 08:56:28 +02:00
retrooper e8fa6d793f Minor fix 2022-07-26 22:36:10 +02:00
retrooper 8fa6c3ad1e Don't use nexus snapshot repo I guess? 2022-07-26 22:30:34 +02:00
retrooper 2044657fb6 Last nexus fix xd 2022-07-26 22:25:37 +02:00
retrooper 8c216d0aa6 Apparently we cannot publish twice. 2022-07-26 22:24:06 +02:00
retrooper b80f22bf08 Another nexus fix 2022-07-26 22:22:09 +02:00
retrooper 4b0414c61b Fixes for nexus repo 2022-07-26 22:18:42 +02:00
retrooper 3c43382148 Attempting rebuild for Nexus repository 2022-07-26 22:03:55 +02:00
retrooper 00e081fcad ProtocolPacketEvent#getFullBufferClone to assist users attempting to delay packets. 2022-07-26 18:13:24 +02:00
retrooper 8cc8e5f171 Minor change to terminate. 2022-07-26 16:51:23 +02:00
retrooper b449205b6f Unregister listeners on termination to avoid duplicate packet listeners. 2022-07-26 16:32:09 +02:00
retrooper bbe88eba3d Attempting nexus repo fixes. 2022-07-25 19:33:56 +02:00
retrooper f271778905 Properly publish dependencies to Nexus repository. 2022-07-25 19:25:04 +02:00
retrooper fdefa91208 Minor changes 2022-07-25 19:09:44 +02:00
retrooper 909eb7cde3 Don't minimize jar to allow jenkins builds to contain all wrappers(even unused ones). 2022-07-25 19:08:30 +02:00
retrooper 1b3598182b Fix WrapperPlayServerChatMessage for versions below 1.16. 2022-07-25 18:45:38 +02:00
MWHunter 031d190da2 Make shulker boxes exceed full cube 2022-07-24 18:47:53 -05:00
MWHunter 744cb05253 Follow vanilla restrictions on plugin messages 2022-07-22 17:45:21 -05:00
MWHunter b1b2b10ee5 Try fixing edge case of velocity being off by 1 2022-07-21 18:30:46 -05:00
MWHunter 6efb6aebdf Set mud brick wall as exceeding cube 2022-07-20 18:25:09 -05:00
MWHunter a633c2558a Fix mapping inconsistencies in 1.12 2022-07-20 18:22:14 -05:00
retrooper 88cd3bea89 Remove PublicKey from being stored in User. 2022-07-18 11:57:57 +02:00
retrooper 1ec83d1398 Optimize WrapperLoginServerLoginSuccess 2022-07-18 11:14:08 +02:00
retrooper adf46aaeca I think this should fix SpoofMC bots? 2022-07-18 08:26:40 +02:00
retrooper 43669d3652 Support connections that aren't necessarily Epoll or Nio. (there is your IO_URING fix) 2022-07-18 08:23:23 +02:00
retrooper bc356c6daf Improved exception handling. 2022-07-14 10:51:06 +02:00
MWHunter b090424510 Fix explosion packet being off by one in negative coordinates pre-1.14 2022-07-11 21:33:05 -05:00
MWHunter 3fd2b883de Fix ItemTypes capitalization 2022-07-10 12:54:09 -05:00
retrooper e3e29ed79b Deprecate legacy Dimension constructor. 2022-07-06 22:38:53 +02:00
retrooper be4e820c0a Fixes to WrapperPlayServerRespawn for 1.15-1.16? 2022-07-06 22:36:37 +02:00
retrooper d7e1aa2161 Hopefully this breaks nothing but we need to load packet type mappings before the injector injects. As a rare scenario where the main-thread (when the plugin enables) and the netty threads both notice the mappings aren't loaded, they load them simultaneously which isn't handled well. 2022-07-06 21:29:13 +02:00
retrooper f214cc54c6 Fix WrapperPlayServerParticle for 1.19 2022-07-06 15:22:24 +02:00
MWHunter 31157da8bb Add hashcode functions to Vector3 2022-07-05 19:44:56 -05:00
retrooper d54baa4293 Hopefully all works now. 2022-07-03 06:49:58 +02:00
retrooper e3e4ac027f Merge pull request #446 from retrooper/revert-439-feat/improvements
Revert "Cleaned up and improved some wrappers"
2022-07-03 06:48:38 +02:00
retrooper c8023cd828 Revert "Cleaned up and improved some wrappers" 2022-07-03 06:47:53 +02:00
retrooper 9770948c45 Fixed PacketTransformationUtil 2022-07-01 22:10:35 +02:00
retrooper 6b62e2152f EquipmentSlot renamed some enum constats to make more sense. 2022-07-01 22:05:27 +02:00
retrooper 88a223e2d9 Merge pull request #439 from NoJokeFNA/feat/improvements
Cleaned up and improved some wrappers
2022-07-01 22:02:33 +02:00
Julian 74f28ad610 feat: improved EquipmentSlot 2022-07-01 11:00:56 +02:00
Julian 085b37b2ed remove: removed debug 2022-06-30 22:51:12 +02:00
NoJokeFNA ea273ba4b6 feat: some more cleanup 2022-06-29 13:07:32 +02:00
NoJokeFNA f3b14030b1 feat: some cleanup 2022-06-28 11:33:04 +02:00
Julian c565d94d41 Merge branch '2.0' into feat/improvements 2022-06-27 21:58:10 +02:00
retrooper d054164a4b User#sendMessage doesn't look awkward on 1.19 anymore and few minor optimizations or fixes? 2022-06-27 19:44:16 +02:00
Julian cd0679c3b2 Merge remote-tracking branch 'origin/feat/improvements' into feat/improvements 2022-06-27 19:18:59 +02:00
Julian 1be60149f9 feat: added missing data 2022-06-27 19:18:52 +02:00
Julian b48e271ced Merge branch '2.0' into feat/improvements 2022-06-27 19:15:21 +02:00
retrooper 2bcb1dcb90 Fix WrapperPlayClientPluginMessage 2022-06-27 18:55:12 +02:00
retrooper c8d472beb7 Removed WrapperPlayClientPluginMessage generics, channel name always string. 2022-06-27 18:22:11 +02:00
retrooper 18689e4f00 Fixed WrapperPlayServerJoinGame 2022-06-27 18:09:20 +02:00
retrooper 440c73431e Fixed WrapperPlayServerRespawn for 1.19, my bad but i wonder why it doesn't work? 2022-06-27 17:59:21 +02:00
retrooper de634687fa Fixed WrapperPlayServerRespawn for 1.19. 2022-06-27 17:52:02 +02:00
retrooper 6d0a753d2d Remove debugs. 2022-06-27 17:45:10 +02:00
retrooper c43b24c0db Attach public key to user handle for us to verify chat messages. (I hope this is the right key as our message verifier doesn't work rn) 2022-06-27 17:42:00 +02:00
retrooper 7df7ffcc69 Some cleanup to the component wrappers, use the abstraction we have to avoid code duplication. 2022-06-27 17:27:55 +02:00
MWHunter cca73eabe0 Don't do synchronous web requests on join event 2022-06-26 23:14:28 -05:00
MWHunter db7f8d9cbd allow plugins to exceed server address max length 2022-06-25 19:14:32 -05:00
Julian a53ff85a66 change: cleaned up a little more 2022-06-23 19:20:32 +02:00
NoJokeFNA 46a7f39be6 change: improved JavaDocs a bit 2022-06-23 14:24:25 +02:00
NoJokeFNA 89801adc76 fix: fixed compilation errors 2022-06-23 11:06:30 +02:00
Julian a405880a89 feat: cleaned up WrapperPlayClientEntityAction and WrapperPlayClientInteractEntity 2022-06-23 09:04:56 +02:00
Julian bd5c4207bc feat: cleaned up WrapperPlayClientAnimation 2022-06-23 09:02:12 +02:00
Julian 3564bc56e4 fix: fixed WrapperPlayServerParticle on higher server versions 2022-06-22 21:47:54 +02:00
Julian 6f18f867c0 feat: cleaned up and improved wrappers 2022-06-22 18:42:19 +02:00
retrooper 1ae1b5abf1 Merge pull request #353 from NoJokeFNA/feat/recipe-wrappers
Added WrapperPlayClientCraftRecipeRequest & WrapperPlayServerCraftRecipeResponse created
2022-06-22 14:59:27 +02:00
MWHunter f8a920a2cb Fix compilation 2022-06-21 20:31:12 -05:00
Julian b497efc0c1 Merge branch '2.0' into feat/improvements 2022-06-21 22:37:12 +02:00
Julian dfb36a48f9 feat: cleaned up WrapperPlayServerTabComplete 2022-06-21 22:33:34 +02:00
retrooper 0e471c665d Merge pull request #428 from NoJokeFNA/fix/sound-wrappers
[1.19] Fix sound wrappers
2022-06-21 22:23:16 +02:00
Julian f76b2f7c72 Merge branch '2.0' into fix/sound-wrappers 2022-06-21 22:18:20 +02:00
retrooper 4915d7d4a3 Merge pull request #433 from NoJokeFNA/change/cleanup
Refactored WrapperPlayServerChatMessage and cleaned up some classes
2022-06-21 22:12:27 +02:00
Julian 16e3861b41 change: changed signedChatContent to chatContent 2022-06-21 21:51:19 +02:00
NoJokeFNA b57855b6ba remove: removed $multiOptional as it was useless 2022-06-21 20:19:03 +02:00
MWHunter 6edd19e416 Mark mangrove fences as exceeds full cube 2022-06-20 18:43:16 -05:00
Julian 4ef61c71bf Merge remote-tracking branch 'origin/feat/recipe-wrappers' into feat/recipe-wrappers 2022-06-19 19:44:41 +02:00
Julian 6a5f0d3e50 change: cleaned up code 2022-06-19 19:44:34 +02:00
Julian 9b20221587 Merge branch '2.0' into feat/recipe-wrappers 2022-06-19 19:36:40 +02:00
NoJokeFNA 70b540e67f feat: added WrapperPlayClientUpdateJigsawBlock 2022-06-19 18:24:32 +02:00
Julian f76b26e5d7 remove: removed OptionalLong usage 2022-06-19 18:04:48 +02:00
DefineOutside 19b6d3c999 Update BlockTags.java 2022-06-18 16:24:05 -05:00
Julian 49955e2dc8 Merge remote-tracking branch 'origin/change/cleanup' into change/cleanup 2022-06-16 18:22:23 +02:00
Julian cd6a4d0cd2 feat: cleaned up a little more 2022-06-16 18:22:00 +02:00
Julian 4f1cd6c8bc Merge branch '2.0' into change/cleanup 2022-06-16 14:06:01 +02:00
retrooper 29fe12ef57 Merge pull request #427 from NoJokeFNA/fix/set-breacon-effect-wrapper
[1.19] Fixed WrapperPlayClientSetBeaconEffect
2022-06-16 07:48:53 +02:00
retrooper 5116d62488 Merge pull request #359 from NoJokeFNA/feat/set-recipe-book-state-wrapper
Added WrapperPlayClientSetRecipeBookState
2022-06-16 07:47:30 +02:00
retrooper 6387309f01 WrapperPlayClientChatMessage fix message data optional being null. 2022-06-16 07:41:06 +02:00
MWHunter bb27307e25 Fix via mappings weirdness for modern block mappings 2022-06-15 21:01:37 -05:00
MWHunter 0ad3baeea4 Add mangrove logs to block tags 2022-06-14 23:22:41 -05:00
MWHunter 635d0f2a7c comment out debug listener 2022-06-14 23:03:20 -05:00
Julian 5f49f63e8f feat: refactored all Wrappers
feat: recoded WrapperPlayServerScoreboardObjective
feat: added little TODO
2022-06-14 03:34:10 +02:00
Julian 45dd54dfb3 change: changed read-/writeEffect to read-/writeOptionalEffect 2022-06-14 03:23:49 +02:00
Julian bcf35813d8 fixed: fixed WrapperPlayServerEntitySoundEffect and WrapperPlayServerSoundEffect 2022-06-12 04:18:14 +02:00
DefineOutside 327b514216 Merge pull request #431 from NoJokeFNA/feat/new-wrappers
[1.19] Added new Chat Preview-/, Server Data-/ and Chat Command Wrappers
2022-06-11 18:24:57 -05:00
Julian 96f67109fe feat: added new Chat Preview-/, Server Data-/ and Chat Command Wrappers
feat: added `$readOptional(S value, Consumer<S> writeValue)` and `$writeOptional(S value, Consumer<S> writeValue)`
2022-06-12 01:19:15 +02:00
terrarier2111 50d42f9fc9 Merge pull request #387 from NoJokeFNA/feat/spawn-weather-entity
Added WrapperPlayServerSpawnWeatherEntity
2022-06-11 23:37:45 +02:00
NoJokeFNA e248a47a1f feat: added WrapperPlayServerSpawnWeatherEntity
feat: added WrapperPlayServerSpawnWeatherEntity
2022-06-11 23:36:18 +02:00
MWHunter 5d3e4bd0f8 Refactor dimension code 2022-06-11 16:14:43 -05:00
MWHunter 3b3f0a84be Track world height because it is required for world reader 2022-06-11 15:24:26 -05:00
Julian 9b55e982b3 change: improved readability 2022-06-11 21:42:11 +02:00
MWHunter 712f1013f4 mangrove doors are not stairs 2022-06-11 14:41:56 -05:00
Julian eb4bab70d1 fix: fixed WrapperPlayClientSetBeaconEffect for 1.19 2022-06-11 20:38:46 +02:00
MWHunter d970c4e020 Fix error writing bytes 2022-06-11 12:07:38 -05:00
MWHunter 825157f998 Fix 1.19 entity effect and player info packet 2022-06-11 11:49:04 -05:00
MWHunter c41f1797e8 join game readability improvements 2022-06-10 20:38:06 -05:00
MWHunter f871e71823 Fix respawn packet 2022-06-10 20:36:08 -05:00
MWHunter a270b515d2 Fix player digging packet on 1.19 2022-06-10 19:38:05 -05:00
MWHunter b90920e63a Fix 1.13 entity metadata mappings 2022-06-10 19:22:50 -05:00
retrooper 4def9c7ab1 Fix user sendmessage on 1.19 (use system chat message wrapper packet)
Fix WrapperPlayServerRespawn for 1.19.
2022-06-10 21:04:12 +02:00
retrooper 79f102ecc5 Compilation error fix 2022-06-10 20:10:32 +02:00
retrooper 1bdc56d251 Fix WrapperLoginClientLoginStart on 1.19. 2022-06-10 20:07:55 +02:00
retrooper d1d793f9e7 SpigotDataHelper -> SpigotConversionUtil
WrapperPlayServerChatMessage completed,
WrapperPlayServerSystemChatMessage created,
Minor bug fixes to other component wrappers.
2022-06-10 20:00:08 +02:00
MWHunter 1c661f0a5d Merge remote-tracking branch 'origin/dev/1.19' into 2.0 2022-06-10 00:40:14 -05:00
MWHunter 9db70222c0 Merge branch 'dev/1.19' into 2.0
# Conflicts:
#	api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerJoinGame.java
2022-06-10 00:14:39 -05:00
MWHunter 42b16f1fbd Don't write empty buffers 2022-06-09 21:33:30 -05:00
MWHunter 34d4fac6e8 actually fix 1.19 item type mappings 2022-06-09 20:39:42 -05:00
MWHunter f63a290d34 minor optimization 2022-06-09 20:38:34 -05:00
MWHunter 68867c135d Fix item types for 1.19 2022-06-09 20:09:58 -05:00
retrooper 7ae55731fb Minor changes, but still cant verify messages :c 2022-06-09 20:20:55 +02:00
retrooper cd24067ce7 Added 1.19 entity poses. 2022-06-09 19:13:58 +02:00
retrooper 3f1f65e4a3 Merge remote-tracking branch 'origin/2.0' into dev/1.19
# Conflicts:
#	api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerJoinGame.java
2022-06-09 19:08:45 +02:00
MWHunter 0095487773 Fix swapped blocking and solid on 1.19 blocks 2022-06-08 22:11:54 -05:00
MWHunter 7d2e67b95d Fix 1.19 entity type mappings 2022-06-08 22:00:54 -05:00
MWHunter b0db7045f4 Data is a varint in 1.19 2022-06-08 21:47:10 -05:00
MWHunter bfdab3a518 1.19 spawn entity packet support 2022-06-08 21:10:18 -05:00
MWHunter fc49c374bf 1.19 join game packet support 2022-06-08 20:58:58 -05:00
MWHunter 4b776ca7bf Register 1.19 entity data types 2022-06-08 20:38:41 -05:00
MWHunter 0f58efa3cc Support for 1.19 block data type values 2022-06-08 20:37:21 -05:00
MWHunter 0d3a8e5410 1.19 entity data types 2022-06-08 19:53:54 -05:00
MWHunter c6d3d72ce9 Add missing MANGROVE_STAIRS state 2022-06-08 19:39:26 -05:00
MWHunter fc651c65ad Add support for sequences in existing wrappers, add WrapperPlayServerAcknowledgeBlockChanges 2022-06-08 19:12:51 -05:00
MWHunter 9b86427884 1.19 SpigotReflectionUtil support 2022-06-08 19:03:29 -05:00
retrooper 849713eaea Unable to verify messages? 2022-06-08 23:54:06 +02:00
retrooper 52db6d7b6a Working on cryptography additions in 1.19 update for the secure chat system.
Debugs enabled and join game needs to be updated for 1.19 support so some parts are commented out.

Chat messages cause problems.
2022-06-08 22:52:39 +02:00
retrooper 0434cd6bf8 Fix packet type mappings for CHAT_MESSAGE. 2022-06-08 17:57:36 +02:00
MWHunter dbab8591bf Add bloom to block data types 2022-06-07 21:52:32 -05:00
MWHunter 065649d1df Try fixing trying to log in 2022-06-07 21:49:31 -05:00
MWHunter 2d2e0cdfeb Add swift sneak enchantment 2022-06-07 21:46:33 -05:00
MWHunter c3e8f307b7 Fix 1.19 block mappings 2022-06-07 21:33:15 -05:00
MWHunter e03f1ef713 Update BlockTags and add a few missing StateTypes 2022-06-07 21:10:31 -05:00
MWHunter eb4f73b582 ItemTypes and StateTypes variables and data 2022-06-07 20:48:53 -05:00
MWHunter 1609d1c2b0 1.19 entity types mappings 2022-06-07 19:53:45 -05:00
MWHunter 3480620eca 1.19 particle type mappings 2022-06-07 19:42:05 -05:00
MWHunter e694af304e Fix enchantment type mappings on 1.19 2022-06-07 19:33:39 -05:00
MWHunter 581c04e66e 1.19 enchantment types 2022-06-07 19:30:51 -05:00
MWHunter 2e737288ef 1.19 wrapped block state 2022-06-07 19:27:55 -05:00
retrooper 18a1d51c19 Fix number format exception when parsing very outdated protocolsupport build versions. 2022-06-07 23:14:45 +02:00
retrooper db7ec7fe95 Fixed compilation errors. 2022-06-07 23:10:26 +02:00
retrooper d619546735 Reverting the rename of WrapperPlayServerChatMessage. Fixes for some packet type mappings. CHAT_MESSAGE changed and SYSTEM_MESSAGE is a new packet. 2022-06-07 23:09:08 +02:00
retrooper b78b449895 1.19 packet id mappings fixed/complete and now used. 2022-06-07 22:59:41 +02:00
retrooper f53198aec5 Remove duplicate license notice. 2022-06-07 22:46:44 +02:00
retrooper fa1728210a Correct packet ids mappings. 2022-06-07 22:44:27 +02:00
retrooper 90674cefc4 Ordinary CHAT_MESSAGE -> SYSTEM_CHAT_MESSAGE. Please use that if you want the ordinary messages that don't have any cryptography. On new versions those are the system message only but they still have no cryptography. 2022-06-07 19:01:48 +02:00
retrooper 24d4a21007 Working on 1.19 support, need to work on wrappers. 2022-06-07 18:30:42 +02:00
retrooper b4ad4e831d Minor changes. 2022-06-06 11:49:55 +02:00
retrooper 886d872241 Some cleanup in ProtocolManager 2022-06-06 11:44:46 +02:00
retrooper 0ef01b868e Allow packet wrappers to truly be reused. 2022-06-06 11:36:24 +02:00
retrooper 46f89771a5 Remove unnecessary async send/receive methods in our API. 2022-06-06 11:34:09 +02:00
MWHunter 055f473964 expose getEnchantmentsTagName 2022-06-05 19:26:30 -05:00
MWHunter f3850dab24 Fix incomplete client settings copy method 2022-06-05 11:23:10 -05:00
MWHunter 86870c40a5 Fix 1.8 chunk reader exception 2022-06-05 10:58:40 -05:00
MWHunter dbc33f9fe4 Fix leak with multiple packetevents 2.0 instances 2022-06-05 10:47:52 -05:00
threadexception 1f95fda03c Cleanup many enums 2022-06-04 11:18:06 +02:00
MWHunter 1724f54b12 Fix https://github.com/retrooper/packetevents/issues/416 2022-06-03 11:43:55 -05:00
threadexception 4b0132ed90 Rewrite SkinSection 2022-06-02 18:19:42 +02:00
retrooper d219faafd0 Enforce ProtocolSupport 1.18.1-1 or newer. 2022-06-01 21:25:24 +02:00
retrooper 6d19f60049 Add little comment. 2022-06-01 20:38:23 +02:00
retrooper a8f1b23769 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-06-01 20:33:53 +02:00
retrooper 89cb93be67 Remove paper injector. (Not needed anymore)
Injector changes depending on netty version instead of server version.
2022-06-01 20:33:31 +02:00
MWHunter bfe9aba3a8 PacketEncoder/Decoder -> PacketEventsEncoder/Decoder 2022-05-31 15:52:13 -05:00
MWHunter 5265ddd27c Remove duplicate Vector3i code 2022-05-31 15:46:39 -05:00
retrooper 5e118f5e17 Remove debugs? 2022-05-31 21:36:19 +02:00
Julian a522e8262a Fixed code-style 2022-05-31 21:30:54 +02:00
retrooper 028bfd8ada Merge pull request #400 from NoJokeFNA/fix/code-style
Fixed code-style
2022-05-31 21:16:50 +02:00
NoJokeFNA d1ba1b8831 remove: removed @Nullable from UUID as it can't be null any longer 2022-05-31 09:18:52 +02:00
NoJokeFNA 2a7c79235d feat: applied retrooper changes 2022-05-31 09:14:47 +02:00
MWHunter ebaf94a5ec expose internal fields in DataPalette 2022-05-30 18:08:44 -05:00
retrooper 5c9b930737 Merge pull request #368 from NoJokeFNA/feat/spawn-experience-orb-wrapper
Added WrapperPlayServerSpawnExperienceOrb
2022-05-29 14:10:05 +02:00
retrooper 9483582479 Merge pull request #360 from NoJokeFNA/feat/set-displayed-recipe-wrapper
Added WrapperPlayClientSetDisplayedRecipe
2022-05-29 14:08:01 +02:00
retrooper cd7b23a537 Merge pull request #392 from NoJokeFNA/feat/update-entity-nbt
Added WrapperPlayServerUpdateEntityNBT
2022-05-29 14:04:39 +02:00
retrooper 97609976e4 Update README.md 2022-05-29 13:51:03 +02:00
retrooper 4262f1f9cd More changes to README. 2022-05-29 13:45:18 +02:00
retrooper eb6237d913 Minor changes to README. 2022-05-29 13:35:12 +02:00
retrooper fcf2edefe8 Merge pull request #409 from AbhigyaKrishna/2.0
Adventure legacy serialization patches
2022-05-29 13:18:20 +02:00
Abhigya a7a9ef52f0 Adventure Legacy serialization patches 2022-05-29 14:47:23 +05:30
retrooper d8ad50fcf8 Progress on bungee support. 2022-05-26 14:42:12 +02:00
retrooper 3a974ab51f Merge pull request #372 from NoJokeFNA/feat/entity-sound-effect-wrapper
Added WrapperPlayServerEntitySoundEffect
2022-05-26 11:12:33 +02:00
retrooper 9834830bda Remove redundant bytebuf import. 2022-05-25 22:18:26 +02:00
retrooper e673558179 ByteBufHelper.capacity methods added. So people using netty directly just for that can use our api. 2022-05-25 22:16:01 +02:00
retrooper bd17353576 Merge pull request #401 from NoJokeFNA/feat/select-advancement-tab-wrapper
Added WrapperPlayServerSelectAdvancementTab
2022-05-24 21:40:42 +02:00
NoJokeFNA 4f0403d315 remove: removed hasId getter and setter 2022-05-24 19:15:06 +02:00
MWHunter 0232e7b212 Automatically replace minecraft: in getByString 2022-05-24 10:36:15 -05:00
retrooper 68655dd92b Merge pull request #385 from NoJokeFNA/feat/set-compression-wrapper
Added WrapperPlayServerSetCompression
2022-05-24 17:33:25 +02:00
retrooper 28ffd08fbd Merge pull request #369 from NoJokeFNA/feat/update-view-position-wrapper
Added WrapperPlayServerUpdateViewPosition
2022-05-24 17:31:09 +02:00
MWHunter 4b92eb7912 init internal bukkit listener 2022-05-22 22:54:29 -05:00
MWHunter 6f76822785 InternalBukkitListener 2022-05-22 22:54:11 -05:00
MWHunter 165bc85dfa Revert "Fix memory leak"
This reverts commit fdcb42caf2.
2022-05-22 22:25:46 -05:00
MWHunter fdcb42caf2 Fix memory leak 2022-05-22 22:09:53 -05:00
NoJokeFNA 7d5fcb22a8 change: changed String to ResourceLocation (identifier) 2022-05-22 14:41:25 +02:00
NoJokeFNA c2beac9bfa remove: removed useless version check as it got introduced in 1.14 2022-05-22 14:40:20 +02:00
MWHunter 49344d0f3c Revert "Make PacketEvents 2.0 see its own existing decoder"
This reverts commit 18b6ddca70.
2022-05-22 05:37:08 -05:00
MWHunter 18b6ddca70 Make PacketEvents 2.0 see its own existing decoder 2022-05-21 20:21:25 -05:00
MWHunter e901b5dd64 Fix 1.8 chunk reader 2022-05-21 19:49:55 -05:00
MWHunter bf11a02d44 Remove unnecessary code dealing with removing players 2022-05-21 19:19:06 -05:00
MWHunter 15f0295142 Revert 5bf2daa7 2022-05-21 19:13:43 -05:00
MWHunter 5c665053d2 100 MB -> 1 MB idle memory usage in WrappedBlockState 2022-05-21 18:56:07 -05:00
MWHunter cddf378b51 Unload file mappings when done initializing classes 2022-05-21 17:14:47 -05:00
DefineOutside 96bfb98c87 Merge pull request #389 from NoJokeFNA/feat/nbt-query-response-wrapper
Added WrapperPlayServerNBTQueryResponse
2022-05-21 16:35:52 -05:00
DefineOutside d0f85d69ab Merge pull request #363 from NoJokeFNA/feat/update-command-block-wrapper
Added WrapperPlayClientUpdateCommandBlock and WrapperPlayClientUpdateCommandBlockMinecart
2022-05-21 16:29:53 -05:00
MWHunter 3374827e66 Fix createUniversalPacketWrapper 2022-05-21 16:08:37 -05:00
MWHunter 96d8fc6d21 Fix rare race condition memory leak 2022-05-21 12:39:40 -05:00
MWHunter 1fd19db0f2 289 KB jar reduction 2022-05-21 10:43:20 -05:00
MWHunter 2ef717cd72 Unflip logic in PlayerManager 2022-05-20 23:10:26 -05:00
MWHunter 1868cee073 Fix memory leak with storing channels 2022-05-20 23:04:29 -05:00
MWHunter 351742e88e Clean up PlayerManagerImpl, fix memory leak 2022-05-20 22:55:06 -05:00
MWHunter bd67caaeb8 Prevent memory leak when sending packet to a closed channel 2022-05-20 22:33:06 -05:00
MWHunter 0f39521750 Prevent sending packets that don't exist in a version 2022-05-20 22:32:32 -05:00
MWHunter 7fde4a379a Vector3d, f, i utility method to add BlockFace 2022-05-20 22:18:47 -05:00
MWHunter 5cc7e6f2bc Improve WrapperPlayClientClickWindow naming 2022-05-20 22:06:01 -05:00
MWHunter f2f4a8d62b Convert ProtocolManager to using UUID's 2022-05-20 21:50:35 -05:00
MWHunter 16f9eb32c9 Lazily allocate packet wrapper buffers, reusable wrappers 2022-05-20 21:38:15 -05:00
NoJokeFNA 3567b7d735 feat: added WrapperPlayServerSelectAdvancementTab 2022-05-20 17:39:39 +02:00
NoJokeFNA 23a181c33a fix: code-style... gosh 2022-05-20 14:56:39 +02:00
NoJokeFNA 74b6bfca28 fix: fixed WrapperPlayServerSpawnPainting 2022-05-20 14:55:54 +02:00
NoJokeFNA ef1074e7ba fix: fixed PaintingType class 2022-05-20 14:53:37 +02:00
NoJokeFNA b02d7a3df2 Merge branch '2.0' into fix/code-style
# Conflicts:
#	api/src/main/java/com/github/retrooper/packetevents/protocol/world/PaintingType.java
#	api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerSpawnPainting.java
2022-05-20 14:50:18 +02:00
NoJokeFNA 6c3d6f25ac fix: code-style 2022-05-20 14:48:32 +02:00
Julian de4b9887b7 Update WrapperPlayServerUpdateEntityNBT.java 2022-05-20 12:02:53 +02:00
retrooper b7c9eabf8f Merge pull request #396 from NoJokeFNA/feat/time-update-wrapper
Fixed code-style
2022-05-19 23:00:03 +02:00
NoJokeFNA ed43c51428 fix: fixed code-style 2022-05-19 19:10:32 +02:00
NoJokeFNA 69bc454cc0 fix: fixed code-style 2022-05-19 19:02:00 +02:00
NoJokeFNA 83b87cf9cb fix: fixed code-style 2022-05-19 18:59:33 +02:00
MWHunter 0f061764e6 Fix another memory leak 2022-05-19 11:19:26 -05:00
NoJokeFNA 77a6b8152e fix: fixed code-style 2022-05-19 18:17:39 +02:00
NoJokeFNA 6a5e76512f fix: fixed code-style 2022-05-19 18:17:06 +02:00
NoJokeFNA 24bad668bd fix: fixed code-style 2022-05-19 18:11:56 +02:00
MWHunter a670961b99 Reliably call disconnect event using netty API 2022-05-19 00:14:05 -05:00
retrooper f3896d3c78 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-05-18 19:45:29 +02:00
retrooper 04e9e57dad Fixed WrapperPlayServerJoinGame for 1.14.4 2022-05-18 19:45:09 +02:00
MWHunter 2bccff6ae6 Fix player info wrapper 2022-05-15 22:50:53 -05:00
NoJokeFNA 3afa857965 change: correct Optional usage (for now) -> reduce overhead for plain fields 2022-05-15 18:00:05 +02:00
NoJokeFNA 3441da2bd5 change: reformatted code with current code-style 2022-05-15 17:56:23 +02:00
NoJokeFNA 898972d040 change: use MathUtils#floor instead of Math#floor 2022-05-15 17:55:46 +02:00
NoJokeFNA b0d0f18da2 change: reformatted code with current code-style 2022-05-15 17:54:24 +02:00
NoJokeFNA 1d3a828f55 feat: added WrapperPlayServerUpdateEntityNBT 2022-05-15 16:24:24 +02:00
NoJokeFNA 310bb1ea10 remove: removed $toString as it was only used for debugging 2022-05-15 15:48:09 +02:00
NoJokeFNA 7f8deb280a feat: added WrapperPlayServerNBTQueryResponse 2022-05-15 15:47:17 +02:00
retrooper 3204527b6f Paper injector won't be used if ProtocolSupport is on the server. 2022-05-15 13:11:38 +02:00
NoJokeFNA 0354e2b5fc change: use MathUtils class instead of creating own methods 2022-05-13 20:31:51 +02:00
NoJokeFNA 07dac7c20e change: code-style 2022-05-13 20:30:07 +02:00
NoJokeFNA bf09ad27b9 feat: added WrapperPlayServerSetCompression 2022-05-13 20:29:19 +02:00
NoJokeFNA af3bbb3db8 change: cleaned up WrapperLoginServerSetCompression 2022-05-13 20:29:02 +02:00
retrooper f520af9250 Few comments. 2022-05-13 17:39:53 +02:00
Julian df590b7083 Merge branch '2.0' into feat/recipe-wrappers 2022-05-13 17:36:06 +02:00
retrooper 9ec7b8d776 Merge pull request #381 from NoJokeFNA/feat/entity-movement-wrapper
Added WrapperPlayServerEntityMovement
2022-05-13 17:34:07 +02:00
retrooper 18580ced5a Check for updates by default. 2022-05-13 17:32:47 +02:00
retrooper 8dc6b1be29 Add more license notices wherever missing. 2022-05-13 16:36:22 +02:00
retrooper 649839c539 Improve WrapperPlayServerSpawnPainting and bring the type into one form. the old string form is not necessary and complicates the usage of the wrapper. 2022-05-13 16:35:24 +02:00
retrooper 7401b9bbb0 Merge pull request #357 from NoJokeFNA/feat/open-sign-editor-wrapper
Added WrapperPlayServerOpenSignEditor
2022-05-12 22:12:10 +02:00
retrooper 068967fd74 Merge pull request #356 from NoJokeFNA/fix/entity-patch
Fix SpigotDataHelper#fromBukkitEntityType returning null on modern versions
2022-05-12 22:11:41 +02:00
retrooper 20c07143aa Merge pull request #366 from NoJokeFNA/feat/camera-wrapper
Added WrapperPlayServerCamera
2022-05-12 22:11:16 +02:00
retrooper fafa6e5191 Merge pull request #367 from NoJokeFNA/feat/spawn-painting-wrapper
Added WrapperPlayServerSpawnPainting
2022-05-12 22:10:02 +02:00
retrooper 327a986944 Merge pull request #371 from NoJokeFNA/feat/spawn-position
Added WrapperPlayServerSpawnPosition
2022-05-12 22:07:25 +02:00
NoJokeFNA 666cc8f81b change: hopefully resolve soon merge-conflict 2022-05-12 15:11:46 +02:00
NoJokeFNA 7c81ae2fa4 fix: fixed 1.7.x support 2022-05-12 12:44:45 +02:00
NoJokeFNA 8224019e23 change: code-style 2022-05-12 12:42:01 +02:00
NoJokeFNA b334d82e76 remove: removed legacy code 2022-05-12 12:24:32 +02:00
NoJokeFNA e28f416746 fix: fixed 1.7.x support (again) 2022-05-12 12:21:32 +02:00
NoJokeFNA cd821c3d86 fix: fixed 1.7.x support 2022-05-12 12:19:39 +02:00
NoJokeFNA 42fd096ac3 fix: fixed 1.7.x support 2022-05-12 12:10:46 +02:00
NoJokeFNA bff4a10355 change: replaced nullabilities with Optionals 2022-05-11 20:57:03 +02:00
NoJokeFNA bd52a7856d change: replaced nullabilities with Optionals 2022-05-11 20:54:45 +02:00
NoJokeFNA 01fb89f378 change: changed possible nullabilities to Optionals 2022-05-11 20:40:18 +02:00
NoJokeFNA 4abe76816d feat: added WrapperPlayServerEntityMovement 2022-05-11 17:06:46 +02:00
NoJokeFNA e19283e387 remove: removed $toString method as it was only used for debug purposes 2022-05-11 13:42:42 +02:00
NoJokeFNA 03286746a0 remove: removed $toString method as it was only used for debug purposes 2022-05-11 13:42:18 +02:00
NoJokeFNA e7ce4dddec feat: added WrapperPlayServerEntitySoundEffect
change: improved code by a bit
2022-05-11 02:53:10 +02:00
NoJokeFNA cd9829bcae feat: added WrapperPlayServerSpawnPosition 2022-05-11 02:36:50 +02:00
NoJokeFNA 132f8d53a9 remove: removed $toString method as it was only used for debug purposes 2022-05-11 02:05:46 +02:00
NoJokeFNA abb74ab2cf feat: added WrapperPlayServerUpdateViewPosition 2022-05-11 02:04:43 +02:00
NoJokeFNA 3d97cd1aa0 feat: added WrapperPlayServerSpawnExperienceOrb 2022-05-11 01:54:27 +02:00
NoJokeFNA 809f712e80 feat: added WrapperPlayServerSpawnPainting, as well as two other classes which might be helpful for the future for other classes 2022-05-11 01:25:12 +02:00
NoJokeFNA 88877c7874 feat: added WrapperPlayServerCamera 2022-05-11 00:44:10 +02:00
DefineOutside 749f17efbe Merge pull request #362 from NoJokeFNA/fix/missing-constructor-edit-book
Missing constructor in WrapperPlayClientEditBook
2022-05-10 17:39:09 -05:00
DefineOutside 3ef1b424b1 Merge pull request #365 from NoJokeFNA/feat/time-update-wrapper
Added WrapperPlayServerTimeUpdate
2022-05-10 17:38:40 -05:00
NoJokeFNA bd0185f825 feat: added WrapperPlayServerTimeUpdate 2022-05-11 00:36:15 +02:00
NoJokeFNA f86ed401b2 fix: added WrapperPlayClientUpdateCommandBlock and WrapperPlayClientUpdateCommandBlockMinecart 2022-05-10 23:45:55 +02:00
NoJokeFNA b9d01eb9d8 fix: added missing constructor as it was missing 2022-05-10 22:57:54 +02:00
NoJokeFNA 08a0d108b0 feat: added WrapperPlayClientSetDisplayedRecipe wrapper class 2022-05-10 01:21:52 +02:00
NoJokeFNA 30b3c20c80 feat: added WrapperPlayClientSetRecipeBookState wrapper class 2022-05-10 01:13:16 +02:00
NoJokeFNA d56885c3f9 feat: added WrapperPlayServerOpenSignEditor wrapper class 2022-05-09 23:47:35 +02:00
NoJokeFNA 822a52b5b8 fix: fixed e.g. SpigotDataHelper.fromBukkitEntityType(EntityType.ZOMBIE) always returning null on modern (1.13.x) server versions
Tested Server-Versions: 1.8.8, 1.13, 1.13.2, 1.14, 1.14.4, 1.15.2, 1.18.2
2022-05-09 23:25:48 +02:00
NoJokeFNA d8eb1d07f2 change: finished changes 2022-05-09 22:38:51 +02:00
NoJokeFNA 34956af6a2 change: removed the listener registration 2022-05-09 22:01:19 +02:00
NoJokeFNA 1f15d0ba20 feat: added WrapperPlayClientCraftRecipeRequest and WrapperPlayServerCraftRecipeResponse wrapper classes
With this pull request users can use two new wrappers that work fine - I think there is nothing more to explain.
It was tested with the server versions: 1.8.8, 1.12.2, 1.13, 1.13.2, 1.14.4, 1.15.2, 1.16.5 and 1.18.2
Client-Versions: 1.18.2, 1.16.5, 1.13
2022-05-09 21:54:10 +02:00
MWHunter c4798df9dc Fix WrappedBlockState on 1.16.3-1.16.5 2022-05-08 20:47:04 -05:00
retrooper a1fdc00a01 Remove further debug. 2022-05-08 23:04:37 +02:00
retrooper d85e7a2b0f Removed bad compression util (recreating minecraft compression).
Removed debugs.
2022-05-08 23:04:00 +02:00
MWHunter c78727f15f Heavily optimize WrappedBlockState air 2022-05-08 10:29:45 -05:00
MWHunter dd1d85e3e4 WrappedBlockState performance improvements 2022-05-08 10:14:49 -05:00
retrooper e29c907188 Fixed WrapperStatusServerResponse constructor. 2022-05-08 11:45:32 +02:00
retrooper 450aec3191 Add license notice to all wrappers missing it. 2022-05-08 10:40:29 +02:00
MWHunter c672086b8f Add getters and setters to the two new wrappers 2022-05-07 11:23:28 -05:00
MWHunter ae3a3a795d WrapperPlayClientEditBook 2022-05-07 11:14:02 -05:00
MWHunter 2fa200b347 WrapperPlayServerOpenBook 2022-05-07 11:00:24 -05:00
MWHunter 7d750a42ab Fix copying over WrapperPlayClientBlockPlacement itemstack 2022-05-05 22:12:35 -05:00
retrooper f61f93a85d gramr 2022-04-27 19:50:06 +02:00
retrooper e0c38b59c1 Little documenting. 2022-04-27 19:19:27 +02:00
retrooper 198034ae67 Fixed post tasks for outgoing packets. They are now executed once the outgoing packet is successfully sent. 2022-04-27 19:17:48 +02:00
MWHunter 10107a14fc Fix last used wrapper breaking when wrappers are used more than 2 times 2022-04-24 17:27:15 -05:00
retrooper 0e18040bee Fixed sending packets while ProtocolSupport is present. 2022-04-24 23:19:29 +02:00
retrooper ab92d8bdd3 Fixed ProtocolSupport support 2022-04-24 23:00:22 +02:00
retrooper 6bf70f5b47 Fixed reloads on modern paper versions. 2022-04-24 22:56:16 +02:00
MWHunter 59dfa9fabb world border centerY -> centerZ 2022-04-22 20:07:49 -05:00
MWHunter f4a48d5326 Let world border packet be read 2022-04-22 20:02:41 -05:00
MWHunter af5f0d9f85 add getDiameter() and setDiameter() to world border size packet 2022-04-22 20:00:45 -05:00
retrooper ab6fa602cc Update README.md 2022-04-22 22:24:44 +02:00
retrooper a15b0c7cc8 Updated licensing logo 2022-04-22 22:24:20 +02:00
MWHunter 86bffa503c remove debug 2022-04-20 18:15:13 -05:00
MWHunter 511b331735 Play with the injector 2022-04-20 18:03:51 -05:00
MWHunter 78d101dd80 Fix ViaVersionUtil exception 2022-04-20 17:35:23 -05:00
MWHunter 70dc93cd09 Add PacketHandshakeSendEvent to fix null event 2022-04-19 21:44:23 -05:00
MWHunter fed8b95199 Fix early injection on 1.8, fix ViaVersionUtil returning wrong value 2022-04-19 18:43:51 -05:00
retrooper e8d8fb5af8 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-04-19 22:56:34 +02:00
retrooper d98038ecf7 Renamings in AdventureSerializer and PacketWrapper#readComponent works properly again. 2022-04-19 22:54:43 +02:00
MWHunter 5ea3713a22 Revert component change 2022-04-19 15:26:06 -05:00
retrooper 0d4cc8a505 Attempt to bug fix REMOVE_LISTENER_METHOD in paper injector (when cleaning up) 2022-04-19 21:03:59 +02:00
MWHunter 9d0dc9f06d Fix leash always being true 2022-04-18 13:45:23 -05:00
retrooper 261b89792b Confirmed that NPC api works on 1.8. 2022-04-18 20:08:26 +02:00
retrooper 089f0b0e18 Improved error message when using 4.8.0 ProtocolLib 2022-04-18 19:45:50 +02:00
retrooper 53e7fbed0e User#getName & User#getUUID methods, which internally access the profile. It just makes things easier. 2022-04-18 19:34:19 +02:00
retrooper 988d118478 Throw an exception when you try to load PacketEvents with a ProtocolLib version older than 5.0.0 2022-04-18 19:28:05 +02:00
MWHunter df7be9b51f Parse adventure, not component. 2022-04-17 22:56:29 -05:00
MWHunter dead95adad Fix netherite pickaxe not being considered a pickaxe 2022-04-17 21:30:00 -05:00
MWHunter d69ad9ef9a Include mappingsIndex in WrappedBlockState constructor 2022-04-17 20:58:10 -05:00
retrooper b65bbb03a8 Some more changes. 2022-04-17 22:40:38 +02:00
retrooper 83d3ca01fe Removed some non-existing pages and shifted some things around. 2022-04-17 22:39:35 +02:00
retrooper e7732b03f8 Redundant changes 2022-04-17 22:38:04 +02:00
retrooper b742335ffb Little PacketWrapper code optimization 2022-04-17 16:12:38 +02:00
retrooper 262a17659b Merge pull request #331 from AbhigyaKrishna/2.0
Title fix for Open Window Packet
2022-04-17 11:24:53 +02:00
DefineOutside 191e24398a Merge pull request #332 from Jaren8r/2.0
Add .with[XYZ] to vectors
2022-04-17 00:29:01 -05:00
Jaren Knodel ae2a23f0aa Add .with[XYZ] to vectors 2022-04-16 11:32:08 -04:00
Abhigya 59944eadf4 Title fix for Open Window Packet 2022-04-16 12:36:28 +05:30
retrooper 5208b090dd Merge pull request #329 from Jaren8r/2.0
Make vectors immutable
2022-04-15 17:26:55 +02:00
Jaren Knodel c14b18d24e Fix build 2022-04-15 10:52:58 -04:00
Jaren Knodel 01e2e6a19d Make vectors immutable 2022-04-15 10:45:31 -04:00
retrooper 71ca117931 Completing the vector change
Improve vectors (pt. 2)
2022-04-15 14:36:00 +02:00
Jaren Knodel bee7fef71a dot 2022-04-15 03:50:57 -04:00
Jaren Knodel 24b8105dcb crossProduct 2022-04-15 03:44:55 -04:00
retrooper a01e066dae Merge pull request #327 from Jaren8r/2.0
Multiply function to vectors
2022-04-15 09:43:19 +02:00
Jaren Knodel e93f94f87c Add multiple(value) to multiple everything by it 2022-04-15 03:35:43 -04:00
Jaren Knodel eb052cca32 Make setXYZ return itself to remain consistant with add/subtract/multiply 2022-04-15 03:28:49 -04:00
Jaren Knodel b4c1b8c954 Add multiply to vectors 2022-04-15 03:17:03 -04:00
MWHunter 5d1b6a7d2a Cache toClientVersion() and toServerVersion() 2022-04-14 22:02:21 -05:00
MWHunter 12bd685fe7 Rework ItemStack constructor and fix enchantment tags for books 2022-04-14 21:45:54 -05:00
retrooper 3616a18286 Minor change 2022-04-14 23:30:07 +02:00
retrooper db6b3489de Merge pull request #319 from Jaren8r/2.0
Don't clone on vector add/subtract (Changed usage of vectors)
2022-04-14 21:06:03 +02:00
MWHunter 049f5f4123 Fix enchantments on pre-1.13 2022-04-14 00:05:22 -05:00
MWHunter b553f29b71 IdentityHashMap -> HashMap 2022-04-13 18:08:08 -05:00
MWHunter ea6e8ee74e Remove client version cache temporarily due to a memory leak 2022-04-13 13:32:30 -05:00
MWHunter 6559603147 Server response is Json not component 2022-04-12 16:04:35 -05:00
MWHunter ab8839c07f WrapperPlayServerOpenWindow optimization and WrapperStatusServerResponse refactor 2022-04-12 16:01:52 -05:00
MWHunter 2c83f6e5a5 Fix spawn player packet attempt 2 2022-04-11 23:37:33 -05:00
MWHunter fa4a4a0ca0 Revert previous commit 2022-04-11 23:35:52 -05:00
MWHunter e9f0e1d7af Fix WrapperPlayServerSpawnPlayer 2022-04-11 23:26:29 -05:00
Jaren Knodel c9cf4f8c9b Don't clone on vector add/subtract 2022-04-11 19:28:12 -04:00
DefineOutside 89e20ef82a Merge pull request #315 from FairyProject/2.0
Fixed WrapperPlayServerScoreboardObjective again
2022-04-11 13:28:45 -05:00
MWHunter bab579f6f9 Convert item type mappings to be more consistent with other mappings 2022-04-11 12:40:15 -05:00
MWHunter e26b1dac22 Try fixing writing air itemstacks on 1.13.2+ 2022-04-11 12:08:16 -05:00
LeeGod 23d9c77305 Fixed WrapperPlayServerScoreboardObjective again 2022-04-11 19:17:55 +07:00
retrooper 8e49b4b400 Minor change. 2022-04-11 12:15:04 +02:00
retrooper e434e5df76 Little comment added. 2022-04-08 23:29:48 +02:00
retrooper f9136dbf42 All 1.7.10 injector/nms code removed.
PacketEventsSettings#fallbackVersion removed

Added an injector specific for paper, which should be more efficient on their platform and adds NachoSpigot support.

Some refactoring/renaming in our spigot injector
2022-04-08 23:28:35 +02:00
retrooper f144f66e88 Merge branch 'version-dynamic' into 2.0
# Conflicts:
#	api/src/main/java/com/github/retrooper/packetevents/protocol/item/ItemStack.java
#	api/src/main/java/com/github/retrooper/packetevents/protocol/item/type/ItemTypes.java
#	api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerScoreboardObjective.java
2022-04-07 23:00:53 +02:00
DefineOutside ab37570e9b Merge pull request #311 from FairyProject/bugfix/teams
Teams packet wrapper team name read/write with 16 max characters
2022-04-07 11:39:48 -05:00
LeeGod 7a61bb6cdc Teams packet wrapper team name read/write with 16 max characters 2022-04-07 23:08:48 +07:00
DefineOutside 5cf920c78e Merge pull request #310 from FairyProject/bugfix/objective
Fixed incorrect HealthDisplay data in ScoreboardObjective wrapper
2022-04-07 10:45:23 -05:00
LeeGod f1a5ca14bc Fixed incorrect HealthDisplay data in ScoreboardObjective wrapper 2022-04-07 20:07:27 +07:00
MWHunter e08e4645b1 Fix 1.8-1.12 entity type mappings 2022-04-03 19:15:21 -05:00
MWHunter 1452b65879 Fix PacketEvents adding NBT to items, causing desync 2022-04-03 18:45:03 -05:00
MWHunter 85cb8a72ca Fix using 1.16 instead of 1.16.2 item type mappings 2022-04-03 11:00:34 -05:00
623 changed files with 285333 additions and 113843 deletions

No files matched your search

+9 -8
View File
@@ -11,9 +11,10 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
@@ -21,34 +22,34 @@ jobs:
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Gradle
run: gradle shadowJar
run: chmod +x gradlew && ./gradlew shadowJar
- name: Upload build artifacts api
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: api-build
path: api/build/libs
- name: Upload build artifacts spigot
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: spigot-build
path: spigot/build/libs
- name: Upload build artifacts netty-common
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: netty-common-build
path: netty-common/build/libs
- name: Upload build artifacts bungeecord
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: bungeecord-build
path: bungeecord/build/libs
- name: Upload build artifacts velocity
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: velocity-build
path: velocity/build/libs
+5
View File
@@ -102,6 +102,7 @@ $RECYCLE.BIN/
.gradle
build/
bin/
# Ignore Gradle GUI config
gradle-app.setting
@@ -118,3 +119,7 @@ run/
!gradle-wrapper.jar
/src/main/resources/plugin.yml
/.idea/
.vscode/
.project
.settings/
.classpath
+15 -18
View File
@@ -1,20 +1,17 @@
# packetevents
[![](https://img.shields.io/badge/License-GPLv3-yellow.svg)](https://github.com/retrooper/packetevents/blob/dev/LICENSE)
[![](https://jitpack.io/v/retrooper/packetevents.svg)](https://jitpack.io/#retrooper/packetevents)
[![](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)
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. With our API, you can write code that runs on many platforms including Spigot, BungeeCord, Velocity, and even client-sided Fabric!
PacketEvents is 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.
### Resources
* [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
* [JavaDocs](https://packetevents.github.io/javadocs)
* [Discord](https://discord.me/packetevents)
### 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)
### Setup
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup)
### Contributing
[Learn more](https://github.com/retrooper/packetevents/wiki/Contributing)
[How to Setup PacketEvents](https://github.com/retrooper/packetevents/wiki/Depending-on-pre%E2%80%90built-PacketEvents)
### Sponsorships
[![](https://www.ej-technologies.com/images/product_banners/jprofiler_small.png)](https://www.ej-technologies.com/products/jprofiler/overview.html)
@@ -23,11 +20,11 @@ PacketEvents is a powerful packet library. Our packet wrappers are efficient and
PacketEvents optionally collects statistics using [bStats](https://bstats.org/)\
Check out our [bStats page](https://bstats.org/plugin/bukkit/packetevents/11327)
### Credit to
[wiki.vg/Protocol](https://wiki.vg/Protocol)
[adventure](https://github.com/KyoriPowered/adventure)
[gson](https://github.com/google/gson)
[ViaVersion](https://github.com/ViaVersion/ViaVersion)
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)
### 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/)
[netty](https://github.com/netty/netty)
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -18,10 +18,13 @@
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;
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -37,7 +37,8 @@ public abstract class PacketEventsAPI<T> {
private static final UpdateChecker UPDATE_CHECKER = new UpdateChecker();
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
private static final LogManager LOG_MANAGER = new LogManager();
private static final PEVersion VERSION = new PEVersion(2, 0, 0);
//TODO UPDATE
private static final PEVersion VERSION = new PEVersion(2, 2, 0);
public EventManager getEventManager() {
return EVENT_MANAGER;
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -19,15 +19,16 @@
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.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
public class EventManager {
private final Map<Byte, HashSet<PacketListenerCommon>> listenersMap = new ConcurrentHashMap<>();
private final Map<Byte, Set<PacketListenerCommon>> listenersMap = new ConcurrentHashMap<>();
/**
* Call the PacketEvent.
@@ -44,13 +45,16 @@ public class EventManager {
public void callEvent(PacketEvent event, @Nullable Runnable postCallListenerAction) {
for (byte priority = PacketListenerPriority.LOWEST.getId(); priority <= PacketListenerPriority.MONITOR.getId(); priority++) {
HashSet<PacketListenerCommon> listeners = listenersMap.get(priority);
Set<PacketListenerCommon> listeners = listenersMap.get(priority);
if (listeners != null) {
for (PacketListenerCommon listener : listeners) {
try {
event.call(listener);
} catch (Throwable t) {
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
} 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();
@@ -58,7 +62,8 @@ public class EventManager {
}
}
}
if (event instanceof ProtocolPacketEvent && PacketEvents.getAPI().getSettings().shouldListenersReadOnly()) {
// 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);
}
@@ -76,9 +81,9 @@ public class EventManager {
*/
public PacketListenerCommon registerListener(PacketListenerCommon listener) {
byte priority = listener.getPriority().getId();
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(priority);
Set<PacketListenerCommon> listenerSet = listenersMap.get(priority);
if (listenerSet == null) {
listenerSet = new HashSet<>();
listenerSet = ConcurrentHashMap.newKeySet();
}
listenerSet.add(listener);
listenersMap.put(priority, listenerSet);
@@ -98,7 +103,7 @@ public class EventManager {
}
public void unregisterListener(PacketListenerCommon listener) {
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority().getId());
Set<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority().getId());
if (listenerSet == null) return;
listenerSet.remove(listener);
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -47,20 +47,13 @@ public class PacketReceiveEvent extends ProtocolPacketEvent<Object> {
@Override
public PacketReceiveEvent clone() {
if (this instanceof PacketHandshakeReceiveEvent) {
return ((PacketHandshakeReceiveEvent)this).clone();
}
else if (this instanceof PacketStatusReceiveEvent) {
return ((PacketStatusReceiveEvent)this).clone();
}
else if (this instanceof PacketLoginReceiveEvent) {
return ((PacketLoginReceiveEvent)this).clone();
}
else if (this instanceof PacketPlayReceiveEvent) {
return ((PacketPlayReceiveEvent)this).clone();
}
else {
return null;
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -18,9 +18,7 @@
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.PacketLoginSendEvent;
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
import com.github.retrooper.packetevents.event.simple.PacketStatusSendEvent;
import com.github.retrooper.packetevents.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;
@@ -28,7 +26,12 @@ 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);
@@ -48,19 +51,27 @@ public class PacketSendEvent extends ProtocolPacketEvent<Object> {
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() {
if (this instanceof PacketStatusSendEvent) {
return ((PacketStatusSendEvent)this).clone();
}
else if (this instanceof PacketLoginSendEvent) {
return ((PacketLoginSendEvent)this).clone();
}
else if (this instanceof PacketPlaySendEvent) {
return ((PacketPlaySendEvent)this).clone();
}
else {
return null;
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -19,9 +19,11 @@
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;
@@ -50,6 +52,7 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
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,
@@ -59,8 +62,7 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
this.player = player;
if (autoProtocolTranslation || user.getClientVersion() == null) {
this.serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
}
else {
} else {
//TODO Optimize
this.serverVersion = user.getClientVersion().toServerVersion();
}
@@ -76,12 +78,17 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
throw new PacketProcessException("Failed to read the Packet ID of a packet. (Size: " + size + ")");
}
ClientVersion version = serverVersion.toClientVersion();
this.packetType = PacketType.getById(packetSide, user.getConnectionState(),
ConnectionState state = packetSide == PacketSide.CLIENT ? user.getDecoderState() : user.getEncoderState();
this.packetType = PacketType.getById(packetSide, state,
version, packetID);
if (this.packetType == null) {
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
// 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 = user.getConnectionState();
this.connectionState = state;
}
public ProtocolPacketEvent(int packetID, PacketTypeCommon packetType, ServerVersion serverVersion, Object channel,
@@ -93,10 +100,21 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
this.byteBuf = byteBuf;
this.packetID = packetID;
this.packetType = packetType;
this.connectionState = user.getConnectionState();
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;
}
@@ -151,7 +169,6 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
this.byteBuf = byteBuf;
}
@Deprecated
public int getPacketId() {
return packetID;
}
@@ -206,4 +223,12 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -41,7 +41,11 @@ public abstract class SimplePacketListenerAbstract extends PacketListenerCommon
onPacketStatusReceive((PacketStatusReceiveEvent) event);
} else if (event instanceof PacketLoginReceiveEvent) {
onPacketLoginReceive((PacketLoginReceiveEvent) event);
} else if (event instanceof PacketPlayReceiveEvent) {
}
else if (event instanceof PacketConfigReceiveEvent) {
onPacketConfigReceive((PacketConfigReceiveEvent) event);
}
else if (event instanceof PacketPlayReceiveEvent) {
onPacketPlayReceive((PacketPlayReceiveEvent) event);
}
}
@@ -52,7 +56,11 @@ public abstract class SimplePacketListenerAbstract extends PacketListenerCommon
onPacketStatusSend((PacketStatusSendEvent) event);
} else if (event instanceof PacketLoginSendEvent) {
onPacketLoginSend((PacketLoginSendEvent) event);
} else if (event instanceof PacketPlaySendEvent) {
}
else if (event instanceof PacketConfigSendEvent) {
onPacketConfigSend((PacketConfigSendEvent) event);
}
else if (event instanceof PacketPlaySendEvent) {
onPacketPlaySend((PacketPlaySendEvent) event);
}
}
@@ -72,6 +80,12 @@ public abstract class SimplePacketListenerAbstract extends PacketListenerCommon
public void onPacketLoginSend(PacketLoginSendEvent event) {
}
public void onPacketConfigReceive(PacketConfigReceiveEvent event) {
}
public void onPacketConfigSend(PacketConfigSendEvent event) {
}
public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -0,0 +1,59 @@
/*
* 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();
}
}
@@ -0,0 +1,59 @@
/*
* 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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -0,0 +1,40 @@
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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -0,0 +1,5 @@
package com.github.retrooper.packetevents.exception;
public class CancelPacketException extends RuntimeException {
public static final CancelPacketException INSTANCE = new CancelPacketException();
}
@@ -0,0 +1,4 @@
package com.github.retrooper.packetevents.exception;
public class InvalidDisconnectPacketSend extends RuntimeException {
}
@@ -0,0 +1,4 @@
package com.github.retrooper.packetevents.exception;
public class InvalidHandshakeException extends RuntimeException {
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -18,7 +18,7 @@
package com.github.retrooper.packetevents.exception;
public class PacketProcessException extends Exception {
public class PacketProcessException extends RuntimeException {
public PacketProcessException(String msg, Throwable cause) {
super(msg, cause);
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -18,9 +18,7 @@
package com.github.retrooper.packetevents.injector;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.player.User;
import org.jetbrains.annotations.Nullable;
public interface ChannelInjector {
default boolean isServerBound() {
@@ -31,13 +29,9 @@ public interface ChannelInjector {
void uninject();
User getUser(Object channel);
void changeConnectionState(Object channel, @Nullable ConnectionState connectionState);
void updateUser(Object channel, User user);
void setPlayer(Object channel, Object player);
boolean hasPlayer(Object player);
boolean isProxy();
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -32,6 +32,7 @@ import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.wrapper.configuration.server.WrapperConfigServerRegistryData;
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;
@@ -61,49 +62,86 @@ public class InternalPacketListener extends PacketListenerAbstract {
//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
ProtocolManager.CHANNELS.put(profile.getName(), channel);
PacketEvents.getAPI().getLogManager().debug("Mapped player username with their channel.");
synchronized (channel) {
ProtocolManager.CHANNELS.put(profile.getUUID(), channel);
}
//Update connection state(injectors might do some adjustments when we transition into PLAY state)
//This also updates it for the user instance
event.getPostTasks().add(() -> {
PacketEvents.getAPI().getInjector().changeConnectionState(channel, ConnectionState.PLAY);
PacketEvents.getAPI().getLogManager().debug("Transitioned " + profile.getName() + " into the PLAY state!");
});
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);
}
}
// Join game can be used to update world height, and sets dimension data
// 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);
if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
// Store world data
NBTCompound registryDataTag = registryData.getRegistryData();
if (registryDataTag != null) {
NBTList<NBTCompound> list = registryDataTag
.getCompoundTagOrNull("minecraft:dimension_type")
.getCompoundListTagOrNull("value");
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 height
NBTList<NBTCompound> list = joinGame.getDimensionCodec()
.getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
user.setWorldNBT(list);
// Store world data
NBTCompound dimensionCodec = joinGame.getDimensionCodec();
if (dimensionCodec != null) {
NBTList<NBTCompound> list = dimensionCodec
.getCompoundTagOrNull("minecraft:dimension_type")
.getCompoundListTagOrNull("value");
user.setWorldNBT(list);
}
// Update world height
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getType().getName()).getCompoundTagOrNull("element");
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
NBTCompound dimension = user.getWorldNBT(joinGame.getDimension().getDimensionName());
if (dimension != null) {
NBTCompound worldNBT = dimension.getCompoundTagOrNull("element");
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
}
}
// Respawn is used to switch dimensions
if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
if (event.getServerVersion()
.isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
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
}
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getType().getName()).getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
NBTCompound dimension = user.getWorldNBT(respawn.getDimension().getDimensionName());
if (dimension != null) {
NBTCompound worldNBT = dimension.getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
}
} 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);
}
}
@@ -113,25 +151,20 @@ public class InternalPacketListener extends PacketListenerAbstract {
if (event.getPacketType() == PacketType.Handshaking.Client.HANDSHAKE) {
Object channel = event.getChannel();
InetSocketAddress address = event.getSocketAddress();
WrapperHandshakingClientHandshake handshake;
try {
handshake = new WrapperHandshakingClientHandshake(event);
} catch (ArrayIndexOutOfBoundsException exception) {
user.closeConnection();
PacketEvents.getAPI().getLogManager().debug("Disconnected " + address.getHostString() + ":" + address.getPort() + " for sending an invalid handshaking packet. They might be on an outdated client.");
return;
}
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());
event.getPostTasks().add(() -> {
//Transition into the LOGIN OR STATUS connection state
PacketEvents.getAPI().getInjector().changeConnectionState(channel, nextState);
PacketEvents.getAPI().getLogManager().debug("Transitioned " + address.getHostString() + ":" + address.getPort() + " into the " + nextState + " state!");
});
//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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -32,7 +32,7 @@ public interface PlayerManager {
Object getChannel(@NotNull Object player);
@NotNull User getUser(@NotNull Object player);
User getUser(@NotNull Object player);
default ConnectionState getConnectionState(@NotNull Object player) {
return getUser(player).getConnectionState();
@@ -41,96 +41,47 @@ public interface PlayerManager {
default void sendPacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), byteBuf);
}
default void sendPacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), byteBuf);
}
default void sendPacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), wrapper);
}
default void sendPacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), wrapper);
}
default void sendPacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), byteBuf);
}
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), byteBuf);
}
default void sendPacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), wrapper);
}
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), wrapper);
}
default void writePacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), byteBuf);
}
default void writePacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), byteBuf);
}
default void writePacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), wrapper);
}
default void writePacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), wrapper);
}
default void writePacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), byteBuf);
}
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), byteBuf);
}
default void writePacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), wrapper);
}
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), wrapper);
}
default void receivePacket(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), byteBuf);
}
default void receivePacketAsync(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), byteBuf);
}
default void receivePacket(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), wrapper);
}
default void receivePacketAsync(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), wrapper);
}
default void receivePacketSilently(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), byteBuf);
}
default void receivePacketSilentlyAsync(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), byteBuf);
}
default void receivePacketSilently(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), wrapper);
}
default void receivePacketSilentlyAsync(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), wrapper);
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -20,21 +20,21 @@ package com.github.retrooper.packetevents.manager.protocol;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.ProtocolVersion;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public interface ProtocolManager {
Map<String, Object> CHANNELS = new ConcurrentHashMap<>();
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() {
@@ -47,163 +47,120 @@ public interface ProtocolManager {
//Methods to implement
ProtocolVersion getPlatformVersion();
void sendPacket(Object channel, Object packet);
void sendPacketSilently(Object channel, Object packet);
void writePacket(Object channel, Object packet);
void writePacketSilently(Object channel, Object packet);
void receivePacket(Object channel, Object packet);
void receivePacketSilently(Object channel, Object packet);
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 sendPacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacket(channel, byteBuf);
});
default void sendPackets(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
sendPacket(channel, buf);
}
}
default void sendPacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacketSilently(channel, byteBuf);
});
default void sendPacketsSilently(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
sendPacketSilently(channel, buf);
}
}
default void writePacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacket(channel, byteBuf);
});
default void writePackets(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
writePacket(channel, buf);
}
}
default void writePacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacketSilently(channel, byteBuf);
});
default void writePacketsSilently(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
writePacketSilently(channel, buf);
}
}
default void receivePacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacket(channel, byteBuf);
});
default void receivePackets(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
receivePacket(channel, buf);
}
}
default void receivePacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacketSilently(channel, byteBuf);
});
default void receivePacketsSilently(Object channel, Object... byteBuf) {
for (Object buf : byteBuf) {
receivePacketSilently(channel, buf);
}
}
//TODO Make it clear that this only updates the connection state in our user.
//Sometimes you should use getInjector().changeConnectionState because that can allow the injector to make adjustments.
//This is very important, especially on Spigot.
//As soon as we switch to the play state on spigot, our injector makes some adjustments.
default void changeConnectionState(Object channel, ConnectionState connectionState) {
getUser(channel).setConnectionState(connectionState);
}
default void setClientVersion(Object channel, ClientVersion version) {
getUser(channel).setClientVersion(version);
}
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
@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);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
sendPacket(channel, packet.buffer);
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 sendPacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacket(channel, wrapper);
});
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
Object[] transformed = transformWrappers(wrapper, channel, true);
sendPackets(channel, transformed);
}
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
sendPacketSilently(channel, packet.buffer);
}
}
default void sendPacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacketSilently(channel, wrapper);
});
Object[] transformed = transformWrappers(wrapper, channel, true);
sendPacketsSilently(channel, transformed);
}
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
writePacket(channel, packet.buffer);
}
}
default void writePacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacket(channel, wrapper);
});
Object[] transformed = transformWrappers(wrapper, channel, true);
writePackets(channel, transformed);
}
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
writePacketSilently(channel, packet.buffer);
}
}
default void writePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacketSilently(channel, wrapper);
});
Object[] transformed = transformWrappers(wrapper, channel, true);
writePacketsSilently(channel, transformed);
}
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
receivePacket(channel, packet.buffer);
}
}
default void receivePacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacket(channel, wrapper);
});
Object[] transformed = transformWrappers(wrapper, channel, false);
receivePackets(channel, transformed);
}
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
receivePacketSilently(channel, packet.buffer);
}
}
default void receivePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacketSilently(channel, wrapper);
});
Object[] transformed = transformWrappers(wrapper, channel, false);
receivePacketsSilently(channel, transformed);
}
default User getUser(Object channel) {
return USERS.get(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) {
USERS.put(channel, user);
synchronized (channel) {
Object pipeline = ChannelHelper.getPipeline(channel);
USERS.put(pipeline, user);
}
PacketEvents.getAPI().getInjector().updateUser(channel, user);
}
default Object getChannel(String username) {
return CHANNELS.get(username);
default Object getChannel(UUID uuid) {
return CHANNELS.get(uuid);
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.manager.server;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import org.jetbrains.annotations.NotNull;
/**
* Server Version.
@@ -30,7 +31,7 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
* @since 1.6.9
*/
public enum ServerVersion {
//TODO Rename to PlatformVersion or LocalVersion or Version?
//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),
@@ -44,6 +45,10 @@ public enum ServerVersion {
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.
V_1_20(763), V_1_20_1(763), V_1_20_2(764), V_1_20_3(765), V_1_20_4(765),
//TODO UPDATE Add server version constant
ERROR(-1, true);
@@ -64,6 +69,7 @@ public enum ServerVersion {
private final int protocolVersion;
private final String name;
private ClientVersion toClientVersion;
ServerVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
@@ -84,17 +90,17 @@ public enum ServerVersion {
}
public static ServerVersion getLatest() {
return reversedValues()[1];
return REVERSED_VALUES[1];
}
public static ServerVersion getOldest() {
return values()[0];
return VALUES[0];
}
//TODO Optimize
@Deprecated
public static ServerVersion getById(int protocolVersion) {
for (ServerVersion version : values()) {
for (ServerVersion version : VALUES) {
if (version.protocolVersion == protocolVersion) {
return version;
}
@@ -103,12 +109,16 @@ public enum ServerVersion {
}
public ClientVersion toClientVersion() {
return ClientVersion.getById(this.protocolVersion);
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() {
@@ -133,31 +143,7 @@ public enum ServerVersion {
* @return Is this server version newer than the compared server version.
*/
public boolean isNewerThan(ServerVersion target) {
/*
* Some server versions have the same protocol version in the minecraft protocol.
* We still need this method to work in such cases.
* We first check if this is the case, if the protocol versions aren't the same, we can just use the protocol versions
* to compare the server versions.
*/
if (target.protocolVersion != protocolVersion || this == target) {
return protocolVersion > target.protocolVersion;
}
/*
* The server versions unfortunately have the same protocol version.
* We need to look at this "reversedValues" variable.
* The reversed values variable is an array containing all enum constants in this enum but in a reversed order.
* I already made this variable a while ago for a different usage, you can check that out.
* The first one we find in the array is the newer version.
*/
for (ServerVersion version : reversedValues()) {
if (version == target) {
return false;
}
if (version == this) return true;
}
return false;
return this.ordinal() > target.ordinal();
}
/**
@@ -169,28 +155,7 @@ public enum ServerVersion {
* @return Is this server version older than the compared server version.
*/
public boolean isOlderThan(ServerVersion target) {
/*
* Some server versions have the same protocol version in the minecraft protocol.
* We still need this method to work in such cases.
* We first check if this is the case, if the protocol versions aren't the same, we can just use the protocol versions
* to compare the server versions.
*/
if (target.protocolVersion != protocolVersion || this == target) {
return protocolVersion < target.protocolVersion;
}
/*
* The server versions unfortunately have the same protocol version.
* We look at all enum constants in the ServerVersion enum in the order they have been defined in.
* The first one we find in the array is the newer version.
*/
for (ServerVersion version : VALUES) {
if (version == this) {
return true;
} else if (version == target) {
return false;
}
}
return false;
return this.ordinal() < target.ordinal();
}
/**
@@ -202,7 +167,7 @@ public enum ServerVersion {
* @return Is this server version newer than or equal to the compared server version.
*/
public boolean isNewerThanOrEquals(ServerVersion target) {
return this == target || isNewerThan(target);
return this.ordinal() >= target.ordinal();
}
/**
@@ -214,6 +179,36 @@ public enum ServerVersion {
* @return Is this server version older than or equal to the compared server version.
*/
public boolean isOlderThanOrEquals(ServerVersion target) {
return this == target || isOlderThan(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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -0,0 +1,45 @@
/*
* 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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -23,6 +23,14 @@ 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);
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -21,6 +21,8 @@ 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);
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -81,6 +81,10 @@ public class ChannelHelper {
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);
}
@@ -89,6 +93,10 @@ public class ChannelHelper {
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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -20,26 +20,41 @@ package com.github.retrooper.packetevents.netty.channel;
import java.net.SocketAddress;
import java.util.List;
import java.util.Set;
public interface ChannelOperator {
Set<Class<? extends Throwable>> getIgnoredHandlerExceptions();
SocketAddress remoteAddress(Object channel);
SocketAddress localAddress(Object channel);
boolean isOpen(Object channel);
Object close(Object channel);
Object write(Object channel, Object buffer);
Object flush(Object channel);
Object writeAndFlush(Object channel, Object buffer);
Object fireChannelRead(Object channel, Object buffer);
Object writeInContext(Object channel, String ctx, Object buffer);
Object flushInContext(Object channel, String ctx);
Object writeAndFlushInContext(Object channel, String ctx, Object buffer);
Object fireChannelReadInContext(Object channel, String ctx, Object buffer);
List<String> pipelineHandlerNames(Object channel);
Object getPipelineHandler(Object channel, String name);
Object getPipelineContext(Object channel, String name);
Object getPipeline(Object channel);
void runInEventLoop(Object channel, Runnable runnable);
Object pooledByteBuf(Object channel);
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -23,9 +23,12 @@ package com.github.retrooper.packetevents.protocol;
* @since 1.8
*/
public enum ConnectionState {
HANDSHAKING, STATUS, LOGIN, PLAY;
HANDSHAKING, STATUS, LOGIN, PLAY, CONFIGURATION;
public static ConnectionState getById(int id) {
if (id >= values().length || id < 0) {
return null;
}
return values()[id];
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -0,0 +1,13 @@
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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -18,16 +18,8 @@
package com.github.retrooper.packetevents.protocol.chat;
public enum ChatPosition {
CHAT,
SYSTEM,
GAME_INFO;
public int getId() {
return ordinal();
}
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
public interface ChatType extends MappedEntity {
public static ChatPosition getById(int id) {
return values()[id];
}
}
@@ -0,0 +1,94 @@
/*
* 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.TypesBuilder;
import com.github.retrooper.packetevents.util.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",
ClientVersion.V_1_18_2,
ClientVersion.V_1_19,
ClientVersion.V_1_19_1);
static {
TYPES_BUILDER.unloadFileMappings();
}
public static ChatType define(String key) {
TypesBuilderData data = TYPES_BUILDER.define(key);
ChatType chatType = new ChatType() {
private final int[] ids = data.getData();
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
int index = TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
};
CHAT_TYPE_MAP.put(chatType.getName().toString(), chatType);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, ChatType> typeIdMap = CHAT_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(chatType.getId(version), 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");
}
@@ -0,0 +1,105 @@
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;
}
}
}
@@ -0,0 +1,69 @@
/*
* 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;
}
}
@@ -0,0 +1,70 @@
/*
* 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;
}
}
}
@@ -0,0 +1,102 @@
/*
* 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 Optional<Integer> 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, @Nullable Integer redirectNodeIndex, @Nullable String name, @Nullable Integer parserID, @Nullable List<Object> properties, @Nullable ResourceLocation suggestionsType) {
this.flags = flags;
this.children = children;
this.redirectNodeIndex = Optional.ofNullable(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 Optional<Integer> getRedirectNodeIndex() {
return redirectNodeIndex;
}
public void setRedirectNodeIndex(Optional<Integer> 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;
}
}
@@ -0,0 +1,186 @@
/*
* 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 com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class Parsers {
private static final List<Parser> parsers = Arrays.asList(
new Parser("brigadier:bool", null, null),
new Parser("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));
}
),
new Parser("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));
}
),
new Parser("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));
}
),
new Parser("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));
}
),
new Parser("brigadier:string",
packetWrapper -> Collections.singletonList(packetWrapper.readVarInt()),
(packetWrapper, properties) -> packetWrapper.writeVarInt((Integer) properties.get(0))
),
new Parser("minecraft:entity",
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
),
new Parser("minecraft:game_profile", null, null),
new Parser("minecraft:block_pos", null, null),
new Parser("minecraft:column_pos", null, null),
new Parser("minecraft:vec3", null, null),
new Parser("minecraft:vec2", null, null),
new Parser("minecraft:block_state", null, null),
new Parser("minecraft:block_predicate", null, null),
new Parser("minecraft:item_stack", null, null),
new Parser("minecraft:item_predicate", null, null),
new Parser("minecraft:color", null, null),
new Parser("minecraft:component", null, null),
new Parser("minecraft:style", null, null),
new Parser("minecraft:message", null, null),
new Parser("minecraft:nbt", null, null),
new Parser("minecraft:nbt_tag", null, null),
new Parser("minecraft:nbt_path", null, null),
new Parser("minecraft:objective", null, null),
new Parser("minecraft:objective_criteria", null, null),
new Parser("minecraft:operation", null, null),
new Parser("minecraft:particle", null, null),
new Parser("minecraft:angle", null, null),
new Parser("minecraft:rotation", null, null),
new Parser("minecraft:scoreboard_slot", null, null),
new Parser("minecraft:score_holder",
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
),
new Parser("minecraft:swizzle", null, null),
new Parser("minecraft:team", null, null),
new Parser("minecraft:item_slot", null, null),
new Parser("minecraft:resource_location", null, null),
new Parser("minecraft:function", null, null),
new Parser("minecraft:entity_anchor", null, null),
new Parser("minecraft:int_range", null, null),
new Parser("minecraft:float_range", null, null),
new Parser("minecraft:dimension", null, null),
new Parser("minecraft:gamemode", null, null),
new Parser("minecraft:time",
packetWrapper -> Collections.singletonList(packetWrapper.readInt()),
(packetWrapper, properties) -> packetWrapper.writeInt((int) properties.get(0))
),
new Parser("minecraft:resource_or_tag",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
),
new Parser("minecraft:resource_or_tag_key",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
),
new Parser("minecraft:resource",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
),
new Parser("minecraft:resource_key",
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
),
new Parser("minecraft:template_mirror", null, null),
new Parser("minecraft:template_rotation", null, null),
new Parser("minecraft:heightmap", null, null),
new Parser("minecraft:uuid", null, null)
);
public static List<Parser> getParsers() {
return parsers;
}
public static final class Parser {
private final String name; //not really needed, just for toString or something
private final Optional<Function<PacketWrapper<?>, List<Object>>> read;
private final Optional<BiConsumer<PacketWrapper<?>, List<Object>>> write;
public Parser(String name, @Nullable Function<PacketWrapper<?>, List<Object>> read, @Nullable BiConsumer<PacketWrapper<?>, List<Object>> write) {
this.name = name;
this.read = Optional.ofNullable(read);
this.write = Optional.ofNullable(write);
}
public Optional<List<Object>> readProperties(PacketWrapper<?> packetWrapper) {
return read.map(fn -> fn.apply(packetWrapper));
}
public void writeProperties(PacketWrapper<?> packetWrapper, List<Object> properties) {
write.ifPresent(fn -> fn.accept(packetWrapper, properties));
}
}
}
@@ -0,0 +1,41 @@
/*
* 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;
}
}
@@ -0,0 +1,27 @@
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;
}
}
@@ -0,0 +1,52 @@
/*
* 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;
}
}
@@ -0,0 +1,35 @@
/*
* 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;
public enum FilterMaskType {
PASS_THROUGH,
FULLY_FILTERED,
PARTIALLY_FILTERED;
public static final FilterMaskType[] VALUES = values();
public int getId() {
return ordinal();
}
public static FilterMaskType getById(int id) {
return VALUES[id];
}
}
@@ -0,0 +1,48 @@
/*
* 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;
public class ChatMessage {
private Component chatContent;
private ChatType type;
protected ChatMessage(Component chatContent, ChatType type) {
this.chatContent = chatContent;
this.type = type;
}
public Component getChatContent() {
return chatContent;
}
public ChatType getType() {
return type;
}
public void setChatContent(Component chatContent) {
this.chatContent = chatContent;
}
public void setType(ChatType type) {
this.type = type;
}
}
@@ -0,0 +1,28 @@
/*
* 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;
public class ChatMessageLegacy extends ChatMessage {
public ChatMessageLegacy(Component chatContent, ChatType type) {
super(chatContent, type);
}
}
@@ -0,0 +1,41 @@
/*
* 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;
}
}
@@ -0,0 +1,95 @@
/*
* 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;
}
}
@@ -0,0 +1,181 @@
/*
* 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;
}
}
}
@@ -0,0 +1,119 @@
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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -16,15 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.util.reflection;
package com.github.retrooper.packetevents.protocol.chat.message.reader;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
public class ClassUtil {
private static final Map<Class<?>, String> CLASS_SIMPLE_NAME_CACHE = new ConcurrentHashMap<>();
public interface ChatMessageProcessor {
ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper);
public static String getClassSimpleName(Class<?> cls) {
return CLASS_SIMPLE_NAME_CACHE.computeIfAbsent(cls, k -> cls.getSimpleName());
}
void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data);
}
@@ -0,0 +1,44 @@
/*
* 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()));
}
}
@@ -0,0 +1,48 @@
/*
* 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());
}
}
@@ -0,0 +1,64 @@
/*
* 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());
}
}
@@ -0,0 +1,73 @@
/*
* 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());
}
}
@@ -0,0 +1,47 @@
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,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -21,18 +21,29 @@ package com.github.retrooper.packetevents.protocol.entity.data;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import com.github.retrooper.packetevents.protocol.entity.sniffer.SnifferState;
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.particle.Particle;
import com.github.retrooper.packetevents.protocol.particle.type.ParticleType;
import com.github.retrooper.packetevents.protocol.particle.type.ParticleTypes;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.util.*;
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.Quaternion4f;
import com.github.retrooper.packetevents.util.TypesBuilder;
import com.github.retrooper.packetevents.util.TypesBuilderData;
import com.github.retrooper.packetevents.util.Vector3f;
import com.github.retrooper.packetevents.util.Vector3i;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.google.gson.JsonObject;
import net.kyori.adventure.text.Component;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Function;
@@ -48,19 +59,52 @@ public class EntityDataTypes {
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_11,
ClientVersion.V_1_13, //Fix? Why did we not acknoledge 1.13
ClientVersion.V_1_16);
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_19,
ClientVersion.V_1_19_3,
ClientVersion.V_1_19_4);
public static final EntityDataType<Byte> BYTE = define("byte", PacketWrapper::readByte, PacketWrapper::writeByte);
public static final EntityDataType<Integer> INT = define("int", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Short> SHORT = define("short", PacketWrapper::readShort, PacketWrapper::writeShort);
public static final EntityDataType<Integer> INT = define("int", wrapper -> {
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return wrapper.readVarInt();
} else {
return wrapper.readInt();
}
}, (wrapper, value) -> {
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
wrapper.writeVarInt(value);
} else {
wrapper.writeInt(value);
}
});
public static final EntityDataType<Long> LONG = define("long", PacketWrapper::readVarLong, PacketWrapper::writeVarLong);
public static final EntityDataType<Float> FLOAT = define("float", PacketWrapper::readFloat, PacketWrapper::writeFloat);
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
public static final EntityDataType<Component> COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
public static final EntityDataType<Optional<Component>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
@Deprecated
public static final EntityDataType<String> COMPONENT = define("component", PacketWrapper::readComponentJSON, PacketWrapper::writeComponentJSON);
public static final EntityDataType<Component> ADV_COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
@Deprecated
public static final EntityDataType<Optional<String>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentJSONDeserializer(), writeOptionalComponentJSONSerializer());
public static final EntityDataType<Optional<Component>> OPTIONAL_ADV_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
public static final EntityDataType<ItemStack> ITEMSTACK = define("itemstack", PacketWrapper::readItemStack, PacketWrapper::writeItemStack);
public static final EntityDataType<Optional<Object>> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Optional<ItemStack>> OPTIONAL_ITEMSTACK = define("optional_itemstack",
(PacketWrapper<?> wrapper) -> Optional.of(wrapper.readItemStack()),
(PacketWrapper<?> wrapper, Optional<ItemStack> value) -> wrapper.writeItemStack(value.orElse(null)));
public static final EntityDataType<Boolean> BOOLEAN = define("boolean", PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
public static final EntityDataType<Integer> PARTICLE = define("particle", PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final EntityDataType<Vector3f> ROTATION = define("rotation",
(PacketWrapper<?> wrapper) -> new Vector3f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
(PacketWrapper<?> wrapper, Vector3f value) -> {
@@ -68,32 +112,58 @@ public class EntityDataTypes {
wrapper.writeFloat(value.y);
wrapper.writeFloat(value.z);
});
public static final EntityDataType<Vector3i> BLOCK_POSITION = define("block_position", readBlockPositionDeserializer(), writeBlockPositionSerializer());
public static final EntityDataType<Optional<Vector3i>> OPTIONAL_BLOCK_POSITION = define("optional_block_position", readOptionalBlockPositionDeserializer(), writeOptionalBlockPositionSerializer());
public static final EntityDataType<Vector3i> BLOCK_POSITION = define("block_position", (PacketWrapper<?> wrapper) -> {
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return wrapper.readBlockPosition();
} else {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return new Vector3i(x, y, z);
}
}, (wrapper, blockPosition) -> {
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
wrapper.writeBlockPosition(blockPosition);
} else {
wrapper.writeInt(blockPosition.getX());
wrapper.writeInt(blockPosition.getY());
wrapper.writeInt(blockPosition.getZ());
}
});
public static final EntityDataType<Optional<Vector3i>> OPTIONAL_BLOCK_POSITION = define("optional_block_position",
readOptionalBlockPositionDeserializer(), writeOptionalBlockPositionSerializer());
public static final EntityDataType<BlockFace> BLOCK_FACE = define("block_face", (PacketWrapper<?> wrapper) -> {
int id = wrapper.readVarInt();
return BlockFace.getBlockFaceByValue(id);
},
(PacketWrapper<?> wrapper, BlockFace value) -> wrapper.writeVarInt(value.getFaceValue()));
public static final EntityDataType<Optional<UUID>> OPTIONAL_UUID = define("optional_uuid", (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return Optional.of(wrapper.readUUID());
} else {
return Optional.empty();
}
},
(PacketWrapper<?> wrapper, Optional<UUID> value) -> {
if (value.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeUUID(value.get());
} else {
wrapper.writeBoolean(false);
}
});
public static final EntityDataType<Optional<UUID>> OPTIONAL_UUID = define("optional_uuid",
(PacketWrapper<?> wrapper) -> Optional.ofNullable(wrapper.readOptional(PacketWrapper::readUUID)),
(PacketWrapper<?> wrapper, Optional<UUID> value) ->
wrapper.writeOptional(value.orElse(null), PacketWrapper::writeUUID));
public static final EntityDataType<Integer> BLOCK_STATE = define("block_state",
readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Integer> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<NBTCompound> NBT = define("nbt", PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final EntityDataType<Particle> PARTICLE = define("particle", wrapper -> {
int id = wrapper.readVarInt();
ParticleType type = ParticleTypes.getById(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion(), id);
return new Particle(type, type.readDataFunction().apply(wrapper));
}, (wrapper, particle) -> {
wrapper.writeVarInt(particle.getType().getId(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()));
particle.getType().writeDataFunction().accept(wrapper, particle.getData());
});
public static final EntityDataType<VillagerData> VILLAGER_DATA = define("villager_data", PacketWrapper::readVillagerData, PacketWrapper::writeVillagerData);
public static final EntityDataType<Optional<Integer>> OPTIONAL_INT = define("optional_int", (PacketWrapper<?> wrapper) -> {
int i = wrapper.readVarInt();
return i == 0 ? Optional.empty() : Optional.of(i - 1);
@@ -106,12 +176,45 @@ public class EntityDataTypes {
return EntityPose.getById(wrapper.getServerVersion().toClientVersion(), id);
}, (PacketWrapper<?> wrapper, EntityPose value) -> wrapper.writeVarInt(value.getId(wrapper.getServerVersion().toClientVersion())));
@Deprecated
public static final EntityDataType<Short> SHORT = define("short", PacketWrapper::readShort, PacketWrapper::writeShort);
public static final EntityDataType<Integer> CAT_VARIANT = define("cat_variant_type", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Integer> FROG_VARIANT = define("frog_variant_type", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Optional<WorldBlockPosition>> OPTIONAL_GLOBAL_POSITION = define("optional_global_position",
(PacketWrapper<?> wrapper) -> Optional.ofNullable(wrapper.readOptional(w -> new WorldBlockPosition(new ResourceLocation(w.readString(32767)), w.readBlockPosition()))),
(PacketWrapper<?> wrapper, Optional<WorldBlockPosition> value) -> wrapper.writeOptional(value.orElse(null), (w, globalPos) -> {
w.writeString(globalPos.getWorld().toString());
w.writeBlockPosition(globalPos.getBlockPosition());
}));
public static final EntityDataType<Integer> PAINTING_VARIANT_TYPE = define("painting_variant_type", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<SnifferState> SNIFFER_STATE = define("sniffer_state", (PacketWrapper<?> wrapper) -> {
int id = wrapper.readVarInt();
return SnifferState.values()[id];
}, (PacketWrapper<?> wrapper, SnifferState value) -> wrapper.writeVarInt(value.ordinal()));
public static final EntityDataType<Vector3f> VECTOR3F = define("vector3f",
(PacketWrapper<?> wrapper) -> new Vector3f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
(PacketWrapper<?> wrapper, Vector3f value) -> {
wrapper.writeFloat(value.x);
wrapper.writeFloat(value.y);
wrapper.writeFloat(value.z);
});
public static final EntityDataType<Quaternion4f> QUATERNION = define("quaternion",
(PacketWrapper<?> wrapper) -> new Quaternion4f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
(PacketWrapper<?> wrapper, Quaternion4f value) -> {
wrapper.writeFloat(value.getX());
wrapper.writeFloat(value.getY());
wrapper.writeFloat(value.getZ());
wrapper.writeFloat(value.getW());
});
public static EntityDataType<?> getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte)index);
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte) index);
return typeIdMap.get(id);
}
@@ -162,58 +265,48 @@ public class EntityDataTypes {
};
}
private static <T> Function<PacketWrapper<?>, T> readOptionalComponentDeserializer() {
@Deprecated
private static Function<PacketWrapper<?>, Optional<String>> readOptionalComponentJSONDeserializer() {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return (T) Optional.of(wrapper.readComponent());
return Optional.of(wrapper.readComponentJSON());
} else {
return (T) Optional.empty();
return Optional.empty();
}
};
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeOptionalComponentSerializer() {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<Component> optional = (Optional<Component>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeComponent(optional.get());
} else {
wrapper.writeBoolean(false);
}
@Deprecated
private static BiConsumer<PacketWrapper<?>, Optional<String>> writeOptionalComponentJSONSerializer() {
return (PacketWrapper<?> wrapper, Optional<String> value) -> {
if (value != null && value.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeComponentJSON(value.get());
} else {
wrapper.writeBoolean(false);
}
};
}
private static <T> Function<PacketWrapper<?>, T> readBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> (T) wrapper.readBlockPosition();
} else {
return (PacketWrapper<?> wrapper) -> {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return (T) new Vector3i(x, y, z);
};
}
private static Function<PacketWrapper<?>, Optional<Component>> readOptionalComponentDeserializer() {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return Optional.of(wrapper.readComponent());
} else {
return Optional.empty();
}
};
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeBlockPositionSerializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper, T value) -> {
wrapper.writeBlockPosition((Vector3i) value);
};
} else {
return (PacketWrapper<?> wrapper, T value) -> {
Vector3i position = (Vector3i) value;
wrapper.writeInt(position.getX());
wrapper.writeInt(position.getY());
wrapper.writeInt(position.getZ());
};
}
private static BiConsumer<PacketWrapper<?>, Optional<Component>> writeOptionalComponentSerializer() {
return (PacketWrapper<?> wrapper, Optional<Component> value) -> {
if (value != null && value.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeComponent(value.get());
} else {
wrapper.writeBoolean(false);
}
};
}
private static <T> Function<PacketWrapper<?>, T> readOptionalBlockPositionDeserializer() {
@@ -273,4 +366,5 @@ public class EntityDataTypes {
};
}
}
}
@@ -0,0 +1,35 @@
package com.github.retrooper.packetevents.protocol.entity.data;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import java.util.List;
/**
* This is an interface that provides a list of entity data.
* This allows custom addon libraries to implement metadata classes for various entities
* which can then be used in our API.
* @since 2.1.0
*/
public interface EntityMetadataProvider {
/**
* PacketEvents is retrieving the metadata of this specific entity.
* PacketEvents provides you with the protocol version that the library is running on
* to allow you tu specify different metadata depending on the version.
* You are free to ignore it at the cost of your features not working on all versions.
* @param version The protocol version of the format we expect the metadata to be in.
* @return Metadata (list of entity data)
*/
List<EntityData> entityData(ClientVersion version);
/**
* Similar to {@link #entityData(ClientVersion)} but does not provide a protocol version.
* It is not advised to use nor implement this.
* It is deprecated because it restricts you by not providing you the format in which the metadata should be.
* @return Metadata (list of entity data)
* @deprecated Does not specify format of metadata, therefore not advised to use this. It will assume the current latest version.
*/
@Deprecated
default List<EntityData> entityData() {
return entityData(ClientVersion.getLatest());
}
}
@@ -1,343 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class EntityDataProvider implements DataProvider {
@Nullable
private Component customName;
private boolean customNameVisible;
private EntityPose pose = EntityPose.STANDING;
private int airTicks;
private int ticksFrozenInPowderedSnow = 0;
private boolean onFire;
private boolean crouching;
//Now unused
private boolean riding;
private boolean sprinting;
private boolean swimming;
private boolean invisible;
private boolean glowing;
private boolean flyingWithElytra;
private boolean silent;
private boolean hasGravity = true;
@Nullable
public Component getCustomName() {
return customName;
}
public void setCustomName(@Nullable Component customName) {
this.customName = customName;
}
public boolean isCustomNameVisible() {
return customNameVisible;
}
public void setCustomNameVisible(boolean customNameVisible) {
this.customNameVisible = customNameVisible;
}
public EntityPose getPose() {
return pose;
}
public void setPose(EntityPose pose) {
this.pose = pose;
}
public int getAirTicks() {
return airTicks;
}
public void setAirTicks(int airTicks) {
this.airTicks = airTicks;
}
public int getTicksFrozenInPowderedSnow() {
return ticksFrozenInPowderedSnow;
}
public void setTicksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
this.ticksFrozenInPowderedSnow = ticksFrozenInPowderedSnow;
}
public boolean isOnFire() {
return onFire;
}
public void setOnFire(boolean onFire) {
this.onFire = onFire;
}
public boolean isCrouching() {
return crouching;
}
public void setCrouching(boolean crouching) {
this.crouching = crouching;
}
public boolean isRiding() {
return riding;
}
public void setRiding(boolean riding) {
this.riding = riding;
}
public boolean isSprinting() {
return sprinting;
}
public void setSprinting(boolean sprinting) {
this.sprinting = sprinting;
}
public boolean isSwimming() {
return swimming;
}
public void setSwimming(boolean swimming) {
this.swimming = swimming;
}
public boolean isInvisible() {
return invisible;
}
public void setInvisible(boolean invisible) {
this.invisible = invisible;
}
public boolean isGlowing() {
return glowing;
}
public void setGlowing(boolean glowing) {
this.glowing = glowing;
}
public boolean isFlyingWithElytra() {
return flyingWithElytra;
}
public void setFlyingWithElytra(boolean flyingWithElytra) {
this.flyingWithElytra = flyingWithElytra;
}
public boolean isSilent() {
return silent;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isHasGravity() {
return hasGravity;
}
public void setHasGravity(boolean hasGravity) {
this.hasGravity = hasGravity;
}
@Override
public List<EntityData> encode() {
byte mask = 0x00;
if (onFire) {
mask |= 0x01;
}
if (crouching) {
mask |= 0x02;
}
//TODO Rethink, should we add this?
if (riding) {
mask |= 0x04;
}
if (sprinting) {
mask |= 0x08;
}
if (swimming) {
mask |= 0x10;
}
if (invisible) {
mask |= 0x20;
}
if (glowing) {
mask |= 0x40;
}
if (flyingWithElytra) {
mask |= 0x80;
}
List<EntityData> metadata = new ArrayList<>(8);
metadata.add(new EntityData(0, EntityDataTypes.BYTE, mask));
metadata.add(new EntityData(1, EntityDataTypes.INT, airTicks));
metadata.add(new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.ofNullable(customName)));
metadata.add(new EntityData(3, EntityDataTypes.BOOLEAN, customNameVisible));
metadata.add(new EntityData(4, EntityDataTypes.BOOLEAN, silent));
metadata.add(new EntityData(5, EntityDataTypes.BOOLEAN, !hasGravity));
metadata.add(new EntityData(6, EntityDataTypes.ENTITY_POSE, pose));
metadata.add(new EntityData(7, EntityDataTypes.INT, ticksFrozenInPowderedSnow));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 0:
byte mask = (byte) entityData.getValue();
onFire = (mask & 0x01) != 0;
crouching = (mask & 0x02) != 0;
riding = (mask & 0x04) != 0;
sprinting = (mask & 0x08) != 0;
swimming = (mask & 0x10) != 0;
invisible = (mask & 0x20) != 0;
glowing = (mask & 0x40) != 0;
flyingWithElytra = (mask & 0x80) != 0;
break;
case 1:
airTicks = (int) entityData.getValue();
break;
case 2:
customName = ((Optional<Component>) entityData.getValue()).orElse(null);
break;
case 3:
customNameVisible = (boolean) entityData.getValue();
break;
case 4:
silent = (boolean) entityData.getValue();
break;
case 5:
hasGravity = !(boolean) entityData.getValue();
break;
case 6:
pose = (EntityPose) entityData.getValue();
break;
case 7:
ticksFrozenInPowderedSnow = (int) entityData.getValue();
break;
}
}
}
public static EntityBuilder<EntityBuilder> builderEntity() {
return new EntityBuilder<>(new EntityDataProvider());
}
public static class EntityBuilder<T extends EntityBuilder> {
protected EntityDataProvider provider;
public EntityBuilder(EntityDataProvider provider) {
this.provider = provider;
}
public T customName(@Nullable Component customName) {
((EntityDataProvider) provider).setCustomName(customName);
return (T) this;
}
public T customNameVisible(boolean customNameVisible) {
((EntityDataProvider) provider).setCustomNameVisible(customNameVisible);
return (T) this;
}
public T pose(EntityPose pose) {
((EntityDataProvider) provider).setPose(pose);
return (T) this;
}
public T onFire(boolean onFire) {
((EntityDataProvider) provider).setOnFire(onFire);
return (T) this;
}
public T crouching(boolean crouching) {
((EntityDataProvider) provider).setCrouching(crouching);
return (T) this;
}
public T riding(boolean riding) {
((EntityDataProvider) provider).setRiding(riding);
return (T) this;
}
public T sprinting(boolean sprinting) {
((EntityDataProvider) provider).setSprinting(sprinting);
return (T) this;
}
public T swimming(boolean swimming) {
((EntityDataProvider) provider).setSwimming(swimming);
return (T) this;
}
public T invisible(boolean invisible) {
((EntityDataProvider) provider).setInvisible(invisible);
return (T) this;
}
public T glowing(boolean glowing) {
((EntityDataProvider) provider).setGlowing(glowing);
return (T) this;
}
public T flyingWithElytra(boolean flyingWithElytra) {
((EntityDataProvider) provider).setFlyingWithElytra(flyingWithElytra);
return (T) this;
}
public T silent(boolean silent) {
((EntityDataProvider) provider).setSilent(silent);
return (T) this;
}
public T hasGravity(boolean hasGravity) {
((EntityDataProvider) provider).setHasGravity(hasGravity);
return (T) this;
}
public T airTicks(int airTicks) {
((EntityDataProvider) provider).setAirTicks(airTicks);
return (T) this;
}
public T ticksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
((EntityDataProvider) provider).setTicksFrozenInPowderedSnow(ticksFrozenInPowderedSnow);
return (T) this;
}
public <K extends EntityDataProvider> K build() {
return (K) provider;
}
}
}
@@ -1,232 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.util.Vector3i;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class LivingEntityDataProvider extends EntityDataProvider {
private boolean handActive;
private InteractionHand hand = InteractionHand.MAIN_HAND;
private boolean isInRiptideSpinAttack;
private float health = 1.0f;
private int potionEffectColor;
private boolean potionEffectAmbient;
private int arrowInBodyCount;
private int beeStingsInBodyCount;
@Nullable
private Vector3i sleepingPosition;
public boolean isHandActive() {
return handActive;
}
public void setHandActive(boolean handActive) {
this.handActive = handActive;
}
public InteractionHand getHand() {
return hand;
}
public void setHand(InteractionHand hand) {
this.hand = hand;
}
public boolean isInRiptideSpinAttack() {
return isInRiptideSpinAttack;
}
public void setInRiptideSpinAttack(boolean inRiptideSpinAttack) {
isInRiptideSpinAttack = inRiptideSpinAttack;
}
public float getHealth() {
return health;
}
public void setHealth(float health) {
this.health = health;
}
public int getPotionEffectColor() {
return potionEffectColor;
}
public void setPotionEffectColor(int potionEffectColor) {
this.potionEffectColor = potionEffectColor;
}
public boolean isPotionEffectAmbient() {
return potionEffectAmbient;
}
public void setPotionEffectAmbient(boolean potionEffectAmbient) {
this.potionEffectAmbient = potionEffectAmbient;
}
public int getArrowInBodyCount() {
return arrowInBodyCount;
}
public void setArrowInBodyCount(int arrowInBodyCount) {
this.arrowInBodyCount = arrowInBodyCount;
}
public int getBeeStingsInBodyCount() {
return beeStingsInBodyCount;
}
public void setBeeStingsInBodyCount(int beeStingsInBodyCount) {
this.beeStingsInBodyCount = beeStingsInBodyCount;
}
@Nullable
public Vector3i getSleepingPosition() {
return sleepingPosition;
}
public void setSleepingPosition(@Nullable Vector3i sleepingPosition) {
this.sleepingPosition = sleepingPosition;
}
public static LivingEntityBuilder<LivingEntityBuilder> builderLivingEntity() {
return new LivingEntityBuilder<>(new LivingEntityDataProvider());
}
@Override
public List<EntityData> encode() {
List<EntityData> metadata = super.encode();
byte mask = 0x00;
if (handActive) {
mask |= 0x01;
}
//TODO Confirm
if (hand == InteractionHand.OFF_HAND) {
mask |= 0x02;
}
if (isInRiptideSpinAttack) {
mask |= 0x04;
}
metadata.add(new EntityData(8, EntityDataTypes.BYTE, mask));
metadata.add(new EntityData(9, EntityDataTypes.FLOAT, health));
metadata.add(new EntityData(10, EntityDataTypes.INT, potionEffectColor));
metadata.add(new EntityData(11, EntityDataTypes.BOOLEAN, potionEffectAmbient));
metadata.add(new EntityData(12, EntityDataTypes.INT, arrowInBodyCount));
metadata.add(new EntityData(13, EntityDataTypes.INT, beeStingsInBodyCount));
metadata.add(new EntityData(14, EntityDataTypes.OPTIONAL_BLOCK_POSITION, Optional.ofNullable(sleepingPosition)));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
super.decode(data);
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 8:
byte mask = (byte) entityData.getValue();
handActive = (mask & 0x01) != 0;
//TODO Test, look into
hand = (mask & 0x02) != 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
isInRiptideSpinAttack = (mask & 0x04) != 0;
break;
case 9:
health = (float) entityData.getValue();
break;
case 10:
potionEffectColor = (int) entityData.getValue();
break;
case 11:
potionEffectAmbient = (boolean) entityData.getValue();
break;
case 12:
arrowInBodyCount = (int) entityData.getValue();
break;
case 13:
beeStingsInBodyCount = (int) entityData.getValue();
break;
case 14:
sleepingPosition = ((Optional<Vector3i>) entityData.getValue()).orElse(null);
break;
}
}
}
public static class LivingEntityBuilder<T extends LivingEntityBuilder> extends EntityDataProvider.EntityBuilder<T> {
public LivingEntityBuilder(LivingEntityDataProvider livingEntityDataProvider) {
super(livingEntityDataProvider);
}
public T handActive(boolean handActive) {
((LivingEntityDataProvider) provider).setHandActive(handActive);
return (T) this;
}
public T hand(InteractionHand hand) {
((LivingEntityDataProvider) provider).setHand(hand);
return (T) this;
}
public T isInRiptideSpinAttack(boolean isInRiptideSpinAttack) {
((LivingEntityDataProvider) provider).setInRiptideSpinAttack(isInRiptideSpinAttack);
return (T) this;
}
public T health(float health) {
((LivingEntityDataProvider) provider).setHealth(health);
return (T) this;
}
public T potionEffectColor(int potionEffectColor) {
((LivingEntityDataProvider) provider).setPotionEffectColor(potionEffectColor);
return (T) this;
}
public T potionEffectAmbient(boolean potionEffectAmbient) {
((LivingEntityDataProvider) provider).setPotionEffectAmbient(potionEffectAmbient);
return (T) this;
}
public T arrowInBodyCount(int arrowInBodyCount) {
((LivingEntityDataProvider) provider).setArrowInBodyCount(arrowInBodyCount);
return (T) this;
}
public T beeStingsInBodyCount(int beeStingsInBodyCount) {
((LivingEntityDataProvider) provider).setBeeStingsInBodyCount(beeStingsInBodyCount);
return (T) this;
}
public T sleepingPosition(@Nullable Vector3i sleepingPosition) {
((LivingEntityDataProvider) provider).setSleepingPosition(sleepingPosition);
return (T) this;
}
}
}
@@ -1,169 +0,0 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.HumanoidArm;
import com.github.retrooper.packetevents.protocol.player.SkinSection;
import java.util.List;
import java.util.Set;
public class PlayerDataProvider extends LivingEntityDataProvider {
private float additionalHealth;
private int score;
private byte skinPartsMask = SkinSection.getMaskBySections(SkinSection.getAllSections());
private HumanoidArm mainArm = HumanoidArm.RIGHT;
private NBTCompound leftShoulderNBT = new NBTCompound();
private NBTCompound rightShoulderNBT = new NBTCompound();
public float getAdditionalHealth() {
return additionalHealth;
}
public void setAdditionalHealth(float additionalHealth) {
this.additionalHealth = additionalHealth;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public byte getSkinPartsMask() {
return skinPartsMask;
}
public void setSkinPartsMask(byte skinPartsMask) {
this.skinPartsMask = skinPartsMask;
}
public HumanoidArm getMainArm() {
return mainArm;
}
public void setMainArm(HumanoidArm mainArm) {
this.mainArm = mainArm;
}
public NBTCompound getLeftShoulderNBT() {
return leftShoulderNBT;
}
public void setLeftShoulderNBT(NBTCompound leftShoulderNBT) {
this.leftShoulderNBT = leftShoulderNBT;
}
public NBTCompound getRightShoulderNBT() {
return rightShoulderNBT;
}
public void setRightShoulderNBT(NBTCompound rightShoulderNBT) {
this.rightShoulderNBT = rightShoulderNBT;
}
public static PlayerBuilder<PlayerBuilder> builderPlayer() {
return new PlayerBuilder<>(new PlayerDataProvider());
}
@Override
public List<EntityData> encode() {
List<EntityData> metadata = super.encode();
metadata.add(new EntityData(15, EntityDataTypes.FLOAT, additionalHealth));
metadata.add(new EntityData(16, EntityDataTypes.INT, score));
metadata.add(new EntityData(17, EntityDataTypes.BYTE, skinPartsMask));
metadata.add(new EntityData(18, EntityDataTypes.BYTE, (byte) mainArm.ordinal()));
metadata.add(new EntityData(19, EntityDataTypes.NBT, leftShoulderNBT));
metadata.add(new EntityData(20, EntityDataTypes.NBT, rightShoulderNBT));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
super.decode(data);
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 15:
additionalHealth = (float) entityData.getValue();
break;
case 16:
score = (int) entityData.getValue();
break;
case 17:
skinPartsMask = (byte) entityData.getValue();
break;
case 18:
mainArm = HumanoidArm.values()[(byte) entityData.getValue()];
break;
case 19:
leftShoulderNBT = (NBTCompound) entityData.getValue();
break;
case 20:
rightShoulderNBT = (NBTCompound) entityData.getValue();
break;
}
}
}
public static class PlayerBuilder<T extends PlayerBuilder> extends LivingEntityDataProvider.LivingEntityBuilder<T> {
public PlayerBuilder(PlayerDataProvider entityDataProvider) {
super(entityDataProvider);
}
public T additionalHealth(float additionalHealth) {
((PlayerDataProvider)provider).setAdditionalHealth(additionalHealth);
return (T) this;
}
public T score(int score) {
((PlayerDataProvider)provider).setScore(score);
return (T) this;
}
public T skinPartsMask(byte skinPartsMask) {
((PlayerDataProvider)provider).setSkinPartsMask(skinPartsMask);
return (T)this;
}
public T skinParts(Set<SkinSection> skinSections) {
((PlayerDataProvider)provider).setSkinPartsMask(SkinSection.getMaskBySections(skinSections));
return (T)this;
}
public T mainArm(HumanoidArm mainArm) {
((PlayerDataProvider)provider).setMainArm(mainArm);
return (T)this;
}
public T leftShoulderNBT(NBTCompound leftShoulderNBT) {
((PlayerDataProvider)provider).setLeftShoulderNBT(leftShoulderNBT);
return (T)this;
}
public T rightShoulderNBT(NBTCompound rightShoulderNBT) {
((PlayerDataProvider)provider).setRightShoulderNBT(rightShoulderNBT);
return (T)this;
}
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -28,12 +28,22 @@ public enum EntityPose {
SPIN_ATTACK,
CROUCHING,
LONG_JUMPING,
DYING;
DYING,
CROAKING,
USING_TONGUE,
SITTING,
ROARING,
SNIFFING,
EMERGING,
DIGGING;
public int getId(ClientVersion version) {
if (this == DYING && version.isOlderThan(ClientVersion.V_1_17)) {
return 6;
}
if (this.ordinal() >= 11 && version.isOlderThan(ClientVersion.V_1_19_3)) {
return this.ordinal() - 1;
}
return ordinal();
}
@@ -42,6 +52,10 @@ public enum EntityPose {
if (id == 6 && version.isOlderThan(ClientVersion.V_1_17)) {
return DYING;
}
// The SITTING pose was added in 1.19.3, shifting Warden's poses by 1
if (id >= 10 && version.isOlderThan(ClientVersion.V_1_19_3)) {
id++;
}
return values()[id];
}
}
@@ -0,0 +1,29 @@
/*
* 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.entity.sniffer;
public enum SnifferState {
IDLING,
FEELING_HAPPY,
SCENTING,
SNIFFING,
SEARCHING,
DIGGING,
RISING
}
@@ -0,0 +1,91 @@
/*
* 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.entity.transform;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public class EntityTransformType {
public static final EntityTransformType IDENTITY = new EntityTransformType(null, 1.0F, null);
private @Nullable TypeModifier typeModifier;
private float scale;
private @Nullable UserProfile playerSkin;
//Scale must be between 0.1F and 16.0F
public EntityTransformType(@Nullable TypeModifier typeModifier, float scale, @Nullable UserProfile playerSkin) {
this.typeModifier = typeModifier;
this.scale = scale;
this.playerSkin = playerSkin;
}
public Optional<TypeModifier> getTypeModifier() {
return Optional.ofNullable(typeModifier);
}
public void setTypeModifier(@Nullable TypeModifier typeModifier) {
this.typeModifier = typeModifier;
}
public float getScale() {
return scale;
}
public void setScale(float scale) {
this.scale = scale;
}
public Optional<UserProfile> getPlayerSkin() {
return Optional.ofNullable(playerSkin);
}
public void setPlayerSkin(@Nullable UserProfile playerSkin) {
this.playerSkin = playerSkin;
}
public static class TypeModifier {
private EntityType entityType;
private @Nullable NBTCompound tag;
public TypeModifier(EntityType entityType, @Nullable NBTCompound tag) {
this.entityType = entityType;
this.tag = tag;
}
public EntityType getEntityType() {
return entityType;
}
public void setEntityType(EntityType entityType) {
this.entityType = entityType;
}
public Optional<NBTCompound> getTag() {
return Optional.ofNullable(tag);
}
public void setTag(@Nullable NBTCompound tag) {
this.tag = tag;
}
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -42,7 +42,11 @@ public class EntityTypes {
ClientVersion.V_1_15,
ClientVersion.V_1_16,
ClientVersion.V_1_16_2,
ClientVersion.V_1_17);
ClientVersion.V_1_17,
ClientVersion.V_1_19,
ClientVersion.V_1_19_3,
ClientVersion.V_1_19_4,
ClientVersion.V_1_20_3);
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings",
ClientVersion.V_1_8,
ClientVersion.V_1_9,
@@ -51,6 +55,12 @@ public class EntityTypes {
ClientVersion.V_1_12,
ClientVersion.V_1_13);
static {
TYPES_BUILDER.unloadFileMappings();
LEGACY_TYPES_BUILDER.unloadFileMappings();
}
public static EntityType define(String key, @Nullable EntityType parent) {
TypesBuilderData data = TYPES_BUILDER.define(key);
TypesBuilderData legacyData = LEGACY_TYPES_BUILDER.define(key);
@@ -162,13 +172,16 @@ public class EntityTypes {
public static final EntityType CHESTED_MINECART_ABSTRACT = define("chested_minecart_abstract", MINECART_ABSTRACT);
public static final EntityType AREA_EFFECT_CLOUD = define("area_effect_cloud", ENTITY);
public static final EntityType ARMOR_STAND = define("armor_stand", LIVINGENTITY);
public static final EntityType ALLAY = define("allay", ABSTRACT_CREATURE);
public static final EntityType ARROW = define("arrow", ABSTRACT_ARROW);
public static final EntityType AXOLOTL = define("axolotl", ABSTRACT_ANIMAL);
public static final EntityType BAT = define("bat", ABSTRACT_AMBIENT);
public static final EntityType BEE = define("bee", ABSTRACT_INSENTIENT);
public static final EntityType BLAZE = define("blaze", ABSTRACT_MONSTER);
public static final EntityType BOAT = define("boat", ENTITY);
public static final EntityType CHEST_BOAT = define("chest_boat", BOAT);
public static final EntityType CAT = define("cat", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType CAMEL = define("camel", ABSTRACT_HORSE);
public static final EntityType SPIDER = define("spider", ABSTRACT_MONSTER);
public static final EntityType CAVE_SPIDER = define("cave_spider", SPIDER);
public static final EntityType CHICKEN = define("chicken", ABSTRACT_ANIMAL);
@@ -193,6 +206,7 @@ public class EntityTypes {
public static final EntityType FALLING_BLOCK = define("falling_block", ENTITY);
public static final EntityType FIREWORK_ROCKET = define("firework_rocket", ENTITY);
public static final EntityType FOX = define("fox", ABSTRACT_ANIMAL);
public static final EntityType FROG = define("frog", ABSTRACT_ANIMAL);
public static final EntityType GHAST = define("ghast", ABSTRACT_FLYING);
public static final EntityType GIANT = define("giant", ABSTRACT_MONSTER);
public static final EntityType ITEM_FRAME = define("item_frame", ABSTRACT_HANGING);
@@ -254,6 +268,7 @@ public class EntityTypes {
public static final EntityType ENDER_PEARL = define("ender_pearl", PROJECTILE_ABSTRACT);
public static final EntityType EXPERIENCE_BOTTLE = define("experience_bottle", PROJECTILE_ABSTRACT);
public static final EntityType POTION = define("potion", PROJECTILE_ABSTRACT);
public static final EntityType TADPOLE = define("tadpole", ABSTRACT_FISHES);
@Deprecated // Exists only in 1.9 and 1.10
public static final EntityType TIPPED_ARROW = define("tipped_arrow", ARROW);
public static final EntityType TRIDENT = define("trident", ABSTRACT_ARROW);
@@ -264,6 +279,7 @@ public class EntityTypes {
public static final EntityType VILLAGER = define("villager", ABSTRACT_AGEABLE);
public static final EntityType VINDICATOR = define("vindicator", ABSTRACT_ILLAGER_BASE);
public static final EntityType WANDERING_TRADER = define("wandering_trader", ABSTRACT_AGEABLE);
public static final EntityType WARDEN = define("warden", ABSTRACT_MONSTER);
public static final EntityType WITCH = define("witch", ABSTRACT_MONSTER);
public static final EntityType WITHER = define("wither", ABSTRACT_MONSTER);
public static final EntityType WITHER_SKELETON = define("wither_skeleton", ABSTRACT_SKELETON);
@@ -286,4 +302,16 @@ public class EntityTypes {
public static final EntityType MINECART_TNT = define("minecart_tnt", MINECART_ABSTRACT);
public static final EntityType MINECART_HOPPER = define("minecart_hopper", MINECART_ABSTRACT);
public static final EntityType MINECART_MOB_SPAWNER = define("minecart_mob_spawner", MINECART_ABSTRACT);
// Added in 1.19.4
public static final EntityType DISPLAY = define("display", ENTITY);
public static final EntityType BLOCK_DISPLAY = define("block_display", DISPLAY);
public static final EntityType ITEM_DISPLAY = define("item_display", DISPLAY);
public static final EntityType TEXT_DISPLAY = define("text_display", DISPLAY);
public static final EntityType INTERACTION = define("interaction", DISPLAY);
public static final EntityType SNIFFER = define("sniffer", ABSTRACT_ANIMAL);
// Added in 1.20.3
public static final EntityType BREEZE = define("breeze", ABSTRACT_MONSTER);
public static final EntityType WIND_CHARGE = define("wind_charge", PROJECTILE_ABSTRACT);
}
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
* 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
@@ -24,6 +24,7 @@ import com.github.retrooper.packetevents.protocol.item.enchantment.type.Enchantm
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.nbt.*;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -60,9 +61,8 @@ public class ItemStack {
if (!this.cachedIsEmpty && this.getType().getMaxDurability() > 0) {
NBTCompound tag = this.getNBT();
return tag == null || !tag.getBoolean("Unbreakable");
} else {
return false;
}
return false;
}
public boolean isDamaged() {
@@ -125,7 +125,7 @@ public class ItemStack {
}
public ItemStack copy() {
return cachedIsEmpty ? EMPTY : new ItemStack(type, amount, nbt == null ? new NBTCompound() : nbt.copy(), legacyData);
return cachedIsEmpty ? EMPTY : new ItemStack(type, amount, nbt == null ? null : nbt.copy(), legacyData);
}
@Nullable
@@ -145,29 +145,30 @@ public class ItemStack {
this.legacyData = legacyData;
}
public boolean isEnchantable() {
public boolean isEnchantable(ClientVersion version) {
if (getType() == ItemTypes.BOOK) return getAmount() == 1;
if (getType() == ItemTypes.ENCHANTED_BOOK) return false;
return getMaxStackSize() == 1 && canBeDepleted() && !isEnchanted();
return getMaxStackSize() == 1 && canBeDepleted() && !isEnchanted(version);
}
public boolean isEnchanted() {
if (!isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull("Enchantments") != null) {
return !this.nbt.getCompoundListTagOrNull("Enchantments").isEmpty();
} else {
return false;
}
public boolean isEnchanted(ClientVersion version) {
String tagName = getEnchantmentsTagName(version);
return !isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull(tagName) != null && !this.nbt.getCompoundListTagOrNull(tagName).getTags().isEmpty();
}
private static List<Enchantment> getEnchantments(@Nullable NBTCompound nbt) {
if (nbt == null || nbt.getCompoundListTagOrNull("Enchantments") == null)
private List<Enchantment> getEnchantments(@Nullable NBTCompound nbt, ClientVersion version) {
String tagName = getEnchantmentsTagName(version);
if (nbt == null || nbt.getCompoundListTagOrNull(tagName) == null)
return new ArrayList<>(0);
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull("Enchantments");
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull(tagName);
List<NBTCompound> compounds = nbtList.getTags();
List<Enchantment> enchantments = new ArrayList<>(compounds.size());
for (NBTCompound compound : compounds) {
String id = compound.getStringTagValueOrNull("id");
EnchantmentType type = EnchantmentTypes.getByName(id);
EnchantmentType type = getEnchantmentTypeFromTag(compound, version);
if (type != null) {
NBTShort levelTag = compound.getTagOfTypeOrNull("lvl", NBTShort.class);
int level = levelTag.getAsInt();
@@ -175,21 +176,22 @@ public class ItemStack {
enchantments.add(enchantment);
}
}
return enchantments;
}
public List<Enchantment> getEnchantments() {
return getEnchantments(this.nbt);
public List<Enchantment> getEnchantments(ClientVersion version) {
return getEnchantments(this.nbt, version);
}
// TODO: Test on outdated versions
public int getEnchantmentLevel(EnchantmentType enchantment) {
if (isEnchanted()) {
public int getEnchantmentLevel(EnchantmentType enchantment, ClientVersion version) {
if (isEnchanted(version)) {
// isEnchanted() is true, so we can assume that nbt is not null
assert nbt != null;
for (NBTCompound base : nbt.getCompoundListTagOrNull("Enchantments").getTags()) {
NBTString string = base.getTagOfTypeOrNull("id", NBTString.class);
if (string != null && enchantment == EnchantmentTypes.getByName(string.getValue())) {
String tagName = getEnchantmentsTagName(version);
for (NBTCompound base : nbt.getCompoundListTagOrNull(tagName).getTags()) {
EnchantmentType type = getEnchantmentTypeFromTag(base, version);
if (enchantment == type) {
return base.getTagOfTypeOrNull("lvl", NBTShort.class).getAsInt();
}
}
@@ -198,27 +200,51 @@ public class ItemStack {
return 0;
}
public void setEnchantments(List<Enchantment> enchantments) {
@Nullable
private static EnchantmentType getEnchantmentTypeFromTag(NBTCompound tag, ClientVersion version) {
if (version.isNewerThanOrEquals(ClientVersion.V_1_13)) {
String id = tag.getStringTagValueOrNull("id");
return EnchantmentTypes.getByName(id);
} else {
NBTShort idTag = tag.getTagOfTypeOrNull("id", NBTShort.class);
return EnchantmentTypes.getById(version, idTag.getAsInt());
}
}
public void setEnchantments(List<Enchantment> enchantments, ClientVersion version) {
nbt = getOrCreateTag(); // Create tag if null
String tagName = getEnchantmentsTagName(version);
if (enchantments.isEmpty()) {
//Let us clear the enchantments
if (nbt.getTagOrNull("Enchantments") != null) {
nbt.removeTag("Enchantments");
if (nbt.getTagOrNull(tagName) != null) {
nbt.removeTag(tagName);
}
}
else {
} else {
List<NBTCompound> list = new ArrayList<>();
for (Enchantment enchantment : enchantments) {
NBTCompound compound = new NBTCompound();
compound.setTag("id", new NBTString(enchantment.getType().getName().toString()));
if (version.isNewerThanOrEquals(ClientVersion.V_1_13)) {
compound.setTag("id", new NBTString(enchantment.getType().getName().toString()));
} else {
compound.setTag("id", new NBTShort((short) enchantment.getType().getId(version)));
}
compound.setTag("lvl", new NBTShort((short) enchantment.getLevel()));
list.add(compound);
}
assert nbt != null; // NBT was created in getOrCreateTag()
nbt.setTag("Enchantments", new NBTList<>(NBTType.COMPOUND, list));
nbt.setTag(tagName, new NBTList<>(NBTType.COMPOUND, list));
}
}
public String getEnchantmentsTagName(ClientVersion version) {
String tagName = version.isNewerThanOrEquals(ClientVersion.V_1_13) ? "Enchantments" : "ench";
if (type == ItemTypes.ENCHANTED_BOOK) {
tagName = "StoredEnchantments";
}
return tagName;
}
public boolean canBeDepleted() {
return this.getType().getMaxDurability() > 0;
}
@@ -232,7 +258,16 @@ public class ItemStack {
}
public static boolean tagMatches(ItemStack left, ItemStack right) {
return left.isEmpty() && right.isEmpty() || (!left.isEmpty() && !right.isEmpty() && ((left.nbt != null || right.nbt == null) && (left.nbt == null || left.nbt.equals(right.nbt))));
if (left == right) {
return true;
}
if (left == null) {
return right.isEmpty();
}
if (right == null) {
return left.isEmpty();
}
return Objects.equals(left.nbt, right.nbt);
}
@Override
@@ -274,7 +309,6 @@ public class ItemStack {
private int amount = 1;
private NBTCompound nbt = null;
private int legacyData = -1;
private List<Enchantment> enchantments = null;
public Builder type(ItemType type) {
this.type = type;
@@ -288,13 +322,6 @@ public class ItemStack {
public Builder nbt(NBTCompound nbt) {
this.nbt = nbt;
List<Enchantment> nbtEnchantments = getEnchantments(nbt);
// This assumes logically, if already set enchants before NBT, then they would still want the enchants
if (!nbtEnchantments.isEmpty()) {
this.enchantments = nbtEnchantments;
}
return this;
}
@@ -303,32 +330,8 @@ public class ItemStack {
return this;
}
/**
* Side effect: This will cause NBT to be created if it is null
* This may affect some client sided inventory operations and may cause a desync
*
* @param enchantments The enchantments to set
* @return This builder
*/
public Builder enchantments(List<Enchantment> enchantments) {
this.enchantments = enchantments;
return this;
}
public Builder addEnchantment(Enchantment enchantment) {
if (enchantments == null) {
enchantments = new ArrayList<>();
}
this.enchantments.add(enchantment);
return this;
}
public ItemStack build() {
ItemStack stack = new ItemStack(type, amount, nbt, legacyData);
if (enchantments != null) {
stack.setEnchantments(enchantments);
}
return stack;
return new ItemStack(type, amount, nbt, legacyData);
}
}
@@ -0,0 +1,18 @@
package com.github.retrooper.packetevents.protocol.item.book;
public enum BookType {
CRAFTING,
FURNACE,
BLAST_FURNACE,
SMOKER;
public int getId() {
return ordinal();
}
public static BookType getById(int id) {
return VALUES[id];
}
private static final BookType[] VALUES = values();
}
Loaded 100 of 623 files, more files were not shown because too many files have changed in this diff. Show more