CountdownLib

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/


Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    65013
  • Created
    Sep 3, 2013
  • Last Released File
    Oct 15, 2013
  • Total Downloads
    2,455
  • License

Categories

Members