### PacketEvent.fromServer Basic Usage Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-event.md Example of instantiating a basic server packet event. ```java PacketEvent event = PacketEvent.fromServer(source, packet, player); ``` -------------------------------- ### PacketEvent.fromClient Basic Usage Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-event.md Example of instantiating a basic client packet event. ```java PacketEvent event = PacketEvent.fromClient(source, packet, player); ``` -------------------------------- ### Entity Spawn Packet Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Example of reading multiple field types from an entity spawn packet. ```java @Override public void onPacketSending(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Server.SPAWN_ENTITY) { PacketContainer packet = event.getPacket(); // Entity spawn structure int entityId = packet.getIntegers().read(0); UUID uuid = packet.getUUIDs().read(0); double x = packet.getDoubles().read(0); double y = packet.getDoubles().read(1); double z = packet.getDoubles().read(2); System.out.println("Spawning entity " + entityId + " at (" + x + ", " + y + ", " + z + ")"); } } ``` -------------------------------- ### WrappedGameProfile Usage Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Example showing how to instantiate a new WrappedGameProfile. ```java WrappedGameProfile profile = new WrappedGameProfile(uuid, playerName); ``` -------------------------------- ### Creating Explosion Packet Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Example of constructing a new server explosion packet and writing various field types. ```java PacketContainer explosion = new PacketContainer( PacketType.Play.Server.EXPLOSION, true // Force defaults ); // Structure: [0-2]=X,Y,Z coords, [3]=radius, [4]=blocks, [5]=velocity explosion.getDoubles() .write(0, player.getLocation().getX()) .write(1, player.getLocation().getY()) .write(2, player.getLocation().getZ()); explosion.getFloat().write(0, 3.0F); // Radius explosion.getBlockPositionCollectionModifier() .write(0, new ArrayList<>()); // Affected blocks explosion.getVectors() .write(0, new Vector(0, 0, 0)); // Knockback manager.sendServerPacket(player, explosion); ``` -------------------------------- ### onPacketReceiving Simulate Player Action Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Example of detecting a PLAYER_DIGGING packet and sending a message to the player. ```java @Override public void onPacketReceiving(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Client.PLAYER_DIGGING) { Player player = event.getPlayer(); player.sendMessage("You tried to dig!"); } } ``` -------------------------------- ### Check Protocol Version Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Example demonstrating how to retrieve and log a player's protocol version. ```java ProtocolManager manager = ProtocolLibrary.getProtocolManager(); Player player = Bukkit.getPlayer("PlayerName"); int protocolVersion = manager.getProtocolVersion(player); if (protocolVersion != Integer.MIN_VALUE) { plugin.getLogger().info("Player protocol version: " + protocolVersion); } ``` -------------------------------- ### ProtocolLibrary getPlugin Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieves the ProtocolLib plugin instance to access its description and version information. ```java Plugin protocolLib = ProtocolLibrary.getPlugin(); String version = protocolLib.getDescription().getVersion(); plugin.getLogger().info("ProtocolLib version: " + version); ``` -------------------------------- ### Handle Version-Specific Logic Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Example showing how to execute different logic based on the player's protocol version. ```java int version = manager.getProtocolVersion(player); if (version >= 761) { // 1.19.3 and above // Handle newer protocol } else if (version >= 757) { // 1.18.1 // Handle 1.18.1 protocol } ``` -------------------------------- ### Send Simple Packet Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Example of creating and sending a chat packet to a player. ```java PacketContainer packet = manager.createPacket(PacketType.Play.Server.CHAT); packet.getStrings().write(0, "Hello, player!"); manager.sendServerPacket(player, packet, true); ``` -------------------------------- ### Implement Plugin Initialization Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md A complete example showing how to retrieve the ProtocolManager, register packet listeners, and handle lifecycle events in a JavaPlugin. ```java public class MyProtocolPlugin extends JavaPlugin { private ProtocolManager protocolManager; private ProtocolScheduler scheduler; @Override public void onLoad() { // Initialize ProtocolLib if needed plugin.getLogger().info("Loading ProtocolLib..."); } @Override public void onEnable() { try { // Get the protocol manager protocolManager = ProtocolLibrary.getProtocolManager(); if (protocolManager == null) { getLogger().severe("ProtocolLib not found!"); setEnabled(false); return; } // Get scheduler scheduler = ProtocolLibrary.getScheduler(); // Get configuration ProtocolConfig config = ProtocolLibrary.getConfig(); // Add packet listeners protocolManager.addPacketListener(new ChatListener(this)); protocolManager.addPacketListener(new MovementListener(this)); getLogger().info("ProtocolLib version: " + ProtocolLibrary.getPlugin().getDescription().getVersion()); // Optionally disable updates if (getConfig().getBoolean("disable-updates", false)) { ProtocolLibrary.disableUpdates(); } } catch (Exception e) { getLogger().severe("Failed to initialize ProtocolLib!"); e.printStackTrace(); setEnabled(false); } } @Override public void onDisable() { // ProtocolLib automatically removes all listeners for this plugin protocolManager.removePacketListeners(this); getLogger().info("ProtocolLib listeners unregistered."); } public ProtocolManager getProtocolManager() { return protocolManager; } } ``` -------------------------------- ### ProtocolLibrary Initialization Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Demonstrates how to retrieve the ProtocolManager and register a packet listener within a JavaPlugin's onEnable method. ```java public class MyPlugin extends JavaPlugin { private ProtocolManager protocolManager; @Override public void onEnable() { // Get the protocol manager protocolManager = ProtocolLibrary.getProtocolManager(); // Add listeners protocolManager.addPacketListener(new MyPacketAdapter(this)); } } ``` -------------------------------- ### Use ListenerOptions in PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Example of configuring a PacketAdapter to execute synchronously using ListenerOptions. ```java new PacketAdapter( plugin, ListenerPriority.NORMAL, packetTypes, ListenerOptions.SYNC ) { // Will execute synchronously }; ``` -------------------------------- ### ProtocolLibrary Send Packet Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Shows how to create and send a server chat packet using the ProtocolManager. ```java ProtocolManager manager = ProtocolLibrary.getProtocolManager(); PacketContainer packet = manager.createPacket(PacketType.Play.Server.CHAT); packet.getStrings().write(0, "Hello!"); manager.sendServerPacket(player, packet); ``` -------------------------------- ### PacketAdapter Complete Builder Usage Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Example demonstrating the fluent builder pattern to configure a PacketAdapter and register it with the ProtocolManager. ```java PacketAdapter adapter = new PacketAdapter( PacketAdapter.params(plugin, PacketType.Play.Client.CHAT) .listenerPriority(ListenerPriority.HIGH) .connectionSide(ConnectionSide.CLIENT_SIDE) .options(ListenerOptions.SYNC) .gamePhase(GamePhase.PLAYING) ) { @Override public void onPacketReceiving(PacketEvent event) { String message = event.getPacket().getStrings().read(0); if (message.contains("banned_word")) { event.setCancelled(true); } } @Override public void onPacketSending(PacketEvent event) { // This won't be called since we're CLIENT_SIDE only } }; ProtocolLibrary.getProtocolManager().addPacketListener(adapter); ``` -------------------------------- ### Reading Chat Message Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Example of reading a string field from a client chat packet. ```java @Override public void onPacketReceiving(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Client.CHAT) { PacketContainer packet = event.getPacket(); // Chat packet structure: [0] = message string String message = packet.getStrings().read(0); System.out.println("Player said: " + message); } } ``` -------------------------------- ### Simulate Player Action Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Example of simulating a player sending a chat message packet. ```java // Simulate a player sending a chat message PacketContainer chatPacket = manager.createPacket(PacketType.Play.Client.CHAT); chatPacket.getStrings().write(0, "This is a simulated message"); manager.receiveClientPacket(player, chatPacket, true); ``` -------------------------------- ### Collection Access Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Reading a collection of block positions from an explosion packet. ```java // Explosion packet Collection affected = packet.getBlockPositionCollectionModifier().read(0); ``` -------------------------------- ### ProtocolLibrary getConfig Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieves the configuration object to access settings like debug mode and update intervals. ```java ProtocolConfig config = ProtocolLibrary.getConfig(); boolean debug = config.isDebug(); int updateInterval = config.getUpdateInterval(); ``` -------------------------------- ### Use ListenerPriority in PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Example of initializing a PacketAdapter with a specific ListenerPriority. ```java new PacketAdapter(plugin, ListenerPriority.HIGH, packetTypes) { @Override public void onPacketReceiving(PacketEvent event) { // Called with HIGH priority } }; ``` -------------------------------- ### Primitive Access Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Reading primitive values from an animation packet. ```java // Animation packet structure byte byte0 = packet.getBytes().read(0); // Animation type int int0 = packet.getIntegers().read(0); // Entity ID float float0 = packet.getFloat().read(0); // Rotation ``` -------------------------------- ### Modifying Position Packet Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Example of reading and writing double values to modify player position. ```java @Override public void onPacketReceiving(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Client.PLAYER_POSITION) { PacketContainer packet = event.getPacket(); // Position packet structure: [0]=X, [1]=Y, [2]=Z, [3]=Ground double x = packet.getDoubles().read(0); double y = packet.getDoubles().read(1); double z = packet.getDoubles().read(2); // Teleport up 10 blocks packet.getDoubles().write(1, y + 10.0); } } ``` -------------------------------- ### ProtocolLibrary getScheduler Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieves the protocol scheduler instance for scheduling asynchronous tasks. ```java ProtocolScheduler scheduler = ProtocolLibrary.getScheduler(); // Use for scheduling async tasks ``` -------------------------------- ### PacketAdapter Priority Chain Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Demonstrates how listeners with different priorities interact, where a HIGH priority modifier affects the message seen by a MONITOR priority logger. ```java // Plugin A - Chat modifier (HIGH) new PacketAdapter(pluginA, ListenerPriority.HIGH, PacketType.Play.Client.CHAT) { @Override public void onPacketReceiving(PacketEvent event) { String msg = event.getPacket().getStrings().read(0); event.getPacket().getStrings().write(0, msg.toUpperCase()); } }; // Plugin B - Chat monitor (MONITOR) new PacketAdapter(pluginB, ListenerPriority.MONITOR, PacketType.Play.Client.CHAT) { @Override public void onPacketReceiving(PacketEvent event) { String msg = event.getPacket().getStrings().read(0); logChatMessage(msg); // Sees modified message from plugin A } }; ``` -------------------------------- ### onPacketSending Cancel Specific Packet Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Example of cancelling a CLOSE_WINDOW packet to prevent a window from closing. ```java @Override public void onPacketSending(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Server.CLOSE_WINDOW) { event.setCancelled(true); // Keep window open } } ``` -------------------------------- ### Send packets using standard Bukkit API Source: https://github.com/dmulloy2/protocollib/blob/master/Readme.md Example of sending a packet using standard, non-abstracted Bukkit/CraftBukkit methods. ```java PacketPlayOutExplosion fakeExplosion = new PacketPlayOutExplosion( player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), 3.0F, new ArrayList<>(), new Vec3D( player.getVelocity().getX() + 1, player.getVelocity().getY() + 1, player.getVelocity().getZ() + 1 ) ); ((CraftPlayer) player).getHandle().b.a(fakeExplosion); ``` -------------------------------- ### Accessing ProtocolManager and Adding a Packet Listener Source: https://github.com/dmulloy2/protocollib/wiki/ProtocolManager Demonstrates how to obtain the ProtocolManager instance and add a packet listener. This is a common starting point for any ProtocolLib integration. ```java import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolLibrary; @Override public void onEnable() { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); manager.addPacketListener(...); } ``` -------------------------------- ### Send packets using ProtocolLib Source: https://github.com/dmulloy2/protocollib/blob/master/Readme.md Example of sending a packet using the ProtocolLib PacketContainer API. ```java PacketContainer fakeExplosion = new PacketContainer(PacketType.Play.Server.EXPLOSION); fakeExplosion.getDoubles() .write(0, player.getLocation().getX()) .write(1, player.getLocation().getY()) .write(2, player.getLocation().getZ()); fakeExplosion.getFloat().write(0, 3.0F); fakeExplosion.getBlockPositionCollectionModifier().write(0, new ArrayList<>()); fakeExplosion.getVectors().write(0, player.getVelocity().add(new Vector(1, 1, 1))); protocolManager.sendServerPacket(player, fakeExplosion); ``` -------------------------------- ### Documentation File Structure Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/INDEX.md The directory layout for the ProtocolLib documentation, showing the organization of guides, API references, and configuration files. ```text output/ ├── README.md (Overview & navigation) ├── GUIDE.md (Getting started guide) ├── INDEX.md (This file) ├── types.md (Type reference) ├── errors.md (Error handling) ├── configuration.md (Configuration guide) └── api-reference/ ├── protocol-library.md (Entry point) ├── protocol-manager.md (Main API) ├── packet-adapter.md (Listeners) ├── packet-event.md (Events) ├── packet-container.md (Packet wrapper) ├── packet-type.md (Packet types) └── structure-modifier.md (Field access) ``` -------------------------------- ### Safe Field Access Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/structure-modifier.md Demonstrates using optionalRead and size checks to safely access packet fields. ```java @Override public void onPacketSending(PacketEvent event) { PacketContainer packet = event.getPacket(); // Safely read without null checks Optional name = packet.getStrings().optionalRead(0); name.ifPresent(n -> System.out.println("Name: " + n)); // Read with default String displayName = packet.getStrings() .optionalRead(0) .orElse("[No Name]"); // Check field count before access if (packet.getStrings().size() > 0) { String first = packet.getStrings().read(0); } } ``` -------------------------------- ### ProtocolLibrary getErrorReporter Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieves the error reporter to log or report specific warnings. ```java ErrorReporter reporter = ProtocolLibrary.getErrorReporter(); Report report = new Report(ReportType.REPORT_CANNOT_READ_FIELD); reporter.reportWarning(plugin, report); ``` -------------------------------- ### Configure ConnectionSide via PacketAdapter Builder Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Example of setting the connection side for a packet listener using the PacketAdapter builder pattern. ```java PacketAdapter.params(plugin, packetTypes) .connectionSide(ConnectionSide.CLIENT_SIDE) .build() ``` -------------------------------- ### updateEntity usage example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Demonstrates how to force a refresh of an entity for a list of observers. Must be executed on the main thread. ```java List observers = new ArrayList<>(Bukkit.getOnlinePlayers()); manager.updateEntity(entity, observers); ``` -------------------------------- ### Custom Error Handling with Report Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/errors.md Example of catching a FieldAccessException and reporting it using the ErrorReporter. ```java try { // ProtocolLib operation } catch (FieldAccessException e) { Report report = new Report(ReportType.REPORT_CANNOT_READ_FIELD); ProtocolLibrary.getErrorReporter().reportDetailed( plugin, report, new CaughtException(e) ); } ``` -------------------------------- ### Get Protocol Version Method Signature Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md The method signature for retrieving the protocol version of a specific player. ```java int getProtocolVersion(Player player) ``` -------------------------------- ### PacketAdapter Protocol Phase Filtering Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Examples of filtering PacketAdapters by specific protocol phases: Play, Status, and Login. ```java // Only Play phase packets new PacketAdapter(plugin, PacketType.Play.Server.CHAT) { // Handles play-phase packets only }; // Status phase packets new PacketAdapter(plugin, PacketType.Status.Server.SERVER_INFO) { // Handles server status queries }; // Login phase packets new PacketAdapter(plugin, PacketType.Login.Server.SUCCESS) { // Handles login success }; ``` -------------------------------- ### onPacketReceiving Censor Chat Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Example of filtering incoming chat packets and cancelling them if they contain a banned word. ```java @Override public void onPacketReceiving(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Client.CHAT) { PacketContainer packet = event.getPacket(); String message = packet.getStrings().read(0); if (message.contains("banned_word")) { event.setCancelled(true); event.getPlayer().sendMessage("That word is not allowed!"); } } } ``` -------------------------------- ### onPacketSending Modify Chat Message Example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Example of modifying an outgoing chat packet by converting the message to uppercase. ```java @Override public void onPacketSending(PacketEvent event) { if (event.getPacketType() == PacketType.Play.Server.CHAT) { PacketContainer packet = event.getPacket(); String message = packet.getStrings().read(0); packet.getStrings().write(0, message.toUpperCase()); } } ``` -------------------------------- ### Run build and test commands Source: https://github.com/dmulloy2/protocollib/blob/master/AGENTS.md Standard Gradle commands for executing tests and building the project artifact. ```shell ./gradlew test ./gradlew build shadowJar ``` -------------------------------- ### Get Current ErrorReporter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/errors.md Retrieves the current ErrorReporter instance from ProtocolLibrary. ```java ErrorReporter reporter = ProtocolLibrary.getErrorReporter(); ``` -------------------------------- ### Initialize ProtocolManager with error handling Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieve the ProtocolManager instance and throw an exception if initialization fails. ```java public ProtocolManager getProtocolManager() throws Exception { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); if (manager == null) { throw new Exception("ProtocolLib failed to initialize"); } return manager; } ``` -------------------------------- ### Trigger IllegalArgumentException in PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/errors.md Examples of invalid PacketAdapter construction that trigger an IllegalArgumentException. ```java new PacketAdapter(null, PacketType.Play.Server.CHAT) { // Throws // ... }; ``` ```java new PacketAdapter(plugin) { // No types provided - throws // ... }; ``` ```java new PacketAdapter(plugin, null, PacketType.Play.Server.CHAT) { // Null priority - throws // ... }; ``` -------------------------------- ### Add ProtocolLib Dependency with Gradle Source: https://github.com/dmulloy2/protocollib/wiki/Adding-ProtocolLib-as-a-Dependency Set up your Gradle project to use ProtocolLib by adding the repository to your build script and declaring the dependency. Use 'compileOnly' for compile-time inclusion. ```groovy repositories { maven { url "https://repo.dmulloy2.net/repository/public/" } } dependencies { compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "4.7.0"; } ``` -------------------------------- ### Trigger IllegalArgumentException in ProtocolManager Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/errors.md Examples of invalid ProtocolManager method calls that trigger an IllegalArgumentException. ```java manager.sendServerPacket(null, packet, true); // Null player - throws manager.sendServerPacket(player, null, true); // Null packet - throws ``` ```java manager.receiveClientPacket(null, packet, true); // Throws ``` -------------------------------- ### Configure backend in config.yml Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Specifies the backend software, typically auto-detected. ```yaml # Typically auto-detected based on server software backend: "default" ``` -------------------------------- ### PacketAdapter.params(Plugin, PacketType...) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Initializes a builder for fluent configuration of packet listener parameters. ```APIDOC ## PacketAdapter.params(Plugin, PacketType...) ### Description Starts a builder for fluent configuration of listener parameters. ### Method public static AdapterParameteters params(Plugin plugin, PacketType... types) ### Parameters - **plugin** (Plugin) - Required - The plugin instance - **types** (PacketType...) - Required - Initial packet types ### Returns - **AdapterParameteters** - Builder object for method chaining ``` -------------------------------- ### Send Packet Without Filters Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Example of sending a packet while bypassing listeners with priority below MONITOR. ```java // This bypasses all listeners with priority below MONITOR manager.sendServerPacket(player, packet, false); ``` -------------------------------- ### Build ListeningWhitelist Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Constructs a ListeningWhitelist using the builder pattern to define priority, packet types, game phase, and options. ```java ListeningWhitelist whitelist = ListeningWhitelist.newBuilder() .priority(ListenerPriority.NORMAL) .types(PacketType.Play.Server.CHAT) .gamePhase(GamePhase.PLAYING) .options(ListenerOptions.ASYNC) .build(); ``` -------------------------------- ### WrappedDataWatcher Usage Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Example showing how to retrieve a WrappedDataWatcher from a packet's data watcher modifier. ```java StructureModifier watcher = packet.getDataWatcherModifier(); WrappedDataWatcher watcherValue = watcher.read(0); ``` -------------------------------- ### Configure Listener for High-Frequency Packets Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Recommends using ListenerOptions.ASYNC for high-frequency packets like PLAYER_POSITION to maintain performance by offloading expensive operations. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.PLAYER_POSITION, ListenerOptions.ASYNC) { // Async for performance @Override public void onPacketReceiving(PacketEvent event) { // Minimal work - just read and process double x = event.getPacket().getDoubles().read(0); // Schedule expensive operations async processPositionAsync(event.getPlayer(), x); } }; ``` -------------------------------- ### getEntityTrackers usage example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Retrieves the list of players currently tracking a specific entity and logs the count. ```java List trackers = manager.getEntityTrackers(entity); plugin.getLogger().info("Entity tracked by " + trackers.size() + " players"); ``` -------------------------------- ### Configure Gradle dependency Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Add the ProtocolLib dependency to your build.gradle file using compileOnly. ```gradle compileOnly 'net.dmulloy2:ProtocolLib:5.4.0' ``` -------------------------------- ### getPacketType method and usage Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-container.md Retrieves the type of the packet. The example demonstrates checking if a packet is a chat packet. ```java public PacketType getPacketType() ``` ```java PacketType type = container.getPacketType(); if (type == PacketType.Play.Server.CHAT) { // Handle chat packet } ``` -------------------------------- ### Configure Listener for Low-Frequency Packets Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Recommends using ListenerOptions.SYNC for low-frequency packets like CHAT, allowing safe interaction with the Bukkit API. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.CHAT, ListenerOptions.SYNC) { // Sync is fine @Override public void onPacketReceiving(PacketEvent event) { // Can call Bukkit API safely String message = event.getPacket().getStrings().read(0); // Direct validation if (validateMessage(message)) { // OK to modify event.getPacket().getStrings().write(0, message.toUpperCase()); } } }; ``` -------------------------------- ### PacketConstructor Packet Creation Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Example of using PacketConstructor to create a packet with specific arguments and wrapping it in a PacketContainer. ```java PacketConstructor constructor = manager.createPacketConstructor( PacketType.Play.Server.EXPLOSION, x, y, z, radius, entities, knockback ); PacketContainer packet = new PacketContainer(type, constructor.createPacket()); ``` -------------------------------- ### Send Custom Packets Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Demonstrates how to retrieve the ProtocolManager, create a chat packet, populate its fields, and send it to a specific player. ```java ProtocolManager manager = ProtocolLibrary.getProtocolManager(); // Create packet PacketContainer packet = manager.createPacket(PacketType.Play.Server.CHAT); // Set fields packet.getStrings().write(0, "Hello!"); // Send to player manager.sendServerPacket(player, packet); ``` -------------------------------- ### Create PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Initialize a new PacketAdapter to listen for specific packet types. ```java new PacketAdapter(plugin, PacketType.Play.Server.CHAT) { public void onPacketSending(PacketEvent event) { } public void onPacketReceiving(PacketEvent event) { } }; ``` -------------------------------- ### getEntityFromID usage example Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Retrieves a Bukkit entity by its ID within a specific world and logs its type if found. ```java Entity entity = manager.getEntityFromID(world, entityId); if (entity != null) { plugin.getLogger().info("Found entity: " + entity.getType()); } ``` -------------------------------- ### getPlugin method Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Returns the plugin instance that created the listener. ```java public Plugin getPlugin() ``` -------------------------------- ### Import ProtocolLib Classes Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Essential import statements for accessing ProtocolLib functionality. ```java import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.ListenerPriority; ``` -------------------------------- ### getPlugin() Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieves the ProtocolLib plugin instance. ```APIDOC ## public static Plugin getPlugin() ### Description Get the ProtocolLib plugin instance itself. ### Returns - **Plugin** - The ProtocolLib plugin. ``` -------------------------------- ### Creating a PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/README.md Shows the base class for packet listeners with methods for handling outgoing and incoming packets. ```java new PacketAdapter(plugin, PacketType.Play.Server.CHAT) { public void onPacketSending(PacketEvent event) { } public void onPacketReceiving(PacketEvent event) { } } ``` -------------------------------- ### Initialize ProtocolManager Source: https://github.com/dmulloy2/protocollib/blob/master/Readme.md Obtain a reference to the ProtocolManager in your plugin's onLoad or onEnable method. ```java private ProtocolManager protocolManager; public void onLoad() { protocolManager = ProtocolLibrary.getProtocolManager(); } ``` -------------------------------- ### Filter Chat Packets with PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-type.md Demonstrates how to create a PacketAdapter that specifically listens for CHAT packets. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.CHAT) { @Override public void onPacketReceiving(PacketEvent event) { // This listener only sees CHAT packets } @Override public void onPacketSending(PacketEvent event) {} }; ``` -------------------------------- ### Check Thread Context for Bukkit API Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Example of checking if the packet event is running on the main thread and scheduling a task if it is in an async context. ```java @Override public void onPacketReceiving(PacketEvent event) { if (!Bukkit.isPrimaryThread()) { // Async context - schedule sync for Bukkit API Bukkit.getScheduler().runTask(plugin, () -> { event.getPlayer().sendMessage("Test"); }); } } ``` -------------------------------- ### PacketAdapter(Plugin, ListenerPriority, Iterable, ListenerOptions...) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a listener with explicit priority and specific listener options. ```APIDOC ## PacketAdapter(Plugin, ListenerPriority, Iterable, ListenerOptions...) ### Description Creates a listener with explicit priority and specific listener options. ### Parameters - **plugin** (Plugin) - Required - The plugin instance - **listenerPriority** (ListenerPriority) - Required - Priority level - **types** (Iterable) - Required - Packet types to listen for - **options** (ListenerOptions...) - Required - Options like ASYNC or SYNC ``` -------------------------------- ### Check for ProtocolLib availability Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Verify that ProtocolLib is loaded before attempting to use it in your plugin's main class. ```java if (getServer().getPluginManager().getPlugin("ProtocolLib") == null) { getLogger().severe("ProtocolLib not found!"); getServer().getPluginManager().disablePlugin(this); return; } ``` -------------------------------- ### Use SYNC ListenerOption Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Configures a packet listener to execute synchronously on the main server thread. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.CHAT, ListenerOptions.SYNC) { @Override public void onPacketReceiving(PacketEvent event) { // Guaranteed main thread execution event.getPlayer().sendMessage("Test"); // Safe } }; ``` -------------------------------- ### getPlugin() Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Returns the plugin instance associated with the listener. ```APIDOC ## getPlugin() ### Description Returns the plugin that created this listener. ### Returns - **Plugin** - The associated plugin instance. ``` -------------------------------- ### PacketAdapter Constructor with ListenerOptions Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a listener with specified priority, packet types, and listener options like ASYNC or SYNC. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, Arrays.asList(PacketType.Play.Server.CHAT), ListenerOptions.SYNC) { @Override public void onPacketReceiving(PacketEvent event) { // Guaranteed to run synchronously with main thread } }; ``` -------------------------------- ### Accessing Packet Data with PacketContainer Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/README.md Demonstrates how to wrap a packet and read a string field at index 0. ```java PacketContainer packet = event.getPacket(); String message = packet.getStrings().read(0); ``` -------------------------------- ### Configure PacketAdapter with AdapterParameters Builder Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Uses the PacketAdapter.params builder to define specific listener priorities, connection sides, and game phases for multiple packet types. ```java PacketAdapter adapter = new PacketAdapter( PacketAdapter.params(plugin, PacketType.Play.Client.CHAT, PacketType.Play.Client.COMMAND_SUGGESTION ) .listenerPriority(ListenerPriority.HIGH) .connectionSide(ConnectionSide.CLIENT_SIDE) .options(ListenerOptions.SYNC) .gamePhase(GamePhase.PLAYING) ) { @Override public void onPacketReceiving(PacketEvent event) { // Custom configuration applied } @Override public void onPacketSending(PacketEvent event) { // Not called - CLIENT_SIDE only } }; manager.addPacketListener(adapter); ``` -------------------------------- ### Check Version Compatibility Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/errors.md Verify player protocol versions and check supported Minecraft version ranges using ProtocolLibrary constants. ```java if (ProtocolLibrary.getProtocolManager().getProtocolVersion(player) == Integer.MIN_VALUE) { plugin.getLogger().warning("Player protocol version unknown"); } // Check version at startup String minVersion = ProtocolLibrary.MINIMUM_MINECRAFT_VERSION; // "1.8" String maxVersion = ProtocolLibrary.MAXIMUM_MINECRAFT_VERSION; // "26.2" ``` -------------------------------- ### getConfig() Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieves the configuration object for ProtocolLib settings. ```APIDOC ## public static ProtocolConfig getConfig() ### Description Retrieve the ProtocolLib configuration object. ### Returns - **ProtocolConfig** - Configuration for ProtocolLib settings. ``` -------------------------------- ### Create PacketAdapter Listener Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/README.md Implement a PacketAdapter to handle incoming or outgoing packets, such as client chat messages. ```java new PacketAdapter(plugin, PacketType.Play.Client.CHAT) { @Override public void onPacketReceiving(PacketEvent event) { String message = event.getPacket().getStrings().read(0); System.out.println("Player said: " + message); } @Override public void onPacketSending(PacketEvent event) {} }; ``` -------------------------------- ### ProtocolLibrary Version Constants Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Access version constants for Minecraft compatibility. ```APIDOC ## Version Constants ### Description Constants representing the minimum and maximum Minecraft versions tested with ProtocolLib. ### Constants - MINIMUM_MINECRAFT_VERSION (String): "1.8" - MAXIMUM_MINECRAFT_VERSION (String): "26.2" - MINECRAFT_LAST_RELEASE_DATE (String): "2026-06-16" ### Example ```java String minVersion = ProtocolLibrary.MINIMUM_MINECRAFT_VERSION; String maxVersion = ProtocolLibrary.MAXIMUM_MINECRAFT_VERSION; ``` ``` -------------------------------- ### PacketAdapter(Plugin, Iterable) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a listener from a collection of packet types with default NORMAL priority. ```APIDOC ## PacketAdapter(Plugin, Iterable) ### Description Creates a listener from a collection of packet types with default NORMAL priority. ### Parameters - **plugin** (Plugin) - Required - The plugin instance - **types** (Iterable) - Required - Collection of packet types ``` -------------------------------- ### ProtocolLibrary getPlugin method signature Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md The signature for retrieving the ProtocolLib plugin instance. ```java public static Plugin getPlugin() ``` -------------------------------- ### Configure Maven dependency Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Add the ProtocolLib dependency to your pom.xml file using the provided scope. ```xml net.dmulloy2 ProtocolLib 5.4.0 provided ``` -------------------------------- ### MinecraftVersion Version Checking Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/types.md Demonstrates checking the server version using MinecraftVersion to execute version-specific logic. ```java if (MinecraftVersion.NETHER_UPDATE.atOrAbove()) { // Code for 1.16+ } ``` -------------------------------- ### Configure Sync PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Synchronous listeners are executed on the main server thread, making them safe for direct Bukkit API calls at the cost of slight performance overhead. ```java // Safer for Bukkit API, slightly slower new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.CHAT, ListenerOptions.SYNC) { @Override public void onPacketSending(PacketEvent event) { // SYNC - guaranteed main thread // Safe to use Bukkit API String message = event.getPacket().getStrings().read(0); event.getPlayer().sendMessage("You sent: " + message); // OK } }; ``` -------------------------------- ### Add ProtocolLib Dependency with Maven Source: https://github.com/dmulloy2/protocollib/wiki/Adding-ProtocolLib-as-a-Dependency Configure your Maven project to include ProtocolLib by adding the specified repository and dependency to your pom.xml. Ensure you use the correct version. ```xml dmulloy2-repo https://repo.dmulloy2.net/repository/public/ com.comphenix.protocol ProtocolLib 4.7.0 ``` -------------------------------- ### Implement graceful degradation Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Use a try-catch block during plugin enablement to handle cases where ProtocolLib is unavailable without crashing the plugin. ```java @Override public void onEnable() { try { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); manager.addPacketListener(new MyListener(this)); getLogger().info("ProtocolLib packet listener registered"); } catch (Exception e) { getLogger().warning("ProtocolLib not available: " + e.getMessage()); getLogger().info("Plugin will operate without packet interception"); } } ``` -------------------------------- ### PacketAdapter Multiple Packet Types Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Demonstrates listening to multiple packet types simultaneously by passing them as arguments or using a List. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.CHAT, PacketType.Play.Client.COMMAND_SUGGESTION, PacketType.Play.Server.CHAT, PacketType.Play.Server.GAME_STATE_CHANGE ) { @Override public void onPacketReceiving(PacketEvent event) { // Called for any of the client packets above } }; // Or with collection List types = Arrays.asList( PacketType.Play.Client.PLAYER_POSITION, PacketType.Play.Client.PLAYER_LOOK ); new PacketAdapter(plugin, ListenerPriority.NORMAL, types) { // Listen to movement packets }; ``` -------------------------------- ### PacketAdapter(Plugin, ListenerPriority, PacketType...) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a listener with an explicit priority level. ```APIDOC ## PacketAdapter(Plugin, ListenerPriority, PacketType...) ### Description Creates a listener with an explicit priority level. ### Parameters - **plugin** (Plugin) - Required - The plugin instance - **listenerPriority** (ListenerPriority) - Required - Priority level (LOWEST to HIGHEST, or MONITOR) - **types** (PacketType...) - Required - Packet types to listen for ``` -------------------------------- ### Add ProtocolLib as a plugin dependency Source: https://github.com/dmulloy2/protocollib/blob/master/Readme.md Add ProtocolLib to your plugin.yml file as a dependency. ```yml depend: [ ProtocolLib ] ``` -------------------------------- ### Configure Development Environment Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Disable update checks and register a packet listener for debugging purposes within a development environment. ```java if (plugin.getServer().isDev || true) { // In dev environment ProtocolLibrary.disableUpdates(); // Skip update checks new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.CHAT) { @Override public void onPacketSending(PacketEvent event) { plugin.getLogger().info("Sending: " + event.getPacket().getStrings().read(0)); } }; } ``` -------------------------------- ### PacketEvent.fromServer Basic Method Signature Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-event.md The basic factory method signature for creating a server-bound packet event. ```java public static PacketEvent fromServer(Object source, PacketContainer packet, Player recipient) ``` -------------------------------- ### Configure Async PacketAdapter Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Asynchronous listeners run on the Netty thread pool, providing high performance but requiring careful handling of Bukkit API calls. Use Bukkit's scheduler to perform thread-sensitive operations. ```java // Fastest - no synchronization overhead new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.CHAT) { @Override public void onPacketReceiving(PacketEvent event) { // ASYNC - runs on netty thread pool // Do NOT call Bukkit API here // OK: Database queries, file I/O, calculations String message = event.getPacket().getStrings().read(0); processMessageAsync(message); // NOT OK: player.sendMessage(), Bukkit.getOnlinePlayers() // if (message.contains("bad")) { // event.getPlayer().sendMessage("No"); // WRONG // } // Correct: Schedule sync for API calls if (message.contains("bad")) { Bukkit.getScheduler().runTask(plugin, () -> { event.getPlayer().sendMessage("No"); // Correct }); } } }; ``` -------------------------------- ### ProtocolLibrary getConfig method signature Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md The signature for retrieving the ProtocolLib configuration object. ```java public static ProtocolConfig getConfig() ``` -------------------------------- ### PacketAdapter(Plugin, PacketType...) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a packet listener with default NORMAL priority for the specified packet types. ```APIDOC ## PacketAdapter(Plugin, PacketType...) ### Description Creates a packet listener with default NORMAL priority for the specified packet types. ### Parameters - **plugin** (Plugin) - Required - The plugin instance creating this listener - **types** (PacketType...) - Required - Variable arguments list of packet types to listen for ### Throws - IllegalArgumentException if plugin is null or types is empty ``` -------------------------------- ### Access Version Constants Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-library.md Retrieve the minimum and maximum supported Minecraft versions using the provided static constants. ```java String minVersion = ProtocolLibrary.MINIMUM_MINECRAFT_VERSION; // "1.8" String maxVersion = ProtocolLibrary.MAXIMUM_MINECRAFT_VERSION; // "26.2" plugin.getLogger().info("ProtocolLib supports: " + minVersion + " to " + maxVersion); ``` -------------------------------- ### Listener Priorities Order Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Visual representation of the execution order for packet listeners, from LOWEST to MONITOR priority. ```text LOWEST (runs first) ↓ LOW ↓ NORMAL (default) ↓ HIGH ↓ HIGHEST ↓ MONITOR (runs last, read-only) ``` -------------------------------- ### Packet Creation with Default Initialization Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Creates a packet while forcing the initialization of non-primitive fields like List or Set. ```java // Forces initialization of List/Set fields and other non-primitives PacketContainer explosionPacket = manager.createPacket( PacketType.Play.Server.EXPLOSION, true ); ``` -------------------------------- ### PacketEvent.fromServer with Network Marker Signature Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-event.md Factory method signature for creating a server packet event including a network marker. ```java public static PacketEvent fromServer(Object source, PacketContainer packet, NetworkMarker marker, Player recipient) ``` -------------------------------- ### Registering a PacketAdapter Source: https://github.com/dmulloy2/protocollib/wiki/Packet-listeners-and-adapters A basic implementation of a PacketAdapter that listens for incoming entity interaction packets and reads the target entity ID. ```java ProtocolManager manager = ProtocolLibrary.getProtocolManager(); manager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) { @Override public void onPacketReceiving(PacketEvent event) { Player player = event.getPlayer(); PacketContainer packet = event.getPacket(); int entityId = packet.getIntegers().read(0); System.out.println(player.getName() + " interacted with entity " + entityId); } }); ``` -------------------------------- ### createPacket Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Creates a new encapsulated Minecraft packet container. ```APIDOC ## createPacket(PacketType type, boolean forceDefaults) ### Description Creates a new encapsulated Minecraft packet. Optionally initializes non-primitive fields with sensible defaults. ### Parameters - **type** (PacketType) - Required - The packet type to create - **forceDefaults** (boolean) - Optional - If true, automatically initialize non-primitive fields with sensible defaults ### Returns - **PacketContainer** - A new packet container for modification and sending ### Throws - **FieldAccessException** - If packet instantiation fails ``` -------------------------------- ### Initialize ProtocolManager Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/GUIDE.md Retrieve the ProtocolManager instance within your plugin's onEnable method, including error handling for when ProtocolLib is missing. ```java public void onEnable() { try { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); // Use manager } catch (Exception e) { getLogger().severe("ProtocolLib not available"); setEnabled(false); } } ``` -------------------------------- ### PacketEvent.fromClient with Network Marker Signature Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-event.md Factory method signature for creating a client packet event including a network marker for tracking. ```java public static PacketEvent fromClient(Object source, PacketContainer packet, NetworkMarker marker, Player client) ``` -------------------------------- ### PacketAdapter Constructor with Iterable PacketTypes Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a listener from a collection of packet types. ```java List packets = Arrays.asList( PacketType.Play.Server.ENTITY_METADATA, PacketType.Play.Server.ENTITY_POSITION ); new PacketAdapter(plugin, packets) { /* ... */ }; ``` -------------------------------- ### PacketAdapter(AdapterParameteters) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-adapter.md Creates a listener using a builder-constructed parameters object. ```APIDOC ## PacketAdapter(AdapterParameteters) ### Description Creates a listener using a builder-constructed parameters object. ### Parameters - **params** (AdapterParameteters) - Required - Builder-constructed parameters ``` -------------------------------- ### getProtocolVersion(Player player) Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/protocol-manager.md Retrieves the protocol version of a given player. Returns the version as an integer, or Integer.MIN_VALUE if unknown. ```APIDOC ## int getProtocolVersion(Player player) ### Description Retrieves the protocol version of a given player. This is useful for version-specific logic on servers supporting multiple Minecraft versions. ### Parameters - **player** (Player) - Required - The player whose protocol version is requested. ### Returns - **int** - The associated protocol version, or Integer.MIN_VALUE if unknown. ``` -------------------------------- ### Use ASYNC ListenerOption Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/configuration.md Configures a packet listener to execute asynchronously. Note that Bukkit API calls must be scheduled on the main thread. ```java new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.CHAT, ListenerOptions.ASYNC) { @Override public void onPacketReceiving(PacketEvent event) { // Executes asynchronously - don't call Bukkit API } }; ``` ```java Bukkit.getScheduler().runTask(plugin, () -> { player.sendMessage("Test"); // Main thread }); ``` -------------------------------- ### Retrieve and use AsyncMarker Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-event.md Demonstrates how to check for an AsyncMarker and schedule a delayed task if the packet is being processed asynchronously. ```java AsyncMarker marker = event.getAsyncMarker(); if (marker != null) { // Schedule delayed processing marker.incrementProcessingDelay(); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { // Re-enable packet after delay }, delayTicks); } ``` -------------------------------- ### getProtocol Method Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-type.md Retrieves the protocol phase (HANDSHAKING, STATUS, LOGIN, or PLAY) associated with the packet. ```java public Protocol getProtocol() ``` ```java Protocol protocol = packetType.getProtocol(); if (protocol == Protocol.PLAY) { // Handle play phase packet } ``` -------------------------------- ### Dynamic Packet Type Checking Source: https://github.com/dmulloy2/protocollib/blob/master/_autodocs/api-reference/packet-type.md Illustrates how to check the packet type dynamically within the onPacketSending method. ```java new PacketAdapter(plugin, PacketType.Play.Server.CHUNK_DATA) { @Override public void onPacketSending(PacketEvent event) { PacketType type = event.getPacketType(); plugin.getLogger().info("Sending packet: " + type); // Compare with constant if (type == PacketType.Play.Server.CHUNK_DATA) { // Handle chunk packet } } @Override public void onPacketReceiving(PacketEvent event) {} }; ```