Class BukkitCooldown

  • All Implemented Interfaces:
    Cooldown, org.kikikan.deadbymoonlight.util.Toggleable

    public class BukkitCooldown
    extends java.lang.Object
    implements Cooldown
    Represents a Cooldown / Timer that uses Bukkit's scheduler.
    • Constructor Summary

      Constructors 
      Constructor Description
      BukkitCooldown​(org.bukkit.plugin.java.JavaPlugin plugin, long... values)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.UUID addRunnable​(java.lang.Runnable runnable, org.kikikan.deadbymoonlight.util.TimerEventType type)
      Registers a Runnable to run at the specified event.
      org.bukkit.plugin.java.JavaPlugin getPlugin()
      Gets the JavaPlugin object which was given to it through the constructor.
      protected void init​(long... values)
      Initializes the cooldown with the specified values.
      boolean isRunning()
      Checks if the Cooldown is running or not.
      void off()
      Turns off the cooldown.
      void on()
      Turns on the cooldown with the initialized values.
      void on​(long... values)
      Turns on the cooldown with the specified values.
      void removeRunnable​(java.util.UUID uuid)
      Removes the specified runnable using its UUID that was generated when it was added.
      protected void tick()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BukkitCooldown

        public BukkitCooldown​(org.bukkit.plugin.java.JavaPlugin plugin,
                              long... values)
    • Method Detail

      • on

        public void on()
        Turns on the cooldown with the initialized values.
        Specified by:
        on in interface org.kikikan.deadbymoonlight.util.Toggleable
        Throws:
        java.lang.IllegalStateException - if the cooldown wasn't initialized.
      • on

        public void on​(long... values)
        Turns on the cooldown with the specified values. This does not initialize the cooldown. However, you can use this without it being initialized.
        Specified by:
        on in interface Cooldown
        Parameters:
        values - The values it should use. Same as init()
        Throws:
        java.lang.IllegalStateException - If the cooldown is off after executing this method, or another registered runnable tries to turn on the cooldown. (would result to StackOverFlowError)
      • off

        public void off()
        Turns off the cooldown.
        Specified by:
        off in interface org.kikikan.deadbymoonlight.util.Toggleable
        Throws:
        java.lang.IllegalStateException - If the cooldown is on after executing this method, or another registered runnable tries to turn off the cooldown. (would result to StackOverFlowError)
      • isRunning

        public final boolean isRunning()
        Checks if the Cooldown is running or not.
        Specified by:
        isRunning in interface Cooldown
        Returns:
        True if the Cooldown is activated.
      • init

        protected void init​(long... values)
        Initializes the cooldown with the specified values.
        Parameters:
        values - The values used for creating the BukkitTask.
        First value: delay before calling the run() method.
        Second value (if exists): how frequently run() should be called.
      • getPlugin

        public final org.bukkit.plugin.java.JavaPlugin getPlugin()
        Gets the JavaPlugin object which was given to it through the constructor.
        Returns:
        The JavaPlugin instance.
      • tick

        protected void tick()
      • addRunnable

        public java.util.UUID addRunnable​(java.lang.Runnable runnable,
                                          org.kikikan.deadbymoonlight.util.TimerEventType type)
        Registers a Runnable to run at the specified event.
        Specified by:
        addRunnable in interface Cooldown
        Parameters:
        runnable - Method to run
        type - When to run
        Returns:
        The generated UUID that you will have to use for identifying the Runnable.
      • removeRunnable

        public void removeRunnable​(java.util.UUID uuid)
        Removes the specified runnable using its UUID that was generated when it was added.
        Specified by:
        removeRunnable in interface Cooldown
        Parameters:
        uuid - The UUID which was generated when the Runnable was added.