Solved Checking items display name

Discussion in 'Plugin Development' started by LordPyrak, Dec 9, 2013.

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

    LordPyrak

    I'm pretty new to java, so if this is something I'm doing wrong, sorry.
    I have this code:
    Code:java
    1. public void onLaunch(ProjectileLaunchEvent e) {
    2. Player p = (Player) e.getEntity().getShooter();
    3. ItemStack i = p.getItemInHand();
    4. ItemMeta im = i.getItemMeta();
    5. String iName = im.getDisplayName();
    6. if (iName.toLowerCase()=="grenade") {
    7. Main.map.put(String.valueOf(e.getEntity().getEntityId()), 1);
    8. return;

    When I broadcast iName while holding an egg with the display name of "Grenade", it broadcasts "Grenade", like it should. BUT when I run the if statement, it always comes up as false. What's going one here?
     
  2. Offline

    xTrollxDudex

    LordPyrak
    You're comparing strings with ==, use .equals(...)
     
    LordPyrak likes this.
  3. Offline

    GusGold

    LordPyrak
    You need to show your whole code, because we can't tell what Bladder contains.
     
  4. Offline

    Conarnar

    Umm, that is is signature.
     
  5. Offline

    LordPyrak

    xTrollxDudex
    I had a feeling it would be something simple I was missing, thanks! :)

    GusGold
    Bladder currently contains 75% Mountain dew, 25% air, lol

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    GusGold

    Conarnar LordPyrak
    FML, they need to have that dotted line more defined...

    Edit: Thank you Stylebot :p
     
    LordPyrak likes this.
Thread Status:
Not open for further replies.

Share This Page