How retrooper/packetevents works
Main Components and Modules
• Core API Module ("api"): At the heart of the project, this module contains the base interfaces, event classes, packet event management (like PacketEvents, EventManager, and various event types), protocol definitions, and utilities that support packet manipulation.
• Platform-Specific Wrappers: There are several modules that provide platform-specific integrations. For instance:
• bungeecord (for BungeeCord servers)
• fabric (for Fabric-based servers/clients)
• spigot (for Spigot/Bukkit)
• sponge (for Sponge)
• velocity (for Velocity)
These modules include specialized injectors (channel initializers, pipeline injectors), factory builders, handlers/decoders/encoders, and manager implementations tailored for each platform.
• Netty-Common Module ("netty-common"): This module wraps lower-level networking functionality based on Netty. It contains implementations for buffer operations, channel management, and integration with the high-performance networking layer.
• Build and Utility Modules:
• buildSrc contains custom Gradle plugins and tasks for versioning, mapping compression strategies, and build conventions.
• Patch tools and mappings files (under “patch” and “mappings”) support Minecraft protocol compatibility and registry integrations.
Relationships and Interactions
• At the center, the Core API (api module) provides the interfaces and abstract event types that are used and extended by platform-specific modules.
• Each platform-specific module (bungeecord, fabric, spigot, sponge, velocity) acts as an adapter. They rely on the API to capture events and then call into their own implementations (injectors, wrappers, manager classes) to integrate with the respective platform’s network and event frameworks.
• The Netty-common module offers the underlying networking layer that these platform modules may call to perform tasks like channel injection, byte buffer management, and packet encoding/decoding.
• BuildSrc and mapping/patche modules serve as supportive infrastructure. They are used during the build and packaging phase and sometimes for runtime mapping or protocol translation.
Architectural Patterns and Design Principles
• Modularity: The separation into distinct modules (API, platform wrappers, common Netty utilities) ensures that common functionality is shared while platform specifics are encapsulated.
• Abstraction and Adaptation: The API defines generic packet and event interfaces; each platform-specific module implements these abstractions to hook into the corresponding environment.
• Event-Driven Architecture: The design is based largely on dispatching events (such as packet receive/send events, login events, etc.). Components communicate through well-defined interfaces.
• Dependency Injection and Inversion of Control: The wrapper classes and injector components are designed to plug into a server’s networking pipeline, often reusing a common provider (via factories or builder patterns).