Java Code Examples for org.bukkit.scoreboard.Team#getPlayers()
The following examples show how to use
org.bukkit.scoreboard.Team#getPlayers() .
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 |
@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: ClearTeamsCommand.java From UHC with MIT License | 6 votes |
@Override protected boolean runCommand(CommandSender sender, OptionSet options) { Collection<Team> teams = teamSpec.values(options); if (teams.size() == 0) { teams = options.has(allSpec) ? module.getScoreboard().getTeams() : module.getTeams().values(); } int count = 0; for (final Team team : teams) { for (final OfflinePlayer player : team.getPlayers()) { team.removePlayer(player); count++; } } sender.sendMessage(messages.evalTemplate("cleared", ImmutableMap.of("teams", teams.size(), "players", count))); return true; }
Example 3
Source File: TeamCoordinatesCommand.java From UHC with MIT License | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(messages.getRaw("players only")); return true; } final Player player = (Player) sender; final Team team = module.getScoreboard().getPlayerTeam(player); if (team == null) { sender.sendMessage(messages.getRaw("not in team")); return true; } final Location loc = player.getLocation(); final Map<String, String> context = ImmutableMap.<String, String>builder() .put("name", player.getName()) .put("display name", player.getDisplayName()) .put("world", loc.getWorld().getName()) .put("x", String.valueOf(loc.getBlockX())) .put("y", String.valueOf(loc.getBlockY())) .put("z", String.valueOf(loc.getBlockZ())) .build(); final String message = messages.evalTemplate("format", context); for (final OfflinePlayer p : team.getPlayers()) { if (p.isOnline()) { p.getPlayer().sendMessage(message); } } return true; }
Example 4
Source File: ListTeamsCommand.java From UHC with MIT License | 4 votes |
@Override protected boolean runCommand(CommandSender sender, OptionSet options) { final int page = pageSpec.value(options); final boolean emptyOnly = options.has(emptyOnlySpec); final boolean showAll = options.has(showAllSpec); if (showAll && emptyOnly) { sender.sendMessage(ChatColor.RED + "You must provide -e OR -a, you cannot supply both"); return true; } final Predicate<Team> predicate; final String type; if (emptyOnly) { type = "(empty teams)"; predicate = Predicates.not(FunctionalUtil.TEAMS_WITH_PLAYERS); } else if (showAll) { type = "(all teams)"; predicate = Predicates.alwaysTrue(); } else { type = "(with players)"; predicate = FunctionalUtil.TEAMS_WITH_PLAYERS; } final List<Team> teams = Lists.newArrayList(Iterables.filter(teamModule.getTeams().values(), predicate)); if (teams.size() == 0) { sender.sendMessage(ChatColor.RED + "No results found for query " + type); return true; } final List<List<Team>> partitioned = Lists.partition(teams, COUNT_PER_PAGE); if (page > partitioned.size()) { sender.sendMessage(ChatColor.RED + "Page " + page + " does not exist"); return true; } final List<Team> pageItems = partitioned.get(page - 1); final Map<String, Object> context = ImmutableMap.<String, Object>builder() .put("page", page) .put("pages", partitioned.size()) .put("type", type) .put("count", pageItems.size()) .put("teams", teams.size()) .put("multiple", partitioned.size() > 1) .build(); sender.sendMessage(messages.evalTemplate("header", context)); final Joiner joiner = Joiner.on(", "); for (final Team team : pageItems) { final String memberString; final Set<OfflinePlayer> members = team.getPlayers(); if (members.size() == 0) { memberString = NO_MEMBERS; } else { memberString = joiner.join(Iterables.transform(team.getPlayers(), FunctionalUtil.PLAYER_NAME_FETCHER)); } sender.sendMessage( String.format(FORMAT, team.getPrefix() + team.getDisplayName(), team.getName(), memberString) ); } return true; }