Java Code Examples for org.bukkit.scoreboard.Team#setPrefix()
The following examples show how to use
org.bukkit.scoreboard.Team#setPrefix() .
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: TagDataHandler.java From TabooLib with MIT License | 6 votes |
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); } }
Example 2
Source File: ScoreboardModule.java From CardinalPGM with MIT License | 6 votes |
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++; }
Example 3
Source File: ScoreboardModule.java From CardinalPGM with MIT License | 6 votes |
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++; }
Example 4
Source File: ScoreboardMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
protected void updatePartyScoreboardTeam(Party party, Team team, boolean forObservers) { match.getLogger().fine("Updating scoreboard team " + toString(team) + " for party " + party); team.setDisplayName(TextTranslations.translateLegacy(party.getName(), null)); team.setPrefix(party.getColor().toString()); team.setSuffix(ChatColor.WHITE.toString()); team.setCanSeeFriendlyInvisibles(true); team.setAllowFriendlyFire(false); if (!forObservers && party instanceof Competitor) { NameTagVisibility nameTags = ((Competitor) party).getNameTagVisibility(); team.setNameTagVisibility(nameTags); } else { team.setNameTagVisibility(NameTagVisibility.ALWAYS); } }
Example 5
Source File: IndividualPrefix.java From FunnyGuilds with Apache License 2.0 | 5 votes |
protected void removePlayer(String player) { if (player == null) { return; } Team team = getScoreboard().getEntryTeam(player); if (team != null) { team.removeEntry(player); if (team.getName() != null) { team.setPrefix(replace(FunnyGuilds.getInstance().getPluginConfiguration().prefixOther, "{TAG}", team.getName())); } } }
Example 6
Source File: UHTeam.java From KTP with GNU General Public License v3.0 | 5 votes |
public UHTeam(String name, String displayName, ChatColor color, UHPlugin plugin) { this.name = name; this.displayName = displayName; this.color = color; this.plugin = plugin; Scoreboard sb = this.plugin.getScoreboard(); sb.registerNewTeam(this.name); Team t = sb.getTeam(this.name); t.setDisplayName(this.displayName); t.setCanSeeFriendlyInvisibles(true); t.setPrefix(this.color+""); }
Example 7
Source File: Scoreboards.java From CardinalPGM with MIT License | 5 votes |
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; }
Example 8
Source File: ScoreboardModule.java From CardinalPGM with MIT License | 5 votes |
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++; } }
Example 9
Source File: ScoreboardModule.java From CardinalPGM with MIT License | 5 votes |
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++; } }
Example 10
Source File: ScoreboardModule.java From CardinalPGM with MIT License | 5 votes |
public void updateObjectivePrefix(GameObjective objective) { if (!objective.showOnScoreboard()) return; if (getSlots() < 16) { Team team = scoreboard.getTeam(objective.getScoreboardHandler().getNumber() + "-o"); String prefix = objective.getScoreboardHandler().getPrefix(this.team); team.setPrefix(prefix); } else { update(); } }
Example 11
Source File: IndividualPrefix.java From FunnyGuilds with Apache License 2.0 | 5 votes |
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); }
Example 12
Source File: PlayerAppearanceChanger.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 13
Source File: ScoreboardMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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); } }
Example 14
Source File: ScoreboardModule.java From CardinalPGM with MIT License | 4 votes |
public void updateTeamTitle(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)); }
Example 15
Source File: TagUtils.java From NovaGuilds with GNU General Public License v3.0 | 4 votes |
/** * 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()); } }
Example 16
Source File: SimpleScoreboard.java From ScoreboardLib with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private FakePlayer getFakePlayer(String text, int offset) { Team team = null; String name; // If the text has a length less than 16, teams need not to be be created if (text.length() <= 16) { name = text + Strings.repeat(" ", offset); } else { String prefix; String suffix = ""; offset++; // Otherwise, iterate through the string and cut off prefix and suffix prefix = text.substring(0, 16 - offset); name = text.substring(16 - offset); if (name.length() > 16) name = name.substring(0, 16); if (text.length() > 32) suffix = text.substring(32 - offset); // If teams already exist, use them for (Team other : teamCache.rowKeySet()) { if (other.getPrefix().equals(prefix) && other.getSuffix().equals(suffix)) { team = other; } } // Otherwise create them if (team == null) { team = scoreboard.registerNewTeam(TEAM_PREFIX + TEAM_COUNTER++); team.setPrefix(prefix); team.setSuffix(suffix); teamCache.put(team, prefix, suffix); } } FakePlayer faker; if (!playerCache.contains(name, offset)) { faker = new FakePlayer(name, team, offset); playerCache.put(name, offset, faker); if (faker.getTeam() != null) { faker.getTeam().addPlayer(faker); } } else { faker = playerCache.get(name, offset); if (team != null && faker.getTeam() != null) { faker.getTeam().removePlayer(faker); } faker.setTeam(team); if (faker.getTeam() != null) { faker.getTeam().addPlayer(faker); } } return faker; }
Example 17
Source File: CloudServer.java From CloudNet with Apache License 2.0 | 4 votes |
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())); }