promotional bannermobile promotional banner

CountdownLib

Simple library for timer countdowns

A simple library for easily creating countdowns and cooldowns

A really simple(And I mean really simple :)) plugin that allows developers to create easy countdowns and cooldowns using Event's when the countdown ticks and ends. The source might help if you are using an IDE for intellisense and info.

Implementation

To create a countdown and get its UUID.

public void startCountdown(long time, long interval, boolean intervalToSeconds){
    Countdown c = new Countdown(time, interval, intervalToSeconds, plugin);
    someVariable = c.start(); //or if you want to set the UUID variable on another line use someVariable = c.getID();
}

The time is the amount of countdown ticks before the countdown ends and the interval is the time between the ticks.

To listen to when a countdown ticks.

@EventHandler
public void onCountdownTickEvent(CountdownTickEvent event){
    //do something
}

And to listen when a countdown ends(finishes counting down)

@EventHandler
public void onCountdownEndEvent(CountdownEndEvent event){
    //do something
}

Possible idea of implementation would be to store a hashmap.

HashMap<String, UUID> names = new HashMap<String, UUID>();

So then you can assign names to UUIDs just for your plugin :).

v3 now includes fully automatic command cooldowns! Example:

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	if(label.equalsIgnoreCase("foobar")){
		sender.sendMessage("foobar");
                //the 10 int is the number of seconds the cooldown lasts
		CommandCooldown ccd = new CommandCooldown(10, label, sender.getName());
		return true;
	}
}

This will mean that the command will work the first time for the user but then they have to wait until the cooldown has ended before they can use it again.

Things to note: This is only good if your cooldown is going to be a matter of seconds or minutes, or if the server is very unlikely to go down during a cooldown because it will reset when the server shuts down. If a player executes a command and a cooldown is still running for that player it will give them a default message(quite a sexy one), if you want to add your own messages there is an extra constructor argument on the overloaded constructor(sorry for lack of commenting on the constructors but look at the source and you will see what I mean) that allows you to change the message(please use %d where you wan't the number of seconds left or don't if you wan't a plain generic message).

TODO

Nothing ATM

ChangeLog

v2. Added UUID checking instead of naming the countdowns(to avoid confusion between plugins(If you are going to employ your own name system i strongly suggest you match name to UUID)).

v3. Added time modification.

v.3. Added CommandCooldown class for super sexy automatic command cooldowns ;).

v.3. Fixed null UUID on CountdownTickEvent's.

v.4. Added command to execute a command after a period of seconds /Countdown <Seconds> <Command> [Arguments...].

v4. Added static method in CommandCountdown class to execute a command after a period of seconds.

Commands

1. /Countdown <Seconds> <Command> [Arguments] count's down a number of seconds and then executes a command.

Permissions

1. cdl.countdown for the /Countdown command.

Github source

https://github.com/tommycake51/CountdownLib/

The CountdownLib Team

profile avatar
  • 8
    Projects
  • 20.7K
    Downloads

More from _ForgeUser9142288View all

  • iDispenser project image

    iDispenser

    • 6.6K
    • Bukkit Plugins

    A plugin that lets you dispense items infinitely but retains metadata such as in fireworks.

    • 6.6K
    • April 13, 2014
    • Bukkit Plugins
  • Mob Invincibility project image

    Mob Invincibility

    • 1.1K
    • Bukkit Plugins

    plugin based on http://forums.bukkit.org/threads/invincible-mobs.176237

    • 1.1K
    • September 24, 2013
    • Bukkit Plugins
  • AdminLog project image

    AdminLog

    • 3.8K
    • Bukkit Plugins

    AdminLog

    • 3.8K
    • September 10, 2013
    • Bukkit Plugins
  • InfoBooks project image

    InfoBooks

    • 2.1K
    • Bukkit Plugins

    A way to hand out as many books as you like of useful information!

    • 2.1K
    • August 16, 2013
    • Bukkit Plugins
  • iDispenser project image

    iDispenser

    • 6.6K
    • Bukkit Plugins

    A plugin that lets you dispense items infinitely but retains metadata such as in fireworks.

    • 6.6K
    • April 13, 2014
    • Bukkit Plugins
  • Mob Invincibility project image

    Mob Invincibility

    • 1.1K
    • Bukkit Plugins

    plugin based on http://forums.bukkit.org/threads/invincible-mobs.176237

    • 1.1K
    • September 24, 2013
    • Bukkit Plugins
  • AdminLog project image

    AdminLog

    • 3.8K
    • Bukkit Plugins

    AdminLog

    • 3.8K
    • September 10, 2013
    • Bukkit Plugins
  • InfoBooks project image

    InfoBooks

    • 2.1K
    • Bukkit Plugins

    A way to hand out as many books as you like of useful information!

    • 2.1K
    • August 16, 2013
    • Bukkit Plugins