下面列出了org.bukkit.scoreboard.Team#addEntry ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Connect the player to the scoreboard
* - Disconnects from any existing scoreboards
* - Creates a new scoreboard for the world if required
*/
public void connect(GPlayer gPlayer) {
if (gPlayer != null && isEnabled) {
//Disconnect the player from the current scoreboard (if required):
disconnect(gPlayer);
//Connect online players to their associated-world scoreboards:
Player onlinePlayer = gPlayer.getOnlinePlayer();
if (onlinePlayer != null) {
Scoreboard scoreboard = getScoreboard(gPlayer);
onlinePlayer.setScoreboard(scoreboard);
Team team = scoreboard.registerNewTeam(onlinePlayer.getName());
team.addEntry(onlinePlayer.getName());
update(gPlayer);
}
}
}
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);
}
}
/**
* Adds an entry to a team
*
* @param team team
* @param string entry string
*/
public static void addTeamEntry(Team team, String string) {
if(ConfigManager.getServerVersion().isNewerThan(ConfigManager.ServerVersion.MINECRAFT_1_7_R2)) {
team.addEntry(string);
}
else {
try {
Scoreboard sb = team.getScoreboard();
Object board = boardField.get(sb);
addPlayerToTeamMethod.invoke(board, string, team.getName());
}
catch(IllegalAccessException | InvocationTargetException e) {
LoggerUtils.exception(e);
}
}
}
public void renderObjective(GameObjective objective) {
if (!objective.showOnScoreboard()) return;
int score = currentScore;
Team team = scoreboard.getTeam(objective.getScoreboardHandler().getNumber() + "-o");
String prefix = objective.getScoreboardHandler().getPrefix(this.team);
team.setPrefix(prefix);
if (team.getEntries().size() > 0) {
setScore(this.objective, new ArrayList<>(team.getEntries()).get(0), score);
} else {
String raw = (objective instanceof HillObjective ? "" : ChatColor.RESET) + " " + WordUtils.capitalizeFully(objective.getName().replaceAll("_", " "));
while (used.contains(raw)) {
raw = raw + ChatColor.RESET;
}
team.addEntry(raw);
setScore(this.objective, raw, score);
used.add(raw);
}
currentScore++;
}
public void renderTeamTitle(TeamModule teamModule) {
Team team = scoreboard.getTeam(teamModule.getId() + "-t");
team.setPrefix(teamModule.getColor() + Strings.trimTo(teamModule.getName(), 0, 14));
team.setSuffix(Strings.trimTo(teamModule.getName(), 14, 30));
if (team.getEntries().size() > 0) {
setScore(objective, new ArrayList<>(team.getEntries()).get(0), currentScore);
} else {
String name = teamModule.getColor() + "";
while (used.contains(name)) {
name = teamModule.getColor() + name;
}
team.addEntry(name);
setScore(objective, name, currentScore);
used.add(name);
}
currentScore++;
}
public void setup() {
final Scoreboard scoreboard = this.board.getScoreboard();
if (scoreboard == null) {
return;
}
String teamName = this.identifier;
// This shouldn't happen, but just in case
if (teamName.length() > 16) {
teamName = teamName.substring(0, 16);
}
Team team = scoreboard.getTeam(teamName);
// Register the team if it does not exist
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
}
// Add the entry to the team
if (team.getEntries() == null || team.getEntries().isEmpty() || !team.getEntries().contains(this.identifier)) {
team.addEntry(this.identifier);
}
// Add the entry if it does not exist
if (!this.board.getEntries().contains(this)) {
this.board.getEntries().add(this);
}
this.team = team;
}
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");
}
}
protected void addPlayer(String player) {
if (player == null) {
return;
}
User user = User.get(player);
if (!user.hasGuild()) {
return;
}
Scoreboard scoreboard = getScoreboard();
Team team = scoreboard.getEntryTeam(player);
if (team != null) {
team.removeEntry(player);
}
team = scoreboard.getTeam(user.getGuild().getTag());
if (team == null) {
addGuild(user.getGuild());
team = scoreboard.getTeam(user.getGuild().getTag());
}
if (this.getUser().hasGuild()) {
if (this.getUser().equals(user) || this.getUser().getGuild().getMembers().contains(user)) {
team.setPrefix(replace(FunnyGuilds.getInstance().getPluginConfiguration().prefixOur, "{TAG}", user.getGuild().getTag()));
}
}
team.addEntry(player);
}
public void renderCompactObjectives(ModuleCollection<GameObjective> objectives) {
int score = currentScore;
Team team = scoreboard.getTeam(objectives.get(0).getScoreboardHandler().getNumber() + "-o");
if (team != null) {
String compact = "";
for (GameObjective obj : objectives) {
compact += obj.getScoreboardHandler().getCompactPrefix(this.team) + " ";
}
while (compact.length() > 32) {
compact = Strings.removeLastWord(compact);
}
if (compact.length() < 16){
team.setPrefix(Strings.trimTo(compact, 0, 16));
team.setSuffix("r");
} else if (compact.charAt(15) == '\u00A7') {
team.setPrefix(Strings.trimTo(compact, 0, 15));
team.setSuffix(Strings.trimTo(compact, 15, 31));
} else {
team.setPrefix(Strings.trimTo(compact, 0, 16));
team.setSuffix(Strings.getCurrentChatColor(compact, 16).charAt(1) + Strings.trimTo(compact, 16, 31));
}
if (team.getEntries().size() > 0) {
setScore(objective, new ArrayList<>(team.getEntries()).get(0), currentScore);
} else {
String name = "\u00A7";
while (used.contains(name)) {
name = ChatColor.RESET + name;
}
team.addEntry(name);
setScore(objective, name, score);
used.add(name);
}
currentScore++;
}
}
public void renderTeamScore() {
if (minTdmScore == -1){
minTdmScore = currentScore;
}
List<String> fullNames = new ArrayList<>();
for (ScoreModule score : GameHandler.getGameHandler().getMatch().getModules().getModules(ScoreModule.class)){
if (score.getMax() != 0){
fullNames.add(score.getScore() + "" + ChatColor.DARK_GRAY + "/" + ChatColor.GRAY + score.getMax() + " " + score.getTeam().getCompleteName());
} else {
fullNames.add(score.getScore() + " " + score.getTeam().getCompleteName());
}
}
java.util.Collections.sort(fullNames, new Comparator<String>(){
public int compare(String str1, String str2){
int int1 = Integer.parseInt((str1.contains("/") ? str1.split("\u00a7",2) : str1.split(" ",2))[0]);
int int2 = Integer.parseInt((str2.contains("/") ? str2.split("\u00a7",2) : str2.split(" ",2))[0]);
return int1 - int2;
}
});
for (int i = 0; i < fullNames.size(); i++) {
String teamCompleteName = fullNames.get(i).split(" ",2)[1];
Team team = scoreboard.getTeam(Teams.getTeamByName(teamCompleteName.substring(2)).get().getId() + "-s");
team.setPrefix(Strings.trimTo(fullNames.get(i), 0, 16));
team.setSuffix(Strings.trimTo(fullNames.get(i), 16, 32));
if (team.getEntries().size() > 0) {
if (objective.getScore(new ArrayList<>(team.getEntries()).get(0)).getScore() != minTdmScore + i)
setScore(objective, new ArrayList<>(team.getEntries()).get(0), minTdmScore + i);
} else {
String color = teamCompleteName.substring(0, 2);
String name = color + "";
while (used.contains(name)) {
name = color + name;
}
team.addEntry(name);
setScore(objective, name, minTdmScore + i);
used.add(name);
}
currentScore++;
}
}
public static String convertToScoreboard(Team team, String string, String insertColor, boolean doNotInterruptColorCodes) {
int max1 = 16 - insertColor.length();
int max2 = 32 - (insertColor.length() * 2);
int max3 = 48 - (insertColor.length() * 2);
if (string.length() > max1) {
if (string.substring(max1 - 1, max1).equals("§") && doNotInterruptColorCodes && !insertColor.equals("")) {
max1--;
max2--;
max3--;
}
}
if (string.length() > max3) {
string = string.substring(0, max3);
}
if (string.length() <= max1) {
team.setPrefix("");
team.addEntry(insertColor + string);
team.setSuffix("");
return insertColor + string;
} else if (string.length() <= max2) {
team.setPrefix(insertColor + string.substring(0, max1));
team.addEntry(insertColor + string.substring(max1));
team.setSuffix("");
return insertColor + string.substring(max1);
} else if (string.length() <= max3) {
team.setPrefix(insertColor + string.substring(0, max1));
team.addEntry(insertColor + string.substring(max1, max2));
team.setSuffix(string.substring(max2));
return insertColor + string.substring(max1, max2);
}
return null;
}
private void addTeamEntry(Player target, Player all, PermissionGroup permissionGroup) {
String teamName = permissionGroup.getTagId() + permissionGroup.getName();
if (teamName.length() > 16) {
teamName = teamName.substring(0, 16);
CloudAPI.getInstance()
.dispatchConsoleMessage("In order to prevent issues, the name (+ tagID) of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!");
CloudAPI.getInstance().dispatchConsoleMessage("Please fix this issue by changing the name of the group in your perms.yml");
Bukkit.broadcast("In order to prevent issues, the name (+ tagID) of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!",
"cloudnet.notify");
Bukkit.broadcast("Please fix this issue by changing the name of the group in your perms.yml", "cloudnet.notify");
}
Team team = all.getScoreboard().getTeam(teamName);
if (team == null) {
team = all.getScoreboard().registerNewTeam(teamName);
}
if (permissionGroup.getPrefix().length() > 16) {
permissionGroup.setPrefix(permissionGroup.getPrefix().substring(0, 16));
CloudAPI.getInstance()
.dispatchConsoleMessage("In order to prevent issues, the prefix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!");
CloudAPI.getInstance().dispatchConsoleMessage("Please fix this issue by changing the prefix in your perms.yml");
Bukkit.broadcast("In order to prevent issues, the prefix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!",
"cloudnet.notify");
Bukkit.broadcast("Please fix this issue by changing the prefix in your perms.yml", "cloudnet.notify");
}
if (permissionGroup.getSuffix().length() > 16) {
permissionGroup.setSuffix(permissionGroup.getSuffix().substring(0, 16));
CloudAPI.getInstance()
.dispatchConsoleMessage("In order to prevent issues, the suffix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!");
CloudAPI.getInstance().dispatchConsoleMessage("Please fix this issue by changing the suffix in your perms.yml");
Bukkit.broadcast("In order to prevent issues, the suffix of the group " + permissionGroup.getName() + " was temporarily shortened to 16 characters!",
"cloudnet.notify");
Bukkit.broadcast("Please fix this issue by changing the suffix in your perms.yml", "cloudnet.notify");
}
try {
Method setColor = team.getClass().getDeclaredMethod("setColor", ChatColor.class);
setColor.setAccessible(true);
if (permissionGroup.getColor().length() != 0) {
setColor.invoke(team, ChatColor.getByChar(permissionGroup.getColor().replaceAll("&", "").replaceAll("§", "")));
} else {
setColor.invoke(team, ChatColor.getByChar(ChatColor.getLastColors(permissionGroup.getPrefix().replace('&', '§'))
.replaceAll("&", "")
.replaceAll("§", "")));
}
} catch (NoSuchMethodException ignored) {
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
team.setPrefix(ChatColor.translateAlternateColorCodes('&', permissionGroup.getPrefix()));
team.setSuffix(ChatColor.translateAlternateColorCodes('&', permissionGroup.getSuffix()));
team.addEntry(target.getName());
target.setDisplayName(ChatColor.translateAlternateColorCodes('&', permissionGroup.getDisplay() + target.getName()));
}