Adding Items from a specified slot further

Discussion in 'Plugin Development' started by Exfamous, Dec 10, 2016.

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

    Exfamous

    Ok so I'm coding a map system, and I when player's join they're givin' a compass that when opened gives active maps( ones they can join ) on top and in the middle there's a splitter. Then the bottom there's the inactive maps (ones they can't join). I've seen many servers have these type of menus where they have it restarting, and etc.. but instead I have inactive. I'm using one file maps.yml that contains a active-list and a inactive-list, they update through commands such as /map activate/deactivate <map>. Then when I do /map create Map it creates a seperate yml for that map, <mapname>.yml.

    So for example I have two maps, Map A, and Map B.

    Here's what the result is so far when I deactivated all my maps (Map A & B)
    https://gyazo.com/f7a64120250266352f623624b16c1e19

    Here's what the result is so far when I activate 1 map and leave the other deactivated:
    Map A activated, Map B deactivated.
    https://gyazo.com/83b21f06941367b35987aeb82dd04613

    Here's what the result is so far when I activate all my maps (Map A & B).
    https://gyazo.com/927640e8a6e12eaa5818037bb579c7cc

    CODE:
    Code:
    public static Inventory ffaMapSelector() {
    
            Inventory inv = Bukkit.createInventory(null, 45, Message.formatMessage("&aSelect a Map : "));
    
    
            for(String active : main.mapsYML.getStringList("maps.active-list")) {
                File f = new File("plugins/Server/FFA/Maps/" + active + ".yml");
                YamlConfiguration y = YamlConfiguration.loadConfiguration(f);
                ItemStack activeMap = new ItemStack(Material.getMaterial(35), 1, (short) 4);
                ItemMeta activeMapM = activeMap.getItemMeta();
                activeMapM.setDisplayName(Message.formatMessage("&a") + active);
                activeMapM.setLore(Arrays.asList(Message.formatMessage("&aActive Map : &fAvailable to join!"),Message.formatMessage("&7(&a" + y.getInt("map-info.players") + "&7/&a" + y.getInt("map-info.max-players") + "&7)")));
                activeMap.setItemMeta(activeMapM);
    
                inv.addItem(activeMap);
            }
    
            ItemStack choose = new ItemStack(Material.MAP);
            ItemMeta chooseM = choose.getItemMeta();
            chooseM.setDisplayName(Message.formatMessage("&aWhere would you like to go?"));
            chooseM.setLore(Arrays.asList(Message.formatMessage("&aActive Maps &fUpward"), Message.formatMessage("&cInactive Maps &fDownward")));
            choose.setItemMeta(chooseM);
    
            ItemStack divider = new ItemStack(Material.getMaterial(160), 1, (short) 4);
            ItemMeta dividerM = divider.getItemMeta();
            dividerM.setDisplayName(" ");
            divider.setItemMeta(dividerM);
    
            inv.setItem(18, divider);
            inv.setItem(19, divider);
            inv.setItem(20, divider);
            inv.setItem(21, divider);
            inv.setItem(22, choose);
            inv.setItem(23, divider);
            inv.setItem(24, divider);
            inv.setItem(25, divider);
            inv.setItem(26, divider);
    
            for(String inactive : main.mapsYML.getStringList("maps.inactive-list")) {
                ItemStack inactiveMap = new ItemStack(Material.getMaterial(35), 1, (short) 14);
                for(ItemStack inactiveMaps : new ItemStack[]{inv.getItem(27),inv.getItem(28),inv.getItem(29),inv.getItem(30),inv.getItem(31),inv.getItem(32),inv.getItem(33),inv.getItem(34),inv.getItem(35),inv.getItem(36),inv.getItem(37),inv.getItem(38),inv.getItem(39),inv.getItem(40),inv.getItem(41),inv.getItem(42),inv.getItem(43),inv.getItem(44)}) {
                    File f = new File("plugins/Server/FFA/Maps/" + inactive + ".yml");
                    YamlConfiguration y = YamlConfiguration.loadConfiguration(f);
                    ItemMeta inactiveMapM = inactiveMap.getItemMeta();
                    inactiveMapM.setDisplayName(Message.formatMessage("&a") + inactive);
                    inactiveMapM.setLore(Arrays.asList(Message.formatMessage("&cInactive Map : &fUnable to join."),Message.formatMessage("&7(&a" + y.getInt("map-info.players") + "&7/&a" + y.getInt("map-info.max-players") + "&7)")));
                    inactiveMap.setItemMeta(inactiveMapM);
    
                    inv.setItem(main.mapsYML.getList("maps.inactive-list").size() + 26, inactiveMap);
                }
    
            }
    
            return inv;
        }
    So, I want to add inactive maps from one slot onward. If you guys can help me it will be greatly appreciated.
     
    Last edited: Dec 10, 2016
  2. Offline

    Exfamous

  3. Offline

    Lordloss

    What exactly is your question?
     
  4. Offline

    Exfamous

    I'm trying to figure out a method that will add items from a specified slot further, so say I choose a slot, 26, and then I wanted to add items from that point forward. Similar to addItems method but this starts from a specific slot.
     
  5. Offline

    JRL1004

    If you are just wanting to know how to add items from a single index onwards, you can just have a counter for the number of items that increases after each item, and add that to the starting index in the inv.

    Here is an example of the code (you may need to tweak it slightly to match yours):
    Code:
    public void addAfterIndex(Inventory inv, int startingIndex, ItemStack... items) {
        int currentSlot = 0; // This is to make sure you don't re-use a slot
        for (ItemStack stack : items) { // Loop through all of the items that you are adding
            inv.setItem(startingIndex + currentSlot, stack); // Place the item in the slot
            currentSlot++; // Change the slot you are using to the next one over
        }
    }
     
  6. Offline

    Exfamous

    That has the same result.
     
  7. Offline

    Exfamous

  8. Offline

    Lordloss

    Could you please post your current code?
     
Thread Status:
Not open for further replies.

Share This Page