1
0
mirror of https://e.coding.net/circlecloud/MiaoBoard.git synced 2024-12-22 06:49:02 +00:00

fix: 修复suffix分割错误的问题

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-12-30 14:27:50 +08:00
parent be89fc1a18
commit fdf05fc1c0
16 changed files with 66 additions and 51 deletions

11
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>MiaoBoard</artifactId>
<version>2.4.2</version>
<version>2.5.0</version>
<description>喵式记分板</description>
<parent>
@ -13,14 +13,15 @@
</parent>
<properties>
<update.description>§a正式版本 2.4.2</update.description>
<update.description>§a正式版本 2.5.0</update.description>
<update.changes>
§619-12-30 §cfix: 修复字符截取错误导致的报错;
§619-10-24 §cfix: 调整默认配置的 time.end 为2099年;
§618-03-05 §cfix: 修复1.12不兼容的问题;
§617-10-15 §cfix: 修复颜色字符分割错误;
§617-08-15 §cfix: 修复事件未标记为异步的问题
§618-03-05 §cfix: 修复1.12不兼容的问题
</update.changes>
<update.changelog>
§617-10-15 §cfix: 修复颜色字符分割错误;
§617-08-15 §cfix: 修复事件未标记为异步的问题;
§617-06-28 §cfix: 修复T端不兼容的问题;
§617-03-09 §cfix: 修复行更新错误;
§617-03-09 §afeat: 添加记分板更新事件;

View File

