Skip to content

Commit

Permalink
Closed #138 and closed #102
Browse files Browse the repository at this point in the history
PR #142
  • Loading branch information
CraftedMods authored Jun 26, 2018
1 parent e4531a5 commit 60acaf9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pvpmode/EnumPvPMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public enum EnumPvPMode
{

ON, OFF, WARMUP
ON, OFF

}
27 changes: 17 additions & 10 deletions src/main/java/pvpmode/PvPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

}
13 changes: 6 additions & 7 deletions src/main/java/pvpmode/command/PvPCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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.");
Expand All @@ -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;
Expand Down
41 changes: 26 additions & 15 deletions src/main/java/pvpmode/command/PvPCommandList.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ 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;
if (!unsafePlayers.containsKey (proximity))
unsafePlayers.put (proximity, new HashSet<> ());
unsafePlayers.get (proximity).add (player);
break;
case WARMUP:
warmupPlayers.add (player);
break;
}
}
}
Expand All @@ -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, "-------------------------");
Expand All @@ -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;
Expand All @@ -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]");
Expand All @@ -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)
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 60acaf9

Please sign in to comment.