Changing blocks in a GUI constantly

Discussion in 'Plugin Development' started by kraazeekid, Aug 20, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    kraazeekid

    Code:
    @SuppressWarnings("deprecation")
        private void openGUI(Player p) {
            inv = Bukkit.createInventory(null, 9, ChatColor.AQUA
                    + "Hub");
           
            getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
                public void run(){
                    if(num == 1){
                        ItemStack is = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)15);
                        ItemStack is2 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
                        inv.setItem(8, is);
                        inv.setItem(5, is);
                        inv.setItem(1, is);
                        inv.setItem(0, is2);
                        inv.setItem(3, is2);
                        inv.setItem(7, is2);
                        num++;
                    if(num == 2){
                        inv.setItem(0, is);
                        inv.setItem(3, is);
                        inv.setItem(7, is);
                        inv.setItem(8, is2);
                        inv.setItem(5, is2);
                        inv.setItem(1, is2);
                    num = 0;
                        }
                    }
                }
                }   
                , 0, 2);
    The inventory shows the blocks but doesn't make them keep changing, and they disappear if you click the GUI then leave it and click again. Can anyone help? I'm not the best bukkit coder, but I enjoy coding, and I can't figure this error out!

    Thanks!
     
  2. @kraazeekid
    Misplaced brackets, which makes the if(num == 2) check only happen when if(num == 1) returns true, and the num++ is only called when num == 1
     
  3. Offline

    kraazeekid

    Do I just add an else statement to fix it? Or do I need to move the brackets?
     
  4. Offline

    kraazeekid

    I'm really not good at coding. I moved a bracket underneath num++; and it's wrong. Can you assist me further? Sorry to bother you ;p
     
  5. Offline

    nj2miami

    Your problem is not brackets, it is your knowledge of Java unfortunately. :/

    Additionally, why would you be creating an INFINITE repeating task EVERY 2 TICKS which simply keeps creating new ItemStacks???
     
  6. Offline

    RainoBoy97

    Use a boolean and not an integer.
     
Thread Status:
Not open for further replies.

Share This Page