Implement basic scoreboard support.
This commit is contained in:
@@ -102,6 +102,9 @@ public class ArenaImpl implements Arena
|
|||||||
private TimeStrategy timeStrategy;
|
private TimeStrategy timeStrategy;
|
||||||
private AutoStartTimer autoStartTimer;
|
private AutoStartTimer autoStartTimer;
|
||||||
|
|
||||||
|
// Scoreboards
|
||||||
|
private ScoreboardManager scoreboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary constructor. Requires a name and a world.
|
* Primary constructor. Requires a name and a world.
|
||||||
*/
|
*/
|
||||||
@@ -166,6 +169,9 @@ public class ArenaImpl implements Arena
|
|||||||
String timeString = settings.getString("player-time-in-arena", "world");
|
String timeString = settings.getString("player-time-in-arena", "world");
|
||||||
Time time = Enums.getEnumFromString(Time.class, timeString);
|
Time time = Enums.getEnumFromString(Time.class, timeString);
|
||||||
this.timeStrategy = (time != null ? new TimeStrategyLocked(time) : new TimeStrategyNull());
|
this.timeStrategy = (time != null ? new TimeStrategyLocked(time) : new TimeStrategyNull());
|
||||||
|
|
||||||
|
// Scoreboards
|
||||||
|
this.scoreboard = new ScoreboardManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -364,6 +370,10 @@ public class ArenaImpl implements Arena
|
|||||||
return limitManager;
|
return limitManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScoreboardManager getScoreboard() {
|
||||||
|
return scoreboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -407,6 +417,9 @@ public class ArenaImpl implements Arena
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize scoreboards
|
||||||
|
scoreboard.initialize();
|
||||||
|
|
||||||
// Teleport players, give full health, initialize map
|
// Teleport players, give full health, initialize map
|
||||||
for (Player p : arenaPlayers) {
|
for (Player p : arenaPlayers) {
|
||||||
// TODO figure out how people die in lobby and get sent to spectator area early
|
// TODO figure out how people die in lobby and get sent to spectator area early
|
||||||
@@ -425,6 +438,8 @@ public class ArenaImpl implements Arena
|
|||||||
p.setFoodLevel(20);
|
p.setFoodLevel(20);
|
||||||
assignClassPermissions(p);
|
assignClassPermissions(p);
|
||||||
arenaPlayerMap.get(p).resetStats();
|
arenaPlayerMap.get(p).resetStats();
|
||||||
|
|
||||||
|
scoreboard.addPlayer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start spawning monsters (must happen before 'running = true;')
|
// Start spawning monsters (must happen before 'running = true;')
|
||||||
@@ -882,6 +897,8 @@ public class ArenaImpl implements Arena
|
|||||||
arenaPlayers.remove(p);
|
arenaPlayers.remove(p);
|
||||||
lobbyPlayers.remove(p);
|
lobbyPlayers.remove(p);
|
||||||
arenaPlayerMap.remove(p);
|
arenaPlayerMap.remove(p);
|
||||||
|
|
||||||
|
scoreboard.removePlayer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHealth(Player p, int health) {
|
private void setHealth(Player p, int health) {
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ public class ArenaListener
|
|||||||
ArenaPlayerStatistics stats = ap.getStats();
|
ArenaPlayerStatistics stats = ap.getStats();
|
||||||
if (stats != null) {
|
if (stats != null) {
|
||||||
ap.getStats().inc("kills");
|
ap.getStats().inc("kills");
|
||||||
|
arena.getScoreboard().addKill((Player) damager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ public class MASpawnThread implements Runnable
|
|||||||
|
|
||||||
w.announce(arena, wave);
|
w.announce(arena, wave);
|
||||||
|
|
||||||
|
arena.getScoreboard().updateWave(wave);
|
||||||
|
|
||||||
// Set the players' level to the wave number
|
// Set the players' level to the wave number
|
||||||
if (wavesAsLevel) {
|
if (wavesAsLevel) {
|
||||||
for (Player p : arena.getPlayersInArena()) {
|
for (Player p : arena.getPlayersInArena()) {
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
import org.bukkit.scoreboard.Score;
|
||||||
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
|
|
||||||
|
public class ScoreboardManager {
|
||||||
|
private Arena arena;
|
||||||
|
private Scoreboard scoreboard;
|
||||||
|
private Objective kills;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new scoreboard for the given arena.
|
||||||
|
* @param arena an arena
|
||||||
|
*/
|
||||||
|
ScoreboardManager(Arena arena) {
|
||||||
|
this.arena = arena;
|
||||||
|
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a player to the scoreboard by setting the player's scoreboard
|
||||||
|
* and giving him an initial to-be-reset non-zero score.
|
||||||
|
* @param player a player
|
||||||
|
*/
|
||||||
|
void addPlayer(Player player) {
|
||||||
|
/* Set the player's scoreboard and give them an initial non-zero
|
||||||
|
* score. This is necessary due to either Minecraft or Bukkit
|
||||||
|
* not wanting to show non-zero scores initially. */
|
||||||
|
player.setScoreboard(scoreboard);
|
||||||
|
kills.getScore(player).setScore(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a player from the scoreboard by setting the player's scoreboard
|
||||||
|
* to the main server scoreboard.
|
||||||
|
* @param player a player
|
||||||
|
*/
|
||||||
|
void removePlayer(Player player) {
|
||||||
|
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a kill to the player's score. Called when a player kills a mob.
|
||||||
|
* @param player a player
|
||||||
|
*/
|
||||||
|
void addKill(Player player) {
|
||||||
|
Score score = kills.getScore(player);
|
||||||
|
score.setScore(score.getScore() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the scoreboard to display the given wave number.
|
||||||
|
* @param wave a wave number
|
||||||
|
*/
|
||||||
|
void updateWave(int wave) {
|
||||||
|
kills.setDisplayName("§aMobArena Kills §bWave " + wave);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the scoreboard by resetting the kills objective and
|
||||||
|
* setting all player scores to 0.
|
||||||
|
*/
|
||||||
|
void initialize() {
|
||||||
|
/* Initialization involves first unregistering the kill counter if
|
||||||
|
* it was already registered, and then setting it back up.
|
||||||
|
* It is necessary to delay the reset of the player scores, and the
|
||||||
|
* reset is necessary because of non-zero crappiness. */
|
||||||
|
resetKills();
|
||||||
|
arena.scheduleTask(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
for (Player p : arena.getPlayersInArena()) {
|
||||||
|
kills.getScore(p).setScore(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetKills() {
|
||||||
|
if (kills != null) {
|
||||||
|
kills.unregister();
|
||||||
|
}
|
||||||
|
kills = scoreboard.registerNewObjective("kills", "ma-kills");
|
||||||
|
kills.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
|
updateWave(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import com.garbagemule.MobArena.MASpawnThread;
|
|||||||
import com.garbagemule.MobArena.MobArena;
|
import com.garbagemule.MobArena.MobArena;
|
||||||
import com.garbagemule.MobArena.MonsterManager;
|
import com.garbagemule.MobArena.MonsterManager;
|
||||||
import com.garbagemule.MobArena.RewardManager;
|
import com.garbagemule.MobArena.RewardManager;
|
||||||
|
import com.garbagemule.MobArena.ScoreboardManager;
|
||||||
import com.garbagemule.MobArena.leaderboards.Leaderboard;
|
import com.garbagemule.MobArena.leaderboards.Leaderboard;
|
||||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||||
import com.garbagemule.MobArena.repairable.Repairable;
|
import com.garbagemule.MobArena.repairable.Repairable;
|
||||||
@@ -104,6 +105,8 @@ public interface Arena
|
|||||||
|
|
||||||
public void revivePlayer(Player p);
|
public void revivePlayer(Player p);
|
||||||
|
|
||||||
|
public ScoreboardManager getScoreboard();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user