Trying to change color of leather helmet with repeating task while open does not work

Discussion in 'Spigot Plugin Development' started by Bolt, Jul 8, 2015.

  1. I'm trying to create a color-changing leather helmet in an inventory gui but for some reason, the item doesn't change color. I've added debug statements inside to check if the task actually ran and I can't figure out why if I print out the colors to console, it shows that the color actually changes but in-game, the leather helmet stays the same color. If I close it and reopen it again, it sometimes changes color from what it originally was but I still can't figure out why it doesn't change while I'm actively viewing the inventory.
    Code (Text):
    taskid = Bukkit.getScheduler().scheduleSyncRepeatingTask(
                        LastShot.instance, new Runnable() {

                            int index = 0;

                            public void run() {

                                InventoryView view = player.getOpenInventory();
                                Inventory inv = view.getTopInventory();
                                if (inv == null) {
                                ItemStack random = inv.getItem(0);
                                if (random == null) {
                                LeatherArmorMeta im = (LeatherArmorMeta) random
                                Team team = teams.get(teamkeys.get(index));
                                Color color = KitUtils.getColor(team.getColor());
                                inv.setItem(0, random);
                                System.out.println(((LeatherArmorMeta) inv.getItem(0).getItemMeta()).getColor());
                                if (index + 1 < teamkeys.size()) {
                                } else {
                                    index = 0;


                        }, 0, 5);
  2. Try calling Player#updateInventory () after setting the new values for the leather armor. Judging by what you said everything is working but the player cant see these changes.
  3. I didn't realize that there was an updateInventory method. Thanks so much! :)