public abstract class MessageDecorator<T extends net.dv8tion.jda.core.events.Event>
extends java.lang.Object
Message
by interacting in specific manners with it.
Some of the methods of this class aren't required by every type of decorator so they will throw exceptions.Modifier and Type | Field and Description |
---|---|
protected net.dv8tion.jda.core.entities.Message |
binding |
protected long |
creationTime |
protected boolean |
isAlive |
protected com.jesus_crie.modularbot.core.utils.Waiter.WaiterListener<T> |
listener |
protected java.util.List<DecoratorListener> |
listeners |
protected long |
timeout |
Modifier | Constructor and Description |
---|---|
protected |
MessageDecorator(net.dv8tion.jda.core.entities.Message binding,
long timeout)
Build the base of a decorator.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkTimeout(long timeout)
Used to check if the given timeout is valid or not.
|
protected com.jesus_crie.modularbot.core.utils.Waiter.WaiterListener<T> |
createListener(java.lang.Object... args)
Used to create the listener.
|
abstract void |
destroy()
Destroy the decorator.
|
boolean |
equals(java.lang.Object obj)
Check if 2 decorators are the same.
|
net.dv8tion.jda.core.entities.Message |
getBinding()
Get the bound message.
|
long |
getExpireTime()
Get the timestamp in milliseconds where the decorator will have expired or 0 for infinite or -1 if the decorator is
dead.
|
boolean |
isAlive()
Check if the decorator is still alive.
|
protected void |
onTimeout()
Triggered when the decorator times out.
|
void |
register(MessageDecoratorModule module)
Register this decorator.
|
void |
register(com.jesus_crie.modularbot.core.ModularBot bot)
Register this decorator.
|
void |
setup()
Used to setup the decorator, this must be triggered out of the constructor.
|
java.lang.String |
toString() |
protected void |
updateMessage()
Update the reference to the bound message by querying it again from JDA.
|
protected net.dv8tion.jda.core.entities.Message binding
protected final long creationTime
protected final long timeout
protected transient com.jesus_crie.modularbot.core.utils.Waiter.WaiterListener<T extends net.dv8tion.jda.core.events.Event> listener
protected transient java.util.List<DecoratorListener> listeners
protected boolean isAlive
protected MessageDecorator(@Nonnull net.dv8tion.jda.core.entities.Message binding, long timeout)
checkTimeout(long)
) the decorator will call destroy()
and throw an exception right after.binding
- The message to bind to this decorator.timeout
- The amount of time before the decorator expire.java.lang.IllegalArgumentException
- If the given timeout is invalid.@Nonnull protected com.jesus_crie.modularbot.core.utils.Waiter.WaiterListener<T> createListener(@Nonnull java.lang.Object... args)
public void setup()
public void register(@Nonnull com.jesus_crie.modularbot.core.ModularBot bot)
bot
- The current instance of ModularBot
.register(MessageDecoratorModule)
public void register(@Nonnull MessageDecoratorModule module)
module
- The current MessageDecoratorModule
.register(ModularBot)
protected void onTimeout()
On the other hand, an implementation like ReactionDecorator
will call destroy()
on timeout which is an expected behaviour.
public abstract void destroy()
The effect of this method might depend of the implementation.
Depending of the implementation this method can also be called as a result of onTimeout()
.
protected boolean checkTimeout(long timeout)
timeout
- The timeout to check.public long getExpireTime()
public net.dv8tion.jda.core.entities.Message getBinding()
protected void updateMessage()
public boolean isAlive()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The other potentially equal decorator.public java.lang.String toString()
toString
in class java.lang.Object