Java Code Examples for org.bukkit.scoreboard.Objective#setDisplaySlot()

The following examples show how to use org.bukkit.scoreboard.Objective#setDisplaySlot() . 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: UHPlugin.java    From KTP with GNU General Public License v3.0 6 votes vote down vote up
public void setMatchInfo() {
	Objective obj = null;
	try {
		obj = sb.getObjective(sbobjname);
		obj.setDisplaySlot(null);
		obj.unregister();
	} catch (Exception e) {
		
	}
	Random r = new Random();
	sbobjname = "KTP"+r.nextInt(10000000);
	obj = sb.registerNewObjective(sbobjname, "dummy");
	obj = sb.getObjective(sbobjname);

	obj.setDisplayName(this.getScoreboardName());
	obj.setDisplaySlot(DisplaySlot.SIDEBAR);
	obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GRAY+"Episode "+ChatColor.WHITE+episode)).setScore(5);
	obj.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE+""+Bukkit.getServer().getOnlinePlayers().size()+ChatColor.GRAY+" joueurs")).setScore(4);
	obj.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE+""+getAliveTeams().size()+ChatColor.GRAY+" teams")).setScore(3);
	obj.getScore(Bukkit.getOfflinePlayer("")).setScore(2);
	obj.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE+formatter.format(this.minutesLeft)+ChatColor.GRAY+":"+ChatColor.WHITE+formatter.format(this.secondsLeft))).setScore(1);
}
 
Example 2
Source File: EffNameOfScore.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(Event evt) {

    for (Player p : players.getArray(evt)) {
        if (!(p.isOnline())) {
            Skript.error("The player is not online!");
            continue;
        }
        try {
            if (p.getScoreboard().getObjective("sidebarHold") != null) {
                Objective objective = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR);
                objective.setDisplayName(name.getSingle(evt).replace("\"", ""));
            } else {
                Objective objectiveh = p.getScoreboard().registerNewObjective("sidebarHold", "dummy");
                objectiveh.setDisplaySlot(DisplaySlot.SIDEBAR);
                objectiveh.setDisplayName(name.getSingle(evt).replace("\"", ""));
            }
        } catch (IllegalArgumentException e){
            Skript.error(e.getLocalizedMessage());
        }
    }
}
 
Example 3
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void updateScoreboard() {
    if (!getOriginalOrInheritedScoreaboard()) {
        return;
    }

    Objective obj = this.gameScoreboard.getObjective("display");
    if (obj == null) {
        obj = this.gameScoreboard.registerNewObjective("display", "dummy");
    }

    obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    obj.setDisplayName(this.formatScoreboardTitle());

    for (CurrentTeam team : teamsInGame) {
        this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, false));
        this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, true));
        this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, true, false));

        Score score = obj.getScore(this.formatScoreboardTeam(team, !team.isBed, team.isBed && "RESPAWN_ANCHOR".equals(team.teamInfo.bed.getBlock().getType().name()) && Player116ListenerUtils.isAnchorEmpty(team.teamInfo.bed.getBlock())));
        score.setScore(team.players.size());
    }

    for (GamePlayer player : players) {
        player.player.setScoreboard(gameScoreboard);
    }
}
 
Example 4
Source File: GScoreboard.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get any scoreboard by world
 * - Note: players should use their associated-world (not current-world)
 */
private Scoreboard getScoreboard(UUID worldId, boolean isCreateIfNotFound) {
    Scoreboard scoreboard = null;
    if (ClimateEngine.getInstance().isClimateEngineEnabled(worldId)) {
        if (scoreboards.containsKey(worldId)) {
            //Existing scoreboard:
            scoreboard = scoreboards.get(worldId);
        } else if (isCreateIfNotFound) {
            //New scoreboard:
            scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            scoreboards.put(worldId, scoreboard);

            //Objective (scoreboard title / group):
            Objective objective = scoreboard.registerNewObjective(
                    GLOBAL_WARMING,
                    "scores",
                    "Carbon Score");

            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
        }
    }

    return scoreboard;
}
 
