[Util] Cycling Items

Discussion in 'Resources' started by calebbfmv, Feb 8, 2014.

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

    calebbfmv

    I was bored one day and made something that allows, well, the cycling of an item in an inventory, and the slot.
    Code:
    /**
     * 
     * @author ralitski & calebbfmv
     * Nifty little thing for cycling through inventory crap.
     * is very fancy
     * [fanciness level: very]
     */
    public class CycleItems extends BukkitRunnable{
    
        private int index;
        private ItemStack[] items;
        private int slot;
        private Inventory inv;
        private Plugin plugin;
    
        private void next(){
            index ++;
            index %= this.items.length;
        }
    
        public ItemStack get(){
            return items[this.index];
        }
    
        public ItemStack prev() {
            return this.items[(this.items.length + this.index - 1) % this.items.length];
        }
    
        /**
         *  @pararm plugin Your plugin
         * @param inv The inventory
         * @param slot the Placement in the inv
         * @param delay Time between displays
         * @param item The items to be cycled.
         */
        public CycleItems(Plugin plugin, Inventory inv, int slot, long delay, ItemStack... item){
            this.plugin = plugin;
            this.inv = inv;
            this.slot = slot;
            this.index = 0;
            this.items = item;
            inv.setItem(this.slot, this.get());
            this.runTaskTimer(this.plugin, delay, delay);
        }
    
        @Override
        public void run() {
            next();
            ItemStack item = this.inv.getItem(this.slot);
            if(item == null || this.prev().equals(item)) {
                this.inv.setItem(this.slot, this.get());
            }
        }
    }
    
    Simply to use:
    Code:
    new CycleItems(this, player.getInventory(), 31, 10, new ItemStack(Material.APPLE), new ItemStack(Material.BONE));
    
    Enjoy, or not, just for fun.
     
  2. Offline

    SoThatsIt

    calebbfmv
    neat, could come in handy if someone wants to do one of those things where they make an animation in an items lore using ASCII characters
     
  3. Offline

    Goblom

    Thank you sir for giving me an ingenious idea (creating something like the idea behind this resource)
     
  4. Offline

    calebbfmv

    Goblom
    If you mean something like a loading bar, I have done that, but that is secret code :)
     
  5. Offline

    Goblom

  6. Offline

    calebbfmv

  7. Offline

    Goblom

  8. Offline

    calebbfmv

    Goblom
    No but I was thinking, combining this, with the ImgSender UTIL, you could create full blown movies!
     
  9. calebbfmv
    ImageMessage already supports GIFs, that's like a tiny movie already :p
     
  10. Offline

    Scizzr

    Yup! telnet towel.blinkenlights.nl

    Sad that I have this remembered from like 2004 when I first saw it. :)
     
  11. Offline

    calebbfmv

Thread Status:
Not open for further replies.

Share This Page