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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>MiaoBoard</artifactId>
|
<artifactId>MiaoBoard</artifactId>
|
||||||
<version>2.2</version>
|
<version>2.3</version>
|
||||||
<name>MiaoBoard</name>
|
<description>喵式记分板</description>
|
||||||
<description>喵式记分板</description>
|
<build>
|
||||||
<build>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<finalName>${project.name}</finalName>
|
<resources>
|
||||||
<resources>
|
<resource>
|
||||||
<resource>
|
<directory>src/main/resources</directory>
|
||||||
<directory>src/main/resources</directory>
|
<filtering>true</filtering>
|
||||||
<filtering>true</filtering>
|
</resource>
|
||||||
</resource>
|
</resources>
|
||||||
</resources>
|
<plugins>
|
||||||
<plugins>
|
<plugin>
|
||||||
<plugin>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<version>3.1</version>
|
||||||
<version>3.1</version>
|
<configuration>
|
||||||
<configuration>
|
<source>1.7</source>
|
||||||
<source>1.7</source>
|
<target>1.7</target>
|
||||||
<target>1.7</target>
|
</configuration>
|
||||||
</configuration>
|
</plugin>
|
||||||
</plugin>
|
<plugin>
|
||||||
<plugin>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<version>2.3</version>
|
||||||
<version>2.3</version>
|
<configuration>
|
||||||
<configuration>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<minimizeJar>true</minimizeJar>
|
||||||
<minimizeJar>true</minimizeJar>
|
<artifactSet>
|
||||||
<artifactSet>
|
<includes>
|
||||||
<includes>
|
<include>pw.yumc:YumCore</include>
|
||||||
<include>pw.yumc:YumCore</include>
|
<include>cn.citycraft:PluginHelper</include>
|
||||||
<include>cn.citycraft:PluginHelper</include>
|
</includes>
|
||||||
</includes>
|
</artifactSet>
|
||||||
</artifactSet>
|
<relocations>
|
||||||
<relocations>
|
<relocation>
|
||||||
<relocation>
|
<pattern>pw.yumc.YumCore</pattern>
|
||||||
<pattern>pw.yumc.YumCore</pattern>
|
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
</relocation>
|
||||||
</relocation>
|
</relocations>
|
||||||
<relocation>
|
</configuration>
|
||||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
<executions>
|
||||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
<execution>
|
||||||
</relocation>
|
<phase>package</phase>
|
||||||
</relocations>
|
<goals>
|
||||||
</configuration>
|
<goal>shade</goal>
|
||||||
<executions>
|
</goals>
|
||||||
<execution>
|
</execution>
|
||||||
<phase>package</phase>
|
</executions>
|
||||||
<goals>
|
</plugin>
|
||||||
<goal>shade</goal>
|
<plugin>
|
||||||
</goals>
|
<groupId>com.github.wvengen</groupId>
|
||||||
</execution>
|
<artifactId>proguard-maven-plugin</artifactId>
|
||||||
</executions>
|
<executions>
|
||||||
</plugin>
|
<execution>
|
||||||
<plugin>
|
<phase>package</phase>
|
||||||
<groupId>com.github.wvengen</groupId>
|
<goals>
|
||||||
<artifactId>proguard-maven-plugin</artifactId>
|
<goal>proguard</goal>
|
||||||
<executions>
|
</goals>
|
||||||
<execution>
|
<configuration>
|
||||||
<phase>package</phase>
|
<options>
|
||||||
<goals>
|
<option>-repackageclasses \ʼ.ʽ.ʾ.${project.artifactId}</option>
|
||||||
<goal>proguard</goal>
|
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
||||||
</goals>
|
</options>
|
||||||
<configuration>
|
<libs>
|
||||||
<options>
|
<lib>${java.home}/lib/rt.jar</lib>
|
||||||
<option>-repackageclasses nul.j.for.t.class.b</option>
|
</libs>
|
||||||
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
</configuration>
|
||||||
</options>
|
</execution>
|
||||||
<libs>
|
</executions>
|
||||||
<lib>${java.home}/lib/rt.jar</lib>
|
</plugin>
|
||||||
</libs>
|
</plugins>
|
||||||
</configuration>
|
</build>
|
||||||
</execution>
|
<ciManagement>
|
||||||
</executions>
|
<system>Jenkins</system>
|
||||||
</plugin>
|
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||||
</plugins>
|
</ciManagement>
|
||||||
</build>
|
<properties>
|
||||||
<ciManagement>
|
<update.description></update.description>
|
||||||
<system>Jenkins</system>
|
<update.changes></update.changes>
|
||||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||||
</ciManagement>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<properties>
|
</properties>
|
||||||
<update.description></update.description>
|
<repositories>
|
||||||
<update.changes></update.changes>
|
<repository>
|
||||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
<id>yumc-repo</id>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||||
</properties>
|
</repository>
|
||||||
<repositories>
|
</repositories>
|
||||||
<repository>
|
<distributionManagement>
|
||||||
<id>spigot-repo</id>
|
<repository>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
<id>jtb</id>
|
||||||
</repository>
|
<name>YUMC</name>
|
||||||
<repository>
|
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||||
<id>yumc-repo</id>
|
</repository>
|
||||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
</distributionManagement>
|
||||||
</repository>
|
<dependencies>
|
||||||
</repositories>
|
<dependency>
|
||||||
<distributionManagement>
|
<groupId>org.spigotmc</groupId>
|
||||||
<repository>
|
<artifactId>spigot-api</artifactId>
|
||||||
<id>jtb</id>
|
<type>jar</type>
|
||||||
<name>YUMC</name>
|
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
</dependency>
|
||||||
</repository>
|
<dependency>
|
||||||
</distributionManagement>
|
<groupId>pw.yumc</groupId>
|
||||||
<dependencies>
|
<artifactId>YumCore</artifactId>
|
||||||
<dependency>
|
<type>jar</type>
|
||||||
<groupId>org.spigotmc</groupId>
|
<version>1.5</version>
|
||||||
<artifactId>spigot-api</artifactId>
|
</dependency>
|
||||||
<type>jar</type>
|
</dependencies>
|
||||||
<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>
|
|
||||||
</project>
|
</project>
|
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
# -----启用混淆字典-----
|
# -----启用混淆字典-----
|
||||||
-obfuscationdictionary obf.dict
|
-obfuscationdictionary obf.dict
|
||||||
-classobfuscationdictionary class.dict
|
-classobfuscationdictionary obf.dict
|
||||||
-packageobfuscationdictionary class.dict
|
-packageobfuscationdictionary obf.dict
|
||||||
|
|
||||||
# -----保留所有属性
|
# -----保留所有属性
|
||||||
-keepattributes **
|
-keepattributes **
|
||||||
@ -26,22 +26,25 @@
|
|||||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||||
@org.bukkit.event.EventHandler <methods>;
|
@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 {
|
-keepclassmembers class * extends **.config**Inject** {
|
||||||
<fields>;
|
|
||||||
}
|
|
||||||
-keepclassmembers class * extends **.config.InjectConfig {
|
|
||||||
<fields>;
|
<fields>;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护注解命令方法不被清理-----
|
# -----保护注解命令方法不被清理-----
|
||||||
-keepclassmembers class **.commands.annotation.** { <methods>; }
|
-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标记-----
|
# -----保护注解NotProguard标记-----
|
||||||
-keep class **.NotProguard
|
-keep class **.NotProguard
|
||||||
-keep @**.NotProguard class * {*;}
|
-keep @**.NotProguard class * {*;}
|
||||||
@ -49,6 +52,3 @@
|
|||||||
@**.NotProguard <fields>;
|
@**.NotProguard <fields>;
|
||||||
@**.NotProguard <methods>;
|
@**.NotProguard <methods>;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护命令解析正常-----
|
|
||||||
-keepnames class * extends **.commands.BaseCommand
|
|
@ -1,18 +1,18 @@
|
|||||||
package pw.yumc.MiaoBoard;
|
package pw.yumc.MiaoBoard;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import pw.yumc.MiaoBoard.listener.PlayerListener;
|
import pw.yumc.MiaoBoard.listener.PlayerListener;
|
||||||
import pw.yumc.MiaoBoard.misc.Checker;
|
import pw.yumc.MiaoBoard.misc.Checker;
|
||||||
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.commands.CommandArgument;
|
import pw.yumc.YumCore.commands.CommandSub;
|
||||||
import pw.yumc.YumCore.commands.CommandExecutor;
|
|
||||||
import pw.yumc.YumCore.commands.CommandManager;
|
|
||||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
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.Help;
|
||||||
import pw.yumc.YumCore.commands.annotation.Sort;
|
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
|
* @since 2016年6月4日 上午9:08:13
|
||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
*/
|
*/
|
||||||
public class MiaoBoard extends JavaPlugin implements CommandExecutor {
|
public class MiaoBoard extends JavaPlugin implements Executor {
|
||||||
private ScoreBoardManager scoreBoardManager;
|
private ScoreBoardManager scoreBoardManager;
|
||||||
|
|
||||||
public ScoreBoardManager getScoreBoardManager() {
|
public ScoreBoardManager getScoreBoardManager() {
|
||||||
return scoreBoardManager;
|
return scoreBoardManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(permission = "mb.toggle", executor = Executor.PLAYER)
|
@Cmd(permission = "mb.toggle", executor = Cmd.Executor.PLAYER)
|
||||||
@Help("关闭记分板")
|
@Help("关闭记分板")
|
||||||
@Sort(2)
|
@Sort(2)
|
||||||
public void off(final CommandArgument e) {
|
public void off(final Player player) {
|
||||||
Checker.offList.add(e.getSender().getName());
|
Checker.offList.add(player.getName());
|
||||||
Log.toSender(e.getSender(), "§c记分板已关闭!");
|
Log.sender(player, "§c记分板已关闭!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(permission = "mb.toggle", executor = Executor.PLAYER)
|
@Cmd(permission = "mb.toggle", executor = Cmd.Executor.PLAYER)
|
||||||
@Help("打开记分板")
|
@Help("打开记分板")
|
||||||
@Sort(1)
|
@Sort(1)
|
||||||
public void on(final CommandArgument e) {
|
public void on(final Player player) {
|
||||||
Checker.offList.remove(e.getSender().getName());
|
Checker.offList.remove(player.getName());
|
||||||
Log.toSender(e.getSender(), "§a记分板已打开!");
|
Log.sender(player, "§a记分板已打开!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,7 +51,7 @@ public class MiaoBoard extends JavaPlugin implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
scoreBoardManager.start();
|
scoreBoardManager.start();
|
||||||
new CommandManager("mb").register(this);
|
new CommandSub("mb").register(this);
|
||||||
new PlayerListener();
|
new PlayerListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ public class MiaoBoard extends JavaPlugin implements CommandExecutor {
|
|||||||
|
|
||||||
@Cmd(permission = "mb.reload")
|
@Cmd(permission = "mb.reload")
|
||||||
@Help("重新载入配置文件")
|
@Help("重新载入配置文件")
|
||||||
public void reload(final CommandArgument e) {
|
public void reload(final CommandSender sender) {
|
||||||
scoreBoardManager.reload();
|
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.Collections;
|
||||||
import java.util.List;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.kit.StrKit;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
|
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
import pw.yumc.YumCore.bukkit.compatible.C;
|
import pw.yumc.YumCore.bukkit.compatible.C;
|
||||||
|
import pw.yumc.YumCore.kit.StrKit;
|
||||||
|
|
||||||
public class Replace {
|
public class Replace {
|
||||||
public static List<String> $(final Player p, final List<String> text) {
|
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) {
|
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) {
|
private static String s(final String text) {
|
||||||
@ -141,7 +141,7 @@ public class Replace {
|
|||||||
try {
|
try {
|
||||||
final long left = df.parse(time).getTime() - System.currentTimeMillis();
|
final long left = df.parse(time).getTime() - System.currentTimeMillis();
|
||||||
value = String.valueOf(left / 1000);
|
value = String.valueOf(left / 1000);
|
||||||
} catch (final ParseException e) {
|
} catch (final ParseException ignored) {
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import pw.yumc.YumCore.config.ConfigNode;
|
import pw.yumc.YumCore.config.annotation.ConfigNode;
|
||||||
import pw.yumc.YumCore.config.InjectConfigurationSection;
|
import pw.yumc.YumCore.config.annotation.Nullable;
|
||||||
import pw.yumc.YumCore.config.Nullable;
|
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记分板数据模型类
|
* 记分板数据模型类
|
||||||
|
@ -4,7 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
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;
|
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.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scoreboard.Objective;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,15 +10,6 @@ import org.bukkit.scoreboard.Objective;
|
|||||||
* @author 尘曲
|
* @author 尘曲
|
||||||
*/
|
*/
|
||||||
public class SidebarBoard extends Board {
|
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) {
|
public SidebarBoard(final Plugin plugin, final BoardUpdateFunction updateFunction) {
|
||||||
super(plugin, updateFunction);
|
super(plugin, updateFunction);
|
||||||
}
|
}
|
||||||
@ -42,9 +27,7 @@ public class SidebarBoard extends Board {
|
|||||||
@Override
|
@Override
|
||||||
public void update(final Player player) {
|
public void update(final Player player) {
|
||||||
final SiderbarBoardPage boardPage = this.getBoardPage(player);
|
final SiderbarBoardPage boardPage = this.getBoardPage(player);
|
||||||
if (boardPage == null) {
|
if (boardPage == null) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
String title = null;
|
String title = null;
|
||||||
if (this.getUpdateFunction().getTitleFunction() != null) {
|
if (this.getUpdateFunction().getTitleFunction() != null) {
|
||||||
title = this.getUpdateFunction().getTitleFunction().run(player);
|
title = this.getUpdateFunction().getTitleFunction().run(player);
|
||||||
@ -53,41 +36,8 @@ public class SidebarBoard extends Board {
|
|||||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final List<String> newContents = this.getUpdateFunction().getBodyFunction().run(player);
|
boardPage.setTitle(title);
|
||||||
this.formatBody(newContents);
|
boardPage.setBody(getUpdateFunction().getBodyFunction().run(player));
|
||||||
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);
|
|
||||||
}
|
|
||||||
player.setScoreboard(boardPage.getBoard());
|
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;
|
package pw.yumc.MiaoBoard.scoreboard.core;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
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.DisplaySlot;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -13,24 +19,93 @@ import org.bukkit.scoreboard.Objective;
|
|||||||
public class SiderbarBoardPage extends BoardPage {
|
public class SiderbarBoardPage extends BoardPage {
|
||||||
|
|
||||||
private final Objective objective;
|
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() {
|
public SiderbarBoardPage() {
|
||||||
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++) { //循环所有的颜色
|
||||||
|
final ChatColor color = colors.get(i);
|
||||||
public List<Entry> getLastEntries() {
|
final Team team = getBoard().registerNewTeam("MiaoboardLine" + i); //为每个颜色注册一个队伍
|
||||||
return lastEntries;
|
team.addEntry(color.toString()); //为队伍设置一个"行"
|
||||||
|
boardLines.add(new BoardLine(color, team)); //将"行"添加至列表
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Objective getObjective() {
|
public Objective getObjective() {
|
||||||
return objective;
|
return objective;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastEntries(final List<Entry> lastEntries) {
|
public void setTitle(String title) {
|
||||||
this.lastEntries = lastEntries;
|
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;
|
package pw.yumc.MiaoBoard.scoreboard.updater;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
|
||||||
import pw.yumc.MiaoBoard.MiaoBoard;
|
import pw.yumc.MiaoBoard.MiaoBoard;
|
||||||
import pw.yumc.MiaoBoard.misc.Checker;
|
import pw.yumc.MiaoBoard.misc.Checker;
|
||||||
import pw.yumc.MiaoBoard.misc.Replace;
|
import pw.yumc.MiaoBoard.misc.Replace;
|
||||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
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
|
@Override
|
||||||
public List<String> run(final Player param) {
|
public List<String> run(final Player param) {
|
||||||
final Iterator<BoardModel> iterator = plugin.getScoreBoardManager().getModels().iterator();
|
for (BoardModel bmodel : plugin.getScoreBoardManager().getModels()) {
|
||||||
while (iterator.hasNext()) {
|
if (Checker.$(param, bmodel)) { return Replace.$(param, bmodel.lines); }
|
||||||
final BoardModel bmodel = iterator.next();
|
|
||||||
if (Checker.$(param, bmodel)) {
|
|
||||||
return Replace.$(param, bmodel.lines);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package pw.yumc.MiaoBoard.scoreboard.updater;
|
package pw.yumc.MiaoBoard.scoreboard.updater;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
|
||||||
import pw.yumc.MiaoBoard.MiaoBoard;
|
import pw.yumc.MiaoBoard.MiaoBoard;
|
||||||
import pw.yumc.MiaoBoard.misc.Checker;
|
import pw.yumc.MiaoBoard.misc.Checker;
|
||||||
import pw.yumc.MiaoBoard.misc.Replace;
|
import pw.yumc.MiaoBoard.misc.Replace;
|
||||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
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
|
@Override
|
||||||
public String run(final Player param) {
|
public String run(final Player param) {
|
||||||
final Iterator<BoardModel> iterator = plugin.getScoreBoardManager().getModels().iterator();
|
for (BoardModel bmodel : plugin.getScoreBoardManager().getModels()) {
|
||||||
while (iterator.hasNext()) {
|
if (Checker.$(param, bmodel)) { return Replace.$(param, bmodel.title); }
|
||||||
final BoardModel bmodel = iterator.next();
|
|
||||||
if (Checker.$(param, bmodel)) {
|
|
||||||
return Replace.$(param, bmodel.title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user