compare DisplayName doesn´t work

Discussion in 'Plugin Development' started by paul0000, May 26, 2013.

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

    paul0000

    This following code shell check whether the thing a player consumes has a special displayed name:

    Code:
    @EventHandler(priority = EventPriority.NORMAL)
      public void onPlayerDrinks(PlayerItemConsumeEvent e) {
      Player p = e.getPlayer();
      if(e.getItem().getItemMeta() == null || e.getItem().getItemMeta().getDisplayName() == null){
      return;
      }
      ItemMeta meta = e.getItem().getItemMeta();
      String name = meta.getDisplayName();
      if(name == "§bBier") {
          p.sendMessage("erfolgreich");
          p.sendMessage(name);
          }
      else {
          p.sendMessage("fail");
          p.sendMessage(name);  //for debugging
          p.sendMessage("§bBier");
      }
             
      }
    the message name (= the DisplayName is exactly the same then the message "§bBier" (the name a search for), but I get the message fail, so the names same not to be the same.
    I really don´t know why.
     
  2. Offline

    kreashenz

    Change
    Code:java
    1. if(name == "§bBier"){

    to
    Code:java
    1. if(name.equalsIgnoreCase("§bBier")){
     
  3. Offline

    paul0000

    thank you now it works. But why didn´t it work before?
     
  4. Offline

    colony88

    Because equalsIgnoreCase is made specifically for comparing strings
     
Thread Status:
Not open for further replies.

Share This Page