mirror of
https://e.coding.net/circlecloud/MiaoBoard.git
synced 2024-11-22 01:49:05 +00:00
fix: 修复颜色符号处理错误
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
a6585f11db
commit
3104428641
5
pom.xml
5
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>MiaoBoard</artifactId>
|
<artifactId>MiaoBoard</artifactId>
|
||||||
<version>2.3.7</version>
|
<version>2.4.0</version>
|
||||||
<description>喵式记分板</description>
|
<description>喵式记分板</description>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
@ -71,8 +71,9 @@
|
|||||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
<properties>
|
<properties>
|
||||||
<update.description>§a正式版本 2.3.7</update.description>
|
<update.description>§a正式版本 2.4.0</update.description>
|
||||||
<update.changes>
|
<update.changes>
|
||||||
|
§617-10-15 §cfix: 修复颜色字符分割错误;
|
||||||
§617-08-15 §cfix: 修复事件未标记为异步的问题;
|
§617-08-15 §cfix: 修复事件未标记为异步的问题;
|
||||||
§617-06-28 §cfix: 修复T端不兼容的问题;
|
§617-06-28 §cfix: 修复T端不兼容的问题;
|
||||||
§617-03-09 §cfix: 修复行更新错误;
|
§617-03-09 §cfix: 修复行更新错误;
|
||||||
|
99
src/main/java/pw/yumc/MiaoBoard/misc/FakePlayer.java
Normal file
99
src/main/java/pw/yumc/MiaoBoard/misc/FakePlayer.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package pw.yumc.MiaoBoard.misc;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA
|
||||||
|
*
|
||||||
|
* @author 喵♂呜
|
||||||
|
* Created on 2017/10/15 23:30.
|
||||||
|
*/
|
||||||
|
public class FakePlayer implements OfflinePlayer {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public FakePlayer(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOnline() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBanned() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBanned(boolean banned) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWhitelisted() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWhitelisted(boolean value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getPlayer() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getFirstPlayed() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLastPlayed() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPlayedBefore() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getBedSpawnLocation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOp() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOp(boolean value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -18,19 +18,19 @@ public class SidebarBoard extends Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SiderbarBoardPage getBoardPage(final Player player) {
|
public SidebarBoardPage getBoardPage(final Player player) {
|
||||||
return (SiderbarBoardPage) super.getBoardPage(player);
|
return (SidebarBoardPage) super.getBoardPage(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SiderbarBoardPage newPage() {
|
public SidebarBoardPage newPage() {
|
||||||
return new SiderbarBoardPage();
|
return new SidebarBoardPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(final Player player) {
|
public void update(final Player player) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> {
|
||||||
final SiderbarBoardPage boardPage = this.getBoardPage(player);
|
final SidebarBoardPage boardPage = this.getBoardPage(player);
|
||||||
if (boardPage == null) { return; }
|
if (boardPage == null) { return; }
|
||||||
TitleUpdateEvent te = new TitleUpdateEvent(player);
|
TitleUpdateEvent te = new TitleUpdateEvent(player);
|
||||||
Bukkit.getPluginManager().callEvent(te);
|
Bukkit.getPluginManager().callEvent(te);
|
||||||
|
@ -6,11 +6,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.scoreboard.DisplaySlot;
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.compatible.C;
|
import pw.yumc.MiaoBoard.misc.FakePlayer;
|
||||||
import pw.yumc.YumCore.kit.StrKit;
|
import pw.yumc.YumCore.kit.StrKit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +19,7 @@ import pw.yumc.YumCore.kit.StrKit;
|
|||||||
* @since 2016年7月4日 下午4:40:21
|
* @since 2016年7月4日 下午4:40:21
|
||||||
* @author 尘曲
|
* @author 尘曲
|
||||||
*/
|
*/
|
||||||
public class SiderbarBoardPage extends BoardPage {
|
public class SidebarBoardPage extends BoardPage {
|
||||||
private static boolean newVer = true;
|
private static boolean newVer = true;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -33,20 +34,14 @@ public class SiderbarBoardPage extends BoardPage {
|
|||||||
private final List<BoardLine> boardLines = new ArrayList<>();// "行"
|
private final List<BoardLine> boardLines = new ArrayList<>();// "行"
|
||||||
private int maxLine;//用于标注最大行数
|
private int maxLine;//用于标注最大行数
|
||||||
|
|
||||||
public SiderbarBoardPage() {
|
public SidebarBoardPage() {
|
||||||
super();
|
super();
|
||||||
objective = getBoard().registerNewObjective("default", "dummy");
|
objective = getBoard().registerNewObjective("default", "dummy");
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
for (int i = 0; i < colors.size(); i++) { //循环所有的颜色
|
for (int i = 0; i < colors.size(); i++) { //循环所有的颜色
|
||||||
final ChatColor color = colors.get(i);
|
final String name = colors.get(i) + "" + ChatColor.RESET;
|
||||||
final Team team = getBoard().registerNewTeam("MiaoboardLine" + i); //为每个颜色注册一个队伍
|
final Team team = getBoard().registerNewTeam("MiaoboardLine" + i); //为每个颜色注册一个队伍
|
||||||
//为队伍设置一个"行"
|
boardLines.add(new BoardLine(name, team)); //将"行"添加至列表
|
||||||
if (newVer) {
|
|
||||||
team.addEntry(color.toString());
|
|
||||||
} else {
|
|
||||||
team.addPlayer(C.Player.getOfflinePlayer(color.toString()));
|
|
||||||
}
|
|
||||||
boardLines.add(new BoardLine(color, team)); //将"行"添加至列表
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,20 +56,17 @@ public class SiderbarBoardPage extends BoardPage {
|
|||||||
public void setValue(int line, String value) {
|
public void setValue(int line, String value) {
|
||||||
final BoardLine boardLine = getBoardLine(line); //得到我们的"行"
|
final BoardLine boardLine = getBoardLine(line); //得到我们的"行"
|
||||||
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
|
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
|
||||||
objective.getScore(boardLine.getColor().toString()).setScore(line); //设置"行"
|
objective.getScore(boardLine.getName()).setScore(line); //设置"行"
|
||||||
//分割字符串为前16个和后16个
|
//分割字符串为前16个和后16个
|
||||||
String prefix = StrKit.substring(value, 0, 16);
|
String prefix = value;
|
||||||
String suffix = "";
|
String suffix = "";
|
||||||
if (value.length() > 16) {
|
if (value.length() > 16) {
|
||||||
suffix = value.substring(16, value.length());
|
int splitIndex = value.charAt(15) == '§' ? 15 : 16;
|
||||||
//处理前后的颜色
|
prefix = StrKit.substring(value, 0, splitIndex);
|
||||||
String sufpre = ChatColor.getLastColors(prefix);
|
suffix = value.substring(splitIndex, value.length());
|
||||||
if (value.charAt(15) == '§') {
|
// 如果过suffix开头不是颜色符号就把prefix颜色转移到suffix
|
||||||
sufpre = "§";
|
if (suffix.charAt(0) != '§') suffix = ChatColor.getLastColors(prefix) + suffix;
|
||||||
} else if (!suffix.isEmpty() && suffix.charAt(0) == '§') {
|
if (suffix.length() > 16) suffix = suffix.substring(16, suffix.length());
|
||||||
sufpre = "";
|
|
||||||
}
|
|
||||||
suffix = StrKit.substring(sufpre + suffix, 0, 16);
|
|
||||||
}
|
}
|
||||||
boardLine.getTeam().setPrefix(prefix); //设置前16个字符
|
boardLine.getTeam().setPrefix(prefix); //设置前16个字符
|
||||||
boardLine.getTeam().setSuffix(suffix); //设置后16个字符
|
boardLine.getTeam().setSuffix(suffix); //设置后16个字符
|
||||||
@ -94,7 +86,7 @@ public class SiderbarBoardPage extends BoardPage {
|
|||||||
public void removeLine(int line) {
|
public void removeLine(int line) {
|
||||||
final BoardLine boardLine = getBoardLine(line);
|
final BoardLine boardLine = getBoardLine(line);
|
||||||
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
|
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
|
||||||
getBoard().resetScores(boardLine.getColor().toString()); //删除这个"行"
|
getBoard().resetScores(boardLine.getName()); //删除这个"行"
|
||||||
}
|
}
|
||||||
|
|
||||||
private BoardLine getBoardLine(int line) {
|
private BoardLine getBoardLine(int line) {
|
||||||
@ -109,16 +101,27 @@ public class SiderbarBoardPage extends BoardPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BoardLine {
|
class BoardLine {
|
||||||
private final ChatColor color;
|
private String name;
|
||||||
private final Team team;
|
private Team team;
|
||||||
|
private OfflinePlayer player;
|
||||||
|
|
||||||
public BoardLine(ChatColor color, Team team) {
|
public BoardLine(String name, Team team) {
|
||||||
this.color = color;
|
this.name = name;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
|
this.player = new FakePlayer(name);
|
||||||
|
addEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatColor getColor() {
|
public void addEntry() {
|
||||||
return color;
|
if (newVer) {
|
||||||
|
team.addEntry(name);
|
||||||
|
} else {
|
||||||
|
team.addPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Team getTeam() {
|
public Team getTeam() {
|
@ -10,7 +10,7 @@ import pw.yumc.YumCore.kit.StrKit;
|
|||||||
* @since 2017/6/6
|
* @since 2017/6/6
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SiderbarBoardPageTest {
|
public class SidebarBoardPageTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubStr() {
|
public void testSubStr() {
|
||||||
@ -24,19 +24,16 @@ public class SiderbarBoardPageTest {
|
|||||||
public void substr(String value) {
|
public void substr(String value) {
|
||||||
System.out.println("变量: " + value);
|
System.out.println("变量: " + value);
|
||||||
String prefix = StrKit.substring(value, 0, 16);
|
String prefix = StrKit.substring(value, 0, 16);
|
||||||
System.out.println("前缀: " + prefix); //设置前16个字符
|
|
||||||
String suffix = "";
|
String suffix = "";
|
||||||
if (value.length() > 16) {
|
if (value.length() > 16) {
|
||||||
suffix = value.substring(16, value.length());
|
int splitIndex = value.charAt(15) == '§' ? 15 : 16;
|
||||||
//处理前后的颜色
|
prefix = StrKit.substring(value, 0, splitIndex);
|
||||||
String sufpre = ChatColor.getLastColors(prefix);
|
suffix = value.substring(splitIndex, value.length());
|
||||||
if (value.charAt(15) == '§') {
|
// 如果过suffix开头不是颜色符号就把prefix颜色转移到suffix
|
||||||
sufpre = "§";
|
if (suffix.charAt(0) != '§') suffix = ChatColor.getLastColors(prefix) + suffix;
|
||||||
} else if (!suffix.isEmpty() && suffix.charAt(0) == '§') {
|
if (suffix.length() > 16) suffix = suffix.substring(16, suffix.length());
|
||||||
sufpre = "";
|
|
||||||
}
|
|
||||||
suffix = StrKit.substring(sufpre + suffix, 0, 16);
|
|
||||||
}
|
}
|
||||||
|
System.out.println("前缀: " + prefix); //设置前16个字符
|
||||||
System.out.println("后缀: " + suffix);
|
System.out.println("后缀: " + suffix);
|
||||||
System.out.println("====================");
|
System.out.println("====================");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user