Compare commits

...
1043 Commits
Author SHA1 Message Date
retrooper 58f6cf5411 Cut off 1.7.10 injector. We still support 1.7.10 protocol, just not 1.7.10 server software!!!
Attempted reload support again. (Tested on 1.8.8)

PacketSide#getOpposite added
2022-04-07 22:59:38 +02:00
retrooper d966013b69 On Spigot, we now are behind Via & PS again! 2022-04-07 21:27:49 +02:00
retrooper 8261d95a4b Fixed incorrect HealthDisplay data in ScoreboardObjective wrapper by @LeeGodSRC 2022-04-07 20:33:45 +02:00
retrooper 0ec7cbdd64 Merge pull request #311 from FairyProject/bugfix/teams
Teams packet wrapper team name read/write with 16 max characters
2022-04-07 20:31:31 +02:00
retrooper 01aef56066 Fixed Empty NBT from being added to ItemStacks leading to a desync. (DefineOutside) 2022-04-06 22:47:05 +02:00
retrooper a1ca6e68bc Fix 1.8-1.12 entity type mappings
(DefineOutside)
2022-04-06 22:40:28 +02:00
retrooper bd2ae75b08 Fixed duplicate UserLoginEvent calls. 2022-04-03 23:28:36 +02:00
retrooper ed9cd05619 Spigot debug listener unregistered. 2022-04-03 20:43:55 +02:00
retrooper fdbe47a061 PacketListenerReflect removed;
PlayerInjectEvent removed, its replacement is UserLoginEvent
2022-04-03 20:42:18 +02:00
retrooper a4b326cd44 Velocity hopefully working on all versions. 2022-04-03 20:12:36 +02:00
retrooper 7e2c66a82e Optimized WrapperLoginServerLoginSuccess and progress on velocity? 2022-04-03 19:52:22 +02:00
retrooper 0913057d0d Fixed item type mappings on 1.16.2 2022-04-03 18:10:24 +02:00
retrooper 9d75d537cc Merge remote-tracking branch 'origin/version-dynamic' into version-dynamic 2022-04-01 21:30:28 +02:00
retrooper c1a2d05803 Outgoing packets must be in format of server, not client. 2022-04-01 21:30:18 +02:00
retrooper a0e05bb588 Updated our README 2022-04-01 21:19:20 +02:00
retrooper d8d3b77d5f Minor change to README. 2022-04-01 21:14:46 +02:00
retrooper ab4dce2af3 Trying to make protocol translation optional! On proxies we do not want it. 2022-04-01 21:12:11 +02:00
retrooper f0588eed10 Made WrappedBlockState and StateTypes more version dynamic. Now packetevents should hopefully be able to operate before via. 2022-04-01 19:52:57 +02:00
retrooper 99d6ee3554 Merge branch '2.0' into version-dynamic
# Conflicts:
#	spigot/src/main/java/io/github/retrooper/packetevents/injector/latest/connection/ServerConnectionInitializerLatest.java
2022-04-01 17:58:24 +02:00
retrooper 3e00a40918 PlayerManagerImpl in spigot module now reads game profile in players and will pass them into our User class.
User#sendTitle with strings added.
2022-04-01 17:45:06 +02:00
retrooper 1d97510869 Little comment added. 2022-03-31 22:54:39 +02:00
retrooper db3a804d15 NPE for optional in BlockPlacement wrapper fixed;
Decoder handler duplication on reloads fixed on 1.8+ servers
2022-03-31 22:44:27 +02:00
retrooper c83613ab04 Bug fixes for WrapperPlayServerSetTitleText & SetTitleSubtitle HANDLE_JSON should be true by default. 2022-03-28 22:43:59 +02:00
retrooper 42b7bb02c2 Packet type mappings per client version work.
We can process incoming packets ahead of via & protocolsupport successfully, ignoring world packets cause of wrappedblockstate.
2022-03-27 00:20:44 +01:00
retrooper c18739e057 Removed debugs. 2022-03-26 22:34:34 +01:00
retrooper 4ea4bf43e5 PacketType enums are version dynamic. You can get id by version and get the constant by id depending on version. It is beautiful. 2022-03-26 22:32:01 +01:00
retrooper 417571fe8d Bug fix for PotionTypes#getById 2022-03-25 22:23:46 +01:00
retrooper 24a2527fb2 Lots of progress on getting our mapped abstraction more version dynamic. 2022-03-25 22:22:56 +01:00
retrooper c8b94ec829 Optimization to PotionTypes. We removed the mappings and hard-code the IDs statically. EntityEffect & RemoveEntityEffect deprecated constructors removed. 2022-03-23 22:26:45 +01:00
retrooper 8dfbda5e35 We now have more meaningful stacktraces. For example when a packet has no content or fail to read a packet id or map a packet id to a packet type constant. 2022-03-23 22:11:16 +01:00
retrooper a9fb68223a Our netty handlers now produce exceptions in our wrappers and internal api.
WrapperPlayServerMultiBlockChange NPE fixed.
2022-03-23 21:37:14 +01:00
retrooper 9d69afaa81 Updated bug report template. 2022-03-22 23:04:15 +01:00
retrooper 5e1ff9b88a Minor change to namings. 2022-03-22 21:09:50 +01:00
retrooper 9bb6d9326c User#sendTitle implemented.
Implemented all title wrappers.
2022-03-22 20:46:46 +01:00
retrooper b00389f19f Added TimeStampMode setting to allow you to specify details about the timing in our events. You can even disable logging the time if you don't need it. 2022-03-22 19:46:45 +01:00
retrooper a4eb8cbece Minor changes. 2022-03-18 22:36:32 +01:00
retrooper 9463a07e9d PostPlayerInjectEvent removed
Replaced with better UserLoginEvent which also contains the User instance along with the Player instance on the platform.
2022-03-18 22:28:14 +01:00
retrooper 763a6c5d78 readOnly in listeners removed.
Its now a global setting in PacketEventsSettings#readOnlyListeners
2022-03-18 20:21:58 +01:00
retrooper b89ad2e128 Making some helpers in our api module so we don't duplicate lots of code in our implementations(modules)
Added UserConnectEvent & UserDisconnectEvent

threadSafe in PacketListeners removed.
2022-03-18 18:26:33 +01:00
retrooper 747a1a73c4 User references actually get destroyed when they disconnect.
User#getEntityId added.

PacketTransformationUtil memory leaks fixed.
2022-03-16 22:54:21 +01:00
retrooper ab99da9e7a Tryna fix some early packet handling. 2022-03-16 20:18:30 +01:00
retrooper 8969742139 Added few comments. 2022-03-16 16:41:41 +01:00
retrooper c5002778c9 Fixed memory leaks when converting Packetevents itemstack to bukkit and vice versa. 2022-03-16 16:35:42 +01:00
retrooper 97b7e81908 New EntityTypes added.
SpigotDataHelper#fromBukkitEntityType tested to work on 1.8.8
2022-03-13 22:35:23 +01:00
retrooper 323d553d5e Fixed velocity module netty dependency 2022-03-13 19:25:42 +01:00
retrooper fe13d021c1 Improvement to build.gradle 2022-03-13 19:09:12 +01:00
retrooper aa11d7e42e Last minor improvements to ResourcePackSend wrapper. 2022-03-13 18:49:31 +01:00
retrooper 8bca8d1cb5 Code optimization to WrapperPlayServerResourcePackSend. Now accepts a nullable prompt. 2022-03-13 18:43:33 +01:00
retrooper ca5021d090 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-03-13 18:34:04 +01:00
retrooper cbd899983e Cleaned up our build system. Adventure issues fixed. 2022-03-13 18:33:49 +01:00
retrooper 7529499f30 Fixed legacy adventure serializer. 2022-03-13 18:02:49 +01:00
retrooper b69fe1bdc1 Relocating sections of adventure. 2022-03-13 17:57:40 +01:00
MWHunter 424f18e52b Support invalid protocol with 1.8 biome data 2022-03-12 20:22:59 -06:00
retrooper 3a53fa88cb Adventure dependencies are now implementation, not api. 2022-03-13 00:01:20 +01:00
retrooper a1a2275794 Bump up adventure version. 2022-03-13 00:00:10 +01:00
retrooper 354596bc3d Cleaned up weird adventure stuff. We now properly relocate it I hope. 2022-03-12 23:54:13 +01:00
DefineOutside b9b34a4bbe Merge pull request #284 from amnoah/2.0
WrapperPlayServerResourcePackSend
2022-03-12 16:53:33 -06:00
Spiriten 8e8a2a114c Minor issue fix 2022-03-12 17:17:21 -05:00
Spiriten b6667f2fb8 Fixed Define's Points 2022-03-12 17:14:40 -05:00
retrooper ef6a36d5e2 We relocate adventure in Spigot, Velocity & BungeeCord manually. 2022-03-12 22:58:17 +01:00
retrooper 70e385e892 Added "adventure-gson" module.
We now relocate adventure.
2022-03-12 19:41:14 +01:00
Spiriten a74a6b0d0f WrapperPlayServerResourcePackSend
I think I did it correctly, please let me know if anything is wrong.

Basically copied from MCProtocolLib
2022-03-11 23:41:27 -05:00
retrooper 998b950f6f Renaming of methods in PacketWrapper
PacketWrapper#readData() -> read()
PacketWrapper#readData(PacketWrapper) -> copy(PacketWrapper)
PacketWrapper#writeData() -> write()
2022-03-11 23:21:00 +01:00
retrooper 9e54e4f296 Bump adventure api version down. 2022-03-11 23:10:58 +01:00
retrooper 1fb65d2628 Removed redundant .zip extension to builds. 2022-03-11 22:24:30 +01:00
retrooper a7811cd10f Little improvement to github actions. Automatically build all modules. 2022-03-11 22:23:59 +01:00
retrooper 9e3c36d48c Now publish velocity in github actions. Builds are now in .zips cause they are zips 2022-03-11 22:19:14 +01:00
retrooper 57db7d3936 The build names are now normal and not just "spigot" or "bungeecord". 2022-03-11 22:13:52 +01:00
retrooper 98dfccce1a We want the jars to have proper names. Lets see if jitpack can work with these. 2022-03-11 21:58:45 +01:00
retrooper 2eb0959215 Minor change to build.gradle 2022-03-11 21:41:20 +01:00
retrooper 64f1535ae4 Last cleanup/improvement I swear 2022-03-11 17:02:38 +01:00
retrooper 1665fe9ec0 We don't redeclare shadow plugin in each module. 2022-03-11 16:49:59 +01:00
retrooper ac054bee35 Further optimizations to build.gradles. Less code repetition, more coming! 2022-03-11 16:29:41 +01:00
retrooper 92c7c64a19 Cleaning up build.gradles to avoid code repetition. 2022-03-11 16:24:56 +01:00
retrooper 16c4c749e9 Hopefully fixed legacy adventure implementation 2022-03-11 16:17:31 +01:00
retrooper 8dddd3c519 Made sure we bumped the adventure version everywhere. 2022-03-10 22:52:33 +01:00
retrooper f48ba98c22 Our adventure module also bumped up adventure version. 2022-03-10 22:30:55 +01:00
retrooper 9a86f800c7 No debugs 2022-03-10 22:05:04 +01:00
retrooper 3a2e636f1f Cleanup build.gradle files in modules. 2022-03-10 22:04:44 +01:00
retrooper d87439cf0a Optimized/Fixed writePacket implementation on Spigot. 2022-03-10 18:43:10 +01:00
retrooper 0d637e0a2c Bumped jetbrains annotations version. 2022-03-10 17:56:07 +01:00
retrooper 153b751738 Merge pull request #277 from AbhigyaKrishna/2.0
Fix llegacy hover serializer & Update adventure
2022-03-10 17:45:16 +01:00
Abhigya bb6cc79c80 Adventure version bump and Legacy hover serializer 2022-03-10 17:16:19 +05:30
retrooper e67bfb55fe Removed debugs. 2022-03-09 20:57:09 +01:00
retrooper c0212f937e Minor fix in WrapperPlayServerUpdateScore 2022-03-09 19:58:48 +01:00
retrooper e448928194 SpigotDataHelper#fromBukkitItemMaterial probably works now. 2022-03-09 18:24:29 +01:00
retrooper 7c6b6a02a0 Working on converting bukkit material to our data types. 2022-03-09 18:14:23 +01:00
retrooper 79f6903a7d Cleaned up ViaVersionUtil, removed unused methods. 2022-03-09 16:14:16 +01:00
retrooper 800881fec8 Added WrapperStatusClientRequest wrapper (even though it has no fields) 2022-03-08 21:58:12 +01:00
retrooper d47bc0ea29 Removed debugs. 2022-03-08 20:36:47 +01:00
retrooper a9876a0cec Fixed & cleaned up our injector. Optimizations to our handlers. 2022-03-08 20:33:23 +01:00
retrooper 064ceb6c12 Merge branch '2.0' into protocollib_compat 2022-03-08 20:08:50 +01:00
retrooper f6bce0d41b Minor cleanup. 2022-03-08 20:08:11 +01:00
retrooper 31d572a8b6 Fixed update checker. 2022-03-08 20:04:20 +01:00
retrooper 354112c8b3 Again.. 2022-03-06 22:10:50 +01:00
retrooper cc561a6586 Confused, tryna fix jitpack stuff 2022-03-06 22:07:43 +01:00
retrooper 8cbb30711f Trying to fix jitpack? 2022-03-06 22:01:01 +01:00
retrooper ed1d88b1c8 More progress on velocity injector. We just need to support the compression handlers being added. 2022-03-06 20:19:41 +01:00
retrooper ed37c60257 Bug fix in ServerConnectionInitializerLatest#destroyChannel when multiple packetevents instances are present. 2022-03-06 14:24:41 +01:00
retrooper ae2a99a645 We clear our channel cache as soon as the connection closes. 2022-03-06 14:22:18 +01:00
retrooper 88c24308b2 Resolved conflicts. 2022-03-06 14:21:03 +01:00
retrooper 8a86a92504 Merge branch '2.0' into protocollib_compat
# Conflicts:
#	spigot/src/main/java/io/github/retrooper/packetevents/bukkit/InternalBukkitListener.java
2022-03-06 14:20:17 +01:00
retrooper 7d87114d69 Removed ProtocolManager#clearUserData, but we still are vulnerable to memory leaks in our channel caching. Will be fixed in protocollib_compat branch. 2022-03-06 14:16:41 +01:00
retrooper 4c76588493 Minor changes. 2022-03-06 14:03:18 +01:00
retrooper 3a6778eee7 Fixed PlayerDigging status reading, as it's an unsigned byte, not signed.
Fixed WindowConfirmation, OpenHorseWindow, WindowConfirmation window id reading as it's an unsigned byte, not signed.
2022-03-06 13:25:49 +01:00
retrooper 474a2c9e2e Working on Velocity support. 2022-03-06 12:19:01 +01:00
retrooper fdf36cfb62 Merge branch '2.0' into protocollib_compat 2022-03-06 11:35:27 +01:00
retrooper 7ee8799b3d Fixed PostPlayerInjectEvent#getClientVersion 2022-03-06 11:02:41 +01:00
retrooper 8f03460821 Merged "2.0-gradle". Basically cleaning up our gradle stuff. 2022-03-06 10:56:27 +01:00
retrooper 275638339f Make sure we are ideally the last to intercept connecting clients. Not first. 2022-03-05 23:53:37 +01:00
retrooper e86e946463 Merge branch '2.0' into protocollib_compat 2022-03-05 23:51:48 +01:00
retrooper 4d77af307c Merge branch '2.0' into 2.0-gradle 2022-03-05 23:50:39 +01:00
retrooper ec6f947379 Memory usage of mappings already improved, further improvements coming. 2022-03-05 23:49:58 +01:00
retrooper 5b977bb0b9 Added adventure module which does not ship with gson. 2022-03-05 22:02:39 +01:00
retrooper 535a95b199 Attempt to not automatically shade adventure & gson. Allow platforms such as fabric to not include gson. 2022-03-05 21:06:00 +01:00
retrooper 775ebc5de4 PacketCompressionUtil relocated 2022-03-05 18:20:52 +01:00
retrooper b756faf83c Merge branch '2.0' into protocollib_compat
# Conflicts:
#	spigot/src/main/java/io/github/retrooper/packetevents/PacketEventsPlugin.java
2022-03-05 18:16:08 +01:00
retrooper 269df338e4 Debugs removed. 2022-03-05 18:10:10 +01:00
retrooper 2827bef4b9 1.18.2 bug fixes. 2022-03-05 17:53:17 +01:00
retrooper 3d0e7b86b7 Cleaned up mess with using flying and its sub wrappers. Issues fixed. 2022-03-03 23:26:56 +01:00
retrooper 5c5fb9c8c8 Minor change 2022-03-03 22:47:54 +01:00
retrooper 8ae7b30df8 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-03-03 22:02:25 +01:00
retrooper 52d201ac93 Renames of NPC methods 2022-03-03 22:00:09 +01:00
MWHunter 326b3bfe62 WrapperPlayServerWorldBorder 2022-03-03 14:48:22 -06:00
MWHunter 98d037890e World border wrappers 2022-03-03 14:40:33 -06:00
retrooper 6146ef6ac3 NPCManager removed.
NPC class that can be used independently.
2022-03-03 18:21:15 +01:00
MWHunter 117328caf7 Fix multi block change for pre-1.16 servers 2022-03-01 14:22:13 -06:00
retrooper 06b4607769 Added async methods for sending and receiving and writing packets. 2022-03-01 21:18:09 +01:00
retrooper 6d2ffc59da Reverting to older version of packetevents where building worked? 2022-03-01 20:47:32 +01:00
retrooper e91984a2d6 We now relocate the libraries we shade(adventure and gson) 2022-03-01 20:16:05 +01:00
retrooper 9f657bf2ab We really fixed our gradle stuff, we don't unnecessary shade things when we don't need them. Hopefully can get fabric support working sooner than you'd think. 2022-03-01 19:41:39 +01:00
retrooper 0c9475afaf Working on allowing optional adventure & gson shading? Hopefully this works? 2022-03-01 18:48:36 +01:00
retrooper 675fa06ba9 Stop publishing "packetevents" module, only the sub modules. 2022-03-01 18:08:14 +01:00
retrooper 65bc4e18b0 Updated to adventure 4.10.0 2022-03-01 06:41:26 +01:00
retrooper 9d4ecfe283 Added 1.18.2 support. 2022-02-28 22:32:33 +01:00
retrooper b2a664dbd0 WrapperPlayServerEntityHeadLook & WrapperPlayServerEntityRelativeMoveAndRotation & WrapperPlayServerEntityRotation now use floats. 2022-02-27 19:55:09 +01:00
retrooper e80793c71b Cleaned up Spigot injector.
Forgot to commit PacketEncoderLatest
2022-02-27 17:02:00 +01:00
retrooper f3f02fbc28 Cleaned up Spigot injector.
Refactored spigot util classes.
2022-02-27 17:01:25 +01:00
retrooper b469fddae5 Pull optimizations from 2.0, this is a branch where we work on cleaning up the injector. 2022-02-27 14:00:18 +01:00
retrooper 550904f64a Minor change to BungeePipelineInjector 2022-02-27 13:57:22 +01:00
retrooper 6fd8a4c957 Minor optimizations to NetworkChunkData 2022-02-27 10:10:48 +01:00
retrooper e0f5ab6d6d Fixed WrapperPlayClientPlayerDigging for 1.8 2022-02-27 09:54:14 +01:00
retrooper bb8e96da34 User#closeConnection added 2022-02-27 09:27:19 +01:00
retrooper 2a47fa25dd Writing packets is faster now. 2022-02-27 09:16:14 +01:00
retrooper 3a78329fba Removed debug. 2022-02-26 22:44:39 +01:00
retrooper 51879a5003 Removed debug. 2022-02-26 22:16:05 +01:00
retrooper 3b9646436f Reverted back to old encoder system, shoudl work with experimental protocollib builds. 2022-02-26 21:26:39 +01:00
retrooper 0de0042591 Optimizations to utilities 2022-02-25 22:13:10 +01:00
retrooper 4b57de43be Merge remote-tracking branch 'origin/2.0' into 2.0 2022-02-25 16:52:54 +01:00
retrooper f7846f6bc6 Updated to 1.18.2 ahead of time? 2022-02-25 16:51:48 +01:00
MWHunter cc92d8ab69 Flag byte masks are being read wrong 2022-02-24 21:28:37 -06:00
retrooper 62ac36d436 Added support for thread-safe packet listeners(processing packets when not on netty-threads) 2022-02-24 22:13:59 +01:00
MWHunter afe5bed6fc Stop console spam with ProtocolLib + ViaVersion 2022-02-24 13:37:32 -06:00
retrooper a3c956bf04 I don't think we handle cancelling right yet... 2022-02-23 22:46:43 +01:00
retrooper 17d703bf56 Another attempt to fix viaversion cancelling packets.
User#closeInventory added
2022-02-23 21:02:28 +01:00
retrooper 87b58f2ab8 Support ViaVersion cancelling packets. 2022-02-23 20:50:54 +01:00
retrooper 2e660714aa Fixed buffer memory leak in PacketEncoderModern 2022-02-23 20:17:18 +01:00
retrooper 5d983eebf0 Think we support colors now in User#sendMessage(String) 2022-02-23 19:52:07 +01:00
retrooper 2639c615e8 Fixed cancelling outgoing packets. 2022-02-23 19:45:49 +01:00
retrooper e92f1c8e16 Only inject real players. NPCs from plugins such as Citizens will not be injected. 2022-02-23 19:18:17 +01:00
retrooper 6bc8274e2d Removed debugs 2022-02-23 18:48:24 +01:00
retrooper a26b59a233 Trying to fix possibility of null event! 2022-02-23 18:47:38 +01:00
retrooper 6505738fbf Minor change. 2022-02-22 22:21:08 +01:00
retrooper 10c11e3c56 Minor change. 2022-02-22 21:19:36 +01:00
retrooper 4aacdf3a37 Fixed error when closing servers without ViaVersion. 2022-02-22 20:30:47 +01:00
retrooper 6a4cbd5c97 Bug fix on closing servers without viaversion. 2022-02-22 19:54:31 +01:00
retrooper 0f907d9f99 Many bug fixes in spigot injector (1.8+)
Includes stopping server with ViaVersion, attempted to prevent the possibility of null events)
Client version abstraction cleaned up a bit hopefully and implementation.
2022-02-22 19:49:06 +01:00
retrooper 8409bd7d93 Some more features to ChannelHelper and ByteBufHelper (closing channels, copying byte array of buffer without modifying reader index) 2022-02-21 22:34:35 +01:00
retrooper 6123ae9744 Fixed redundant synchronization 2022-02-21 21:32:55 +01:00
retrooper 74751c77c6 Adding more debugs to our server connection initializer, to help catch issues where handlers don't exist for some reason? 2022-02-21 21:26:48 +01:00
retrooper bd5a681a2b Bug fixes in our injector when viaversion is present. 2022-02-21 21:19:10 +01:00
retrooper c2aa0d15cc Removed PacketSendEvent#getPromisedTasks as it was redundant.
Added User#flushPackets
2022-02-21 21:08:32 +01:00
retrooper 9bcc0bb175 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-02-21 20:52:13 +01:00
retrooper dd1c35dfb3 Fixed ProtocolManagerImpl#writePacket on Spigot. 2022-02-21 20:51:29 +01:00
MWHunter 003416e324 Revert gradle upgrade to try to fix jitpack 2022-02-20 16:35:16 -06:00
retrooper 05a44984a3 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-02-20 22:44:14 +01:00
retrooper 03a5f8ec90 Fixed ProtocolLib & Via combination causing an incompatibility. I really hate to have to do this kind of an injector for spigot, but we have to. We will also wrap the vanilla encoder like Via does, and it seems like ProtocolLib caused this mess. 2022-02-20 22:43:54 +01:00
MWHunter b632778c62 Make user versions more resilient 2022-02-20 15:38:49 -06:00
MWHunter 0eb4940cd3 Add debugs for setting client version 2022-02-20 14:34:05 -06:00
MWHunter b964913af0 Bump gradle version 2022-02-19 14:33:17 -06:00
MWHunter 31e12c31ed Add ability to write packets without flushing 2022-02-19 14:32:21 -06:00
retrooper e65c125e01 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-02-18 22:33:35 +01:00
retrooper f08bd9310d Working on PLIB compatibility 2022-02-18 22:33:17 +01:00
DefineOutside 7517493b07 Merge pull request #251 from AbhigyaKrishna/2.0
Created WrapperPlayServerWindowProperty
2022-02-18 12:15:29 -06:00
Abhigya 898f1d86a9 Fixed constructor to PacketSendEvent 2022-02-18 23:43:34 +05:30
MWHunter 873cd20dba Add useful methods to Chunk_v1_18 2022-02-18 10:48:33 -06:00
Abhigya 982a984ad4 Create WrapperPlayServerWindowProperty 2022-02-18 17:26:28 +05:30
MWHunter 8ba3ef0d7f Add method for creating empty chunks 2022-02-17 23:10:41 -06:00
MWHunter 94b8642eec Add WrapperPlayServerUseBed 2022-02-17 21:15:05 -06:00
retrooper 43ed8bcf49 WrapperHandshakingClientHandshake stackoverflow fixed 2022-02-17 22:49:10 +01:00
retrooper 95a6a8ee1f No debugs. 2022-02-17 21:39:20 +01:00
retrooper 444eff637b Nevermind, we were just discarding exceptions which isn't great. 2022-02-17 21:29:53 +01:00
retrooper d2e230c0cb Fixed many exceptions in exceptionCaught method in our netty handlers. Including ClosedChannelException 2022-02-17 21:25:03 +01:00
retrooper 195f3326fc Removed many injector/implementation classes that are no longer needed. File size hopefully gone down by a lot now. 2022-02-17 21:00:41 +01:00
retrooper fefbddcc92 Massive changes to the way netty methods are declared and implemented. 2022-02-17 20:47:37 +01:00
MWHunter bb2e9902c9 Legacy doors have no powered variable 2022-02-15 13:34:00 -06:00
MWHunter 555786d906 Add difficulty to correctly be copied for WrapperPlayServerJoinGame 2022-02-15 09:36:38 -06:00
MWHunter c5926e71ab Even more block mapping bug fixes 2022-02-14 23:15:31 -06:00
MWHunter 0e0d68e6d2 Activator rail was missing from legacy mappings 2022-02-14 23:09:36 -06:00
MWHunter cc3658591c Add warning just in case mappings are wrong 2022-02-14 23:03:47 -06:00
MWHunter 8b9030bda6 Fix some type mappings 2022-02-14 23:00:44 -06:00
MWHunter fe1a718926 Fix some type mappings 2022-02-14 22:52:25 -06:00
MWHunter 4cbc67683d Remove EntityTypes equal method 2022-02-14 22:37:40 -06:00
DefineOutside c308742582 Merge pull request #241 from RohanGoyalDev/2.0
Added MerchantRecipeData and WrapperPlayServerOpenWindowMerchant
2022-02-14 21:20:16 -06:00
RGoyalmc 029b568f5c Changed the name to avoid confusion 2022-02-15 01:14:37 +05:30
RGoyalmc 4bfe3ab62d Fixes for WrapperPlayServerOpenWindow 2022-02-15 00:58:06 +05:30
RGoyalmc 377e2a9c79 Added MerchantRecipeData and WrapperPlayServerOpenWindowMerchant 2022-02-15 00:57:53 +05:30
MWHunter f0192b3d4f pre-1.13 block mappings fixes 2022-02-14 12:19:42 -06:00
retrooper b7a15692d5 ByteBufAllocationHandler created. 2022-02-14 18:11:41 +01:00
retrooper cac05219b4 Added a ByteBufHelper which uses the bytebufhandler methods for us. 2022-02-14 17:56:33 +01:00
retrooper 5732f9e15d Added write buffer methods to ByteBufHandler 2022-02-14 17:36:11 +01:00
retrooper 8378b9265a Working on reducing memory usage with changing our netty declarations (implemented by each platform) 2022-02-14 17:22:37 +01:00
MWHunter 0ba2121283 1.13-1.16 default block states 2022-02-13 23:06:30 -06:00
retrooper ec78edcd7a Forgot to execute build commands for bungee and netty-common in gradle-publish.yml 2022-02-13 19:50:26 +01:00
retrooper de1b368ae8 Updated github gradle publish file. 2022-02-13 19:46:21 +01:00
retrooper 0bc3ab989b netty-common publishing fixed. sorry for all the past down-times. 2022-02-13 19:42:09 +01:00
retrooper b3a23fe9c0 Forgot to publish netty-common. 2022-02-13 19:34:44 +01:00
retrooper b53c9ac6fd Bug fixes in netty-common build script. 2022-02-13 16:53:07 +01:00
retrooper 5de39dd131 Update BungeePacketEventsBuilder to see if jitpack updates their caches? 2022-02-13 16:46:01 +01:00
retrooper 7a08005e53 Looking into why ProtocolLib & ViaVersion and our plugin just aren't compatible. 2022-02-13 11:29:59 +01:00
retrooper 6f3ce820d3 Forgot netty-common's build gradle 2022-02-13 10:30:56 +01:00
retrooper cc9cd837b3 netty-common module created. 2022-02-13 10:30:26 +01:00
MWHunter 170175a4cb 1.7-1.12 items final bug fixes 2022-02-12 22:13:30 -06:00
MWHunter 95cb1fcdfa 1.7-1.12 items bug fixes 2022-02-12 21:45:04 -06:00
MWHunter 81489a70a2 Convert 1.7-1.12 items to use the 1.18 names 2022-02-12 21:26:45 -06:00
MWHunter ea7f455ca7 1.13-1.18 item type bug fixes. pre-1.13 still broken 2022-02-12 18:43:25 -06:00
MWHunter 0056a2c2c7 Replace legacy item type mappings 2022-02-12 18:43:25 -06:00
retrooper 6c6bbca60f Fixed BungeePacketEventsBuilder and updated to latest packetevents-netty-impl. 2022-02-12 21:49:55 +01:00
MWHunter de7ff0439b Fix entity type mappings on legacy versions 2022-02-12 14:29:16 -06:00
retrooper 930f491b3f Made a ProtocolManager with protocol utilities, that don't require a platform-dependent object. Just ChannelAbstracts and User objects usually.
Many deprecations in PlayerManager and ServerManager

ClientVersion minor optimization.

