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.
So, I had an idea, I could add an overloaded constructor with another parameter called longTime and if this is true then it would resume on startup(Command cooldowns will automatically decide I guess). Might take a while to implement depending on the storage method I choose etc, anyway expect an update for 1.7.4 sometime soon-ish I need to set myself a reminder
Kudos to you! Exactly what I have been looking for :)
Just wanted to say thanks again for the command update. I just now got a moment to install and test it, works exactly as I'd hoped.
/countdown 420 /give tommycake50 nerdy-white-guy-high-five
Im having trouble with everything involving this plugin i will pay 5 dollars if you help me set it up! OR JUST make a video tutorial on this plugin please author respond willing to pay 5 - 7 bucks through paypal
I'm not necessarily sure it needs to be fixed..
I think it's probably better to leave it how it is.. for example if someone pays $1000 in-game money for 30 minutes of VIP access and the server goes offline for 20 minutes, that person should still gets their full allotment of time when the server comes back up.
@1337ingDisorder
You are correct. However I did notice my mistake there recently, I'm going to fix it in the next release for sure, that is at the top of my agenda right now.
Question: how does CountdownLib handle the following:
* Daemon is reloaded or stopped
* Server OS is rebooted or powered off
* Server crashes unexpectedly
In those events will the countdown be resumed once the server is back online?
Also, from what I can glean from the documentation above it seems like the countdown is counted by in-game ticks, is this correct? ie, if I have a timer set for 10 minutes and the server is brought offline for 5 minutes for maintenance, when the server comes back online will there be 5 minutes less on the timer, or will it resume from where it left off?
Thanks
@tommycake50:
You, sir, are a gentleman!
Many thanks, and if I ever notice a donations link on this page I'll remember how swiftly you jumped on that suggestion :)
@1337ingDisorder
Sure I will get right to it. You don't need to offer me any reward, I will get this in in the next release.
@tommycake50:
Awesome, thanks for making this.. Is there any way you could be pursuaded to whip up a super-simple front-end for this as a standalone plugin?
I'd like to be able to do something like:
/countdown 300 /command argument argument
...and have it simply run that command when the countdown reaches zero. No notifications every 10 seconds, or even at all.. just want it to silently obey my request and execute the command after the requested delay.
I could maybe even tempt you with a bounty of BTC or LTC..
Awesome!
Thanks :D