pvp kit selection menu help?

Discussion in 'Plugin Development' started by thewalkingplay, Jun 5, 2015.

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

    thewalkingplay

    hi, i'm making a pvp plugin and i need to make a pvp kit selection menu, what can i do to get all the gui items for the kits? the plugin saves in the config this item(name) with this path: kits.<NAME>.mst
    "mst" because i'm brazilian and is the abreviation of "mostruario" (showcase in english). I don't know if this will help:

    Kit Manager class:
    Code:
    package me.thewalkingplay.pvp.utils;
    
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    
    import me.thewalkingplay.pvp.Events;
    import me.thewalkingplay.pvp.Main;
    
    public class KitManager extends Events {
    
        public KitManager(Main pl) {
            super(pl);
        }
       
        public static void setKit(Player p, String kit) {
            p.getInventory().clear();
           
            @SuppressWarnings("unchecked")
            List<ItemStack> armorList = (List<ItemStack>)plugin.getConfig().get("kits." + kit + ".armor");
            ItemStack[] armor = armorList.toArray(new ItemStack[0]);
            p.getInventory().setArmorContents(armor);
           
            @SuppressWarnings("unchecked")
            List<ItemStack> itemList = (List<ItemStack>)plugin.getConfig().get("kits." + kit + ".items");
            ItemStack[] items = itemList.toArray(new ItemStack[0]);
            p.getInventory().addItem(items);
            p.sendMessage(ChatColor.GREEN + "Kit " + kit + " selecionado!");
           
        }
       
        public static void getKitItem(String kit) {
           
            // GET KIT ITEMS CODE HERE
           
        }
    
    }
    
    kit creator class:
    Code:
    package me.thewalkingplay.pvp.utils;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import me.thewalkingplay.pvp.Events;
    import me.thewalkingplay.pvp.Main;
    
    public class KitCreator extends Events implements CommandExecutor {
    
        public KitCreator(Main pl) {
            super(pl);
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String arg, String[] arg3) {
            if (sender instanceof Player) {
                if (cmd.getName().equalsIgnoreCase("createkit")) {
                    Player p = (Player)sender;
                    if (p.hasPermission("pvp.createkit") && arg3[0] != null) {
                       
                        String nome = arg3[0];
                        String item = arg3[1];
                        if (plugin.getConfig().get("kits." + nome) == null) {
                            plugin.getConfig().set("kits." + nome + ".items", p.getInventory().getContents());
                            plugin.getConfig().set("kits." + nome + ".armor", p.getInventory().getArmorContents());
                            plugin.getConfig().set("kits." + nome + ".mst", item);
                            plugin.saveConfig();
                            p.sendMessage(ChatColor.GREEN + "kit " + nome + " criado!");
                           
                            return true;
                        } else {
                            p.sendMessage(ChatColor.RED + "Este kit ja existe!");
                        }
                       
                       
                       
                       
                    } else {
                        p.sendMessage(ChatColor.RED + "Eu acho que voce falhou em sua missao de executar este comando :v");
                        return true;
                    }
                   
                   
                }
               
               
            } else {
                sender.sendMessage(ChatColor.RED + "Este comando so pode ser executado por um player");
            }
            return false;
        }
       
    
    }
    
    the "event" class just implements listener and defines the main class as a plugin

    can anyone help me?
    sorry for my english, i'm brazilian
     
  2. Offline

    mine-care

    Where exacly you need help? Please specify. Do you need with the creation of the inventory? with adding items? what?
     
  3. Offline

    thewalkingplay

    @mine-care i need help to get the item that will show in the inventory
     
  4. Offline

    Monollyth

    You're doing this way more complicated than it needs to be. You do not 'need' a createkit method, however if you want one, that is fine. The way I'd create a kit is when a player runs the command for that kit, you'd just assign them all the abilities/armor/weapons of that certain kit. For going about creating a Kit GUI, just call a PlayerInteractEvent, and check if the player is right clicking/holding a certain item. If so, Use "Inventory inv = Bukkit.createInventory(null, title, slots);". Then just create ItemStacks with displaynames of the Kits and add them to the inventory. Also, don't forget to open the inventory for the player using "p.openInventory(inv);".
    Hope this helped! :D
     
  5. Offline

    thewalkingplay

    @Monollyth i know how to create, open an iventory and add items, but i need a method to select all the showcase items for the kits without add more code for witch new kit that i add
     
  6. Offline

    Monollyth

    @thewalkingplay Ah. Well, I've done this in the past with some of my plugins. You could make a method called "openGUI" or whatever you want, and have all the showcase items for the kits pre-made inside of it, so the outcome is only one line of code. However, if you are going about making more than one GUI, I've used an enum for GUI's to specify in the method which GUI I want to open.
     
  7. Offline

    Reynergodoy

    FOR EDUCATIVE PURPOSES THIS WILL BE IN PORTUGUESE:
    Cara, você pederia usar o integer, como por exemplo:
    public static int = nomedokit
    daí você poderia botar em

    ItemStack hg = new ItemStack(Material.BROWN_MUSHROOM);
    ItemMeta khg = hg.getItemMeta();
    khg.setDisplayName(ChatColor.GOLD + nomedokit);
    List<String> lhg = new ArrayList<>();
    lhg.add(ChatColor.GOLD + "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
    lhg.add(ChatColor.GOLD + " Para jogadores Hardcore!");
    lhg.add(ChatColor.GOLD + "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
    khg.setLore(lhg);
    hg.setItemMeta(khg);

    daí na hora que criar o kit usando o comando, ele poderia acionar o evento de integer pra colocar no inventario de kits criados :)

    toma um exemplo basico:
    CRIARKIT (open)

    Code:
    package me.thewalkingplay.pvp.utils;
    
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    
    import SUACLASSEMAIN;
    
    public class KitGlobal
      implements Listener, CommandExecutor
    {
      public HashMap<String, ItemStack[]> kits = new HashMap<>();
      public HashMap<String, ItemStack[]> armor = new HashMap<>();
    
      public KitGlobal(Main main) {
    }
    
    public KitGlobal() {
    }
    
    public boolean isInt(String s)
      {
        try
        {
          Integer.parseInt(s);
          return true;
        }
        catch (NumberFormatException localNumberFormatException) {}
        return false;
      }
    
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if (!(sender instanceof Player))
        {
          sender.sendMessage(ChatColor.RED + "Somente jogadores podem executar este comando!");
          return true;
        }
        Player p = (Player)sender;
        if ((cmd.getName().equalsIgnoreCase("globalkit")) && (
          (p.hasPermission("AccelPvP.Admin")) || (p.isOp())))
        {
          if (args.length == 0)
          {
            p.sendMessage(ChatColor.AQUA + "Como criar um globalkit(kit para eventos):");
            p.sendMessage(ChatColor.GRAY + "1º - Monte seu inventario da maneira como quer que os jogadores recebam");
            p.sendMessage(ChatColor.GRAY + "2º - Digite /globalkit criar <nome>");
            p.sendMessage(ChatColor.RED + " ");
            p.sendMessage(ChatColor.GREEN + "Como aplicar um globalkit:");
            p.sendMessage(ChatColor.GRAY + "1º - Digite /globalkit aplicar <nome> <raio>");
            p.sendMessage(ChatColor.RED + "OBS.:" + ChatColor.GRAY + " O kit precisa ter sido criado previamente!");
            return true;
          }
          if (args[0].equalsIgnoreCase("criar"))
          {
            if (args.length == 1)
            {
              p.sendMessage(ChatColor.AQUA + "Como criar um globalkit:");
              p.sendMessage(ChatColor.GRAY + "1º - Monte seu inventario da maneira como quer que os jogadores recebam");
              p.sendMessage(ChatColor.GRAY + "2º - Digite /globalkit criar <nome>");
              return true;
            }
            String name = args[1];
            this.kits.put(name, p.getInventory().getContents());
            this.armor.put(name, p.getInventory().getArmorContents());
            p.sendMessage(ChatColor.GREEN + "Kit " + args[1] + " criado com sucesso!");
            return true;
          }
          if (args[0].equalsIgnoreCase("aplicar"))
          {
            if (args.length <= 2)
            {
              p.sendMessage(ChatColor.GREEN + "Como aplicar um globalkit:");
              p.sendMessage(ChatColor.GRAY + "1º - Digite /globalkit aplicar <nome> <raio>");
              p.sendMessage(ChatColor.RED + "OBS.:" + ChatColor.GRAY + " O kit precisa ter sido criado previamente!");
              return true;
            }
            String name = args[1];
            if ((!this.kits.containsKey(name)) && (!this.armor.containsKey(name)))
            {
              p.sendMessage(ChatColor.RED + "Kit " + name + " nao encontrado!");
              return true;
            }
            if (isInt(args[2]))
            {
              int numero = Integer.parseInt(args[2]);
              for (Entity ent : p.getNearbyEntities(numero, numero, numero)) {
                if ((ent instanceof Player))
                {
                  Player plr = (Player)ent;
                  plr.getInventory().setArmorContents((ItemStack[])this.armor.get(name));
                  plr.getInventory().setContents((ItemStack[])this.kits.get(name));
                }
              }
              Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "Kit " + name + " aplicado para jogadores em um raio de " + numero + " blocos");
              p.sendMessage(ChatColor.GREEN + "Kit " + name + " aplicado para jogadores em um raio de " + numero + " blocos");
              return true;
            }
            return true;
          }
        }
        if ((cmd.getName().equalsIgnoreCase("setarpvp")) && (
          (p.hasPermission("AccelPvP.setarpvp")) || (p.isOp())))
        {
          if (p.getWorld().getPVP())
          {
            p.getWorld().setPVP(false);
            Bukkit.getServer().broadcastMessage(ChatColor.RED + "" + ChatColor.BOLD + "PvP Desativado");
            return true;
          }
          p.getWorld().setPVP(true);
          Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "PvP Ativado");
          return true;
        }
        return true;
      }
    }
    


    Agora você só precisa linkar isso com o seu kit selector

    Porém isso vai ser bem difícil, considerando que você é um iniciante ( também sou :))
     
  8. Offline

    Monollyth

    @Reynergodoy Just some advice when making ItemStacks for GUIs. I find the way you're making an ItemStack to be long and tedious when making a GUI with tons of items. I resorted to using a method like this:

    Code:
        public static void addGuiItem(Material m, String displayName, List<String> lore, Inventory inv, int slot)
        {
            ItemStack i = new ItemStack(m);
            ItemMeta me = i.getItemMeta();
            me.setDisplayName(displayName);
            me.setLore(lore);
            i.setItemMeta(me);
            inv.setItem(slot, i);
        }
    This way, you can add items in one line of code. :)
     
Thread Status:
Not open for further replies.

Share This Page