Solved Player Inventory re-rendering

Discussion in 'Plugin Development' started by chunza2542, Mar 22, 2017.

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

    chunza2542

    In this week, I try to make a plugin to change displayName with inventory GUI.

    This is a picture of my plugin:
    [​IMG]
    If you see the paper on the top of inventory, This paper is showing a player the new displayName with color when the player clicked on stained glass pane to select a name color.

    But my problem is: When I reRender(update) displayName of paper. All player in the server are update to same. How can I write code to update paper displayName only player who clicked not for all player in the server.

    Here is my paperRender code:
    Code:
       private void paperRender(String displayName){
            ItemStack paper = new ItemStack(Material.PAPER, 1);
            ItemMeta mpaper = paper.getItemMeta();
            mpaper.setDisplayName(displayName);
            paper.setItemMeta(mpaper);
           
            for(int i = 0; i < 9; i++){
                inv.setItem(i, paper);
            }
        }
    onInventoryClick Event code:
    Code:
    @EventHandler
        public void onInventoryClick(InventoryClickEvent e){
            if(!(e.getInventory().getName().equalsIgnoreCase(inv.getName()))) return;
            if(e.getCurrentItem().getItemMeta() == null) return;
            e.setCancelled(true);
            if(e.getCurrentItem().getType() == Material.STAINED_GLASS_PANE){
                String color = colorConvertor(e.getCurrentItem().getItemMeta().getDisplayName());
                paperRender(color+"TEST");
            }
        }
    Thank you.
    Sorry for my English.
     
  2. Offline

    Caderape2

    @chunza2542 You have may be only one inventory created for everyone. If i understand well what you're saying.
    Create an inventory per player
     
  3. Offline

    Ragnarok_

    @chunza2542
    Maybe just set the name in the click event, and then reopen it(reopening is basically updating it)
    Code:
    @EventHandler
        public void onInventoryClick(InventoryClickEvent  e) {
            ItemStack paper = new ItemStack(Material.PAPER, 1);
            ItemMeta mpaper = paper.getItemMeta();
            mpaper.setDisplayName(displayName);
            paper.setItemMeta(mpaper);
          
            e.getWhoClicked().openInventory(inventory)
     
  4. Offline

    Zombie_Striker

    @chunza2542
    If you want each player to see something different in the inventory, you should just create different inventories.
     
  5. Offline

    chunza2542

    Thank you. I find the solution that I should use hashmap.
     
  6. Offline

    Zombie_Striker

    @chunza2542
    If your problem has been solved, mark this thread as solved.
     
    chunza2542 likes this.
Thread Status:
Not open for further replies.

Share This Page