Modify menu items according to permissions

Discussion in 'Plugin Development' started by nnx, Jun 21, 2020.

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

    nnx

    Hi everyone! I'm from Russia and I don't speak English, I'm using Google Translate. If I have mistakes in writing, sorry.

    I would like to create a menu, and according to the player's permission the item would be modified.
    Example:
    Vip Area - permission: viparea.local (example)
    If the player has this permission the item would be an emerald;
    If not, it would be a barrier.

    Thanks for listening!
     
  2. Offline

    KarimAKL

    @nnx You create a new inventory for every player, then you set the items according to their permissions.
     
  3. Offline

    nnx

    I tried to do it that way, but it wasn't
    Code:
    import java.util.Arrays;
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class LocalsMenu {
    
       private HashMap<Player, Object> view = new HashMap<>();
    
       public HashMap<Player, Object> getView() {
         return view;
       }
    
       public void open(Player p) {
         Inventory inv = Bukkit.createInventory(null, 3 * 9, "Mines");
         boolean perm1 = p.hasPermission("core.1");
       
    
         if (perm1) {
           inv.setItem(10, getMine1());
         } else {
           inv.setItem(10, getMina1Perm());
    
         }
       }
    
       private ItemStack getMine1() {
         ItemStack item = new ItemStack(Material.DIRT);
         ItemMeta meta = item.getItemMeta();
         meta.setDisplayName("§eDirt Mine");
         meta.setLore(Arrays.asList("§7Click to tepeort"));
         item.setItemMeta(meta);
         return item;
       }
    
       private ItemStack getMine1Perm() {
         ItemStack item = new ItemStack(Material.BARRIER);
         ItemMeta meta = item.getItemMeta();
         meta.setDisplayName("§eMina Terra");
         meta.setLore(Arrays.asList("§cNo permission"));
         item.setItemMeta(meta);
         return item;
       }
    
    What is the best method to do this?
     
    Last edited by a moderator: Jun 21, 2020
  4. Offline

    KarimAKL

    @nnx You're creating the inventory without either returning the inventory or opening the inventory to the player.
     
  5. Offline

    nnx

    PS: English from Google Translate

    Should I create all items using ItemStack and within the Listener define the permissions and items that will be returned?
     
  6. Offline

    KarimAKL

    @nnx You simply need to open the inventory to the player using the Player#openInventory(Inventory) method.
     
  7. Offline

    mAndAle

    Just use:

    Code:
    p.openInventory(//yourinventory)
    
     
Thread Status:
Not open for further replies.

Share This Page