2015-01-20 00:59:15 +01:00
|
|
|
package com.massivecraft.factions.util;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
2015-01-20 00:59:15 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
|
|
|
|
public class WarmUpUtil {
|
|
|
|
|
2019-08-24 19:18:50 +02:00
|
|
|
/**
|
|
|
|
* @param player The player to notify.
|
|
|
|
* @param translationKey The translation key used for notifying.
|
|
|
|
* @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>
|
|
|
|
* note: for translations: %s = action, %d = delay
|
|
|
|
*/
|
|
|
|
public static void process(final FPlayer player, Warmup warmup, TL translationKey, String action, final Runnable runnable, long delay) {
|
|
|
|
if (delay > 0) {
|
|
|
|
if (player.isWarmingUp()) {
|
|
|
|
player.msg(TL.WARMUPS_ALREADY);
|
|
|
|
} else {
|
|
|
|
player.msg(translationKey.format(action, delay));
|
2019-09-14 21:13:01 +02:00
|
|
|
int id = FactionsPlugin.getInstance().getServer().getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> {
|
2019-08-24 19:18:50 +02:00
|
|
|
player.stopWarmup();
|
|
|
|
runnable.run();
|
|
|
|
}, delay * 20).getTaskId();
|
|
|
|
player.addWarmup(warmup, id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
runnable.run();
|
|
|
|
}
|
|
|
|
}
|
2015-05-25 06:42:31 +02:00
|
|
|
|
2019-08-24 19:18:50 +02:00
|
|
|
public enum Warmup {
|
|
|
|
HOME, WARP, FLIGHT, BANNER, CHECKPOINT
|
|
|
|
}
|
2015-05-25 06:42:31 +02:00
|
|
|
|
2015-01-20 00:59:15 +01:00
|
|
|
}
|