mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-24 03:05:52 +01:00
Add warmups for /f home and /f warp
This commit is contained in:
parent
b923e1efd7
commit
355e1f58b0
@ -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);
|
||||
}
|
||||
|
@ -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<Location> smokeLocations = new ArrayList<Location>();
|
||||
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<Location> smokeLocations = new ArrayList<Location>();
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<P> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
27
src/main/java/com/massivecraft/factions/util/WarmUpUtil.java
Normal file
27
src/main/java/com/massivecraft/factions/util/WarmUpUtil.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -141,3 +141,11 @@ scoreboard:
|
||||
- "{power}"
|
||||
- "&aBalance"
|
||||
- "${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
|
||||
|
Loading…
Reference in New Issue
Block a user