how to add more

Discussion in 'Plugin Development' started by xguysprison, Mar 6, 2015.

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

    xguysprison

    hallo so i have this code
    Code:
       @EventHandler
       public void inventoryClickEvent(InventoryClickEvent event) {
         if (!(event.getInventory() instanceof AnvilInventory)) {
           return;
         }
    /* 84 */     if (event.getSlotType() != InventoryType.SlotType.RESULT) {
           return;
         }
    
         if (event.getCurrentItem().getItemMeta().getDisplayName()
           .contains("Hero Sword"))
          event.setCancelled(true);
       }
    }
    and i need to figure out how add so if the name is Hero Sword then cancle same if its Hero Axe ect
     
  2. @xguysprison What isn't working exactly? You need to to tell us what the error is, not just "This doesn't work". Please explain a bit more detailed what isn't working. Are you getting a stack trace? Are you registering your events? Make sure that you do ChatColor.stripColors() when checking for the name of an item.
     
  3. Offline

    xguysprison

    it is working i just dont know how to add more names
     
  4. @xguysprison Pretty sure you need to check for:
    Code:
    if (event.getCurrentItem().getItemMeta().getDisplayName().equals("blah blah blah") {
    // Do things
    } else if (event.getCurrentItem().getItemMeta().getDisplayName().euals("blah blah blah") {
    // Do stuff
    }
    
    If you didn't know about this I highly suggest to learn Java. It's so much easier to code when you learn Java; then learn Bukkit. :)
     
  5. Offline

    xguysprison

    @CodePlaysMinecraft thx but i found a better way by looking into it myself i did
    Code:
    String display_name = event.getCurrentItem().getItemMeta().getDisplayName();
    if (display_name.contains("Hero Sword") || display_name.contains("Hero axe")) {
    // Cancel
     
  6. @xguysprison I was going to suggest that but then, they'd both do the same thing when executed, and I wasn't sure if you wanted that or not, lol. :p Anyway, since your problem is solved, please set it to solved by going to Thread Tools > Edit Title > Prefix > Solved. :)
     
Thread Status:
Not open for further replies.

Share This Page