From 95a921cee458f2302f0f1788f8173b1e7ad11cde Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 6 Jun 2017 20:36:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=20=E4=BF=AE=E5=A4=8D=E8=A1=8C=E5=88=86?= =?UTF-8?q?=E5=89=B2=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../scoreboard/core/SiderbarBoardPage.java | 20 ++++----- .../core/SiderbarBoardPageTest.java | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/test/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPageTest.java diff --git a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPage.java b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPage.java index 5cab6f5..1a40122 100644 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPage.java +++ b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPage.java @@ -19,9 +19,8 @@ import pw.yumc.YumCore.kit.StrKit; */ public class SiderbarBoardPage extends BoardPage { - private final Objective objective; - private static final List colors = Arrays.asList(ChatColor.values()); //所有颜色 + private final Objective objective; private final List boardLines = new ArrayList<>();// "行" private int maxLine;//用于标注最大行数 @@ -50,22 +49,21 @@ public class SiderbarBoardPage extends BoardPage { Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在 objective.getScore(boardLine.getColor().toString()).setScore(line); //设置"行" //分割字符串为前16个和后16个 - boardLine.getTeam().setPrefix(StrKit.substring(value, 0, 16)); //设置前16个字符 + String prefix = StrKit.substring(value, 0, 16); + String suffix = ""; if (value.length() > 16) { - String suffix = value.substring(16, value.length()); + suffix = value.substring(16, value.length()); //处理前后的颜色 - String sufpre = ""; - String prepre = ChatColor.getLastColors(value); + String sufpre = ChatColor.getLastColors(prefix); if (value.charAt(15) == '§') { sufpre = "§"; - } else if (!"".equals(prepre)) { - sufpre = prepre; + } else if (!suffix.isEmpty() && suffix.charAt(0) == '§') { + sufpre = ""; } suffix = StrKit.substring(sufpre + suffix, 0, 16); - boardLine.getTeam().setSuffix(suffix);//"设置后16个字符" - } else { - boardLine.getTeam().setSuffix("");//"清理后16个字符" } + boardLine.getTeam().setPrefix(prefix); //设置前16个字符 + boardLine.getTeam().setSuffix(suffix); //设置后16个字符 maxLine = line + 1; } diff --git a/src/test/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPageTest.java b/src/test/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPageTest.java new file mode 100644 index 0000000..0ce8e68 --- /dev/null +++ b/src/test/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPageTest.java @@ -0,0 +1,43 @@ +package pw.yumc.MiaoBoard.scoreboard.core; + +import org.bukkit.ChatColor; +import org.junit.Test; + +import pw.yumc.YumCore.kit.StrKit; + +/** + * @author 喵♂呜 + * @since 2017/6/6 + */ + +public class SiderbarBoardPageTest { + + @Test + public void testSubStr() { + substr("§aaaaaaaaaaa§bcdepqrstuvwxyz"); + substr("§aaaaaaaaaaab§cdefqrstuvwxyz"); + substr("§aaaaaaaaaaabc§defqrstuvwxyz"); + substr("§aaaaaaaaaaabcd§efqrstuvwxyz"); + substr("§aaaaaaaaaaabcde§fqrstuvwxyz"); + } + + public void substr(String value) { + System.out.println("变量: " + value); + String prefix = StrKit.substring(value, 0, 16); + System.out.println("前缀: " + prefix); //设置前16个字符 + String suffix = ""; + if (value.length() > 16) { + suffix = value.substring(16, value.length()); + //处理前后的颜色 + String sufpre = ChatColor.getLastColors(prefix); + if (value.charAt(15) == '§') { + sufpre = "§"; + } else if (!suffix.isEmpty() && suffix.charAt(0) == '§') { + sufpre = ""; + } + suffix = StrKit.substring(sufpre + suffix, 0, 16); + } + System.out.println("后缀: " + suffix); + System.out.println("===================="); + } +} \ No newline at end of file