Create a gist now

Instantly share code, notes, and snippets.

Set a different armor color per observer.
package com.comphenix.example;
import org.bukkit.Color;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
public class ExampleMod extends JavaPlugin implements Listener {
private ProtocolManager manager;
public void onLoad() {
manager = ProtocolLibrary.getProtocolManager();
public void onEnable() {
manager.addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE,
Packets.Server.ENTITY_EQUIPMENT) {
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
ItemStack stack = packet.getItemModifier().read(0);
// Only modify leather armor
if (stack != null && stack.getType().name().contains("LEATHER")) {
// The problem turned out to be that certain Minecraft functions update
// every player with the same packet for an equipment, whereas other
// methods update the equipment with a different packet per player.
// To fix this, we'll simply clone the packet before we modify it
packet = event.getPacket().deepClone();
stack = packet.getItemModifier().read(0);
// Color that depends on the player's name
String recieverName = event.getPlayer().getName();
int color = recieverName.hashCode() & 0xFFFFFF;
// Update the color
LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment