diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f15cb..a76b147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog of PvPMode for Minecraft 1.7.10: ## 1.1.4-BETA +* Fixed that players switching from PvP on to off couldn't do PvP during the warmup phase +* Fixed that the warmup timer was displayed in an incorrect way sometimes in `pvplist` ## 1.1.3-BETA * Fixed that the PvP timer wasn't resetted for creative/flying players diff --git a/src/main/java/pvpmode/EnumPvPMode.java b/src/main/java/pvpmode/EnumPvPMode.java index a3e3dce..5b00cb4 100644 --- a/src/main/java/pvpmode/EnumPvPMode.java +++ b/src/main/java/pvpmode/EnumPvPMode.java @@ -3,6 +3,6 @@ public enum EnumPvPMode { - ON, OFF, WARMUP + ON, OFF } diff --git a/src/main/java/pvpmode/PvPUtils.java b/src/main/java/pvpmode/PvPUtils.java index 3fbf502..5f9c8ae 100644 --- a/src/main/java/pvpmode/PvPUtils.java +++ b/src/main/java/pvpmode/PvPUtils.java @@ -140,16 +140,7 @@ public static EnumPvPMode getPvPMode (EntityPlayer player) if (data.getPvPTimer () == 0) { // Player is not in PvP - if (data.getPvPWarmup () == 0) - { - // No warmup timer is running - return data.isPvPEnabled () ? EnumPvPMode.ON : EnumPvPMode.OFF; - } - else - { - // Warmup timer is running - return EnumPvPMode.WARMUP; - } + return data.isPvPEnabled () ? EnumPvPMode.ON : EnumPvPMode.OFF; } else { @@ -311,4 +302,20 @@ public static EntityPlayerMP getMaster (Entity entity) return PvPUtils.postEventAndGetResult (event, event::getMaster); } + /** + * Returns whether the warmup timer for the supplied player is running + */ + public static boolean isWarmupTimerRunning (EntityPlayer player) + { + return getPvPData (player).getPvPWarmup () != 0; + } + + /** + * Returns the remaining warmup time. + */ + public static long getWarmupTimer (EntityPlayer player) + { + return Math.max (getPvPData (player).getPvPWarmup () - PvPUtils.getTime (), 0); + } + } diff --git a/src/main/java/pvpmode/command/PvPCommand.java b/src/main/java/pvpmode/command/PvPCommand.java index da1b663..cffb536 100644 --- a/src/main/java/pvpmode/command/PvPCommand.java +++ b/src/main/java/pvpmode/command/PvPCommand.java @@ -31,7 +31,6 @@ public boolean canCommandSenderUseCommand (ICommandSender sender) public void processCommand (ICommandSender sender, String[] args) { EntityPlayerMP player = getCommandSenderAsPlayer (sender); - EnumPvPMode currentMode = PvPUtils.getPvPMode (player); PvPData data = PvPUtils.getPvPData (player); if (!PvPUtils.isCreativeMode (player)) @@ -46,12 +45,12 @@ public void processCommand (ICommandSender sender, String[] args) { if (requireArgument (sender, args, 0, "cancel")) { - cancelPvPTimer (player, currentMode, data); + cancelPvPTimer (player, data); } } else { - togglePvPMode (sender, currentMode, data); + togglePvPMode (player, data); } } else @@ -75,9 +74,9 @@ public void processCommand (ICommandSender sender, String[] args) } } - private void cancelPvPTimer (EntityPlayer player, EnumPvPMode mode, PvPData data) + private void cancelPvPTimer (EntityPlayer player, PvPData data) { - if (mode == EnumPvPMode.WARMUP) + if (PvPUtils.isWarmupTimerRunning (player)) { data.setPvPWarmup (0); PvPUtils.yellow (player, "PvP warmup canceled."); @@ -88,9 +87,9 @@ private void cancelPvPTimer (EntityPlayer player, EnumPvPMode mode, PvPData data } } - private void togglePvPMode (ICommandSender sender, EnumPvPMode mode, PvPData data) + private void togglePvPMode (EntityPlayer sender, PvPData data) { - if (mode != EnumPvPMode.WARMUP) + if (!PvPUtils.isWarmupTimerRunning (sender)) { long time = PvPUtils.getTime (); long toggleTime = time + PvPMode.warmup; diff --git a/src/main/java/pvpmode/command/PvPCommandList.java b/src/main/java/pvpmode/command/PvPCommandList.java index 051b2f7..95b2ee7 100644 --- a/src/main/java/pvpmode/command/PvPCommandList.java +++ b/src/main/java/pvpmode/command/PvPCommandList.java @@ -48,7 +48,14 @@ public void processCommand (ICommandSender sender, String[] args) switch (mode) { case OFF: - safePlayers.add (player); + if (PvPUtils.isWarmupTimerRunning (player)) + { + warmupPlayers.add (player); + } + else + { + safePlayers.add (player); + } break; case ON: int proximity = PvPMode.radar ? PvPUtils.roundedDistanceBetween (senderPlayer, player) : -1; @@ -56,9 +63,6 @@ public void processCommand (ICommandSender sender, String[] args) unsafePlayers.put (proximity, new HashSet<> ()); unsafePlayers.get (proximity).add (player); break; - case WARMUP: - warmupPlayers.add (player); - break; } } } @@ -74,7 +78,7 @@ public void processCommand (ICommandSender sender, String[] args) } } warmupPlayers.forEach ( - player -> displayMessageForPlayer (player, senderPlayer, EnumPvPMode.WARMUP, senderPlayerPvPMode, -1)); + player -> displayMessageForPlayer (player, senderPlayer, EnumPvPMode.OFF, senderPlayerPvPMode, -1)); safePlayers.forEach ( player -> displayMessageForPlayer (player, senderPlayer, EnumPvPMode.OFF, senderPlayerPvPMode, -1)); PvPUtils.green (sender, "-------------------------"); @@ -87,6 +91,7 @@ private void displayMessageForPlayer (EntityPlayerMP player, EntityPlayerMP send { boolean isSenderPlayer = player == senderPlayer; boolean hasSenderPlayerPvPEnabled = senderPlayerMode == EnumPvPMode.ON; + boolean isWarmupTimerRunning = PvPUtils.isWarmupTimerRunning (player); IChatComponent modeComponent = null; IChatComponent nameComponent = new ChatComponentText (String.format (" %s", player.getDisplayName ())); IChatComponent additionalComponent = null; @@ -96,7 +101,9 @@ private void displayMessageForPlayer (EntityPlayerMP player, EntityPlayerMP send modeComponent = new ChatComponentText ( String.format ("[OFF%s]", PvPUtils.isCreativeMode (player) ? ":GM1" : PvPUtils.canFly (player) ? ":FLY" : "")); - setComponentColors (EnumChatFormatting.GREEN, isSenderPlayer, modeComponent, nameComponent); + setComponentColors (isWarmupTimerRunning ? EnumChatFormatting.YELLOW : EnumChatFormatting.GREEN, + isSenderPlayer, modeComponent, + nameComponent); break; case ON: modeComponent = new ChatComponentText ("[ON]"); @@ -107,13 +114,14 @@ private void displayMessageForPlayer (EntityPlayerMP player, EntityPlayerMP send setComponentColors (EnumChatFormatting.RED, isSenderPlayer, modeComponent, nameComponent, additionalComponent); break; - case WARMUP: - modeComponent = new ChatComponentText ("[WARMUP]"); - additionalComponent = new ChatComponentText (String.format (" - %d seconds till PvP", - PvPUtils.getPvPData (player).getPvPWarmup () - PvPUtils.getTime ())); - setComponentColors (EnumChatFormatting.YELLOW, isSenderPlayer, modeComponent, nameComponent, - additionalComponent); - break; + } + if (isWarmupTimerRunning) + { + ChatComponentText warmupComponent = new ChatComponentText ( + String.format (" [%ds]", PvPUtils.getWarmupTimer (player))); + warmupComponent.getChatStyle ().setColor (EnumChatFormatting.YELLOW); + modeComponent + .appendSibling (warmupComponent); } modeComponent.appendSibling (nameComponent); if (additionalComponent != null) @@ -129,8 +137,11 @@ private void setComponentColors (EnumChatFormatting baseColor, boolean isSenderP boolean first = true; for (IChatComponent component : components) { - component.getChatStyle ().setColor (!first && isSenderPlayer ? EnumChatFormatting.BLUE : baseColor); - first = false; + if (component != null) + { + component.getChatStyle ().setColor (!first && isSenderPlayer ? EnumChatFormatting.BLUE : baseColor); + first = false; + } } }