Java Code Examples for org.bukkit.scoreboard.Team#addPlayer()

The following examples show how to use org.bukkit.scoreboard.Team#addPlayer() . 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: TeamAddCommand.java    From UHC with MIT License 6 votes vote down vote up
@Override
protected boolean runCommand(CommandSender sender, OptionSet options) {
    final Team team = teamSpec.value(options);
    final Set<OfflinePlayer> players = Sets.newHashSet(playersSpec.values(options));
    players.removeAll(team.getPlayers());

    for (final OfflinePlayer player : players) {
        team.addPlayer(player);
    }

    final Set<OfflinePlayer> finalTeam = team.getPlayers();

    final String members = finalTeam.size() == 0
            ? ChatColor.DARK_GRAY + "No members"
            : Joiner.on(", ").join(Iterables.transform(team.getPlayers(), FunctionalUtil.PLAYER_NAME_FETCHER));

    sender.sendMessage(messages.evalTemplate(
            "added",
            ImmutableMap.of(
                    "count", players.size(),
                    "players", members
            )
    ));
    return false;
}
 
Example 2
Source File: Scoreboards.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Puts a player into a team of their own and sets the team suffix to be the level
 * @param playerUUID - the player's UUID
 */
public void setLevel(UUID playerUUID) {
    Player player = plugin.getServer().getPlayer(playerUUID);
    if (player == null) {
        // Player is offline...
        return;
    }
    // The default team name is their own name
    String teamName = player.getName();
    String level = String.valueOf(plugin.getPlayers().getIslandLevel(playerUUID));
    Team team = board.getTeam(teamName);
    if (team == null) {
        //Team does not exist
        team = board.registerNewTeam(teamName);
    }
    // Add the suffix
    team.setSuffix(Settings.teamSuffix.replace("[level]",String.valueOf(level)));
    //Adding player to team
    team.addPlayer(player);
    // Assign scoreboard to player
    player.setScoreboard(board);
}
 
Example 3
Source File: Scoreboards.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the player's level explicitly
 * @param playerUUID - the player's UUID
 * @param l
 */
public void setLevel(UUID playerUUID, long l) {
    Player player = plugin.getServer().getPlayer(playerUUID);
    if (player == null) {
        // Player is offline...
        return;
    }
    // The default team name is their own name - must be 16 chars or less
    String teamName = player.getName();
    Team team = board.getTeam(teamName);
    if (team == null) {
        //Team does not exist
        team = board.registerNewTeam(teamName);
    }
    // Add the suffix
    team.setSuffix(Settings.teamSuffix.replace("[level]",String.valueOf(l)));
    //Adding player to team
    team.addPlayer(player);
    // Assign scoreboard to player
    player.setScoreboard(board);
}
 
Example 4
Source File: ScoreboardMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Team createPartyScoreboardTeam(
    Party party, Scoreboard scoreboard, boolean forObservers) {
  match
      .getLogger()
      .fine("Creating team for party " + party + " on scoreboard " + toString(scoreboard));

  Team team = scoreboard.registerNewTeam(getScoreboardTeamName(party));
  updatePartyScoreboardTeam(party, team, forObservers);
  for (MatchPlayer player : party.getPlayers()) {
    team.addPlayer(player.getBukkit());
  }

  return team;
}
 
Example 5
Source File: ScoreboardMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Team createPartyScoreboardTeam(Party party, Scoreboard scoreboard, boolean forObservers) {
    logger.fine("Creating team for party " + party + " on scoreboard " + toString(scoreboard));

    Team team = scoreboard.registerNewTeam(getScoreboardTeamName(party));
    updatePartyScoreboardTeam(party, team, forObservers);
    for(MatchPlayer player : party.getPlayers()) {
        team.addPlayer(player.getBukkit());
    }

    return team;
}
 
Example 6
Source File: PlayerAppearanceChanger.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Sets a prefix for a player's overhead name by adding them to a scoreboard team.
 * Don't use this if scoreboard teams are being used for any other purpose.
 */
