Events specific to certain items?

Discussion in 'Plugin Development' started by Slayer9x9, Jan 30, 2012.

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

    Slayer9x9

    Hey all.
    My question is, how might I go about creating events specific to certain items?

    For example, I want an event to trigger when a SPECIFIC item is picked up by the player.
    I know I can take the easy route and just track every single item picked up, and use a simple conditional to determine which item it is, but I want a more efficient method to track only a specific kind of item.

    Any ideas?
     
  2. Offline

    Lolmewn

    There's no way to only track one item, you have to use the check.
     
  3. Offline

    Slayer9x9

    Thats too bad.. :(
     
  4. Offline

    troed

    There's an enhancement suggested for Bukkit that would add this functionality, until then there might be a workaround that works for you.

    Courier does this, and I think BookWorm does as well. Whether it can be done or not depends upon what types of items you want to track. In Courier's case the items I want to track (ItemStacks of Maps) can be enchanted since Maps don't have enchantments in Minecraft, and BookWorm sets the damage value since Books don't normally use those.

    If the Items you want to track use both damage values and enchantments you might be out of luck :/

    In short, in Courier I'm using the no-checks API to add an enchantment that shouldn't affect anything with the current in-game rules to an item that isn't enchanteable, again with the current in-game rules, using its level as a unique ID that I can associate with specific database content:
    • Add a unique ID to an Item:
    Code:
    ItemStack letter = new ItemStack(Material.MAP, 1, Courier.MAPID);
     
    letter.addUnsafeEnchantment(Enchantment.DURABILITY, generateUUID());
    • Retrieve the unique ID:
    Code:
    int id = letterItem.getEnchantmentLevel(Enchantment.DURABILITY);
    Look up whatever data you wanted to associate with that item in your database structure of choice.

    (caveat: In the usual resource starved world of Mojang that int is getting cast to a short somewhere - no more than 65536 items possible to track this way)

    Hope this might be of any help.
     
Thread Status:
Not open for further replies.

Share This Page