Solved Comparing two ItemStacks with ItemMeta

Discussion in 'Plugin Development' started by ipodtouch0218, Jun 16, 2016.

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

    ipodtouch0218

    I'm trying to make a short game about shooting armor stands. It works fine, but pets on the server also uses armor stands, so I'm trying to check for the ItemStack in the Helmet slot of the armor stand. I need some way to compare the "Helmet ItemStack" with a template ItemStack.

    http://pastebin.com/FJqWBiUp

    I've tried creating another ItemStack with the same meta and using
    Code:
    if (helmet.equals(template)) {
        //Code (Check Pastebin)
    }
    I've tried just checking for the ItemStack's display name

    Code:
    String name = meta.getDisplayName().toString();
    if (name == "Skull of Ventality") {
        //Code (Check Pastebin)
    }
    I've tried to compare the two ItemMetas

    Code:
    if (helmet.getItemMeta().toString().equals(template.getItemMeta().toString()) {
        //Code (Check Pastebin)
    }
    //not sure if this is the correct method for getItemMeta... made this up as i'm going
    Heck, I've tried to compare them using "==" which I know wouldn't work, but good to test.

    I've made a debug message for when you shoot the armor stand (which gets called), telling me what the armor stand's ItemStack info is. "player.sendMessage(helmet.toString() + " compared to " + template.toString())"

    I noticed that all the metadata was the same, just the "internal:" tag was different. I thought .equals compares them without comparing internal.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @ipodtouch0218 Strings are compared with equals, so the name check won't work the way you posted.
     
    ipodtouch0218 likes this.
  3. Offline

    ipodtouch0218

    @timtower
    Of course, the one time I don't use .equals() I needed to.
    Also, I tried to rename the head in an anvil, and Essentials uses a "§f" color code when spawning in heads, which is why the name never was accepted.

    It works now, thanks :3
     
    timtower likes this.
  4. Offline

    I Al Istannen

Thread Status:
Not open for further replies.

Share This Page