Solved Getting inventory name issue

Discussion in 'Plugin Development' started by ILoveCode, Nov 21, 2015.

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

    ILoveCode

    So I have this code that does not work. When I say it does not work, I mean that it does not get called even though the inventory name is correct.
    Code:
                  if(player.getInventory().getTitle().equalsIgnoreCase(utils.format(core.getConfig().getString("InventoryTitle")))){
                        player.closeInventory();
                    }
    I have also tried using player.getInventory().getName() but that did not do anything too. This code is part of a runnable. Full method:
    Code:
        public void closeGame(final Player player){
            new BukkitRunnable(){
    
                @Override
                public void run() {
                    if(core.getConfig().getInt("Time")==0){
                        return;
                    }
                    if(player.getInventory().getTitle().equalsIgnoreCase(utils.format(core.getConfig().getString("InventoryTitle")))){
                        player.closeInventory();
                    }
                }
            }.runTaskLater(core, core.getConfig().getInt("Time")*20);
        }
    Any help is appreciated!
     
  2. Offline

    CraftCreeper6

    @ILoveCode
    Are you sure that "InventoryTitle" isn't set to something other in the config?
     
  3. Offline

    Creeper674

    Try messaging yourself the value of player.getInventory().getTitle(), to see if that is the same as what you have in config under 'InventoryTitle'.
     
  4. Offline

    ILoveCode

    I am 100% sure. I even copied and pasted the String just to make sure I had no spelling mistakes.
     
  5. Offline

    CraftCreeper6

  6. Offline

    ILoveCode

    So I did what @Creeper674 said and it keeps returning the following: "container.inventory" Here is my method that I used to test:
    Code:
        public void debugTest(Player player){
            player.sendMessage(utils.format(player.getInventory().getTitle()));
        }
    If you are wondering what utils.format does, it's just a method that returns ChatColor.translateAltColorCodes.
     
  7. Offline

    Zombie_Striker

    You should make a method that get/stores the inventorie's title, and instead of formatting it each time, just get that instance.
     
  8. Offline

    ILoveCode

    @Zombie_Striker I am going to try to use InventoryOpenEvent and go on from there.

    EDIT: InventoryOpenEvent solved my problem. Going to mark this as solved. Thanks to everyone who helped though!
     
Thread Status:
Not open for further replies.

Share This Page