Java Code Examples for org.bukkit.scoreboard.Scoreboard#getObjective()

The following examples show how to use org.bukkit.scoreboard.Scoreboard#getObjective() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlagTeamScoreboard.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onTeamScoreboardInitialize(TeamScoreboardInitializeEvent event) {
	FlagTeam flag = (FlagTeam) getParent();
	Scoreboard board = flag.getScoreboard();
	
	if (board == null) {
		return;
	}
	
	FlagScoreboard.GetScoreboardDisplayNameEvent getDisplayNameEvent = new FlagScoreboard.GetScoreboardDisplayNameEvent();
	game.getEventBus().callEvent(getDisplayNameEvent);
	String displayName = getDisplayNameEvent.getDisplayName();
	
	objective = board.getObjective(FlagTeam.OBJECTIVE_NAME);
	objective.setDisplayName(displayName);
	objective.setDisplaySlot(DisplaySlot.SIDEBAR);
}
 
Example 2
Source File: GScoreboard.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Update the global score for all worlds
 */
private void updateGlobalScores() {
    for (World world : Bukkit.getWorlds()) {
        //Do not update worlds with disabled climate-engines:
        WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(world.getUID());
        if (climateEngine != null && climateEngine.isEnabled()) {
            //Get the scoreboard for this world:
            Scoreboard scoreboard = getScoreboard(world.getUID(), false);

            //Get its objective (scoreboard title / group):
            Objective objective = null;
            if (scoreboard != null) {
                objective = scoreboard.getObjective(GLOBAL_WARMING);
            }

            //Update the title to show this world's temperature:
            if (objective != null) {
                double temperature = climateEngine.getTemperature();
                objective.setDisplayName(climateEngine.formatTemp(temperature));
            }
        }
    }
}
 
Example 3
Source File: GScoreboard.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Display a player's score
 * - Uses the player's associated-world scoreboard
 * - Note: the player may be in a different world, that's ok
 * - Player names are mapped to color warmth (based on their score)
 */
