From 355e1f58b0958270cd4bc48fe1f8c1ea1387abfb Mon Sep 17 00:00:00 2001 From: Joshua Popoff Date: Mon, 19 Jan 2015 15:59:15 -0800 Subject: [PATCH] Add warmups for /f home and /f warp --- .../massivecraft/factions/cmd/CmdFWarp.java | 11 +++++--- .../massivecraft/factions/cmd/CmdHome.java | 27 +++++++++++-------- .../massivecraft/factions/cmd/FCommand.java | 9 +++++++ .../factions/util/WarmUpUtil.java | 27 +++++++++++++++++++ .../massivecraft/factions/zcore/util/TL.java | 6 ++++- src/main/resources/config.yml | 10 ++++++- 6 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/util/WarmUpUtil.java diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java index b20996c3..8e2ddba5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java @@ -37,13 +37,18 @@ public class CmdFWarp extends FCommand { } else if (args.size() > 1) { fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT); } else { - String warpName = argAsString(0); + final String warpName = argAsString(0); if (myFaction.isWarp(argAsString(0))) { if (!transact(fme)) { return; } - fme.getPlayer().teleport(myFaction.getWarp(warpName).getLocation()); - fme.msg(TL.COMMAND_FWARP_WARPED, warpName); + this.doWarmUp(TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() { + @Override + public void run() { + CmdFWarp.this.fme.getPlayer().teleport(CmdFWarp.this.myFaction.getWarp(warpName).getLocation()); + CmdFWarp.this.fme.msg(TL.COMMAND_FWARP_WARPED, warpName); + } + }, this.p.getConfig().getLong("warmups.f-warp", 0)); } else { fme.msg(TL.COMMAND_FWARP_INVALID, warpName); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index ed962a66..22351b1a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -63,7 +63,7 @@ public class CmdHome extends FCommand { } Faction faction = Board.getInstance().getFactionAt(new FLocation(me.getLocation())); - Location loc = me.getLocation().clone(); + final Location loc = me.getLocation().clone(); // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby if (Conf.homesTeleportAllowedEnemyDistance > 0 && @@ -110,17 +110,22 @@ public class CmdHome extends FCommand { return; } - // Create a smoke effect - if (Conf.homesTeleportCommandSmokeEffectEnabled) { - List smokeLocations = new ArrayList(); - smokeLocations.add(loc); - smokeLocations.add(loc.add(0, 1, 0)); - smokeLocations.add(myFaction.getHome()); - smokeLocations.add(myFaction.getHome().clone().add(0, 1, 0)); - SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness); - } + this.doWarmUp(TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() { + @Override + public void run() { + // Create a smoke effect + if (Conf.homesTeleportCommandSmokeEffectEnabled) { + List smokeLocations = new ArrayList(); + smokeLocations.add(loc); + smokeLocations.add(loc.add(0, 1, 0)); + smokeLocations.add(CmdHome.this.myFaction.getHome()); + smokeLocations.add(CmdHome.this.myFaction.getHome().clone().add(0, 1, 0)); + SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness); + } - me.teleport(myFaction.getHome()); + CmdHome.this.me.teleport(CmdHome.this.myFaction.getHome()); + } + }, this.p.getConfig().getLong("warmups.f-home", 0)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/FCommand.java b/src/main/java/com/massivecraft/factions/cmd/FCommand.java index cd878c31..aff173b3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCommand.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.*; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.MCommand; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.command.CommandSender; @@ -286,4 +287,12 @@ public abstract class FCommand extends MCommand

{ return Econ.hasAtLeast(fme, cost, toDoThis); } } + + public void doWarmUp(TL translationKey, String action, Runnable runnable, long delay) { + this.doWarmUp(this.fme, translationKey, action, runnable, delay); + } + + public void doWarmUp(FPlayer player, TL translationKey, String action, Runnable runnable, long delay) { + WarmUpUtil.process(player, translationKey, action, runnable, delay); + } } diff --git a/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java b/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java new file mode 100644 index 00000000..0d8d6702 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/WarmUpUtil.java @@ -0,0 +1,27 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.P; +import com.massivecraft.factions.zcore.util.TL; + +public class WarmUpUtil { + + /** + * + * @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. + * + * note: for translations: %s = action, %d = delay + */ + public static void process(FPlayer player, TL translationKey, String action, Runnable runnable, long delay) { + if (delay > 0) { + player.msg(translationKey.format(action, delay)); + P.p.getServer().getScheduler().runTaskLater(P.p, runnable, delay * 20); + } else { + runnable.run(); + } + } +} diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 5b3dcd5a..5cc511f7 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -458,6 +458,10 @@ public enum TL { DEFAULT_PREFIX("default-prefix", "{relationcolor}[{faction}] &r"), FACTION_LOGIN("faction-login", "&e%s &9logged in."), FACTION_LOGOUT("faction-logout", "&e%s &9logged out.."), + /** + * Warmups + */ + WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%s &ein &d%d &eseconds."), ; private String path; @@ -523,4 +527,4 @@ public enum TL { public String getPath() { return this.path; } -} \ No newline at end of file +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9eee8828..7ca5b584 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -140,4 +140,12 @@ scoreboard: - "&3Your Power" - "{power}" - "&aBalance" - - "${balance}" \ No newline at end of file + - "${balance}" + +# Configration section for warmups. +# Warmup times are in seconds - if a value of 0 is set, there is no warmup. +warmups: + # Delay for /f home + f-home: 0 + # Delay for /f warp + f-warp: 0