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
5a53213666
commit
73c39d110a
239
pom.xml
239
pom.xml
@ -1,129 +1,114 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoBoard</artifactId>
|
||||
<version>2.2</version>
|
||||
<name>MiaoBoard</name>
|
||||
<description>喵式记分板</description>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>pw.yumc:YumCore</include>
|
||||
<include>cn.citycraft:PluginHelper</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>pw.yumc.YumCore</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.wvengen</groupId>
|
||||
<artifactId>proguard-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>proguard</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<options>
|
||||
<option>-repackageclasses nul.j.for.t.class.b</option>
|
||||
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
||||
</options>
|
||||
<libs>
|
||||
<lib>${java.home}/lib/rt.jar</lib>
|
||||
</libs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<update.description></update.description>
|
||||
<update.changes></update.changes>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtb</id>
|
||||
<name>YUMC</name>
|
||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<artifactId>PluginHelper</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoBoard</artifactId>
|
||||
<version>2.3</version>
|
||||
<description>喵式记分板</description>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>pw.yumc:YumCore</include>
|
||||
<include>cn.citycraft:PluginHelper</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>pw.yumc.YumCore</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.wvengen</groupId>
|
||||
<artifactId>proguard-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>proguard</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<options>
|
||||
<option>-repackageclasses \ʼ.ʽ.ʾ.${project.artifactId}</option>
|
||||
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
||||
</options>
|
||||
<libs>
|
||||
<lib>${java.home}/lib/rt.jar</lib>
|
||||
</libs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<update.description></update.description>
|
||||
<update.changes></update.changes>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtb</id>
|
||||
<name>YUMC</name>
|
||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -10,8 +10,8 @@
|
||||
|
||||
# -----启用混淆字典-----
|
||||
-obfuscationdictionary obf.dict
|
||||
-classobfuscationdictionary class.dict
|
||||
-packageobfuscationdictionary class.dict
|
||||
-classobfuscationdictionary obf.dict
|
||||
-packageobfuscationdictionary obf.dict
|
||||
|
||||
# -----保留所有属性
|
||||
-keepattributes **
|
||||
@ -26,22 +26,25 @@
|
||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler <methods>;
|
||||
}
|
||||
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
||||
@net.md_5.bungee.event.EventHandler <methods>;
|
||||
}
|
||||
|
||||
# -----保护枚举方法的完整性-----
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
# -----保护配置注入不被清理-----
|
||||
-keepclassmembers class * extends **.config.InjectConfigurationSection {
|
||||
<fields>;
|
||||
}
|
||||
-keepclassmembers class * extends **.config.InjectConfig {
|
||||
-keepclassmembers class * extends **.config**Inject** {
|
||||
<fields>;
|
||||
}
|
||||
|
||||
# -----保护注解命令方法不被清理-----
|
||||
-keepclassmembers class **.commands.annotation.** { <methods>; }
|
||||
-keepclassmembers class * implements **.commands.CommandExecutor { <methods>; }
|
||||
-keepclassmembers class * implements **.commands**CommandExecutor { <methods>; }
|
||||
|
||||
-keepclassmembers class **.commands.HandlerCommand { <methods>; }
|
||||
-keepclassmembers class * implements **.commands.HandlerCommands {
|
||||
@**.commands.HandlerCommand <methods>;
|
||||
@**.commands.HandlerTabComplete <methods>;
|
||||
}
|
||||
# -----保护注解NotProguard标记-----
|
||||
-keep class **.NotProguard
|
||||
-keep @**.NotProguard class * {*;}
|
||||
@ -49,6 +52,3 @@
|
||||
@**.NotProguard <fields>;
|
||||
@**.NotProguard <methods>;
|
||||
}
|
||||
|
||||
# -----保护命令解析正常-----
|
||||
-keepnames class * extends **.commands.BaseCommand
|
@ -1,18 +1,18 @@
|
||||
package pw.yumc.MiaoBoard;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import pw.yumc.MiaoBoard.listener.PlayerListener;
|
||||
import pw.yumc.MiaoBoard.misc.Checker;
|
||||
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.commands.CommandArgument;
|
||||
import pw.yumc.YumCore.commands.CommandExecutor;
|
||||
import pw.yumc.YumCore.commands.CommandManager;
|
||||
import pw.yumc.YumCore.commands.CommandSub;
|
||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
||||
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
|
||||
import pw.yumc.YumCore.commands.annotation.Help;
|
||||
import pw.yumc.YumCore.commands.annotation.Sort;
|
||||
import pw.yumc.YumCore.commands.interfaces.Executor;
|
||||
|
||||
/**
|
||||
* 喵式记分板主类
|
||||
@ -20,27 +20,27 @@ import pw.yumc.YumCore.commands.annotation.Sort;
|
||||
* @since 2016年6月4日 上午9:08:13
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class MiaoBoard extends JavaPlugin implements CommandExecutor {
|
||||
public class MiaoBoard extends JavaPlugin implements Executor {
|
||||
private ScoreBoardManager scoreBoardManager;
|
||||
|
||||
public ScoreBoardManager getScoreBoardManager() {
|
||||
return scoreBoardManager;
|
||||
}
|
||||
|
||||
@Cmd(permission = "mb.toggle", executor = Executor.PLAYER)
|
||||
@Cmd(permission = "mb.toggle", executor = Cmd.Executor.PLAYER)
|
||||
@Help("关闭记分板")
|
||||
@Sort(2)
|
||||
public void off(final CommandArgument e) {
|
||||
Checker.offList.add(e.getSender().getName());
|
||||
Log.toSender(e.getSender(), "§c记分板已关闭!");
|
||||
public void off(final Player player) {
|
||||
Checker.offList.add(player.getName());
|
||||
Log.sender(player, "§c记分板已关闭!");
|
||||
}
|
||||
|
||||
@Cmd(permission = "mb.toggle", executor = Executor.PLAYER)
|
||||
@Cmd(permission = "mb.toggle", executor = Cmd.Executor.PLAYER)
|
||||
@Help("打开记分板")
|
||||
@Sort(1)
|
||||
public void on(final CommandArgument e) {
|
||||
Checker.offList.remove(e.getSender().getName());
|
||||
Log.toSender(e.getSender(), "§a记分板已打开!");
|
||||
public void on(final Player player) {
|
||||
Checker.offList.remove(player.getName());
|
||||
Log.sender(player, "§a记分板已打开!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,7 +51,7 @@ public class MiaoBoard extends JavaPlugin implements CommandExecutor {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
scoreBoardManager.start();
|
||||
new CommandManager("mb").register(this);
|
||||
new CommandSub("mb").register(this);
|
||||
new PlayerListener();
|
||||
}
|
||||
|
||||
@ -62,8 +62,8 @@ public class MiaoBoard extends JavaPlugin implements CommandExecutor {
|
||||
|
||||
@Cmd(permission = "mb.reload")
|
||||
@Help("重新载入配置文件")
|
||||
public void reload(final CommandArgument e) {
|
||||
public void reload(final CommandSender sender) {
|
||||
scoreBoardManager.reload();
|
||||
Log.toSender(e.getSender(), "§a配置重载完毕!");
|
||||
Log.sender(sender, "§a配置重载完毕!");
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package pw.yumc.MiaoBoard.config;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import pw.yumc.YumCore.config.InjectConfig;
|
||||
import pw.yumc.YumCore.config.inject.InjectConfig;
|
||||
|
||||
/**
|
||||
* 记分板配置文件类
|
||||
|
@ -12,10 +12,10 @@ import java.util.regex.Pattern;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.kit.StrKit;
|
||||
import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.bukkit.compatible.C;
|
||||
import pw.yumc.YumCore.kit.StrKit;
|
||||
|
||||
public class Replace {
|
||||
public static List<String> $(final Player p, final List<String> text) {
|
||||
@ -31,7 +31,7 @@ public class Replace {
|
||||
}
|
||||
|
||||
private static String p(final Player p, final String text) {
|
||||
return PluginAPI.PlaceholderAPI(p, SimpleRelpace.$(p, text));
|
||||
return PlaceholderAPI.setPlaceholders(p, SimpleRelpace.$(p, text));
|
||||
}
|
||||
|
||||
private static String s(final String text) {
|
||||
@ -141,7 +141,7 @@ public class Replace {
|
||||
try {
|
||||
final long left = df.parse(time).getTime() - System.currentTimeMillis();
|
||||
value = String.valueOf(left / 1000);
|
||||
} catch (final ParseException e) {
|
||||
} catch (final ParseException ignored) {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import pw.yumc.YumCore.config.ConfigNode;
|
||||
import pw.yumc.YumCore.config.InjectConfigurationSection;
|
||||
import pw.yumc.YumCore.config.Nullable;
|
||||
import pw.yumc.YumCore.config.annotation.ConfigNode;
|
||||
import pw.yumc.YumCore.config.annotation.Nullable;
|
||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||
|
||||
/**
|
||||
* 记分板数据模型类
|
||||
|
@ -4,7 +4,7 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
||||
import pw.yumc.YumCore.callback.CallBackReturn;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1,45 +0,0 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.core;
|
||||
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public class Entry {
|
||||
private final SiderbarBoardPage boardPage;
|
||||
private Team team;
|
||||
private final String id;
|
||||
private String last;
|
||||
private final int index;
|
||||
|
||||
public Entry(final SiderbarBoardPage boardPage, final int index) {
|
||||
this.boardPage = boardPage;
|
||||
this.id = String.valueOf(index);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Team getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
if (this.last != null) {
|
||||
this.boardPage.getBoard().resetScores(last);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(final String text, final int score) {
|
||||
this.unregister();
|
||||
final Objective objective = boardPage.getObjective();
|
||||
final Score scoreObject = objective.getScore(text);
|
||||
scoreObject.setScore(score);
|
||||
this.last = text;
|
||||
}
|
||||
}
|
@ -1,14 +1,8 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,15 +10,6 @@ import org.bukkit.scoreboard.Objective;
|
||||
* @author 尘曲
|
||||
*/
|
||||
public class SidebarBoard extends Board {
|
||||
private static final TreeMap<Integer, String> coloursById = new TreeMap<>();
|
||||
|
||||
static {
|
||||
int i = 0;
|
||||
for (final ChatColor chatColor : ChatColor.values()) {
|
||||
coloursById.put(i++, chatColor.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public SidebarBoard(final Plugin plugin, final BoardUpdateFunction updateFunction) {
|
||||
super(plugin, updateFunction);
|
||||
}
|
||||
@ -42,9 +27,7 @@ public class SidebarBoard extends Board {
|
||||
@Override
|
||||
public void update(final Player player) {
|
||||
final SiderbarBoardPage boardPage = this.getBoardPage(player);
|
||||
if (boardPage == null) {
|
||||
return;
|
||||
}
|
||||
if (boardPage == null) { return; }
|
||||
String title = null;
|
||||
if (this.getUpdateFunction().getTitleFunction() != null) {
|
||||
title = this.getUpdateFunction().getTitleFunction().run(player);
|
||||
@ -53,41 +36,8 @@ public class SidebarBoard extends Board {
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
return;
|
||||
}
|
||||
final List<String> newContents = this.getUpdateFunction().getBodyFunction().run(player);
|
||||
this.formatBody(newContents);
|
||||
final Objective objective = boardPage.getObjective();
|
||||
objective.setDisplayName(title);
|
||||
for (int i = 0; i < newContents.size(); i++) {
|
||||
objective.getScore(newContents.get(i)).setScore(newContents.size() - i);
|
||||
}
|
||||
int index = 0;
|
||||
if (boardPage.getLastEntries() != null) {
|
||||
for (; index < boardPage.getLastEntries().size() && index < newContents.size(); index++) {
|
||||
final Entry entry = boardPage.getLastEntries().get(index);
|
||||
entry.update(newContents.get(index), newContents.size() - index - 1);
|
||||
}
|
||||
while (index < boardPage.getLastEntries().size()) {
|
||||
final Entry entry = boardPage.getLastEntries().remove(index);
|
||||
entry.unregister();
|
||||
}
|
||||
}
|
||||
if (boardPage.getLastEntries() == null) {
|
||||
boardPage.setLastEntries(new ArrayList<Entry>());
|
||||
}
|
||||
for (; index < newContents.size(); index++) {
|
||||
final String line = newContents.get(index);
|
||||
final Entry entry = new Entry(boardPage, index);
|
||||
entry.update(line, newContents.size() - index - 1);
|
||||
boardPage.getLastEntries().add(entry);
|
||||
}
|
||||
boardPage.setTitle(title);
|
||||
boardPage.setBody(getUpdateFunction().getBodyFunction().run(player));
|
||||
player.setScoreboard(boardPage.getBoard());
|
||||
}
|
||||
|
||||
private void formatBody(final List<String> texts) {
|
||||
for (int i = 0; i < texts.size(); i++) {
|
||||
final String line = texts.get(i);
|
||||
texts.set(i, line + coloursById.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -13,24 +19,93 @@ import org.bukkit.scoreboard.Objective;
|
||||
public class SiderbarBoardPage extends BoardPage {
|
||||
|
||||
private final Objective objective;
|
||||
private List<Entry> lastEntries;
|
||||
|
||||
private static final List<ChatColor> colors = Arrays.asList(ChatColor.values()); //所有颜色
|
||||
private final List<BoardLine> boardLines = new ArrayList<>();// "行"
|
||||
|
||||
public SiderbarBoardPage() {
|
||||
super();
|
||||
objective = getBoard().registerNewObjective("default", "dummy");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
}
|
||||
|
||||
public List<Entry> getLastEntries() {
|
||||
return lastEntries;
|
||||
for (int i = 0; i < colors.size(); i++) { //循环所有的颜色
|
||||
final ChatColor color = colors.get(i);
|
||||
final Team team = getBoard().registerNewTeam("MiaoboardLine" + i); //为每个颜色注册一个队伍
|
||||
team.addEntry(color.toString()); //为队伍设置一个"行"
|
||||
boardLines.add(new BoardLine(color, team)); //将"行"添加至列表
|
||||
}
|
||||
}
|
||||
|
||||
public Objective getObjective() {
|
||||
return objective;
|
||||
}
|
||||
|
||||
public void setLastEntries(final List<Entry> lastEntries) {
|
||||
this.lastEntries = lastEntries;
|
||||
public void setTitle(String title) {
|
||||
objective.setDisplayName(title);
|
||||
}
|
||||
|
||||
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.getColor().toString()).setScore(line); //设置"行"
|
||||
String prefix = value;
|
||||
String suffix = null;
|
||||
//分割字符串为前16个和后16个
|
||||
if (value.length() > 16) {
|
||||
prefix = value.substring(0, 16);
|
||||
if (ChatColor.getLastColors(prefix) != null && !Objects.equals(ChatColor.getLastColors(prefix), "") && !Objects.equals(ChatColor.getLastColors(prefix), " ")) {
|
||||
//继承前16个字符的颜色
|
||||
suffix = ChatColor.getLastColors(prefix) + value.substring(16, value.length());
|
||||
} else {
|
||||
suffix = ChatColor.RESET + value.substring(16, value.length());
|
||||
}
|
||||
}
|
||||
boardLine.getTeam().setPrefix(prefix); //设置前16个字符
|
||||
if (suffix != null) {
|
||||
boardLine.getTeam().setSuffix(suffix);//"设置后16个字符"
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(int size) {
|
||||
if (size < boardLines.size()) {
|
||||
for (int i = size; i < boardLines.size(); i++) {
|
||||
removeLine(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLine(int line) {
|
||||
final BoardLine boardLine = getBoardLine(line);
|
||||
Validate.notNull(boardLine, "Unable to find BoardLine with index of " + line + "."); //确认是否存在
|
||||
getBoard().resetScores(boardLine.getColor().toString()); //删除这个"行"
|
||||
}
|
||||
|
||||
private BoardLine getBoardLine(int line) {
|
||||
return boardLines.get(line);
|
||||
}
|
||||
|
||||
public void setBody(List<String> newContents) {
|
||||
for (int i = 0; i < newContents.size(); i++) {
|
||||
setValue(newContents.size() - i, newContents.get(i));
|
||||
}
|
||||
clear(newContents.size());
|
||||
}
|
||||
|
||||
class BoardLine {
|
||||
private final ChatColor color;
|
||||
private final Team team;
|
||||
|
||||
public BoardLine(ChatColor color, Team team) {
|
||||
this.color = color;
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public ChatColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public Team getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.updater;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
||||
import pw.yumc.MiaoBoard.MiaoBoard;
|
||||
import pw.yumc.MiaoBoard.misc.Checker;
|
||||
import pw.yumc.MiaoBoard.misc.Replace;
|
||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.callback.CallBackReturn;
|
||||
|
||||
/**
|
||||
* 记分板行更新类
|
||||
@ -24,12 +23,8 @@ public class BodyUpdater extends CallBackReturn.One<Player, List<String>> {
|
||||
|
||||
@Override
|
||||
public List<String> run(final Player param) {
|
||||
final Iterator<BoardModel> iterator = plugin.getScoreBoardManager().getModels().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final BoardModel bmodel = iterator.next();
|
||||
if (Checker.$(param, bmodel)) {
|
||||
return Replace.$(param, bmodel.lines);
|
||||
}
|
||||
for (BoardModel bmodel : plugin.getScoreBoardManager().getModels()) {
|
||||
if (Checker.$(param, bmodel)) { return Replace.$(param, bmodel.lines); }
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.updater;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
||||
import pw.yumc.MiaoBoard.MiaoBoard;
|
||||
import pw.yumc.MiaoBoard.misc.Checker;
|
||||
import pw.yumc.MiaoBoard.misc.Replace;
|
||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.callback.CallBackReturn;
|
||||
|
||||
/**
|
||||
* 记分板标题更新类
|
||||
@ -22,12 +20,8 @@ public class TitleUpdater extends CallBackReturn.One<Player, String> {
|
||||
|
||||
@Override
|
||||
public String run(final Player param) {
|
||||
final Iterator<BoardModel> iterator = plugin.getScoreBoardManager().getModels().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final BoardModel bmodel = iterator.next();
|
||||
if (Checker.$(param, bmodel)) {
|
||||
return Replace.$(param, bmodel.title);
|
||||
}
|
||||
for (BoardModel bmodel : plugin.getScoreBoardManager().getModels()) {
|
||||
if (Checker.$(param, bmodel)) { return Replace.$(param, bmodel.title); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user