Kits in GUI with permissions.

Discussion in 'Plugin Development' started by rykker_, Jun 24, 2020.

  1. Offline

    rykker_

    Hi, how can I do it for example: "if the player has permission (gracz.kits) set with (food) and the set (kit gracz) will be visible to him". And for example: "if the player has permission (vip.kits), set with (food), set with (kit gracz) and (kit vip)" will be visible to him. Same with SVIP.

    CODE (InventoryClickEvent):
    Code:
    package GUI;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    
    public class GUIMoveItem implements Listener{
        @EventHandler
        public void clickEvent(InventoryClickEvent e){
            //Check to see if its the GUI menu
            if(e.getView().getTitle().equals(ChatColor.AQUA + "Custom GUI")){
                Player player = (Player) e.getWhoClicked();
                Material item = e.getCurrentItem().getType();
                if (item == Material.COOKED_BEEF) {
                    player.setFoodLevel(20);
                    e.setCancelled(true);
                }
                if (item == Material.LEATHER_HELMET) {
                    player.sendMessage("1");
                    e.setCancelled(true);
                }
                if (item == Material.CHAINMAIL_HELMET) {
                    player.sendMessage("3");
                    e.setCancelled(true);
                }
                if (item == Material.IRON_HELMET) {
                    player.sendMessage("3");
                    e.setCancelled(true);
                }
                if (item == Material.GOLDEN_HELMET) {
                    player.sendMessage("3");
                    e.setCancelled(true);
               
                }
                if (item == Material.TNT) {
                    player.sendMessage("4");
                    e.setCancelled(true);
               
                }
            }
        }   
    }
    CODE (Inventory, command):
    Code:
    package GUI;
    
    import org.bukkit.Bukkit;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import java.util.ArrayList;
    public class GUICommand implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(sender instanceof Player){
                Player player = (Player) sender;
                Inventory gui = Bukkit.createInventory(player, 9, ChatColor.AQUA + "Custom GUI");
                //Menu Options(Items)
                ItemStack TNT = new ItemStack(Material.TNT);
                ItemStack beef =  new ItemStack(Material.COOKED_BEEF);
                ItemStack lhelmet =  new ItemStack(Material.CHAINMAIL_HELMET);
                ItemStack chelmet = new ItemStack(Material.IRON_HELMET);
                ItemStack ihelmet = new ItemStack(Material.GOLDEN_HELMET);
                //Edit the items
                ItemMeta tnt_meta = TNT.getItemMeta();
                tnt_meta.setDisplayName("§7Zestaw z §c§lTNT");
                ArrayList<String> tnt_lore = new ArrayList<>();
                tnt_lore.add(ChatColor.GOLD + "Kill yourself. ;)");
                tnt_meta.setLore(tnt_lore);
                TNT.setItemMeta(tnt_meta);
                ItemMeta beef_meta = beef.getItemMeta();
                beef_meta.setDisplayName("§7Zestaw z §a§lJedzeniem");
                ArrayList<String> beef_lore = new ArrayList<>();
                beef_lore.add(ChatColor.GOLD + "Hunger no more.");
                beef_meta.setLore(beef_lore);
                beef.setItemMeta(beef_meta);
                ItemMeta lhelmet_meta = lhelmet.getItemMeta();
                lhelmet_meta.setDisplayName("§7Zestaw z §8§lKIT GRACZ");
                ArrayList<String> lhelmet_lore = new ArrayList<>();
                lhelmet_lore.add(ChatColor.GOLD + "Get a sword.");
                lhelmet_meta.setLore(lhelmet_lore);
                lhelmet.setItemMeta(lhelmet_meta);
               
                ItemMeta chelmet_meta = chelmet.getItemMeta();
                chelmet_meta.setDisplayName("§7Zestaw z §a§lKIT VIP");
                ArrayList<String> chelmet_lore = new ArrayList<>();
                chelmet_lore.add(ChatColor.GOLD + "Get a sword.");
                chelmet_meta.setLore(chelmet_lore);
                chelmet.setItemMeta(chelmet_meta);
               
                ItemMeta ihelmet_meta = ihelmet.getItemMeta();
                ihelmet_meta.setDisplayName("§7Zestaw z §6§lKIT SVIP");
                ArrayList<String> ihelmet_lore = new ArrayList<>();
                ihelmet_lore.add(ChatColor.GOLD + "Get a sword.");
                ihelmet_meta.setLore(ihelmet_lore);
                ihelmet.setItemMeta(ihelmet_meta);
    
                ItemStack[] menu_items3 = {TNT, beef, lhelmet, chelmet, ihelmet};
                gui.setContents(menu_items3);
                player.openInventory(gui);
              
            }
            return true;
        }
    }
     
  2. Offline

    timtower Moderator Moderator

    @rykker_ Check the permission when creating the items, only create the items that the player has permission for.
     
    rykker_ likes this.
  3. Offline

    rykker_

    @timtower OK, how can I do this, I'm new to plugin programming
     
    Last edited by a moderator: Jun 24, 2020
  4. Offline

    mAndAle

    You can do that with:
    Code:
    if (p.hasPermission("gracz.1")){
      //your code
    }
     
    rykker_ likes this.

Share This Page