From 5825eb169668f97626635c80c36c4de59870daa1 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Mon, 14 Apr 2014 15:54:50 +0200 Subject: [PATCH] Make sure to shorten long ability and skill names (cherry picked from commit 236ccd6ebdd0834f87b373794e1597ef36fb2ff6) --- .../util/scoreboards/ScoreboardManager.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java index b94515931..cb01ead18 100644 --- a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java +++ b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java @@ -77,13 +77,13 @@ public class ScoreboardManager { int i = 0; for (SkillType type : SkillType.values()) { // Include child skills - skillLabelBuilder.put(type, colors.get(i) + type.getName()); + skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false)); if (type.getAbility() != null) { - abilityLabelBuilder.put(type.getAbility(), colors.get(i) + type.getAbility().getName()); + abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getName())); if (type == SkillType.MINING) { - abilityLabelBuilder.put(AbilityType.BLAST_MINING, colors.get(i) + AbilityType.BLAST_MINING.getName()); + abilityLabelBuilder.put(AbilityType.BLAST_MINING, getShortenedName(colors.get(i) + AbilityType.BLAST_MINING.getName())); } } @@ -95,20 +95,20 @@ public class ScoreboardManager { else { for (SkillType type : SkillType.values()) { // Include child skills - skillLabelBuilder.put(type, ChatColor.GREEN + type.getName()); + skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName())); if (type.getAbility() != null) { - abilityLabelBuilder.put(type.getAbility(), ChatColor.AQUA + type.getAbility().getName()); + abilityLabelBuilder.put(type.getAbility(), getShortenedName(ChatColor.AQUA + type.getAbility().getName())); if (type == SkillType.MINING) { - abilityLabelBuilder.put(AbilityType.BLAST_MINING, ChatColor.AQUA + AbilityType.BLAST_MINING.getName()); + abilityLabelBuilder.put(AbilityType.BLAST_MINING, getShortenedName(ChatColor.AQUA + AbilityType.BLAST_MINING.getName())); } } } } for (AbilityType type : AbilityType.values()) { - abilityLabelSkillBuilder.put(type, (type == AbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA) + type.getName()); + abilityLabelSkillBuilder.put(type, getShortenedName((type == AbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA) + type.getName())); } skillLabels = skillLabelBuilder.build(); @@ -127,6 +127,18 @@ public class ScoreboardManager { TOP_BOARD; } + private static String getShortenedName(String name) { + return getShortenedName(name, true); + } + + private static String getShortenedName(String name, boolean useDots) { + if (name.length() > 16) { + name = useDots ? name.substring(0, 14) + ".." : name.substring(0, 16); + } + + return name; + } + // **** Listener call-ins **** // // Called by PlayerJoinEvent listener