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

The following examples show how to use org.bukkit.scoreboard.Objective#unregister() . 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: 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 3
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 4
Source File: Lobby.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setupScoreboard() {
    Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
    for(Team team : scoreboard.getTeams()) {
        team.unregister();
    }
    for(Objective objective : scoreboard.getObjectives()) {
        objective.unregister();
    }
}
 
Example 5
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 6
Source File: PlayerStat.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private static void resetScoreboard(Player player) {
	Scoreboard scoreboard = scoreboards.get(player);
	for (Objective objective: scoreboard.getObjectives()) {
    	if (objective != null) {
            objective.unregister();
        }
	}
}
 
Example 7
Source File: PlayerStat.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private static void resetScoreboard(Player player) {
	Scoreboard scoreboard = scoreboards.get(player);
	for (Objective objective: scoreboard.getObjectives()) {
    	if (objective != null) {
            objective.unregister();
        }
	}
    
    if (scoreboard != null) {
        scoreboard = null;
    }
}
 
Example 8
Source File: RaindropsListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler
public void playerQuit(final PlayerQuitEvent event) {
    Objective objective = Bukkit.getScoreboardManager().getMainScoreboard().getObjective(event.getPlayer().getName());
    if(objective != null) objective.unregister();
    raindrops.remove(event.getPlayer());
}
 
Example 9
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 10
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());
	}
}