Class AbstractAnimation
java.lang.Object
xyz.xenondevs.invui.animation.impl.AbstractAnimation
- All Implemented Interfaces:
Animation
- Direct Known Subclasses:
AbstractSoundAnimation
Abstract base class for
Animation
implementations.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFinishHandler
(@NotNull Runnable finish) void
addShowHandler
(@NotNull BiConsumer<Integer, Integer> show) Adds a show handler.void
cancel()
Cancels theAnimation
.protected int
convToIndex
(int x, int y) Converts the given x and y coordinates to a slot index.protected void
finish()
Stops theAnimation
and runs finish handlers.Set
<org.bukkit.entity.Player> Finds all current viewers of thisAnimation
.protected int
getSlots()
The slots that are being animated.protected int
getWidth()
protected abstract void
handleFrame
(int frame) Handles the next frame of theAnimation
.void
void
Sets the slots that should be shown.void
setWindows
(@NotNull List<Window> windows) Sets theWindow
s that will see this animation.protected void
show
(int... slots) Shows the given slots.void
start()
Starts theAnimation
.
-
Constructor Details
-
AbstractAnimation
public AbstractAnimation(int tickDelay) Creates a newAbstractAnimation
.- Parameters:
tickDelay
- The delay between each frame
-
-
Method Details
-
setGui
Description copied from interface:Animation
-
setWindows
Description copied from interface:Animation
Sets theWindow
s that will see this animation. Useful for playing sounds in a showHandler. (Animation.addShowHandler(BiConsumer)
)- Specified by:
setWindows
in interfaceAnimation
- Parameters:
windows
- TheWindow
s that will see this animation
-
addShowHandler
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 interfaceAnimation
- Parameters:
show
- The show handler as aBiConsumer
consisting of frame number (first int) and slot index to show (second int).
-
addFinishHandler
Description copied from interface:Animation
- Specified by:
addFinishHandler
in interfaceAnimation
- Parameters:
finish
- TheRunnable
that should run after theAnimation
is finished.
-
start
public void start()Description copied from interface:Animation
Starts theAnimation
. -
cancel
public void cancel()Description copied from interface:Animation
Cancels theAnimation
. -
finish
protected void finish()Stops theAnimation
and runs finish handlers. -
handleFrame
protected abstract void handleFrame(int frame) Handles the next frame of theAnimation
.- Parameters:
frame
- The current frame
-
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
Description copied from interface:Animation
Sets 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 coordinatey
- The y coordinate- Returns:
- The slot index
-
getWidth
protected int getWidth()- Returns:
- The width of the
Gui
-
getHeight
protected int getHeight()- Returns:
- The height of the
Gui
-
getCurrentViewers
Finds all current viewers of thisAnimation
.- Returns:
- The current viewers
-