Live players are now displayed on leaderboards in green. Dead players are still displayed in black.

This commit is contained in:
Garbage Mule 2011-10-08 12:55:10 +02:00
parent 4762fb5a6e
commit 7567d10dda
6 changed files with 81 additions and 20 deletions

Binary file not shown.

View File

@ -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 File

@ -674,6 +674,7 @@ public class Arena
arenaPlayers.remove(p);
lobbyPlayers.remove(p);
classMap.remove(p);
arenaPlayerMap.remove(p);
}
/**
@ -703,9 +704,10 @@ public class Arena
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 File

@ -18,7 +18,7 @@ public class ArenaPlayer
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 class ArenaPlayer
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 File

@ -3,21 +3,25 @@ package com.garbagemule.MobArena.leaderboards;
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 class LeaderboardColumn
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 File

@ -39,4 +39,18 @@ public class TextUtils
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); }
}