Add option to use scoreboards for power level display, similar to the

Spout titles. This will NOT override any existing plugin that uses the
overhead scoreboard slot.
This commit is contained in:
GJ 2013-05-15 15:13:11 -04:00
parent 48aafa9834
commit aa9eb0868c
6 changed files with 38 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Version 1.4.06-dev
+ Added config option to multiply xp gains from mob spawner mobs + Added config option to multiply xp gains from mob spawner mobs
+ Added multiplier to Archery XP based on bow force + Added multiplier to Archery XP based on bow force
+ Added information about /party itemshare and /party expshare to the party help page + Added information about /party itemshare and /party expshare to the party help page
+ Added option to use scoreboards for power level display instead of Spout.
= Fixed bug where players were able to join the same party multiple times = Fixed bug where players were able to join the same party multiple times
= Fixed displaying partial names when trying to use /ptp = Fixed displaying partial names when trying to use /ptp
= Fixed wolves from Call of the Wild only having 8 health = Fixed wolves from Call of the Wild only having 8 health

View File

@ -80,6 +80,8 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getSkillScoreboardEnabled() { return config.getBoolean("Scoreboards.Skillname.Use", true); } public boolean getSkillScoreboardEnabled() { return config.getBoolean("Scoreboards.Skillname.Use", true); }
public int getSkillScoreboardTime() { return config.getInt("Scoreboards.Skillname.Display_Time", 10); } public int getSkillScoreboardTime() { return config.getInt("Scoreboards.Skillname.Display_Time", 10); }
public boolean getPowerLevelsEnabled() { return config.getBoolean("Scoreboards.Power_Level.Use", true); }
/* Database Purging */ /* Database Purging */
public int getPurgeInterval() { return config.getInt("Database_Purging.Purge_Interval", -1); } public int getPurgeInterval() { return config.getInt("Database_Purging.Purge_Interval", -1); }
public int getOldUsersCutoff() { return config.getInt("Database_Purging.Old_User_Cutoff", 6); } public int getOldUsersCutoff() { return config.getInt("Database_Purging.Old_User_Cutoff", 6); }

View File

@ -54,6 +54,7 @@ import com.gmail.nossr50.util.MobHealthbarUtils;
import com.gmail.nossr50.util.Motd; import com.gmail.nossr50.util.Motd;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
@ -144,6 +145,7 @@ public class PlayerListener implements Listener {
} }
UserManager.addUser(player).actualizeRespawnATS(); UserManager.addUser(player).actualizeRespawnATS();
ScoreboardManager.enablePowerLevelDisplay(player);
} }
/** /**

View File

@ -19,6 +19,7 @@ public class ScoreboardChangeTask extends BukkitRunnable {
public void run() { public void run() {
if (player.isOnline()) { if (player.isOnline()) {
player.setScoreboard(oldScoreboard); player.setScoreboard(oldScoreboard);
ScoreboardManager.enablePowerLevelDisplay(player);
} }
ScoreboardManager.clearPendingTask(player.getName()); ScoreboardManager.clearPendingTask(player.getName());

View File

@ -23,6 +23,7 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.runnables.scoreboards.ScoreboardChangeTask; import com.gmail.nossr50.runnables.scoreboards.ScoreboardChangeTask;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class ScoreboardManager { public class ScoreboardManager {
@ -32,6 +33,7 @@ public class ScoreboardManager {
private final static String PLAYER_STATS_HEADER = "mcMMO Stats"; private final static String PLAYER_STATS_HEADER = "mcMMO Stats";
private final static String PLAYER_RANK_HEADER = "mcMMO Rankings"; private final static String PLAYER_RANK_HEADER = "mcMMO Rankings";
private final static String PLAYER_INSPECT_HEADER = "mcMMO Stats: "; private final static String PLAYER_INSPECT_HEADER = "mcMMO Stats: ";
private final static String POWER_LEVEL_HEADER = "Power Level";
private final static List<String> SCOREBOARD_TASKS = new ArrayList<String>(); private final static List<String> SCOREBOARD_TASKS = new ArrayList<String>();
@ -43,6 +45,32 @@ public class ScoreboardManager {
PLAYER_SCOREBOARDS.put(playerName, mcMMO.p.getServer().getScoreboardManager().getNewScoreboard()); PLAYER_SCOREBOARDS.put(playerName, mcMMO.p.getServer().getScoreboardManager().getNewScoreboard());
} }
public static void enablePowerLevelDisplay(Player player) {
if (!Config.getInstance().getPowerLevelsEnabled()) {
return;
}
Scoreboard scoreboard = player.getScoreboard();
Objective objective;
if (scoreboard.getObjective(DisplaySlot.BELOW_NAME) == null) {
objective = scoreboard.registerNewObjective(POWER_LEVEL_HEADER, "dummy");
objective.getScore(player).setScore(UserManager.getPlayer(player).getPowerLevel());
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
}
else {
objective = scoreboard.getObjective(POWER_LEVEL_HEADER);
if (scoreboard.getObjective(POWER_LEVEL_HEADER) != null) {
objective.getScore(player).setScore(UserManager.getPlayer(player).getPowerLevel());
}
else {
mcMMO.p.debug("Another plugin is using this scoreboard slot, so power levels cannot be enabled."); //TODO: Locale
}
}
}
public static void enablePlayerSkillScoreboard(McMMOPlayer mcMMOPlayer, SkillType skill) { public static void enablePlayerSkillScoreboard(McMMOPlayer mcMMOPlayer, SkillType skill) {
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
Scoreboard oldScoreboard = player.getScoreboard(); Scoreboard oldScoreboard = player.getScoreboard();
@ -307,6 +335,7 @@ public class ScoreboardManager {
String playerName = player.getName(); String playerName = player.getName();
player.setScoreboard(newScoreboard); player.setScoreboard(newScoreboard);
enablePowerLevelDisplay(player);
if (displayTime != -1 && !SCOREBOARD_TASKS.contains(playerName)) { if (displayTime != -1 && !SCOREBOARD_TASKS.contains(playerName)) {
new ScoreboardChangeTask(player, oldScoreboard).runTaskLater(mcMMO.p, displayTime * 20); new ScoreboardChangeTask(player, oldScoreboard).runTaskLater(mcMMO.p, displayTime * 20);

View File

@ -56,6 +56,9 @@ Scoreboards:
Skillname: Skillname:
Use: true Use: true
Display_Time: 10 Display_Time: 10
# Should mcMMO display power levels on scoreboards?
Power_Level:
Use: true
Mob_Healthbar: Mob_Healthbar:
# Default display for mob health bars - HEARTS, BAR, or DISABLED # Default display for mob health bars - HEARTS, BAR, or DISABLED