@ -18,8 +18,8 @@ import pw.yumc.YumCore.commands.interfaces.Executor;
/**
* 喵式记分板主类
*
* @author MiaoWoo
* @since 2016年6月4日 上午9:08:13
* @author
*/
public class MiaoBoard extends JavaPlugin implements Executor {
private ScoreBoardManager scoreBoardManager;

View File

@ -8,8 +8,8 @@ import pw.yumc.YumCore.config.inject.InjectConfig;
/**
* 记分板配置文件类
*
* @author MiaoWoo
* @since 2016年7月21日 下午5:21:13
* @author
*/
public class MiaoBoardConfig extends InjectConfig {
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();

View File

@ -9,7 +9,9 @@ import org.bukkit.event.HandlerList;
/**
* 记分板更新事件
* Created by 蒋天蓓 on 2017/3/7 0007.
*
* @author MiaoWoo
* @date 2017/3/7 0007
*/
public class BodyUpdateEvent extends Event {
private Player player;

View File

@ -6,7 +6,9 @@ import org.bukkit.event.HandlerList;
/**
* 记分板标题更新
* Created by 蒋天蓓 on 2017/3/7 0007.
*
* @author MiaoWoo
* @date 2017/3/7 0007
*/
public class TitleUpdateEvent extends Event {
private Player player;

View File

@ -17,8 +17,8 @@ import pw.yumc.YumCore.update.SubscribeTask;
/**
* 玩家监听
*
* @since 2016年6月24日 下午3:29:39
* @author
* @author MiaoWoo
* @date 2016年6月24日 下午3:29:39
*/
public class PlayerListener implements Listener {
private MiaoBoard plugin = P.getPlugin();

View File

@ -15,7 +15,9 @@ import pw.yumc.YumCore.text.Replace;
/**
* 自身记分板监听类
* Created by 蒋天蓓 on 2017/3/7 0007.
*
* @author MiaoWoo
* @date 2017/3/7 0007
*/
public class SelfListener implements Listener {
private MiaoBoard plugin = P.getPlugin();

View File

@ -7,6 +7,9 @@ import org.bukkit.entity.Player;
import pw.yumc.MiaoBoard.model.BoardModel;
/**
* @author MiaoWoo
*/
public class Checker {
public static List<String> offList = new ArrayList<>();

View File

@ -13,7 +13,7 @@ import com.google.common.base.Charsets;
* Created with IntelliJ IDEA
*
* @author
* Created on 2017/10/15 23:30.
* Created on 2017/10/15 23:30.
*/
public class FakePlayer implements OfflinePlayer {
private String name;

View File

@ -12,8 +12,8 @@ import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
/**
* 记分板数据模型类
*
* @author MiaoWoo
* @since 2016年7月21日 下午6:58:58
* @author
*/
public class BoardModel extends InjectConfigurationSection {
public transient String name;
@ -32,7 +32,9 @@ public class BoardModel extends InjectConfigurationSection {
* 自动载入配置
*
* @param name
* 记分板名称
* @param config
* 记分板配置
*/
public BoardModel(String name, final ConfigurationSection config) {
super(config);

View File

@ -18,8 +18,8 @@ import pw.yumc.YumCore.config.FileConfig;
/**
* 记分板管理类
*
* @author MiaoWoo
* @since 2016年6月24日 下午3:31:31
* @author
*/
public class ScoreBoardManager {
private Status cot = new Status();
@ -47,7 +47,9 @@ public class ScoreBoardManager {
private void load() {
bms.clear();
config.getConfigurationSection("Boards").getKeys(false).forEach(bmn -> bms.add(new BoardModel(bmn, config.getConfigurationSection("Boards." + bmn))));
config.getConfigurationSection("Boards")
.getKeys(false)
.forEach(bmn -> bms.add(new BoardModel(bmn, config.getConfigurationSection("Boards." + bmn))));
bms.sort(Comparator.comparing(o -> o.index));
}
@ -67,7 +69,7 @@ public class ScoreBoardManager {
C.Player.getOnlinePlayers().forEach(this::addTarget);
}
private class Status implements Condition {
private static class Status implements Condition {
private boolean status = true;
@Override
@ -75,7 +77,7 @@ public class ScoreBoardManager {
return status;
}
Status set(final boolean status) {
Status set(boolean status) {
this.status = status;
return this;
}

View File

@ -8,11 +8,11 @@ import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
* @since 2016年7月4日 下午4:40:21
*/
public abstract class Board implements Iterable<Player> {
@ -69,6 +69,7 @@ public abstract class Board implements Iterable<Player> {
return this.targets.containsKey(player);
}
@NotNull
@Override
public Iterator<Player> iterator() {
return this.targets.keySet().iterator();

View File

@ -4,9 +4,8 @@ import org.bukkit.Bukkit;
import org.bukkit.scoreboard.Scoreboard;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
* @since 2016年7月4日 下午4:40:21
*/
public abstract class BoardPage {

View File

@ -1,12 +1,9 @@
package pw.yumc.MiaoBoard.scoreboard.core;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
* @since 2016年7月4日 下午4:40:21
*/
public interface Condition {
boolean get();
}

View File

@ -8,9 +8,8 @@ import pw.yumc.MiaoBoard.event.BodyUpdateEvent;
import pw.yumc.MiaoBoard.event.TitleUpdateEvent;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
* @since 2016年7月4日 下午4:40:21
*/
public class SidebarBoard extends Board {
public SidebarBoard(final Plugin plugin) {

View File

@ -15,12 +15,12 @@ import pw.yumc.MiaoBoard.misc.FakePlayer;
import pw.yumc.YumCore.kit.StrKit;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
* @since 2016年7月4日 下午4:40:21
*/
public class SidebarBoardPage extends BoardPage {
private static boolean newVer = true;
static {
try {
Team.class.getDeclaredMethod("addEntry", String.class);
@ -29,19 +29,21 @@ public class SidebarBoardPage extends BoardPage {
}
}
private static final List<ChatColor> colors = Arrays.asList(ChatColor.values()); //所有颜色
private static final List<ChatColor> COLORS = Arrays.asList(ChatColor.values());
private static final int BOARD_LINE_MAX_CHARS = 16;
private static final int BOARD_LINE_MAX_CHARS_SUB1 = BOARD_LINE_MAX_CHARS - 1;
private final Objective objective;
private final List<BoardLine> boardLines = new ArrayList<>();// ""
private int maxLine;//用于标注最大行数
private final List<BoardLine> boardLines = new ArrayList<>();
private int maxLine;
public SidebarBoardPage() {
super();
objective = getBoard().registerNewObjective("default", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
for (int i = 0; i < colors.size(); i++) { //循环所有的颜色
final String name = colors.get(i) + "" + ChatColor.RESET;
final Team team = getBoard().registerNewTeam("MiaoboardLine" + i); //为每个颜色注册一个队伍
boardLines.add(new BoardLine(name, team)); //""添加至列表
for (int i = 0; i < COLORS.size(); i++) {
final String name = COLORS.get(i) + "" + ChatColor.RESET;
final Team team = getBoard().registerNewTeam("MiaoboardLine" + i);
boardLines.add(new BoardLine(name, team));
}
}
@ -54,22 +56,26 @@ public class SidebarBoardPage extends BoardPage {
}
public void setValue(int line, String value) {
final BoardLine boardLine = getBoardLine(line); //得到我们的""
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
objective.getScore(boardLine.getName()).setScore(line); //设置""
final BoardLine boardLine = getBoardLine(line);
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + ".");
objective.getScore(boardLine.getName()).setScore(line);
//分割字符串为前16个和后16个
String prefix = value;
String suffix = "";
if (value.length() > 16) {
int splitIndex = value.charAt(15) == '§' ? 15 : 16;
if (value.length() > BOARD_LINE_MAX_CHARS) {
int splitIndex = value.charAt(BOARD_LINE_MAX_CHARS_SUB1) == ChatColor.COLOR_CHAR ? BOARD_LINE_MAX_CHARS_SUB1 : BOARD_LINE_MAX_CHARS;
prefix = StrKit.substring(value, 0, splitIndex);
suffix = value.substring(splitIndex, value.length());
suffix = value.substring(splitIndex);
// 如果过suffix开头不是颜色符号就把prefix颜色转移到suffix
if (suffix.charAt(0) != '§') suffix = ChatColor.getLastColors(prefix) + suffix;
if (suffix.length() > 16) suffix = suffix.substring(16, suffix.length());
if (suffix.charAt(0) != ChatColor.COLOR_CHAR) {
suffix = ChatColor.getLastColors(prefix) + suffix;
}
if (suffix.length() > BOARD_LINE_MAX_CHARS) {
suffix = StrKit.substring(suffix, 0, BOARD_LINE_MAX_CHARS);
}
}
boardLine.getTeam().setPrefix(prefix); //设置前16个字符
boardLine.getTeam().setSuffix(suffix); //设置后16个字符
boardLine.getTeam().setPrefix(prefix);
boardLine.getTeam().setSuffix(suffix);
maxLine = line + 1;
}
@ -85,8 +91,8 @@ public class SidebarBoardPage extends BoardPage {
public void removeLine(int line) {
final BoardLine boardLine = getBoardLine(line);
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
getBoard().resetScores(boardLine.getName()); //删除这个""
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + ".");
getBoard().resetScores(boardLine.getName());
}
private BoardLine getBoardLine(int line) {
@ -100,7 +106,7 @@ public class SidebarBoardPage extends BoardPage {
clear(newContents.size());
}
class BoardLine {
static class BoardLine {
private String name;
private Team team;
private OfflinePlayer player;
@ -127,6 +133,5 @@ public class SidebarBoardPage extends BoardPage {
public Team getTeam() {
return team;
}
}
}