Cancel warmup on damage or movement

This commit is contained in:
Paul Sauve 2015-05-24 23:42:31 -05:00 committed by drtshock
parent fc1d08e507
commit 1481d604d4
10 changed files with 95 additions and 14 deletions

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.WarmUpUtil;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -228,4 +229,19 @@ public interface FPlayer extends EconomyParticipator {
public boolean isOffline();
public void setId(String id);
// -------------------------------
// Warmups
// -------------------------------
public boolean isWarmingUp();
public WarmUpUtil.Warmup getWarmupType();
public void addWarmup(WarmUpUtil.Warmup warmup, int taskId);
public void stopWarmup();
public void clearWarmup();
}

View File

@ -50,7 +50,7 @@ public class CmdFWarp extends FCommand {
if (!transact(fme)) {
return;
}
this.doWarmUp(TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() {
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() {
@Override
public void run() {
CmdFWarp.this.fme.getPlayer().teleport(CmdFWarp.this.myFaction.getWarp(warpName).getLocation());

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.integration.Essentials;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.SmokeUtil;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
@ -110,7 +111,7 @@ public class CmdHome extends FCommand {
return;
}
this.doWarmUp(TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
@Override
public void run() {
// Create a smoke effect

View File

@ -302,11 +302,11 @@ public abstract class FCommand extends MCommand<P> {
}
}
public void doWarmUp(TL translationKey, String action, Runnable runnable, long delay) {
this.doWarmUp(this.fme, translationKey, action, runnable, delay);
public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
this.doWarmUp(this.fme, warmup, translationKey, action, runnable, delay);
}
public void doWarmUp(FPlayer player, TL translationKey, String action, Runnable runnable, long delay) {
WarmUpUtil.process(player, translationKey, action, runnable, delay);
public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
}
}

View File

@ -114,7 +114,13 @@ public class FactionsEntityListener implements Listener {
// entity took generic damage?
Entity entity = event.getEntity();
if (entity instanceof Player) {
cancelFStuckTeleport((Player) event.getEntity());
Player player = (Player) entity;
FPlayer me = FPlayers.getInstance().getByPlayer(player);
cancelFStuckTeleport(player);
if (me.isWarmingUp()) {
me.clearWarmup();
me.msg(TL.WARMUPS_CANCELLED);
}
}
}

View File

@ -122,9 +122,16 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
FPlayer me = FPlayers.getInstance().getByPlayer(player);
// clear visualization
if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
VisualizeUtil.clear(event.getPlayer());
if (me.isWarmingUp()) {
me.clearWarmup();
me.msg(TL.WARMUPS_CANCELLED);
}
}
// quick check to make sure player is moving between chunks; good performance boost
@ -132,9 +139,6 @@ public class FactionsPlayerListener implements Listener {
return;
}
Player player = event.getPlayer();
FPlayer me = FPlayers.getInstance().getByPlayer(player);
// Did we change coord?
FLocation from = me.getLastStoodAt();
FLocation to = new FLocation(event.getTo());

View File

@ -15,12 +15,28 @@ public class WarmUpUtil {
* <p/>
* note: for translations: %s = action, %d = delay
*/
public static void process(FPlayer player, TL translationKey, String action, Runnable runnable, long delay) {
public static void process(final FPlayer player, Warmup warmup, TL translationKey, String action, final Runnable runnable, long delay) {
if (delay > 0) {
player.msg(translationKey.format(action, delay));
P.p.getServer().getScheduler().runTaskLater(P.p, runnable, delay * 20);
if (player.isWarmingUp()) {
player.msg(TL.WARMUPS_ALREADY);
} else {
player.msg(translationKey.format(action, delay));
int id = P.p.getServer().getScheduler().runTaskLater(P.p, new Runnable() {
@Override
public void run() {
player.stopWarmup();
runnable.run();
}
}, delay * 20).getTaskId();
player.addWarmup(warmup, id);
}
} else {
runnable.run();
}
}
public enum Warmup {
HOME, WARP;
}
}

View File

@ -15,6 +15,7 @@ import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -95,6 +96,9 @@ public abstract class MemoryFPlayer implements FPlayer {
protected boolean spyingChat = false;
protected boolean showScoreboard;
protected WarmUpUtil.Warmup warmup;
protected int warmupTask;
public Faction getFaction() {
if (this.factionId == null) {
this.factionId = "0";
@ -883,4 +887,34 @@ public abstract class MemoryFPlayer implements FPlayer {
public void setId(String id) {
this.id = id;
}
@Override
public void clearWarmup() {
if (warmup != null) {
Bukkit.getScheduler().cancelTask(warmupTask);
this.stopWarmup();
}
}
@Override
public void stopWarmup() {
warmup = null;
}
@Override
public boolean isWarmingUp() {
return warmup != null;
}
@Override
public WarmUpUtil.Warmup getWarmupType() {
return warmup;
}
@Override
public void addWarmup(WarmUpUtil.Warmup warmup, int taskId) {
if (this.warmup != null) {
this.clearWarmup();
}
}
}

View File

@ -708,7 +708,9 @@ public enum TL {
/**
* Warmups
*/
WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds.");
WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds."),
WARMUPS_ALREADY("&cYou are already warming up."),
WARMUPS_CANCELLED("&cYou have cancelled your warmup.");
private String path;
private String def;

View File

@ -501,3 +501,5 @@ faction-logout: '&e%1$s &9logged out..'
WARMUPS:
NOTIFY:
TELEPORT: '&eYou will teleport to &d%1$s &ein &d%2$d &eseconds.'
ALREADY: '&cYou are already warming up.'
CANCELLED: '&cYou have cancelled your warmup.'