potion_type_mappings.json are now in the potion folder, instead of item(i don't know why they were there in the first place)
2022-02-12 21:08:44 +01:00
MWHunter 8fde01c50f Fix tracking world height 2022-02-11 21:26:06 -06:00
MWHunter c144955530 Fix 1.17/1.18 extended world chunk reading 2022-02-11 21:09:11 -06:00
MWHunter 176161be01 Respawn previous gamemode can be null 2022-02-11 20:05:27 -06:00
MWHunter 0fdc0bf7ce Revert to using spigot-api 1.18 instead of 1.18.1 2022-02-11 14:36:17 -06:00
retrooper ca72e0cbfb Working on more helpful errors. 2022-02-11 20:02:08 +01:00
MWHunter e5212aa687 Check isEmpty() instead of getAmount == -1 2022-02-11 11:59:37 -06:00
MWHunter 959e494b1c Merge ItemStack.AIR into ItemStack.EMPTY to try to fix 1.8 items 2022-02-11 11:59:37 -06:00
retrooper 6cf2e0407e Attempting to fix build.gradle in api module. 2022-02-11 09:02:25 +01:00
retrooper 77d31e32ce Relocated BungeePacketEventsBuilder 2022-02-11 08:09:24 +01:00
MWHunter 0176344bf8 Fix 1.16.2-1.16.5 support 2022-02-10 20:38:59 -06:00
MWHunter f311b0e0c3 bump spigot-api version to 1.18.1 2022-02-10 20:00:22 -06:00
retrooper 9b631a3e21 Actually register the internal bungee processor. 2022-02-10 19:16:48 +01:00
retrooper c43922bdc1 Removed debugs. 2022-02-10 14:41:05 +01:00
retrooper 3fdc992846 Optimizations. 2022-02-10 13:58:33 +01:00
retrooper 30a2e935fd Managed to get compression & decompression issues out the way. Issue is when a client connects to the proxy, the packets are in the format of the client. (Unless ViaVersion is inbetween) 2022-02-10 11:44:36 +01:00
retrooper d432fa0664 More progress on bungee packetevents, can't get passed the PLAY state at the moment. 2022-02-09 23:14:44 +01:00
retrooper e11cc9d9f0 Attempting to fix gradle for jitpack. 2022-02-09 21:09:40 +01:00
retrooper ed2d16d775 Added copyright notices in some files where it was missing.
Progress on bungee.
2022-02-09 21:00:13 +01:00
retrooper 96c1321772 Small changes to bungee 2022-02-09 19:38:36 +01:00
retrooper 1d9ba33b21 Removed IDE config file 2022-02-09 18:00:34 +01:00
retrooper b6766cbaa6 Changes in build configuration files. 2022-02-09 17:58:10 +01:00
retrooper 215ef2a20d Working on BungeeCord support. 2022-02-09 17:55:37 +01:00
retrooper 7efc5b3174 Update .gitignore 2022-02-09 15:54:30 +01:00
retrooper 9f3ca243e2 Removed debugs. 2022-02-09 15:54:16 +01:00
retrooper 0b3746454e Add spigot build.gradle and .gitignore 2022-02-09 15:43:39 +01:00
retrooper c64115661c Back to a gradle multi-module project. 2022-02-09 15:41:06 +01:00
MWHunter 9c5fea1656 Fix isKnownEmpty(), rename to isEmpty() 2022-02-06 16:18:09 -06:00
MWHunter c6f7d4d4f9 Fix negative block position support 2022-02-06 15:48:42 -06:00
MWHunter 8ab1f82e29 Fix WrapperPlayServerJoinGame on 1.17 2022-02-06 14:55:47 -06:00
retrooper f947fd8fdf Merge remote-tracking branch 'origin/api' into api 2022-02-06 21:32:06 +01:00
retrooper 7f460f243c Bug fix in WrapperPlayServerScoreboardObjective 2022-02-06 21:31:50 +01:00
MWHunter 1ffbda71f7 WrapperPlayServerChunkDataBulk for 1.8, in-progress 1.7 2022-02-06 13:34:37 -06:00
retrooper 52a001d7cd Compilation error fixed and PacketListenerCommon is publicly accessible. 2022-02-06 17:20:28 +01:00
retrooper c80d2c094e Fixed WrapperPlayServerWindowItems 2022-02-06 17:15:51 +01:00
retrooper abba5d8870 Updated annotations. 2022-02-06 15:51:47 +01:00
retrooper cf69381c32 Fixed shadowJar(last time) 2022-02-06 11:20:46 +01:00
retrooper 597dd3123d Fixed shadowJar(last time) 2022-02-06 11:19:38 +01:00
retrooper 342da1e039 Added shadowJar to api module. 2022-02-06 11:13:59 +01:00
retrooper dfe0bd5825 Fixed github actions. 2022-02-06 10:38:13 +01:00
retrooper 40b9474896 Must work now. 2022-02-06 10:36:30 +01:00
retrooper 64ddc54325 Eliminated shadowJar. 2022-02-06 10:35:18 +01:00
retrooper 9d2ed8fd9a No longer minimize shadowJar? 2022-02-06 10:11:21 +01:00
retrooper b0740e7af7 Still tryna fix publishing. 2022-02-06 09:55:14 +01:00
retrooper ec5abbe2cb Trying to fix jitpack publishing. 2022-02-06 09:49:25 +01:00
retrooper 7ee7e9897e Added shadowJar plugin to api. 2022-02-06 09:26:04 +01:00
retrooper 91d35cb671 PEVersion is now stored in PacketEventsAPI 2022-02-06 09:01:29 +01:00
retrooper 0064517e99 This is the API branch, removed other modules. 2022-02-06 08:57:39 +01:00
MWHunter e05aa69674 In-progress 1.7 chunk wrapper support 2022-02-05 22:53:20 -06:00
MWHunter e9ffe18674 Port chunk wrapper to 1.8 (for 1.8 - 1.18 support) 2022-02-05 22:10:52 -06:00
MWHunter 3f0bce90ea Port chunk wrapper to 1.12 2022-02-05 21:06:44 -06:00
MWHunter d220a17679 Clean up legacy block mappings 2022-02-05 20:51:53 -06:00
MWHunter a310347420 Port WrappedBlockState to pre-flattening 2022-02-05 18:56:49 -06:00
MWHunter a7096b876f Port chunk wrapper back to 1.13 2022-02-05 17:59:39 -06:00
MWHunter 184e846592 Port chunk wrapper back to 1.14 2022-02-05 17:36:51 -06:00
MWHunter 88b02b60a4 Port chunk wrapper back to 1.15 for 1.15-1.18 support 2022-02-05 17:06:47 -06:00
retrooper 87f8af7977 Changes to PacketEventsAPI. It is now an abstract class, not every method must be implemented! Removed some unused classes. 2022-02-04 21:19:41 +01:00
retrooper 388619661b Merge remote-tracking branch 'origin/2.0' into 2.0 2022-02-04 21:12:39 +01:00
retrooper f9326359af Changes to PacketEventsAPI. It is now an abstract class, not every method must be implemented! 2022-02-04 21:12:01 +01:00
MWHunter f5693273a6 Fix enchantments being reset 2022-02-04 13:43:07 -06:00
retrooper 1b237b5615 Removed debug. 2022-02-04 19:15:54 +01:00
retrooper 8eaea5feb1 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-02-04 19:14:59 +01:00
retrooper 7aa624c8ed In our decoder, we don't process empty buffers anymore. 2022-02-04 19:14:23 +01:00
MWHunter ed866810d6 Fix explosion packet off by 1 generating ghost blocks 2022-02-04 11:39:28 -06:00
retrooper 4fde212445 WrapperPlayServerWindowItems fixed for server versions lower than 1.7.10. Attempted GeyserUtil 2.0 API support, but untested. Cleaned up build.gradle 2022-02-04 18:09:40 +01:00
retrooper a11e013668 Merge pull request #221 from retrooper/revert-220-2.0
Revert "find field in superclass"
2022-02-04 17:41:37 +01:00
retrooper 4bab379986 Revert "find field in superclass" 2022-02-04 17:41:19 +01:00
retrooper 71b3089ae6 Merge pull request #218 from AbhigyaKrishna/2.0
Fixes for legacy mappings
2022-02-04 16:39:26 +01:00
retrooper 7e81bcb5be Merge pull request #220 from huanmeng-qwq/2.0
find field in superclass
2022-02-04 16:30:39 +01:00
huanmeng_qwq 2496b7c2c5 Update ReflectionObject.java 2022-02-03 23:07:04 +08:00
huanmeng_qwq 9aeb148ea9 find field in superclass 2022-02-03 22:53:49 +08:00
Abhigya 8e7c4f2b2c Typo fixes in mapping 2022-02-02 19:18:09 +05:30
Abhigya 60201b4ac3 Spawn entity packet mapping fix 2022-02-02 18:51:35 +05:30
Abhigya 169a7fd064 Mappings for 1.8 items 2022-02-02 18:49:08 +05:30
Abhigya bfba14106e Made the enums public 2022-02-02 18:48:33 +05:30
retrooper f6b22f0ff2 Minor change to javadocs 2022-02-01 23:43:09 +01:00
retrooper 313d2f956c Last bug fix in join game wrapper. 2022-02-01 23:13:59 +01:00
retrooper a0ae5e7dcf Bug fixes for JoinGame wrapper. 2022-02-01 23:02:20 +01:00
retrooper 30c070a60c PlayerManager#clearUserData bug fixes 2022-02-01 22:47:29 +01:00
retrooper 5bf2daa734 Set default values for chunk data wrapper lighting attributes. 2022-02-01 22:33:10 +01:00
retrooper af0faf6436 WrapperPlayServerJoinGame created 2022-02-01 20:08:38 +01:00
retrooper 0333aad4fb PlayerManager#clearUserData method created 2022-01-31 17:34:29 +01:00
retrooper abee3e2cf2 Removed debugs. 2022-01-31 16:56:46 +01:00
retrooper 86fc6bb452 Fixed decoder when ViaVersion isn't present. 2022-01-31 16:44:23 +01:00
retrooper b1681772b0 WrapperPlayServerTeams constructor with sendevent exists. WrapperStatusServerResponse created. 2022-01-30 22:51:07 +01:00
retrooper 6aef8a7b14 Post-tasks in ProtocolPacketEvents now are also called when the event is cancelled! 2022-01-30 22:33:04 +01:00
retrooper 5306c090c0 PacketSendEvent#hasPromisedTasks created 2022-01-30 22:28:30 +01:00
retrooper 248799229d All in all, particle packets are working on 1.8. 1.7.10 still needs some work, and 1.8 a few tweaks.
Fixed issue where JOIN_GAME packet type just wouldn't get called in our listener.
2022-01-30 22:05:06 +01:00
retrooper d84d258d5c PacketSendEvent#getPromisedTasks added to distinct from post-tasks (in receive and send events). 2022-01-30 20:57:47 +01:00
retrooper 751c4f3ce8 Forgot to document that we added post-tasks to receive-events too. 2022-01-30 20:34:56 +01:00
retrooper b52f8d5ce9 Fixed viaversion support, because we misplaced our encoder. 2022-01-30 19:52:07 +01:00
retrooper 94823b93cd Removed debugs. 2022-01-30 19:24:07 +01:00
retrooper b2039f5741 SimplePacketListenerAbstract created. Relocation of so many event classes. Fixed late injectors on reload not updating UserProfile. 2022-01-30 18:52:35 +01:00
retrooper 0fd0c62c96 Working on bug fixes in the injector, worked on ViaVersion bug fixes, but isn't perfect(atleast not on 1.8) 2022-01-29 23:49:29 +01:00
retrooper ce66fa1aa6 Attempt on 1.7 support for particle wrapper. 2022-01-29 15:52:47 +01:00
retrooper a955b85620 Fixed comression issues. Fixed WrapperPlayClientPlayerBlockPlacement for 1.8 and 1.7.10 2022-01-29 07:51:37 +01:00
retrooper 0c3908de28 Minor optimization in ProtocolPacketEvent 2022-01-28 23:21:55 +01:00
retrooper aed27d6fc4 Fixed bug in Spigot Packet encoders! 2022-01-28 23:12:59 +01:00
retrooper f2e232d6cf Optimized build.gradle? 2022-01-28 21:06:19 +01:00
retrooper 5311189ec2 Minor changes 2022-01-28 20:49:33 +01:00
retrooper 719ad602ce All debugs eliminated 2022-01-26 20:49:36 +01:00
retrooper 66831ca814 Fixed login success being play state. Fixed post tasks. 2022-01-26 20:37:09 +01:00
retrooper 323ae164f2 LoginSuccess is allegedly in play state for some packet listeners. 2022-01-26 20:23:11 +01:00
retrooper 082924fe82 Removed debugs 2022-01-26 19:27:37 +01:00
retrooper 86b8d6d7e7 Made encoders more memory efficient and reduced memory leaks. ItemStack items aren't always enchanted now. 2022-01-26 19:26:57 +01:00
retrooper dafc082838 Working on making our decoders more memory efficient and reduce potential memory leaks. 2022-01-26 19:09:43 +01:00
retrooper f0128e0f5d ProtocolPacketEvent#getSocketAddress optimization 2022-01-25 23:24:20 +01:00
retrooper c04322c3a0 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-25 23:21:44 +01:00
retrooper b1463a6d5b Attempted optimizations, we now store clientversion and connectionstate in our user instance. Hopefully reduced map calls. 2022-01-25 23:21:27 +01:00
MWHunter 13a532eed0 Fix null pointer when setting invalid block data 2022-01-25 10:13:00 -06:00
MWHunter 625f74fbc5 Fix explosion for 1.17+ 2022-01-24 17:27:06 -06:00
retrooper d23efe4154 Attached good-looking credit to various projects
We might have not credited every single external project out there, I'll look deeply soon.
2022-01-23 23:20:13 +01:00
retrooper 0ef56aab3a Removed debugs 2022-01-23 18:08:50 +01:00
retrooper e2f1415820 ProtocolPacketEvent#getUser finally implemented properly.
GlobalChannelInjector -> SpigotChannelInjector.
 User#sendPacket added.
 We really try ensure getUser never returns null.
2022-01-23 18:07:12 +01:00
retrooper d17747490f PacketEvents.getAPI().getPlayerManager().getUser created. Renamed GameProfile to UserProfile and made a User class 2022-01-23 14:56:20 +01:00
retrooper 1866de2908 DiggingAction is no longer a subclass,
WrapperPlayServerAcknowledgePlayerDigging created
2022-01-23 10:24:10 +01:00
retrooper ffd5ce2f90 Removed debug in flying wrapper 2022-01-23 09:38:38 +01:00
retrooper 83624452a4 Fixed WrapperPlayClientPlayerFlying 2022-01-23 09:22:10 +01:00
retrooper b7b35c3ea1 Merge pull request #201 from AbhigyaKrishna/2.0
Fix for WrapperPlayServerEntityTeleport on 1.8
2022-01-22 20:10:36 +01:00
retrooper fe5c5bf6fa WrapperPlayServerParticle created, still might need some little finishing on versions before 1.13. And particle types doesnt have legacy particles 2022-01-22 20:09:47 +01:00
retrooper 705e2759dc Particle abstraction added 2022-01-22 19:04:38 +01:00
Abhigya 4a6e8cada0 Fixed packet reading for WrapperPlayServerEntityTeleport 2022-01-22 21:29:37 +05:30
Abhigya dcb30a19e4 Fix for WrapperPlayServerEntityTeleport again 2022-01-22 21:19:28 +05:30
retrooper 6e846705ec Merge pull request #199 from RohanGoyalDev/2.0
Added unregisterListeners methods
2022-01-22 15:43:19 +01:00
retrooper 9d018e0886 Added unregisterListener method for single listener, remove unregisterListeners with priority
Priorities are already attached to packetlistenerabstracts. No need to additionally attach a priority.
2022-01-22 15:43:11 +01:00
retrooper c4f6ea71b4 PacketSendEvent#getPostTasks now working 2022-01-21 22:41:43 +01:00
retrooper 4549b8305e No more relocating of libraries, as it causes issues with API users 2022-01-21 21:42:19 +01:00
retrooper ed10be50ea Fixed WrapperPlayServerSpawnPlayer and WrapperPlayServerEntityTeleport for 1.8 & 1.7.10 by AbhigyaKrishna
Fixed WrapperPlayServerSpawnPlayer and WrapperPlayServerEntityTeleport for 1.8 & 1.7.10
2022-01-21 21:39:55 +01:00
retrooper 3a6f0c4c7b Fixed WrapperPlayServerEntityTeleport for 1.8, and fixed 1.7 support broken in this PR 2022-01-21 19:58:58 +01:00
retrooper 1ea32c79e3 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-21 19:33:13 +01:00
retrooper 3612d96029 Removed debug listener 2022-01-21 19:32:14 +01:00
Abhigya cd4e5a21f6 Fix for writing entityId in WrapperPlayServerEntityTeleport for 1.8 2022-01-21 21:10:11 +05:30
RGoyalmc aaf3c915bc Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-21 20:28:22 +05:30
RGoyalmc 3bd9014b5a registerListener returns PacketListenerAbstract to allow unregistering later 2022-01-21 20:28:10 +05:30
Abhigya ab209d950b Removed relocation 2022-01-21 19:14:45 +05:30
Abhigya e92413a53d WrapperPlayServerSpawnPlayer fix for 1.8 and lower 2022-01-21 19:11:11 +05:30
RG fb74a7f99b Merge branch 'retrooper:2.0' into 2.0 2022-01-21 14:02:00 +05:30
RGoyalmc 96b9442c29 Added unregisterListeners methods 2022-01-21 14:00:52 +05:30
MWHunter 7db5ff25f0 Correct Optional_Integer entity data type 2022-01-20 16:55:19 -06:00
retrooper a20d067d62 NPC API additions, custom prefix and suffixes, colored name feature. 2022-01-20 21:15:25 +01:00
retrooper c85b5dce14 Merge pull request #198 from RohanGoyalDev/2.0
Added WrapperPlayServerScoreboardObjective and WrapperPlayServerTeams
2022-01-20 18:35:37 +01:00
retrooper 70ab66889b Removed some examples 2022-01-20 18:30:35 +01:00
RGoyalmc 3acf776efe Added WrapperPlayServerScoreboardObjective and WrapperPlayServerTeams 2022-01-20 22:53:21 +05:30
retrooper 0430a94f31 Moved AdventureSerializer to util package 2022-01-19 22:46:21 +01:00
retrooper 044c3b186d Deleted our chat component abstraction and
migrated to Kyori Adventure
2022-01-19 22:45:34 +01:00
retrooper 620a63f09c Correctly relocate adventure, might do some changes 2022-01-19 22:12:09 +01:00
retrooper b76933f26d Merge pull request #197 from AbhigyaKrishna/2.0
Adventure implementation
2022-01-19 20:52:09 +01:00
Abhigya 3d94e6fb75 Adventure implementation 2022-01-19 23:00:18 +05:30
retrooper 925f9a3c3e Vector3d, Vector3f, Vector3i#zero created 2022-01-17 22:22:40 +01:00
retrooper 1fae8ad4d6 Removed debug 2022-01-17 22:20:51 +01:00
retrooper 1860de9529 WrapperPlayServerCloseWindow default constructor created;
ServerManager#receivePacket and
ServerManager#receivePacketSilently created
2022-01-17 22:20:28 +01:00
retrooper 3dcce9ea5d Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-17 21:03:48 +01:00
retrooper 4809c8db27 Some optimizations/simplifying to the current netty abstraction implementation of packetevents 2022-01-17 21:03:21 +01:00
MWHunter c14297aa51 WrapperPlayServerCloseWindow 2022-01-17 13:30:32 -06:00
retrooper 0ccfdc6ef4 Minor change to a comment 2022-01-17 19:49:05 +01:00
retrooper 45ad93778d Fixed compatibility with ProtocolSupport 2022-01-17 19:48:01 +01:00
retrooper f1d683abb0 Compilation error fixed!! 2022-01-16 22:04:10 +01:00
retrooper 8fad01156b We now collect our packetevents version with bStats;
SpigotDataHelper.fromBukkitItemStack bug fix
2022-01-16 21:59:26 +01:00
retrooper b1c7f2a3c5 Update bStats notice 2022-01-16 21:11:44 +01:00
retrooper f2c0468487 Vector3d#ZERO created;
Vector3f#ZERO created;
Vector3i#ZERO created
2022-01-15 18:10:13 +01:00
retrooper 89110b21f1 Minor changes 2022-01-13 22:19:22 +01:00
retrooper 79f176221a Equipment and EquipmentSlot now have their own class;
ItemStack#AIR added;
NPC#getMainHand, getOffHand, getHelmet, getChestPlate, getLeggings, getBoots added;
NPCManager#updateEquipment;

PlayerManager#sendPacket works again
2022-01-13 22:03:26 +01:00
retrooper 56ebeffda1 WrapperPlayServerCollectItem created;
ItemStack#Builder default amount is 1;
Vector3d#toVector3i created;
Vector3i#toVector3d created;
2022-01-09 21:54:33 +01:00
retrooper 0fe5d63220 Add WrapperPlayServerEntityEquipment 2022-01-09 19:34:01 +01:00
retrooper 43d18cd6f2 Added WrapperPlayServerEntityEquipment 2022-01-09 19:00:47 +01:00
retrooper ffcb91ef05 Removed preProcessed feature in listeners 2022-01-08 17:36:41 +01:00
retrooper d42de7d96a Removed redundant duplication when sending packet bytebufs 2022-01-07 18:34:37 +01:00
retrooper 04cf207105 Change to debug listener 2022-01-07 17:30:28 +01:00
retrooper b404274e26 Removed debugs 2022-01-07 17:02:34 +01:00
retrooper 011d52a246 Last attempt to support pre processed listener and "cloned" event instances 2022-01-07 16:57:33 +01:00
retrooper 2e01f71e95 Redundant code removed from PacketWrapper 2022-01-07 16:26:10 +01:00
retrooper 17aa045349 Added small debug 2022-01-07 16:14:59 +01:00
retrooper 264e6e5e81 Pre processed events are working 2022-01-07 16:01:44 +01:00
retrooper b5a15cbbbb 2nd Attempt to fix pre processed events 2022-01-07 15:51:57 +01:00
retrooper a8ee5ee79a Attempt to fix pre processed events 2022-01-07 15:34:47 +01:00
retrooper d7be938767 You should now be able to read the same event multiple times with many wrappers. 2022-01-07 15:18:58 +01:00
retrooper 00ecb18efb Compilation error fixed 2022-01-07 14:59:04 +01:00
retrooper 0880664a58 PacketListener and PacketListenerReflect can now be preProcessed. This means the buffer is cached and you can safely read the data in the packet on a separate thread or later. 2022-01-07 14:53:01 +01:00
retrooper a5641ee557 PacketListenerAbstract#isPreProcessed added;
WrapperPlayClientBlockPlacement renamed to WrapperPlayClientPlayerBlockPlacement
2022-01-07 14:36:31 +01:00
retrooper ac4d9601d9 Packet wrapper objects can be sent multiple times now 2022-01-07 12:07:09 +01:00
retrooper 597cd2462c PlayerManager#sendPacketSilently defined;
PlayerManagerImpl#sendPacketSilently implements it
2022-01-07 12:03:04 +01:00
retrooper a4aabcfbcc WrapperPlayServerFacePlayer created 2022-01-06 22:22:48 +01:00
retrooper 58839ae503 WrapperPlayServerPlayerPositionAndLook.java additions;
WrapperPlayClientPlayerFlying#hasPositionChanged and hasRotationChanged now accessible
2022-01-06 21:27:37 +01:00
retrooper 85a0edc131 Set default values for player data providers 2022-01-06 19:09:45 +01:00
retrooper 8aedcff494 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-06 18:59:54 +01:00
retrooper 78581d99ae Set default values for entity data providers 2022-01-06 18:58:11 +01:00
MWHunter 8cf6e07a6b WrapperPlayServerOpenHorseWindow 2022-01-06 10:46:47 -06:00
retrooper 7f44343ec7 Attempt to fix WrapperPlayServerPlayerPositionAndLook and RelativeFlags;
SkinSection improvements;

WrapperPlayClientSettings#isSkinSectionVisible, setSkinSectionVisible added
2022-01-06 15:50:47 +01:00
retrooper bb78cfcaf6 Attempt to transform destroy entities packet into multiple when needed;
SpigotDataHelper created, which helps for converting Bukkit data types into packetevents data types
2022-01-06 12:35:01 +01:00
retrooper 3464fa8ea7 Many comments removed, we instead made GitHub issues 2022-01-06 12:07:24 +01:00
retrooper 23c427944f Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-06 11:49:25 +01:00
retrooper b0943da09f Attempted to complete the entity data provider builders, not entirely perfectbut should work. 2022-01-06 11:49:11 +01:00
retrooper dd20f0c7c7 Credit bStats metrics class owner 2022-01-06 00:24:10 +01:00
retrooper 4093a23fb3 SkinSections refactored;
WrapperPlayClientPlayerFlying can now parse its sub packets;

Working on builders for entity data providers.(player one is left)
2022-01-05 23:27:10 +01:00
retrooper c5c9d6e1fd Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-05 13:30:05 +01:00
retrooper 3c88c64cac LivingEntityDataProvider created;
PlayerDataProvider also created, now time to test
2022-01-05 13:29:26 +01:00
MWHunter 55dacc62dc Fix MCProtocolLib bug 2022-01-04 21:16:31 -06:00
MWHunter 0056adae8e Fix equals and hashcode comparison for WrappedBlockState 2022-01-04 19:19:41 -06:00
MWHunter 7c9dd702c4 Fix yet another WrappedBlockState corruption method 2022-01-04 18:58:32 -06:00
MWHunter 8e73755566 Fix another WrappedBlockState corruption method 2022-01-04 18:40:47 -06:00
MWHunter 21da5c8be8 Don't let WrappedBlockState become corrupted 2022-01-04 17:50:19 -06:00
DefineOutside 8900e613b2 Fix compilation 2022-01-04 17:34:53 -06:00
retrooper 6e37546336 EntityDataProvider done;
Working on LivingEntityDataProvider
2022-01-04 22:56:12 +01:00
retrooper 4b4aec1e32 Attempting to fix a connection handler issue 2022-01-04 19:30:57 +01:00
retrooper b356696d1e Removed debugs and debug listener 2022-01-04 18:19:25 +01:00
retrooper 3dd75fc51e Attempted to fix PacketEncoderLegacy for 1.7 servers 2022-01-04 18:18:25 +01:00
retrooper d6a0823d57 Some bug fixes, skins now work again! 2022-01-04 17:47:46 +01:00
retrooper eb7e8752ed Fixed encoder issues with sending packets 2022-01-04 17:09:54 +01:00
retrooper 201666365f Fixed encoder issues when cancelling packets;
Improved ViaVersion support(optimizations)
2022-01-04 17:00:25 +01:00
retrooper 04ba2c29dd Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-04 16:39:11 +01:00
retrooper 8b2750389d Before we try change our encoder system. 2022-01-04 16:38:54 +01:00
MWHunter 586657d973 Fix 1.17+ support for EntityPose 2022-01-03 19:09:08 -06:00
retrooper 7e0f491a73 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-03 22:08:29 +01:00
retrooper 8e62e6a6a3 CustomPipelineUtil should now work on 1.7.10 2022-01-03 22:08:06 +01:00
MWHunter 45ab932d3c Fix WrapperPlayClientBlockPlacement and add WrapperPlayClientUseItem 2022-01-03 15:00:55 -06:00
retrooper eb295e16e9 PlayerManagerImpl#sendPacket now calls our send event when Via isn't present 2022-01-03 21:07:14 +01:00
retrooper deec409f02 Fixed compilation error. 2022-01-03 11:33:37 +01:00
retrooper 246c5c4c55 Trying to add plugin.yml 2022-01-03 11:25:58 +01:00
retrooper 352750a247 Relocation of ResourceLocation 2022-01-03 08:44:27 +01:00
retrooper 4abb66f06a Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-03 08:37:09 +01:00
retrooper 7840391061 Finally we handle Villager data in the entity metadata packet! 2022-01-03 08:36:59 +01:00
MWHunter 5cf2d24098 Fix isReplaceable() 2022-01-02 21:51:12 -06:00
MWHunter 14781b3f7b Fix isSolid() for StateTypes 2022-01-02 17:24:53 -06:00
MWHunter 04beb32199 Fix WrappedBlockState 2022-01-02 15:29:02 -06:00
MWHunter 57c3f00f1d Fix BlockTags + ItemTags and rearrange their code 2022-01-02 14:57:02 -06:00
MWHunter f021974c73 Fix WrapperPlayServerUpdateHealth 2022-01-02 11:05:45 -06:00
MWHunter b97ab7c054 Fix entity metadata writing 2022-01-02 10:45:40 -06:00
MWHunter a930af9656 Fix entity type mappings for 1.16+ 2022-01-01 18:21:15 -06:00
MWHunter b74d0bce71 Try fixing EntityMetadata packet 2022-01-01 17:47:22 -06:00
retrooper 0a5f73d2a6 Finally got NPCManager#changeNPCSkin kind of working;
Removed debug listener
2022-01-02 00:00:13 +01:00
retrooper 94d02606f6 Bug fixes to MojangAPIUtil 2022-01-01 22:33:12 +01:00
retrooper 274618b899 MojangAPIUtil and UUIDUtil created 2022-01-01 22:22:27 +01:00
retrooper e77d23e908 Removed some things to prevent compilation 2022-01-01 21:59:17 +01:00
retrooper db878badae Fixed PacketWrapper#readEntityMetadata and writeEntityMetadata for 1.10+ 2022-01-01 21:58:30 +01:00
retrooper c723bee425 Merge remote-tracking branch 'origin/2.0' into 2.0 2022-01-01 21:50:02 +01:00
retrooper 6cf055501b Fixed WrapperPlayServerEntityProperties on 1.16+;
WrapperPlayServerSpawnPlayer minor addition;

NPCManager#updateNPCSkin and NPCManager#updateNPCDisplayPing added
2022-01-01 21:49:37 +01:00
MWHunter 7152615e3c Allow getting all valid item types and state types 2022-01-01 13:05:16 -06:00
retrooper b7bbdfa3e3 SpigotPacketEventsBuilder#clearBuildCache added 2022-01-01 18:50:44 +01:00
retrooper 1262855d05 SpigotReflectionUtil#getEntityById created 2021-12-31 21:37:14 +01:00
retrooper 1cea4d9766 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-31 20:41:37 +01:00
retrooper 627c23ec15 Removed tab completion thing 2021-12-31 20:41:24 +01:00
MWHunter d6d447c6bf Restore getEnchantmentLevel 2021-12-31 13:36:15 -06:00
MWHunter 1852c48e93 ItemStack clean up duplicate code 2021-12-31 13:28:22 -06:00
MWHunter 78f8a6b7db Fix compilation on java 8 2021-12-31 12:48:07 -06:00
MWHunter 63f7d1aac5 ItemTypes <---> StateTypes when placeable 2021-12-31 12:31:01 -06:00
MWHunter c5a1bfdd62 Remove commented out code from ItemTypes 2021-12-31 11:59:18 -06:00
MWHunter 13627a83cf Rewrite ItemTypes to use a design pattern instead of 5 constructors 2021-12-31 11:57:08 -06:00
MWHunter 88023852b3 Add default block states for 1.17/1.18 2021-12-30 16:08:47 -06:00
retrooper 5adb6378e2 Change in one wrapper 2021-12-30 20:35:57 +01:00
retrooper 619cc77823 Minor fixes 2021-12-30 20:25:19 +01:00
retrooper fab8cdde35 Implemented a utility method NettyManager#asByteArray 2021-12-30 20:21:34 +01:00
retrooper 730eda864f Trying to fix game-profile failing to cache. 2021-12-30 20:14:02 +01:00
retrooper 1309c77f3c Minor changes 2021-12-30 13:17:21 +01:00
retrooper 35e503a2ae We can now build all the components officially with the API. 2021-12-30 12:41:59 +01:00
retrooper a82951f85e Removed debug and debug listener 2021-12-30 12:26:43 +01:00
retrooper 5ef782a04b Minor bug fix in translatable component, need to look into hover event 2021-12-30 12:11:00 +01:00
retrooper 78d1bf814f Lots of bug fixes in the chat component API 2021-12-30 12:03:09 +01:00
retrooper 4dcc33f7b7 Removed debug listener 2021-12-29 23:39:22 +01:00
retrooper 79514e0a51 Lots of code repetition fixed, working on fixing translatable components 2021-12-29 23:38:31 +01:00
retrooper f2c78c794a More progress on component serializer 2021-12-29 23:09:05 +01:00
retrooper 435e27d02c Addition to NBT components 2021-12-29 22:56:43 +01:00
retrooper b4640aecb0 Addition to NBT components 2021-12-29 22:47:21 +01:00
retrooper 6915c97a51 More progress on chat component api, working on nbt components 2021-12-29 22:45:26 +01:00
retrooper 7e6996813a Attempted getEnchantments in ItemStack;
Relocated EnchantmentType/s;

MappedEntity#getIdentifier -> MappedEntity#getName(For ItemType, PotionType, EnchantmentType)
2021-12-27 22:42:56 +01:00
MWHunter fd787fd3fb Migrate to ViaVersion block mappings 2021-12-26 19:59:18 -06:00
MWHunter 17aadda1c5 Initial ItemTags implementation 2021-12-26 16:49:18 -06:00
MWHunter 68335024ea Utility methods to WrapperPlayServerBlockAction.java 2021-12-25 17:12:48 -06:00
MWHunter c5cf140961 Add sword, shovel, axe, pickaxe, and hoe to ItemAttributes 2021-12-25 17:04:53 -06:00
retrooper 6764c39bfb Despawn NPC correctly 2021-12-25 18:51:05 +01:00
retrooper 59c6f58e77 Bukkit module -> Spigot module;
Read only listener bug fixes
2021-12-25 17:51:26 +01:00
retrooper 6a6a9f5a9e BukkitPacketEventsBuilder -> SpigotPacketEventsBuilder 2021-12-25 17:25:49 +01:00
retrooper 697f65c07e Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-25 17:23:13 +01:00
retrooper f59a2e5144 Packet listeners can now be readable only(which means the wrappers won't modify the packet being listened to, this can help optimize your usage of wrappers. 2021-12-25 17:23:02 +01:00
MWHunter f161ba5718 Utility methods to BlockFace 2021-12-24 21:21:21 -06:00
retrooper 467d5e596d Minor bug fix with getNPCManager() method 2021-12-24 22:43:00 +01:00
retrooper b66cf34975 Attempted to fix NPC head rotation 2021-12-24 22:33:09 +01:00
retrooper 528a7ec7e5 Renamed MinecraftReflectionUtil in bukkit module to SpigotReflectionUtil (considering renaming module to "spigot") 2021-12-24 22:20:16 +01:00
retrooper 3cee15aef0 Minor changes 2021-12-24 21:58:47 +01:00
MWHunter 677e2739a6 Finish missed boolean getX() and fix a statetype 2021-12-24 14:30:06 -06:00
MWHunter 79bf0f674c boolean getX() -> boolean isX() 2021-12-24 14:25:40 -06:00
MWHunter 8376abcfaa Add Attachment to wrapped block state 2021-12-24 14:18:37 -06:00
MWHunter 14201f8747 Add WrapperPlayServerDeclareRecipes 2021-12-24 14:08:49 -06:00
MWHunter c34d26670f Replace Facing enum with BlockFace enum 2021-12-23 21:53:56 -06:00
MWHunter 3c669c6e93 Add East state to WrappedBlockState 2021-12-23 21:49:41 -06:00
MWHunter e7896f9ec2 Make StateType in WrappedBlockState accessible
A bit of an oversight
2021-12-23 21:22:04 -06:00
MWHunter 1a17587d3a Working MultiBlockChange wrapper for 1.17+ 2021-12-23 20:39:46 -06:00
retrooper c23e066d63 WrapperPlayServerEntityRelativeMove had wrong packet type 2021-12-23 22:44:35 +01:00
retrooper aee4bfd240 Merge pull request #178 from Izibane/patch-1
すごい
2021-12-23 22:18:40 +01:00
retrooper 2ca0a14dfd despawn NPC bug fix 2021-12-23 22:17:09 +01:00
retrooper c9afbbc573 Location#clone added 2021-12-23 22:14:51 +01:00
retrooper 6967092a39 Minor bug fixes in NPCManager, now IT SHOULD BE WORKING 2021-12-23 22:03:09 +01:00
Izibane 2fc17edfd1 すごい
Super Idol的笑容 都没你的甜 八月正午的阳光 都没你耀眼 热爱 105 °C的你 滴滴清纯的蒸馏水
2021-12-23 21:00:45 +00:00
retrooper e5f04b9dd8 Another bug fix in NPCManager#updateNPCLocation 2021-12-23 21:59:35 +01:00
retrooper 72cea36b4c Another bug fix in NPCManager#updateNPCLocation 2021-12-23 21:58:29 +01:00
retrooper cb3dc07da4 Bug fix with NPCManager#updateNPCRotation 2021-12-23 21:46:00 +01:00
retrooper 7a6adba398 Optimization to NPCManager#updateNPCRotation 2021-12-23 21:28:01 +01:00
retrooper 52ac010d6f Redundant import removed 2021-12-23 20:23:29 +01:00
retrooper 285085ab14 Renaming in entity relative move PacketType EntityLook -> EntityRotation (like on wiki.vg) and in Wrapper names;
WrapperPlayServerSpawnPlayer final touches;
Location created and applied in a few wrappers.
2021-12-23 20:18:32 +01:00
MWHunter ed088c2d8e Working chunk data wrapper for 1.17 2021-12-22 21:39:53 -06:00
MWHunter 4e33c323df Working chunk data wrapper for 1.18! 2021-12-22 19:45:32 -06:00
MWHunter e4f1492744 Clean up multi-version chunk wrappers 2021-12-22 17:44:07 -06:00
MWHunter 922d234c45 Convert (untested) chunks to using the WrappedBlockState 2021-12-21 17:50:03 -06:00
MWHunter 05edb94249 Add extra utilities for block tags 2021-12-21 16:32:41 -06:00
retrooper f6de2e066e Some renaming of wrappers. 2021-12-21 21:06:40 +01:00
MWHunter 8204c5d631 Add shapeExceedsCube to StateType 2021-12-20 19:45:54 -06:00
MWHunter 4d9ce8419d Fix Java 8 support 2021-12-20 18:12:07 -06:00
MWHunter f47ddb5330 Expose item type attributes 2021-12-20 17:57:27 -06:00
MWHunter 1fab6e5396 Add Fuel to ItemType attributes 2021-12-20 17:51:03 -06:00
MWHunter f77b370ee9 More ItemStack utilities 2021-12-20 17:20:57 -06:00
MWHunter 30e46ef672 Add some utility methods to ItemStack 2021-12-20 16:02:10 -06:00
retrooper bdeab22d57 Compilation error fixed in EntityDataTypes 2021-12-19 21:41:05 +01:00
retrooper 982ad348a4 Hopefully fixed WrapperPlayServerEntityMetadata,
And created EntityData and EntityDataType/s,
all metadata stuff should be working, just need to test;

Refactored some item categorized mappings;
WrapperPlayServerBlockChange bug fix;
2021-12-19 21:26:40 +01:00
retrooper 296d3a8330 Fixed some more bugs in WatchableObject 2021-12-19 11:08:29 +01:00
retrooper 1ad13506f8 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-19 10:44:20 +01:00
retrooper 8887fdf227 Fixed some bugs in WatchableObject 2021-12-19 10:43:54 +01:00
DefineOutside 8ac94578cb Add BlockTags class 2021-12-18 14:22:46 -06:00
DefineOutside adcf8f9b0d Add speed to state types 2021-12-18 13:54:28 -06:00
DefineOutside 6b7f08d27b Initial working WrappedBlockState for 1.18 with WrappedPlayServerBlockChange 2021-12-18 12:09:11 -06:00
DefineOutside 14fa2a7e5f Fix some wrapped block state enums 2021-12-18 11:49:13 -06:00
DefineOutside f9d1f8ad39 Add globalID to wrapped block state to allow reversion with bad modifications 2021-12-18 10:56:07 -06:00
DefineOutside 86fb8f57da Efficiency improvements for packet block states 2021-12-17 20:41:09 -06:00
DefineOutside 84d87ba5bc Prototype for packet based representations of 1.7 through 1.18 blocks 2021-12-17 19:06:30 -06:00
DefineOutside 922b1e783b Prototype for turning strings into enums and stuff 2021-12-17 18:28:29 -06:00
DefineOutside a1e68ea71f Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-17 15:29:27 -06:00
DefineOutside af025bb76b Prototype for universal state types 2021-12-17 15:29:17 -06:00
retrooper 16f2d66b82 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-17 21:37:08 +01:00
retrooper b5205e10aa Client-bound keep alive packet created 2021-12-17 21:36:44 +01:00
DefineOutside c53ca172ef Add push reaction to state types 2021-12-17 13:27:07 -06:00
DefineOutside 4cdf42a6d8 don't commit debug 2021-12-17 13:01:28 -06:00
DefineOutside bdae6431b7 Add WrapperPlayServerTags 2021-12-17 13:00:54 -06:00
retrooper a8e1e7c09f Minor change/fix component 2021-12-17 19:29:20 +01:00
retrooper 1e4bbaa979 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-17 18:53:33 +01:00
retrooper b00f28399b WrapperPlayServerPlayerInfo bug fixes attempt.
PacketWrapper#readComponent created
2021-12-17 18:53:17 +01:00
retrooper 232c668a45 Merge pull request #176 from AlessioGr/2.0
PLS NO SYSTEM.OUT.PRINTLN
2021-12-17 18:09:20 +01:00
Alessio Gravili 242435a0af Merge pull request #2 from AlessioGr/retrooper-2.0
Retrooper 2.0
2021-12-17 17:42:07 +01:00
AlessioGr 5e093dbac8 Merge branch '2.0' of https://github.com/retrooper/packetevents into retrooper-2.0
Signed-off-by: AlessioGr <alessio@gravili.de>

# Conflicts:
#	bukkit/src/main/java/io/github/retrooper/packetevents/handlers/modern/PacketDecoderModern.java
2021-12-17 17:41:24 +01:00
retrooper e84c299d77 Removed a few debugs;
WrapperPlayServerDifficulty added
2021-12-17 17:26:42 +01:00
AlessioGr 680511621c PLS NO SYSTEM.OUT.PRINTLN
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-17 17:25:40 +01:00
AlessioGr a4a44f735f PLS NO SYSTEM.OUT.PRINTLN
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-17 17:24:24 +01:00
DefineOutside bbfc4f2e20 In-progress block state types 2021-12-16 22:55:22 -06:00
DefineOutside 6498ef9d25 Add durability and tool tiers to ItemType 2021-12-16 15:58:12 -06:00
DefineOutside c833196faa Fix compilation 2021-12-16 14:55:34 -06:00
DefineOutside 0f84b1fd9f Add CraftRemainder to item type 2021-12-16 14:38:51 -06:00
DefineOutside ad39ca31b2 Add ItemAttribute.FIRE_RESISTANT 2021-12-16 14:21:50 -06:00
retrooper 9bccd08531 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-16 21:20:08 +01:00
retrooper db1ca78fbb Strip away colors from log manager if we are not on Bukkit. Colors must be handled by the implementation and cannot be cross-platform. Everything remains white on other platforms or unknown implementations, unless they implement it correctly. 2021-12-16 21:19:55 +01:00
DefineOutside 70e2484d99 Corrections to max stack size 2021-12-16 14:18:11 -06:00
DefineOutside 4f81138bde Add edible to item types 2021-12-16 14:12:20 -06:00
retrooper a16cc34f8d Attempted some bug fixes in decoder for legacy versions such as 1.8 2021-12-16 20:58:38 +01:00
retrooper 69cffe5b3d Updated position and look constructor 2021-12-16 17:50:25 +01:00
retrooper 4c53c6fe56 We now use GameProfile in LoginSuccess packet. 2021-12-16 16:35:03 +01:00
retrooper 87748980ea Minor fix in HumanoidArm 2021-12-16 16:14:07 +01:00
retrooper 9bc6a15581 Minor documentation fix 2021-12-16 16:11:37 +01:00
retrooper 3e4eb458d3 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-16 16:07:31 +01:00
retrooper 8d643fddcf EntityType should work for all supported server versions now.
ItemTypes#getById can never be null, it returns AIR if not found in the map.
2021-12-16 16:07:18 +01:00
DefineOutside 67da1c6184 Air stacks to 64 not 1 2021-12-15 23:18:05 -06:00
DefineOutside 1957fc0b77 Add CARTESIAN_VALUES to BlockFace 2021-12-15 19:27:06 -06:00
DefineOutside baebf06dc0 Add utility methods to BlockFace 2021-12-15 19:19:42 -06:00
DefineOutside 078aa4ab88 Add WrapperPlayClientSteerVehicle 2021-12-15 17:30:32 -06:00
DefineOutside 97d82994cc Fix compilation error due to PacketEventsPlugin.java 2021-12-15 16:59:45 -06:00
DefineOutside 0f2d7c05a9 Separate main hand vs interaction hand 2021-12-15 16:54:38 -06:00
DefineOutside 2ad01ba158 Make clientbound/serverbound window confirmations consistent 2021-12-15 16:43:55 -06:00
DefineOutside 4c454f3793 Add constructors to WrapperPlayServerOpenWindow 2021-12-15 16:40:38 -06:00
retrooper 987fb97fad Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-15 23:08:21 +01:00
retrooper 104bdf0e37 Added entity type mappings for 1.14 till 1.18 2021-12-15 23:08:11 +01:00
DefineOutside 9846133f97 Initial WrapperPlayServerOpenWindow 2021-12-15 14:44:30 -06:00
retrooper fa087ca733 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-15 16:40:30 +01:00
retrooper 9cb661df86 Improvements to ClientVersion and ServerVersion, we added the getReleaseName to both;
InternalPacketListener should be cross-platform, and is no longer in the bukkit module, implementations must register it;
We now cache the game profiles with channels instead of player usernames.
2021-12-15 16:40:05 +01:00
DefineOutside 6a20277b7e Add the parent type to EntityType 2021-12-14 22:19:45 -06:00
DefineOutside 46e54fb8db Force GeyserUtil safety 2021-12-14 20:28:47 -06:00
DefineOutside b0fc8aa0a3 WrapperPlayServerWindowItems 2021-12-14 19:59:12 -06:00
retrooper 6caa434cd0 Merge pull request #175 from AlessioGr/fixlogs
Fix missing color in Bukkit log manager implementation
2021-12-14 21:12:16 +01:00
AlessioGr c85cffbed1 Fix missing color in bukkit log manager implementation
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-14 15:39:34 +01:00
retrooper 2377ca8e02 Minor improvements to cross-platform log manager. 2021-12-13 07:21:12 +01:00
retrooper 5a90d2fd19 Some changes to GameProfile and some cleanups. 2021-12-12 22:27:23 +01:00
retrooper 9ca4606cf5 Progress on EntityTypes;
Some refactoring of some protocol data types;
2021-12-12 22:06:47 +01:00
retrooper 4b648ac0d0 Improvements to WrapperPlayServerEntityEffect 2021-12-12 21:11:07 +01:00
retrooper d3ae9e5c35 Cleanup to logger manager. 2021-12-12 20:55:28 +01:00
retrooper 584452adc9 Merge pull request #173 from AlessioGr/2.0
Add LogManager
2021-12-12 18:10:40 +01:00
retrooper 8303a6f8a5 Some corrections to WrapperLoginClientEncryptionResponse and minor changes to MinecraftEncryptionUtil 2021-12-12 15:34:18 +01:00
retrooper a107493942 Minor fixes to MinecraftEncryptionUtil 2021-12-12 15:20:35 +01:00
retrooper 0c79206e62 Merge pull request #174 from TRGReal/patch-1
Add vanilla MinecraftEncryptionUtil.
2021-12-12 14:40:14 +01:00
TRGReal 6fbd8843e8 Add vanilla MinecraftEncryptionUtil.
Allows you to easily encrypt/decrypt using Minecraft-like RSA/AES in PE util.
2021-12-12 21:39:22 +08:00
retrooper f6ac6d8c60 Removed decrypt and encrypt methods 2021-12-12 14:37:50 +01:00
retrooper 03768c587c Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-12 13:56:04 +01:00
retrooper 04be4cad57 Minor corrections to WrapperLoginClientEncryptionResponse 2021-12-12 13:55:51 +01:00
AlessioGr 5ad0284c92 Finalize logmanager
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-11 23:19:28 +01:00
AlessioGr 8471ae512b Disable plugin.yml.dis
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-11 23:18:56 +01:00
AlessioGr 388fd05e90 Improvements
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-11 23:13:34 +01:00
AlessioGr 7aac404238 Add LogManager
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-11 22:58:02 +01:00
retrooper faf6bff61b Merge pull request #172 from AlessioGr/2.0
Update gradle shadow & add github actions to 2.0
2021-12-11 22:38:19 +01:00
retrooper b644f8d4aa Comments added 2021-12-11 21:57:40 +01:00
retrooper d091f169ad Minor correction in comment 2021-12-11 21:26:42 +01:00
retrooper a1e9aef5dc Attempted to add Geyser/Floodgate support 2021-12-11 21:02:29 +01:00
retrooper 94bd45a1f9 Fixed WrapperPlayClientUpdateSign,
Added 1.18.1 support,
Fixed mappings when being parsed.
2021-12-10 22:47:21 +01:00
retrooper aa00273a97 Updated to support 1.18.1 2021-12-10 20:58:06 +01:00
retrooper 077db29072 Item mappings should work for 1.17 and below 2021-12-10 16:06:48 +01:00
retrooper 266702d3ff We have switched to ViaVersion's mappings, these are much easier to use, especially in our case, still need to complete the mappings for server versions older than 1.18. 2021-12-09 22:58:46 +01:00
retrooper bdfcfed7fe Pre mappings fix/switch 2021-12-09 21:41:13 +01:00
retrooper 0513511b4b Updated build.gradle to use Spigot 1.18 API 2021-12-09 20:13:34 +01:00
retrooper 6dba94e69d Lots of cleanup in PlayerManager and ServerManager. You don't need to implement as many methods anymore. 2021-12-08 22:55:30 +01:00
retrooper c088dfbf64 Minor changes to GameMode 2021-12-08 17:20:39 +01:00
retrooper 8a95ba99ac Removed PlayerManager#sendMessage 2021-12-08 14:41:20 +01:00
retrooper 9abaa18ba0 Add GameMode;
Add PlayerManager#sendMessage (will be removed next commit)
2021-12-08 14:39:47 +01:00
retrooper 16d57cead7 Minor changes 2021-12-05 11:21:52 +01:00
retrooper bccad0fe6e Minor bug fixes in chunk data(progress) 2021-12-05 11:03:08 +01:00
retrooper 31bbd66497 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-05 10:50:02 +01:00
retrooper 2d38f37be7 Working on decoding/encoding watchable objects. 2021-12-05 10:49:51 +01:00
DefineOutside ebb48c5a6d In-progress chunk wrappers 2021-12-04 16:56:55 -06:00
DefineOutside 5de377d535 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-04 16:09:03 -06:00
DefineOutside 719dedeebf In-progress chunk wrappers 2021-12-04 16:08:54 -06:00
retrooper 9567ab2aab ItemTypes mapping correction attempt,
WrapperPlayServerEntityEffect new constructor added
2021-12-04 20:06:30 +01:00
retrooper b9077e5112 Many corrections to wrappers. 2021-12-04 19:48:15 +01:00
retrooper b9fac2d6c9 Some bug fixes on more wrappers. 2021-12-04 19:25:55 +01:00
retrooper 5fa664b59f Fixed WrapperPlayServerAttachEntity and WrapperPlayServerSetCooldown 2021-12-04 19:21:31 +01:00
retrooper 307cc62a6a Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-04 19:19:41 +01:00
retrooper ab3bfa3018 Trying to fix ItemTypes mappings, what went wrong? 2021-12-04 19:19:15 +01:00
DefineOutside 480cee7fec Player teleport wrapper 2021-12-04 11:40:44 -06:00
DefineOutside 924b0c2b24 WrapperPlayServerSetCooldown 2021-12-04 11:09:43 -06:00
DefineOutside 5db3c59ff0 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-04 10:58:33 -06:00
DefineOutside ff8b593438 Attach entity wrapper 2021-12-04 10:58:28 -06:00
retrooper 0f9197a1f0 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-12-04 17:44:50 +01:00
retrooper ac6bda02de Updated item type mappings to 1.18 2021-12-04 17:43:39 +01:00
DefineOutside eef49aa7c3 Entity effect, remove entity effect, set passengers wrappers 2021-12-04 10:23:04 -06:00
retrooper 2b84919759 Temporarily disabled debugs. 2021-12-03 22:38:00 +01:00
retrooper 7b56fbd453 Created WrapperPlayServerUpdateSimulationDistance 2021-12-03 22:16:26 +01:00
retrooper b62ac638f8 Updated debugs. 2021-12-03 22:13:52 +01:00
retrooper 074004d57f Re-added debugs in a rather smarter way. 2021-12-03 22:01:27 +01:00
retrooper d36a93b050 Added support for 1.18 regarding packet types.
Working on fixing injector issues.
2021-12-03 21:41:53 +01:00
retrooper 4abffd87f8 Some optimizations by removing redundant packet processing in my internal listener 2021-12-02 18:26:02 +01:00
Alessio Gravili a6b83d7e58 Merge branch 'retrooper:2.0' into 2.0 2021-12-02 18:20:22 +01:00
retrooper 679dda68ea Last debug removed! 2021-12-02 18:09:28 +01:00
retrooper 4952487937 Removed chat message debugs. 2021-12-02 17:33:33 +01:00
Alessio Gravili d7a52e797e Merge branch 'retrooper:2.0' into 2.0 2021-12-02 17:21:41 +01:00
retrooper 23e5282b0f Minor fix 2021-12-02 17:19:36 +01:00
Alessio Gravili 978f0382b9 Merge branch 'retrooper:2.0' into 2.0 2021-12-02 17:19:32 +01:00
retrooper b598384f22 Fixed WrapperPlayServerPluginMessage and WrapperPlayClientPluginMessage;
Removed one more debug
2021-12-02 17:17:00 +01:00
AlessioGr fb9d69e191 JDK 8
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-02 17:03:39 +01:00
AlessioGr 2125d3cd49 Update gradle wrapper from 7.3 to 7.3.1
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-02 11:49:14 +01:00
Alessio Gravili 348e400be3 Create gradle-publish.yml 2021-12-02 10:28:17 +01:00
AlessioGr a236e24b25 Update shadow version
Signed-off-by: AlessioGr <alessio@gravili.de>
2021-12-02 10:15:49 +01:00
retrooper 4eae63c898 Removed debugs 2021-12-01 23:07:52 +01:00
retrooper 9cd931225d Small comments added 2021-12-01 23:05:44 +01:00
retrooper 65232f6c47 Chat components reworked and mostly working, just need to work on Hover event show item and show entity, cause their values are strings and NOT json objects. 2021-12-01 23:04:59 +01:00
retrooper c82895612b Working on ScoreComponent 2021-12-01 19:27:08 +01:00
retrooper e50feeb9cd Some more adjustments to gradle. 2021-12-01 18:12:59 +01:00
retrooper d10f91538f Added some info to maven publishing. 2021-12-01 18:11:54 +01:00
retrooper 2327997910 Updated to latest gradle version, to add support for later java versions. 2021-12-01 18:02:28 +01:00
retrooper 469e610c15 Some bug fixes in client settings. 2021-12-01 17:21:38 +01:00
retrooper 7ab59f3cbe Officially supporting 1.18. 2021-11-30 18:09:45 +01:00
retrooper 8eb8a7ea2d ClientVersion#getLatest added;
ClientVersion#getOldest added;
PlayerManager#getClientVersion(ChannelAbstract) bukkit impl improved
2021-11-29 19:55:37 +01:00
retrooper 1d014a5848 Updated WrapperPlayClientSettings to support 1.18 2021-11-28 23:03:31 +01:00
retrooper a29a0f9e20 Working on 1.18 support 2021-11-28 22:27:31 +01:00
retrooper 4b866d2d72 Yes 2021-11-28 18:09:03 +01:00
retrooper 76024f5ddd Fixed issues in WrapperLoginClientEncryptionResponse, WrapperLoginServerEncryptionRequest,
WrapperPlayClientPluginMessage,
WrapperPlayServerPluginMessage
2021-11-28 17:30:47 +01:00
retrooper d20673cc3e PacketTypeCommon optimized; 2021-11-28 17:01:50 +01:00
retrooper e68f960928 Minor changes to WrapperPlayClientInteractEntity 2021-11-28 16:52:23 +01:00
retrooper 68586850f4 Minor change 2021-11-28 14:24:49 +01:00
retrooper 7c8845e425 Minor remapping optimizations/cleanups 2021-11-28 12:06:01 +01:00
retrooper 66ad7be601 You can now dynamically change a wrapper's version, basically allowing you to transform it to a format of a different version. 2021-11-28 11:30:18 +01:00
retrooper ecfd39825f ItemTypes is fully functioning for all versions. 2021-11-28 11:27:37 +01:00
retrooper 3028b0c0ba Small API changes 2021-11-26 22:24:29 +01:00
retrooper dad68786ce Minor injector bug fixes 2021-11-26 18:24:10 +01:00
retrooper feb94a3982 Fixed issues when you left the server on legacy versions such as 1.8 2021-11-26 17:55:18 +01:00
retrooper 13e0c45b03 Minor fix to injector, still need to work on users leaving while server is running. 2021-11-25 22:33:31 +01:00
retrooper 6078046efa WrapperPlayClientInteractEntity fixed for 1.8.8 servers;
Progress on fixing the ItemType mappings to get it cross version, still working on getting a few items such as MUTTON working
2021-11-25 22:27:18 +01:00
retrooper 0c27a8e793 We fixed ItemStack bugs on older versions 2021-11-25 20:09:12 +01:00
retrooper 27d71dc05d I think we managed to fix item types for versions older than 1.13 2021-11-25 19:47:57 +01:00
retrooper b078b66db9 Removed a few debugs 2021-11-23 21:36:34 +01:00
retrooper bb20f92af8 PacketWrapper#readIdentifier and writeIdentifier created 2021-11-22 20:12:55 +01:00
retrooper 616a4142d2 ComponentSerializer should work on 1.8 2021-11-22 15:38:38 +01:00
retrooper 6e47bbbff6 Trying to have the mapped IDs equivalent to the server version, and not always the IDs of latest server version(1.17.1) 2021-11-21 14:03:03 +01:00
retrooper 01fab2b75e Working on fixing reload issues. 2021-11-20 21:08:10 +01:00
retrooper 09182267c9 We changed some naming conventions, setEntityID -> setEntityId for example;
We now successfully shade and relocate GSON.
2021-11-20 18:51:29 +01:00
retrooper 6b88c08796 Working on supporting transforming item types IDs. Currently not as efficient. 2021-11-19 22:37:28 +01:00
retrooper 485bfbc093 Small bug fixes for hoverEvent 2021-11-19 20:43:26 +01:00
retrooper 82367dd6d6 Fixed HoverEvent and BaseComponent API 2021-11-19 19:09:13 +01:00
retrooper 5bc3597c70 PotionTypes created 2021-11-18 23:01:03 +01:00
retrooper 06113b1cee EntityTypes & EntityType created 2021-11-18 22:15:53 +01:00
retrooper 93c2e4fcd0 Fixed issues when you sent the same wrapper twice. 2021-11-18 19:49:16 +01:00
retrooper c2129f98bb Fixed Plugin message wrappers for 1.12.2 and below 2021-11-18 18:15:10 +01:00
retrooper 896d760236 Small doc changes 2021-11-18 07:10:15 +01:00
retrooper d5adae6be2 Corrected ClientVersion referencing documentation. 2021-11-17 22:10:34 +01:00
retrooper be681c7005 Switched over to GSON JSON API, but still running into some issues 2021-11-15 22:52:44 +01:00
retrooper c9aa7223f0 Corrected max counts of the music disc ItemTypes, added ItemType#isMusicDisc 2021-11-15 12:05:11 +01:00
retrooper 6520e39814 ClientVersion and ServerVersion enum constants now follow java enum conventions and are capitalized. 2021-11-15 00:29:01 +01:00
retrooper 5944174c24 Trying to fix component serialization errors. 2021-11-15 00:18:40 +01:00
retrooper c6202f2a4c Cross version PacketWrapper#readItemStack and PacketWrapper#writeItemStack 2021-11-14 23:50:05 +01:00
retrooper 6c4331a97f All ItemTypes should have the correct maxCount 2021-11-14 23:29:55 +01:00
retrooper 710ace21e4 Updated more maxCounts of ItemTypes, reached ACACIA_SLAB 2021-11-14 23:04:46 +01:00
retrooper dd8119105c Updated more maxCounts of ItemTypes, reached BIRCH_LEAVES 2021-11-14 15:07:53 +01:00
retrooper ecfd5d46f9 Updated more maxCounts of ItemTypes, reached BIRCH_LEAVES 2021-11-14 08:22:21 +01:00
retrooper f88455c011 Updated maxCounts in many ItemTypes, currently at SMOOTH_SANDSTONE_SLAB 2021-11-12 23:17:38 +01:00
retrooper 8250a06d90 Removed debugs 2021-11-12 00:13:49 +01:00
retrooper 710d23dece All ItemTypes added, just need to correct all max amounts!
WrapperPlayServerSetSlot created, but NOT working!
2021-11-12 00:07:42 +01:00
retrooper d23cf6ac1b Commit modified mappings from ProtocolSupport 2021-11-11 18:26:57 +01:00
retrooper 0f1798c7ce We work to support more than just arrays in hover event action values. 2021-11-11 17:07:38 +01:00
retrooper 1e2362aa56 We've got more progress on hover event and click event, many bug fixes, and works better. 2021-11-10 23:04:45 +01:00
retrooper 0a054b88a7 We can successfully send the chat message packet. 2021-11-10 07:17:53 +01:00
retrooper ee8af858b2 Merge remote-tracking branch 'origin/2.0' into 2.0
# Conflicts:
#	bukkit/src/main/java/io/github/retrooper/packetevents/processor/InternalPacketListener.java
2021-11-09 06:57:54 +01:00
retrooper 86f8a440f3 Reverted our wrapper on json.simple;
Testing components
2021-11-09 06:57:34 +01:00
retrooper 4b3069bed9 Fixed JSON stuff 2021-11-08 20:06:26 +01:00
retrooper 4953a7f855 UpdateChecker cleaned up;
Added mapping files
2021-11-08 17:01:00 +01:00
retrooper 2471baf5af NPE bug fix for PacketWrapper#readItemStack usage 2021-11-07 23:43:19 +01:00
retrooper 2f59c0523a Some progress on ItemStack, ItemType and ItemTypes;
Some API refactoring, lots of getIDs converted to getIds
2021-11-07 23:10:51 +01:00
retrooper 88b81b7d51 WrapperPlayServerSpawnPlayer,
WrapperPlayServerVehicleMove created
2021-11-07 21:50:06 +01:00
retrooper 05e445a934 WrapperPlayServerEntityRelativeMove,
WrapperPlayServerEntityLook created
2021-11-07 20:45:54 +01:00
retrooper fa66721f81 WrapperPlayServerEntityRelativeMoveAndLook created 2021-11-07 18:14:35 +01:00
retrooper cfd63c2c1d WrapperPlayServerEntityTeleport,
WrapperPlayServerUpdateViewDistance created
2021-11-07 16:29:36 +01:00
retrooper 4e1b960a06 Removed debugs 2021-11-06 20:36:26 +01:00
retrooper de8ebbdfd0 WrapperPlayServerTabComplete created;
Player attribute system created;
2021-11-06 20:26:31 +01:00
retrooper a4ddf8e3e9 Progress on tab complete 2021-11-05 22:19:07 +01:00
retrooper b47286f947 Working on WrapperPlayServerTabComplete 2021-11-04 22:39:13 +01:00
retrooper af4a9ea590 WrapperPlayServerRespawn optimized; 2021-11-04 07:00:08 +01:00
retrooper c7f25d0c9d WrapperPlayServerRespawn completed, hasn't been tested yet. 2021-11-03 22:50:46 +01:00
retrooper 50aa821110 WrapperPlayServerRespawn almost done 2021-11-02 11:52:56 +01:00
retrooper a35139fddb Progress with WrapperPlayServerRespawn 2021-11-01 15:57:16 +01:00
retrooper be7715fe42 WrapperPlayServerRespawn progress 2021-10-31 23:09:52 +01:00
retrooper 3d9df2118b WrapperPlayServerRespawn created, but no support for older versions than 1.17.1 yet 2021-10-31 22:56:53 +01:00
retrooper 3e3ac32159 WrapperPlayServerPlayerListHeaderAndFooter created 2021-10-31 20:07:15 +01:00
retrooper d089e9dbb0 Some refactoring of a lot of protocol related classes;
WrapperPlayServerSoundEffect created
2021-10-31 19:16:16 +01:00
retrooper e20578b4b7 WrapperPlayServerDisconnect now parses the json message reason! 2021-10-31 10:34:31 +01:00
retrooper 779427702d PacketEvents#build -> PacketEvents#setAPI 2021-10-31 10:18:10 +01:00
retrooper 0a523a93ba WrapperPlayServerEntityHeadLook created;
Color#getByName improved
2021-10-31 10:13:47 +01:00
retrooper 5f3ededf9a Should have fixed all issues in WrapperPlayServerChatMessage;
Color naming issues fixed
2021-10-30 23:06:53 +02:00
retrooper fee52d8931 WrapperPlayServerChatMessage some optimizations 2021-10-30 22:02:50 +02:00
retrooper 3f98b5dc15 We have completed WrapperPlayServerChatMessage and TextComponent and BaseComponent, we might need to look out for errors. 2021-10-30 20:06:04 +02:00
retrooper 5dad71b935 Corrected chat message packet from using a base component to a text component 2021-10-30 18:07:02 +02:00
retrooper e235fe1f46 Fixed a class cast exception when parsing json messages 2021-10-30 17:51:00 +02:00
retrooper c1f99063dd Finished click events. 2021-10-30 17:44:10 +02:00
retrooper 2bb0677cef Color#toString works, ClickEvents progress 2021-10-30 08:25:01 +02:00
retrooper caa004756d ClickEvent class created, not used yet 2021-10-30 07:25:03 +02:00
retrooper 6653fba315 More progress to parsing chat message packet 2021-10-29 22:37:55 +02:00
retrooper 67f64b406c Added missing constructor arguments for some wrappers 2021-10-27 14:42:13 +02:00
retrooper 56f46a1e9e WrapperPlayClientQueryBlockNBT created;
WrapperPlayClientQueryEntityNBT created;
2021-10-27 11:54:39 +02:00
retrooper 348acdedcc Progress on processing chunks on most versions, still need to test lower than 1.16.3 and 1.17+;
Flying packet mappings corrected;
2021-10-27 10:54:47 +02:00
retrooper c6442cdab8 Corrected many incorrect license notices 2021-10-26 22:51:47 +02:00
retrooper 0568ea0c72 Forgot to add license notice to some moroe files. 2021-10-26 22:46:23 +02:00
retrooper 5ba2440a70 Forgot to add license notice to some files. 2021-10-26 22:41:09 +02:00
retrooper 4564ce65e8 Small modification to WrapperPlayClientFlying 2021-10-26 20:26:06 +02:00
retrooper 21585033d9 Flying packets published 2021-10-20 23:06:38 +02:00
retrooper 3cb55fe3ef Flying packets created, some naming and mapping changes of the flying packets; 2021-10-20 23:01:03 +02:00
retrooper d459403bb5 WrapperPlayServerDisplayScoreboard, WrapperPlayServerUpdateScore created 2021-10-17 12:16:38 +02:00
retrooper 47b4b7caa2 Some small cleanup 2021-10-16 23:31:10 +02:00
retrooper 53717ae948 WrapperPlayClientUseItem created;
Direction -> BlockFace
2021-10-15 23:10:58 +02:00
retrooper 8b555c0dbe Fixed NPE with getConnectionState 2021-10-12 16:58:55 +02:00
retrooper 81c1280c20 Fixed getDecoder in early injector with multiple packetevents instances 2021-10-12 16:03:34 +02:00
retrooper 93bb3a6040 We now don't duplicate packetevents APIs 2021-10-12 15:54:38 +02:00
retrooper 67aeae5717 Attempt on supporting multiple packetevents instances 2021-10-12 15:38:06 +02:00
retrooper a1eb97dbe7 Removed all debugs! ViaVersion support added! 2021-10-11 22:34:47 +02:00
retrooper f9ee1e1f87 Got a working encoder with via 2021-10-11 22:28:21 +02:00
retrooper 47580f01a7 Decoder working, we need to call the mc decoder via reflection when Via is present, now time to work on Encoder 2021-10-11 22:08:02 +02:00
retrooper 105e52d5ac Added Via support for decoder, still need to fix encoder. 2021-10-11 19:18:10 +02:00
retrooper d60e7d9e0b Remove redundant method 2021-10-10 21:23:50 +02:00
retrooper 9b9af06f53 Attempt to get a working CustomBukkitEncodeHandlerModern, but we can't ;c, viaversion, why do you have to be so CURSED!!!!111 2021-10-10 21:20:08 +02:00
retrooper 1abf538ecd Publish api module, to allow jitpack to detect it as a sub-module 2021-10-10 18:48:10 +02:00
retrooper 473bb3a1c3 WrapperPlayServerEntityVelocity created 2021-10-10 18:32:41 +02:00
retrooper 49b9b139f2 Maybe fixed build scripts pt.2 2021-10-10 17:58:47 +02:00
retrooper e34e806cad Maybe fixed build scripts? 2021-10-10 17:25:28 +02:00
retrooper 565220fc99 Small changes to build scripts 2021-10-10 17:05:42 +02:00
retrooper b5aaf2fddb Test 2021-10-10 12:30:12 +02:00
retrooper 9df5da312e Removed redundant info in the buildscripts of all subprojects 2021-10-10 11:40:40 +02:00
retrooper 3c3cc88042 Properly generated gradle wrapper 2021-10-10 11:30:28 +02:00
retrooper 397f133751 Wrapper task specified? 2021-10-10 11:21:31 +02:00
retrooper e110acd59c Removed most debug code;
PEVersion#clone fixed
2021-10-10 08:35:46 +02:00
retrooper 4ed541d65d Some project cleanup 2021-10-09 23:12:08 +02:00
retrooper baf1466ee2 Sadly can't use generics to assume Player type at compile time in listeners. 2021-10-09 23:01:18 +02:00
retrooper abf447f5da Updated some links 2021-10-09 20:43:37 +02:00
retrooper c68ae24807 Small correction 2021-10-09 20:35:21 +02:00
retrooper 7b121172fe Tested bukkit implementation, and it works! 2021-10-08 22:18:05 +02:00
retrooper c9eff0f745 Added to gitignore 2021-10-08 21:44:27 +02:00
retrooper 0ae72246c3 More progress on implementing the API in bukkit module 2021-10-08 21:38:57 +02:00
retrooper c1401f0eac Fixed all known errors. Bukkit module fully implemented the api module, now time to test. 2021-10-08 21:21:19 +02:00
retrooper 8ea0c75081 PacketEventsBuilder progress 2021-10-08 18:11:45 +02:00
retrooper e0a101c8db More progress on multi-module project, made bukkit packetevents api builder 2021-10-08 15:36:54 +02:00
retrooper 3162ec6864 Some progress on the multi-module project, bukkit module doesn't compile yet though 2021-10-07 22:08:38 +02:00
retrooper b7a1bfb072 Merge pull request #168 from Conclure/2.0
Fix :D
2021-10-07 20:57:20 +02:00
Conclure c6d8af9024 Fix :D 2021-10-07 20:54:40 +02:00
retrooper 6157ca9e3b Push forgotten files 2021-10-07 20:28:26 +02:00
retrooper 1cde4e16cb Attempting to split project up into modules 2021-10-07 20:25:47 +02:00
retrooper 4bc2d08017 WrapperPlayServerSpawnEntity created;
Redundant comments removed;
2021-10-04 21:53:54 +02:00
retrooper 2511b7f850 WrapperPlayServerEntityStatus created 2021-10-04 18:11:50 +02:00
retrooper 8e283e6a1c Much more WrapperPlayServerEntityMetadata progress 2021-10-03 22:21:09 +02:00
retrooper c29146ee25 Progress on WrapperPlayServerEntityMetadata 2021-10-03 17:22:43 +02:00
retrooper 2840cf3146 WrapperPlayServerEntityProperties created;
WrapperPlayServerPlayerInfo.java bug fix
2021-10-03 15:45:13 +02:00
retrooper 98440415c4 Renamed BlockPosition.java to Vector3i.java 2021-10-03 15:05:13 +02:00
retrooper 44622140af WrapperPlayServerExplosion created 2021-10-03 14:30:59 +02:00
retrooper 463c0920db WrapperPlayServerBlockAction bug fixes and small changes;
WrapperPlayServerBlockBreakAnimation created
2021-10-03 12:57:12 +02:00
retrooper 272f27625e Small corrections for WrapperPlayServerBlockAction;
WrapperPlayServerPlayerInfo finished, but untested;
2021-10-03 12:45:31 +02:00
retrooper 962cb6cd82 More progress on game profile utilities 2021-10-02 20:05:06 +02:00
retrooper 62f60ec815 Merge remote-tracking branch 'origin/2.0' into 2.0 2021-10-02 19:52:18 +02:00
retrooper eaf0a7226f GameProfile utilities completed? 2021-10-02 19:52:00 +02:00
DefineOutside 7585420593 Fix cloning vectors 2021-09-29 13:49:39 -05:00
retrooper 68fe3e214a Still figuring out how to fix our via decoder 2021-09-28 18:35:46 +02:00
retrooper fa43163386 ProtocolSupport works again 2021-09-28 18:03:15 +02:00
retrooper 96625be5b1 Debugs removed 2021-09-27 21:58:46 +02:00
retrooper df3eb01bc6 WrapperPlayClientSettings created;
Hand enum improved
2021-09-27 21:33:05 +02:00
retrooper 7a4092db32 WrapperPlayServerChangeGameState created;
WrapperPlayServerUpdateHealth created
2021-09-27 20:24:52 +02:00
retrooper edda3adead WrapperPlayServerDestroyEntities created;
WrapperPlayServerSetExperience created
2021-09-26 22:17:25 +02:00
retrooper cf6321de5c WrapperPlayServerEntityAnimation created;
Small wrapper API change;
2021-09-26 21:08:53 +02:00
retrooper 2a44f3c0e2 WrapperPlayClientPlayerDigging created 2021-09-26 20:59:57 +02:00
retrooper 500eb55aa7 Some API refactoring;
PacketTypeCommon#getID created;
2021-09-26 19:28:40 +02:00
retrooper e10d5a17c4 Trying to add 1.16.5 support with chunk data packet :c 2021-09-26 15:48:27 +02:00
retrooper f36d1f32b1 Almost finished WrapperPlayServerChunkData 2021-09-26 13:03:29 +02:00
retrooper 0256dc416c Progress with WrapperPlayServerChunkData 2021-09-26 09:11:47 +02:00
retrooper e77e428ba3 Project cleanup with IDE 2021-09-26 00:26:08 +02:00
retrooper 3ad9a75284 Progress for WrapperPlayServerChunkData 2021-09-26 00:24:37 +02:00
retrooper 3355b1c5ab Clientbound packet type mappings for 1.16.2 fixed;
Progress on WrapperPlayServerChunkData;

API refactoring/cleanup
2021-09-25 23:14:34 +02:00
retrooper 9ad33aac0f Progress on via encoder support 2021-09-23 21:25:10 +02:00
retrooper d9ad6bc684 About to start working on supporting ViaVersion with a custom encoder. 2021-09-23 20:58:00 +02:00
retrooper 043dfb5a8b Some API refactoring 2021-09-23 19:55:37 +02:00
retrooper c2a218f067 WrapperPlayServerChunkData is being recoded;
1.17 PacketType server-sided mappings corrected
2021-09-23 18:46:35 +02:00
retrooper 2aefd88e5e WrapperPlayServerChunkData is being recoded;
1.17 PacketType server-sided mappings corrected
2021-09-23 18:33:38 +02:00
retrooper 87223f8df1 Many methods in ServerManager now static 2021-09-22 21:19:49 +02:00
retrooper 794ad6b042 Progress on WrapperPlayServerChunkData 2021-09-22 20:40:24 +02:00
retrooper 0105d466bb PacketWrapper#writeTag created 2021-09-22 18:39:11 +02:00
retrooper 9e28502620 More progress on WrapperPlayServerChunkData 2021-09-22 18:20:17 +02:00
DefineOutside c958999476 Make ServerManager.getVersion() static 2021-09-21 17:29:23 -05:00
DefineOutside 903e0bdc3d Replace PacketWrapperUtil 2021-09-21 17:23:35 -05:00
DefineOutside 408d35b25b Fix block action ID 2021-09-21 16:31:42 -05:00
DefineOutside 01cf822f67 Block action wrapper 2021-09-21 16:18:46 -05:00
DefineOutside 055750e49e Unload chunk wrapper 2021-09-21 15:57:41 -05:00
DefineOutside 088aa9b81b Remove duplicate serverbound window confirmation packet 2021-09-21 15:52:58 -05:00
DefineOutside 1008f88f23 Merge remote-tracking branch 'origin/2.0' into 2.0
# Conflicts:
#	src/main/java/io/github/retrooper/packetevents/wrapper/play/client/WrappedGameClientWindowConfirmation.java
#	src/main/java/io/github/retrooper/packetevents/wrapper/play/server/WrappedGameServerWindowConfirmation.java
2021-09-21 15:43:23 -05:00
DefineOutside 0e4ca3554e Add the window confirmation packet 2021-09-21 15:43:06 -05:00
DefineOutside 221b901a81 Optimize ServerVersion 2021-09-21 15:09:44 -05:00
retrooper 3b3e0ad377 Progress on WrapperPlayServerChunkData, but not near done 2021-09-21 19:53:03 +02:00
retrooper 2b3145f497 WrapperPlayClientAdvancementTab created 2021-09-20 23:02:50 +02:00
retrooper 32bc08b986 WrapperPlayClientPickItem created 2021-09-20 22:47:06 +02:00
retrooper 834adb48eb WrapperPlayClientWindowConfirmation created 2021-09-20 22:36:05 +02:00
retrooper 5403ce9d44 WrapperPlayClientTabComplete, WrapperPlayClientPlayerAbilities created 2021-09-20 22:24:23 +02:00
retrooper 80910efb00 WrapperPlayClientTeleportConfirm, WrapperPlayClientLockDifficulty created 2021-09-19 22:27:41 +02:00
retrooper 5cadf1224f WrapperPlayClientNameItem created 2021-09-19 22:09:36 +02:00
retrooper fa804557ed ClientVersion#isResolved typo fixed 2021-09-19 22:03:35 +02:00
retrooper dbd6efc987 ClientVersion never resolving issue fixed 2021-09-19 21:59:25 +02:00
retrooper 03f02079d8 WrapperPlayClientEntityAction created 2021-09-19 21:57:50 +02:00
retrooper 54ef96eaa1 Got some progress on our legacy handlers. 2021-09-19 19:53:08 +02:00
retrooper 7343cf757b Now supporting legacy ViaVersion releases 2021-09-19 19:33:53 +02:00
retrooper fb69f34821 Removed debugs 2021-09-19 18:33:29 +02:00
retrooper f50464956b WrapperPlayClientCloseWindow, WrapperPlayClientSelectTrade, WrapperPlayClientSetDifficulty created 2021-09-19 18:33:05 +02:00
retrooper 71886b503e WrapperPlayClientSteerBoat and WrapperPlayClientVehicleMove created 2021-09-19 16:14:42 +02:00
retrooper 7606445e1e WrapperPlayClientClickWindow created 2021-09-19 16:03:13 +02:00
retrooper 774a48103b Stopped following vanilla mapping namings and started following wiki.vg's packet namings. 2021-09-19 13:36:15 +02:00
retrooper a9469fed78 WrapperGameClientClientStatus created 2021-09-18 22:13:58 +02:00
retrooper 6e5787a9e1 Removed debugs 2021-09-18 21:45:36 +02:00
retrooper 0654796f82 Removed ProtocolLib redundant dependency in build.gradle 2021-09-18 21:43:33 +02:00
retrooper 63ddd56507 ProtocolSupport support added 2021-09-18 21:10:12 +02:00
retrooper ac12d94448 Paper injector removed. 2021-09-18 20:56:15 +02:00
retrooper 9f845173de ProtocolLib support added!!!!! 2021-09-18 20:49:29 +02:00
retrooper 1aa9bde676 Second attempt at ProtocolLib hook, but we get spammed with errors 2021-09-18 20:42:48 +02:00
retrooper 8c06f24cf4 Attempt at ProtocolLib hook, but we get an illegal access error :O 2021-09-18 18:54:47 +02:00
retrooper a6625b0325 Got stuff working, but we face a ProtocolLib incompatibility 2021-09-18 14:00:18 +02:00
retrooper 106b74d901 Removed ProtocolLib stuff 2021-09-18 13:32:33 +02:00
retrooper 7b7d51dcee PacketReceiveEvent and PacketSendEvent support constructors with ConnectionState specified to optimize always looking them up in the map 2021-09-18 13:29:26 +02:00
retrooper 53012ee386 Third attempt to support Via, need to figure out why CustomBukkitDecodeHandler isn't receiving any bytebufs? 2021-09-18 13:23:09 +02:00
retrooper dcf1b7a6d8 Revert "Attempt to support ViaVersion, obviously not complete, working on fixing issues."
This reverts commit b2294d405e.
2021-09-18 13:05:23 +02:00
retrooper 49cdc7bf79 Revert "Second attempt to support Via, packets still end up being larger than the server expects?"
This reverts commit 8abf92420a.
2021-09-18 13:05:15 +02:00
retrooper 8abf92420a Second attempt to support Via, packets still end up being larger than the server expects? 2021-09-17 22:04:06 +02:00
retrooper b2294d405e Attempt to support ViaVersion, obviously not complete, working on fixing issues. 2021-09-17 19:27:23 +02:00
retrooper 5d708e3195 Add NBT abstraction (not used yet) 2021-09-14 21:49:16 +02:00
retrooper dde3a49925 We came this far, when leaving the server an exception is thrown, ProtocolLib just floods us with errors, this caused more issues than before, we might have to go with the Via like approach if via is available. 2021-09-14 21:45:47 +02:00
retrooper 639abb53ff Cleanup 2021-09-14 21:02:12 +02:00
retrooper 7a511eec7c Fixed issues with all wrappers. 2021-09-14 20:16:06 +02:00
retrooper 05e7b33376 ProtocolLib incompatibilities partially fixed, we still need to handle disconnection index out of bounds errors and ViaVersion's attempt at PLIB support 2021-09-14 17:51:18 +02:00
retrooper 2d8b10888d Our decoder is finally behind ViaVersion, just facing ProtocolLib incompatibilities 2021-09-14 17:23:29 +02:00
retrooper 4fdaece1df PacketWrapper#readItemStack progress, but not done, it only supports clients that have same protocol version as the server 2021-09-10 23:00:52 +02:00
retrooper 6bce3cc847 Some changes (lazy to document) 2021-09-07 17:44:57 +02:00
retrooper b8c9760275 Lots of refactoring;
Documented some wrappers;
Working on PacketWrapper#readItemStack;
Import optimization;
Code cleanup
2021-09-06 13:34:21 +02:00
retrooper 7c0c845a3d WrapperGameClientResourcePackStatus created 2021-09-04 01:19:47 +02:00
retrooper 678adda106 WrapperGameClientHeldItemChange created 2021-09-04 01:01:39 +02:00
retrooper 180a7cd505 WrapperGameServerDisconnect created 2021-09-04 00:54:57 +02:00
retrooper 68f0053b9b WrapperGameServerSpawnLivingEntity created, but incomplete, We need to make our own EntityType enum. (and map all ids per version);
Small fixing in PacketTypes, cleaned up some duplicate types.
2021-09-04 00:39:38 +02:00
retrooper 5139f8a38f Removed debugs. 2021-09-03 19:16:33 +02:00
retrooper 68ff049691 ServerManager#receivePacket works better now. 2021-09-03 19:13:55 +02:00
retrooper 30836c6714 ServerManager#receivePacket works, but has a performance cost. 2021-09-03 18:53:56 +02:00
retrooper 1ce86f7e63 Realized the build issue was jitpack's fault 2021-09-03 17:23:31 +02:00
retrooper ec4f44f215 Trying to fix build issues for jitpack pt. 4 2021-09-03 17:19:29 +02:00
retrooper 3b48c18e9a Trying to fix build issues for jitpack pt. 3 2021-09-03 17:17:02 +02:00
retrooper db3a6e3076 Trying to fix build issues for jitpack pt. 3 2021-09-03 17:16:48 +02:00
retrooper 4848a4c078 Trying to fix build issues for jitpack pt. 2 2021-09-03 17:15:13 +02:00
retrooper 8f550a67d6 Trying to fix build issues for jitpack 2021-09-03 17:12:45 +02:00
retrooper fb01545c1b All wrappers from now on must be sendable.
Still need to work on sending client-sided packets.
2021-09-03 15:49:12 +02:00
retrooper 2f572dc3ac Made the client-side wrappers sendable. 2021-09-03 15:19:31 +02:00
retrooper da8126d62e Small cleanup 2021-09-03 14:33:40 +02:00
retrooper c3993c3e6e PacketEventsSettings#lock removed; 2021-09-03 14:30:49 +02:00
retrooper 587fb09f4d All wrappers can now modify data. Created setters for all current wrappers. 2021-09-03 14:18:10 +02:00
retrooper dc6b457e2d PacketSendEvent#getPostTask created 2021-09-01 15:07:47 +02:00
retrooper 64606f5cb8 Worked on 1.7.10 handlers. Still need to test them. 2021-08-31 22:53:05 +02:00
retrooper eca616f9a9 Added required license notices for each file. 2021-08-31 22:41:07 +02:00
retrooper 4f25bfcde3 PacketSendEvent actually gets cancelled in our modern encoder. 2021-08-31 22:07:02 +02:00
retrooper 03a437fb7f Corrected the credit. We give credit to all projects that help build up our cross-version injector. 2021-08-31 20:40:47 +02:00
retrooper 9e4a56e936 Optimize all imports. 2021-08-31 20:26:41 +02:00
retrooper b39f3daf97 PlayerManager#sendPacket now works with ProtocolSupport;
PacketListener and PacketListenerReflect exist;
2021-08-31 20:23:51 +02:00
retrooper 158d2a9ea9 WrapperGameClientChatMessage#setMessage created, not efficient, but works for now;
WrapperGameServerChatMessage bug fix;
2021-08-31 10:55:38 +02:00
retrooper 96c53be358 Injector fixed for 1.11.2 server versions and lower. 2021-08-29 14:20:35 +02:00
retrooper 56459dcf5a We are having issues on 1.9 with our injector. About to do changes.
WrapperGameClientSetBeaconEffect created;
2021-08-29 13:30:40 +02:00
retrooper 5c370d13ae Small cleanup; 2021-08-29 11:34:07 +02:00
retrooper ed61e4f968 PacketWrapper#readString cleanups 2021-08-29 11:02:37 +02:00
retrooper e23fdc09b9 Wrappers support a constructor taking in an event. 2021-08-29 10:57:17 +02:00
retrooper f6ca0e0ec4 WrapperGameServerChatMessage created; 2021-08-28 23:04:53 +02:00
retrooper bec616d924 Worked on sendable wrapper abstraction;
ByteBufAbstract#writeBytes(byte[]) created;

WrapperGameServerHeldItemChange created;

All other clientbound wrappers are now sendable.
2021-08-28 20:38:52 +02:00
retrooper 1b03192d09 We now support processing packets while ProtocolSupport is present. Sending packets while ProtocolSupport is present doesn't seem to work. 2021-08-28 18:18:00 +02:00
retrooper 9b455654c7 Reverted to a working commit. 2021-08-27 09:40:33 +02:00
retrooper 1af9dde7bb Working on supporting sending packets. We currently get a decoderexception. 2021-08-27 09:34:07 +02:00
retrooper fcb607399d Revert "ProtocolSupport support added, but we are still behind protocolsupport until we receive the handshake packet unfortunately, would be great if we could always be before them."
This reverts commit dae2419cef.
2021-08-27 09:25:07 +02:00
retrooper d181269171 Revert "Working on supporting sending packets. We currently get a decoderexception."
This reverts commit 130d711640.
2021-08-26 23:08:39 +02:00
retrooper cb6d7d96b3 Revert "Added some debugs to our injector, considering changing our injection approach."
This reverts commit 3ffdc6aa79.
2021-08-26 23:08:12 +02:00
retrooper 3ffdc6aa79 Added some debugs to our injector, considering changing our injection approach. 2021-08-26 10:46:36 +02:00
retrooper 130d711640 Working on supporting sending packets. We currently get a decoderexception. 2021-08-25 22:36:29 +02:00
retrooper dae2419cef ProtocolSupport support added, but we are still behind protocolsupport until we receive the handshake packet unfortunately, would be great if we could always be before them. 2021-08-25 21:06:34 +02:00
retrooper b4e2eb76b5 Encoder bug fix. 2021-08-25 17:09:56 +02:00
retrooper e4768096b2 Project code cleanup with IDE (Optimize imports, etc);
Added legacy netty import (1.7.10 spigots) support to our decoders and encoders.
2021-08-25 17:01:52 +02:00
retrooper 505531f8e5 Created lots of netty abstraction. 2021-08-25 16:04:09 +02:00
retrooper 47f5768474 EventManager cleanup;
GlobalChannelInjector fixed;
2021-08-25 10:40:38 +02:00
retrooper 898c4a1a40 WrapperGameClientInteractEntity created;
Some debugs removed;
compatInjector setting removed;
2021-08-25 10:22:35 +02:00
retrooper 57e6beb904 Our encoder and decoder are officially working. 2021-08-25 09:07:37 +02:00
retrooper e09080436b Working on some stuff. 2021-08-24 22:13:30 +02:00
retrooper 6862cda387 Some progress on supporting the decompressor with our decoder. 2021-08-24 19:58:24 +02:00
retrooper 5c4ac0a0fa Small cleanup 2021-08-24 16:40:54 +02:00
retrooper 8e577eedf0 Sort of reverted the encoder and decoder to their initial form. 2021-08-24 15:42:19 +02:00
retrooper 442d171cfc Encoder pretty empty 2021-08-24 15:16:45 +02:00
retrooper df85c00175 Did some testing, did not manage to complete encoder, reverting some stuff. 2021-08-24 13:39:26 +02:00
retrooper 3af610bb73 Progress on encoder, we can finally successfully switch to the game state, now we need to work on processing game packets, some are compressed, some aren't. 2021-08-24 12:38:26 +02:00
retrooper 2708f00556 Working on our decoder and encoder, many changes, this is not stable. Just a progress/safety commit. 2021-08-23 22:25:59 +02:00
retrooper 510a5a8d09 Corrections 2021-08-23 21:14:47 +02:00
retrooper 2b184e6ce7 Small change. 2021-08-23 14:39:43 +02:00
retrooper a68df54ffe Some bug fixing. 2021-08-23 14:33:09 +02:00
retrooper a8233b492a Worked on fixing our decoder, still working on fixing our encoder. 2021-08-22 22:22:22 +02:00
retrooper 20cbdef83c PacketType.Game.Server optimized 2021-08-22 13:46:52 +02:00
retrooper 13a1ae1069 Small build.gradle cleanup 2021-08-22 10:22:16 +02:00
retrooper 7fd63d30c9 PacketListenerPriority renamed to Priority 2021-08-22 09:18:43 +02:00
retrooper 6396545364 PacketType abstraction reverted and modified. This is the better approach. 2021-08-22 09:16:29 +02:00
retrooper d7b03dd947 Revert "PacketType abstraction improved, still need to test."
This reverts commit a1d20a7b7c.
2021-08-22 09:14:56 +02:00
retrooper a1d20a7b7c PacketType abstraction improved, still need to test. 2021-08-22 00:12:10 +02:00
retrooper 433c49e6be Some small cleanup 2021-08-22 00:02:01 +02:00
retrooper 3eea564cba Hopefully got rid of the IDE specific files and gradle build files. 2021-08-21 23:49:31 +02:00
retrooper a6b6ade573 MinecraftReflection cleanup 2021-08-21 22:35:41 +02:00
retrooper 70658b952c PacketType.Handshaking.Client.LEGACY_SERVER_LIST_PING created 2021-08-21 22:33:15 +02:00
retrooper 2b8130d2e7 Event abstraction cleanup;
PacketListenerPriority refactored;
2021-08-21 21:51:34 +02:00
retrooper 969d218519 Documented more wrappers. 2021-08-21 20:47:31 +02:00
retrooper af7f7baa57 Started documenting some server-bound game wrappers. 2021-08-20 22:15:41 +02:00
retrooper 387e521019 Cleaned up MinecraftReflection; Deleted some unneeded classes 2021-08-20 21:55:12 +02:00
retrooper 0da5ddbe6c Progress on encoder, only status packets can be listened to, made some samples and some corrections to our code. 2021-08-20 16:56:52 +02:00
retrooper cfa1c4c076 All wrapper's constructors are now consistent;
PacketType#Play -> PacketType#Game;
PacketState#PLAY -> PacketState#GAME
2021-08-17 08:13:44 +02:00
retrooper 9460812be5 WrapperGameClientAnimation corrected; 2021-08-16 22:53:34 +02:00
retrooper a2c4ffc1a9 WrapperGameClientAnimation created;
WrapperGameClientClickWindowButton created;
WrapperGameClientGenerateStructure created;

WrapperLoginClientEncryptionResponse fixed;
WrapperLoginClientPluginResponse fixed;
2021-08-16 22:45:34 +02:00
retrooper 260c67ba8d Merge remote-tracking branch 'origin/2.0' into 2.0 2021-08-16 21:55:17 +02:00
retrooper 8c41a24bb7 Added missing ClientboundPacketType_1_12 2021-08-16 21:54:19 +02:00
retrooper 60399cfb01 Corrected credit in README 2021-08-16 08:47:45 +00:00
retrooper 3294495bda Merge branch '2.0' of https://github.com/retrooper/packetevents into 2.0 2021-08-14 20:53:08 +02:00
retrooper 1583b1e0a3 New attempt at encoder. 2021-08-14 20:51:44 +02:00
retrooper 7f635d46e1 Update README.md 2021-08-14 14:14:06 +02:00
retrooper 55b38b499a Finished client-bound packet types. Still need to test. 2021-08-13 21:18:50 +02:00
retrooper 8b13cd2dad Calling via's decoder doesn't work? 2021-08-12 12:18:57 +02:00
retrooper fa824c9ebd Attempt at encoder, does not work, trying something else. 2021-08-12 11:38:44 +02:00
retrooper c418ddfd1c Lots of project cleanup. 2021-08-11 20:26:30 +02:00
retrooper c753839df7 Progress to server-bound packet types. 2021-08-11 19:23:17 +02:00
retrooper ae1df7e2a1 Fixed some PacketType confusion. 2021-08-11 14:33:11 +02:00
retrooper b341df4098 Small cleanup, still some confusion with 1.16.5 and 1.16.4 having some different packet ids? 2021-08-11 13:56:49 +02:00
retrooper 9339bdb428 More cleanup to PacketTypes 2021-08-11 13:40:22 +02:00
retrooper 8d79248c0b All serverbound packet types finished. Need to work on clientbound PLAY ones. 2021-08-11 13:34:13 +02:00
retrooper 140b432364 PacketType abstraction and cleanup, still need to test 2021-08-11 12:12:53 +02:00
retrooper 75e45dbc52 Removed some gradle files hopefully 2021-08-11 11:48:26 +02:00
retrooper 63c6207d71 PacketType bug fix;
Add .gradle to gitignore
2021-08-11 11:46:58 +02:00
retrooper b6dd3e0e82 Remove .idea files 2021-08-11 11:04:09 +02:00
retrooper dca5fc6a4b Custom decoder should now work on 1.7.10 too. 2021-08-11 11:02:57 +02:00
retrooper a0765b7169 Merge remote-tracking branch 'abhi289/dev' into 2.0
# Conflicts:
#	.gradle/7.0/executionHistory/executionHistory.bin
#	.gradle/7.0/executionHistory/executionHistory.lock
#	.gradle/7.0/fileHashes/fileHashes.bin
#	.gradle/7.0/fileHashes/fileHashes.lock
#	.gradle/7.0/javaCompile/classAnalysis.bin
#	.gradle/buildOutputCleanup/buildOutputCleanup.lock
#	.gradle/checksums/checksums.lock
#	src/main/java/io/github/retrooper/packetevents/packetwrappers/play/out/setslot/WrappedPacketOutSetSlot.java
#	src/main/java/io/github/retrooper/packetevents/packetwrappers/play/out/spawnentityliving/WrappedPacketOutSpawnEntityLiving.java
2021-08-11 10:36:33 +02:00
retrooper ea7b9b432a Serverbound packet types finished. 2021-08-11 10:28:11 +02:00
retrooper 4c57e37807 "Bad packet xyz" issue, still need to fix, check via discord 2021-08-10 23:16:11 +02:00
retrooper fc526ae232 ViaVersion now works with packetevents on paper! Need to test on spigot and need to test older via versions and add protocolsupport support. 2021-08-10 22:29:06 +02:00
retrooper dc46c8b5ea Back to old replacing injector, we need to try initialize our channelinitializer BEFORE viaversion. 2021-08-10 21:05:22 +02:00
retrooper 5f78d2d059 PacketSplitter replacing attempt when making a decoder did NOT WORK :c 2021-08-10 20:45:20 +02:00
retrooper 0cf894567f Removed debug 2021-08-10 10:58:01 +02:00
retrooper 651c4a9955 Small adjustments to the decoder, we realized we are receiving invalid packets and passing invalid packets onto the next handlers. We need to figure out why we are getting invalid packets. 2021-08-09 17:52:16 +02:00
retrooper 9bfab5d899 Small cleanup 2021-08-09 10:04:15 +02:00
retrooper 99b24b7ad1 Working on injector with ViaVersion support. We get a ViaVersion exception 2021-08-08 13:44:40 +02:00
retrooper db9025dcea Progress working on injector. 2021-08-08 12:08:58 +02:00
retrooper b3729ad078 WrapperLoginServerLoginSuccess corrected;
WrapperGameClientKeepAlive completed;
WrapperGameClientPong completed;
WrapperGameClientSpectate completed;
2021-08-06 14:48:32 +02:00
retrooper 709812d307 WrapperGameClientChatMessage complete 2021-08-05 23:22:02 +02:00
retrooper fd7f0282a5 WrapperGameClientUpdateSign finished 2021-08-05 23:03:29 +02:00
retrooper 39be921ae8 Fixed issues with PluginMessage wrappers 2021-08-05 13:37:28 +02:00
retrooper d1c9d55158 Some exception refactoring 2021-08-05 12:09:20 +02:00
retrooper 0f887d3e7e Some refactoring and cleaning up, some recoding. 2021-08-05 12:08:24 +02:00
retrooper 67a89e2578 Few renamings 2021-08-05 11:55:12 +02:00
retrooper 038933e978 All login and status wrappers created 2021-08-05 11:34:51 +02:00
retrooper ca2003b644 Some changes 2021-08-05 08:41:58 +02:00
retrooper d68e69ffdf Improved some wrappers. 2021-08-05 07:21:21 +02:00
abhiram555 db1b73ca6e Wrote few wrappers for client login 2021-08-05 01:15:08 +05:30
abhiram555 e69739be72 Added Client Ping Packet Wrapper 2021-08-05 00:39:36 +05:30
abhiram555 c33681e3be Fix PacketDecodeEvent cancelling 2021-08-05 00:07:04 +05:30
retrooper 7c04d9ea7c WrapperLoginClientLoginStart finished 2021-08-04 20:33:47 +02:00
retrooper b97454dbde Merge branch 'dev' of https://github.com/abhiram555/packetevents into abhi-dev 2021-08-04 19:52:24 +02:00
abhiram555 1ba5442d0c Fixed Lagacy decoder too 2021-08-04 23:21:58 +05:30
abhiram555 7e59b91723 Added a packet wrapper for CustomPayload 2021-08-04 23:18:23 +05:30
abhiram555 9b88efec36 Properly fix the decoder 2021-08-04 22:59:32 +05:30
abhiram555 9678ef523a Fix the decoder 2021-08-04 22:06:30 +05:30
retrooper fe3664e8fa Attempt to create some bytebuf wrappers, they don't really work. Did some API cleanup, removed deprecations. 2021-08-04 11:13:10 +02:00
retrooper 3ed2656935 Deleted many classes, looking to recode most of them or just remove them. They aren't needed anymore. Working with new bytebuf system. 2021-08-03 22:52:40 +02:00
retrooper dc354330fb Build changes 2021-08-03 21:45:01 +02:00
retrooper 24cefaeeff Small cleanup, trying to find issue with weird values from bytebufs (when you haven't reloaded) 2021-08-03 18:49:56 +02:00
retrooper 897d7d035d Duplicate the bytebuf for PacketDecodeEvent so the next handler doesn't end up with an empty bytebuf 2021-08-03 18:05:00 +02:00
retrooper b4132946c9 Build issues? 2021-08-03 16:57:16 +02:00
retrooper 7e3a2a2875 Early injector duplicate decoder issue fixed 2021-08-03 16:55:15 +02:00
retrooper c28e8cd732 Small changes 2021-08-03 15:35:59 +02:00
retrooper e39e86966c Added getPlayer to PacketDecodeEvent, applied ByteBufAbstract, Still need to test 2021-08-03 13:40:42 +02:00
retrooper 90b2f6444d ByteBuf abstraction finished, now time to apply it. 2021-08-03 13:03:47 +02:00
retrooper 8a754af137 Progress on ByteBuf abstraction so we can support both 1.7.10 and newer versions. 2021-08-03 11:17:07 +02:00
abhiram555 340e10ff6d Remove .gradle 2021-08-02 20:58:06 +05:30
abhiram555 37517af695 Project Cleanup 2021-08-02 20:32:21 +05:30
abhiram555 33fcf6105a Project Cleanup 2021-08-02 20:17:50 +05:30
abhiram555 8cf9af3024 Project files cleanup 2021-08-02 20:15:49 +05:30
abhiram555 eed8409e4b Added PacketDecoder on lagacy minecraft 2021-08-02 20:12:29 +05:30
abhiram555 bd193e4be2 Removed IJ files 2021-08-02 16:19:40 +05:30
abhiram555 87c73392eb Added PacketDecodeEvent for modern minecraft version's 2021-08-02 16:18:51 +05:30
647 changed files with 152816 additions and 23552 deletions

No files matched your search

+15 -18
View File
@@ -1,7 +1,7 @@
---
name: Bug report
about: Report a bug to help us fix
title: "[BUG REPORT]"
about: Report bugs to help us improve our software.
title: ""
labels: bug
assignees: ''
@@ -10,11 +10,21 @@ assignees: ''
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
**Software brand**
Please let us know what software you are using.
Eg. Spigot 1.18.2, Paper 1.18.2, Tuinity 1.18.2, Pufferfish 1.18.2, etc...
Make sure to mention the version of the software.
**Plugins**
Please give us a list of your plugins. Sometimes we run into incompatibilities. Having an overview of the plugins on your server can really help identify the problem quicker.
Eg. ViaVersion, ProtocolLib, HolographicDisplays
You may also provide a screenshot.
**How To Reproduce**
Steps to reproduce the behavior:
*Example:*
1. Login on the 1.16.4 minecraft client.
2. Join the server while it is still starting up.
1. Join with the 1.18.2 vanilla minecraft client.
2. Spam
3. ....
4. See error
@@ -24,18 +34,5 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**About your server (please complete the following information):**
- Spigot: [eg. Paper or Tuinity]
We only accept reports that are reproducible
on one of the supported spigots.
- Server Version: [eg. 1.16.4]
Feel free to report bugs for versions newer than 1.7.10, even if we
don’t support them yet, but be aware that we might have already
found the bug and fixed it in a dev build, just before you reported it.
Please don’t get frustrated in such cases.
- Plugins List if possible: [eg. ViaVersion, ProtocolLib, HolographicDisplays]
**Additional context**
Add any other context about the problem here.
+54
View File
@@ -0,0 +1,54 @@
name: Gradle Package
on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Gradle
run: gradle shadowJar
- name: Upload build artifacts api
uses: actions/upload-artifact@v1
with:
name: api-build
path: api/build/libs
- name: Upload build artifacts spigot
uses: actions/upload-artifact@v1
with:
name: spigot-build
path: spigot/build/libs
- name: Upload build artifacts netty-common
uses: actions/upload-artifact@v1
with:
name: netty-common-build
path: netty-common/build/libs
- name: Upload build artifacts bungeecord
uses: actions/upload-artifact@v1
with:
name: bungeecord-build
path: bungeecord/build/libs
- name: Upload build artifacts velocity
uses: actions/upload-artifact@v1
with:
name: velocity-build
path: velocity/build/libs
+89 -82
View File
@@ -1,78 +1,18 @@
#
# JetBrains
#
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
/.idea
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iml
*.ipr
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
#
# Java
#
# Compiled class file
*.class
@@ -82,9 +22,6 @@ fabric.properties
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
@@ -97,17 +34,87 @@ fabric.properties
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
#
# Maven
#
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Cache of project
.gradletasknamecache
**/build/
# Common working directory
run/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
/src/main/resources/plugin.yml
/.idea/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16 -12
View File
@@ -3,27 +3,31 @@
[![](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 an open-source Packet API. It has many cross-version packet-wrappers. You can process incoming and outgoing packets on the server. You can even send packets with our packet-wrappers. We are here to save you a ton of time.
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/)
* [JavaDoc](https://packetevents.github.io/javadocs)
* [JavaDocs](https://packetevents.github.io/javadocs)
* [Discord](https://discord.me/packetevents)
### Setup
[Learn more](https://github.com/retrooper/packetevents/wiki/1.-Setup)
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup)
### Discord
[Learn more](https://discord.me/packetevents)
### Contributing/Forking
[Learn more](https://github.com/retrooper/packetevents/wiki/2.-Contributing-and-Forking)\
Our discord server has a role for contributors and forkers.
### Contributing
[Learn more](https://github.com/retrooper/packetevents/wiki/Contributing)
### Sponsorships
[![](https://www.ej-technologies.com/images/product_banners/jprofiler_small.png)](https://www.ej-technologies.com/products/jprofiler/overview.html)
### Statistics
PacketEvents collects statistics anonymously through bStats. Participation is completely optional and you can opt-out at any time, although it is really helpful in figuring out what environments the plugin is running in (i.e. versions of Spigot, Java), so I can adjust development accordingly.
PacketEvents optionally collects statistics using [bStats](https://bstats.org/)\
Check out our [bStats page](https://bstats.org/plugin/bukkit/packetevents/11327)
### Credit
PacketEvents uses an injector that is extremely similar to ViaVersion's injector. I have included license and copyright holder notice in the files taken from ViaVersion. Thank you ViaVersion.
### Credit to
[wiki.vg/Protocol](https://wiki.vg/Protocol)
[adventure](https://github.com/KyoriPowered/adventure)
[gson](https://github.com/google/gson)
[ViaVersion](https://github.com/ViaVersion/ViaVersion)
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)
[MCProtocolLib](https://github.com/GeyserMC/MCProtocolLib/)
[netty](https://github.com/netty/netty)
+3
View File
@@ -0,0 +1,3 @@
dependencies {
compileOnly(adventureDependencies)
}
@@ -16,21 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.packetwrappers.play.in.tabcomplete;
package com.github.retrooper.packetevents;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
public final class PacketEvents {
private static PacketEventsAPI<?> API;
public class WrappedPacketInTabComplete extends WrappedPacket {
public WrappedPacketInTabComplete(NMSPacket packet) {
super(packet);
//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;
public static PacketEventsAPI<?> getAPI() {
return API;
}
public String getText() {
return readString(0);
}
public void setText(String text) {
writeString(0, text);
public static void setAPI(PacketEventsAPI<?> api) {
API = api;
}
}
@@ -0,0 +1,87 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents;
import com.github.retrooper.packetevents.event.EventManager;
import com.github.retrooper.packetevents.injector.ChannelInjector;
import com.github.retrooper.packetevents.manager.player.PlayerManager;
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
import com.github.retrooper.packetevents.manager.server.ServerManager;
import com.github.retrooper.packetevents.netty.NettyManager;
import com.github.retrooper.packetevents.settings.PacketEventsSettings;
import com.github.retrooper.packetevents.util.LogManager;
import com.github.retrooper.packetevents.util.PEVersion;
import com.github.retrooper.packetevents.util.updatechecker.UpdateChecker;
import java.util.logging.Logger;
public abstract class PacketEventsAPI<T> {
private static final EventManager EVENT_MANAGER = new EventManager();
private static final PacketEventsSettings SETTINGS = new PacketEventsSettings();
private static final UpdateChecker UPDATE_CHECKER = new UpdateChecker();
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
private static final LogManager LOG_MANAGER = new LogManager();
private static final PEVersion VERSION = new PEVersion(2, 0, 0);
public EventManager getEventManager() {
return EVENT_MANAGER;
}
public PacketEventsSettings getSettings() {
return SETTINGS;
}
public UpdateChecker getUpdateChecker() {
return UPDATE_CHECKER;
}
public PEVersion getVersion() {
return VERSION;
}
public Logger getLogger() {
return LOGGER;
}
public LogManager getLogManager() {
return LOG_MANAGER;
}
public abstract void load();
public abstract boolean isLoaded();
public abstract void init();
public abstract boolean isInitialized();
public abstract void terminate();
public abstract T getPlugin();
public abstract ServerManager getServerManager();
public abstract ProtocolManager getProtocolManager();
public abstract PlayerManager getPlayerManager();
public abstract NettyManager getNettyManager();
public abstract ChannelInjector getInjector();
}
@@ -16,23 +16,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event.eventtypes;
package com.github.retrooper.packetevents.event;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketListenerAbstract;
import io.github.retrooper.packetevents.event.impl.PacketPlayReceiveEvent;
import com.github.retrooper.packetevents.event.PacketEvent;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
/**
* The {@link PacketEvent} implements this interface.
* Every inbuilt event should implement the {@link #call(PacketListenerAbstract)} method.
* Every inbuilt event should implement the {@link #call(PacketListenerCommon)} method.
* If you are making a custom event, don't implement this.
* The {@link PacketListenerAbstract#onPacketEventExternal(PacketEvent)} method is called for every event that is not in-built.
* The {@link PacketListenerCommon#onPacketEventExternal(PacketEvent)} method is called for every event that is not in-built.
* including custom events.
*
* @author retrooper
* @see PacketPlayReceiveEvent
* @since 1.8
*/
public interface CallableEvent {
void call(PacketListenerAbstract listener);
default void call(PacketListenerCommon listener) {
listener.onPacketEventExternal((PacketEvent) this);
}
}
@@ -16,9 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event.eventtypes;
package com.github.retrooper.packetevents.event;
import io.github.retrooper.packetevents.event.impl.PacketPlayReceiveEvent;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
/**
* Every event that supports cancellation should implement this interface.
@@ -26,11 +26,11 @@ import io.github.retrooper.packetevents.event.impl.PacketPlayReceiveEvent;
* in deciding whether the event will cancel.
* This means an event with a lower priority than the higher priority one would not be able to decide.
* Cancelling the event means the action assosiated with the event will be cancelled.
* For example, cancelling the {@link PacketPlayReceiveEvent}
* For example, cancelling the {@link PacketReceiveEvent}
* will prevent minecraft from processing the incoming packet.
*
* @author retrooper
* @see PacketPlayReceiveEvent
* @see PacketReceiveEvent
* @since 1.7
*/
public interface CancellableEvent {
@@ -0,0 +1,119 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.PacketEvents;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
public class EventManager {
private final Map<Byte, HashSet<PacketListenerCommon>> listenersMap = new ConcurrentHashMap<>();
/**
* Call the PacketEvent.
* This method processes the event on all the registered dynamic packet event listeners.
* The {@link PacketListenerPriority#LOWEST} prioritized listeners will be processing first,
* the {@link PacketListenerPriority#MONITOR} will be processing last and can
* be the final decider whether the event has been cancelled or not.
*
* @param event {@link PacketEvent}
*/
public void callEvent(PacketEvent event) {
callEvent(event, null);
}
public void callEvent(PacketEvent event, @Nullable Runnable postCallListenerAction) {
for (byte priority = PacketListenerPriority.LOWEST.getId(); priority <= PacketListenerPriority.MONITOR.getId(); priority++) {
HashSet<PacketListenerCommon> listeners = listenersMap.get(priority);
if (listeners != null) {
for (PacketListenerCommon listener : listeners) {
try {
event.call(listener);
} catch (Throwable t) {
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
}
if (postCallListenerAction != null) {
postCallListenerAction.run();
}
}
}
}
if (event instanceof ProtocolPacketEvent && PacketEvents.getAPI().getSettings().shouldListenersReadOnly()) {
((ProtocolPacketEvent<?>) event).setLastUsedWrapper(null);
}
}
public PacketListenerCommon registerListener(PacketListener listener, PacketListenerPriority priority) {
PacketListenerCommon packetListenerAbstract = listener.asAbstract(priority);
return registerListener(packetListenerAbstract);
}
/**
* Register the dynamic packet event listener.
*
* @param listener {@link PacketListenerCommon}
*/
public PacketListenerCommon registerListener(PacketListenerCommon listener) {
byte priority = listener.getPriority().getId();
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(priority);
if (listenerSet == null) {
listenerSet = new HashSet<>();
}
listenerSet.add(listener);
listenersMap.put(priority, listenerSet);
return listener;
}
/**
* Register multiple dynamic packet event listeners with one method.
*
* @param listeners {@link PacketListenerCommon}
*/
public PacketListenerCommon[] registerListeners(PacketListenerCommon... listeners) {
for (PacketListenerCommon listener : listeners) {
registerListener(listener);
}
return listeners;
}
public void unregisterListener(PacketListenerCommon listener) {
HashSet<PacketListenerCommon> listenerSet = listenersMap.get(listener.getPriority().getId());
if (listenerSet == null) return;
listenerSet.remove(listener);
}
public void unregisterListeners(PacketListenerCommon... listeners) {
for (PacketListenerCommon listener : listeners) {
unregisterListener(listener);
}
}
/**
* Unregister all dynamic packet event listeners.
*/
public void unregisterAllListeners() {
listenersMap.clear();
}
}
@@ -16,10 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event;
package com.github.retrooper.packetevents.event;
import io.github.retrooper.packetevents.event.eventtypes.CallableEvent;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.util.TimeStampMode;
/**
* An event in both of PacketEvents' event systems.
@@ -28,7 +29,23 @@ import io.github.retrooper.packetevents.event.eventtypes.CallableEvent;
* @since 1.2.6
*/
public abstract class PacketEvent implements CallableEvent {
private long timestamp = System.currentTimeMillis();
private final long timestamp;
public PacketEvent() {
TimeStampMode timeStampMode = PacketEvents.getAPI().getSettings()
.getTimeStampMode();
switch (timeStampMode) {
case MILLIS:
timestamp = System.currentTimeMillis();
break;
case NANO:
timestamp = System.nanoTime();
break;
//AKA NONE:
default:
timestamp = 0L;
}
}
/**
* Timestamp of when the PacketEvent was created.
@@ -40,20 +57,7 @@ public abstract class PacketEvent implements CallableEvent {
return timestamp;
}
/**
* Setter for the timestamp.
*
* @param timestamp Packet timestamp in milliseconds.
*/
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
}
public void callPacketEventExternal(final PacketListenerAbstract listener) {
public void callPacketEventExternal(PacketListenerCommon listener) {
listener.onPacketEventExternal(this);
}
public boolean isInbuilt() {
return false;
}
}
@@ -16,24 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event.annotation;
package com.github.retrooper.packetevents.event;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This is what you override your event listener with on the old event system.
* You can specify the event priority of the listener method.
*
* @author retrooper
* @since 1.0
* @deprecated Was used for the old event system, the new one doesn't need this anymore.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Deprecated
public @interface PacketHandler {
byte priority() default 2; //NORMAL priority value
}
@@ -0,0 +1,73 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
public interface PacketListener {
default PacketListenerAbstract asAbstract(PacketListenerPriority priority) {
return new PacketListenerAbstract(priority) {
@Override
public void onUserConnect(UserConnectEvent event) {
PacketListener.this.onUserConnect(event);
}
@Override
public void onUserLogin(UserLoginEvent event) {
PacketListener.this.onUserLogin(event);
}
@Override
public void onUserDisconnect(UserDisconnectEvent event) {
PacketListener.this.onUserDisconnect(event);
}
@Override
public void onPacketReceive(PacketReceiveEvent event) {
PacketListener.this.onPacketReceive(event);
}
@Override
public void onPacketSend(PacketSendEvent event) {
PacketListener.this.onPacketSend(event);
}
@Override
public void onPacketEventExternal(PacketEvent event) {
PacketListener.this.onPacketEventExternal(event);
}
};
}
default void onUserConnect(UserConnectEvent event) {
}
default void onUserLogin(UserLoginEvent event) {
}
default void onUserDisconnect(UserDisconnectEvent event) {
}
default void onPacketReceive(PacketReceiveEvent event) {
}
default void onPacketSend(PacketSendEvent event) {
}
default void onPacketEventExternal(PacketEvent event) {
}
}
@@ -16,20 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.google;
package com.github.retrooper.packetevents.event;
import com.google.common.base.Optional;
public class GoogleOptionalUtils {
public static Object getOptionalValue(Object opt) {
return ((Optional<?>) opt).get();
public abstract class PacketListenerAbstract extends PacketListenerCommon {
public PacketListenerAbstract(PacketListenerPriority priority) {
super(priority);
}
public static Object getOptionalEmpty() {
return Optional.absent();
public PacketListenerAbstract() {
super();
}
public static Object getOptional(Object value) {
return Optional.of(value);
@Override
public void onPacketReceive(PacketReceiveEvent event) {
}
@Override
public void onPacketSend(PacketSendEvent event) {
}
}
@@ -0,0 +1,64 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
/**
* Abstract packet listener.
*
* @author retrooper
* @since 1.8
*/
public abstract class PacketListenerCommon {
private final PacketListenerPriority priority;
public PacketListenerCommon(PacketListenerPriority priority) {
this.priority = priority;
}
public PacketListenerCommon() {
this.priority = PacketListenerPriority.NORMAL;
}
public PacketListenerPriority getPriority() {
return priority;
}
public void onUserConnect(UserConnectEvent event) {
}
public void onUserLogin(UserLoginEvent event) {
}
public void onUserDisconnect(UserDisconnectEvent event) {
}
void onPacketReceive(PacketReceiveEvent event) {
}
void onPacketSend(PacketSendEvent event) {
}
public void onPacketEventExternal(PacketEvent event) {
}
}
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event;
package com.github.retrooper.packetevents.event;
/**
* The priority of packet listeners affect the order they will be invoked in.
@@ -0,0 +1,66 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.*;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketReceiveEvent extends ProtocolPacketEvent<Object> {
protected PacketReceiveEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(PacketSide.CLIENT, channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketReceiveEvent(int packetID, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel, User user, Object player,
Object byteBuf) throws PacketProcessException {
super(packetID, packetType, serverVersion,
channel, user, player, byteBuf);
}
@Override
public void call(PacketListenerCommon listener) {
listener.onPacketReceive(this);
}
@Override
public PacketReceiveEvent clone() {
if (this instanceof PacketHandshakeReceiveEvent) {
return ((PacketHandshakeReceiveEvent)this).clone();
}
else if (this instanceof PacketStatusReceiveEvent) {
return ((PacketStatusReceiveEvent)this).clone();
}
else if (this instanceof PacketLoginReceiveEvent) {
return ((PacketLoginReceiveEvent)this).clone();
}
else if (this instanceof PacketPlayReceiveEvent) {
return ((PacketPlayReceiveEvent)this).clone();
}
else {
return null;
}
}
}
@@ -0,0 +1,66 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.PacketLoginSendEvent;
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
import com.github.retrooper.packetevents.event.simple.PacketStatusSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketSendEvent extends ProtocolPacketEvent<Object> {
protected PacketSendEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(PacketSide.SERVER, channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketSendEvent(int packetID, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel, User user,
Object player, Object byteBuf) throws PacketProcessException {
super(packetID, packetType,
serverVersion,
channel, user, player, byteBuf);
}
@Override
public void call(PacketListenerCommon listener) {
listener.onPacketSend(this);
}
@Override
public PacketSendEvent clone() {
if (this instanceof PacketStatusSendEvent) {
return ((PacketStatusSendEvent)this).clone();
}
else if (this instanceof PacketLoginSendEvent) {
return ((PacketLoginSendEvent)this).clone();
}
else if (this instanceof PacketPlaySendEvent) {
return ((PacketPlaySendEvent)this).clone();
}
else {
return null;
}
}
}
@@ -16,23 +16,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event.eventtypes;
import io.github.retrooper.packetevents.event.impl.PacketPlayReceiveEvent;
import org.bukkit.entity.Player;
package com.github.retrooper.packetevents.event;
/**
* Every event that has an associated player is recommended to implement this interface.
*
* @author retrooper
* @see PacketPlayReceiveEvent
* @since 1.6.9
*/
public interface PlayerEvent {
public interface PlayerEvent<T> {
/**
* Associated player.
*
* @return Player.
*/
Player getPlayer();
T getPlayer();
}
@@ -0,0 +1,209 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.PacketSide;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
public abstract class ProtocolPacketEvent<T> extends PacketEvent implements PlayerEvent<T>, CancellableEvent, UserEvent {
private final Object channel;
private final ConnectionState connectionState;
private final User user;
private final T player;
private Object byteBuf;
private final int packetID;
private final PacketTypeCommon packetType;
private ServerVersion serverVersion;
private boolean cancel;
private PacketWrapper<?> lastUsedWrapper;
private List<Runnable> postTasks = null;
private boolean cloned;
public ProtocolPacketEvent(PacketSide packetSide, Object channel,
User user, T player, Object byteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
this.channel = channel;
this.user = user;
this.player = player;
if (autoProtocolTranslation || user.getClientVersion() == null) {
this.serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
}
else {
//TODO Optimize
this.serverVersion = user.getClientVersion().toServerVersion();
}
this.byteBuf = byteBuf;
int size = ByteBufHelper.readableBytes(byteBuf);
if (size == 0) {
throw new PacketProcessException("Trying to process a packet, but it has no content. (Size=0)");
}
try {
this.packetID = ByteBufHelper.readVarInt(byteBuf);
} catch (Exception e) {
throw new PacketProcessException("Failed to read the Packet ID of a packet. (Size: " + size + ")");
}
ClientVersion version = serverVersion.toClientVersion();
this.packetType = PacketType.getById(packetSide, user.getConnectionState(),
version, packetID);
if (this.packetType == null) {
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
}
this.connectionState = user.getConnectionState();
}
public ProtocolPacketEvent(int packetID, PacketTypeCommon packetType, ServerVersion serverVersion, Object channel,
User user, T player, Object byteBuf) {
this.channel = channel;
this.user = user;
this.player = player;
this.serverVersion = serverVersion;
this.byteBuf = byteBuf;
this.packetID = packetID;
this.packetType = packetType;
this.connectionState = user.getConnectionState();
cloned = true;
}
public boolean isClone() {
return cloned;
}
public Object getChannel() {
return channel;
}
public InetSocketAddress getSocketAddress() {
return (InetSocketAddress) ChannelHelper.remoteAddress(channel);
}
@Override
public User getUser() {
return user;
}
@Override
public T getPlayer() {
return player;
}
public ConnectionState getConnectionState() {
return connectionState;
}
//TODO Possibly put clientversion inside User class and remove here
@Deprecated
public ClientVersion getClientVersion() {
return user.getClientVersion();
}
@Deprecated
public void setClientVersion(@NotNull ClientVersion clientVersion) {
PacketEvents.getAPI().getLogManager().debug("Setting client version with deprecated method " + clientVersion.getReleaseName());
user.setClientVersion(clientVersion);
}
public ServerVersion getServerVersion() {
return serverVersion;
}
public void setServerVersion(@NotNull ServerVersion serverVersion) {
this.serverVersion = serverVersion;
}
public Object getByteBuf() {
return byteBuf;
}
public void setByteBuf(Object byteBuf) {
this.byteBuf = byteBuf;
}
@Deprecated
public int getPacketId() {
return packetID;
}
public PacketTypeCommon getPacketType() {
return packetType;
}
@Deprecated
public String getPacketName() {
return ((Enum<?>) packetType).name();
}
@Override
public boolean isCancelled() {
return this.cancel;
}
@Override
public void setCancelled(boolean val) {
this.cancel = val;
}
@Nullable
public PacketWrapper<?> getLastUsedWrapper() {
return lastUsedWrapper;
}
public void setLastUsedWrapper(@Nullable PacketWrapper<?> lastUsedWrapper) {
this.lastUsedWrapper = lastUsedWrapper;
}
public List<Runnable> getPostTasks() {
if (postTasks == null) {
postTasks = new ArrayList<>();
}
return postTasks;
}
public boolean hasPostTasks() {
return postTasks != null && !postTasks.isEmpty();
}
@Override
public ProtocolPacketEvent<?> clone() {
return this instanceof PacketReceiveEvent ? ((PacketReceiveEvent) this).clone()
: ((PacketSendEvent) this).clone();
}
public void cleanUp() {
if (isClone()) {
ByteBufHelper.release(byteBuf);
}
}
}
@@ -0,0 +1,80 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.event.simple.*;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
public abstract class SimplePacketListenerAbstract extends PacketListenerCommon {
public SimplePacketListenerAbstract(PacketListenerPriority priority) {
super(priority);
}
public SimplePacketListenerAbstract() {
super();
}
@Override
void onPacketReceive(PacketReceiveEvent event) {
if (event instanceof PacketHandshakeReceiveEvent) {
onPacketHandshakeReceive((PacketHandshakeReceiveEvent) event);
} else if (event instanceof PacketStatusReceiveEvent) {
onPacketStatusReceive((PacketStatusReceiveEvent) event);
} else if (event instanceof PacketLoginReceiveEvent) {
onPacketLoginReceive((PacketLoginReceiveEvent) event);
} else if (event instanceof PacketPlayReceiveEvent) {
onPacketPlayReceive((PacketPlayReceiveEvent) event);
}
}
@Override
void onPacketSend(PacketSendEvent event) {
if (event instanceof PacketStatusSendEvent) {
onPacketStatusSend((PacketStatusSendEvent) event);
} else if (event instanceof PacketLoginSendEvent) {
onPacketLoginSend((PacketLoginSendEvent) event);
} else if (event instanceof PacketPlaySendEvent) {
onPacketPlaySend((PacketPlaySendEvent) event);
}
}
public void onPacketHandshakeReceive(PacketHandshakeReceiveEvent event) {
}
public void onPacketStatusReceive(PacketStatusReceiveEvent event) {
}
public void onPacketStatusSend(PacketStatusSendEvent event) {
}
public void onPacketLoginReceive(PacketLoginReceiveEvent event) {
}
public void onPacketLoginSend(PacketLoginSendEvent event) {
}
public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
}
public void onPacketPlaySend(PacketPlaySendEvent event) {
}
}
@@ -16,21 +16,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.event.eventtypes;
package com.github.retrooper.packetevents.event;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import com.github.retrooper.packetevents.protocol.player.User;
import java.net.InetSocketAddress;
public abstract class CancellableNMSPacketEvent extends NMSPacketEvent implements CancellableEvent {
public class UserConnectEvent extends PacketEvent implements CancellableEvent, UserEvent{
private final User user;
private boolean cancelled;
public CancellableNMSPacketEvent(Object channel, NMSPacket packet) {
super(channel, packet);
public UserConnectEvent(User user) {
this.user = user;
}
public CancellableNMSPacketEvent(InetSocketAddress address, NMSPacket packet) {
super(address, packet);
@Override
public User getUser() {
return user;
}
@Override
@@ -39,7 +39,12 @@ public abstract class CancellableNMSPacketEvent extends NMSPacketEvent implement
}
@Override
public void setCancelled(boolean value) {
cancelled = value;
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public void call(PacketListenerCommon listener) {
listener.onUserConnect(this);
}
}
@@ -16,21 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.packetwrappers.play.in.trsel;
package com.github.retrooper.packetevents.event;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import com.github.retrooper.packetevents.protocol.player.User;
public class WrappedPacketInTrSel extends WrappedPacket {
public WrappedPacketInTrSel(NMSPacket packet) {
super(packet);
public class UserDisconnectEvent extends PacketEvent implements UserEvent {
private final User user;
public UserDisconnectEvent(User user) {
this.user = user;
}
public int getSlot() {
return readInt(0);
@Override
public User getUser() {
return user;
}
public void setSlot(int slot) {
writeInt(0, slot);
@Override
public void call(PacketListenerCommon listener) {
listener.onUserDisconnect(this);
}
}
@@ -16,14 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.packetwrappers.api;
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.protocol.player.User;
/**
* Packet-Wrappers that can be sent to clients.
* Event that involves users.
*
* @author retrooper
* //TODO since javadoc annotation
* @since 2.0.0
*/
public interface SendableWrapper {
Object asNMSPacket() throws Exception;
public interface UserEvent {
User getUser();
}
@@ -0,0 +1,46 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event;
import com.github.retrooper.packetevents.protocol.player.User;
public class UserLoginEvent extends PacketEvent implements CallableEvent, UserEvent, PlayerEvent<Object> {
private final User user;
private final Object player;
public UserLoginEvent(User user, Object player) {
this.user = user;
this.player = player;
}
@Override
public User getUser() {
return user;
}
@Override
public Object getPlayer() {
return player;
}
@Override
public void call(PacketListenerCommon listener) {
listener.onUserLogin(this);
}
}
@@ -0,0 +1,58 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketHandshakeReceiveEvent extends PacketReceiveEvent {
public PacketHandshakeReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketHandshakeReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketHandshakeReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketHandshakeReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Handshaking.Client getPacketType() {
return (PacketType.Handshaking.Client) super.getPacketType();
}
}
@@ -0,0 +1,59 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketLoginReceiveEvent extends PacketReceiveEvent {
public PacketLoginReceiveEvent(Object channel, User user, Object player,
Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketLoginReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketLoginReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketLoginReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Login.Client getPacketType() {
return (PacketType.Login.Client) super.getPacketType();
}
}
@@ -0,0 +1,57 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketLoginSendEvent extends PacketSendEvent {
public PacketLoginSendEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketLoginSendEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketLoginSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketLoginSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Login.Server getPacketType() {
return (PacketType.Login.Server) super.getPacketType();
}
}
@@ -0,0 +1,58 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketPlayReceiveEvent extends PacketReceiveEvent {
public PacketPlayReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketPlayReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketPlayReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketPlayReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Play.Client getPacketType() {
return (PacketType.Play.Client) super.getPacketType();
}
}
@@ -0,0 +1,58 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketPlaySendEvent extends PacketSendEvent {
public PacketPlaySendEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketPlaySendEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketPlaySendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketPlaySendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Play.Server getPacketType() {
return (PacketType.Play.Server) super.getPacketType();
}
}
@@ -0,0 +1,58 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketStatusReceiveEvent extends PacketReceiveEvent {
public PacketStatusReceiveEvent(Object channel, User user,
Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketStatusReceiveEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketStatusReceiveEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketStatusReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Status.Client getPacketType() {
return (PacketType.Status.Client) super.getPacketType();
}
}
@@ -0,0 +1,58 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.event.simple;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.exception.PacketProcessException;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
public class PacketStatusSendEvent extends PacketSendEvent {
public PacketStatusSendEvent(Object channel, User user, Object player, Object rawByteBuf,
boolean autoProtocolTranslation) throws PacketProcessException {
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
}
protected PacketStatusSendEvent(int packetId, PacketTypeCommon packetType,
ServerVersion serverVersion,
Object channel,
User user, Object player, Object byteBuf) throws PacketProcessException {
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
}
@Override
public PacketStatusSendEvent clone() {
try {
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
return new PacketStatusSendEvent(getPacketId(), getPacketType(), getServerVersion(),
getChannel(), getUser(), getPlayer(), clonedBuffer);
} catch (PacketProcessException e) {
e.printStackTrace();
}
return null;
}
public PacketType.Status.Server getPacketType() {
return (PacketType.Status.Server) super.getPacketType();
}
}
@@ -16,15 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.netty.channel;
package com.github.retrooper.packetevents.exception;
import io.netty.channel.Channel;
public class PacketProcessException extends Exception {
public PacketProcessException(String msg, Throwable cause) {
super(msg, cause);
}
import java.net.InetSocketAddress;
public PacketProcessException(Throwable cause) {
super(cause);
}
public final class ChannelUtils8 {
public static InetSocketAddress getSocketAddress(Object ch) {
Channel channel = (Channel) ch;
return ((InetSocketAddress) channel.remoteAddress());
public PacketProcessException(String msg) {
super(msg);
}
}
@@ -16,28 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.injector;
package com.github.retrooper.packetevents.injector;
import org.bukkit.entity.Player;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.player.User;
import org.jetbrains.annotations.Nullable;
public interface ChannelInjector {
default boolean isBound() {
default boolean isServerBound() {
return true;
}
void inject();
void eject();
void uninject();
void injectPlayer(Player player);
User getUser(Object channel);
void ejectPlayer(Player player);
void changeConnectionState(Object channel, @Nullable ConnectionState connectionState);
boolean hasInjected(Player player);
void updateUser(Object channel, User user);
void writePacket(Object channel, Object rawNMSPacket);
void setPlayer(Object channel, Object player);
void flushPackets(Object channel);
void sendPacket(Object channel, Object rawNMSPacket);
boolean hasPlayer(Object player);
}
@@ -0,0 +1,137 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.manager;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.wrapper.handshaking.client.WrapperHandshakingClientHandshake;
import com.github.retrooper.packetevents.wrapper.login.server.WrapperLoginServerLoginSuccess;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRespawn;
import java.net.InetSocketAddress;
public class InternalPacketListener extends PacketListenerAbstract {
public InternalPacketListener() {
this(PacketListenerPriority.LOWEST);
}
public InternalPacketListener(PacketListenerPriority priority) {
super(priority);
}
@Override
public void onPacketSend(PacketSendEvent event) {
User user = event.getUser();
if (event.getPacketType() == PacketType.Login.Server.LOGIN_SUCCESS) {
Object channel = event.getChannel();
//Process outgoing login success packet
WrapperLoginServerLoginSuccess loginSuccess = new WrapperLoginServerLoginSuccess(event);
UserProfile profile = loginSuccess.getUserProfile();
//Update user profile
user.getProfile().setUUID(profile.getUUID());
user.getProfile().setName(profile.getName());
//Map username with channel
ProtocolManager.CHANNELS.put(profile.getName(), channel);
PacketEvents.getAPI().getLogManager().debug("Mapped player username with their channel.");
//Update connection state(injectors might do some adjustments when we transition into PLAY state)
//This also updates it for the user instance
event.getPostTasks().add(() -> {
PacketEvents.getAPI().getInjector().changeConnectionState(channel, ConnectionState.PLAY);
PacketEvents.getAPI().getLogManager().debug("Transitioned " + profile.getName() + " into the PLAY state!");
});
}
// Join game can be used to update world height, and sets dimension data
if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
user.setEntityId(joinGame.getEntityId());
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
// Store world height
NBTList<NBTCompound> list = joinGame.getDimensionCodec()
.getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
user.setWorldNBT(list);
// Update world height
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getType().getName()).getCompoundTagOrNull("element");
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
}
// Respawn is used to switch dimensions
if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
if (event.getServerVersion()
.isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
return; // Fixed world height, no tags are sent to the client
}
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getType().getName()).getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
}
}
@Override
public void onPacketReceive(PacketReceiveEvent event) {
User user = event.getUser();
if (event.getPacketType() == PacketType.Handshaking.Client.HANDSHAKE) {
Object channel = event.getChannel();
InetSocketAddress address = event.getSocketAddress();
WrapperHandshakingClientHandshake handshake;
try {
handshake = new WrapperHandshakingClientHandshake(event);
} catch (ArrayIndexOutOfBoundsException exception) {
user.closeConnection();
PacketEvents.getAPI().getLogManager().debug("Disconnected " + address.getHostString() + ":" + address.getPort() + " for sending an invalid handshaking packet. They might be on an outdated client.");
return;
}
ConnectionState nextState = handshake.getNextConnectionState();
ClientVersion clientVersion = handshake.getClientVersion();
//Update client version for this event call(and user)
user.setClientVersion(clientVersion);
PacketEvents.getAPI().getLogManager().debug("Processed " + address.getHostString() + ":" + address.getPort() + "'s client version. Client Version: " + clientVersion.getReleaseName());
event.getPostTasks().add(() -> {
//Transition into the LOGIN OR STATUS connection state
PacketEvents.getAPI().getInjector().changeConnectionState(channel, nextState);
PacketEvents.getAPI().getLogManager().debug("Transitioned " + address.getHostString() + ":" + address.getPort() + " into the " + nextState + " state!");
});
}
}
}
@@ -0,0 +1,136 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.manager.player;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.NotNull;
public interface PlayerManager {
int getPing(@NotNull Object player);
@NotNull ClientVersion getClientVersion(@NotNull Object player);
Object getChannel(@NotNull Object player);
@NotNull User getUser(@NotNull Object player);
default ConnectionState getConnectionState(@NotNull Object player) {
return getUser(player).getConnectionState();
}
default void sendPacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), byteBuf);
}
default void sendPacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), byteBuf);
}
default void sendPacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), wrapper);
}
default void sendPacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), wrapper);
}
default void sendPacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), byteBuf);
}
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), byteBuf);
}
default void sendPacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), wrapper);
}
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), wrapper);
}
default void writePacket(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), byteBuf);
}
default void writePacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), byteBuf);
}
default void writePacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), wrapper);
}
default void writePacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), wrapper);
}
default void writePacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), byteBuf);
}
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), byteBuf);
}
default void writePacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), wrapper);
}
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), wrapper);
}
default void receivePacket(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), byteBuf);
}
default void receivePacketAsync(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), byteBuf);
}
default void receivePacket(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), wrapper);
}
default void receivePacketAsync(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), wrapper);
}
default void receivePacketSilently(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), byteBuf);
}
default void receivePacketSilentlyAsync(Object player, Object byteBuf) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), byteBuf);
}
default void receivePacketSilently(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), wrapper);
}
default void receivePacketSilentlyAsync(Object player, PacketWrapper<?> wrapper) {
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), wrapper);
}
}
@@ -0,0 +1,209 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.manager.protocol;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
import com.github.retrooper.packetevents.protocol.ConnectionState;
import com.github.retrooper.packetevents.protocol.ProtocolVersion;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public interface ProtocolManager {
Map<String, Object> CHANNELS = new ConcurrentHashMap<>();
Map<Object, User> USERS = new ConcurrentHashMap<>();
default Collection<User> getUsers() {
return USERS.values();
}
default Collection<Object> getChannels() {
return CHANNELS.values();
}
//Methods to implement
ProtocolVersion getPlatformVersion();
void sendPacket(Object channel, Object packet);
void sendPacketSilently(Object channel, Object packet);
void writePacket(Object channel, Object packet);
void writePacketSilently(Object channel, Object packet);
void receivePacket(Object channel, Object packet);
void receivePacketSilently(Object channel, Object packet);
ClientVersion getClientVersion(Object channel);
default void sendPacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacket(channel, byteBuf);
});
}
default void sendPacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacketSilently(channel, byteBuf);
});
}
default void writePacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacket(channel, byteBuf);
});
}
default void writePacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacketSilently(channel, byteBuf);
});
}
default void receivePacketAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacket(channel, byteBuf);
});
}
default void receivePacketSilentlyAsync(Object channel, Object byteBuf) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacketSilently(channel, byteBuf);
});
}
//TODO Make it clear that this only updates the connection state in our user.
//Sometimes you should use getInjector().changeConnectionState because that can allow the injector to make adjustments.
//This is very important, especially on Spigot.
//As soon as we switch to the play state on spigot, our injector makes some adjustments.
default void changeConnectionState(Object channel, ConnectionState connectionState) {
getUser(channel).setConnectionState(connectionState);
}
default void setClientVersion(Object channel, ClientVersion version) {
getUser(channel).setClientVersion(version);
}
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
sendPacket(channel, packet.buffer);
}
}
default void sendPacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacket(channel, wrapper);
});
}
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
sendPacketSilently(channel, packet.buffer);
}
}
default void sendPacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
sendPacketSilently(channel, wrapper);
});
}
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
writePacket(channel, packet.buffer);
}
}
default void writePacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacket(channel, wrapper);
});
}
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
writePacketSilently(channel, packet.buffer);
}
}
default void writePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
writePacketSilently(channel, wrapper);
});
}
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
receivePacket(channel, packet.buffer);
}
}
default void receivePacketAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacket(channel, wrapper);
});
}
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
for (PacketWrapper<?> packet : wrappers) {
packet.prepareForSend();
receivePacketSilently(channel, packet.buffer);
}
}
default void receivePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
ChannelHelper.runInEventLoop(channel, () -> {
receivePacketSilently(channel, wrapper);
});
}
default User getUser(Object channel) {
return USERS.get(channel);
}
default void setUser(Object channel, User user) {
USERS.put(channel, user);
PacketEvents.getAPI().getInjector().updateUser(channel, user);
}
default Object getChannel(String username) {
return CHANNELS.get(username);
}
}
@@ -16,15 +16,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.netty.channel;
package com.github.retrooper.packetevents.manager.server;
import net.minecraft.util.io.netty.channel.Channel;
public interface ServerManager {
/**
* Get the server version.
*
* @return Get Server Version
*/
ServerVersion getVersion();
import java.net.InetSocketAddress;
public final class ChannelUtils7 {
public static InetSocketAddress getSocketAddress(Object ch) {
Channel channel = (Channel) ch;
return ((InetSocketAddress) channel.remoteAddress());
/**
* Get the operating system of the local machine
*
* @return Get Operating System
*/
default SystemOS getOS() {
return SystemOS.getOS();
}
}
@@ -16,10 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.server;
package com.github.retrooper.packetevents.manager.server;
import io.github.retrooper.packetevents.PacketEvents;
import org.bukkit.Bukkit;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
/**
* Server Version.
@@ -31,119 +30,97 @@ import org.bukkit.Bukkit;
* @since 1.6.9
*/
public enum ServerVersion {
v_1_7_10((short) 5),
v_1_8((short) 47), v_1_8_3((short) 47), v_1_8_8((short) 47),
v_1_9((short) 107), v_1_9_2((short) 109), v_1_9_4((short) 110),
//TODO Rename to PlatformVersion or LocalVersion or Version?
V_1_7_10(5),
V_1_8(47), V_1_8_3(47), V_1_8_8(47),
V_1_9(107), V_1_9_2(109), V_1_9_4(110),
//1.10 and 1.10.1 are redundant
v_1_10((short) 210), v_1_10_1((short) 210), v_1_10_2((short) 210),
v_1_11((short) 315), v_1_11_2((short) 316),
v_1_12((short) 335), v_1_12_1((short) 338), v_1_12_2((short) 340),
v_1_13((short) 393), v_1_13_1((short) 401), v_1_13_2((short) 404),
v_1_14((short) 477), v_1_14_1((short) 480), v_1_14_2((short) 485), v_1_14_3((short) 490), v_1_14_4((short) 498),
v_1_15((short) 573), v_1_15_1((short) 575), v_1_15_2((short) 578),
v_1_16((short) 735), v_1_16_1((short) 736), v_1_16_2((short) 751), v_1_16_3((short) 753), v_1_16_4((short) 754), v_1_16_5((short) 754),
v_1_17((short) 755), v_1_17_1((short) 756),
ERROR((short) -1);
V_1_10(210), V_1_10_1(210), V_1_10_2(210),
V_1_11(315), V_1_11_2(316),
V_1_12(335), V_1_12_1(338), V_1_12_2(340),
V_1_13(393), V_1_13_1(401), V_1_13_2(404),
V_1_14(477), V_1_14_1(480), V_1_14_2(485), V_1_14_3(490), V_1_14_4(498),
V_1_15(573), V_1_15_1(575), V_1_15_2(578),
V_1_16(735), V_1_16_1(736), V_1_16_2(751), V_1_16_3(753), V_1_16_4(754), V_1_16_5(754),
V_1_17(755), V_1_17_1(756),
V_1_18(757), V_1_18_1(757), V_1_18_2(758),
//TODO UPDATE Add server version constant
ERROR(-1, true);
private static final String NMS_VERSION_SUFFIX = Bukkit.getServer().getClass().getPackage().getName()
.replace(".", ",").split(",")[3];
private static final ServerVersion[] VALUES = values();
public static ServerVersion[] reversedValues = new ServerVersion[VALUES.length];
private static ServerVersion cachedVersion;
private final short protocolVersion;
private static final ServerVersion[] REVERSED_VALUES;
ServerVersion(short protocolId) {
this.protocolVersion = protocolId;
}
private static ServerVersion getVersionNoCache() {
if (reversedValues[0] == null) {
reversedValues = ServerVersion.reverse();
}
if (reversedValues == null) {
throw new IllegalStateException("Failed to reverse the ServerVersion enum constant values.");
}
for (final ServerVersion val : reversedValues) {
String valName = val.name().substring(2).replace("_", ".");
if (Bukkit.getBukkitVersion().contains(valName)) {
return val;
}
}
ServerVersion fallbackVersion = PacketEvents.get().getSettings().getFallbackServerVersion();
if (fallbackVersion != null) {
if (fallbackVersion == ServerVersion.v_1_7_10) {
try {
Class.forName("net.minecraft.util.io.netty.buffer.ByteBuf");
}
catch (Exception ex) {
//We will assume its 1.8.8
fallbackVersion = ServerVersion.v_1_8_8;
}
}
PacketEvents.get().getPlugin().getLogger().warning("[packetevents] Your server software is preventing us from checking the server version. We will assume the server version is " + fallbackVersion.name() + "...");
return fallbackVersion;
}
return ERROR;
}
/**
* Get the server version.
* If PacketEvents has already attempted resolving, return the cached version.
* If PacketEvents hasn't already attempted resolving, it will resolve it, cache it and return the version.
*
* @return Server Version. (possibly cached)
*/
public static ServerVersion getVersion() {
if (cachedVersion == null) {
cachedVersion = getVersionNoCache();
}
return cachedVersion;
}
/**
* The values in this enum in reverse.
*
* @return Reversed server version enum values.
*/
private static ServerVersion[] reverse() {
ServerVersion[] array = values();
static {
REVERSED_VALUES = values();
int i = 0;
int j = array.length - 1;
int j = REVERSED_VALUES.length - 1;
ServerVersion tmp;
while (j > i) {
tmp = array[j];
array[j--] = array[i];
array[i++] = tmp;
tmp = REVERSED_VALUES[j];
REVERSED_VALUES[j--] = REVERSED_VALUES[i];
REVERSED_VALUES[i++] = tmp;
}
return array;
}
public static String getNMSSuffix() {
return NMS_VERSION_SUFFIX;
private final int protocolVersion;
private final String name;
ServerVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
this.name = name().substring(2).replace("_", ".");
}
public static String getNMSDirectory() {
return "net.minecraft.server." + getNMSSuffix();
ServerVersion(int protocolVersion, boolean isNotRelease) {
this.protocolVersion = protocolVersion;
if (isNotRelease) {
this.name = name();
} else {
this.name = name().substring(2).replace("_", ".");
}
}
public static String getOBCDirectory() {
return "org.bukkit.craftbukkit." + (getNMSSuffix());
public static ServerVersion[] reversedValues() {
return REVERSED_VALUES;
}
public static ServerVersion getLatest() {
return reversedValues[0];
return reversedValues()[1];
}
public static ServerVersion getOldest() {
return values()[0];
}
//TODO Optimize
@Deprecated
public static ServerVersion getById(int protocolVersion) {
for (ServerVersion version : values()) {
if (version.protocolVersion == protocolVersion) {
return version;
}
}
return null;
}
public ClientVersion toClientVersion() {
return ClientVersion.getById(this.protocolVersion);
}
/**
* Get the release name of this server version.
* For example, for the V_1_18 enum constant, it would return "1.18".
* @return Release name
*/
public String getReleaseName() {
return name;
}
/**
* Get this server version's protocol version.
*
* @return Protocol version.
*/
public short getProtocolVersion() {
public int getProtocolVersion() {
return protocolVersion;
}
@@ -173,12 +150,11 @@ public enum ServerVersion {
* 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) {
for (ServerVersion version : reversedValues()) {
if (version == target) {
return false;
}
if (version == this) return true;
if (version == target) return false;
}
return false;
@@ -240,52 +216,4 @@ public enum ServerVersion {
public boolean isOlderThanOrEquals(ServerVersion target) {
return this == target || isOlderThan(target);
}
/**
* Deprecated, please use {@link #isNewerThan(ServerVersion)}
*
* @param target Compared version.
* @return Is this server version newer than the compared server version.
* @deprecated Rename...
**/
@Deprecated
public boolean isHigherThan(final ServerVersion target) {
return isNewerThan(target);
}
/**
* Deprecated, Please use {@link #isNewerThanOrEquals(ServerVersion)}
*
* @param target Compared server version.
* @return Is this server version newer than or equal to the compared server version.
* @deprecated Rename...
*/
@Deprecated
public boolean isHigherThanOrEquals(final ServerVersion target) {
return isNewerThanOrEquals(target);
}
/**
* Deprecated... Please use {@link #isOlderThan(ServerVersion)}
*
* @param target Compared server version.
* @return Is this server version older than the compared server version.
* @deprecated Rename....
*/
@Deprecated
public boolean isLowerThan(final ServerVersion target) {
return isOlderThan(target);
}
/**
* Deprecated, please use {@link #isOlderThanOrEquals(ServerVersion)}
*
* @param target Compared server version.
* @return Is this server version older than or equal to the compared server version.
* @deprecated Rename...
*/
@Deprecated
public boolean isLowerThanOrEquals(final ServerVersion target) {
return isOlderThanOrEquals(target);
}
}
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.server;
package com.github.retrooper.packetevents.manager.server;
/**
* System Operating system.
@@ -27,9 +27,7 @@ package io.github.retrooper.packetevents.utils.server;
public enum SystemOS {
WINDOWS, MACOS, LINUX, OTHER;
private static final SystemOS[] VALUES = values();
private static SystemOS value;
private static SystemOS CACHE;
/**
* Get the server's operating system.
@@ -39,7 +37,7 @@ public enum SystemOS {
*/
public static SystemOS getOSNoCache() {
final String os = System.getProperty("os.name").toLowerCase();
for (SystemOS sysos : VALUES) {
for (SystemOS sysos : values()) {
if (os.contains(sysos.name().toLowerCase())) {
return sysos;
}
@@ -54,22 +52,10 @@ public enum SystemOS {
* @return Operating System.
*/
public static SystemOS getOS() {
if (value == null) {
value = getOSNoCache();
if (CACHE == null) {
CACHE = getOSNoCache();
}
return value;
}
/**
* Get the server's operating system.
* This method will CACHE for you.
*
* @return Operating System.
* @deprecated Use {@link #getOS()}, method renamed.
*/
@Deprecated
public static SystemOS getOperatingSystem() {
return getOS();
return CACHE;
}
}
@@ -0,0 +1,31 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty;
import com.github.retrooper.packetevents.netty.buffer.ByteBufAllocationOperator;
import com.github.retrooper.packetevents.netty.buffer.ByteBufOperator;
import com.github.retrooper.packetevents.netty.channel.ChannelOperator;
public interface NettyManager {
ChannelOperator getChannelOperator();
ByteBufOperator getByteBufOperator();
ByteBufAllocationOperator getByteBufAllocationOperator();
}
@@ -16,12 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.immutableset;
package com.github.retrooper.packetevents.netty.buffer;
abstract class ImmutableSetAbstract<T> {
public abstract boolean contains(T element);
public interface ByteBufAllocationOperator {
Object wrappedBuffer(byte[] bytes);
public abstract void add(T element);
Object copiedBuffer(byte[] bytes);
public abstract void addAll(T... element);
Object buffer();
Object directBuffer();
Object compositeBuffer();
}
@@ -0,0 +1,257 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import com.github.retrooper.packetevents.PacketEvents;
import java.nio.charset.Charset;
public class ByteBufHelper {
public static int readerIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer);
}
public static Object readerIndex(Object buffer, int readerIndex) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer, readerIndex);
}
public static int writerIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writerIndex(buffer);
}
public static Object writerIndex(Object buffer, int writerIndex) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writerIndex(buffer, writerIndex);
}
public static int readableBytes(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readableBytes(buffer);
}
public static int writableBytes(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writableBytes(buffer);
}
public static Object clear(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().clear(buffer);
}
public static String toString(Object buffer, int index, int length, Charset charset) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().toString(buffer, index, length, charset);
}
public static byte readByte(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readByte(buffer);
}
public static void writeByte(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeByte(buffer, value);
}
public static boolean readBoolean(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBoolean(buffer);
}
public static void writeBoolean(Object buffer, boolean value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBoolean(buffer, value);
}
public static short readUnsignedByte(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedByte(buffer);
}
public static char readChar(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readChar(buffer);
}
public static void writeChar(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeChar(buffer, value);
}
public static short readShort(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readShort(buffer);
}
public static int readUnsignedShort(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedShort(buffer);
}
public static void writeShort(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeShort(buffer, value);
}
public static int readInt(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readInt(buffer);
}
public static void writeInt(Object buffer, int value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeInt(buffer, value);
}
public static long readUnsignedInt(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedInt(buffer);
}
public static long readLong(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readLong(buffer);
}
public static void writeLong(Object buffer, long value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeLong(buffer, value);
}
public static float readFloat(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readFloat(buffer);
}
public static void writeFloat(Object buffer, float value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeFloat(buffer, value);
}
public static double readDouble(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readDouble(buffer);
}
public static void writeDouble(Object buffer, double value) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeDouble(buffer, value);
}
public static Object getBytes(Object buffer, int index, byte[] destination) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().getBytes(buffer, index, destination);
}
public static short getUnsignedByte(Object buffer, int index) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().getUnsignedByte(buffer, index);
}
public static boolean isReadable(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().isReadable(buffer);
}
public static Object copy(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().copy(buffer);
}
public static Object duplicate(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().duplicate(buffer);
}
public static boolean hasArray(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().hasArray(buffer);
}
public static byte[] array(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().array(buffer);
}
public static Object retain(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().retain(buffer);
}
public static Object retainedDuplicate(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().retainedDuplicate(buffer);
}
public static Object readSlice(Object buffer, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readSlice(buffer, length);
}
public static Object readBytes(Object buffer, byte[] destination, int destinationIndex, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, destination, destinationIndex, length);
}
public static Object readBytes(Object buffer, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, length);
}
public static Object writeBytes(Object buffer, Object src) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, src);
}
public static void readBytes(Object buffer, byte[] bytes) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, bytes);
}
public static void writeBytes(Object buffer, byte[] bytes) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, bytes);
}
public static void writeBytes(Object buffer, byte[] bytes, int offset, int length) {
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, bytes, offset, length);
}
public static boolean release(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().release(buffer);
}
public static int refCnt(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().refCnt(buffer);
}
public static Object skipBytes(Object buffer, int length) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().skipBytes(buffer, length);
}
public static Object markReaderIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().markReaderIndex(buffer);
}
public static Object resetReaderIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetReaderIndex(buffer);
}
public static Object markWriterIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().markWriterIndex(buffer);
}
public static Object resetWriterIndex(Object buffer) {
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetWriterIndex(buffer);
}
public static int readVarInt(Object buffer) {
int value = 0;
int length = 0;
byte currentByte;
do {
currentByte = readByte(buffer);
value |= (currentByte & 0x7F) << (length * 7);
length++;
if (length > 5) {
throw new RuntimeException("VarInt is too large. Must be smaller than 5 bytes.");
}
} while ((currentByte & 0x80) == 0x80);
return value;
}
public static void writeVarInt(Object buffer, int value) {
while (true) {
if ((value & ~0x7F) == 0) {
writeByte(buffer, value);
return;
}
writeByte(buffer, (value & 0x7F) | 0x80);
value >>>= 7;
}
}
public static byte[] copyBytes(Object buffer) {
byte[] bytes = new byte[readableBytes(buffer)];
getBytes(buffer, readerIndex(buffer), bytes);
return bytes;
}
}
@@ -0,0 +1,232 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import java.io.*;
//TODO give netty credit
public class ByteBufInputStream extends InputStream implements DataInput {
private final Object buffer;
private final int startIndex;
private final int endIndex;
private final boolean releaseOnClose;
private final StringBuilder lineBuf;
private boolean closed;
public ByteBufInputStream(Object buffer) {
this(buffer, ByteBufHelper.readableBytes(buffer));
}
public ByteBufInputStream(Object buffer, int length) {
this(buffer, length, false);
}
public ByteBufInputStream(Object buffer, boolean releaseOnClose) {
this(buffer, ByteBufHelper.readableBytes(buffer), releaseOnClose);
}
public ByteBufInputStream(Object buffer, int length, boolean releaseOnClose) {
this.lineBuf = new StringBuilder();
if (buffer == null) {
throw new NullPointerException("buffer");
} else if (length < 0) {
if (releaseOnClose) {
ByteBufHelper.release(buffer);
}
throw new IllegalArgumentException("length: " + length);
} else if (length > ByteBufHelper.readableBytes(buffer)) {
if (releaseOnClose) {
ByteBufHelper.release(buffer);
}
throw new IndexOutOfBoundsException("Too many bytes to be read - Needs " + length + ", maximum is " + ByteBufHelper.readableBytes(buffer));
} else {
this.releaseOnClose = releaseOnClose;
this.buffer = buffer;
this.startIndex = ByteBufHelper.readerIndex(buffer);
this.endIndex = this.startIndex + length;
ByteBufHelper.markReaderIndex(buffer);
}
}
public int readBytes() {
return ByteBufHelper.readerIndex(buffer) - this.startIndex;
}
public void close() throws IOException {
try {
super.close();
} finally {
if (this.releaseOnClose && !this.closed) {
this.closed = true;
ByteBufHelper.release(buffer);
}
}
}
public int available() throws IOException {
return this.endIndex - ByteBufHelper.readerIndex(buffer);
}
public void mark(int readlimit) {
ByteBufHelper.markReaderIndex(buffer);
}
public boolean markSupported() {
return true;
}
public int read() throws IOException {
return !(ByteBufHelper.isReadable(buffer)) ? -1 : ByteBufHelper.readByte(buffer) & 255;
}
public int read(byte[] b, int off, int len) throws IOException {
int available = this.available();
if (available == 0) {
return -1;
} else {
len = Math.min(available, len);
ByteBufHelper.readBytes(buffer, b, off, len);
return len;
}
}
public void reset() throws IOException {
ByteBufHelper.resetReaderIndex(buffer);
}
public long skip(long n) throws IOException {
return n > 2147483647L ? (long) this.skipBytes(2147483647) : (long) this.skipBytes((int) n);
}
public boolean readBoolean() throws IOException {
this.checkAvailable(1);
return this.read() != 0;
}
public byte[] readBytes(int len) {
byte[] bytes = new byte[len];
ByteBufHelper.readBytes(buffer, bytes);
return bytes;
}
public byte readByte() throws IOException {
if (!(ByteBufHelper.isReadable(buffer))) {
throw new EOFException();
} else {
return ByteBufHelper.readByte(buffer);
}
}
public char readChar() throws IOException {
return (char) this.readShort();
}
public double readDouble() throws IOException {
return Double.longBitsToDouble(this.readLong());
}
public float readFloat() throws IOException {
return Float.intBitsToFloat(this.readInt());
}
public void readFully(byte[] b) throws IOException {
this.readFully(b, 0, b.length);
}
public void readFully(byte[] b, int off, int len) throws IOException {
this.checkAvailable(len);
ByteBufHelper.readBytes(buffer, b, off, len);
}
public int readInt() throws IOException {
this.checkAvailable(4);
return ByteBufHelper.readInt(buffer);
}
public String readLine() throws IOException {
this.lineBuf.setLength(0);
while (ByteBufHelper.isReadable(buffer)) {
int c = ByteBufHelper.readUnsignedByte(buffer);
switch (c) {
case 13:
if (ByteBufHelper.isReadable(buffer)
&& (char) ByteBufHelper.getUnsignedByte(buffer, ByteBufHelper.readerIndex(buffer)) == '\n') {
ByteBufHelper.skipBytes(buffer, 1);
}
case 10:
return this.lineBuf.toString();
default:
this.lineBuf.append((char) c);
}
}
return this.lineBuf.length() > 0 ? this.lineBuf.toString() : null;
}
public long readLong() throws IOException {
this.checkAvailable(8);
return ByteBufHelper.readLong(buffer);
}
public long[] readLongs(int size) throws IOException {
long[] array = new long[size];
for (int i = 0; i < array.length; i++) {
array[i] = readLong();
}
return array;
}
public short readShort() throws IOException {
this.checkAvailable(2);
return ByteBufHelper.readShort(buffer);
}
public String readUTF() throws IOException {
return DataInputStream.readUTF(this);
}
public int readUnsignedByte() throws IOException {
return this.readByte() & 255;
}
public int readUnsignedShort() throws IOException {
return this.readShort() & '\uffff';
}
public int skipBytes(int n) throws IOException {
int nBytes = Math.min(this.available(), n);
ByteBufHelper.skipBytes(buffer, nBytes);
return nBytes;
}
private void checkAvailable(int fieldSize) throws IOException {
if (fieldSize < 0) {
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
} else if (fieldSize > this.available()) {
throw new EOFException("fieldSize is too long! Length is " + fieldSize + ", but maximum is " + this.available());
}
}
}
@@ -0,0 +1,114 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import java.nio.charset.Charset;
public interface ByteBufOperator {
int readerIndex(Object buffer);
Object readerIndex(Object buffer, int readerIndex);
int writerIndex(Object buffer);
Object writerIndex(Object buffer, int writerIndex);
int readableBytes(Object buffer);
int writableBytes(Object buffer);
Object clear(Object buffer);
byte readByte(Object buffer);
short readShort(Object buffer);
int readInt(Object buffer);
long readUnsignedInt(Object buffer);
long readLong(Object buffer);
void writeByte(Object buffer, int value);
void writeShort(Object buffer, int value);
void writeInt(Object buffer, int value);
void writeLong(Object buffer, long value);
Object getBytes(Object buffer, int index, byte[] destination);
short getUnsignedByte(Object buffer, int index);
boolean isReadable(Object buffer);
Object copy(Object buffer);
Object duplicate(Object buffer);
boolean hasArray(Object buffer);
byte[] array(Object buffer);
Object retain(Object buffer);
Object retainedDuplicate(Object buffer);
Object readSlice(Object buffer, int length);
Object readBytes(Object buffer, byte[] destination, int destinationIndex, int length);
Object readBytes(Object buffer, int length);
void readBytes(Object buffer, byte[] bytes);
Object writeBytes(Object buffer, Object src);
Object writeBytes(Object buffer, byte[] bytes);
Object writeBytes(Object buffer, byte[] bytes, int offset, int length);
boolean release(Object buffer);
int refCnt(Object buffer);
Object skipBytes(Object buffer, int length);
String toString(Object buffer, int index, int length, Charset charset);
Object markReaderIndex(Object buffer);
Object resetReaderIndex(Object buffer);
Object markWriterIndex(Object buffer);
Object resetWriterIndex(Object buffer);
default float readFloat(Object buffer) {
return Float.intBitsToFloat(readInt(buffer));
}
default void writeFloat(Object buffer, float value) {
writeInt(buffer, Float.floatToIntBits(value));
}
default double readDouble(Object buffer) {
return Double.longBitsToDouble(readLong(buffer));
}
default void writeDouble(Object buffer, double value) {
writeLong(buffer, Double.doubleToLongBits(value));
}
default char readChar(Object buffer) {
return (char) readShort(buffer);
}
default void writeChar(Object buffer, int value) {
writeShort(buffer, value);
}
//Use writeShort to write
default int readUnsignedShort(Object buffer) {
return readShort(buffer) & '\uffff';
}
//Use writeByte to write
default short readUnsignedByte(Object buffer) {
return (short) (this.readByte(buffer) & 255);
}
default boolean readBoolean(Object buffer) {
return readByte(buffer) != 0;
}
default void writeBoolean(Object buffer, boolean value) {
writeByte(buffer, value ? 1 : 0);
}
}
@@ -0,0 +1,114 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//TODO Give netty credit
package com.github.retrooper.packetevents.netty.buffer;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class ByteBufOutputStream extends OutputStream implements DataOutput {
private final Object buffer;
private final int startIndex;
private final DataOutputStream utf8out = new DataOutputStream(this);
public ByteBufOutputStream(Object buffer) {
if (buffer == null) {
throw new NullPointerException("buffer");
} else {
this.buffer = buffer;
this.startIndex = ByteBufHelper.writerIndex(buffer);
}
}
public int writtenBytes() {
return ByteBufHelper.writerIndex(buffer) - this.startIndex;
}
public void write(byte[] b, int off, int len) throws IOException {
if (len != 0) {
ByteBufHelper.writeBytes(buffer, b, off, len);
}
}
public void write(byte[] b) throws IOException {
ByteBufHelper.writeBytes(buffer, b);
}
public void write(int b) throws IOException {
ByteBufHelper.writeByte(buffer, b);
}
public void writeBoolean(boolean v) throws IOException {
ByteBufHelper.writeBoolean(buffer, v);
}
public void writeByte(int v) throws IOException {
ByteBufHelper.writeByte(buffer, v);
}
@Deprecated
public void writeBytes(String s) throws IOException {
throw new IllegalStateException("This operation is not supported!");
}
public void writeChar(int v) throws IOException {
ByteBufHelper.writeChar(buffer, v);
}
public void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0; i < len; ++i) {
ByteBufHelper.writeChar(buffer, s.charAt(i));
}
}
public void writeDouble(double v) throws IOException {
ByteBufHelper.writeDouble(buffer, v);
}
public void writeFloat(float v) throws IOException {
ByteBufHelper.writeFloat(buffer, v);
}
public void writeInt(int v) throws IOException {
ByteBufHelper.writeInt(buffer, v);
}
public void writeLong(long v) throws IOException {
ByteBufHelper.writeLong(buffer, v);
}
public void writeShort(int v) throws IOException {
ByteBufHelper.writeShort(buffer, v);
}
public void writeUTF(String s) throws IOException {
this.utf8out.writeUTF(s);
}
public Object buffer() {
return this.buffer;
}
}
@@ -0,0 +1,43 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.buffer;
import com.github.retrooper.packetevents.PacketEvents;
public class UnpooledByteBufAllocationHelper {
public static Object wrappedBuffer(byte[] bytes) {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().wrappedBuffer(bytes);
}
public static Object copiedBuffer(byte[] bytes) {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().copiedBuffer(bytes);
}
public static Object buffer() {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().buffer();
}
public static Object directBuffer() {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().directBuffer();
}
public static Object compositeBuffer() {
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().compositeBuffer();
}
}
@@ -0,0 +1,95 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.channel;
import com.github.retrooper.packetevents.PacketEvents;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.List;
public class ChannelHelper {
public static SocketAddress remoteAddress(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().remoteAddress(channel);
}
public static SocketAddress localAddress(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().localAddress(channel);
}
public static boolean isOpen(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().isOpen(channel);
}
public static Object close(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().close(channel);
}
public static Object write(Object channel, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().write(channel, buffer);
}
public static Object flush(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().flush(channel);
}
public static Object writeAndFlush(Object channel, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeAndFlush(channel, buffer);
}
public static Object fireChannelRead(Object channel, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().fireChannelRead(channel, buffer);
}
public static Object writeInContext(Object channel, String ctx, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeInContext(channel, ctx, buffer);
}
public static Object flushInContext(Object channel, String ctx) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().flushInContext(channel, ctx);
}
public static Object writeAndFlushInContext(Object channel, String ctx, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeAndFlushInContext(channel, ctx, buffer);
}
public static Object fireChannelReadInContext(Object channel, String ctx, Object buffer) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().fireChannelReadInContext(channel, ctx, buffer);
}
public static List<String> pipelineHandlerNames(Object channel) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().pipelineHandlerNames(channel);
}
public static String pipelineHandlerNamesAsString(Object channel) {
return Arrays.toString(pipelineHandlerNames(channel).toArray(new String[0]));
}
public static Object getPipelineHandler(Object channel, String name) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineHandler(channel, name);
}
public static Object getPipelineContext(Object channel, String handlerName) {
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineContext(channel, handlerName);
}
public static void runInEventLoop(Object channel, Runnable runnable) {
PacketEvents.getAPI().getNettyManager().getChannelOperator().runInEventLoop(channel, runnable);
}
}
@@ -0,0 +1,45 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.netty.channel;
import java.net.SocketAddress;
import java.util.List;
import java.util.Set;
public interface ChannelOperator {
Set<Class<? extends Throwable>> getIgnoredHandlerExceptions();
SocketAddress remoteAddress(Object channel);
SocketAddress localAddress(Object channel);
boolean isOpen(Object channel);
Object close(Object channel);
Object write(Object channel, Object buffer);
Object flush(Object channel);
Object writeAndFlush(Object channel, Object buffer);
Object fireChannelRead(Object channel, Object buffer);
Object writeInContext(Object channel, String ctx, Object buffer);
Object flushInContext(Object channel, String ctx);
Object writeAndFlushInContext(Object channel, String ctx, Object buffer);
Object fireChannelReadInContext(Object channel, String ctx, Object buffer);
List<String> pipelineHandlerNames(Object channel);
Object getPipelineHandler(Object channel, String name);
Object getPipelineContext(Object channel, String name);
void runInEventLoop(Object channel, Runnable runnable);
}
@@ -16,17 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.player;
//TODO Remove this enum, use Bukkit's GameMode enum everywhere.
package com.github.retrooper.packetevents.protocol;
/**
* Representation of a player's game mode.
*
* @author retrooper
* @since 1.8
*/
public enum GameMode {
SURVIVAL,
CREATIVE,
ADVENTURE,
SPECTATOR
public enum ConnectionState {
HANDSHAKING, STATUS, LOGIN, PLAY;
public static ConnectionState getById(int id) {
return values()[id];
}
}
@@ -0,0 +1,32 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol;
public enum PacketSide {
CLIENT, SERVER;
public PacketSide getOpposite() {
if (this == CLIENT) {
return SERVER;
}
else {
return CLIENT;
}
}
}
@@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.injector;
public interface LateInjector extends ChannelInjector {
package com.github.retrooper.packetevents.protocol;
//TODO
public enum ProtocolVersion {
UNKNOWN
}
@@ -0,0 +1,33 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.chat;
public enum ChatPosition {
CHAT,
SYSTEM,
GAME_INFO;
public int getId() {
return ordinal();
}
public static ChatPosition getById(int id) {
return values()[id];
}
}
@@ -16,30 +16,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.player;
package com.github.retrooper.packetevents.protocol.entity.data;
public class Skin {
private String value;
private String signature;
public class EntityData {
private int index;
private EntityDataType<?> type;
private Object value;
public Skin(String value, String signature) {
public EntityData(int index, EntityDataType<?> type, Object value) {
this.index = index;
this.type = type;
this.value = value;
this.signature = signature;
}
public String getValue() {
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public EntityDataType<?> getType() {
return type;
}
public void setType(EntityDataType<?> type) {
this.type = type;
}
public Object getValue() {
return value;
}
public void setValue(String value) {
public void setValue(Object value) {
this.value = value;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
}
}
@@ -0,0 +1,56 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class EntityDataType<T> {
private final String name;
private final int[] ids;
private final Function<PacketWrapper<?>, T> dataDeserializer;
private final BiConsumer<PacketWrapper<?>, Object> dataSerializer;
public EntityDataType(String name, int[] ids, Function<PacketWrapper<?>, T> dataDeserializer, BiConsumer<PacketWrapper<?>, Object> dataSerializer) {
this.name = name;
this.ids = ids;
this.dataDeserializer = dataDeserializer;
this.dataSerializer = dataSerializer;
}
public String getName() {
return name;
}
public int getId(ClientVersion version) {
int index = EntityDataTypes.TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
public Function<PacketWrapper<?>, T> getDataDeserializer() {
return dataDeserializer;
}
public BiConsumer<PacketWrapper<?>, Object> getDataSerializer() {
return dataSerializer;
}
}
@@ -0,0 +1,276 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.util.*;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.google.gson.JsonObject;
import net.kyori.adventure.text.Component;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class EntityDataTypes {
//1.7 -> 1.18 block_position is just 3 ints, not serialized with a long
//short was removed in 1.9+
//boolean was added in 1.9
//nbt was added in 1.12
private static final Map<String, EntityDataType<?>> ENTITY_DATA_TYPE_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, EntityDataType<?>>> ENTITY_DATA_TYPE_ID_MAP = new HashMap<>();
protected static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_data_type_mappings",
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_11,
ClientVersion.V_1_13, //Fix? Why did we not acknoledge 1.13
ClientVersion.V_1_16);
public static final EntityDataType<Byte> BYTE = define("byte", PacketWrapper::readByte, PacketWrapper::writeByte);
public static final EntityDataType<Integer> INT = define("int", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Float> FLOAT = define("float", PacketWrapper::readFloat, PacketWrapper::writeFloat);
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
public static final EntityDataType<Component> COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
public static final EntityDataType<Optional<Component>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
public static final EntityDataType<ItemStack> ITEMSTACK = define("itemstack", PacketWrapper::readItemStack, PacketWrapper::writeItemStack);
public static final EntityDataType<Optional<Object>> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
public static final EntityDataType<Boolean> BOOLEAN = define("boolean", PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
public static final EntityDataType<Integer> PARTICLE = define("particle", PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
public static final EntityDataType<Vector3f> ROTATION = define("rotation",
(PacketWrapper<?> wrapper) -> new Vector3f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
(PacketWrapper<?> wrapper, Vector3f value) -> {
wrapper.writeFloat(value.x);
wrapper.writeFloat(value.y);
wrapper.writeFloat(value.z);
});
public static final EntityDataType<Vector3i> BLOCK_POSITION = define("block_position", readBlockPositionDeserializer(), writeBlockPositionSerializer());
public static final EntityDataType<Optional<Vector3i>> OPTIONAL_BLOCK_POSITION = define("optional_block_position", readOptionalBlockPositionDeserializer(), writeOptionalBlockPositionSerializer());
public static final EntityDataType<BlockFace> BLOCK_FACE = define("block_face", (PacketWrapper<?> wrapper) -> {
int id = wrapper.readVarInt();
return BlockFace.getBlockFaceByValue(id);
},
(PacketWrapper<?> wrapper, BlockFace value) -> wrapper.writeVarInt(value.getFaceValue()));
public static final EntityDataType<Optional<UUID>> OPTIONAL_UUID = define("optional_uuid", (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return Optional.of(wrapper.readUUID());
} else {
return Optional.empty();
}
},
(PacketWrapper<?> wrapper, Optional<UUID> value) -> {
if (value.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeUUID(value.get());
} else {
wrapper.writeBoolean(false);
}
});
public static final EntityDataType<NBTCompound> NBT = define("nbt", PacketWrapper::readNBT, PacketWrapper::writeNBT);
public static final EntityDataType<VillagerData> VILLAGER_DATA = define("villager_data", PacketWrapper::readVillagerData, PacketWrapper::writeVillagerData);
public static final EntityDataType<Optional<Integer>> OPTIONAL_INT = define("optional_int", (PacketWrapper<?> wrapper) -> {
int i = wrapper.readVarInt();
return i == 0 ? Optional.empty() : Optional.of(i - 1);
}, (PacketWrapper<?> wrapper, Optional<Integer> value) -> {
wrapper.writeVarInt(value.orElse(-1) + 1);
});
public static final EntityDataType<EntityPose> ENTITY_POSE = define("entity_pose", (PacketWrapper<?> wrapper) -> {
int id = wrapper.readVarInt();
return EntityPose.getById(wrapper.getServerVersion().toClientVersion(), id);
}, (PacketWrapper<?> wrapper, EntityPose value) -> wrapper.writeVarInt(value.getId(wrapper.getServerVersion().toClientVersion())));
@Deprecated
public static final EntityDataType<Short> SHORT = define("short", PacketWrapper::readShort, PacketWrapper::writeShort);
public static EntityDataType<?> getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte)index);
return typeIdMap.get(id);
}
public static EntityDataType<?> getByName(String name) {
return ENTITY_DATA_TYPE_MAP.get(name);
}
public static <T> EntityDataType<T> define(String name, Function<PacketWrapper<?>, T> deserializer, BiConsumer<PacketWrapper<?>, T> serializer) {
TypesBuilderData data = TYPES_BUILDER.define(name);
EntityDataType<T> type = new EntityDataType<>(name, data.getData(), deserializer,
(BiConsumer<PacketWrapper<?>, Object>) serializer);
ENTITY_DATA_TYPE_MAP.put(type.getName(), type);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
if (index == -1) continue;
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP
.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(type.getId(version), type);
}
return type;
}
private static <T> Function<PacketWrapper<?>, T> readIntDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> (T) ((Object) wrapper.readVarInt());
} else {
return (PacketWrapper<?> wrapper) -> (T) ((Object) wrapper.readInt());
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeIntSerializer() {
return (PacketWrapper<?> wrapper, T value) -> {
int output = 0;
if (value instanceof Byte) {
output = ((Byte) value).intValue();
} else if (value instanceof Short) {
output = ((Short) value).intValue();
} else if (value instanceof Integer) {
output = (Integer) value;
} else if (value instanceof Long) {
output = ((Long) value).intValue();
}
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
wrapper.writeVarInt(output);
} else {
wrapper.writeInt(output);
}
};
}
private static <T> Function<PacketWrapper<?>, T> readOptionalComponentDeserializer() {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return (T) Optional.of(wrapper.readComponent());
} else {
return (T) Optional.empty();
}
};
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeOptionalComponentSerializer() {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<Component> optional = (Optional<Component>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeComponent(optional.get());
} else {
wrapper.writeBoolean(false);
}
} else {
wrapper.writeBoolean(false);
}
};
}
private static <T> Function<PacketWrapper<?>, T> readBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> (T) wrapper.readBlockPosition();
} else {
return (PacketWrapper<?> wrapper) -> {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return (T) new Vector3i(x, y, z);
};
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeBlockPositionSerializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper, T value) -> {
wrapper.writeBlockPosition((Vector3i) value);
};
} else {
return (PacketWrapper<?> wrapper, T value) -> {
Vector3i position = (Vector3i) value;
wrapper.writeInt(position.getX());
wrapper.writeInt(position.getY());
wrapper.writeInt(position.getZ());
};
}
}
private static <T> Function<PacketWrapper<?>, T> readOptionalBlockPositionDeserializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
return (T) Optional.of(wrapper.readBlockPosition());
} else {
return (T) Optional.empty();
}
};
} else {
return (PacketWrapper<?> wrapper) -> {
if (wrapper.readBoolean()) {
int x = wrapper.readInt();
int y = wrapper.readInt();
int z = wrapper.readInt();
return (T) Optional.of(new Vector3i(x, y, z));
} else {
return (T) Optional.empty();
}
};
}
}
private static <T> BiConsumer<PacketWrapper<?>, T> writeOptionalBlockPositionSerializer() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<?> optional = (Optional<?>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
wrapper.writeBlockPosition((Vector3i) optional.get());
} else {
wrapper.writeBoolean(false);
}
} else {
wrapper.writeBoolean(false);
}
};
} else {
return (PacketWrapper<?> wrapper, T value) -> {
if (value instanceof Optional) {
Optional<?> optional = (Optional<?>) value;
if (optional.isPresent()) {
wrapper.writeBoolean(true);
Vector3i position = (Vector3i) optional.get();
wrapper.writeInt(position.getX());
wrapper.writeInt(position.getY());
wrapper.writeInt(position.getZ());
} else {
wrapper.writeBoolean(false);
}
} else {
wrapper.writeBoolean(false);
}
};
}
}
}
@@ -0,0 +1,28 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import java.util.List;
public interface DataProvider {
List<EntityData> encode();
void decode(List<EntityData> data);
}
@@ -0,0 +1,343 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class EntityDataProvider implements DataProvider {
@Nullable
private Component customName;
private boolean customNameVisible;
private EntityPose pose = EntityPose.STANDING;
private int airTicks;
private int ticksFrozenInPowderedSnow = 0;
private boolean onFire;
private boolean crouching;
//Now unused
private boolean riding;
private boolean sprinting;
private boolean swimming;
private boolean invisible;
private boolean glowing;
private boolean flyingWithElytra;
private boolean silent;
private boolean hasGravity = true;
@Nullable
public Component getCustomName() {
return customName;
}
public void setCustomName(@Nullable Component customName) {
this.customName = customName;
}
public boolean isCustomNameVisible() {
return customNameVisible;
}
public void setCustomNameVisible(boolean customNameVisible) {
this.customNameVisible = customNameVisible;
}
public EntityPose getPose() {
return pose;
}
public void setPose(EntityPose pose) {
this.pose = pose;
}
public int getAirTicks() {
return airTicks;
}
public void setAirTicks(int airTicks) {
this.airTicks = airTicks;
}
public int getTicksFrozenInPowderedSnow() {
return ticksFrozenInPowderedSnow;
}
public void setTicksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
this.ticksFrozenInPowderedSnow = ticksFrozenInPowderedSnow;
}
public boolean isOnFire() {
return onFire;
}
public void setOnFire(boolean onFire) {
this.onFire = onFire;
}
public boolean isCrouching() {
return crouching;
}
public void setCrouching(boolean crouching) {
this.crouching = crouching;
}
public boolean isRiding() {
return riding;
}
public void setRiding(boolean riding) {
this.riding = riding;
}
public boolean isSprinting() {
return sprinting;
}
public void setSprinting(boolean sprinting) {
this.sprinting = sprinting;
}
public boolean isSwimming() {
return swimming;
}
public void setSwimming(boolean swimming) {
this.swimming = swimming;
}
public boolean isInvisible() {
return invisible;
}
public void setInvisible(boolean invisible) {
this.invisible = invisible;
}
public boolean isGlowing() {
return glowing;
}
public void setGlowing(boolean glowing) {
this.glowing = glowing;
}
public boolean isFlyingWithElytra() {
return flyingWithElytra;
}
public void setFlyingWithElytra(boolean flyingWithElytra) {
this.flyingWithElytra = flyingWithElytra;
}
public boolean isSilent() {
return silent;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isHasGravity() {
return hasGravity;
}
public void setHasGravity(boolean hasGravity) {
this.hasGravity = hasGravity;
}
@Override
public List<EntityData> encode() {
byte mask = 0x00;
if (onFire) {
mask |= 0x01;
}
if (crouching) {
mask |= 0x02;
}
//TODO Rethink, should we add this?
if (riding) {
mask |= 0x04;
}
if (sprinting) {
mask |= 0x08;
}
if (swimming) {
mask |= 0x10;
}
if (invisible) {
mask |= 0x20;
}
if (glowing) {
mask |= 0x40;
}
if (flyingWithElytra) {
mask |= 0x80;
}
List<EntityData> metadata = new ArrayList<>(8);
metadata.add(new EntityData(0, EntityDataTypes.BYTE, mask));
metadata.add(new EntityData(1, EntityDataTypes.INT, airTicks));
metadata.add(new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.ofNullable(customName)));
metadata.add(new EntityData(3, EntityDataTypes.BOOLEAN, customNameVisible));
metadata.add(new EntityData(4, EntityDataTypes.BOOLEAN, silent));
metadata.add(new EntityData(5, EntityDataTypes.BOOLEAN, !hasGravity));
metadata.add(new EntityData(6, EntityDataTypes.ENTITY_POSE, pose));
metadata.add(new EntityData(7, EntityDataTypes.INT, ticksFrozenInPowderedSnow));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 0:
byte mask = (byte) entityData.getValue();
onFire = (mask & 0x01) != 0;
crouching = (mask & 0x02) != 0;
riding = (mask & 0x04) != 0;
sprinting = (mask & 0x08) != 0;
swimming = (mask & 0x10) != 0;
invisible = (mask & 0x20) != 0;
glowing = (mask & 0x40) != 0;
flyingWithElytra = (mask & 0x80) != 0;
break;
case 1:
airTicks = (int) entityData.getValue();
break;
case 2:
customName = ((Optional<Component>) entityData.getValue()).orElse(null);
break;
case 3:
customNameVisible = (boolean) entityData.getValue();
break;
case 4:
silent = (boolean) entityData.getValue();
break;
case 5:
hasGravity = !(boolean) entityData.getValue();
break;
case 6:
pose = (EntityPose) entityData.getValue();
break;
case 7:
ticksFrozenInPowderedSnow = (int) entityData.getValue();
break;
}
}
}
public static EntityBuilder<EntityBuilder> builderEntity() {
return new EntityBuilder<>(new EntityDataProvider());
}
public static class EntityBuilder<T extends EntityBuilder> {
protected EntityDataProvider provider;
public EntityBuilder(EntityDataProvider provider) {
this.provider = provider;
}
public T customName(@Nullable Component customName) {
((EntityDataProvider) provider).setCustomName(customName);
return (T) this;
}
public T customNameVisible(boolean customNameVisible) {
((EntityDataProvider) provider).setCustomNameVisible(customNameVisible);
return (T) this;
}
public T pose(EntityPose pose) {
((EntityDataProvider) provider).setPose(pose);
return (T) this;
}
public T onFire(boolean onFire) {
((EntityDataProvider) provider).setOnFire(onFire);
return (T) this;
}
public T crouching(boolean crouching) {
((EntityDataProvider) provider).setCrouching(crouching);
return (T) this;
}
public T riding(boolean riding) {
((EntityDataProvider) provider).setRiding(riding);
return (T) this;
}
public T sprinting(boolean sprinting) {
((EntityDataProvider) provider).setSprinting(sprinting);
return (T) this;
}
public T swimming(boolean swimming) {
((EntityDataProvider) provider).setSwimming(swimming);
return (T) this;
}
public T invisible(boolean invisible) {
((EntityDataProvider) provider).setInvisible(invisible);
return (T) this;
}
public T glowing(boolean glowing) {
((EntityDataProvider) provider).setGlowing(glowing);
return (T) this;
}
public T flyingWithElytra(boolean flyingWithElytra) {
((EntityDataProvider) provider).setFlyingWithElytra(flyingWithElytra);
return (T) this;
}
public T silent(boolean silent) {
((EntityDataProvider) provider).setSilent(silent);
return (T) this;
}
public T hasGravity(boolean hasGravity) {
((EntityDataProvider) provider).setHasGravity(hasGravity);
return (T) this;
}
public T airTicks(int airTicks) {
((EntityDataProvider) provider).setAirTicks(airTicks);
return (T) this;
}
public T ticksFrozenInPowderedSnow(int ticksFrozenInPowderedSnow) {
((EntityDataProvider) provider).setTicksFrozenInPowderedSnow(ticksFrozenInPowderedSnow);
return (T) this;
}
public <K extends EntityDataProvider> K build() {
return (K) provider;
}
}
}
@@ -0,0 +1,232 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.util.Vector3i;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class LivingEntityDataProvider extends EntityDataProvider {
private boolean handActive;
private InteractionHand hand = InteractionHand.MAIN_HAND;
private boolean isInRiptideSpinAttack;
private float health = 1.0f;
private int potionEffectColor;
private boolean potionEffectAmbient;
private int arrowInBodyCount;
private int beeStingsInBodyCount;
@Nullable
private Vector3i sleepingPosition;
public boolean isHandActive() {
return handActive;
}
public void setHandActive(boolean handActive) {
this.handActive = handActive;
}
public InteractionHand getHand() {
return hand;
}
public void setHand(InteractionHand hand) {
this.hand = hand;
}
public boolean isInRiptideSpinAttack() {
return isInRiptideSpinAttack;
}
public void setInRiptideSpinAttack(boolean inRiptideSpinAttack) {
isInRiptideSpinAttack = inRiptideSpinAttack;
}
public float getHealth() {
return health;
}
public void setHealth(float health) {
this.health = health;
}
public int getPotionEffectColor() {
return potionEffectColor;
}
public void setPotionEffectColor(int potionEffectColor) {
this.potionEffectColor = potionEffectColor;
}
public boolean isPotionEffectAmbient() {
return potionEffectAmbient;
}
public void setPotionEffectAmbient(boolean potionEffectAmbient) {
this.potionEffectAmbient = potionEffectAmbient;
}
public int getArrowInBodyCount() {
return arrowInBodyCount;
}
public void setArrowInBodyCount(int arrowInBodyCount) {
this.arrowInBodyCount = arrowInBodyCount;
}
public int getBeeStingsInBodyCount() {
return beeStingsInBodyCount;
}
public void setBeeStingsInBodyCount(int beeStingsInBodyCount) {
this.beeStingsInBodyCount = beeStingsInBodyCount;
}
@Nullable
public Vector3i getSleepingPosition() {
return sleepingPosition;
}
public void setSleepingPosition(@Nullable Vector3i sleepingPosition) {
this.sleepingPosition = sleepingPosition;
}
public static LivingEntityBuilder<LivingEntityBuilder> builderLivingEntity() {
return new LivingEntityBuilder<>(new LivingEntityDataProvider());
}
@Override
public List<EntityData> encode() {
List<EntityData> metadata = super.encode();
byte mask = 0x00;
if (handActive) {
mask |= 0x01;
}
//TODO Confirm
if (hand == InteractionHand.OFF_HAND) {
mask |= 0x02;
}
if (isInRiptideSpinAttack) {
mask |= 0x04;
}
metadata.add(new EntityData(8, EntityDataTypes.BYTE, mask));
metadata.add(new EntityData(9, EntityDataTypes.FLOAT, health));
metadata.add(new EntityData(10, EntityDataTypes.INT, potionEffectColor));
metadata.add(new EntityData(11, EntityDataTypes.BOOLEAN, potionEffectAmbient));
metadata.add(new EntityData(12, EntityDataTypes.INT, arrowInBodyCount));
metadata.add(new EntityData(13, EntityDataTypes.INT, beeStingsInBodyCount));
metadata.add(new EntityData(14, EntityDataTypes.OPTIONAL_BLOCK_POSITION, Optional.ofNullable(sleepingPosition)));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
super.decode(data);
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 8:
byte mask = (byte) entityData.getValue();
handActive = (mask & 0x01) != 0;
//TODO Test, look into
hand = (mask & 0x02) != 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
isInRiptideSpinAttack = (mask & 0x04) != 0;
break;
case 9:
health = (float) entityData.getValue();
break;
case 10:
potionEffectColor = (int) entityData.getValue();
break;
case 11:
potionEffectAmbient = (boolean) entityData.getValue();
break;
case 12:
arrowInBodyCount = (int) entityData.getValue();
break;
case 13:
beeStingsInBodyCount = (int) entityData.getValue();
break;
case 14:
sleepingPosition = ((Optional<Vector3i>) entityData.getValue()).orElse(null);
break;
}
}
}
public static class LivingEntityBuilder<T extends LivingEntityBuilder> extends EntityDataProvider.EntityBuilder<T> {
public LivingEntityBuilder(LivingEntityDataProvider livingEntityDataProvider) {
super(livingEntityDataProvider);
}
public T handActive(boolean handActive) {
((LivingEntityDataProvider) provider).setHandActive(handActive);
return (T) this;
}
public T hand(InteractionHand hand) {
((LivingEntityDataProvider) provider).setHand(hand);
return (T) this;
}
public T isInRiptideSpinAttack(boolean isInRiptideSpinAttack) {
((LivingEntityDataProvider) provider).setInRiptideSpinAttack(isInRiptideSpinAttack);
return (T) this;
}
public T health(float health) {
((LivingEntityDataProvider) provider).setHealth(health);
return (T) this;
}
public T potionEffectColor(int potionEffectColor) {
((LivingEntityDataProvider) provider).setPotionEffectColor(potionEffectColor);
return (T) this;
}
public T potionEffectAmbient(boolean potionEffectAmbient) {
((LivingEntityDataProvider) provider).setPotionEffectAmbient(potionEffectAmbient);
return (T) this;
}
public T arrowInBodyCount(int arrowInBodyCount) {
((LivingEntityDataProvider) provider).setArrowInBodyCount(arrowInBodyCount);
return (T) this;
}
public T beeStingsInBodyCount(int beeStingsInBodyCount) {
((LivingEntityDataProvider) provider).setBeeStingsInBodyCount(beeStingsInBodyCount);
return (T) this;
}
public T sleepingPosition(@Nullable Vector3i sleepingPosition) {
((LivingEntityDataProvider) provider).setSleepingPosition(sleepingPosition);
return (T) this;
}
}
}
@@ -0,0 +1,169 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.data.provider;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.HumanoidArm;
import com.github.retrooper.packetevents.protocol.player.SkinSection;
import java.util.List;
import java.util.Set;
public class PlayerDataProvider extends LivingEntityDataProvider {
private float additionalHealth;
private int score;
private byte skinPartsMask = SkinSection.getMaskBySections(SkinSection.getAllSections());
private HumanoidArm mainArm = HumanoidArm.RIGHT;
private NBTCompound leftShoulderNBT = new NBTCompound();
private NBTCompound rightShoulderNBT = new NBTCompound();
public float getAdditionalHealth() {
return additionalHealth;
}
public void setAdditionalHealth(float additionalHealth) {
this.additionalHealth = additionalHealth;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public byte getSkinPartsMask() {
return skinPartsMask;
}
public void setSkinPartsMask(byte skinPartsMask) {
this.skinPartsMask = skinPartsMask;
}
public HumanoidArm getMainArm() {
return mainArm;
}
public void setMainArm(HumanoidArm mainArm) {
this.mainArm = mainArm;
}
public NBTCompound getLeftShoulderNBT() {
return leftShoulderNBT;
}
public void setLeftShoulderNBT(NBTCompound leftShoulderNBT) {
this.leftShoulderNBT = leftShoulderNBT;
}
public NBTCompound getRightShoulderNBT() {
return rightShoulderNBT;
}
public void setRightShoulderNBT(NBTCompound rightShoulderNBT) {
this.rightShoulderNBT = rightShoulderNBT;
}
public static PlayerBuilder<PlayerBuilder> builderPlayer() {
return new PlayerBuilder<>(new PlayerDataProvider());
}
@Override
public List<EntityData> encode() {
List<EntityData> metadata = super.encode();
metadata.add(new EntityData(15, EntityDataTypes.FLOAT, additionalHealth));
metadata.add(new EntityData(16, EntityDataTypes.INT, score));
metadata.add(new EntityData(17, EntityDataTypes.BYTE, skinPartsMask));
metadata.add(new EntityData(18, EntityDataTypes.BYTE, (byte) mainArm.ordinal()));
metadata.add(new EntityData(19, EntityDataTypes.NBT, leftShoulderNBT));
metadata.add(new EntityData(20, EntityDataTypes.NBT, rightShoulderNBT));
return metadata;
}
@Override
public void decode(List<EntityData> data) {
super.decode(data);
for (EntityData entityData : data) {
switch (entityData.getIndex()) {
case 15:
additionalHealth = (float) entityData.getValue();
break;
case 16:
score = (int) entityData.getValue();
break;
case 17:
skinPartsMask = (byte) entityData.getValue();
break;
case 18:
mainArm = HumanoidArm.values()[(byte) entityData.getValue()];
break;
case 19:
leftShoulderNBT = (NBTCompound) entityData.getValue();
break;
case 20:
rightShoulderNBT = (NBTCompound) entityData.getValue();
break;
}
}
}
public static class PlayerBuilder<T extends PlayerBuilder> extends LivingEntityDataProvider.LivingEntityBuilder<T> {
public PlayerBuilder(PlayerDataProvider entityDataProvider) {
super(entityDataProvider);
}
public T additionalHealth(float additionalHealth) {
((PlayerDataProvider)provider).setAdditionalHealth(additionalHealth);
return (T) this;
}
public T score(int score) {
((PlayerDataProvider)provider).setScore(score);
return (T) this;
}
public T skinPartsMask(byte skinPartsMask) {
((PlayerDataProvider)provider).setSkinPartsMask(skinPartsMask);
return (T)this;
}
public T skinParts(Set<SkinSection> skinSections) {
((PlayerDataProvider)provider).setSkinPartsMask(SkinSection.getMaskBySections(skinSections));
return (T)this;
}
public T mainArm(HumanoidArm mainArm) {
((PlayerDataProvider)provider).setMainArm(mainArm);
return (T)this;
}
public T leftShoulderNBT(NBTCompound leftShoulderNBT) {
((PlayerDataProvider)provider).setLeftShoulderNBT(leftShoulderNBT);
return (T)this;
}
public T rightShoulderNBT(NBTCompound rightShoulderNBT) {
((PlayerDataProvider)provider).setRightShoulderNBT(rightShoulderNBT);
return (T)this;
}
}
}
@@ -16,21 +16,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.packetwrappers.play.in.teleportaccept;
package com.github.retrooper.packetevents.protocol.entity.pose;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
public class WrappedPacketInTeleportAccept extends WrappedPacket {
public WrappedPacketInTeleportAccept(NMSPacket packet) {
super(packet);
}
public enum EntityPose {
STANDING,
FALL_FLYING,
SLEEPING,
SWIMMING,
SPIN_ATTACK,
CROUCHING,
LONG_JUMPING,
DYING;
public int getTeleportId() {
return readInt(0);
}
public int getId(ClientVersion version) {
if (this == DYING && version.isOlderThan(ClientVersion.V_1_17)) {
return 6;
}
return ordinal();
}
public void setTeleportId(int teleportId) {
writeInt(0, teleportId);
}
public static EntityPose getById(ClientVersion version, int id) {
// The LONG_JUMPING pose was added in 1.17, shifting things by 1
if (id == 6 && version.isOlderThan(ClientVersion.V_1_17)) {
return DYING;
}
return values()[id];
}
}
@@ -0,0 +1,28 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.type;
import com.github.retrooper.packetevents.protocol.mapper.LegacyMappedEntity;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import java.util.Optional;
public interface EntityType extends MappedEntity, LegacyMappedEntity {
Optional<EntityType> getParent();
}
@@ -0,0 +1,289 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.type;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.TypesBuilder;
import com.github.retrooper.packetevents.util.TypesBuilderData;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class EntityTypes {
private static final Map<String, EntityType> ENTITY_TYPE_MAP = new HashMap<>();
//Key - mappings version, value - map with entity type ids and entity types
private static final Map<Byte, Map<Integer, EntityType>> ENTITY_TYPE_ID_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, EntityType>> LEGACY_ENTITY_TYPE_ID_MAP = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("entity/entity_type_mappings",
ClientVersion.V_1_10,
ClientVersion.V_1_11,
ClientVersion.V_1_12,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_15,
ClientVersion.V_1_16,
ClientVersion.V_1_16_2,
ClientVersion.V_1_17);
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings",
ClientVersion.V_1_8,
ClientVersion.V_1_9,
ClientVersion.V_1_10,
ClientVersion.V_1_11,
ClientVersion.V_1_12,
ClientVersion.V_1_13);
public static EntityType define(String key, @Nullable EntityType parent) {
TypesBuilderData data = TYPES_BUILDER.define(key);
TypesBuilderData legacyData = LEGACY_TYPES_BUILDER.define(key);
Optional<EntityType> optParent = Optional.ofNullable(parent);
EntityType entityType = new EntityType() {
private final int[] ids = data.getData();
private final int[] legacyIds = legacyData.getData();
@Override
public Optional<EntityType> getParent() {
return optParent;
}
@Override
public int getLegacyId(ClientVersion version) {
if (version.isNewerThanOrEquals(ClientVersion.V_1_14)) {
return -1;
}
int index = LEGACY_TYPES_BUILDER.getDataIndex(version);
return legacyIds[index];
}
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
int index = TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
};
ENTITY_TYPE_MAP.put(entityType.getName().toString(), entityType);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityType> typeIdMap = ENTITY_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(entityType.getId(version), entityType);
}
for (ClientVersion version : LEGACY_TYPES_BUILDER.getVersions()) {
int index = LEGACY_TYPES_BUILDER.getDataIndex(version);
Map<Integer, EntityType> legacyTypeIdMap = LEGACY_ENTITY_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
legacyTypeIdMap.put(entityType.getLegacyId(version), entityType);
}
return entityType;
}
public static boolean isTypeInstanceOf(EntityType type, EntityType parent) {
while (type != null) {
if (type == parent) {
return true;
}
if (type.getParent().isPresent()) {
type = type.getParent().get();
} else {
return false;
}
}
return false;
}
//with minecraft:key
public static EntityType getByName(String name) {
return ENTITY_TYPE_MAP.get(name);
}
public static EntityType getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
return ENTITY_TYPE_ID_MAP.get((byte) index).get(id);
}
public static EntityType getByLegacyId(ClientVersion version, int id) {
if (version.isNewerThanOrEquals(ClientVersion.V_1_14)) {
return null;
}
int index = LEGACY_TYPES_BUILDER.getDataIndex(version);
return LEGACY_ENTITY_TYPE_ID_MAP.get((byte) index).get(id);
}
// Credit to ViaVersion for these categories
public static final EntityType ENTITY = define("entity", null);
public static final EntityType LIVINGENTITY = define("livingentity", ENTITY);
public static final EntityType ABSTRACT_INSENTIENT = define("abstract_insentient", LIVINGENTITY);
public static final EntityType ABSTRACT_CREATURE = define("abstract_creature", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_AGEABLE = define("abstract_ageable", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_ANIMAL = define("abstract_animal", ABSTRACT_AGEABLE);
public static final EntityType ABSTRACT_TAMEABLE_ANIMAL = define("abstract_tameable_animal", ABSTRACT_ANIMAL);
public static final EntityType ABSTRACT_PARROT = define("abstract_parrot", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType ABSTRACT_HORSE = define("abstract_horse", ABSTRACT_ANIMAL);
public static final EntityType CHESTED_HORSE = define("chested_horse", ABSTRACT_HORSE);
public static final EntityType ABSTRACT_GOLEM = define("abstract_golem", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_FISHES = define("abstract_fishes", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_MONSTER = define("abstract_monster", ABSTRACT_CREATURE);
public static final EntityType ABSTRACT_PIGLIN = define("abstract_piglin", ABSTRACT_MONSTER);
public static final EntityType ABSTRACT_ILLAGER_BASE = define("abstract_illager_base", ABSTRACT_MONSTER);
public static final EntityType ABSTRACT_EVO_ILLU_ILLAGER = define("abstract_evo_illu_illager", ABSTRACT_ILLAGER_BASE);
public static final EntityType ABSTRACT_SKELETON = define("abstract_skeleton", ABSTRACT_MONSTER);
public static final EntityType ABSTRACT_FLYING = define("abstract_flying", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_AMBIENT = define("abstract_ambient", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_WATERMOB = define("abstract_watermob", ABSTRACT_INSENTIENT);
public static final EntityType ABSTRACT_HANGING = define("abstract_hanging", ENTITY);
public static final EntityType ABSTRACT_LIGHTNING = define("abstract_lightning", ENTITY);
public static final EntityType ABSTRACT_ARROW = define("abstract_arrow", ENTITY);
public static final EntityType ABSTRACT_FIREBALL = define("abstract_fireball", ENTITY);
public static final EntityType PROJECTILE_ABSTRACT = define("projectile_abstract", ENTITY);
public static final EntityType MINECART_ABSTRACT = define("minecart_abstract", ENTITY);
public static final EntityType CHESTED_MINECART_ABSTRACT = define("chested_minecart_abstract", MINECART_ABSTRACT);
public static final EntityType AREA_EFFECT_CLOUD = define("area_effect_cloud", ENTITY);
public static final EntityType ARMOR_STAND = define("armor_stand", LIVINGENTITY);
public static final EntityType ARROW = define("arrow", ABSTRACT_ARROW);
public static final EntityType AXOLOTL = define("axolotl", ABSTRACT_ANIMAL);
public static final EntityType BAT = define("bat", ABSTRACT_AMBIENT);
public static final EntityType BEE = define("bee", ABSTRACT_INSENTIENT);
public static final EntityType BLAZE = define("blaze", ABSTRACT_MONSTER);
public static final EntityType BOAT = define("boat", ENTITY);
public static final EntityType CAT = define("cat", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType SPIDER = define("spider", ABSTRACT_MONSTER);
public static final EntityType CAVE_SPIDER = define("cave_spider", SPIDER);
public static final EntityType CHICKEN = define("chicken", ABSTRACT_ANIMAL);
public static final EntityType COD = define("cod", ABSTRACT_FISHES);
public static final EntityType COW = define("cow", ABSTRACT_ANIMAL);
public static final EntityType CREEPER = define("creeper", ABSTRACT_MONSTER);
public static final EntityType DOLPHIN = define("dolphin", ABSTRACT_INSENTIENT);
public static final EntityType DONKEY = define("donkey", CHESTED_HORSE);
public static final EntityType DRAGON_FIREBALL = define("dragon_fireball", ABSTRACT_FIREBALL);
public static final EntityType ZOMBIE = define("zombie", ABSTRACT_MONSTER);
public static final EntityType DROWNED = define("drowned", ZOMBIE);
public static final EntityType GUARDIAN = define("guardian", ABSTRACT_MONSTER);
public static final EntityType ELDER_GUARDIAN = define("elder_guardian", GUARDIAN);
public static final EntityType END_CRYSTAL = define("end_crystal", ENTITY);
public static final EntityType ENDER_DRAGON = define("ender_dragon", ABSTRACT_INSENTIENT);
public static final EntityType ENDERMAN = define("enderman", ABSTRACT_MONSTER);
public static final EntityType ENDERMITE = define("endermite", ABSTRACT_MONSTER);
public static final EntityType EVOKER = define("evoker", ABSTRACT_EVO_ILLU_ILLAGER);
public static final EntityType EVOKER_FANGS = define("evoker_fangs", ENTITY);
public static final EntityType EXPERIENCE_ORB = define("experience_orb", ENTITY);
public static final EntityType EYE_OF_ENDER = define("eye_of_ender", ENTITY);
public static final EntityType FALLING_BLOCK = define("falling_block", ENTITY);
public static final EntityType FIREWORK_ROCKET = define("firework_rocket", ENTITY);
public static final EntityType FOX = define("fox", ABSTRACT_ANIMAL);
public static final EntityType GHAST = define("ghast", ABSTRACT_FLYING);
public static final EntityType GIANT = define("giant", ABSTRACT_MONSTER);
public static final EntityType ITEM_FRAME = define("item_frame", ABSTRACT_HANGING);
public static final EntityType GLOW_ITEM_FRAME = define("glow_item_frame", ITEM_FRAME);
public static final EntityType SQUID = define("squid", ABSTRACT_WATERMOB);
public static final EntityType GLOW_SQUID = define("glow_squid", SQUID);
public static final EntityType GOAT = define("goat", ABSTRACT_ANIMAL);
public static final EntityType HOGLIN = define("hoglin", ABSTRACT_ANIMAL);
public static final EntityType HORSE = define("horse", ABSTRACT_HORSE);
public static final EntityType HUSK = define("husk", ZOMBIE);
public static final EntityType ILLUSIONER = define("illusioner", ABSTRACT_EVO_ILLU_ILLAGER);
public static final EntityType IRON_GOLEM = define("iron_golem", ABSTRACT_GOLEM);
public static final EntityType ITEM = define("item", ENTITY);
public static final EntityType FIREBALL = define("fireball", ABSTRACT_FIREBALL);
public static final EntityType LEASH_KNOT = define("leash_knot", ABSTRACT_HANGING);
public static final EntityType LIGHTNING_BOLT = define("lightning_bolt", ABSTRACT_LIGHTNING);
public static final EntityType LLAMA = define("llama", CHESTED_HORSE);
public static final EntityType LLAMA_SPIT = define("llama_spit", ENTITY);
public static final EntityType SLIME = define("slime", ABSTRACT_INSENTIENT);
public static final EntityType MAGMA_CUBE = define("magma_cube", SLIME);
public static final EntityType MARKER = define("marker", ENTITY);
public static final EntityType MINECART = define("minecart", MINECART_ABSTRACT);
public static final EntityType CHEST_MINECART = define("chest_minecart", CHESTED_MINECART_ABSTRACT);
public static final EntityType COMMAND_BLOCK_MINECART = define("command_block_minecart", MINECART_ABSTRACT);
public static final EntityType FURNACE_MINECART = define("furnace_minecart", MINECART_ABSTRACT);
public static final EntityType HOPPER_MINECART = define("hopper_minecart", CHESTED_MINECART_ABSTRACT);
public static final EntityType SPAWNER_MINECART = define("spawner_minecart", MINECART_ABSTRACT);
public static final EntityType TNT_MINECART = define("tnt_minecart", MINECART_ABSTRACT);
public static final EntityType MULE = define("mule", CHESTED_HORSE);
public static final EntityType MOOSHROOM = define("mooshroom", COW);
public static final EntityType OCELOT = define("ocelot", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType PAINTING = define("painting", ABSTRACT_HANGING);
public static final EntityType PANDA = define("panda", ABSTRACT_INSENTIENT);
public static final EntityType PARROT = define("parrot", ABSTRACT_PARROT);
public static final EntityType PHANTOM = define("phantom", ABSTRACT_FLYING);
public static final EntityType PIG = define("pig", ABSTRACT_ANIMAL);
public static final EntityType PIGLIN = define("piglin", ABSTRACT_PIGLIN);
public static final EntityType PIGLIN_BRUTE = define("piglin_brute", ABSTRACT_PIGLIN);
public static final EntityType PILLAGER = define("pillager", ABSTRACT_ILLAGER_BASE);
public static final EntityType POLAR_BEAR = define("polar_bear", ABSTRACT_ANIMAL);
public static final EntityType TNT = define("tnt", ENTITY);
public static final EntityType PUFFERFISH = define("pufferfish", ABSTRACT_FISHES);
public static final EntityType RABBIT = define("rabbit", ABSTRACT_ANIMAL);
public static final EntityType RAVAGER = define("ravager", ABSTRACT_MONSTER);
public static final EntityType SALMON = define("salmon", ABSTRACT_FISHES);
public static final EntityType SHEEP = define("sheep", ABSTRACT_ANIMAL);
public static final EntityType SHULKER = define("shulker", ABSTRACT_GOLEM); // yes this is correct
public static final EntityType SHULKER_BULLET = define("shulker_bullet", ENTITY);
public static final EntityType SILVERFISH = define("silverfish", ABSTRACT_MONSTER);
public static final EntityType SKELETON = define("skeleton", ABSTRACT_SKELETON);
public static final EntityType SKELETON_HORSE = define("skeleton_horse", ABSTRACT_HORSE);
public static final EntityType SMALL_FIREBALL = define("small_fireball", ABSTRACT_FIREBALL);
public static final EntityType SNOW_GOLEM = define("snow_golem", ABSTRACT_GOLEM);
public static final EntityType SNOWBALL = define("snowball", PROJECTILE_ABSTRACT);
public static final EntityType SPECTRAL_ARROW = define("spectral_arrow", ABSTRACT_ARROW);
public static final EntityType STRAY = define("stray", ABSTRACT_SKELETON);
public static final EntityType STRIDER = define("strider", ABSTRACT_ANIMAL);
public static final EntityType EGG = define("egg", PROJECTILE_ABSTRACT);
public static final EntityType ENDER_PEARL = define("ender_pearl", PROJECTILE_ABSTRACT);
public static final EntityType EXPERIENCE_BOTTLE = define("experience_bottle", PROJECTILE_ABSTRACT);
public static final EntityType POTION = define("potion", PROJECTILE_ABSTRACT);
@Deprecated // Exists only in 1.9 and 1.10
public static final EntityType TIPPED_ARROW = define("tipped_arrow", ARROW);
public static final EntityType TRIDENT = define("trident", ABSTRACT_ARROW);
public static final EntityType TRADER_LLAMA = define("trader_llama", CHESTED_HORSE);
public static final EntityType TROPICAL_FISH = define("tropical_fish", ABSTRACT_FISHES);
public static final EntityType TURTLE = define("turtle", ABSTRACT_ANIMAL);
public static final EntityType VEX = define("vex", ABSTRACT_MONSTER);
public static final EntityType VILLAGER = define("villager", ABSTRACT_AGEABLE);
public static final EntityType VINDICATOR = define("vindicator", ABSTRACT_ILLAGER_BASE);
public static final EntityType WANDERING_TRADER = define("wandering_trader", ABSTRACT_AGEABLE);
public static final EntityType WITCH = define("witch", ABSTRACT_MONSTER);
public static final EntityType WITHER = define("wither", ABSTRACT_MONSTER);
public static final EntityType WITHER_SKELETON = define("wither_skeleton", ABSTRACT_SKELETON);
public static final EntityType WITHER_SKULL = define("wither_skull", ABSTRACT_FIREBALL);
public static final EntityType WOLF = define("wolf", ABSTRACT_TAMEABLE_ANIMAL);
public static final EntityType ZOGLIN = define("zoglin", ABSTRACT_MONSTER);
public static final EntityType ZOMBIE_HORSE = define("zombie_horse", ABSTRACT_HORSE);
public static final EntityType ZOMBIE_VILLAGER = define("zombie_villager", ZOMBIE);
public static final EntityType ZOMBIFIED_PIGLIN = define("zombified_piglin", ZOMBIE);
public static final EntityType PLAYER = define("player", LIVINGENTITY);
public static final EntityType FISHING_BOBBER = define("fishing_bobber", ENTITY);
public static final EntityType ENDER_SIGNAL = define("ender_signal", ENTITY);
public static final EntityType THROWN_EXP_BOTTLE = define("thrown_exp_bottle", PROJECTILE_ABSTRACT);
public static final EntityType PRIMED_TNT = define("primed_tnt", ENTITY);
public static final EntityType FIREWORK = define("firework", ENTITY);
public static final EntityType MINECART_COMMAND = define("minecart_command", MINECART_ABSTRACT);
public static final EntityType MINECART_RIDEABLE = define("minecart_rideable", MINECART_ABSTRACT);
public static final EntityType MINECART_CHEST = define("minecart_chest", MINECART_ABSTRACT);
public static final EntityType MINECART_FURNACE = define("minecart_furnace", MINECART_ABSTRACT);
public static final EntityType MINECART_TNT = define("minecart_tnt", MINECART_ABSTRACT);
public static final EntityType MINECART_HOPPER = define("minecart_hopper", MINECART_ABSTRACT);
public static final EntityType MINECART_MOB_SPAWNER = define("minecart_mob_spawner", MINECART_ABSTRACT);
}
@@ -0,0 +1,64 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager;
import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfession;
import com.github.retrooper.packetevents.protocol.entity.villager.profession.VillagerProfessions;
import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerType;
import com.github.retrooper.packetevents.protocol.entity.villager.type.VillagerTypes;
public class VillagerData {
private VillagerType type;
private VillagerProfession profession;
private int level;
public VillagerData(VillagerType type, VillagerProfession profession, int level) {
this.type = type;
this.profession = profession;
this.level = level;
}
public VillagerData(int typeId, int professionId, int level) {
this(VillagerTypes.getById(typeId), VillagerProfessions.getById(professionId), level);
}
public VillagerType getType() {
return type;
}
public void setType(VillagerType type) {
this.type = type;
}
public VillagerProfession getProfession() {
return profession;
}
public void setProfession(VillagerProfession profession) {
this.profession = profession;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}
@@ -0,0 +1,25 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.profession;
import com.github.retrooper.packetevents.protocol.mapper.StaticMappedEntity;
public interface VillagerProfession extends StaticMappedEntity {
}
@@ -0,0 +1,73 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.profession;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.TypesBuilder;
import java.util.HashMap;
import java.util.Map;
public class VillagerProfessions {
private static final Map<String, VillagerProfession> VILLAGER_PROFESSION_MAP = new HashMap<>();
private static final Map<Byte, VillagerProfession> VILLAGER_PROFESSION_ID_MAP = new HashMap<>();
public static VillagerProfession define(int id, String name) {
ResourceLocation location = new ResourceLocation(name);
VillagerProfession type = new VillagerProfession() {
@Override
public ResourceLocation getName() {
return location;
}
@Override
public int getId() {
return id;
}
};
VILLAGER_PROFESSION_MAP.put(type.getName().toString(), type);
VILLAGER_PROFESSION_ID_MAP.put((byte) type.getId(), type);
return type;
}
public static VillagerProfession getById(int id) {
return VILLAGER_PROFESSION_ID_MAP.get((byte)id);
}
public static VillagerProfession getByName(String name) {
return VILLAGER_PROFESSION_MAP.get(name);
}
public static final VillagerProfession NONE = define(0, "minecraft:none");
public static final VillagerProfession ARMORER = define(1, "minecraft:armorer");
public static final VillagerProfession BUTCHER = define(2, "minecraft:butcher");
public static final VillagerProfession CARTOGRAPHER = define(3, "minecraft:cartographer");
public static final VillagerProfession CLERIC = define(4, "minecraft:cleric");
public static final VillagerProfession FARMER = define(5, "minecraft:farmer");
public static final VillagerProfession FISHERMAN = define(6, "minecraft:fisherman");
public static final VillagerProfession FLETCHER = define(7, "minecraft:fletcher");
public static final VillagerProfession LEATHERWORKER = define(8, "minecraft:leatherworker");
public static final VillagerProfession LIBRARIAN = define(9, "minecraft:librarian");
public static final VillagerProfession MASON = define(10, "minecraft:mason");
public static final VillagerProfession NITWIT = define(11, "minecraft:nitwit");
public static final VillagerProfession SHEPHERD = define(12, "minecraft:shepherd");
public static final VillagerProfession TOOLSMITH = define(13, "minecraft:toolsmith");
public static final VillagerProfession WEAPONSMITH = define(14, "minecraft:weaponsmith");
}
@@ -0,0 +1,25 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.type;
import com.github.retrooper.packetevents.protocol.mapper.StaticMappedEntity;
public interface VillagerType extends StaticMappedEntity {
}
@@ -0,0 +1,65 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.entity.villager.type;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import java.util.HashMap;
import java.util.Map;
public class VillagerTypes {
private static final Map<String, VillagerType> VILLAGER_TYPE_MAP = new HashMap<>();
private static final Map<Byte, VillagerType> VILLAGER_TYPE_ID_MAP = new HashMap<>();
public static VillagerType define(int id, String name) {
ResourceLocation location = new ResourceLocation(name);
VillagerType type = new VillagerType() {
@Override
public ResourceLocation getName() {
return location;
}
@Override
public int getId() {
return id;
}
};
VILLAGER_TYPE_MAP.put(type.getName().toString(), type);
VILLAGER_TYPE_ID_MAP.put((byte)type.getId(), type);
return type;
}
public static VillagerType getById(int id) {
return VILLAGER_TYPE_ID_MAP.get((byte)id);
}
public static VillagerType getByName(String name) {
return VILLAGER_TYPE_MAP.get(name);
}
public static final VillagerType DESERT = define(0, "minecraft:desert");
public static final VillagerType JUNGLE = define(1, "minecraft:jungle");
public static final VillagerType PLAINS = define(2, "minecraft:plains");
public static final VillagerType SAVANNA = define(3, "minecraft:savanna");
public static final VillagerType SNOW = define(4, "minecraft:snow");
public static final VillagerType SWAMP = define(5, "minecraft:swamp");
public static final VillagerType TAIGA = define(6, "minecraft:taiga");
}
@@ -0,0 +1,335 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.item;
import com.github.retrooper.packetevents.protocol.item.enchantment.Enchantment;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.nbt.*;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ItemStack {
public static final ItemStack EMPTY = new ItemStack(ItemTypes.AIR, 0, new NBTCompound(), 0);
private final ItemType type;
private int amount;
@Nullable
private NBTCompound nbt;
private int legacyData = -1;
private boolean cachedIsEmpty = false;
private ItemStack(ItemType type, int amount, @Nullable NBTCompound nbt, int legacyData) {
this.type = type;
this.amount = amount;
this.nbt = nbt;
this.legacyData = legacyData;
updateCachedEmptyStatus();
}
public int getMaxStackSize() {
return getType().getMaxAmount();
}
public boolean isStackable() {
return this.getMaxStackSize() > 1 && (!this.isDamageableItem() || !this.isDamaged());
}
public boolean isDamageableItem() {
if (!this.cachedIsEmpty && this.getType().getMaxDurability() > 0) {
NBTCompound tag = this.getNBT();
return tag == null || !tag.getBoolean("Unbreakable");
} else {
return false;
}
}
public boolean isDamaged() {
return this.isDamageableItem() && this.getDamageValue() > 0;
}
public int getDamageValue() {
if (nbt == null) return 0;
NBTInt damage = this.nbt.getTagOfTypeOrNull("Damage", NBTInt.class);
return damage == null ? 0 : damage.getAsInt();
}
public void setDamageValue(int damage) {
this.getOrCreateTag().setTag("Damage", new NBTInt(Math.max(0, damage)));
}
public int getMaxDamage() {
return this.getType().getMaxDurability();
}
public NBTCompound getOrCreateTag() {
if (this.nbt == null) {
this.nbt = new NBTCompound();
}
return this.nbt;
}
private void updateCachedEmptyStatus() {
cachedIsEmpty = isEmpty();
}
public ItemType getType() {
return cachedIsEmpty ? ItemTypes.AIR : type;
}
public int getAmount() {
return cachedIsEmpty ? 0 : amount;
}
public void shrink(int amount) {
this.setAmount(this.getAmount() - amount);
}
public void grow(int amount) {
this.setAmount(this.getAmount() + amount);
}
public void setAmount(int amount) {
this.amount = amount;
updateCachedEmptyStatus();
}
public ItemStack split(int toTake) {
int i = Math.min(toTake, getAmount());
ItemStack itemstack = this.copy();
itemstack.setAmount(i);
this.shrink(i);
return itemstack;
}
public ItemStack copy() {
return cachedIsEmpty ? EMPTY : new ItemStack(type, amount, nbt == null ? new NBTCompound() : nbt.copy(), legacyData);
}
@Nullable
public NBTCompound getNBT() {
return nbt;
}
public void setNBT(NBTCompound nbt) {
this.nbt = nbt;
}
public int getLegacyData() {
return legacyData;
}
public void setLegacyData(int legacyData) {
this.legacyData = legacyData;
}
public boolean isEnchantable() {
if (getType() == ItemTypes.BOOK) return getAmount() == 1;
if (getType() == ItemTypes.ENCHANTED_BOOK) return false;
return getMaxStackSize() == 1 && canBeDepleted() && !isEnchanted();
}
public boolean isEnchanted() {
if (!isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull("Enchantments") != null) {
return !this.nbt.getCompoundListTagOrNull("Enchantments").isEmpty();
} else {
return false;
}
}
private static List<Enchantment> getEnchantments(@Nullable NBTCompound nbt) {
if (nbt == null || nbt.getCompoundListTagOrNull("Enchantments") == null)
return new ArrayList<>(0);
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull("Enchantments");
List<NBTCompound> compounds = nbtList.getTags();
List<Enchantment> enchantments = new ArrayList<>(compounds.size());
for (NBTCompound compound : compounds) {
String id = compound.getStringTagValueOrNull("id");
EnchantmentType type = EnchantmentTypes.getByName(id);
if (type != null) {
NBTShort levelTag = compound.getTagOfTypeOrNull("lvl", NBTShort.class);
int level = levelTag.getAsInt();
Enchantment enchantment = Enchantment.builder().type(type).level(level).build();
enchantments.add(enchantment);
}
}
return enchantments;
}
public List<Enchantment> getEnchantments() {
return getEnchantments(this.nbt);
}
// TODO: Test on outdated versions
public int getEnchantmentLevel(EnchantmentType enchantment) {
if (isEnchanted()) {
// isEnchanted() is true, so we can assume that nbt is not null
assert nbt != null;
for (NBTCompound base : nbt.getCompoundListTagOrNull("Enchantments").getTags()) {
NBTString string = base.getTagOfTypeOrNull("id", NBTString.class);
if (string != null && enchantment == EnchantmentTypes.getByName(string.getValue())) {
return base.getTagOfTypeOrNull("lvl", NBTShort.class).getAsInt();
}
}
}
return 0;
}
public void setEnchantments(List<Enchantment> enchantments) {
nbt = getOrCreateTag(); // Create tag if null
if (enchantments.isEmpty()) {
//Let us clear the enchantments
if (nbt.getTagOrNull("Enchantments") != null) {
nbt.removeTag("Enchantments");
}
}
else {
List<NBTCompound> list = new ArrayList<>();
for (Enchantment enchantment : enchantments) {
NBTCompound compound = new NBTCompound();
compound.setTag("id", new NBTString(enchantment.getType().getName().toString()));
compound.setTag("lvl", new NBTShort((short) enchantment.getLevel()));
list.add(compound);
}
assert nbt != null; // NBT was created in getOrCreateTag()
nbt.setTag("Enchantments", new NBTList<>(NBTType.COMPOUND, list));
}
}
public boolean canBeDepleted() {
return this.getType().getMaxDurability() > 0;
}
public boolean is(ItemType type) {
return this.getType() == type;
}
public static boolean isSameItemSameTags(ItemStack stack, ItemStack otherStack) {
return stack.is(otherStack.getType()) && ItemStack.tagMatches(stack, otherStack);
}
public static boolean tagMatches(ItemStack left, ItemStack right) {
return left.isEmpty() && right.isEmpty() || (!left.isEmpty() && !right.isEmpty() && ((left.nbt != null || right.nbt == null) && (left.nbt == null || left.nbt.equals(right.nbt))));
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj instanceof ItemStack) {
ItemStack itemStack = (ItemStack) obj;
return getType().equals(itemStack.getType())
&& amount == itemStack.amount
&& Objects.equals(nbt, itemStack.nbt)
&& legacyData == itemStack.legacyData;
}
return false;
}
@Override
public String toString() {
if (cachedIsEmpty) {
return "ItemStack[null]";
} else {
String identifier = type == null ? "null" : type.getName().toString();
int maxAmount = getType().getMaxAmount();
return "ItemStack[type=" + identifier + ", amount=" + amount + "/" + maxAmount
+ ", nbt tag names: " + (nbt != null ? nbt.getTagNames() : "[null]") + ", legacyData=" + legacyData + "]";
}
}
public boolean isEmpty() {
return type == null || type == ItemTypes.AIR || amount <= 0;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private ItemType type;
private int amount = 1;
private NBTCompound nbt = null;
private int legacyData = -1;
private List<Enchantment> enchantments = null;
public Builder type(ItemType type) {
this.type = type;
return this;
}
public Builder amount(int amount) {
this.amount = amount;
return this;
}
public Builder nbt(NBTCompound nbt) {
this.nbt = nbt;
List<Enchantment> nbtEnchantments = getEnchantments(nbt);
// This assumes logically, if already set enchants before NBT, then they would still want the enchants
if (!nbtEnchantments.isEmpty()) {
this.enchantments = nbtEnchantments;
}
return this;
}
public Builder legacyData(int legacyData) {
this.legacyData = legacyData;
return this;
}
/**
* Side effect: This will cause NBT to be created if it is null
* This may affect some client sided inventory operations and may cause a desync
*
* @param enchantments The enchantments to set
* @return This builder
*/
public Builder enchantments(List<Enchantment> enchantments) {
this.enchantments = enchantments;
return this;
}
public Builder addEnchantment(Enchantment enchantment) {
if (enchantments == null) {
enchantments = new ArrayList<>();
}
this.enchantments.add(enchantment);
return this;
}
public ItemStack build() {
ItemStack stack = new ItemStack(type, amount, nbt, legacyData);
if (enchantments != null) {
stack.setEnchantments(enchantments);
}
return stack;
}
}
}
@@ -0,0 +1,71 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.item.enchantment;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
public class Enchantment {
private EnchantmentType type;
private int level;
private Enchantment(EnchantmentType type, int level) {
this.type = type;
this.level = level;
}
public EnchantmentType getType() {
return type;
}
public void setType(EnchantmentType type) {
this.type = type;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private EnchantmentType type;
private int level;
public Builder type(EnchantmentType type) {
this.type = type;
return this;
}
public Builder level(int level) {
this.level = level;
return this;
}
public Enchantment build() {
return new Enchantment(type, level);
}
}
}
@@ -16,10 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.injector;
package com.github.retrooper.packetevents.protocol.item.enchantment.type;
import org.bukkit.entity.Player;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
public interface EarlyInjector extends ChannelInjector {
void updatePlayerObject(Player player, Object channel);
public interface EnchantmentType extends MappedEntity {
}
@@ -0,0 +1,123 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.item.enchantment.type;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.TypesBuilder;
import com.github.retrooper.packetevents.util.TypesBuilderData;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class EnchantmentTypes {
private static final Map<String, EnchantmentType> ENCHANTMENT_TYPE_MAPPINGS = new HashMap<>();
private static final Map<Byte, Map<Integer, EnchantmentType>> ENCHANTMENT_TYPE_ID_MAPPINGS = new HashMap<>();
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("enchantment/enchantment_type_mappings",
ClientVersion.V_1_12,
ClientVersion.V_1_13,
ClientVersion.V_1_14,
ClientVersion.V_1_16);
public static EnchantmentType define(String key) {
TypesBuilderData data = TYPES_BUILDER.define(key);
EnchantmentType enchantmentType = new EnchantmentType() {
private final int[] ids = data.getData();
@Override
public ResourceLocation getName() {
return data.getName();
}
@Override
public int getId(ClientVersion version) {
int index = TYPES_BUILDER.getDataIndex(version);
return ids[index];
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EnchantmentType) {
return getName() == ((EnchantmentType) obj).getName();
}
return false;
}
};
ENCHANTMENT_TYPE_MAPPINGS.put(enchantmentType.getName().toString(), enchantmentType);
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EnchantmentType> typeIdMap = ENCHANTMENT_TYPE_ID_MAPPINGS.computeIfAbsent((byte) index, k -> new HashMap<>());
typeIdMap.put(enchantmentType.getId(version), enchantmentType);
}
return enchantmentType;
}
@Nullable
public static EnchantmentType getByName(String name) {
return ENCHANTMENT_TYPE_MAPPINGS.get(name);
}
@Nullable
public static EnchantmentType getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, EnchantmentType> typeIdMap = ENCHANTMENT_TYPE_ID_MAPPINGS.get((byte) index);
return typeIdMap.get(id);
}
public static final EnchantmentType ALL_DAMAGE_PROTECTION = define("protection");
public static final EnchantmentType FIRE_PROTECTION = define("fire_protection");
public static final EnchantmentType FALL_PROTECTION = define("feather_falling");
public static final EnchantmentType BLAST_PROTECTION = define("blast_protection");
public static final EnchantmentType PROJECTILE_PROTECTION = define("projectile_protection");
public static final EnchantmentType RESPIRATION = define("respiration");
public static final EnchantmentType AQUA_AFFINITY = define("aqua_affinity");
public static final EnchantmentType THORNS = define("thorns");
public static final EnchantmentType DEPTH_STRIDER = define("depth_strider");
public static final EnchantmentType FROST_WALKER = define("frost_walker");
public static final EnchantmentType BINDING_CURSE = define("binding_curse");
public static final EnchantmentType SOUL_SPEED = define("soul_speed");
public static final EnchantmentType SHARPNESS = define("sharpness");
public static final EnchantmentType SMITE = define("smite");
public static final EnchantmentType BANE_OF_ARTHROPODS = define("bane_of_arthropods");
public static final EnchantmentType KNOCKBACK = define("knockback");
public static final EnchantmentType FIRE_ASPECT = define("fire_aspect");
public static final EnchantmentType MOB_LOOTING = define("looting");
public static final EnchantmentType SWEEPING_EDGE = define("sweeping");
public static final EnchantmentType BLOCK_EFFICIENCY = define("efficiency");
public static final EnchantmentType SILK_TOUCH = define("silk_touch");
public static final EnchantmentType UNBREAKING = define("unbreaking");
public static final EnchantmentType BLOCK_FORTUNE = define("fortune");
public static final EnchantmentType POWER_ARROWS = define("power");
public static final EnchantmentType PUNCH_ARROWS = define("punch");
public static final EnchantmentType FLAMING_ARROWS = define("flame");
public static final EnchantmentType INFINITY_ARROWS = define("infinity");
public static final EnchantmentType FISHING_LUCK = define("luck_of_the_sea");
public static final EnchantmentType FISHING_SPEED = define("lure");
public static final EnchantmentType LOYALTY = define("loyalty");
public static final EnchantmentType IMPALING = define("impaling");
public static final EnchantmentType RIPTIDE = define("riptide");
public static final EnchantmentType CHANNELING = define("channeling");
public static final EnchantmentType MULTISHOT = define("multishot");
public static final EnchantmentType QUICK_CHARGE = define("quick_charge");
public static final EnchantmentType PIERCING = define("piercing");
public static final EnchantmentType MENDING = define("mending");
public static final EnchantmentType VANISHING_CURSE = define("vanishing_curse");
}
@@ -16,31 +16,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.npc;
package com.github.retrooper.packetevents.protocol.item.type;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Set;
public class NPCManager {
private final Map<Integer, NPC> npcMap = new ConcurrentHashMap<>();
public interface ItemType extends MappedEntity {
int getMaxAmount();
int getMaxDurability();
boolean isMusicDisc();
ItemType getCraftRemainder();
@Nullable
public NPC getNPCById(int entityID) {
return npcMap.get(entityID);
}
StateType getPlacedType();
public Collection<NPC> getNPCList() {
return npcMap.values();
}
Set<ItemTypes.ItemAttribute> getAttributes();
public void registerNPC(NPC npc) {
npcMap.put(npc.getEntityId(), npc);
}
public void unregisterNPC(NPC npc) {
npcMap.remove(npc.getEntityId());
}
boolean hasAttribute(ItemTypes.ItemAttribute attribute);
}
@@ -0,0 +1,12 @@
package com.github.retrooper.packetevents.protocol.mapper;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
public interface LegacyMappedEntity {
ResourceLocation getName();
int getLegacyId(ClientVersion version);
}
@@ -0,0 +1,28 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.mapper;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.resources.ResourceLocation;
public interface MappedEntity {
ResourceLocation getName();
int getId(ClientVersion version);
}
@@ -16,12 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.retrooper.packetevents.utils.google;
package com.github.retrooper.packetevents.protocol.mapper;
import java.util.Optional;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
public class OptionalUtils {
public static Optional<?> convertToJavaOptional(Object googleOptional) {
return Optional.of(GoogleOptionalUtils.getOptionalValue(googleOptional));
public interface StaticMappedEntity extends MappedEntity{
int getId();
default int getId(ClientVersion version) {
return getId();
}
}
@@ -0,0 +1,37 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public abstract class NBT {
public abstract NBTType<?> getType();
@Override
public abstract boolean equals(Object other);
@Override
public abstract int hashCode();
@Override
public String toString() {
return "nbt";
}
public abstract NBT copy();
}
@@ -0,0 +1,92 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTByte extends NBTNumber {
protected final byte value;
public NBTByte(byte value) {
this.value = value;
}
public NBTByte(boolean value) {
this((byte) (value ? 1 : 0));
}
@Override
public NBTType<NBTByte> getType() {
return NBTType.BYTE;
}
@Override
public byte getAsByte() {
return value;
}
@Override
public short getAsShort() {
return value;
}
@Override
public int getAsInt() {
return value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public int hashCode() {
return Byte.hashCode(value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTByte other = (NBTByte) obj;
return value == other.value;
}
@Override
public NBTByte copy() {
return this;
}
}
@@ -0,0 +1,65 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Arrays;
public class NBTByteArray extends NBT {
protected final byte[] array;
public NBTByteArray(byte[] array) {
this.array = array;
}
@Override
public NBTType<NBTByteArray> getType() {
return NBTType.BYTE_ARRAY;
}
public byte[] getValue() {
return array;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTByteArray other = (NBTByteArray) obj;
return Arrays.equals(array, other.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
public NBTByteArray copy() {
byte[] abyte = new byte[this.array.length];
System.arraycopy(this.array, 0, abyte, 0, this.array.length);
return new NBTByteArray(abyte);
}
}
@@ -0,0 +1,226 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class NBTCompound extends NBT {
protected final Map<String, NBT> tags = new LinkedHashMap<>();
@Override
public NBTType<NBTCompound> getType() {
return NBTType.COMPOUND;
}
public boolean isEmpty() {
return tags.isEmpty();
}
public Set<String> getTagNames() {
return Collections.unmodifiableSet(tags.keySet());
}
public Map<String, NBT> getTags() {
return Collections.unmodifiableMap(tags);
}
public NBT getTagOrThrow(String key) {
NBT tag = getTagOrNull(key);
if (tag == null) {
throw new IllegalStateException(MessageFormat.format("NBT {0} does not exist", key));
}
return tag;
}
public NBT getTagOrNull(String key) {
return tags.get(key);
}
@SuppressWarnings("unchecked")
public <T extends NBT> T getTagOfTypeOrThrow(String key, Class<T> type) {
NBT tag = getTagOrThrow(key);
if (type.isInstance(tag)) {
return (T) tag;
} else {
throw new IllegalStateException(MessageFormat.format("NBT {0} has unexpected type, expected {1}, but got {2}", key, type, tag.getClass()));
}
}
@SuppressWarnings("unchecked")
public <T extends NBT> T getTagOfTypeOrNull(String key, Class<T> type) {
NBT tag = getTagOrNull(key);
if (type.isInstance(tag)) {
return (T) tag;
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends NBT> NBTList<T> getTagListOfTypeOrThrow(String key, Class<T> type) {
NBTList<? extends NBT> list = getTagOfTypeOrThrow(key, NBTList.class);
if (!type.isAssignableFrom(list.getTagsType().getNBTClass())) {
throw new IllegalStateException(MessageFormat.format("NBTList {0} tags type has unexpected type, expected {1}, but got {2}", key, type, list.getTagsType().getNBTClass()));
}
return (NBTList<T>) list;
}
@SuppressWarnings("unchecked")
public <T extends NBT> NBTList<T> getTagListOfTypeOrNull(String key, Class<T> type) {
NBTList<? extends NBT> list = getTagOfTypeOrNull(key, NBTList.class);
if ((list != null) && type.isAssignableFrom(list.getTagsType().getNBTClass())) {
return (NBTList<T>) list;
}
return null;
}
public NBTCompound getCompoundTagOrThrow(String key) {
return getTagOfTypeOrThrow(key, NBTCompound.class);
}
public NBTCompound getCompoundTagOrNull(String key) {
return getTagOfTypeOrNull(key, NBTCompound.class);
}
public NBTNumber getNumberTagOrThrow(String key) {
return getTagOfTypeOrThrow(key, NBTNumber.class);
}
public NBTNumber getNumberTagOrNull(String key) {
return getTagOfTypeOrNull(key, NBTNumber.class);
}
public NBTString getStringTagOrThrow(String key) {
return getTagOfTypeOrThrow(key, NBTString.class);
}
public NBTString getStringTagOrNull(String key) {
return getTagOfTypeOrNull(key, NBTString.class);
}
public NBTList<NBTCompound> getCompoundListTagOrThrow(String key) {
return getTagListOfTypeOrThrow(key, NBTCompound.class);
}
public NBTList<NBTCompound> getCompoundListTagOrNull(String key) {
return getTagListOfTypeOrNull(key, NBTCompound.class);
}
public NBTList<NBTNumber> getNumberTagListTagOrThrow(String key) {
return getTagListOfTypeOrThrow(key, NBTNumber.class);
}
public NBTList<NBTNumber> getNumberListTagOrNull(String key) {
return getTagListOfTypeOrNull(key, NBTNumber.class);
}
public NBTList<NBTString> getStringListTagOrThrow(String key) {
return getTagListOfTypeOrThrow(key, NBTString.class);
}
public NBTList<NBTString> getStringListTagOrNull(String key) {
return getTagListOfTypeOrNull(key, NBTString.class);
}
public String getStringTagValueOrThrow(String key) {
return getStringTagOrThrow(key).getValue();
}
public String getStringTagValueOrNull(String key) {
NBT tag = getTagOrNull(key);
if (tag instanceof NBTString) {
return ((NBTString) tag).getValue();
}
return null;
}
public String getStringTagValueOrDefault(String key, String defaultValue) {
NBT tag = getTagOrNull(key);
if (tag instanceof NBTString) {
return ((NBTString) tag).getValue();
}
return defaultValue;
}
public NBT removeTag(String key) {
return tags.remove(key);
}
@SuppressWarnings("unchecked")
public <T extends NBT> T removeTagAndReturnIfType(String key, Class<T> type) {
NBT tag = removeTag(key);
if (type.isInstance(tag)) {
return (T) tag;
}
return null;
}
@SuppressWarnings("unchecked")
public <T extends NBT> NBTList<T> removeTagAndReturnIfListType(String key, Class<T> type) {
NBTList<?> list = removeTagAndReturnIfType(key, NBTList.class);
if ((list != null) && type.isAssignableFrom(list.getTagsType().getNBTClass())) {
return (NBTList<T>) list;
}
return null;
}
public void setTag(String key, NBT tag) {
if (tag != null) {
tags.put(key, tag);
} else {
tags.remove(key);
}
}
public NBTCompound copy() {
NBTCompound clone = new NBTCompound();
for (Map.Entry<String, NBT> entry : tags.entrySet()) {
clone.setTag(entry.getKey(), entry.getValue().copy());
}
return clone;
}
public boolean getBoolean(String string) {
NBTByte nbtByte = this.getTagOfTypeOrNull(string, NBTByte.class);
// Empty byte tags are considered 0
byte byteValue = nbtByte == null ? 0 : nbtByte.getAsByte();
return byteValue != 0;
}
@Override
public boolean equals(Object other) {
if (other instanceof NBTCompound) {
if (isEmpty() && ((NBTCompound) other).isEmpty()) {
return true;
}
return tags.equals(((NBTCompound) other).tags);
}
return false;
}
@Override
public int hashCode() {
return tags.hashCode();
}
}
@@ -0,0 +1,88 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTDouble extends NBTNumber {
protected final double value;
public NBTDouble(double value) {
this.value = value;
}
@Override
public NBTType<NBTDouble> getType() {
return NBTType.DOUBLE;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return (int) value;
}
@Override
public long getAsLong() {
return (long) value;
}
@Override
public float getAsFloat() {
return (float) value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public int hashCode() {
return Double.hashCode(value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTDouble other = (NBTDouble) obj;
return Double.doubleToLongBits(value) == Double.doubleToLongBits(other.value);
}
@Override
public NBTDouble copy() {
return this;
}
}
@@ -0,0 +1,50 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTEnd extends NBT {
public static final NBTEnd INSTANCE = new NBTEnd();
@Override
public NBTType<NBTEnd> getType() {
return NBTType.END;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return getClass() == obj.getClass();
}
@Override
public int hashCode() {
return 0;
}
@Override
public NBTEnd copy() {
return this;
}
}
@@ -0,0 +1,88 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTFloat extends NBTNumber {
protected final float value;
public NBTFloat(float value) {
this.value = value;
}
@Override
public NBTType<NBTFloat> getType() {
return NBTType.FLOAT;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return (int) value;
}
@Override
public long getAsLong() {
return (long) value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTFloat other = (NBTFloat) obj;
return Float.floatToIntBits(value) == Float.floatToIntBits(other.value);
}
@Override
public int hashCode() {
return Float.hashCode(value);
}
@Override
public NBTFloat copy() {
return this;
}
}
@@ -0,0 +1,88 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTInt extends NBTNumber {
protected final int value;
public NBTInt(int value) {
this.value = value;
}
@Override
public NBTType<NBTInt> getType() {
return NBTType.INT;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTInt other = (NBTInt) obj;
return value == other.value;
}
@Override
public int hashCode() {
return Integer.hashCode(value);
}
@Override
public NBTInt copy() {
return this;
}
}
@@ -0,0 +1,66 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Arrays;
public class NBTIntArray extends NBT {
protected final int[] array;
public NBTIntArray(int[] array) {
this.array = array;
}
@Override
public NBTType<NBTIntArray> getType() {
return NBTType.INT_ARRAY;
}
public int[] getValue() {
return array;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTIntArray other = (NBTIntArray) obj;
return Arrays.equals(array, other.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
@Override
public NBTIntArray copy() {
int[] aint = new int[this.array.length];
System.arraycopy(this.array, 0, aint, 0, this.array.length);
return new NBTIntArray(aint);
}
}
@@ -0,0 +1,125 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class NBTList<T extends NBT> extends NBT {
protected final NBTType<T> type;
protected final List<T> tags = new ArrayList<>();
public NBTList(NBTType<T> type) {
this.type = type;
}
public NBTList(NBTType<T> type, List<T> tags) {
this.type = type;
this.tags.addAll(tags);
}
public static NBTList<NBTCompound> createCompoundList() {
return new NBTList<>(NBTType.COMPOUND);
}
public static NBTList<NBTString> createStringList() {
return new NBTList<>(NBTType.STRING);
}
@Override
@SuppressWarnings("rawtypes")
public NBTType<NBTList> getType() {
return NBTType.LIST;
}
public NBTType<T> getTagsType() {
return type;
}
public boolean isEmpty() {
return tags.isEmpty();
}
public int size() {
return tags.size();
}
public List<T> getTags() {
return Collections.unmodifiableList(tags);
}
public T getTag(int index) {
return tags.get(index);
}
public void setTag(int index, T tag) {
validateAddTag(tag);
tags.set(index, tag);
}
public void addTag(int index, T tag) {
validateAddTag(tag);
tags.add(index, tag);
}
public void addTag(T tag) {
validateAddTag(tag);
tags.add(tag);
}
protected void validateAddTag(T tag) {
if (type != tag.getType()) {
throw new IllegalArgumentException(MessageFormat.format("Invalid tag type. Expected {0}, got {1}.", type.getNBTClass(), tag.getClass()));
}
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTList<T> other = (NBTList<T>) obj;
return Objects.equals(type, other.type) && Objects.equals(tags, other.tags);
}
@Override
public int hashCode() {
return Objects.hash(type, tags);
}
@Override
public NBTList<T> copy() {
List<T> newTags = new ArrayList<>();
for (T tag : this.tags) {
newTags.add((T) tag.copy());
}
return new NBTList<>(type, newTags);
}
}
@@ -0,0 +1,88 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTLong extends NBTNumber {
protected final long value;
public NBTLong(long value) {
this.value = value;
}
@Override
public NBTType<NBTLong> getType() {
return NBTType.LONG;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return (short) value;
}
@Override
public int getAsInt() {
return (int) value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTLong other = (NBTLong) obj;
return value == other.value;
}
@Override
public int hashCode() {
return Long.hashCode(value);
}
@Override
public NBTLong copy() {
return this;
}
}
@@ -0,0 +1,66 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Arrays;
public class NBTLongArray extends NBT {
protected final long[] array;
public NBTLongArray(long[] array) {
this.array = array;
}
@Override
public NBTType<NBTLongArray> getType() {
return NBTType.LONG_ARRAY;
}
public long[] getValue() {
return array;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTLongArray other = (NBTLongArray) obj;
return Arrays.equals(array, other.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
@Override
public NBTLongArray copy() {
long[] along = new long[this.array.length];
System.arraycopy(this.array, 0, along, 0, this.array.length);
return new NBTLongArray(along);
}
}
@@ -0,0 +1,35 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public abstract class NBTNumber extends NBT {
public abstract byte getAsByte();
public abstract short getAsShort();
public abstract int getAsInt();
public abstract long getAsLong();
public abstract float getAsFloat();
public abstract double getAsDouble();
}
@@ -0,0 +1,87 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
public class NBTShort extends NBTNumber {
protected final short value;
public NBTShort(short value) {
this.value = value;
}
@Override
public NBTType<NBTShort> getType() {
return NBTType.SHORT;
}
@Override
public byte getAsByte() {
return (byte) value;
}
@Override
public short getAsShort() {
return value;
}
@Override
public int getAsInt() {
return value;
}
@Override
public long getAsLong() {
return value;
}
@Override
public float getAsFloat() {
return value;
}
@Override
public double getAsDouble() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTShort other = (NBTShort) obj;
return value == other.value;
}
@Override
public int hashCode() {
return Short.hashCode(value);
}
@Override
public NBTShort copy() {
return this;
}
}
@@ -0,0 +1,64 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Objects;
public class NBTString extends NBT {
protected final String string;
public NBTString(String string) {
this.string = string;
}
@Override
public NBTType<NBTString> getType() {
return NBTType.STRING;
}
public String getValue() {
return string;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTString other = (NBTString) obj;
return Objects.equals(string, other.string);
}
@Override
public int hashCode() {
return Objects.hash(string);
}
@Override
public NBTString copy() {
return this;
}
}
@@ -0,0 +1,76 @@
/*
* This file is part of ProtocolSupport - https://github.com/ProtocolSupport/ProtocolSupport
* Copyright (C) 2021 ProtocolSupport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.protocol.nbt;
import java.util.Objects;
public class NBTType<T extends NBT> {
public static final NBTType<NBTEnd> END = new NBTType<>(NBTEnd.class);
public static final NBTType<NBTByte> BYTE = new NBTType<>(NBTByte.class);
public static final NBTType<NBTShort> SHORT = new NBTType<>(NBTShort.class);
public static final NBTType<NBTInt> INT = new NBTType<>(NBTInt.class);
public static final NBTType<NBTLong> LONG = new NBTType<>(NBTLong.class);
public static final NBTType<NBTFloat> FLOAT = new NBTType<>(NBTFloat.class);
public static final NBTType<NBTDouble> DOUBLE = new NBTType<>(NBTDouble.class);
public static final NBTType<NBTByteArray> BYTE_ARRAY = new NBTType<>(NBTByteArray.class);
public static final NBTType<NBTString> STRING = new NBTType<>(NBTString.class);
@SuppressWarnings("rawtypes")
public static final NBTType<NBTList> LIST = new NBTType<>(NBTList.class);
public static final NBTType<NBTCompound> COMPOUND = new NBTType<>(NBTCompound.class);
public static final NBTType<NBTIntArray> INT_ARRAY = new NBTType<>(NBTIntArray.class);
public static final NBTType<NBTLongArray> LONG_ARRAY = new NBTType<>(NBTLongArray.class);
protected final Class<T> clazz;
protected NBTType(Class<T> clazz) {
this.clazz = clazz;
}
public Class<T> getNBTClass() {
return clazz;
}
@Override
public String toString() {
return clazz.getSimpleName();
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NBTType<T> other = (NBTType<T>) obj;
return Objects.equals(clazz, other.clazz);
}
@Override
public int hashCode() {
return clazz.hashCode();
}
}
Loaded 100 of 647 files, more files were not shown because too many files have changed in this diff. Show more