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


    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.
    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


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


    I tried to do it that way, but it wasn't
    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"));
         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"));
         return item;
    What is the best method to do this?
    Last edited by a moderator: Jun 21, 2020
  4. Offline


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


    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


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


    Just use:

Thread Status:
Not open for further replies.

Share This Page