[Solved]Creating Custom GUI's | ?

Discussion in 'Spigot Plugin Development' started by UnthinkableR, May 15, 2015.

  1. [BLOCKED BY UNTHINKABLER]
     
    #1 UnthinkableR, May 15, 2015
    Last edited: May 16, 2015
  2. @UnthinkableR I don't thing getConfig() will give you the shop.yml data ;)
     
    • Like Like x 1
    • Agree Agree x 1
  3. Inkzzz

    Resource Staff

    pastebin.com
     
    • Funny Funny x 1
  4. Very repetitive. Use a for loop instead.
     
    • Optimistic Optimistic x 1
    • Useful Useful x 1
  5. New Topic!
     
  6. A little side note:
    You should just make a method for translateAlternateColorCodes and use that rather then repeating it all the time xD
     
  7. @UnthinkableR you can't, it's a language restriction. You will have to use if-else if-else blocks, or use a Map<Material, SomeCallbackObject>.
     
  8. i do use translate alternate color codes
     
  9. can't what?
     
  10. You can't do that what you asked for in that quote
     
  11. oh shall i make a new thread?
     
  12. i just don't like making thousands of threads
    it makes me feel stupid
     
  13. SIDE NOTE: i am stupid XD
     
  14. That's not what I meant, lol. You can't use variables in a switch case, only constants.
     
  15. Okay but er uh how do i switch my case to get the config
     
  16. PHP:
    //KITS GUI
    private void openGUI ( Player player) {
        Inventory i = Bukkit.createInventory(null, 54, ChatColor.DARK_GRAY + getShopConfig().getString("ShopGUI"));

        //LORE
        BeserkerLore.clear();
        TankLore.clear();
        KnightLore.clear();
        MarksmenLore.clear();
        ArcherLore.clear();
    if(getPlayersConfig().getString(player.getName() + ".Kit1").equalsIgnoreCase("true")){
        MarksmenLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("UnlockedStatus")));  
    }else{
        MarksmenLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit1.Lore")));  
    }
    if(getPlayersConfig().getString(player.getName() + ".Kit2").equalsIgnoreCase("true")){
        BeserkerLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("UnlockedStatus")));
    }else{
        BeserkerLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit2.Lore")));      
    }
    if(getPlayersConfig().getString(player.getName() + ".Kit3").equalsIgnoreCase("true")){
        ArcherLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("UnlockedStatus")));
    }else{
        ArcherLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit3.Lore")));  
    }
    if(getPlayersConfig().getString(player.getName() + ".Kit4").equalsIgnoreCase("true")){
        TankLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("UnlockedStatus")));
    }else{
       
    }    TankLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit4.Lore")));
    if(getPlayersConfig().getString(player.getName() + ".Kit5").equalsIgnoreCase("true")){
        KnightLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("UnlockedStatus")));
    }else{
        KnightLore.add(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit5.Lore")));  
    }



       
        //LORE
       
        ItemStack Back = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15);
        ItemMeta BackMeta = Back.getItemMeta();
       
        BackMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&8&l&m-"));
        Back.setItemMeta(BackMeta);
       
        ItemStack Knight = new ItemStack(Material.matchMaterial(getShopConfig().getString("Kits.Kit5.Item")));
        ItemMeta KnightMeta = Knight.getItemMeta();
       
        KnightMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit5.Prefix") + getShopConfig().getString("Kits.Kit5.Name")));
        KnightMeta.setLore(KnightLore);
        Knight.setItemMeta(KnightMeta);
       
        ItemStack Tank = new ItemStack(Material.matchMaterial(getShopConfig().getString("Kits.Kit4.Item")));
        ItemMeta TankMeta = Tank.getItemMeta();
       
        TankMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit4.Prefix") + getShopConfig().getString("Kits.Kit4.Name")));
        TankMeta.setLore(TankLore);
        Tank.setItemMeta(TankMeta);
       
        ItemStack Archer = new ItemStack(Material.matchMaterial(getShopConfig().getString("Kits.Kit3.Item")));
        ItemMeta ArcherMeta = Archer.getItemMeta();
       
        ArcherMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit3.Prefix") + getShopConfig().getString("Kits.Kit3.Name")));
        ArcherMeta.setLore(ArcherLore);
        Archer.setItemMeta(ArcherMeta);
       
        ItemStack Beserker = new ItemStack(Material.matchMaterial(getShopConfig().getString("Kits.Kit2.Item")));
        ItemMeta BeserkerMeta = Beserker.getItemMeta();
       
        BeserkerMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit2.Prefix") + getShopConfig().getString("Kits.Kit2.Name")));
        BeserkerMeta.setLore(BeserkerLore);
        Beserker.setItemMeta(BeserkerMeta);
       
        ItemStack BAL = new ItemStack(Material.DIAMOND);
        ItemMeta BALMeta = BAL.getItemMeta();
       
        BALMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&7&lCOINS: &8&l" + getPlayersConfig().getString(player.getName() + ".coins")));
        BAL.setItemMeta(BALMeta);
       
       
        ItemStack Marksmen = new ItemStack(Material.matchMaterial(getShopConfig().getString("Kits.Kit1.Item")));
        ItemMeta MarksmenMeta = Marksmen.getItemMeta();
       
        MarksmenMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getShopConfig().getString("Kits.Kit1.Prefix") + getShopConfig().getString("Kits.Kit1.Name")));
        MarksmenMeta.setLore(MarksmenLore);
        Marksmen.setItemMeta(MarksmenMeta);
       
        i.setItem(0, Back);
        i.setItem(1, Back);
        i.setItem(2, Back);
        i.setItem(3, Back);
        i.setItem(4, BAL);
        i.setItem(5, Back);
        i.setItem(6, Back);
        i.setItem(7, Back);
        i.setItem(8, Back);
        i.setItem(9, Back);
        i.setItem(10, Back);
        i.setItem(11, Back);
        i.setItem(12, Back);
        i.setItem(13, Back);
        i.setItem(14, Back);
        i.setItem(15, Back);
        i.setItem(16, Back);
        i.setItem(17, Back);
        i.setItem(18, Back);
        i.setItem(19, Back);
        i.setItem(20, Knight);
        i.setItem(21, Tank);
        i.setItem(22, Archer);
        i.setItem(23, Beserker);
        i.setItem(24, Marksmen);
        i.setItem(25, Back);
        i.setItem(26, Back);
        i.setItem(27, Back);
        i.setItem(28, Back);
        i.setItem(29, Back);
        i.setItem(30, Back);
        i.setItem(31, Back);
        i.setItem(32, Back);
        i.setItem(33, Back);
        i.setItem(34, Back);
        i.setItem(35, Back);
        i.setItem(36, Back);
        i.setItem(37, Back);
        i.setItem(38, Back);
        i.setItem(39, Back);
        i.setItem(40, Back);
        i.setItem(41, Back);
        i.setItem(42, Back);
        i.setItem(43, Back);
        i.setItem(44, Back);
        i.setItem(45, Back);
        i.setItem(46, Back);
        i.setItem(47, Back);
        i.setItem(48, Back);
        i.setItem(49, Back);
        i.setItem(50, Back);
        i.setItem(51, Back);
        i.setItem(52, Back);
        i.setItem(53, Back);

        player.openInventory(i);
    }
    //KITS GUI EVENT
    @EventHandler
    public void onInventoryClickEvent(InventoryClickEvent e) {
        if(!ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase(getShopConfig().getString("ShopGUI")))
        return;
        Player p = (Player) e.getWhoClicked();
        e.setCancelled(true);
       
        if(e.getCurrentItem() == null
                || e.getCurrentItem().getType() == Material.AIR
                || !e.getCurrentItem().hasItemMeta()) {
            p.closeInventory();
            return;
        }
       
        switch (e.getCurrentItem().getType()){
        case CHEST:      
           
           
            break;
        case STAINED_GLASS_PANE:
                e.setCancelled(true);
            break;
        case REDSTONE_TORCH_ON:
            p.closeInventory();
        break;
        default:
            p.closeInventory();
            break;
           
    }      
        }
     
  17. I mean a method so you only have to do something like
    format(String);
    instead of ChatColor.translateAlternateColorCodes(String);
    but it's up to you
     
  18. Code (Text):
    private static String format(String s){
    return ChatColor.translateAlternateColorCodes('&', s);
    }
     
  19. i have done it like so:
    Code (Text):
    public static void sendMessage(Player p, String message){
            p.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
            Methods.sendTitle(p, 1, 5, 1, "KitPvP", message);
        }