use of org.bukkit.scoreboard.Objective in project MassiveCore by MassiveCraft.
the class BoardUtil method setActiveInner.
// -------------------------------------------- //
// UPDATE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active) {
if (active) {
// We do not trigger an update here.
// We must wait for the first server tick.
// Otherwise the Scoreboard manager is null.
} else {
// We delete everything marked as temporary on deactivation.
List<Objective> objectives = new MassiveList<>(getTemporaryObjectives());
for (Objective objective : objectives) {
deleteObjective(objective);
}
List<Team> teams = new MassiveList<>(getTemporaryTeams());
for (Team team : teams) {
deleteTeam(team);
}
}
}
use of org.bukkit.scoreboard.Objective in project Village_Defense by Plajer.
the class ArenaUtils method updateScoreboard.
public static void updateScoreboard(Arena arena) {
if (arena.getPlayers().size() == 0)
return;
for (Player p : arena.getPlayers()) {
User user = UserManager.getUser(p.getUniqueId());
if (user.getScoreboard().getObjective("vd_state_0") == null) {
for (ArenaState state : ArenaState.values()) {
user.getScoreboard().registerNewObjective("vd_state_" + state.ordinal(), "dummy");
}
// fighting stage of IN_GAME state
user.getScoreboard().registerNewObjective("vd_state_2F", "dummy");
}
if (arena.getArenaState() == ArenaState.ENDING) {
user.removeScoreboard();
return;
}
Objective gameObjective;
if (arena.getArenaState() == ArenaState.IN_GAME) {
gameObjective = user.getScoreboard().getObjective("vd_state_" + arena.getArenaState().ordinal() + (arena.isFighting() ? "F" : ""));
} else {
gameObjective = user.getScoreboard().getObjective("vd_state_" + arena.getArenaState().ordinal());
}
if (gameObjective == null)
return;
gameObjective.setDisplayName(ChatManager.colorMessage("Scoreboard.Header"));
gameObjective.setDisplaySlot(DisplaySlot.SIDEBAR);
switch(arena.getArenaState()) {
case WAITING_FOR_PLAYERS:
Score playersTotal1 = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Players")));
playersTotal1.setScore(arena.getPlayers().size());
Score neededPlayers2 = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Minimum-Players")));
neededPlayers2.setScore(arena.getMinimumPlayers());
break;
case STARTING:
Score timer = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Starting-In")));
timer.setScore(arena.getTimer());
Score playersTotal = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Players")));
playersTotal.setScore(arena.getPlayers().size());
Score neededPlayers = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Minimum-Players")));
neededPlayers.setScore(arena.getMinimumPlayers());
break;
case IN_GAME:
Score playersLeft = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Players-Left")));
playersLeft.setScore(arena.getPlayersLeft().size());
Score villagersLeft = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Villagers-Left")));
villagersLeft.setScore(arena.getVillagers().size());
Score orbs = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Orbs")));
orbs.setScore(user.getInt("orbs"));
if (arena.isFighting()) {
Score zombiesLeft = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Zombies-Left")));
zombiesLeft.setScore(arena.getZombiesLeft());
} else {
Score nextWaveIn = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Next-Wave-In")));
nextWaveIn.setScore(arena.getTimer());
}
Score rottenFlesh = gameObjective.getScore(ChatManager.formatMessage(arena, ChatManager.colorMessage("Scoreboard.Rotten-Flesh")));
rottenFlesh.setScore(arena.getRottenFlesh());
break;
case RESTARTING:
break;
default:
arena.setArenaState(ArenaState.WAITING_FOR_PLAYERS);
break;
}
Score empty = gameObjective.getScore("");
empty.setScore(-1);
Score footer = gameObjective.getScore(ChatManager.colorMessage("Scoreboard.Footer"));
footer.setScore(-2);
user.setScoreboard(user.getScoreboard());
}
}
use of org.bukkit.scoreboard.Objective in project Minigames by AddstarMC.
the class Team method addScore.
/**
* Adds a specific amount to the teams score.
*
* @param amount - The amount of points to add to the team
* @return The new score for the team.
*/
public int addScore(int amount) {
score += amount;
Objective obj = mgm.getScoreboardManager().getObjective(mgm.getName(false));
if (obj != null)
obj.getScore(getColoredDisplayName()).setScore(score);
return score;
}
use of org.bukkit.scoreboard.Objective in project Minigames by AddstarMC.
the class Minigame method setScore.
public void setScore(MinigamePlayer ply, int amount) {
if (sbManager == null) {
ScoreboardManager s = Minigames.getPlugin().getServer().getScoreboardManager();
if (s != null) {
sbManager = s.getNewScoreboard();
Minigames.getPlugin().getLogger().info("ScoreBoardManager was null - Created new Scoreboard - for:" + name);
} else {
Minigames.getPlugin().getLogger().warning("ScoreBoardManager is null is the WORLD loaded!!! - Could not set Score!!!");
return;
}
}
Objective o = sbManager.getObjective(getName(false));
if (o != null) {
o.getScore(ply.getName()).setScore(amount);
}
}
use of org.bukkit.scoreboard.Objective in project Denizen-For-Bukkit by DenizenScript.
the class ScoreboardCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
List<PlayerTag> viewers = (List<PlayerTag>) scriptEntry.getObject("viewers");
ListTag lines = scriptEntry.hasObject("lines") ? ListTag.valueOf(scriptEntry.getElement("lines").asString(), scriptEntry.getContext()) : new ListTag();
ElementTag action = scriptEntry.getElement("action");
ElementTag id = scriptEntry.getElement("id");
ElementTag objective = scriptEntry.getElement("objective");
ElementTag criteria = scriptEntry.getElement("criteria");
ElementTag score = scriptEntry.getElement("score");
ElementTag displaySlot = scriptEntry.getElement("displayslot");
ElementTag displayName = scriptEntry.getElement("displayname");
ElementTag renderType = scriptEntry.getElement("rendertype");
Action act = Action.valueOf(action.asString().toUpperCase());
boolean hadCriteria = criteria != null;
boolean hadDisplaySlot = displaySlot != null;
if (!hadCriteria) {
criteria = new ElementTag("dummy");
}
if (!hadDisplaySlot) {
displaySlot = new ElementTag("sidebar");
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, id, db("viewers", viewers), objective, lines, score, objective, displaySlot, criteria, displayName, renderType);
}
Scoreboard board = null;
// Get the main scoreboard by default
if (id.asString().equalsIgnoreCase("main")) {
board = ScoreboardHelper.getMain();
} else if (id.asString().equalsIgnoreCase("player")) {
board = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().getScoreboard();
} else {
// If this scoreboard already exists, get it
if (ScoreboardHelper.hasScoreboard(id.asString())) {
board = ScoreboardHelper.getScoreboard(id.asString());
} else // Else, create a new one if Action is ADD
if (act.equals(Action.ADD)) {
board = ScoreboardHelper.createScoreboard(id.asString());
}
}
// Don't progress if we ended up with a null board
if (board == null) {
Debug.echoError(scriptEntry, "Scoreboard " + id.asString() + " does not exist!");
return;
}
Objective obj;
if (act.equals(Action.ADD)) {
if (objective != null) {
// Try getting the objective from the board
obj = board.getObjective(objective.asString());
boolean existedAlready = obj != null;
// Create the objective if it does not already exist
if (obj == null) {
obj = board.registerNewObjective(objective.asString(), criteria.asString());
} else // recreate the objective
if (hadCriteria && !obj.getCriteria().equals(criteria.asString())) {
obj.unregister();
obj = board.registerNewObjective(objective.asString(), criteria.asString());
}
// Change the objective's display slot
if ((!existedAlready || hadDisplaySlot) && !displaySlot.asString().equalsIgnoreCase("none")) {
obj.setDisplaySlot(DisplaySlot.valueOf(displaySlot.asString().toUpperCase()));
}
if (renderType != null) {
obj.setRenderType(RenderType.valueOf(renderType.asString().toUpperCase()));
}
if (displayName != null) {
obj.setDisplayName(displayName.asString());
} else if (!existedAlready) {
obj.setDisplayName(objective.asString());
}
if (!lines.isEmpty()) {
// use a score of 0
if (score == null) {
score = new ElementTag(0);
}
for (ObjectTag line : lines.objectForms) {
ScoreboardHelper.addScore(obj, checkLine(line), score.asInt());
}
}
} else // the command cannot do anything at all, so print a message about that
if (viewers == null && !lines.isEmpty()) {
Debug.echoDebug(scriptEntry, "Cannot add lines without specifying an objective!");
}
} else if (act.equals(Action.REMOVE)) {
if (objective != null) {
// Try getting the objective from the board
obj = board.getObjective(objective.asString());
if (obj != null) {
// Remove the entire objective if no lines have been specified
if (lines.isEmpty()) {
Debug.echoDebug(scriptEntry, "Removing objective " + obj.getName() + " from scoreboard " + id.asString());
obj.unregister();
} else {
for (ObjectTag line : lines.objectForms) {
ScoreboardHelper.removeScore(obj, checkLine(line));
}
}
} else {
Debug.echoError(scriptEntry, "Objective " + objective.asString() + " does not exist in scoreboard " + id.asString());
}
} else // lines from every objective
if (!lines.isEmpty()) {
Debug.echoDebug(scriptEntry, "Removing lines " + lines.identify() + " from all objectives in scoreboard " + id.asString());
for (ObjectTag line : lines.objectForms) {
ScoreboardHelper.removePlayer(id.asString(), checkLine(line));
}
} else // of viewers should be removed instead)
if (viewers == null) {
Debug.echoDebug(scriptEntry, "Removing scoreboard " + id.asString());
ScoreboardHelper.deleteScoreboard(id.asString());
}
}
if (viewers != null) {
for (PlayerTag viewer : viewers) {
// Add viewers for this scoreboard
if (act.equals(Action.ADD)) {
// to the map of viewers saved by Denizen
if (!id.asString().equalsIgnoreCase("main")) {
ScoreboardHelper.viewerMap.put(viewer.getUUID(), id.asString());
}
// is already online
if (viewer.isOnline()) {
viewer.getPlayerEntity().setScoreboard(board);
}
} else // Remove viewers for this scoreboard
if (act.equals(Action.REMOVE)) {
// Take this player out of the map of viewers
ScoreboardHelper.viewerMap.remove(viewer.getUUID());
// provided by Bukkit)
if (viewer.isOnline()) {
viewer.getPlayerEntity().setScoreboard(ScoreboardHelper.createScoreboard());
}
}
}
}
}
Aggregations