setBrewingTime error?

Discussion in 'Spigot Plugin Development' started by MrGG4ming, Aug 14, 2018.

  1. Hello everyone, I've been trying for 3 hours to understand what's going on with the "setBrewingTime" function and I've already done several tests and it does not go anywhere. I am trying to create a system that I can create new potions, however I started to do and when I got to the stage of updating the brewing team it does not happen at all. I'm using 1.13 and I do not know if this might be influencing this, but so far it's my only suggestion for not working. The code is as follows:

    Code (Text):
    @EventHandler
        public void inventoryBrew(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            if (event.getClickedInventory().getType().equals(InventoryType.BREWING)) {
                BrewerInventory inventoryBrewer = (BrewerInventory) event.getClickedInventory();

                if (event.getClick() != ClickType.LEFT) {
                    return;
                }
                final ItemStack hand = event.getCursor().clone();
                if (hand == null || hand.getType() == Material.AIR) {
                    return;
                }
                Bukkit.getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void run() {
                        event.setCursor(new ItemStack(Material.AIR));
                        event.getClickedInventory().setItem(event.getSlot(), hand);
                    }
                }, 1L);
                player.updateInventory();

                int rotacao = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
                    int time = 400;
                    @Override
                    public void run() {
                        time--;
                        //PROBLEM HERE!
                        inventoryBrewer.getHolder().setBrewingTime(time);
                        System.out.println(inventoryBrewer.getHolder().getBrewingTime());

                        if (time == 0) {
                            System.out.println(inventoryBrewer.getIngredient().getType().name());
                        }
                    }
                }, 2L, 1L);

                Bukkit.getScheduler().runTaskLater(Main.plugin, new Runnable() {
                    @Override
                    public void run() {
                        Bukkit.getScheduler().cancelTask(rotacao);
                    }
                }, 401L);
            }
        }
    I know the way it would cause some bugs for lack of some "if", however in this case I'm just testing trying to make the brewing timer update itself.

    I have already tried to solve with inventoryBrewer.getHolder (). Update () ;, transforming the inv to block and updating the state among several other forms, but it does not get anywhere. During the test I used the brewer with some fuel and even without, but it does not change at all.

    If someone identifies the error, or know the reason helps me. Thank you all!