private void updatePlayerScore(GPlayer gPlayer) {
    if (gPlayer != null) {
        //Do not update associated-worlds with disabled climate-engines:
        // - Ignore offline players (e.g., someone completing an offline player's bounty)
        Player onlinePlayer = gPlayer.getOnlinePlayer();
        if (onlinePlayer != null && ClimateEngine.getInstance().isClimateEngineEnabled(gPlayer.getAssociatedWorldId())) {
            //Update the player's score:
            Scoreboard scoreboard = getScoreboard(gPlayer);
            if (scoreboard != null) {
                Objective objective = scoreboard.getObjective(GLOBAL_WARMING);
                if (objective != null) {
                    Team team = scoreboard.getPlayerTeam(onlinePlayer);
                    if (team != null) {
                        team.setColor(Colorizer.getScoreColor(gPlayer.getCarbonScore()));
                        objective.getScore(onlinePlayer).setScore(gPlayer.getCarbonScore());
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: Dummy.java    From FunnyGuilds with Apache License 2.0 6 votes vote down vote up
public void updateScore(User user) {
    if (! FunnyGuilds.getInstance().getPluginConfiguration().dummyEnable) {
        return;
    }

    Scoreboard scoreboard = this.user.getCache().getScoreboard();

    if (scoreboard == null) {
        FunnyGuilds.getInstance().getPluginLogger().debug(
                "We're trying to update Dummy score but scoreboard hasn't been initialized yet" +
                        "(maybe player left the game while updating?)");
        return;
    }

    Objective objective = scoreboard.getObjective(OBJECTIVE_NAME);

    if (objective == null || ! objective.getName().equals(OBJECTIVE_NAME)) {
        this.initialize();
    } else {
        objective.getScore(user.getName()).setScore(user.getRank().getPoints());
    }
}
 
Example 5
Source File: RaindropsListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setRaindropsCount(Player player, int count) {
    if(player == null) return;

    final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
    Objective objective = scoreboard.getObjective(player.getName());

    Integer oldCount = raindrops.get(player);
    if(oldCount != null) {
        Utils.removeScore(player, String.format("%,d", oldCount));
    }
    Utils.addScore(player, objective, String.format("%,d", count), 1);

    raindrops.put(player, count);

    Utils.giveGhastTear(player, count);
}
 
Example 6
Source File: ScoreBoardManager.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public void removeScoreboard(Player player) {
    UUID uuid = player.getUniqueId();
    CustomScoreBoard customScoreBoard = this.customScoreBoardMap.remove(uuid);
    if(customScoreBoard == null) return;
    
    customScoreBoard.disableScoreboard();
    if(shouldSavePrevious() && this.previousScoreboardMap.containsKey(uuid)) {
        Scoreboard previousScoreboard = this.previousScoreboardMap.get(uuid);
        if(previousScoreboard == null) return;
        
        Objective objective = previousScoreboard.getObjective("combatlogx");
        if(objective != null) return;
        
        player.setScoreboard(previousScoreboard);
    }
}
 
Example 7
Source File: EffSetScore.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(Event evt) {
    if (player == null || num == null || player.getSingle(evt).getScoreboard() == null) {
        Skript.error("This player is either not online or has yet to have a scoreboard set for them");
        return;
    }
    Scoreboard sb = player.getSingle(evt).getScoreboard();
    Objective objective = sb.getObjective(DisplaySlot.SIDEBAR);
    Score score;
    if (name.getSingle(evt) == null){
        Skript.warning("First arg in \"set score %string% in sidebar of %player% to %number%\" was null. " +
                "Objective will now be named null.");
        score = objective.getScore("null");
    } else {
        score = objective.getScore(name.getSingle(evt).replace("\"", ""));
    }
    score.setScore(num.getSingle(evt).intValue());
}
 
Example 8
Source File: ScoreBoardManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private void enableScoreboard(Player player) {
    if(isDisabledGlobally()) return;
    if(isDisabled(player)) return;
    
    UUID uuid = player.getUniqueId();
    if(shouldSavePrevious() && !this.previousScoreboardMap.containsKey(uuid)) {
        Scoreboard previousScoreboard = player.getScoreboard();
        Objective objective = previousScoreboard.getObjective("combatlogx");
        if(objective == null) this.previousScoreboardMap.put(uuid, previousScoreboard);
    }
    
    CustomScoreBoard customScoreBoard = this.customScoreBoardMap.getOrDefault(uuid, new CustomScoreBoard(this.expansion, player));
    this.customScoreBoardMap.put(uuid, customScoreBoard);
    customScoreBoard.enableScoreboard();
}
 
Example 9
Source File: ScoreComponent.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getValue(String locale) {
	String value = forcedvalue;
	if (value == null) {
		Player player = Bukkit.getPlayerExact(playername);
		if (player != null) {
			Scoreboard board = player.getScoreboard();
			Objective objective = board.getObjective(objectivename);
			if (objective != null) {
				value = String.valueOf(objective.getScore(playername).getScore());
			}
		}
	}
	return value != null ? value : "";
}
 
Example 10
Source File: EffSetIdBasedScore.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    if (player == null || num == null || name == null
            || player.getSingle(evt).getScoreboard() == null) {
        Skript.error("This player is either not online or has yet to have a scoreboard set for them");
    } else {
        Scoreboard sb = player.getSingle(evt).getScoreboard();
        Objective objective = sb.getObjective(DisplaySlot.SIDEBAR);
        Score score = objective.getScore(name.getSingle(evt).replace("\"", ""));
        score.setScore(num.getSingle(evt).intValue());
        Core.sbManager.setScoreId(id.getSingle(evt).replace("\"", ""), score, player.getSingle(evt));
    }
}
 
Example 11
Source File: ScoreboardEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void execute(String playerID) throws IllegalStateException, QuestRuntimeException {
    Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
    Objective obj = board.getObjective(objective);
    if (obj == null) {
        throw new QuestRuntimeException("Scoreboard objective " + objective + " does not exist!");
    }
    Score score = obj.getScore(PlayerConverter.getName(playerID));
    if (multi) {
        score.setScore((int) Math.floor(score.getScore() * count.getDouble(playerID)));
    } else {
        score.setScore((int) Math.floor(score.getScore() + count.getDouble(playerID)));
    }
    return null;
}
 
Example 12
Source File: ScoreboardCondition.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Boolean execute(String playerID) throws QuestRuntimeException {
    Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
    Objective obj = board.getObjective(objective);
    if (obj == null) {
        throw new QuestRuntimeException("Scoreboard objective " + objective + " does not exist!");
    }
    Score score = obj.getScore(PlayerConverter.getName(playerID));
    return score.getScore() >= count.getInt(playerID);
}
 
Example 13
Source File: AssembleBoard.java    From Assemble with GNU General Public License v3.0 5 votes vote down vote up
public Objective getObjective() {
	Scoreboard scoreboard = getScoreboard();
	if (scoreboard.getObjective("Assemble") == null) {
		Objective objective = scoreboard.registerNewObjective("Assemble", "dummy");
		objective.setDisplaySlot(DisplaySlot.SIDEBAR);
		objective.setDisplayName(getAssemble().getAdapter().getTitle(Bukkit.getPlayer(getUuid())));
		return objective;
	} else {
		return scoreboard.getObjective("Assemble");
	}
}
 
Example 14
Source File: TpsPingTask.java    From NyaaUtils with MIT License 5 votes vote down vote up
public TpsPingTask(NyaaUtils plugin) {
    this.plugin = plugin;
    Scoreboard mainScoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
    Objective pingObj = mainScoreboard.getObjective("nyaautilsping");
    if (plugin.cfg.ping_tab) {
        if (pingObj == null) {
            pingObj = mainScoreboard.registerNewObjective("nyaautilsping", "dummy", "Ping");
        }
        pingObj.setDisplaySlot(DisplaySlot.PLAYER_LIST);
    } else if (pingObj != null) {
        pingObj.setDisplaySlot(null);
    }
}
 
Example 15
Source File: RaindropsListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Objective getOrCreateObjective(Scoreboard scoreboard, String name, String criteria) {
    Objective obj = scoreboard.getObjective(name);
    if(obj == null) {
        obj = scoreboard.registerNewObjective(name, criteria);
    }
    return obj;
}
 
Example 16
Source File: GScoreboard.java    From GlobalWarming with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Show or hide the scoreboard (UI)
 */
public void show(GPlayer gPlayer, boolean isVisible) {
    if (!isEnabled) {
        return;
    }
    Scoreboard scoreboard = getScoreboard(gPlayer);
    if (isVisible) {
        Objective objective = scoreboard.getObjective(GLOBAL_WARMING);
        if (objective != null) {
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
        }
    } else {
        scoreboard.clearSlot(DisplaySlot.SIDEBAR);
    }
}
 
Example 17
Source File: TagUtils.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Refreshes tag of a player
 *
 * @param p target player
 */
@SuppressWarnings("deprecation")
public static void refresh(Player p) {
	if(!Config.TAGAPI_ENABLED.getBoolean()) {
		return;
	}

	Scoreboard board = p.getScoreboard();
	for(Player player : CompatibilityUtils.getOnlinePlayers()) {
		NovaPlayer nPlayerLoop = PlayerManager.getPlayer(player);

		String tName = "ng_" + player.getName();
		if(tName.length() > 16) {
			tName = tName.substring(0, 16);
		}

		Team team = board.getTeam(tName);

		if(team == null) {
			team = board.registerNewTeam(tName);
			team.addPlayer(player);
		}

		//Points
		Objective pointsObjective = board.getObjective("points");
		if(Config.POINTSBELOWNAME.getBoolean()) {
			if(pointsObjective == null) {
				pointsObjective = board.registerNewObjective("points", "dummy");
				pointsObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
				pointsObjective.setDisplayName(Message.MISC_POINTSBELOWNAME.get());
			}

			Score score = pointsObjective.getScore(player);
			score.setScore(nPlayerLoop.getPoints());
		}
		else if(pointsObjective != null) {
			pointsObjective.unregister();
		}

		//set tag
		PreparedTag tag = new PreparedTagScoreboardImpl(PlayerManager.getPlayer(player));
		tag.setTagColorFor(PlayerManager.getPlayer(p));
		team.setPrefix(tag.get());
	}
}