1.12.2 Animated ItemStack

Discussion in 'Spigot Plugin Development' started by Nico12, Feb 18, 2020.

  1. Hi! I am working on a complement with inventory animations, I have a method to animate the elements consisting of a BukkitTask that changes the element every 1 second, the list is as follows:
    Code (Text):

      - 'END_STONE'
      - 'GOLD_PICKAXE'
    X: 5
    Y: 1
      - 'IRON SWORD'
    X: 4
    Y: 1
    Well, what I do to check the lists is list.get (i);
    and when it reaches the end I need it to review the list again and so create a cycle, then I do:
    if (itemIndex <list.size () - 1) {
    } else {
    itemIndex = 0;
    but it happens that if the lists do not have the same size the animation does not work and the int i always stays at 0
    Will you help me fix it?
    Code (Text):

    public void inventoryContents(Player player, String fileName) {
            File file = new File(plugin.folder(), fileName);
            FileConfiguration config = YamlConfiguration.loadConfiguration(file);
            Inventory inv = Bukkit.createInventory(null, 54, "");
            BukkitScheduler sc = Bukkit.getServer().getScheduler();
            sc.scheduleSyncRepeatingTask(plugin, new Runnable() {
                List<String> items;
                int itemIndex = 0;

                int X;
                int Y;
                ItemStack stack;
                public void run() {
                    for(String itemkey : config.getConfigurationSection("Inventory.Items").getKeys(false)) {
                        items = new ArrayList<String>(config.getStringList("Inventory.Items."+itemkey+".ID"));
                        X = config.getInt("Inventory.Items."+itemkey+".X");
                        Y = config.getInt("Inventory.Items."+itemkey+".Y");
                            stack = new ItemStack(Material.valueOf(ChatColor.translateAlternateColorCodes('&', items.get(itemIndex))));
                            inv.setItem(Y*9-1-9+X, stack);
                            if(itemIndex < items.size()-1) {
                            }else {
                                itemIndex = 0;
            }, 0, 20);
    #1 Nico12, Feb 18, 2020
    Last edited: Feb 18, 2020
  2. Are you trying to animate it like those crates type?(where a row of line scrolls to the left?)
  3. No, I just want to change the item every 1 second
  4. Your problem is the items ArrayList is empty. “1” and “2” are lists, they don’t have an “ID” section inside them.
  5. Sorry, forget to put "ID" in the example above, the "ID" if it is placed in the configuration file, what happens is that if the size of the lists are not equal then the items do not change, but if the Size of the lists are the same the ArrayList starts to run