Class AbstractAnimation

java.lang.Object
xyz.xenondevs.invui.animation.impl.AbstractAnimation
All Implemented Interfaces:
Animation
Direct Known Subclasses:
AbstractSoundAnimation

public abstract class AbstractAnimation extends Object implements Animation
Abstract base class for Animation implementations.
  • Constructor Details

    • AbstractAnimation

      public AbstractAnimation(int tickDelay)
      Creates a new AbstractAnimation.
      Parameters:
      tickDelay - The delay between each frame
  • Method Details

    • setGui

      public void setGui(Gui gui)
      Description copied from interface: Animation
      Sets the Gui this Animation will take place in.
      Specified by:
      setGui in interface Animation
      Parameters:
      gui - The Gui this Animation will take place in
    • setWindows

      public void setWindows(@NotNull @NotNull List<Window> windows)
      Description copied from interface: Animation
      Sets the Windows that will see this animation. Useful for playing sounds in a showHandler. (Animation.addShowHandler(BiConsumer))
      Specified by:
      setWindows in interface Animation
      Parameters:
      windows - The Windows that will see this animation
    • addShowHandler

      public void addShowHandler(@NotNull @NotNull BiConsumer<Integer,Integer> show)
      Description copied from interface: Animation
      Adds a show handler. Can be used to for example play a sound when a slot pops up.
      Specified by:
      addShowHandler in interface Animation
      Parameters:
      show - The show handler as a BiConsumer consisting of frame number (first int) and slot index to show (second int).
    • addFinishHandler

      public void addFinishHandler(@NotNull @NotNull Runnable finish)
      Description copied from interface: Animation
      Adds a Runnable that should run after the Animation is finished.
      Specified by:
      addFinishHandler in interface Animation
      Parameters:
      finish - The Runnable that should run after the Animation is finished.
    • start

      public void start()
      Description copied from interface: Animation
      Starts the Animation.
      Specified by:
      start in interface Animation
    • cancel

      public void cancel()
      Description copied from interface: Animation
      Cancels the Animation.
      Specified by:
      cancel in interface Animation
    • finish

      protected void finish()
      Stops the Animation and runs finish handlers.
    • handleFrame

      protected abstract void handleFrame(int frame)
      Handles the next frame of the Animation.
      Parameters:
      frame - The current frame
    • getSlots

      public CopyOnWriteArrayList<Integer> getSlots()
      The slots that are being animated. Animation implementations may or may not remove slots that have been shown from the list.
      Returns:
      The slots that are being animated
    • setSlots

      public void setSlots(List<Integer> slots)
      Description copied from interface: Animation
      Sets the slots that should be shown.
      Specified by:
      setSlots in interface Animation
      Parameters:
      slots - The slots that should be shown.
    • show

      protected void show(int... slots)
      Shows the given slots.
      Parameters:
      slots - The slots to show
    • convToIndex

      protected int convToIndex(int x, int y)
      Converts the given x and y coordinates to a slot index.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      Returns:
      The slot index
    • getWidth

      protected int getWidth()
      Gets the width of the Gui this Animation is taking place in.
      Returns:
      The width of the Gui
    • getHeight

      protected int getHeight()
      Gets the height of the Gui this Animation is taking place in.
      Returns:
      The height of the Gui
    • getCurrentViewers

      public Set<org.bukkit.entity.Player> getCurrentViewers()
      Finds all current viewers of this Animation.
      Returns:
      The current viewers