private static void setOverheadNamePrefix(Player player, String prefix) {
    final Scoreboard scoreboard = player.getServer().getScoreboardManager().getMainScoreboard();
    prefix = prefix.substring(0, Math.min(prefix.length(), 14));

    Team team = scoreboard.getTeam(prefix);
    if(team == null) {
        team = scoreboard.registerNewTeam(prefix);
        team.setPrefix(prefix);
        team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
    }
    team.addPlayer(player);
}
 
Example 7
Source File: TeamupCommand.java    From UHC with MIT License 4 votes vote down vote up
@Override
protected boolean runCommand(CommandSender sender, OptionSet options) {
    final List<OfflinePlayer> players = playersSpec.values(options);

    if (players.size() == 0) {
        sender.sendMessage(messages.getRaw("supply one player"));
        return true;
    }

    final Team team;
    // if they're specifying a team name to use
    if (options.has(teamNameSpec)) {
        final String teamName = teamNameSpec.value(options);

        team = teamModule.getScoreboard().getTeam(teamName);

        if (team == null) {
            sender.sendMessage(messages.evalTemplate("doesnt exist", ImmutableMap.of("name", teamName)));
            return true;
        }

        if (team.getPlayers().size() > 0) {
            sender.sendMessage(messages.getRaw("not empty"));
            return true;
        }
    } else {
        // grab the first UHC team available
        final Optional<Team> teamOptional = teamModule.findFirstEmptyTeam();

        if (!teamOptional.isPresent()) {
            sender.sendMessage(messages.getRaw("no uhc teams"));
            return true;
        }

        team = teamOptional.get();
    }

    final String members = Joiner.on(", ").join(Iterables.transform(players, FunctionalUtil.PLAYER_NAME_FETCHER));

    final Map<String, String> context = ImmutableMap.<String, String>builder()
            .put("prefix", team.getPrefix())
            .put("name", team.getName())
            .put("display name", team.getDisplayName())
            .put("players", members)
            .put("count", String.valueOf(players.size()))
            .build();

    final String teamNotification = messages.evalTemplate("teamup notification", context);

    for (final OfflinePlayer player : players) {
        team.addPlayer(player);

        if (player.isOnline()) {
            player.getPlayer().sendMessage(teamNotification);
        }
    }

    sender.sendMessage(messages.evalTemplate("completed", context));
    return true;
}
 
Example 8
Source File: RequestManager.java    From UHC with MIT License 4 votes vote down vote up
/**
 * Removes the request and processes the response.
 *
 * @param id the id of the request
 * @param accepted the state to set
 * @return true if id existed, false otherwise
 */
public boolean finalizeRequest(int id, AcceptState accepted) {
    final Optional<TeamRequest> optional = removeRequest(id);

    if (!optional.isPresent()) return false;

    final TeamRequest request = optional.get();

    final Map<String, Object> context = ImmutableMap.<String, Object>builder()
            .put("name", request.getOwnerName())
            .put("id", request.getId())
            .put("members", Joiner.on(", ").join(request.getOthers()))
            .build();

    broadcast(messages.evalTemplate("on." + accepted.name().toLowerCase() + ".broadcast", context));

    final Player player = Bukkit.getPlayer(request.getOwner());

    if (player != null) {
        player.sendMessage(messages.evalTemplate("on." + accepted.name().toLowerCase() + ".notify", context));
    }

    if (accepted == AcceptState.ACCEPT) {
        final Iterable<OfflinePlayer> players = Iterables.filter(
                Iterables.transform(
                        request.getOthers(),
                        FunctionalUtil.OFFLINE_PLAYER_FROM_NAME
                ),
                Predicates.notNull()
        );

        final Optional<Team> potentialTeam = module.findFirstEmptyTeam();

        if (!potentialTeam.isPresent()) {
            broadcast(messages.getRaw("no empty teams"));
            return true;
        }

        final Team team = potentialTeam.get();

        for (final OfflinePlayer p : players) {
            team.addPlayer(p);
            if (autoWhitelistAcceptedTeams) p.setWhitelisted(true);
        }

        final OfflinePlayer ownerOfflinePlayer = Bukkit.getOfflinePlayer(request.getOwner());
        team.addPlayer(ownerOfflinePlayer);

        if (autoWhitelistAcceptedTeams) {
            ownerOfflinePlayer.setWhitelisted(true);
        }
    }

    // otherwise do nothing
    return true;
}
 
Example 9
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());
	}
}