Example 5
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void updateScoreboard() {
    if (!getOriginalOrInheritedScoreaboard()) {
        return;
    }

    Objective obj = this.gameScoreboard.getObjective("display");
    if (obj == null) {
        obj = this.gameScoreboard.registerNewObjective("display", "dummy");
    }

    obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    obj.setDisplayName(this.formatScoreboardTitle());

    for (CurrentTeam team : teamsInGame) {
        this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, false));
        this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, true));
        this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, true, false));

        Score score = obj.getScore(this.formatScoreboardTeam(team, !team.isBed, team.isBed && "RESPAWN_ANCHOR".equals(team.teamInfo.bed.getBlock().getType().name()) && Player116ListenerUtils.isAnchorEmpty(team.teamInfo.bed.getBlock())));
        score.setScore(team.players.size());
    }

    for (GamePlayer player : players) {
        player.player.setScoreboard(gameScoreboard);
    }
}
 
Example 6
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 7
Source File: PlayerStat.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public static void getScoreboard(Player player) {
	Scoreboard scoreboard = scoreboards.get(player);
	if (scoreboard != null) {
           resetScoreboard(player);
       }
	ScoreboardManager manager = SkyWarsReloaded.get().getServer().getScoreboardManager();
	scoreboard = manager.getNewScoreboard();
       Objective objective = scoreboard.registerNewObjective("info", "dummy");
       objective.setDisplaySlot(DisplaySlot.SIDEBAR);
       scoreboards.put(player, scoreboard);
	updateScoreboard(player);
}
 
Example 8
Source File: PlayerStat.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private static void getScoreboard(Player player) {
	Scoreboard scoreboard = scoreboards.get(player);
	if (scoreboard != null) {
           resetScoreboard(player);
       }
	ScoreboardManager manager = SkyWarsReloaded.get().getServer().getScoreboardManager();
	scoreboard = manager.getNewScoreboard();
       Objective objective = SkyWarsReloaded.getNMS().getNewObjective(scoreboard, "dummy", "info");
       objective.setDisplaySlot(DisplaySlot.SIDEBAR);
       scoreboards.put(player, scoreboard);
	updateScoreboard(player);
}
 
Example 9
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public void updateScoreboard() {
  if (this.state == GameState.WAITING
      && BedwarsRel.getInstance().getBooleanConfig("lobby-scoreboard.enabled", true)) {
    this.updateLobbyScoreboard();
    return;
  }

  Objective obj = this.scoreboard.getObjective("display");
  if (obj == null) {
    obj = this.scoreboard.registerNewObjective("display", "dummy");
  }

  obj.setDisplaySlot(DisplaySlot.SIDEBAR);
  obj.setDisplayName(this.formatScoreboardTitle());

  for (Team t : this.teams.values()) {
    this.scoreboard.resetScores(this.formatScoreboardTeam(t, false));
    this.scoreboard.resetScores(this.formatScoreboardTeam(t, true));

    boolean teamDead = (t.isDead(this) && this.getState() == GameState.RUNNING) ? true : false;
    Score score = obj.getScore(this.formatScoreboardTeam(t, teamDead));
    score.setScore(t.getPlayers().size());
  }

  for (Player player : this.getPlayers()) {
    player.setScoreboard(this.scoreboard);
  }
}
 
Example 10
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
private void updateLobbyScoreboard() {
  this.scoreboard.clearSlot(DisplaySlot.SIDEBAR);

  Objective obj = this.scoreboard.getObjective("lobby");
  if (obj != null) {
    obj.unregister();
  }

  obj = this.scoreboard.registerNewObjective("lobby", "dummy");
  obj.setDisplaySlot(DisplaySlot.SIDEBAR);
  obj.setDisplayName(this.formatLobbyScoreboardString(
      BedwarsRel.getInstance().getStringConfig("lobby-scoreboard.title", "&eBEDWARS")));

  List<String> rows = BedwarsRel.getInstance().getConfig()
      .getStringList("lobby-scoreboard.content");
  int rowMax = rows.size();
  if (rows == null || rows.isEmpty()) {
    return;
  }

  for (String row : rows) {
    if (row.trim().equals("")) {
      for (int i = 0; i <= rowMax; i++) {
        row = row + " ";
      }
    }

    Score score = obj.getScore(this.formatLobbyScoreboardString(row));
    score.setScore(rowMax);
    rowMax--;
  }

  for (Player player : this.getPlayers()) {
    player.setScoreboard(this.scoreboard);
  }
}
 
