Changing items in a GUI constantly on a Runnable

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

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

    kraazeekid

    Code:
    private void openGUI(Player p) {
            inv = Bukkit.createInventory(null, 9, ChatColor.AQUA
                    + "Teleport");
            new BukkitRunnable(){
                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(0, is);
                        inv.setItem(1, is2);
                    num++;
                    }
                    else
                            if(num == 2){
                                ItemStack is = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)15);
                                ItemStack is2 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
                                inv.setItem(0,is2);
                                inv.setItem(1,is);
                            num = 0;  
                    }
                }
            }.runTaskTimer(Hub.getInstance(), 0, 20);
    I want the glass to flicker between spots. I just did the first 2 slots for testing purposes. Don't know the error, seeking help :p. Thanks for taking the time to read :D
     
    Last edited: Aug 26, 2015
  2. Offline

    OhhPickles

    What exactly is the problem?
     
  3. Offline

    kraazeekid

    The glass appears on the first click after a reload, but doesn't flicker, then doesn't appear at all.
     
  4. Offline

    BrickBoy55

    @kraazeekid On the second one, you're setting num to 0, but you check if num is 1 or 2.
     
  5. Offline

    Zombie_Striker

    @kraazeekid
    That is because unless you're saving the instance in a file, the instance is not saved, and thus after the reload it won't work. You can't get around it.
     
  6. Offline

    au2001

    @kraazeekid You should use booleans for this:
    Code:
    boolean name = false;
    name = !name;
    if (name) {
        // Set to spot 1
    } else {
        // Set to spot 2
    }
     
  7. Offline

    kraazeekid

    I used a boolean and it didn't work.
     
Thread Status:
Not open for further replies.

Share This Page