Solved Inventory click not initiating straight away

Discussion in 'Plugin Development' started by mythridleg35, Jun 30, 2014.

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

    mythridleg35

    Hey, im working on a plugin and i am having a strange problem i have never encountered, i have setup a PlayerInteractEntityEvent to detect when a player clicks on a npc and it will open a GUI and once this gui is open players can move things back and forward from there bank and there backpack, but when they close the inventory all items they took out dissapear and go back into the bank, but if you then click on the npc again and repeat it works fine.

    The reason i think this is a problem with the inventory click event is because 9 of the 54 possible items in the GUi i create cannot be moved or swapped over but they can be when this problem happens, but thee is no error.

    i have checked and there is no lag causing this and if i make the GUI open on a block interact event or with a command it works with no problem, anyone seen this problem before or is it a bug with the current bukkit build?



    Solution add a small delay
    Code:
                if(entName.equals(Npcs.Banker.name())){
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
                    {
                      public void run()
                      {
                          Bank.openPage(p, 1);
                      }
                    }, 2L);
                   
                }
    Thumpy Bumpy

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    minoneer

    Would you mind sharing the applicable code with us?
     
  3. Offline

    MoeMix

    mythridleg35
    When you create the inventory, are you setting the player as the holder/owner of the inventory?

    share your code so we can solve this.
     
  4. Offline

    mythridleg35

    Bank.Class
    Code:
    public static void openPage(Player p, int pageNumb) {
    Inventory inv = Bukkit.createInventory(p.getPlayer(), 54, p.getDisplayName()+" Bank, Page "+pageNumb);
    String page = Main.bankconfig.getString(p.getDisplayName()+"."+pageNumb);
    String[] parts = page.split(",");
    for(int a=0;a<9;a++){
    ItemStack tab = new ItemStack(Material.WOOL);
    ItemMeta im = tab.getItemMeta();
    im.setDisplayName(ChatColor.LIGHT_PURPLE+"Page: "+(a+1));
    tab.setItemMeta(im);
    inv.setItem(a, tab);
    }
    int count = 8;
    int i = 0;
    if(parts.toString()!=""){
    for(String s:parts){
    count++;
    if(!s.equals("")){
    int itemAmount = Integer.parseInt(parts.split(":")[1]);
    ItemStack item = Items.getByName(parts.split(":")[0]).generateItem();
    item.setAmount(itemAmount);
    inv.setItem(count, item);
    }
    i++;
    }
    }
    p.openInventory(inv);
    }
     
     
    
    Click Listener (Relevant part)
    Code:
    Player p = (Player)e.getWhoClicked();
    if(e.getInventory().getTitle().contains("Bank")){
    if(e.getRawSlot()<=8){
    e.setCancelled(true);
    p.closeInventory();
    Bank.openPage(p, (e.getRawSlot()+1));
    }
    }
    The reason i get items in such a uniqe way is because i have over 3k diffrent items in my items.class and 99% of them are not allowed to stack, and i save the bank config in this fashion (item name: amount) as a eg or (BronzeHatchet:1,SmallGoldPile:3)

    De Thumpy bumpy

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    mythridleg35

    Yet Another Thumpy Bumpy
     
  6. Offline

    fireblast709

  7. Offline

    mythridleg35

    Thanks man, its such a derpy fix but it works and if anyone else has this issue hear is the code i used to fix it
    Code:
                if(entName.equals(Npcs.Banker.name())){
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
                    {
                      public void run()
                      {
                          Bank.openPage(p, 1);
                      }
                    }, 2L);
                   
                }
     
  8. mythridleg35 It's not really a derpy solution if you think about it as trying to click an item, close the inventory, and then open a new one at the same time, no wonder it gets confused :)
     
  9. Offline

    mythridleg35

    It is tho because you closing the inventory and the server sends the packet saying its closed and then send the new packet and the player actually seed the new inventory but bukkit just wants to be temperamental and not recognize anything on it.
     
Thread Status:
Not open for further replies.

Share This Page