Example 11
Source File: Game.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public void Scoreboard(Player player) {
       ScoreboardManager manager = Bukkit.getScoreboardManager();
       Scoreboard board = manager.getNewScoreboard();
       
       Objective objective = board.registerNewObjective("test", "dummy");
       objective.setDisplaySlot(DisplaySlot.SIDEBAR);
       objective.setDisplayName("Scoreboard");
       objective.getName();
       
       Score score = objective.getScore(ChatColor.GREEN + "Kills:"); //Get a fake offline player
       score.setScore(1);
}
 
Example 12
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 13
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateLobbyScoreboard() {
    if (status != GameStatus.WAITING || !getOriginalOrInheritedLobbyScoreaboard()) {
        return;
    }
    gameScoreboard.clearSlot(DisplaySlot.SIDEBAR);

    Objective obj = gameScoreboard.getObjective("lobby");
    if (obj != null) {
        obj.unregister();
    }

    obj = gameScoreboard.registerNewObjective("lobby", "dummy");
    obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    obj.setDisplayName(this.formatLobbyScoreboardString(
            Main.getConfigurator().config.getString("lobby-scoreboard.title", "§eBEDWARS")));

    List<String> rows = Main.getConfigurator().config.getStringList("lobby-scoreboard.content");
    int rowMax = rows.size();
    if (rows == null || rows.isEmpty()) {
        return;
    }

    for (String row : rows) {
        if (row.trim().equals("")) {
            for (int i = 0; i <= rowMax; i++) {
                row = row + " ";
            }
        }

        Score score = obj.getScore(this.formatLobbyScoreboardString(row));
        score.setScore(rowMax);
        rowMax--;
    }

    for (GamePlayer player : players) {
        player.player.setScoreboard(gameScoreboard);
    }
}
 
Example 14
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 15
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateLobbyScoreboard() {
    if (status != GameStatus.WAITING || !getOriginalOrInheritedLobbyScoreaboard()) {
        return;
    }
    gameScoreboard.clearSlot(DisplaySlot.SIDEBAR);

    Objective obj = gameScoreboard.getObjective("lobby");
    if (obj != null) {
        obj.unregister();
    }

    obj = gameScoreboard.registerNewObjective("lobby", "dummy");
    obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    obj.setDisplayName(this.formatLobbyScoreboardString(
            Main.getConfigurator().config.getString("lobby-scoreboard.title", "§eBEDWARS")));

    List<String> rows = Main.getConfigurator().config.getStringList("lobby-scoreboard.content");
    int rowMax = rows.size();
    if (rows == null || rows.isEmpty()) {
        return;
    }

    for (String row : rows) {
        if (row.trim().equals("")) {
            for (int i = 0; i <= rowMax; i++) {
                row = row + " ";
            }
        }

        Score score = obj.getScore(this.formatLobbyScoreboardString(row));
        score.setScore(rowMax);
        rowMax--;
    }

    for (GamePlayer player : players) {
        player.player.setScoreboard(gameScoreboard);
    }
}
 
Example 16
Source File: PlayerListHealthCommand.java    From UHC with MIT License 4 votes vote down vote up
@Override
protected boolean runCommand(CommandSender sender, OptionSet options) {
    final String objectiveName = nameSpec.value(options);
    final boolean force = options.has(forceSpec);
    final DisplaySlot slot = slotSpec.value(options);

    Objective objective = scoreboard.getObjective(objectiveName);

    // unregister the current objective if it exists and we want to force remake it
    if (objective != null && force) {
        sender.sendMessage(messages.evalTemplate("unregistered", ImmutableMap.of("name", objective.getName())));
        objective.unregister();
        objective = null;
    }

    // register the objective
    if (objective == null) {
        objective = scoreboard.registerNewObjective(objectiveName, "health");

        // add all online player manually
        for (final Player player : Bukkit.getOnlinePlayers()) {
            objective.getScore(player.getName()).setScore((int) Math.ceil(player.getHealth()));
        }
    }

    // set display name if needed
    if (options.has(displayNameSpec)) {
        objective.setDisplayName(
                ChatColor.translateAlternateColorCodes('&', displayNameSpec.value(options)).replace("&h", "♥")
        );
    }

    // set the slot to render in
    objective.setDisplaySlot(slot);

    sender.sendMessage(messages.evalTemplate(
            "assigned",
            ImmutableMap.of(
                    "name", objective.getName(),
                    "display", objective.getDisplayName(),
                    "slot", objective.getDisplaySlot().name()
            )
    ));
    return true;
}
 
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());
	}
}