1.12.2 Animated items

Discussion in 'Spigot Plugin Development' started by MetalWarrior, Feb 20, 2020.

  1. Hello, good afternoon, nights, day, or whatever in your country ...
    I am creating a complement of menus, and I need a way to create animated itemstacks, and that the materials of the itemstacks are in an ArrayList of
    a configuration file, what I don't know how to do is serialize the lists to be able to go through each one individually. I will give an example of what I am trying to say.
    Code (Text):

    Inventory:
      1:
       Material:
       - 'DIAMOND'
       - 'GOLD'
      2:
      Material:
      - 'COAL'
      - 'STONE'
      - 'REDSTONE'
      3:
      Material:
      - 'EMERALD_BLOCK'
     
    Going through the materials I think I know how I could do it, just a BukkitTask. Well, I appreciate any help in advance.
     
  2. config.getList(inventory.1.material) // convert to itemstacks
    bukkitrunnable {
    int index = 0
    void run() {
    setitem(?, list.get(index))
    index++
    }
    }.timer(delay, interval)
     
  3. But how do I get the other strings?
    "1 :, 2 :, 3:"
     
  4. section = config.getconfigsection(inventory)
    list string keys = section.getkeys(false)
    for(key : keys){
    list string materials = section.getstringlist(key + ".material")
    //convert
    }
     
  5. I have this code:
    Code (Text):
        public void Inventory(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9);
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                List<String> list;
                int pos;
                ItemStack stack;
                int i;
                @Override
                public void run() {
                    ConfigurationSection section = plugin.getConfig().getConfigurationSection("Inventory.Items");
                    for(String key : section.getKeys(false)) {
                        list = plugin.getConfig().getStringList("Inventory.Items."+key+".ID");
                        pos = plugin.getConfig().getInt("Inventory.Items."+key+".Pos");
                        stack = new ItemStack(Material.valueOf(list.get(i)));
                        inv.setItem(pos, stack);
                    }
                    if(i < list.size()-1) {
                        i++;
                    }else{
                        i = 0;
                    }
                }
               
            }, 0, 20);
            player.openInventory(inv);
        }
    }
     
    When the size of the lists are equal then the item begins to animate but when a list is equal to 1 then the items do not start to animate, and then when the list is larger than another list it throws error, I will show you the error and the list.
    Code (Text):
    [22:50:46 WARN]: [Prueba] Task #1097 for Prueba v1.0 generated an exception
    java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
            at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_231]
            at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_231]
            at com.theunclebarto.mein.Inv$1.run(Inv.java:48) ~[?:?]
            at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftTask.run(CraftTask.java:76) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:361) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
     
    Code (Text):
    Inventory:
      Items:
        '1':
          ID:
          - DIAMOND
          - COAL
          Pos: 2
        '2':
          ID:
          - DIAMOND_AXE
          - IRON_SWORD
          - IRON_HOE
          Pos: 1