Saber-Factions/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java

43 lines
1.6 KiB
Java
Raw Normal View History

2015-01-20 00:59:15 +01:00
package com.massivecraft.factions.util;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.SavageFactions;
2015-01-20 00:59:15 +01:00
import com.massivecraft.factions.zcore.util.TL;
public class WarmUpUtil {
/**
2015-05-13 06:17:22 +02:00
* @param player The player to notify.
2015-01-20 00:59:15 +01:00
* @param translationKey The translation key used for notifying.
2015-05-13 06:17:22 +02:00
* @param action The action, inserted into the notification message.
* @param runnable The task to run after the delay. If the delay is 0, the task is instantly ran.
* @param delay The time used, in seconds, for the delay.
* <p>
2015-05-13 06:17:22 +02:00
* note: for translations: %s = action, %d = delay
2015-01-20 00:59:15 +01:00
*/
2015-05-25 06:42:31 +02:00
public static void process(final FPlayer player, Warmup warmup, TL translationKey, String action, final Runnable runnable, long delay) {
2015-01-20 00:59:15 +01:00
if (delay > 0) {
2015-05-25 06:42:31 +02:00
if (player.isWarmingUp()) {
player.msg(TL.WARMUPS_ALREADY);
} else {
player.msg(translationKey.format(action, delay));
2018-11-07 06:38:43 +01:00
int id = SavageFactions.plugin.getServer().getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() {
2015-05-25 06:42:31 +02:00
@Override
public void run() {
player.stopWarmup();
runnable.run();
}
}, delay * 20).getTaskId();
player.addWarmup(warmup, id);
}
2015-01-20 00:59:15 +01:00
} else {
runnable.run();
}
}
2015-05-25 06:42:31 +02:00
public enum Warmup {
2018-11-07 06:38:43 +01:00
HOME, WARP, FLIGHT, BANNER, CHECKPOINT
2015-05-25 06:42:31 +02:00
}
2015-01-20 00:59:15 +01:00
}