1.14.4 update inventory (itemstack lore)

Discussion in 'Spigot Plugin Development' started by Marshmalah, Jan 18, 2020.

  1. hey, I would like to be able to update my itemstack when someone presses a menu item, for example on this item there are several lore depending on the permissions but when we click on the item its adds a permission but it will not be pressed not display unless the player closes and reopens the menu
    Code (Java):
                ItemStack c1 = new ItemStack(Material.BLUE_DYE);
                ItemMeta c1M = c1.getItemMeta();
                c1M.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                c1M.setCustomModelData(10);
                if(p.hasPermission("forgeron.recette.apprenti.1")) {
                    c1M.setDisplayName(ChatColor.WHITE + "Recette : Silex à Aiguiser Brute");
                    if(p.hasPermission("forgeron.10")) {
                        c1M.setLore(Arrays.asList(ChatColor.DARK_PURPLE+"Composant d'artisanat",ChatColor.GREEN+"Déjà Connue"));    
                    }else {
                        c1M.setLore(Arrays.asList(ChatColor.DARK_PURPLE+"Composant d'artisanat",ChatColor.YELLOW + "Augmente la compétence de 0 - 10",ChatColor.GREEN+"Déjà Connue"));
                    }
                }else {
                    c1M.setDisplayName(ChatColor.WHITE + "Achat - Recette : Silex à Aiguiser Brute");
                    c1M.setLore(Arrays.asList(ChatColor.DARK_PURPLE+"Composant d'artisanat",ChatColor.YELLOW + "Compétence Requis : 1",ChatColor.RED + "Prix : 1000$",ChatColor.RED+"Inconnue"));    
                }
                c1.setItemMeta(c1M);
    I tried to put this but nothing changes on the lore
    Code (Java):
                                        case 0:
                                            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manuaddp "+p.getName()+" forgeron."+competenceup1);
                                            p.sendMessage(ChatColor.BLUE + "[Forge] -> Compétence +1 "+competenceup1+"/75");
                                            p.updateInventory();
                                            return;
    Thanks for watching ;)




     
  2. Something you can do to achieve this is to re-open the inventory for them automatically when you want one of the lores to change.

    I would also recommend using Vault's API for adding/removing permissions and groups from players instead of dispatching commands from console to do this.
     
  3. would you have a tutorial to advise me to go see for this please ?
     
  4. This page tells you how you would hook into vault: https://www.spigotmc.org/wiki/hook-into-vault/

    In your case, since it is for permissions you would only want to hook into the Permission section of vault and not Chat or Economy (unless you need these too). You can then use Permission#playerAdd(String world, OfflinePlayer player, String permission) and Permission#playerRemove(String world, OfflinePlayer player, String permission) to add/remove permissions from a player accordingly. Most of the time for world you would put "null" since I assume you want these permissions to be globally on the server.

    Hopefully that helps, let me know if you have anymore questions :)
     
    • Friendly Friendly x 1
  5. Thanks you man ! I would like to know if I initialize vault permission in my main class I have to reinitialize it in the others under class?

    Have try that in my under class :
    Code (Java):
        private Permission perms;
     
        @SuppressWarnings("unused")
        private boolean setupPermissions() {
            getServer();
            RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }
    and have replace the performcommand with that
    Code (Java):
                        perms.playerAdd(p, "mineur.cuivre");
                        perms.playerAdd(p, "mineur.1");
                        perms.playerAdd(p, "mineur.apprenti");
                        perms.playerAdd(p, "metier.recolte");
                       
    and that don't work
    Edit: ok have see, I forgot the setup in my code, work thanks :)
     
    #5 Marshmalah, Jan 18, 2020
    Last edited: Jan 18, 2020
  6. Sorry I was not available for a lot of today, I am glad to see you got it working though :)

    To answer your question about initialization though: you do not need to re-initialize vault permission under each new class, this would be quite inefficient. Instead, I would suggest to just initialize it in your main class and either pass your main class as a parameter in the constructor of other classes so you can reference it, or pass the vault permission variable itself in constructors or methods in other class files.