Cancel warmup on damage or movement
This commit is contained in:
parent
fc1d08e507
commit
1481d604d4
@ -5,6 +5,7 @@ import com.massivecraft.factions.iface.RelationParticipator;
|
|||||||
import com.massivecraft.factions.struct.ChatMode;
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
|
import com.massivecraft.factions.util.WarmUpUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -228,4 +229,19 @@ public interface FPlayer extends EconomyParticipator {
|
|||||||
public boolean isOffline();
|
public boolean isOffline();
|
||||||
|
|
||||||
public void setId(String id);
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class CmdFWarp extends FCommand {
|
|||||||
if (!transact(fme)) {
|
if (!transact(fme)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.doWarmUp(TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() {
|
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
CmdFWarp.this.fme.getPlayer().teleport(CmdFWarp.this.myFaction.getWarp(warpName).getLocation());
|
CmdFWarp.this.fme.getPlayer().teleport(CmdFWarp.this.myFaction.getWarp(warpName).getLocation());
|
||||||
|
@ -5,6 +5,7 @@ import com.massivecraft.factions.integration.Essentials;
|
|||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.struct.Role;
|
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.SmokeUtil;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -110,7 +111,7 @@ public class CmdHome extends FCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.doWarmUp(TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
|
this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Create a smoke effect
|
// Create a smoke effect
|
||||||
|
@ -302,11 +302,11 @@ public abstract class FCommand extends MCommand<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doWarmUp(TL translationKey, String action, Runnable runnable, long delay) {
|
public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
|
||||||
this.doWarmUp(this.fme, translationKey, action, runnable, delay);
|
this.doWarmUp(this.fme, warmup, translationKey, action, runnable, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doWarmUp(FPlayer player, TL translationKey, String action, Runnable runnable, long delay) {
|
public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
|
||||||
WarmUpUtil.process(player, translationKey, action, runnable, delay);
|
WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,13 @@ public class FactionsEntityListener implements Listener {
|
|||||||
// entity took generic damage?
|
// entity took generic damage?
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity instanceof Player) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +122,16 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
FPlayer me = FPlayers.getInstance().getByPlayer(player);
|
||||||
|
|
||||||
// clear visualization
|
// clear visualization
|
||||||
if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
|
if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
|
||||||
VisualizeUtil.clear(event.getPlayer());
|
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
|
// quick check to make sure player is moving between chunks; good performance boost
|
||||||
@ -132,9 +139,6 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
FPlayer me = FPlayers.getInstance().getByPlayer(player);
|
|
||||||
|
|
||||||
// Did we change coord?
|
// Did we change coord?
|
||||||
FLocation from = me.getLastStoodAt();
|
FLocation from = me.getLastStoodAt();
|
||||||
FLocation to = new FLocation(event.getTo());
|
FLocation to = new FLocation(event.getTo());
|
||||||
|
@ -15,12 +15,28 @@ public class WarmUpUtil {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* note: for translations: %s = action, %d = delay
|
* 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) {
|
if (delay > 0) {
|
||||||
|
if (player.isWarmingUp()) {
|
||||||
|
player.msg(TL.WARMUPS_ALREADY);
|
||||||
|
} else {
|
||||||
player.msg(translationKey.format(action, delay));
|
player.msg(translationKey.format(action, delay));
|
||||||
P.p.getServer().getScheduler().runTaskLater(P.p, runnable, delay * 20);
|
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 {
|
} else {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Warmup {
|
||||||
|
HOME, WARP;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import com.massivecraft.factions.struct.Permission;
|
|||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
import com.massivecraft.factions.util.RelationUtil;
|
import com.massivecraft.factions.util.RelationUtil;
|
||||||
|
import com.massivecraft.factions.util.WarmUpUtil;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -95,6 +96,9 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
protected boolean spyingChat = false;
|
protected boolean spyingChat = false;
|
||||||
protected boolean showScoreboard;
|
protected boolean showScoreboard;
|
||||||
|
|
||||||
|
protected WarmUpUtil.Warmup warmup;
|
||||||
|
protected int warmupTask;
|
||||||
|
|
||||||
public Faction getFaction() {
|
public Faction getFaction() {
|
||||||
if (this.factionId == null) {
|
if (this.factionId == null) {
|
||||||
this.factionId = "0";
|
this.factionId = "0";
|
||||||
@ -883,4 +887,34 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,7 +708,9 @@ public enum TL {
|
|||||||
/**
|
/**
|
||||||
* Warmups
|
* 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 path;
|
||||||
private String def;
|
private String def;
|
||||||
|
@ -501,3 +501,5 @@ faction-logout: '&e%1$s &9logged out..'
|
|||||||
WARMUPS:
|
WARMUPS:
|
||||||
NOTIFY:
|
NOTIFY:
|
||||||
TELEPORT: '&eYou will teleport to &d%1$s &ein &d%2$d &eseconds.'
|
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.'
|
||||||
|
Loading…
Reference in New Issue
Block a user