Scoreboards fixes

This commit is contained in:
nossr50 2020-08-08 15:56:53 -07:00
parent 771ed9a8b4
commit 3a035e234a
4 changed files with 233 additions and 112 deletions

View File

@ -1,3 +1,10 @@
Version 2.1.140
Deployed a few fixes to scoreboards code
Updated polish locale
NOTES:
Scoreboards code is a mess and most of it is ancient, I plan to rewrite it in a future update. The way scoreboards API works in general is just difficult to deal with.
Version 2.1.139 Version 2.1.139
Code used to fetch UUIDs was reworked to avoid a scenario where it failed (thanks t00thpick1) Code used to fetch UUIDs was reworked to avoid a scenario where it failed (thanks t00thpick1)
Added 'Netherite_Gold_Ore' to Smelting XP tables (thanks Quavelen) Added 'Netherite_Gold_Ore' to Smelting XP tables (thanks Quavelen)

View File

@ -33,7 +33,7 @@ public class SelfListener implements Listener {
public void onPlayerLevelUp(McMMOPlayerLevelUpEvent event) { public void onPlayerLevelUp(McMMOPlayerLevelUpEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PrimarySkillType skill = event.getSkill(); PrimarySkillType skill = event.getSkill();
if(player.isOnline()) {
//Players can gain multiple levels especially during xprate events //Players can gain multiple levels especially during xprate events
for(int i = 0; i < event.getLevelsGained(); i++) for(int i = 0; i < event.getLevelsGained(); i++)
{ {
@ -47,26 +47,27 @@ public class SelfListener implements Listener {
if(Config.getInstance().getScoreboardsEnabled()) if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.handleLevelUp(player, skill); ScoreboardManager.handleLevelUp(player, skill);
if (!Config.getInstance().getLevelUpEffectsEnabled()) {
} }
/*if ((event.getSkillLevel() % Config.getInstance().getLevelUpEffectsTier()) == 0) {
skill.celebrateLevelUp(player);
}*/
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerXp(McMMOPlayerXpGainEvent event) { public void onPlayerXp(McMMOPlayerXpGainEvent event) {
Player player = event.getPlayer();
if(player.isOnline()) {
if(Config.getInstance().getScoreboardsEnabled()) if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.handleXp(event.getPlayer(), event.getSkill()); ScoreboardManager.handleXp(player, event.getSkill());
}
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAbility(McMMOPlayerAbilityActivateEvent event) { public void onAbility(McMMOPlayerAbilityActivateEvent event) {
Player player = event.getPlayer();
if(player.isOnline()) {
if(Config.getInstance().getScoreboardsEnabled()) if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.cooldownUpdate(event.getPlayer(), event.getSkill()); ScoreboardManager.cooldownUpdate(event.getPlayer(), event.getSkill());
} }
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerXpGain(McMMOPlayerXpGainEvent event) { public void onPlayerXpGain(McMMOPlayerXpGainEvent event) {

View File

@ -6,6 +6,8 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.events.scoreboard.McMMOScoreboardMakeboardEvent;
import com.gmail.nossr50.events.scoreboard.ScoreboardEventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -18,6 +20,8 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
@ -42,13 +46,15 @@ public class ScoreboardManager {
static final String LABEL_LEVEL = LocaleLoader.getString("Scoreboard.Misc.Level"); static final String LABEL_LEVEL = LocaleLoader.getString("Scoreboard.Misc.Level");
static final String LABEL_CURRENT_XP = LocaleLoader.getString("Scoreboard.Misc.CurrentXP"); static final String LABEL_CURRENT_XP = LocaleLoader.getString("Scoreboard.Misc.CurrentXP");
static final String LABEL_REMAINING_XP = LocaleLoader.getString("Scoreboard.Misc.RemainingXP"); static final String LABEL_REMAINING_XP = LocaleLoader.getString("Scoreboard.Misc.RemainingXP");
static final String LABEL_ABILITY_COOLDOWN = LocaleLoader.getString("Scoreboard.Misc.Cooldown"); // static final String LABEL_ABILITY_COOLDOWN = LocaleLoader.getString("Scoreboard.Misc.Cooldown");
static final String LABEL_OVERALL = LocaleLoader.getString("Scoreboard.Misc.Overall"); // static final String LABEL_OVERALL = LocaleLoader.getString("Scoreboard.Misc.Overall");
static final Map<PrimarySkillType, String> skillLabels; static final Map<PrimarySkillType, String> skillLabels;
static final Map<SuperAbilityType, String> abilityLabelsColored; static final Map<SuperAbilityType, String> abilityLabelsColored;
static final Map<SuperAbilityType, String> abilityLabelsSkill; static final Map<SuperAbilityType, String> abilityLabelsSkill;
public static final String DISPLAY_NAME = "powerLevel";
/* /*
* Initializes the static properties of this class * Initializes the static properties of this class
*/ */
@ -170,23 +176,30 @@ public class ScoreboardManager {
// Called by PlayerJoinEvent listener // Called by PlayerJoinEvent listener
public static void setupPlayer(Player player) { public static void setupPlayer(Player player) {
PLAYER_SCOREBOARDS.put(player.getName(), ScoreboardWrapper.create(player)); teardownPlayer(player);
PLAYER_SCOREBOARDS.put(player.getName(), makeNewScoreboard(player));
dirtyPowerLevels.add(player.getName()); dirtyPowerLevels.add(player.getName());
} }
// Called by PlayerQuitEvent listener and OnPlayerTeleport under certain circumstances // Called by PlayerQuitEvent listener and OnPlayerTeleport under certain circumstances
public static void teardownPlayer(Player player) { public static void teardownPlayer(Player player) {
if(player == null)
return;
//Hacky world blacklist fix //Hacky world blacklist fix
if(player.isOnline() && player.isValid()) if(player.isOnline() && player.isValid()) {
if(Bukkit.getServer().getScoreboardManager() != null) if(Bukkit.getServer().getScoreboardManager() != null)
player.setScoreboard(Bukkit.getServer().getScoreboardManager().getMainScoreboard()); player.setScoreboard(Bukkit.getServer().getScoreboardManager().getMainScoreboard());
}
if(getWrapper(player) != null) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.remove(player.getName()); ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.remove(player.getName());
if(wrapper.revertTask != null) {
if (wrapper != null && wrapper.revertTask != null) {
wrapper.revertTask.cancel(); wrapper.revertTask.cancel();
} }
} }
}
// Called in onDisable() // Called in onDisable()
public static void teardownAll() { public static void teardownAll() {
@ -209,18 +222,24 @@ public class ScoreboardManager {
// Called by internal level-up event listener // Called by internal level-up event listener
public static void handleLevelUp(Player player, PrimarySkillType skill) { public static void handleLevelUp(Player player, PrimarySkillType skill) {
// Selfboards // Selfboards
ScoreboardWrapper selfboardWrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if ((selfboardWrapper.isSkillScoreboard() && selfboardWrapper.targetSkill == skill) || (selfboardWrapper.isStatsScoreboard()) && selfboardWrapper.isBoardShown()) { if(wrapper == null) {
selfboardWrapper.doSidebarUpdateSoon(); setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
if ((wrapper.isSkillScoreboard() && wrapper.targetSkill == skill) || (wrapper.isStatsScoreboard()) && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon();
} }
// Otherboards // Otherboards
String playerName = player.getName(); String playerName = player.getName();
for (ScoreboardWrapper wrapper : PLAYER_SCOREBOARDS.values()) { for (ScoreboardWrapper iWrapper : PLAYER_SCOREBOARDS.values()) {
if (wrapper.isStatsScoreboard() && playerName.equals(wrapper.targetPlayer) && selfboardWrapper.isBoardShown()) { if (iWrapper.isStatsScoreboard() && playerName.equals(iWrapper.targetPlayer) && wrapper.isBoardShown()) {
selfboardWrapper.doSidebarUpdateSoon(); wrapper.doSidebarUpdateSoon();
} }
} }
@ -231,12 +250,14 @@ public class ScoreboardManager {
if (Config.getInstance().getSkillLevelUpBoard()) { if (Config.getInstance().getSkillLevelUpBoard()) {
enablePlayerSkillLevelUpScoreboard(player, skill); enablePlayerSkillLevelUpScoreboard(player, skill);
} }
}
} }
// Called by internal xp event listener // Called by internal xp event listener
public static void handleXp(Player player, PrimarySkillType skill) { public static void handleXp(Player player, PrimarySkillType skill) {
// Selfboards // Selfboards
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if (wrapper != null && wrapper.isSkillScoreboard() && wrapper.targetSkill == skill && wrapper.isBoardShown()) { if (wrapper != null && wrapper.isSkillScoreboard() && wrapper.targetSkill == skill && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon(); wrapper.doSidebarUpdateSoon();
@ -246,40 +267,59 @@ public class ScoreboardManager {
// Called by internal ability event listeners // Called by internal ability event listeners
public static void cooldownUpdate(Player player, PrimarySkillType skill) { public static void cooldownUpdate(Player player, PrimarySkillType skill) {
// Selfboards // Selfboards
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if (wrapper != null && (wrapper.isCooldownScoreboard() || wrapper.isSkillScoreboard() && wrapper.targetSkill == skill) && wrapper.isBoardShown()) { if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
if ((wrapper.isCooldownScoreboard() || wrapper.isSkillScoreboard() && wrapper.targetSkill == skill) && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon(); wrapper.doSidebarUpdateSoon();
} }
} }
}
// **** Setup methods **** // // **** Setup methods **** //
public static void enablePlayerSkillScoreboard(Player player, PrimarySkillType skill) { public static void enablePlayerSkillScoreboard(Player player, PrimarySkillType skill) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeSkill(skill); wrapper.setTypeSkill(skill);
changeScoreboard(wrapper, Config.getInstance().getSkillScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getSkillScoreboardTime());
} }
}
public static void enablePlayerSkillLevelUpScoreboard(Player player, PrimarySkillType skill) { public static void enablePlayerSkillLevelUpScoreboard(Player player, PrimarySkillType skill) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
// Do NOT run if already shown // Do NOT run if already shown
if (wrapper.isBoardShown()) { if (wrapper != null && wrapper.isBoardShown()) {
if(wrapper.isBoardShown())
return; return;
}
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeSkill(skill); wrapper.setTypeSkill(skill);
changeScoreboard(wrapper, Config.getInstance().getSkillLevelUpTime()); changeScoreboard(wrapper, Config.getInstance().getSkillLevelUpTime());
} }
}
public static void enablePlayerStatsScoreboard(Player player) { public static void enablePlayerStatsScoreboard(Player player) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null)
return;
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeSelfStats(); wrapper.setTypeSelfStats();
@ -288,62 +328,113 @@ public class ScoreboardManager {
} }
public static void enablePlayerInspectScoreboard(Player player, PlayerProfile targetProfile) { public static void enablePlayerInspectScoreboard(Player player, PlayerProfile targetProfile) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeInspectStats(targetProfile); wrapper.setTypeInspectStats(targetProfile);
changeScoreboard(wrapper, Config.getInstance().getInspectScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getInspectScoreboardTime());
} }
}
public static void enablePlayerCooldownScoreboard(Player player) { public static void enablePlayerCooldownScoreboard(Player player) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeCooldowns(); wrapper.setTypeCooldowns();
changeScoreboard(wrapper, Config.getInstance().getCooldownScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getCooldownScoreboardTime());
} }
}
public static void showPlayerRankScoreboard(Player player, Map<PrimarySkillType, Integer> rank) { public static void showPlayerRankScoreboard(Player player, Map<PrimarySkillType, Integer> rank) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeSelfRank(); wrapper.setTypeSelfRank();
wrapper.acceptRankData(rank); wrapper.acceptRankData(rank);
changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime());
} }
}
public static void showPlayerRankScoreboardOthers(Player player, String targetName, Map<PrimarySkillType, Integer> rank) { public static void showPlayerRankScoreboardOthers(Player player, String targetName, Map<PrimarySkillType, Integer> rank) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeInspectRank(targetName); wrapper.setTypeInspectRank(targetName);
wrapper.acceptRankData(rank); wrapper.acceptRankData(rank);
changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime());
} }
}
public static void showTopScoreboard(Player player, PrimarySkillType skill, int pageNumber, List<PlayerStat> stats) { public static void showTopScoreboard(Player player, PrimarySkillType skill, int pageNumber, List<PlayerStat> stats) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeTop(skill, pageNumber); wrapper.setTypeTop(skill, pageNumber);
wrapper.acceptLeaderboardData(stats); wrapper.acceptLeaderboardData(stats);
changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime());
} }
}
public static void showTopPowerScoreboard(Player player, int pageNumber, List<PlayerStat> stats) { public static void showTopPowerScoreboard(Player player, int pageNumber, List<PlayerStat> stats) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName()); ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard(); wrapper.setOldScoreboard();
wrapper.setTypeTopPower(pageNumber); wrapper.setTypeTopPower(pageNumber);
wrapper.acceptLeaderboardData(stats); wrapper.acceptLeaderboardData(stats);
changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime()); changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime());
} }
}
public static @Nullable ScoreboardWrapper getWrapper(Player player) {
if(PLAYER_SCOREBOARDS.get(player.getName()) == null) {
makeNewScoreboard(player);
}
return PLAYER_SCOREBOARDS.get(player.getName());
}
// **** Helper methods **** // // **** Helper methods **** //
@ -386,9 +477,12 @@ public class ScoreboardManager {
* *
* @return the main targetBoard objective, or null if disabled * @return the main targetBoard objective, or null if disabled
*/ */
public static Objective getPowerLevelObjective() { public static @Nullable Objective getPowerLevelObjective() {
if (!Config.getInstance().getPowerLevelTagsEnabled()) { if (!Config.getInstance().getPowerLevelTagsEnabled()) {
Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); if(getScoreboardManager() == null)
return null;
Objective objective = getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if (objective != null) { if (objective != null) {
objective.unregister(); objective.unregister();
@ -398,10 +492,14 @@ public class ScoreboardManager {
return null; return null;
} }
Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if(getScoreboardManager() == null)
return null;
Objective powerObjective = getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if (powerObjective == null) { if (powerObjective == null) {
powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy"); powerObjective = getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy", DISPLAY_NAME);
powerObjective.setDisplayName(TAG_POWER_LEVEL); powerObjective.setDisplayName(TAG_POWER_LEVEL);
powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME); powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
} }
@ -409,6 +507,11 @@ public class ScoreboardManager {
return powerObjective; return powerObjective;
} }
public @Nullable static org.bukkit.scoreboard.ScoreboardManager getScoreboardManager() {
return mcMMO.p.getServer().getScoreboardManager();
}
private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) { private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) {
if (displayTime == -1) { if (displayTime == -1) {
wrapper.showBoardWithNoRevert(); wrapper.showBoardWithNoRevert();
@ -433,4 +536,16 @@ public class ScoreboardManager {
public static void setRevertTimer(String playerName, int seconds) { public static void setRevertTimer(String playerName, int seconds) {
PLAYER_SCOREBOARDS.get(playerName).showBoardAndScheduleRevert(seconds * Misc.TICK_CONVERSION_FACTOR); PLAYER_SCOREBOARDS.get(playerName).showBoardAndScheduleRevert(seconds * Misc.TICK_CONVERSION_FACTOR);
} }
public static @Nullable ScoreboardWrapper makeNewScoreboard(Player player) {
if(getScoreboardManager() == null)
return null;
//Call our custom event
Scoreboard scoreboard = getScoreboardManager().getNewScoreboard();
McMMOScoreboardMakeboardEvent event = new McMMOScoreboardMakeboardEvent(scoreboard, player.getScoreboard(), player, ScoreboardEventReason.CREATING_NEW_SCOREBOARD);
player.getServer().getPluginManager().callEvent(event);
//Use the values from the event
return new ScoreboardWrapper(event.getTargetPlayer(), event.getTargetBoard());
}
} }

View File

@ -6,7 +6,10 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.events.scoreboard.*; import com.gmail.nossr50.events.scoreboard.McMMOScoreboardObjectiveEvent;
import com.gmail.nossr50.events.scoreboard.McMMOScoreboardRevertEvent;
import com.gmail.nossr50.events.scoreboard.ScoreboardEventReason;
import com.gmail.nossr50.events.scoreboard.ScoreboardObjectiveEventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.child.FamilyTree; import com.gmail.nossr50.skills.child.FamilyTree;
@ -27,6 +30,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class ScoreboardWrapper { public class ScoreboardWrapper {
public static final String SIDE_OBJECTIVE = "mcMMO_sideObjective";
public static final String POWER_OBJECTIVE = "mcMMO_powerObjective";
// Initialization variables // Initialization variables
public final String playerName; public final String playerName;
public final Player player; public final Player player;
@ -46,13 +51,13 @@ public class ScoreboardWrapper {
private PlayerProfile targetProfile = null; private PlayerProfile targetProfile = null;
public int leaderboardPage = -1; public int leaderboardPage = -1;
private ScoreboardWrapper(Player player, Scoreboard scoreboard) { public ScoreboardWrapper(Player player, Scoreboard scoreboard) {
this.player = player; this.player = player;
this.playerName = player.getName(); this.playerName = player.getName();
this.scoreboard = scoreboard; this.scoreboard = scoreboard;
sidebarType = SidebarType.NONE; sidebarType = SidebarType.NONE;
sidebarObjective = this.scoreboard.registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy"); sidebarObjective = this.scoreboard.registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy", SIDE_OBJECTIVE);
powerObjective = this.scoreboard.registerNewObjective(ScoreboardManager.POWER_OBJECTIVE, "dummy"); powerObjective = this.scoreboard.registerNewObjective(ScoreboardManager.POWER_OBJECTIVE, "dummy", POWER_OBJECTIVE);
if (Config.getInstance().getPowerLevelTagsEnabled()) { if (Config.getInstance().getPowerLevelTagsEnabled()) {
powerObjective.setDisplayName(ScoreboardManager.TAG_POWER_LEVEL); powerObjective.setDisplayName(ScoreboardManager.TAG_POWER_LEVEL);
@ -64,14 +69,6 @@ public class ScoreboardWrapper {
} }
} }
public static ScoreboardWrapper create(Player player) {
//Call our custom event
McMMOScoreboardMakeboardEvent event = new McMMOScoreboardMakeboardEvent(mcMMO.p.getServer().getScoreboardManager().getNewScoreboard(), player.getScoreboard(), player, ScoreboardEventReason.CREATING_NEW_SCOREBOARD);
player.getServer().getPluginManager().callEvent(event);
//Use the values from the event
return new ScoreboardWrapper(event.getTargetPlayer(), event.getTargetBoard());
}
public BukkitTask updateTask = null; public BukkitTask updateTask = null;
private class ScoreboardQuickUpdate extends BukkitRunnable { private class ScoreboardQuickUpdate extends BukkitRunnable {
@ -158,16 +155,17 @@ public class ScoreboardWrapper {
return; return;
} }
Scoreboard oldBoard = player.getScoreboard(); Scoreboard previousBoard = player.getScoreboard();
if (oldBoard == scoreboard) { // Already displaying it if (previousBoard == scoreboard) { // Already displaying it
if (this.oldBoard == null) { if (this.oldBoard == null) {
// (Shouldn't happen) Use failsafe value - we're already displaying our board, but we don't have the one we should revert to // (Shouldn't happen) Use failsafe value - we're already displaying our board, but we don't have the one we should revert to
if(mcMMO.p.getServer().getScoreboardManager() != null)
this.oldBoard = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard(); this.oldBoard = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard();
} }
} }
else { else {
this.oldBoard = oldBoard; this.oldBoard = previousBoard;
} }
} }
@ -394,7 +392,7 @@ public class ScoreboardWrapper {
//Register objective //Register objective
McMMOScoreboardObjectiveEvent registerEvent = callObjectiveEvent(ScoreboardObjectiveEventReason.REGISTER_NEW_OBJECTIVE); McMMOScoreboardObjectiveEvent registerEvent = callObjectiveEvent(ScoreboardObjectiveEventReason.REGISTER_NEW_OBJECTIVE);
if(!registerEvent.isCancelled()) if(!registerEvent.isCancelled())
sidebarObjective = registerEvent.getTargetBoard().registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy"); sidebarObjective = registerEvent.getTargetBoard().registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy", SIDE_OBJECTIVE);
if (displayName.length() > 32) { if (displayName.length() > 32) {
displayName = displayName.substring(0, 32); displayName = displayName.substring(0, 32);