### Maven Repository Configuration
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started
Adds the Exceptionflug Maven repository to your project's pom.xml file, allowing you to download Protocolize artifacts.
```xml
exceptionflug
https://mvn.exceptionflug.de/repository/exceptionflug-public/
```
--------------------------------
### Plugin Dependency Configuration (Velocity)
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started
Specifies Protocolize as a dependency for your Velocity plugin using the @Plugin annotation.
```java
@Plugin(id = "your-plugin-id", name = "Your Plugin Name", version = "1.0", dependencies = {
@Dependency("protocolize")
})
```
--------------------------------
### Custom Packet Mappings Example
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
Provides an example of creating a List for custom packets, showing how to define protocol version ranges and their corresponding packet IDs.
```java
public final static List MAPPINGS = Arrays.asList(
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_8, MINECRAFT_1_8, 0x08),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_9, MINECRAFT_1_11_2, 0x1C),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_12, MINECRAFT_1_12_2, 0x1F),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_13, MINECRAFT_1_13_2, 0x29),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_14, MINECRAFT_1_15_2, 0x2C),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_16, MINECRAFT_1_16_1, 0x2D),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_16_2, MINECRAFT_1_17_1, 0x2E)
);
```
--------------------------------
### Maven Dependency for Protocolize API
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started
Includes the Protocolize API as a provided dependency in your Maven project. This is necessary for interacting with Protocolize features.
```xml
dev.simplix
protocolize-api
${protocolize.version}
provided
```
--------------------------------
### Accessing ProtocolizePlayer
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
ProtocolizePlayer instances, which now handle inventory and sound functionalities, can be obtained from the ProtocolizePlayerProvider using the player's unique ID.
```java
ProtocolizePlayer player = Protocolize.playerProvider().player(uniqueId);
```
--------------------------------
### Accessor/Mutator Naming Convention Change
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
Protocolize v2 has removed 'get' and 'set' prefixes for accessors and mutators, returning 'this' for a more fluent API. This example shows the old vs. new syntax for setting inventory title and item.
```java
// old
inventory.setTitle("Hello");
inventory.setItem(0, itemStack);
// new
inventory.title("Hello").item(0, itemStack);
```
--------------------------------
### Listening to Inventory Clicks
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
To listen for inventory clicks in Protocolize v2, register a Consumer using the Inventory#onClick method.
```java
inventory.onClick(event -> {
// Handle click event
});
```
--------------------------------
### Registering Player Interact Consumer
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
Demonstrates how to register a consumer for player interactions, either for a specific player or globally for all players upon their construction.
```java
Protocolize.playerProvider().onConstruct(player -> {
player.onInteract(interact -> {
// handle interact
});
});
```
--------------------------------
### Registering Custom Packets
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
Shows the method for registering a custom packet with Protocolize, specifying its mappings, protocol, direction, and class.
```java
Protocolize.protocolRegistration().registerPacket(WindowItems.MAPPINGS, Protocol.PLAY, PacketDirection.CLIENTBOUND, WindowItems.class);
```
--------------------------------
### Accessing ProtocolRegistrationProvider
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
In Protocolize v2, the PacketRegistration functionality is now an interface called ProtocolRegistrationProvider, accessible via Protocolize#protocolRegistration.
```java
Protocolize.protocolRegistration
```
--------------------------------
### Listening for Opened Windows (InventoryOpenEvent Replacement)
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
The InventoryOpenEvent has been removed. Listen for opened windows by registering an AbstractPacketListener and obtaining the Inventory instance using the window ID from the player's registeredInventories.
```java
public class MyOpenWindowListener extends AbstractPacketListener {
@Override
public void onPacketReceiving(PacketEvent event) {
OpenWindow packet = event.packet();
Inventory inventory = event.player().registeredInventories().get(packet.windowId());
if (inventory != null) {
// Handle opened inventory
}
}
}
```
--------------------------------
### Registering a Packet Listener
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
The method for registering a packet listener has changed from ProtocolAPI.getEventManager().registerListener() to Protocolize.listenerProvider().registerListener().
```java
// old
ProtocolAPI.getEventManager().registerListener(new MyListener());
//new
Protocolize.listenerProvider().registerListener(new MyListener());
```
--------------------------------
### Listening to Inventory Closes
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
To listen for inventory closes in Protocolize v2, register a Consumer using the Inventory#onClose method.
```java
inventory.onClose(event -> {
// Handle close event
});
```
--------------------------------
### Accessing PacketListenerProvider
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
The EventManager has been replaced by PacketListenerProvider, which is accessible through Protocolize#listenerProvider.
```java
Protocolize.listenerProvider()
```
--------------------------------
### Protocolize Packet Structure and Registration
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
Details the requirements for custom packets in Protocolize v2, including the mandatory extension of AbstractPacket and the registration process via ProtocolRegistrationProvider.
```APIDOC
AbstractPacket:
- Mandatory base class for all custom implemented packets in Protocolize v2.
- Packets must extend this class to be registered.
ProtocolRegistrationProvider:
- Service for registering custom packets.
- registerPacket(List mappings, Protocol protocol, PacketDirection direction, Class extends AbstractPacket> packetClass)
- Parameters:
- mappings: A list of ProtocolIdMapping defining the packet's ID across different protocol versions.
- protocol: The protocol context (e.g., Protocol.PLAY).
- direction: The packet direction (e.g., PacketDirection.CLIENTBOUND).
- packetClass: The class of the custom packet extending AbstractPacket.
- Example:
Protocolize.protocolRegistration().registerPacket(WindowItems.MAPPINGS, Protocol.PLAY, PacketDirection.CLIENTBOUND, WindowItems.class);
ProtocolIdMapping:
- Represents a mapping of a packet ID for a specific range of protocol versions.
- AbstractProtocolMapping.rangedIdMapping(ProtocolVersion startVersion, ProtocolVersion endVersion, int id)
- Creates a ranged mapping.
- Example:
// id 0x1C for 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.10.x, 1.11, 1.11.1, 1.11.2
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_9, MINECRAFT_1_11_2, 0x1C)
```
--------------------------------
### Get Damage Component Example
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started-with-structured-items
Demonstrates how to retrieve the DamageComponent from an ItemStack and access its damage value. This is useful for inspecting item properties.
```java
DamageComponent damageComponent = itemStack.getComponent(DamageComponent.class);
if (damageComponent != null) {
int damage = damageComponent.getDamage();
}
```
--------------------------------
### Maven Dependency Update
Source: https://github.com/exceptionflug/protocolize/wiki/Migrating-from-Protocolize-v1
Update your Maven dependency to use the new protocolize-api artifact for Protocolize v2. This replaces all previous protocolize dependencies.
```xml
dev.simplix
protocolize-api
2.0.0
provided
```
--------------------------------
### Remove Damage Component Example
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started-with-structured-items
Illustrates how to remove the DamageComponent from an ItemStack. This requires obtaining an instance of the component first.
```java
itemStack.removeComponent(damageComponent.getType());
```
--------------------------------
### Add Damage Component Example
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started-with-structured-items
Shows how to add a new DamageComponent to an ItemStack, allowing you to set the damage value of an item. This modifies the item's properties.
```java
itemStack.addComponent(DamageComponent.create(damage));
```
--------------------------------
### Intercept and Rewrite Actionbar Messages
Source: https://github.com/exceptionflug/protocolize/wiki/Packet-listening
Provides an example of how to modify packet data, specifically changing an actionbar message (position 2) to a normal chat message (position 0) and marking the packet for rewriting on BungeeCord.
```java
public class MyPacketListener extends AbstractPacketListener {
public MyPacketListener() {
super(Chat.class, Direction.DOWNSTREAM, 0);
}
@Override
public void packetReceive(PacketReceiveEvent event) {
Chat packet = event.packet();
if(packet.getPosition() == 2) { // Position 2 means actionbar
packet.setPosition((byte) 0); // Set to normal chat
event.markForRewrite(); // We need to mark the packet for rewriting after we changed fields in the packet class. This is only necessary when receiving packets on BungeeCord.
}
}
}
```
--------------------------------
### Maven Dependency and Repository
Source: https://github.com/exceptionflug/protocolize/blob/master/README.md
Instructions for adding the Protocolize Maven repository and dependency to a Maven project.
```xml
exceptionflug
https://mvn.exceptionflug.de/repository/exceptionflug-public/
```
```xml
dev.simplix
protocolize-api
2.4.2
provided
```
--------------------------------
### Gradle Dependency
Source: https://github.com/exceptionflug/protocolize/blob/master/README.md
Instructions for adding the Protocolize Maven repository and dependency to a Gradle project.
```kotlin
repositories {
maven {
url = uri('https://mvn.exceptionflug.de/repository/exceptionflug-public/')
}
}
dependencies {
compileOnly("dev.simplix:protocolize-api:2.4.1")
}
```
--------------------------------
### Supported Structured Components in Protocolize
Source: https://github.com/exceptionflug/protocolize/wiki/Getting-started-with-structured-items
Lists the structured components supported by Protocolize, along with their corresponding Protocolize API classes. Components not listed are not supported by default.
```APIDOC
Component Name | Protocolize Class
--|--
`minecraft:custom_data` | `dev.simplix.protocolize.api.item.component.CustomDataComponent`
`minecraft:max_stack_size` | `dev.simplix.protocolize.api.item.component.MaxStackSizeComponent`
`minecraft:max_damage` | `dev.simplix.protocolize.api.item.component.MaxDamageComponent`
`minecraft:damage` | `dev.simplix.protocolize.api.item.component.DamageComponent`
`minecraft:custom_name` | `dev.simplix.protocolize.api.item.component.CustomNameComponent`
`minecraft:item_name` | `dev.simplix.protocolize.api.item.component.ItemNameComponent`
`minecraft:lore` | `dev.simplix.protocolize.api.item.component.LoreComponent`
`minecraft:custom_model_data` | `dev.simplix.protocolize.api.item.component.CustomModelDataComponent`
`minecraft:hide_tooltip` | `dev.simplix.protocolize.api.item.component.HideTooltipComponent`
```
--------------------------------
### Display Inventory to a Player
Source: https://github.com/exceptionflug/protocolize/wiki/Inventories
Explains how to open a custom inventory for a specific player. Requires obtaining a `ProtocolizePlayer` instance and using the `openInventory` method.
```java
ProtocolizePlayer player = Protocolize.playerProvider().player(playerUniqueId);
player.openInventory(inventory);
```
--------------------------------
### Create AbstractPacketListener
Source: https://github.com/exceptionflug/protocolize/wiki/Packet-listening
Demonstrates the basic structure of creating a custom packet listener by extending AbstractPacketListener and specifying the packet type, direction, and priority.
```java
public class MyPacketListener extends AbstractPacketListener {
public MyPacketListener() {
super(Chat.class, Direction.UPSTREAM, 0);
}
}
```
--------------------------------
### Register Packet Listener
Source: https://github.com/exceptionflug/protocolize/wiki/Packet-listening
Demonstrates the final step of registering a created AbstractPacketListener with the Protocolize listener provider.
```java
Protocolize.listenerProvider().registerListener(new MyPacketAdapter());
```
--------------------------------
### Protocolize API - Listener Provider
Source: https://github.com/exceptionflug/protocolize/wiki/Packet-listening
Provides documentation for the ListenerProvider interface in Protocolize, focusing on the registerListener method.
```apidoc
ListenerProvider:
registerListener(listener: AbstractPacketListener): void
Registers a packet listener with the Protocolize system.
Parameters:
listener: An instance of AbstractPacketListener to register.
Example:
Protocolize.listenerProvider().registerListener(new MyPacketListener());
```
--------------------------------
### Create a Custom Inventory
Source: https://github.com/exceptionflug/protocolize/wiki/Inventories
Demonstrates how to create a new custom inventory with a specified type and title. Requires the `Inventory` and `ChatElement` classes.
```java
Inventory inventory = new Inventory(InventoryType.GENERIC_9X4);
inventory.title(ChatElement.ofLegacyText("§9Inventory"));
```
--------------------------------
### Send Packet to Player's Server
Source: https://github.com/exceptionflug/protocolize/wiki/Sending-packets
Demonstrates sending a packet to the server the player is connected to. Requires a ProtocolizePlayer instance obtained via ProtocolizePlayerProvider and a packet extending AbstractPacket.
```java
ProtocolizePlayer player = Protocolize.playerProvider().player(playerUniqueId);
player.sendPacketToServer(new HeldItemChange(slot));
```
--------------------------------
### Send Packet to Player
Source: https://github.com/exceptionflug/protocolize/wiki/Sending-packets
Demonstrates sending a packet to a specific player. Requires a ProtocolizePlayer instance obtained via ProtocolizePlayerProvider and a packet extending AbstractPacket.
```java
ProtocolizePlayer player = Protocolize.playerProvider().player(playerUniqueId);
player.sendPacket(new CloseWindow(id));
```
--------------------------------
### Play Sound for Player
Source: https://github.com/exceptionflug/protocolize/wiki/Sounds
Plays a specified sound on a given sound channel with specified volume and pitch to a player. Requires obtaining a ProtocolizePlayer instance.
```java
ProtocolizePlayer player = Protocolize.playerProvider().player(playerUniqueId);
player.playSound(Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.MASTER, 1f, 1f);
```
--------------------------------
### Set Items in an Inventory
Source: https://github.com/exceptionflug/protocolize/wiki/Inventories
Shows how to place an ItemStack into a specific slot of a custom inventory. Uses the `Inventory` and `ItemStack` classes.
```java
inventory.item(0, new ItemStack(ItemType.GLASS_PANE));
```
--------------------------------
### Implement Packet Receive and Send
Source: https://github.com/exceptionflug/protocolize/wiki/Packet-listening
Shows how to implement the packetReceive and packetSend methods within an AbstractPacketListener to handle incoming and outgoing packets respectively. It clarifies the meaning of UPSTREAM and DOWNSTREAM directions for receiving and sending.
```java
@Override
public void packetReceive(PacketReceiveEvent event) {
// Receive on UPSTREAM means receiving a packet from a player
// Receive on DOWNSTREAM means receiving a packet from a server a player is connected to
}
@Override
public void packetSend(PacketSendEvent event) {
// Sending on UPSTREAM means sending a packet to a player
// Sending on DOWNSTREAM means sending a packet to a server a player is connected with
}
```
--------------------------------
### Handle Inventory Clicks
Source: https://github.com/exceptionflug/protocolize/wiki/Inventories
Details how to register a callback for inventory click events. The `onClick` method accepts a `Consumer` to process clicks.
```java
Inventory inventory = new Inventory(InventoryType.GENERIC_9X4);
inventory.title(ChatElement.ofLegacyText("§9Inventory"));
inventory.onClick(click -> {
player.sendMessage("Clicked on slot " + click.slot());
});
```
--------------------------------
### Manipulate Player Inventory
Source: https://github.com/exceptionflug/protocolize/wiki/Inventories
Demonstrates how to access and modify the player's own inventory. Requires obtaining the `PlayerInventory` proxy and using Minecraft slot indices.
```java
ProtocolizePlayer player = Protocolize.playerProvider().player(playerUniqueId);
PlayerInventory inventory = player.proxyInventory();
inventory.item(40, new ItemStack(ItemType.BLAZE_ROD));
inventory.update();
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.