Inventory and item unique identifier

Discussion in 'Skript' started by MrNice007, Jul 29, 2020.

  1. Hey it my first post here and after few later of break o am trying to make a own plugin based on spigot
    spigot-api-1.14.1-R0.1-20190527.022734-35
    i know it is outdated but trying to make it work on later version may require a litle tweak to make it run never.

    Ewntualy i am trying to make a self planting farm using droppers or dispensers.
    I scan the inventory for item and then i becomes buggy when i have more then one item
    Code (Java):
    public void ScanInv(Inventory inv) {
            ItemStack[] InvCont = inv.getStorageContents();
            boolean NoHoe = true;
            // inv.firstEmpty()
            for (int x = 0; x < InvCont.length; x++) {
                // for (int j = 0; j < InvCont.length; j++) {
                if (InvCont[x] != null) {
                    // Bukkit.broadcastMessage("item in here: " + InvCont[x].getType().toString() +
                    // " -in slot i: " + x + " ");
                    /*
                     * if(InvCont[i].getType().toString().toLowerCase().contains("_seeds")||InvCont[
                     * i].getType().toString().toLowerCase().contains("_sapling")){
                     * Seeds.put(InvCont[i].getType(), i); Bukkit.broadcastMessage("itemseed/sap"+
                     * InvCont[i].getType()+"in slot i: "+ i+" "); }
                     */

                    if (InvCont[x].getType().toString().toLowerCase().contains("hoe".toLowerCase()) == true
                            && NoHoe == true) {
                        this.HoeIndex = x;
                        NoHoe = false;

                        // String name;
                        setHoeItem(new Hoe(InvCont[x].getType(), 1, x, InvCont[x].getDurability()));
                        // continue;
                    } else {

                        for (String s : KnowSeeding) {
                            if (InvCont[x].getType().toString().toLowerCase().contains(s.toLowerCase())) {
                                Seeds.put(InvCont[x].getType(), x);
                                Seeds1.add(new Seed(InvCont[x].getType(), x, InvCont[x].getAmount()));
                                // Bukkit.broadcastMessage("Seed type"+ InvCont[i].getType()+"in slot i: ");
                            }
                        }
                    }

                    // }
                }
            }
            // Bukkit.broadcastMessage("Hoe " + HoeIndex);
            SortedSet<Entry<Material, Integer>> sorted = entriesSortedByValues(Seeds);
            // Bukkit.broadcastMessage("Sorted seeds" + Arrays.asList(sorted).toString());
            Collections.sort(Seeds1);
            for (Seed seditem : Seeds1) {
                Bukkit.broadcastMessage("Sorted seeds" + seditem.getMat().toString() + " index at " + seditem.getIndex()
                        + " much " + seditem.getAmout());
            }
    but when runing the code with few item in inv i have diffrent results..
    I get 2 diffrent indexes not 0 but for example 3.

    Instead of giving first index of found item in invetory it jumps sometimes and passes it..
    Is there a way to avoid it, using some king of built in id uniqie idntifier of items, and not ites id groups
    or is something that i missed
     
  2. This is not the plugin-section. You've posted this in the Skript section.
     
  3. Sry then can be moved to placed when it should be??