下面列出了org.bukkit.scoreboard.Team#setOption ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void updateTeamVariable(Scoreboard scoreboard, TagPlayerData playerData) {
Team entryTeam = TagUtils.getTeamComputeIfAbsent(scoreboard, playerData.getTeamHash());
if (!entryTeam.getEntries().contains(playerData.getNameDisplay())) {
entryTeam.addEntry(playerData.getNameDisplay());
}
if (entryTeam.getPrefix() == null || !entryTeam.getPrefix().equals(playerData.getPrefix())) {
entryTeam.setPrefix(playerData.getPrefix());
}
if (entryTeam.getSuffix() == null || !entryTeam.getSuffix().equals(playerData.getSuffix())) {
entryTeam.setSuffix(playerData.getSuffix());
}
Team.OptionStatus option = entryTeam.getOption(Team.Option.NAME_TAG_VISIBILITY);
if (option == Team.OptionStatus.ALWAYS && !playerData.isNameVisibility()) {
entryTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
} else if (option == Team.OptionStatus.NEVER && playerData.isNameVisibility()) {
entryTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
}
if (TabooLib.getConfig().getBoolean("TABLIST-AUTO-CLEAN-TEAM", true)) {
TagUtils.cleanEmptyTeamInScoreboard(scoreboard);
}
}
protected void updatePartyScoreboardTeam(Party party, Team team, boolean forObservers) {
logger.fine("Updating scoreboard team " + toString(team) + " for party " + party);
team.setDisplayName(party.getName());
team.setPrefix(party.getColor().toString());
team.setSuffix(ChatColor.WHITE.toString());
team.setCanSeeFriendlyInvisibles(true);
team.setAllowFriendlyFire(getMatch().getMapInfo().friendlyFire);
team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
if(!forObservers && party instanceof Competitor) {
Team.OptionStatus nameTags = ((Competitor) party).getNameTagVisibility();
// #HACK until this is fixed https://bugs.mojang.com/browse/MC-48730 we need to
// ensure enemy name tags are always hidden for GS.
if(getMatch().getMatchModule(GhostSquadronMatchModule.class) != null) {
switch(nameTags) {
case ALWAYS: nameTags = Team.OptionStatus.FOR_OWN_TEAM; break;
case FOR_OTHER_TEAMS: nameTags = Team.OptionStatus.NEVER; break;
}
}
team.setOption(Team.Option.NAME_TAG_VISIBILITY, nameTags);
} else {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
}
}
/**
* 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);
}
public void setCantPush(Player p) {
Team team = p.getScoreboard().getTeam("Vanished");
if (team == null) {
team = p.getScoreboard().registerNewTeam("Vanished");
}
try {
team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
team.addEntry(p.getName());
} catch (NoSuchMethodError | NoClassDefFoundError ignored) {
}
}
/**
* Handles push protection
* @param player
*/
public void setPush(Player player) {
scoreboard = player.getScoreboard();
if (scoreboard == null) {
//plugin.getLogger().info("1.9 " +"DEBUG: initializing scoreboard");
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
}
if (Settings.allowPushing) {
if (scoreboard.getTeam(NO_PUSH_TEAM_NAME) != null) {
//plugin.getLogger().info("1.9 " +"DEBUG: unregistering the team");
scoreboard.getTeam(NO_PUSH_TEAM_NAME).unregister();
}
return;
}
// Try and get what team the player is on right now
Team pushTeam = scoreboard.getEntryTeam(player.getName());
if (pushTeam == null) {
// It doesn't exist yet, so make it
pushTeam = scoreboard.getTeam(NO_PUSH_TEAM_NAME);
if (pushTeam == null) {
pushTeam = scoreboard.registerNewTeam(NO_PUSH_TEAM_NAME);
}
// Add the player to the team
pushTeam.addEntry(player.getName());
}
if (pushTeam.getName().equals(NO_PUSH_TEAM_NAME)) {
//plugin.getLogger().info("1.9 " +"DEBUG: pushing not allowed");
pushTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
} else {
//plugin.getLogger().info("1.9 " +"DEBUG: player is already in another team");
}
}
@EventHandler
public void onMatchStartEvent(MatchStartEvent event) {
for (TeamModule team : Teams.getTeams()) {
Team scoreboardTeam = scoreboard.getTeam(team.getId());
if (!team.isObserver()) scoreboardTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
}
}
@EventHandler
public void onMatchEndEvent(MatchEndEvent event) {
for (TeamModule team : Teams.getTeams()) {
Team scoreboardTeam = scoreboard.getTeam(team.getId());
if (!team.isObserver()) scoreboardTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
}
}
@Override
public void setTeamNameTagVisibility(Team team, boolean value){
team.setOption(Team.Option.NAME_TAG_VISIBILITY, value?Team.OptionStatus.ALWAYS:Team.OptionStatus.NEVER);
}
@Override
public void setTeamNameTagVisibility(Team team, boolean value){
team.setOption(Team.Option.NAME_TAG_VISIBILITY, value?Team.OptionStatus.ALWAYS:Team.OptionStatus.NEVER);
}