Prerequisites
Networking and TCP/IP
Section titled “Networking and TCP/IP”Previously, we mentioned that PacketEvents is a library that facilitates the transmission and processing of packets on Minecraft. Thus, some networking knowledge is paramount. Minecraft Java Edition (unlike Bedrock Edition) relies on the TCP/IP protocol, and thus it would be great to have some knowledge about that. In summary, there are some promises that are made to you, as a developer, when working with the TCP/IP protocol. First, the order in which packets are sent is the same order in which packets are received.
Another promise that is made to you is that dropped packets are rescheduled. TCP/IP is known for its high reliability on packet delivery. This is a promise that other protocols, such as UDP/IP, do not deliver on.
Minecraft Protocol
Section titled “Minecraft Protocol”Some knowledge of the Minecraft Protocol is necessary. PacketEvents simply implements the protocol; it is not here to explain all of it to you. The protocol changes nearly each Minecraft update. It’s quite difficult to write documentation for a protocol that changes all the time. If you want your software operational after Minecraft updates, you will have to update PacketEvents and possibly follow up with the Minecraft Protocol changes. The community maintains a wiki that covers the Minecraft protocol with high accuracy.
Threading & Concurrency
Section titled “Threading & Concurrency”Experience with threading and concurrency is also essential. Threading allows developers to execute tasks in parallel. Here’s an analogy we tend to use:
Not only is concurrency important in the kitchen, but it’s even more important in software development. Minecraft leverages concurrency to a degree. In Minecraft, network communication processing is handled by one (or multiple) worker thread(s). Logic, such as NPC behavior and world generation, is handled by the so-called ‘main thread.’ Since we’re dealing with a multi-threaded system, you’re going to have to design your software with caution. Multi-threading has its benefits (performance-wise), but it can cause developers to run into many issues. Suppose, for instance, two threads attempt to modify/access a particular piece of information at the same time. You may need to account for that. Thus, we suggest that you familiarize yourself with concurrency & threading in Java before interacting with our library.