Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Display a fake pumkin helmet for all users. DEPRECIATED: Use instead.
package com.comphenix.example;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
public class FakePumpinHelmets extends JavaPlugin {
public static final int SLOT_HELD = 0;
public static final int SLOT_BOOTS = 1;
public static final int SLOT_LEGGINGS = 2;
public static final int SLOT_CHESTPLATE = 3;
public static final int SLOT_HELMET = 4;
public void onEnable() {
new PacketAdapter(this, ConnectionSide.SERVER_SIDE,
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
// The entity that is being displayed on the player's screen
Entity visibleEntity = packet.getEntityModifier(event).read(0);
// The player that is receiving the armor information
Player observingPlayer = event.getPlayer();
switch (event.getPacketID()) {
case Packets.Server.ENTITY_EQUIPMENT :
// Determine if this is a helmet slot
if (packet.getIntegers().read(1) == SLOT_HELMET) {
packet.getItemModifier().write(0, new ItemStack(Material.PUMPKIN, 1));
// Entity equipment is not sent when the helm slot is empty, so we have to help it along
case Packets.Server.NAMED_ENTITY_SPAWN:
// Update the head slot too
LivingEntity living = (LivingEntity) visibleEntity;
updateEquipmentSlot(observingPlayer, living, SLOT_HELMET, living.getEquipment().getHelmet());
throw new IllegalArgumentException("Unknown packet ID:" + event.getPacketID());
private void updateEquipmentSlot(final Player observer, LivingEntity entity, int slot, ItemStack content) {
final PacketContainer equipmentPacket = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT);
write(0, entity.getEntityId()).
write(1, slot);
equipmentPacket.getItemModifier().write(0, content);
// We have to send the packet AFTer named entity spawn has been sent
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, equipmentPacket);
} catch (InvocationTargetException e) {
throw new RuntimeException("Unable to update slot.", e);

This comment has been minimized.

Copy link

@SupaHam SupaHam commented Nov 25, 2013

How come this only works on entities that spawn with armor


This comment has been minimized.

Copy link
Owner Author

@aadnk aadnk commented Apr 26, 2014

@SupaHam: You're supposed to call updateEquipmentSlot() with the slot you want to modify.

But I think I'll just rewrite this example with a better API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment