Compare commits

..
Author SHA1 Message Date
retrooper 9b3cf41f35 Working on loading API improvements for Spigot. 2022-12-07 22:20:44 +01: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 67eaa91252 Fix 1.12.2 chunk issues
* fix #472
2022-08-26 10:36:16 +02: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
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
535 changed files with 145903 additions and 110693 deletions

No files matched your search

+22 -18
View File
@@ -1,20 +1,15 @@
# 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)
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!
### Resources
* [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
* [JavaDocs](https://packetevents.github.io/javadocs)
* [Discord](https://discord.me/packetevents)
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. With our API, you can write code that runs on many platforms including Spigot, BungeeCord, Velocity, and even client-sided Fabric! Switch to PacketEvents today by joining \
our [Discord Server](https://discord.me/packetevents) for help.
### Links
* [Find release builds on SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
* [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)
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup-2.0)
### Sponsorships
[![](https://www.ej-technologies.com/images/product_banners/jprofiler_small.png)](https://www.ej-technologies.com/products/jprofiler/overview.html)
@@ -23,11 +18,20 @@ 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)
This library is licensed under the GPLv3 (General Public License version 3). Here are a few sources to learn more about the license.\
[![](https://www.gnu.org/graphics/gplv3-with-text-136x68.png)](https://github.com/retrooper/packetevents/blob/2.0/LICENSE)
### GPL Resources
* https://www.gnu.org/philosophy/free-sw.html
* https://www.gnu.org/philosophy/free-sw.html#clarifying
* https://www.gnu.org/licenses/copyleft.en.html
* https://www.gnu.org/licenses/quick-guide-gplv3.html
* https://gpl-violations.org/faq/sourcecode-faq/
### 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,12 +18,20 @@
package com.github.retrooper.packetevents;
import com.github.retrooper.packetevents.injector.ChannelInjector;
import com.github.retrooper.packetevents.manager.player.PlayerManager;
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
import com.github.retrooper.packetevents.manager.server.ServerManager;
import com.github.retrooper.packetevents.netty.NettyManager;
import com.github.retrooper.packetevents.settings.PacketEventsSettings;
import com.github.retrooper.packetevents.util.LogManager;
public final class PacketEvents {
private static PacketEventsAPI<?> API;
//Put these variable names anywhere else, they are really only for the injectors
public static String IDENTIFIER, ENCODER_NAME, DECODER_NAME, CONNECTION_HANDLER_NAME, SERVER_CHANNEL_HANDLER_NAME,
TIMEOUT_HANDLER_NAME;
TIMEOUT_HANDLER_NAME;
public static PacketEventsAPI<?> getAPI() {
return API;
@@ -32,4 +40,87 @@ public final class PacketEvents {
public static void setAPI(PacketEventsAPI<?> api) {
API = api;
}
public static Builder builder() {
return new Builder();
}
public abstract static class Context<T> {
private final Object pluginInstance;
private final ProtocolManager protocolManager;
private final ServerManager serverManager;
private final PlayerManager playerManager;
private final NettyManager nettyManager;
private final ChannelInjector injector;
private final LogManager logManager;
protected boolean lateBind = false;
public Context(Object pluginInstance, ProtocolManager protocolManager, ServerManager serverManager, PlayerManager playerManager,
NettyManager nettyManager, ChannelInjector injector, LogManager logManager) {
this.pluginInstance = pluginInstance;
this.protocolManager = protocolManager;
this.serverManager = serverManager;
this.playerManager = playerManager;
this.nettyManager = nettyManager;
this.injector = injector;
this.logManager = logManager;
}
protected abstract PacketEventsAPI<T> build();
public Object getPluginInstance() {
return pluginInstance;
}
public ProtocolManager getProtocolManager() {
return protocolManager;
}
public ServerManager getServerManager() {
return serverManager;
}
public PlayerManager getPlayerManager() {
return playerManager;
}
public NettyManager getNettyManager() {
return nettyManager;
}
public ChannelInjector getInjector() {
return injector;
}
public LogManager getLogManager() {
return logManager;
}
}
public static class Builder {
private Context<?> context = null;
private PacketEventsSettings settings = new PacketEventsSettings();
public Builder context(Context<?> context) {
this.context = context;
return this;
}
public Builder settings(PacketEventsSettings settings) {
this.settings = settings;
return this;
}
public PacketEventsAPI<?> build() {
if (context == null) {
throw new IllegalStateException("Failed to build a PacketEvents instance. Please specify a PacketEvents context in the PacketEvents builder to allow PacketEvents to load the correct implementation.");
}
PacketEventsAPI<?> api = context.build();
api.setSettings(settings);
//The implementation may have already set the API.
if (getAPI() == null) {
setAPI(api);
}
return api;
}
}
}
@@ -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
@@ -33,10 +33,11 @@ import java.util.logging.Logger;
public abstract class PacketEventsAPI<T> {
private static final EventManager EVENT_MANAGER = new EventManager();
private static final PacketEventsSettings SETTINGS = new PacketEventsSettings();
private static final UpdateChecker UPDATE_CHECKER = new UpdateChecker();
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
private static final LogManager LOG_MANAGER = new LogManager();
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
private PacketEventsSettings settings = new PacketEventsSettings();
//TODO UPDATE
private static final PEVersion VERSION = new PEVersion(2, 0, 0);
public EventManager getEventManager() {
@@ -44,7 +45,11 @@ public abstract class PacketEventsAPI<T> {
}
public PacketEventsSettings getSettings() {
return SETTINGS;
return settings;
}
public void setSettings(PacketEventsSettings settings) {
this.settings = settings;
}
public UpdateChecker getUpdateChecker() {
@@ -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
@@ -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
@@ -22,6 +22,7 @@ import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.netty.buffer.UnpooledByteBufAllocationHelper;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.PacketSide;
@@ -59,8 +60,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();
}
@@ -79,7 +79,7 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
this.packetType = PacketType.getById(packetSide, user.getConnectionState(),
version, packetID);
if (this.packetType == null) {
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
}
this.connectionState = user.getConnectionState();
}
@@ -206,4 +206,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
@@ -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,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
@@ -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
@@ -61,10 +61,15 @@ 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);
}
PacketEvents.getAPI().getLogManager().debug("Mapped player UUID with their channel.");
//Update connection state(injectors might do some adjustments when we transition into PLAY state)
//This also updates it for the user instance
@@ -76,32 +81,32 @@ public class InternalPacketListener extends PacketListenerAbstract {
// Join game can be used to update world height, and sets dimension data
if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
else if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
user.setEntityId(joinGame.getEntityId());
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
// Store world height
NBTList<NBTCompound> list = joinGame.getDimensionCodec()
.getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
NBTList<NBTCompound> list = joinGame.getDimensionCodec().getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
user.setWorldNBT(list);
// Update world height
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getType().getName()).getCompoundTagOrNull("element");
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getDimensionName()).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) {
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
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getDimensionName()).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());
}
@@ -113,17 +118,12 @@ 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();
if (clientVersion == ClientVersion.UNKNOWN) {
return;
}
//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());
@@ -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
@@ -26,15 +26,14 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public interface ProtocolManager {
Map<String, Object> CHANNELS = new ConcurrentHashMap<>();
Map<UUID, Object> CHANNELS = new ConcurrentHashMap<>();
Map<Object, User> USERS = new ConcurrentHashMap<>();
default Collection<User> getUsers() {
@@ -47,55 +46,49 @@ 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.
@@ -110,88 +103,46 @@ public interface ProtocolManager {
getUser(channel).setClientVersion(version);
}
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
default Object[] transformWrappers(PacketWrapper<?> wrapper) {
//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();
buffers[i] = wrappers[i].buffer;
}
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);
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);
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);
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);
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);
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);
receivePacketsSilently(channel, transformed);
}
default User getUser(Object channel) {
@@ -199,11 +150,13 @@ public interface ProtocolManager {
}
default void setUser(Object channel, User user) {
USERS.put(channel, user);
synchronized (channel) {
USERS.put(channel, 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,8 @@ 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),
//TODO UPDATE Add server version constant
ERROR(-1, true);
@@ -64,6 +67,7 @@ public enum ServerVersion {
private final int protocolVersion;
private final String name;
private ClientVersion toClientVersion;
ServerVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
@@ -84,17 +88,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 +107,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 +141,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 +153,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 +165,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 +177,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
@@ -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
@@ -26,6 +26,9 @@ public enum ConnectionState {
HANDSHAKING, STATUS, LOGIN, PLAY;
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,70 @@
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.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 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 Update {
private final LastSeenMessages lastSeenMessages;
private final @Nullable Entry lastReceived;
public Update(LastSeenMessages lastSeenMessages, @Nullable Entry lastReceived) {
this.lastSeenMessages = lastSeenMessages;
this.lastReceived = lastReceived;
}
public LastSeenMessages getLastSeenMessages() {
return lastSeenMessages;
}
public @Nullable Entry getLastReceived() {
return lastReceived;
}
}
}
@@ -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,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;
}
}
@@ -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,18 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.util.google;
package com.github.retrooper.packetevents.protocol.chat.filter;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
public enum FilterMaskType {
PASS_THROUGH,
FULLY_FILTERED,
PARTIALLY_FILTERED;
import java.util.concurrent.ConcurrentMap;
public static final FilterMaskType[] VALUES = values();
public class GuavaUtil {
public static <T, K> ConcurrentMap<T, K> makeMap(ServerVersion serverVersion) {
if (serverVersion.isNewerThan(ServerVersion.V_1_7_10)) {
return GuavaUtils_8.makeMap();
} else {
return GuavaUtils_7.makeMap();
}
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,105 @@
/*
* 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;
public class ChatMessage_v1_19 extends ChatMessage {
private @Nullable Component unsignedChatContent;
private UUID senderUUID;
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);
this.unsignedChatContent = unsignedChatContent;
this.senderUUID = senderUUID;
this.senderDisplayName = senderDisplayName;
this.teamName = teamName;
this.timestamp = timestamp;
this.salt = salt;
this.signature = signature;
}
public @Nullable Component getUnsignedChatContent() {
return unsignedChatContent;
}
public UUID getSenderUUID() {
return senderUUID;
}
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 setSenderUUID(UUID senderUUID) {
this.senderUUID = senderUUID;
}
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,191 @@
/*
* 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;
public class ChatMessage_v1_19_1 extends ChatMessage {
private String plainContent;
private @Nullable Component unsignedChatContent;
private UUID senderUUID;
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());
this.plainContent = plainContent;
this.unsignedChatContent = unsignedChatContent;
this.senderUUID = senderUUID;
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;
}
public UUID getSenderUUID() {
return senderUUID;
}
public void setSenderUUID(UUID senderUUID) {
this.senderUUID = senderUUID;
}
@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,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.chat.message.reader;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
public interface ChatMessageProcessor {
ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper);
void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data);
}
@@ -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,79 @@
/*
* 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) {
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();
int id = wrapper.readVarInt();
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
Component name = wrapper.readComponent();
Component targetName = wrapper.readOptional(PacketWrapper::readComponent);
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = new ChatMessage_v1_19_1.ChatTypeBoundNetwork(type, name, targetName);
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.writeVarInt(newData.getChatType().getType().getId(wrapper.getServerVersion().toClientVersion()));
wrapper.writeComponent(newData.getChatType().getName());
wrapper.writeOptional(newData.getChatType().getTargetName(), PacketWrapper::writeComponent);
}
}
@@ -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,16 +23,25 @@ import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.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.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 +57,44 @@ 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);
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<Float> FLOAT = define("float", PacketWrapper::readFloat, PacketWrapper::writeFloat);
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
public static final EntityDataType<Component> COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
public static final EntityDataType<Optional<Component>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
public static final EntityDataType<ItemStack> ITEMSTACK = define("itemstack", PacketWrapper::readItemStack, PacketWrapper::writeItemStack);
public static final EntityDataType<Optional<Object>> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<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 +102,55 @@ 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> 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 +163,22 @@ 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 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);
}
@@ -188,34 +255,6 @@ public class EntityDataTypes {
};
}
private static <T> Function<PacketWrapper<?>, T> readBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> (T) wrapper.readBlockPosition();
} else {
return (PacketWrapper<?> wrapper) -> {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return (T) new Vector3i(x, y, z);
};
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeBlockPositionSerializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper, T value) -> {
wrapper.writeBlockPosition((Vector3i) value);
};
} else {
return (PacketWrapper<?> wrapper, T value) -> {
Vector3i position = (Vector3i) value;
wrapper.writeInt(position.getX());
wrapper.writeInt(position.getY());
wrapper.writeInt(position.getZ());
};
}
}
private static <T> Function<PacketWrapper<?>, T> readOptionalBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> {
@@ -273,4 +312,5 @@ public class EntityDataTypes {
};
}
}
}
@@ -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
@@ -25,12 +25,11 @@ 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 byte skinPartsMask = SkinSection.ALL.getMask();
private HumanoidArm mainArm = HumanoidArm.RIGHT;
private NBTCompound leftShoulderNBT = new NBTCompound();
private NBTCompound rightShoulderNBT = new NBTCompound();
@@ -114,7 +113,7 @@ public class PlayerDataProvider extends LivingEntityDataProvider {
skinPartsMask = (byte) entityData.getValue();
break;
case 18:
mainArm = HumanoidArm.values()[(byte) entityData.getValue()];
mainArm = HumanoidArm.VALUES[(byte) entityData.getValue()];
break;
case 19:
leftShoulderNBT = (NBTCompound) entityData.getValue();
@@ -146,8 +145,8 @@ public class PlayerDataProvider extends LivingEntityDataProvider {
return (T)this;
}
public T skinParts(Set<SkinSection> skinSections) {
((PlayerDataProvider)provider).setSkinPartsMask(SkinSection.getMaskBySections(skinSections));
public T skinParts(SkinSection skinSections) {
((PlayerDataProvider)provider).setSkinPartsMask(skinSections.getMask());
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,7 +28,13 @@ public enum EntityPose {
SPIN_ATTACK,
CROUCHING,
LONG_JUMPING,
DYING;
DYING,
CROAKING,
USING_TONGUE,
ROARING,
SNIFFING,
EMERGING,
DIGGING;
public int getId(ClientVersion version) {
if (this == DYING && version.isOlderThan(ClientVersion.V_1_17)) {
@@ -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,8 @@ 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);
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings",
ClientVersion.V_1_8,
ClientVersion.V_1_9,
@@ -51,6 +52,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,12 +169,14 @@ 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 SPIDER = define("spider", ABSTRACT_MONSTER);
public static final EntityType CAVE_SPIDER = define("cave_spider", SPIDER);
@@ -193,6 +202,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 +264,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 +275,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);
@@ -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() {
@@ -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;
}
@@ -274,7 +300,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 +313,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 +321,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();
}
@@ -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
@@ -34,7 +34,8 @@ public class EnchantmentTypes {
ClientVersion.V_1_12,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_16);
ClientVersion.V_1_16,
ClientVersion.V_1_19);
public static EnchantmentType define(String key) {
TypesBuilderData data = TYPES_BUILDER.define(key);
@@ -94,6 +95,7 @@ public class EnchantmentTypes {
public static final EnchantmentType FROST_WALKER = define("frost_walker");
public static final EnchantmentType BINDING_CURSE = define("binding_curse");
public static final EnchantmentType SOUL_SPEED = define("soul_speed");
public static final EnchantmentType SWIFT_SNEAK = define("swift_sneak");
public static final EnchantmentType SHARPNESS = define("sharpness");
public static final EnchantmentType SMITE = define("smite");
public static final EnchantmentType BANE_OF_ARTHROPODS = define("bane_of_arthropods");
@@ -120,4 +122,8 @@ public class EnchantmentTypes {
public static final EnchantmentType PIERCING = define("piercing");
public static final EnchantmentType MENDING = define("mending");
public static final EnchantmentType VANISHING_CURSE = define("vanishing_curse");
static {
TYPES_BUILDER.unloadFileMappings();
}
}
@@ -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
@@ -43,7 +43,8 @@ public class ItemTypes {
ClientVersion.V_1_16,
ClientVersion.V_1_16_2,
ClientVersion.V_1_17,
ClientVersion.V_1_18);
ClientVersion.V_1_18,
ClientVersion.V_1_19);
public static final ItemType GILDED_BLACKSTONE = builder("gilded_blackstone").setMaxAmount(64).setPlacedType(StateTypes.GILDED_BLACKSTONE).build();
public static final ItemType NETHER_BRICK_SLAB = builder("nether_brick_slab").setMaxAmount(64).setPlacedType(StateTypes.NETHER_BRICK_SLAB).build();
@@ -767,7 +768,7 @@ public class ItemTypes {
public static final ItemType MAGENTA_STAINED_GLASS = builder("magenta_stained_glass").setMaxAmount(64).setPlacedType(StateTypes.MAGENTA_STAINED_GLASS).build();
public static final ItemType LAPIS_LAZULI = builder("lapis_lazuli").setMaxAmount(64).build();
public static final ItemType MUSIC_DISC_WAIT = builder("music_disc_wait").setMaxAmount(1).setAttributes(ItemAttribute.MUSIC_DISC).build();
public static final ItemType NETHERITE_PICKAXE = builder("netherite_pickaxe").setMaxAmount(1).setAttributes(ItemAttribute.FIRE_RESISTANT, ItemAttribute.NETHERITE_TIER).setMaxDurability(2031).build();
public static final ItemType NETHERITE_PICKAXE = builder("netherite_pickaxe").setMaxAmount(1).setAttributes(ItemAttribute.FIRE_RESISTANT, ItemAttribute.NETHERITE_TIER, ItemAttribute.PICKAXE).setMaxDurability(2031).build();
public static final ItemType BUNDLE = builder("bundle").setMaxAmount(1).build();
public static final ItemType MOOSHROOM_SPAWN_EGG = builder("mooshroom_spawn_egg").setMaxAmount(64).build();
public static final ItemType MAP = builder("map").setMaxAmount(64).build();
@@ -1146,6 +1147,57 @@ public class ItemTypes {
public static final ItemType PINK_CONCRETE = builder("pink_concrete").setMaxAmount(64).setPlacedType(StateTypes.PINK_CONCRETE).build();
public static final ItemType CARROT = builder("carrot").setMaxAmount(64).setAttributes(ItemAttribute.EDIBLE).setPlacedType(StateTypes.CARROTS).build();
public static final ItemType MUSIC_DISC_OTHERSIDE = builder("music_disc_otherside").setMaxAmount(1).setAttributes(ItemAttribute.MUSIC_DISC).build();
// 1.19 items
public static final ItemType MUD = builder("mud").setMaxAmount(64).setPlacedType(StateTypes.MUD).build();
public static final ItemType MANGROVE_PLANKS = builder("mangrove_planks").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_PLANKS).build();
public static final ItemType MANGROVE_PROPAGULE = builder("mangrove_propagule").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_PROPAGULE).build();
public static final ItemType MANGROVE_LOG = builder("mangrove_log").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_LOG).build();
public static final ItemType MANGROVE_ROOTS = builder("mangrove_roots").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_ROOTS).build();
public static final ItemType MUDDY_MANGROVE_ROOTS = builder("muddy_mangrove_roots").setMaxAmount(64).setPlacedType(StateTypes.MUDDY_MANGROVE_ROOTS).build();
public static final ItemType STRIPPED_MANGROVE_LOG = builder("stripped_mangrove_log").setMaxAmount(64).setPlacedType(StateTypes.STRIPPED_MANGROVE_LOG).build();
public static final ItemType STRIPPED_MANGROVE_WOOD = builder("stripped_mangrove_wood").setMaxAmount(64).setPlacedType(StateTypes.STRIPPED_MANGROVE_WOOD).build();
public static final ItemType MANGROVE_WOOD = builder("mangrove_wood").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_WOOD).build();
public static final ItemType MANGROVE_LEAVES = builder("mangrove_leaves").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_LEAVES).build();
public static final ItemType MANGROVE_SLAB = builder("mangrove_slab").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_SLAB).build();
public static final ItemType MUD_BRICK_SLAB = builder("mud_brick_slab").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICK_SLAB).build();
public static final ItemType MANGROVE_FENCE = builder("mangrove_fence").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_FENCE).build();
public static final ItemType PACKED_MUD = builder("packed_mud").setMaxAmount(64).setPlacedType(StateTypes.PACKED_MUD).build();
public static final ItemType MUD_BRICKS = builder("mud_bricks").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICKS).build();
public static final ItemType REINFORCED_DEEPSLATE = builder("reinforced_deepslate").setMaxAmount(64).setPlacedType(StateTypes.REINFORCED_DEEPSLATE).build();
public static final ItemType MUD_BRICK_STAIRS = builder("mud_brick_stairs").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICK_STAIRS).build();
public static final ItemType SCULK = builder("sculk").setMaxAmount(64).setPlacedType(StateTypes.SCULK).build();
public static final ItemType SCULK_VEIN = builder("sculk_vein").setMaxAmount(64).setPlacedType(StateTypes.SCULK_VEIN).build();
public static final ItemType SCULK_CATALYST = builder("sculk_catalyst").setMaxAmount(64).setPlacedType(StateTypes.SCULK_CATALYST).build();
public static final ItemType SCULK_SHRIEKER = builder("sculk_shrieker").setMaxAmount(64).setPlacedType(StateTypes.SCULK_SHRIEKER).build();
public static final ItemType MUD_BRICK_WALL = builder("mud_brick_wall").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICK_WALL).build();
public static final ItemType MANGROVE_BUTTON = builder("mangrove_button").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_BUTTON).build();
public static final ItemType MANGROVE_PRESSURE_PLATE = builder("mangrove_pressure_plate").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_PRESSURE_PLATE).build();
public static final ItemType MANGROVE_DOOR = builder("mangrove_door").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_DOOR).build();
public static final ItemType MANGROVE_TRAPDOOR = builder("mangrove_trapdoor").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_TRAPDOOR).build();
public static final ItemType MANGROVE_FENCE_GATE = builder("mangrove_fence_gate").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_FENCE_GATE).build();
public static final ItemType MANGROVE_SIGN = builder("mangrove_sign").setMaxAmount(16).setPlacedType(StateTypes.MANGROVE_SIGN).build();
public static final ItemType TADPOLE_BUCKET = builder("tadpole_bucket").setMaxAmount(1).build();
public static final ItemType RECOVERY_COMPASS = builder("recovery_compass").setMaxAmount(64).build();
public static final ItemType ALLAY_SPAWN_EGG = builder("allay_spawn_egg").setMaxAmount(64).build();
public static final ItemType FROG_SPAWN_EGG = builder("frog_spawn_egg").setMaxAmount(64).build();
public static final ItemType TADPOLE_SPAWN_EGG = builder("tadpole_spawn_egg").setMaxAmount(64).build();
public static final ItemType WARDEN_SPAWN_EGG = builder("warden_spawn_egg").setMaxAmount(64).build();
public static final ItemType MUSIC_DISC_5 = builder("music_disc_5").setMaxAmount(1).build();
public static final ItemType DISC_FRAGMENT_5 = builder("disc_fragment_5").setMaxAmount(64).build();
public static final ItemType OCHRE_FROGLIGHT = builder("ochre_froglight").setMaxAmount(64).setPlacedType(StateTypes.OCHRE_FROGLIGHT).build();
public static final ItemType VERDANT_FROGLIGHT = builder("verdant_froglight").setMaxAmount(64).setPlacedType(StateTypes.VERDANT_FROGLIGHT).build();
public static final ItemType PEARLESCENT_FROGLIGHT = builder("pearlescent_froglight").setMaxAmount(64).setPlacedType(StateTypes.PEARLESCENT_FROGLIGHT).build();
public static final ItemType FROGSPAWN = builder("frogspawn").setMaxAmount(64).setPlacedType(StateTypes.FROGSPAWN).build();
public static final ItemType ECHO_SHARD = builder("echo_shard").setMaxAmount(64).build();
public static final ItemType GOAT_HORN = builder("goat_horn").setMaxAmount(1).build();
public static final ItemType OAK_CHEST_BOAT = builder("oak_chest_boat").setMaxAmount(1).build();
public static final ItemType SPRUCE_CHEST_BOAT = builder("spruce_chest_boat").setMaxAmount(1).build();
public static final ItemType BIRCH_CHEST_BOAT = builder("birch_chest_boat").setMaxAmount(1).build();
public static final ItemType JUNGLE_CHEST_BOAT = builder("jungle_chest_boat").setMaxAmount(1).build();
public static final ItemType ACACIA_CHEST_BOAT = builder("acacia_chest_boat").setMaxAmount(1).build();
public static final ItemType DARK_OAK_CHEST_BOAT = builder("dark_oak_chest_boat").setMaxAmount(1).build();
public static final ItemType MANGROVE_BOAT = builder("mangrove_boat").setMaxAmount(1).build();
public static final ItemType MANGROVE_CHEST_BOAT = builder("mangrove_chest_boat").setMaxAmount(1).build();
/**
* @deprecated Burning furnace shows up as a missing texture, removed in 1.9
*/
@@ -1178,7 +1230,6 @@ public class ItemTypes {
Collections.unmodifiableSet(new HashSet<>(attributesArr));
TypesBuilderData data = TYPES_BUILDER.define(key);
boolean musicDisc = attributes.contains(ItemAttribute.MUSIC_DISC);
ItemType type = new ItemType() {
private final int[] ids = data.getData();
@@ -1206,7 +1257,7 @@ public class ItemTypes {
@Override
public boolean isMusicDisc() {
return musicDisc;
return getAttributes().contains(ItemAttribute.MUSIC_DISC);
}
@Override
@@ -1313,4 +1364,8 @@ public class ItemTypes {
return this;
}
}
static {
TYPES_BUILDER.unloadFileMappings();
}
}
@@ -1,3 +1,21 @@
/*
* 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.mapper;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
@@ -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
@@ -20,7 +20,7 @@ package com.github.retrooper.packetevents.protocol.mapper;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
public interface StaticMappedEntity extends MappedEntity{
public interface StaticMappedEntity extends MappedEntity {
int getId();
default int getId(ClientVersion version) {
@@ -35,6 +35,11 @@ public class NBTByte extends NBTNumber {
return NBTType.BYTE;
}
@Override
public Number getAsNumber() {
return value;
}
@Override
public byte getAsByte() {
return value;
@@ -203,8 +203,7 @@ public class NBTCompound extends NBT {
public boolean getBoolean(String string) {
NBTByte nbtByte = this.getTagOfTypeOrNull(string, NBTByte.class);
// Empty byte tags are considered 0
byte byteValue = nbtByte == null ? 0 : nbtByte.getAsByte();
return byteValue != 0;
return nbtByte != null && nbtByte.getAsByte() != 0;
}
@Override
@@ -31,6 +31,11 @@ public class NBTDouble extends NBTNumber {
return NBTType.DOUBLE;
}
@Override
public Number getAsNumber() {
return value;
}
@Override
public byte getAsByte() {
return (byte) value;
@@ -31,6 +31,11 @@ public class NBTFloat extends NBTNumber {
return NBTType.FLOAT;
}
@Override
public Number getAsNumber() {
return value;
}
@Override
public byte getAsByte() {
return (byte) value;
@@ -31,6 +31,11 @@ public class NBTInt extends NBTNumber {
return NBTType.INT;
}
@Override
public Number getAsNumber() {
return value;
}
@Override
public byte getAsByte() {
return (byte) value;
@@ -87,6 +87,10 @@ public class NBTList<T extends NBT> extends NBT {
tags.add(tag);
}
public void addTagUnsafe(NBT nbt) {
addTag((T)nbt);
}
protected void validateAddTag(T tag) {
if (type != tag.getType()) {
throw new IllegalArgumentException(MessageFormat.format("Invalid tag type. Expected {0}, got {1}.", type.getNBTClass(), tag.getClass()));
@@ -31,6 +31,11 @@ public class NBTLong extends NBTNumber {
return NBTType.LONG;
}
@Override
public Number getAsNumber() {
return value;
}
@Override
public byte getAsByte() {
return (byte) value;
@@ -20,6 +20,11 @@ package com.github.retrooper.packetevents.protocol.nbt;
public abstract class NBTNumber extends NBT {
//PacketEvents start - We added this to make the nbt -> json conversion easier.
//We also implemented it in the classes extending this class.
public abstract Number getAsNumber();
//PacketEvents end
public abstract byte getAsByte();
public abstract short getAsShort();
Loaded 100 of 535 files, more files were not shown because too many files have changed in this diff. Show more