Solved DisplayName not comparing

Discussion in 'Plugin Development' started by TheMcScavenger, Jan 30, 2014.

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

    TheMcScavenger

    So, I've run into a really odd situation here, and I've never had trouble with it before. I've created an itemstack with a custom item meta (display name), and set it to the item stack. I have no problems modifying the item, or getting the item (or the display name for that matter...), but once I try to compare the display name to a string, it doesn't work.

    Creating & Getting the bow:
    Code:java
    1. ItemStack stack = new ItemStack(Material.BOW, 1);
    2. ItemMeta meta = stack.getItemMeta();
    3. meta.setDisplayName("§6Custom Bow");
    4. stack.setItemMeta(meta);
    5. return stack;


    Getting the Display Name & Comparing it:
    Code:java
    1. ItemStack stack = player.getInventory().getItemInHand();
    2. ItemMeta meta = stack.getItemMeta();
    3. String displayName = meta.getDisplayName();
    4. Bukkit.broadcastMessage(displayName);
    5.  
    6. if(displayName.equalsIgnoreCase("&6Custom Bow")){
    7. return "custom";
    8. }
    9. else{
    10. return null;
    11. }


    Note that this code is called immediately after the arrow hits an object, and that the item in hand is still the bow. Also, the broadcast does in fact return the correct item name (&6Custom Bow). I've tried .equals(), I've tried .equalsIgnoreCase(), and I've tried with and without the colour code (&6).

    Problem: always returns null instead of "custom", which it should return.
     
  2. Offline

    Drew1080

    Well from what I can see when your created the bow you set the display name to §6Custom Bow using '§' but when you check it your checking for '&6Custom Bow' using '&'.
     
  3. Offline

    TheMcScavenger

    Drew1080 Haha ye, I just saw it. That's what I get for writing the first half the first day, and the second half the second day :p Thanks though :)
     
Thread Status:
Not open for further replies.

Share This Page