diff --git a/pom.xml b/pom.xml index d3d84a4..983f3fc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,129 +1,114 @@ - 4.0.0 - pw.yumc - MiaoBoard - 2.2 - MiaoBoard - 喵式记分板 - - ${project.name} - - - src/main/resources - true - - - - - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-shade-plugin - 2.3 - - false - true - - - pw.yumc:YumCore - cn.citycraft:PluginHelper - - - - - pw.yumc.YumCore - ${project.groupId}.${project.artifactId} - - - cn.citycraft.PluginHelper - ${project.groupId}.${project.artifactId} - - - - - - package - - shade - - - - - - com.github.wvengen - proguard-maven-plugin - - - package - - proguard - - - - - - - - ${java.home}/lib/rt.jar - - - - - - - - - Jenkins - http://ci.yumc.pw/job/${project.artifactId}/ - - - - - DEBUG - UTF-8 - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - yumc-repo - http://repo.yumc.pw/content/groups/public/ - - - - - jtb - YUMC - http://repo.yumc.pw/content/repositories/yumcenter/ - - - - - org.spigotmc - spigot-api - jar - 1.10.2-R0.1-SNAPSHOT - - - cn.citycraft - PluginHelper - jar - 1.0 - - - pw.yumc - YumCore - jar - 1.0 - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + pw.yumc + MiaoBoard + 2.3 + 喵式记分板 + + ${project.artifactId} + + + src/main/resources + true + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + true + + + pw.yumc:YumCore + cn.citycraft:PluginHelper + + + + + pw.yumc.YumCore + ${project.groupId}.${project.artifactId} + + + + + + package + + shade + + + + + + com.github.wvengen + proguard-maven-plugin + + + package + + proguard + + + + + + + + ${java.home}/lib/rt.jar + + + + + + + + + Jenkins + http://ci.yumc.pw/job/${project.artifactId}/ + + + + + DEBUG + UTF-8 + + + + yumc-repo + http://repo.yumc.pw/content/groups/public/ + + + + + jtb + YUMC + http://repo.yumc.pw/content/repositories/yumcenter/ + + + + + org.spigotmc + spigot-api + jar + 1.10.2-R0.1-SNAPSHOT + + + pw.yumc + YumCore + jar + 1.5 + + \ No newline at end of file diff --git a/proguard.conf b/proguard.conf index c9e47c4..94858c6 100644 --- a/proguard.conf +++ b/proguard.conf @@ -10,8 +10,8 @@ # -----启用混淆字典----- -obfuscationdictionary obf.dict --classobfuscationdictionary class.dict --packageobfuscationdictionary class.dict +-classobfuscationdictionary obf.dict +-packageobfuscationdictionary obf.dict # -----保留所有属性 -keepattributes ** @@ -20,35 +20,35 @@ -keep class cn.citycraft.CommonData.** {*;} # -----保护所有实体中的字段名称----- --keepclassmembers class * implements java.io.Serializable { ; } +-keepclassmembers class * implements java.io.Serializable { ; } # -----保护监听方法不被清理----- --keepclassmembers class * implements org.bukkit.event.Listener { - @org.bukkit.event.EventHandler ; +-keepclassmembers class * implements org.bukkit.event.Listener { + @org.bukkit.event.EventHandler ; +} +-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener { + @net.md_5.bungee.event.EventHandler ; } -# -----保护配置注入不被清理----- --keepclassmembers class * extends **.config.InjectConfigurationSection { - ; -} --keepclassmembers class * extends **.config.InjectConfig { - ; -} -# -----保护注解命令方法不被清理----- --keepclassmembers class **.commands.annotation.** { ; } --keepclassmembers class * implements **.commands.CommandExecutor { ; } --keepclassmembers class **.commands.HandlerCommand { ; } --keepclassmembers class * implements **.commands.HandlerCommands { - @**.commands.HandlerCommand ; - @**.commands.HandlerTabComplete ; -} +# -----保护枚举方法的完整性----- +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# -----保护配置注入不被清理----- +-keepclassmembers class * extends **.config**Inject** { + ; +} + +# -----保护注解命令方法不被清理----- +-keepclassmembers class **.commands.annotation.** { ; } +-keepclassmembers class * implements **.commands**CommandExecutor { ; } + # -----保护注解NotProguard标记----- -keep class **.NotProguard -keep @**.NotProguard class * {*;} --keepclassmembers class * { - @**.NotProguard ; - @**.NotProguard ; -} - -# -----保护命令解析正常----- --keepnames class * extends **.commands.BaseCommand \ No newline at end of file +-keepclassmembers class * { + @**.NotProguard ; + @**.NotProguard ; +} \ No newline at end of file diff --git a/src/main/java/pw/yumc/MiaoBoard/MiaoBoard.java b/src/main/java/pw/yumc/MiaoBoard/MiaoBoard.java index 93c6560..0c77a24 100644 --- a/src/main/java/pw/yumc/MiaoBoard/MiaoBoard.java +++ b/src/main/java/pw/yumc/MiaoBoard/MiaoBoard.java @@ -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配置重载完毕!"); } } diff --git a/src/main/java/pw/yumc/MiaoBoard/config/MiaoBoardConfig.java b/src/main/java/pw/yumc/MiaoBoard/config/MiaoBoardConfig.java index 4eda9f8..c70efb9 100644 --- a/src/main/java/pw/yumc/MiaoBoard/config/MiaoBoardConfig.java +++ b/src/main/java/pw/yumc/MiaoBoard/config/MiaoBoardConfig.java @@ -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; /** * 记分板配置文件类 diff --git a/src/main/java/pw/yumc/MiaoBoard/misc/Replace.java b/src/main/java/pw/yumc/MiaoBoard/misc/Replace.java index bf57022..969144a 100644 --- a/src/main/java/pw/yumc/MiaoBoard/misc/Replace.java +++ b/src/main/java/pw/yumc/MiaoBoard/misc/Replace.java @@ -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 $(final Player p, final List 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; } diff --git a/src/main/java/pw/yumc/MiaoBoard/model/BoardModel.java b/src/main/java/pw/yumc/MiaoBoard/model/BoardModel.java index c6f68aa..d3393fa 100644 --- a/src/main/java/pw/yumc/MiaoBoard/model/BoardModel.java +++ b/src/main/java/pw/yumc/MiaoBoard/model/BoardModel.java @@ -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; /** * 记分板数据模型类 diff --git a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/BoardUpdateFunction.java b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/BoardUpdateFunction.java index cd04ebd..eb060f0 100644 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/BoardUpdateFunction.java +++ b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/BoardUpdateFunction.java @@ -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; /** * diff --git a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/Entry.java b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/Entry.java deleted file mode 100644 index 71826a7..0000000 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/Entry.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SidebarBoard.java b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SidebarBoard.java index 76aa6f0..2a9f915 100644 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SidebarBoard.java +++ b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SidebarBoard.java @@ -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 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 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()); - } - 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 texts) { - for (int i = 0; i < texts.size(); i++) { - final String line = texts.get(i); - texts.set(i, line + coloursById.get(i)); - } - } - } 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 13b8b0c..d3d9bcf 100644 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPage.java +++ b/src/main/java/pw/yumc/MiaoBoard/scoreboard/core/SiderbarBoardPage.java @@ -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 lastEntries; + + private static final List colors = Arrays.asList(ChatColor.values()); //所有颜色 + private final List boardLines = new ArrayList<>();// "行" public SiderbarBoardPage() { super(); objective = getBoard().registerNewObjective("default", "dummy"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); - } - - public List 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 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 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; + } + + } } diff --git a/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/BodyUpdater.java b/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/BodyUpdater.java index 70c1a7e..272c74d 100644 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/BodyUpdater.java +++ b/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/BodyUpdater.java @@ -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> { @Override public List run(final Player param) { - final Iterator 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(); } diff --git a/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/TitleUpdater.java b/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/TitleUpdater.java index 8096e3b..be2be1f 100644 --- a/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/TitleUpdater.java +++ b/src/main/java/pw/yumc/MiaoBoard/scoreboard/updater/TitleUpdater.java @@ -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 { @Override public String run(final Player param) { - final Iterator 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; }