Permalink
Browse files

Live players are now displayed on leaderboards in green. Dead players…

… are still displayed in black.
  • Loading branch information...
1 parent 4762fb5 commit 7567d10ddaeba64004043cd21dab57dd87519eef @garbagemule committed Oct 8, 2011
View
BIN MobArena.jar
Binary file not shown.
View
2 resources/plugin.yml
@@ -1,6 +1,6 @@
name: MobArena
main: com.garbagemule.MobArena.MobArena
-version: 0.94.3.15
+version: 0.94.3.16
softdepend: [Spout,Permissions,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells]
commands:
ma:
View
8 src/com/garbagemule/MobArena/Arena.java
@@ -674,6 +674,7 @@ private void clearPlayer(Player p)
arenaPlayers.remove(p);
lobbyPlayers.remove(p);
classMap.remove(p);
+ arenaPlayerMap.remove(p);
}
/**
@@ -703,9 +704,10 @@ private void finishArenaPlayer(Player p, boolean dead)
if (dead) restoreInvAndGiveRewardsDelayed(p);
else restoreInvAndGiveRewards(p);
-
- if (log != null && spawnThread != null)
- arenaPlayerMap.get(p).getStats().lastWave = spawnThread.getWave() - 1;
+
+ ArenaPlayer ap = arenaPlayerMap.get(p);
+ if (ap != null)
+ ap.setDead(true);
}
public void repairBlocks()
View
21 src/com/garbagemule/MobArena/ArenaPlayer.java
@@ -18,7 +18,7 @@
private ArenaPlayerStatistics stats;
- protected boolean inArena, inLobby, inSpec, isReady;
+ protected boolean isDead, inArena, inLobby, inSpec, isReady;
public ArenaPlayer(Player player, Arena arena, MobArena plugin)
{
@@ -36,5 +36,24 @@ public ArenaPlayer(Player player, Arena arena, MobArena plugin)
public Player getPlayer() { return player; }
public Arena getArena() { return arena; }
public String getClassName() { return className; }
+
+ /**
+ * Check if the player is "dead", i.e. died or not.
+ * @return true, if the player is either a spectator or played and died, false otherwise
+ */
+ public boolean isDead()
+ {
+ return isDead;
+ }
+
+ /**
+ * Set the player's death status.
+ * @param value true, if the player is dead, false otherwise
+ */
+ public void setDead(boolean value)
+ {
+ isDead = value;
+ }
+
public ArenaPlayerStatistics getStats() { return stats; }
}
View
56 src/com/garbagemule/MobArena/leaderboards/LeaderboardColumn.java
@@ -3,21 +3,25 @@
import java.lang.reflect.Field;
import java.util.List;
+import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import com.garbagemule.MobArena.ArenaPlayerStatistics;
+import com.garbagemule.MobArena.util.TextUtils;
public class LeaderboardColumn
{
private Field field;
+ private boolean isPlayerName;
private Sign header;
private List<Sign> signs;
private LeaderboardColumn(String statname, Sign header, List<Sign> signs) throws Exception
{
- this.field = ArenaPlayerStatistics.class.getDeclaredField(statname);
- this.header = header;
- this.signs = signs;
+ this.field = ArenaPlayerStatistics.class.getDeclaredField(statname);
+ this.isPlayerName = statname.equals("playerName");
+ this.header = header;
+ this.signs = signs;
}
/**
@@ -48,19 +52,41 @@ public void update(List<ArenaPlayerStatistics> stats)
try
{
- for (int i = 0; i < range; i++)
+ if (isPlayerName)
{
- // Grab the right sign.
- Sign s = signs.get(i/4);
-
- // Get the stat value.
- field.setAccessible(true);
- Object o = field.get(stats.get(i));
- field.setAccessible(false);
-
- // Set the value on the right line.
- s.setLine(i % 4, o.toString());
- s.update();
+ for (int i = 0; i < range; i++)
+ {
+ // Grab the right sign.
+ Sign s = signs.get(i/4);
+
+ // Get the stat value.
+ field.setAccessible(true);
+ ArenaPlayerStatistics aps = stats.get(i);
+ Object o = field.get(aps);
+ field.setAccessible(false);
+ String name = aps.getArenaPlayer().isDead() ? o.toString() : ChatColor.GREEN + o.toString();
+
+ // Set the value on the right line.
+ s.setLine(i % 4, TextUtils.truncate(name));
+ s.update();
+ }
+ }
+ else
+ {
+ for (int i = 0; i < range; i++)
+ {
+ // Grab the right sign.
+ Sign s = signs.get(i/4);
+
+ // Get the stat value.
+ field.setAccessible(true);
+ Object o = field.get(stats.get(i));
+ field.setAccessible(false);
+
+ // Set the value on the right line.
+ s.setLine(i % 4, o.toString());
+ s.update();
+ }
}
}
catch (Exception e) { e.printStackTrace(); }
View
14 src/com/garbagemule/MobArena/util/TextUtils.java
@@ -39,4 +39,18 @@ public static String padLeft(String s, int length, char pad)
public static String padLeft(String s, int length) { return padLeft(s, length, ' '); }
public static String padLeft(int s, int length) { return padLeft(Integer.toString(s), length, ' '); }
public static String padLeft(double s, int length) { return padLeft(Double.toString(s), length, ' '); }
+
+ /**
+ * Truncate the input string to be at most the input length
+ * @param s The string to truncate
+ * @param length The maximum length
+ * @return A truncated string with length 15, or the input string
+ */
+ public static String truncate(String s, int length)
+ {
+ if (s.length() <= length)
+ return s;
+ return s.substring(0, length);
+ }
+ public static String truncate(String s) { return truncate(s, 15); }
}

0 comments on commit 7567d10

Please sign in to comment.