InventoryClick Event

Discussion in 'Plugin Development' started by UnAnswereed, Oct 30, 2017.

Thread Status:
Not open for further replies.
  1. I did an inventory menu with submenus, and I can't use InventoryClickEvent because it only counts the event in the first menu, then in the submenu it isn't works.


    Here are some examples from my code:
    Code:
    if (e.getInventory().getTitle().equalsIgnoreCase(Main.EventInfo.prefix + "§5Shop")) {
                if (e.getCurrentItem().getType() == Material.DIAMOND) {
                    Main.diamondShop(p);
                } else if (e.getCurrentItem().getType() == Material.IRON_INGOT) {   
                    Main.ironShop(p);
                } else if (e.getCurrentItem().getType() == Material.STONE) {
                    Main.stoneShop(p);
                }
    }
    
    Code:
    if (e.getInventory().getTitle().equalsIgnoreCase("§7Iron Items")) {
                if (e.getCurrentItem().getType() == Material.WOOL || e.getCurrentItem().getDurability() == 14) {
                    p.closeInventory();
                    p.chat("/event shop");
                   
                }
    }
    
     
  2. Offline

    MightyOne

    What indicates that you can not use the InventoryClickEvent anymore? Inventory is Inventory so actually that should work
     
  3. @MightyOne If I open the main inventory, and then a sub, in the subinventory when I click to some item, nothing happens. But, I set a command, so I can reach the submenus instant, and in that way I can use the items, and there is a "back" button, so I can go back to the main menu, and there I can't use anything again.
     
  4. Offline

    AdamDev

    @UnAnswereed
    Try not to use .getTitle()
    Do
    Code:
    if (!e.getInventory().getName() == "name") {
         return;
    } else {
        if (e.getCurrentItem().getItemMeta().getDisplayName() == "&5name") {
        e.setCancelled(true);
      } 
    }
    
    I could be wrong currently can't remember so if something is wrong I'll correct later when I'm home
     
  5. Offline

    timtower Administrator Administrator Moderator

    @AdamDev Strings are compared with equals or equalsIgnoreCase
     
    ipodtouch0218 likes this.
  6. Offline

    ItsComits

  7. @ItsComits It's not the same problem. I can open the inventory from the main, but I can't do anything in that, and the problem isn't with the second inventory's programming.
     
  8. Offline

    Side8StarLite

    @UnAnswereed
    Maybe the colored text is messing up the string comparisons. Try using ChatColor.stripColor to compare strings without their color.
     
  9. Offline

    jackiejoe4

    Before you compare the strings that have a color assigned to them, translate the code using:
    Code:
    ChatColor.translateAlternateColorCodes('§', "§5String to translate");
    
     
  10. Offline

    Zombie_Striker

    @jackiejoe4
    What are you doing? The paragraph symbol is the color code. If you're including the paragraph symbol (Which you really shouldn't. We've had multiple threads on this topic, but in short, doing this bloats the jar file and may cause problems if the color codes change), then you don't need the translate method, because all that method does is add the paragraph symbol.

    Either remove the colorcode method and leave the paragraph symbol, or replace the symbol with &.
     
  11. Guys, I can use every inventory if I open them with a command. But if I open it from an other inventory it's just not working
     
  12. Offline

    Side8StarLite

    @UnAnswereed
    I tried your code and it should work fine. Can you post the methods that open the shop inventory and the iron shop subinventory?
     
  13. Offline

    Pandi.O

    Maybe you can try: ChatColor.StripColor(e.getInventory().getName()).equalsIgnorCase("iron items"). It's intested but i had issues with the chatcolor before
     
Thread Status:
Not open for further replies.

Share This Page