Helmets and Events!

Discussion in 'Plugin Development' started by Developher, Aug 8, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    So I am making a plugin where it listens if a player has a helmet, if so, it checks to see if the item is a certain wool, but I can only do material.wool, not getType() == DyeColor.red. I am checking for the color, and setting their display name accordingly. I have two questions.
    A: How do I check for the certain color wool?
    B: Will this work? Am I using the right Event? (PlayerInventoryEvent).

    public class WarColours extends JavaPlugin implements Listener {

    Material wool;

    public void onEnable() {

    PluginManager pm = Bukkit.getServer().getPluginManager();
    pm.registerEvents(this, this);


    public void onDisable() {


    public void method(PlayerInventoryEvent e) {

    PlayerInventory inventory = e.getPlayer().getInventory();
    if(inventory.getHelmet().getType() == Material.WOOL) {
    e.getPlayer().setDisplayName(ChatColor.BLUE + e.getPlayer().getName());


    if(inventory.getHelmet().getType() == Material.WOOL) {
    e.getPlayer().setDisplayName(ChatColor.RED + e.getPlayer().getName());





    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 27, 2016
  2. Offline


    It would help if you used the code tags
  3. Isn't PlayerInventoryEvent just an interface for the actual events ?
    At any rate, it's deprecated so you shouldn't use it...

    Apart from the id/type/material (same thing) you can specify data/damage/durability (same thing) value which defines some sub-types of items... colors of wool, colors of dyes, smooth brick types, wood types, potions, etc.
    item.getDurability() will get that data value.

    I don't know what event you should use tough... because you can't place wool in the helmet slot in the inventory, unless a plugin hooks it and allows it - if that's the case you can use InventoryClickEvent and get if player has clicked the slot... you can check if item in hand is something to check if player placed something or took something, if slot has an item.
    So... how do players actually place the wool on their head ?
  4. Offline


    A couple of things.

    First, you're not checking for null, when an inventory slot is empty in MC it's null, the code you posted would cause an NPE every time someone wasn't wearing a helm.

    Why are you listening for an event here? It's not possible to naturally equip that helm, your plugin, or another plugin, has to put it there.

    As for the actual question, you need to check durability. So look at inventory.getHelmet().getDurability(). 11 is blue, 14 is red.
Thread Status:
Not open for further replies.

Share This Page