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

feat: 2.0正式版完成

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-06 21:43:30 +08:00
parent 2e513d3b9f
commit 6cc671eb89
19 changed files with 511 additions and 90 deletions

View File

@ -3,8 +3,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>MiaoBoard</artifactId>
<version>1.4.6</version>
<version>2.0</version>
<name>MiaoBoard</name>
<description>喵式记分板</description>
<build>
<finalName>${project.name}</finalName>
<resources>

View File

@ -5,14 +5,13 @@ 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.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.commands.annotation.Sort;
import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask;
/**
* 喵式记分板主类
@ -21,46 +20,49 @@ import pw.yumc.YumCore.update.SubscribeTask;
* @author
*/
public class MiaoBoard extends JavaPlugin implements CommandExecutor {
private ScoreBoardManager scoreBoardManager;
@Cmd()
public ScoreBoardManager getScoreBoardManager() {
return scoreBoardManager;
}
@Cmd(permission = "mb.toggle")
@Help("关闭记分板")
@Sort(2)
public void off(final CommandArgument e) {
Checker.offList.add(e.getSender().getName());
e.getSender().sendMessage("§c记分板已关闭!");
Log.toSender(e.getSender(), "§c记分板已关闭!");
}
@Cmd()
@Cmd(permission = "mb.toggle")
@Help("打开记分板")
@Sort(1)
public void on(final CommandArgument e) {
Checker.offList.remove(e.getSender().getName());
e.getSender().sendMessage("§a记分板已打开!");
Log.toSender(e.getSender(), "§a记分板已打开!");
}
@Override
public void onDisable() {
ScoreBoardManager.getSidebarBoard().cancel();
scoreBoardManager.getSidebarBoard().cancel();
}
@Override
public void onEnable() {
ScoreBoardManager.start();
scoreBoardManager.start();
new CommandManager("mb").register(this);
new PlayerListener();
new Statistics();
new SubscribeTask(true, true);
}
@Override
public void onLoad() {
ScoreBoardManager.load();
scoreBoardManager = new ScoreBoardManager();
}
@Cmd(permission = "mb.reload")
@Help("重新载入配置文件")
public void reload(final CommandArgument e) {
ScoreBoardManager.reload();
e.getSender().sendMessage("§a配置重载完毕!");
scoreBoardManager.reload();
Log.toSender(e.getSender(), "§a配置重载完毕!");
}
}

View File

@ -1,20 +1,20 @@
package pw.yumc.MiaoBoard.config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import cn.citycraft.PluginHelper.config.InjectConfig;
import pw.yumc.YumCore.config.InjectConfig;
/**
* 记分板配置文件类
*
*
* @since 2016年7月21日 下午5:21:13
* @author
*/
public class MiaoBoardConfig extends InjectConfig {
public static Integer UpdateTime;
public static List<String> DisableWorld = new ArrayList<>();
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();;
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();
private Integer UpdateTime;
private List<String> DisableWorld;
public static MiaoBoardConfig i() {
return instance;
@ -23,4 +23,15 @@ public class MiaoBoardConfig extends InjectConfig {
public static void reInject() {
instance.reload();
}
public List<String> getDisableWorld() {
if (DisableWorld == null) {
DisableWorld = Collections.emptyList();
}
return DisableWorld;
}
public Integer getUpdateTime() {
return UpdateTime;
}
}

View File

@ -7,9 +7,11 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import pw.yumc.MiaoBoard.MiaoBoard;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask;
/**
* 玩家监听
@ -18,28 +20,30 @@ import pw.yumc.YumCore.bukkit.P;
* @author
*/
public class PlayerListener implements Listener {
MiaoBoard plugin = P.getPlugin();
public PlayerListener() {
Bukkit.getPluginManager().registerEvents(this, P.instance);
Bukkit.getPluginManager().registerEvents(this, plugin);
new Statistics();
new SubscribeTask(true, true);
}
@EventHandler
public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) {
if (MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
ScoreBoardManager.getSidebarBoard().removeTarget(e.getPlayer());
if (MiaoBoardConfig.i().getDisableWorld().contains(e.getPlayer().getWorld().getName())) {
plugin.getScoreBoardManager().getSidebarBoard().removeTarget(e.getPlayer());
} else {
ScoreBoardManager.getSidebarBoard().addTarget(e.getPlayer());
plugin.getScoreBoardManager().getSidebarBoard().addTarget(e.getPlayer());
}
}
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent e) {
if (!MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
ScoreBoardManager.getSidebarBoard().addTarget(e.getPlayer());
}
plugin.getScoreBoardManager().addTarget(e.getPlayer());
}
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent e) {
ScoreBoardManager.getSidebarBoard().removeTarget(e.getPlayer());
plugin.getScoreBoardManager().getSidebarBoard().removeTarget(e.getPlayer());
}
}

View File

@ -16,6 +16,6 @@ public class Checker {
public static boolean dataCheck(final BoardModel model) {
final long now = System.currentTimeMillis();
return model.time_start != null && model.time_start.getTime() <= now && model.time_end != null && now <= model.time_end.getTime();
return (model.time_start == null || model.time_start.getTime() <= now) && (model.time_end == null || now <= model.time_end.getTime());
}
}

View File

@ -4,9 +4,11 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.kit.StrKit;
@ -15,12 +17,19 @@ import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.bukkit.compatible.C;
public class Replace {
public static List<String> $(final Player p, final List<String> text) {
for (int i = 0; i < text.size(); i++) {
text.set(i, $(p, text.get(i)));
}
return text;
}
public static String $(final Player p, final String text) {
return s(p(p, text));
}
private static String p(final Player p, final String text) {
return SimpleRelpace.$(p, PluginAPI.PlaceholderAPI(p, text));
return PluginAPI.PlaceholderAPI(p, SimpleRelpace.$(p, text));
}
private static String s(final String text) {
@ -30,7 +39,6 @@ public class Replace {
static class SimpleRelpace {
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
private static final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final String EMPTY = "";
public static String $(final Player player, String text) {
final Matcher m = PLACEHOLDER_PATTERN.matcher(text);
@ -38,7 +46,7 @@ public class Replace {
final String format = m.group(1);
if (format.contains("_")) {
final String[] ka = format.split("_", 2);
String value = format;
String value = null;
switch (ka[0]) {
case "player":
value = player(player, ka[1]);
@ -53,7 +61,9 @@ public class Replace {
value = time(player, ka[1]);
break;
}
text = text.replace("%" + format + "%", Matcher.quoteReplacement(value));
if (value != null) {
text = text.replace("%" + format + "%", Matcher.quoteReplacement(value));
}
}
}
return text;
@ -82,20 +92,20 @@ public class Replace {
case "max_health":
return String.valueOf(player.getMaxHealth());
default:
return EMPTY;
return String.format("%%player_%s%%", key);
}
}
private static String plugin(final Player player, final String key) {
switch (key) {
case "version":
return P.getDescription().getVersion();
return P.getDescription().getVersion().split("-")[0];
case "name":
return P.getName();
case "author":
return Arrays.toString(P.getDescription().getAuthors().toArray());
default:
return EMPTY;
return String.format("%%plugin_%s%%", key);
}
}
@ -104,6 +114,10 @@ public class Replace {
switch (key) {
case "online":
return String.valueOf(C.Player.getOnlinePlayers().size());
case "max":
return String.valueOf(Bukkit.getMaxPlayers());
case "unique_joins":
return String.valueOf(Bukkit.getOfflinePlayers().length);
case "ram_used":
return String.valueOf((runtime.totalMemory() - runtime.freeMemory()) / 1048576L);
case "ram_free":
@ -113,14 +127,14 @@ public class Replace {
case "ram_max":
return String.valueOf(runtime.maxMemory() / 1048576L);
default:
return EMPTY;
return String.format("%%server_%s%%", key);
}
}
private static String time(final Player player, final String key) {
final Date date = new Date();
if (key.startsWith("left") && key.contains("_")) {
final String time = key.split("_")[1].replace("`", " ");
final String time = key.split("_")[1];
String value = "解析错误";
try {
final long left = df.parse(time).getTime() - System.currentTimeMillis();
@ -145,7 +159,7 @@ public class Replace {
case "second":
return String.valueOf(date.getSeconds());
}
return EMPTY;
return String.format("%%time_%s%%", key);
}
}
}

View File

@ -5,7 +5,9 @@ import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import cn.citycraft.PluginHelper.config.InjectConfigurationSection;
import pw.yumc.YumCore.config.ConfigNode;
import pw.yumc.YumCore.config.InjectConfigurationSection;
import pw.yumc.YumCore.config.Nullable;
/**
* 记分板数据模型类
@ -16,7 +18,11 @@ import cn.citycraft.PluginHelper.config.InjectConfigurationSection;
public class BoardModel extends InjectConfigurationSection {
public transient String name;
public Integer index;
@Nullable
@ConfigNode("time.start")
public Date time_start;
@Nullable
@ConfigNode("time.end")
public Date time_end;
public String title;
public String permission;

View File

@ -7,16 +7,16 @@ import java.util.List;
import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.scoreboard.BoardUpdateFunction;
import cn.citycraft.PluginHelper.scoreboard.Condition;
import cn.citycraft.PluginHelper.scoreboard.SidebarBoard;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.model.BoardModel;
import pw.yumc.MiaoBoard.scoreboard.core.BoardUpdateFunction;
import pw.yumc.MiaoBoard.scoreboard.core.Condition;
import pw.yumc.MiaoBoard.scoreboard.core.SidebarBoard;
import pw.yumc.MiaoBoard.scoreboard.updater.BodyUpdater;
import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.bukkit.compatible.C;
import pw.yumc.YumCore.config.FileConfig;
/**
* 记分板管理类
@ -25,20 +25,30 @@ import pw.yumc.YumCore.bukkit.compatible.C;
* @author
*/
public class ScoreBoardManager {
public static Status cot = new Status();
public static SidebarBoard sbd = new SidebarBoard(P.instance, new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
public static FileConfig config = MiaoBoardConfig.i().getConfig();;
public static List<BoardModel> bms = new LinkedList<>();
public Status cot = new Status();
public SidebarBoard sbd = new SidebarBoard(P.instance, new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
public FileConfig config = MiaoBoardConfig.i().getConfig();
public List<BoardModel> bms = new LinkedList<>();
public static List<BoardModel> getModels() {
public ScoreBoardManager() {
load();
}
public void addTarget(final Player player) {
if (!MiaoBoardConfig.i().getDisableWorld().contains(player.getWorld().getName())) {
getSidebarBoard().addTarget(player);
}
}
public List<BoardModel> getModels() {
return bms;
}
public static SidebarBoard getSidebarBoard() {
public SidebarBoard getSidebarBoard() {
return sbd;
}
public static void load() {
public void load() {
bms.clear();
for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) {
bms.add(new BoardModel(config.getConfigurationSection("Boards." + bmn)).setName(bmn));
@ -46,28 +56,28 @@ public class ScoreBoardManager {
Collections.sort(bms, new BoardComparator());
}
public static void reload() {
public void reload() {
sbd.cancel();
MiaoBoardConfig.reInject();
load();
start();
}
public static void start() {
sbd.update(cot.set(true), MiaoBoardConfig.UpdateTime);
public void start() {
sbd.update(cot.set(true), MiaoBoardConfig.i().getUpdateTime());
for (final Player player : C.Player.getOnlinePlayers()) {
sbd.addTarget(player);
addTarget(player);
}
}
private static class BoardComparator implements Comparator<BoardModel> {
private class BoardComparator implements Comparator<BoardModel> {
@Override
public int compare(final BoardModel o1, final BoardModel o2) {
return o1.index.compareTo(o2.index);
}
}
private static class Status implements Condition {
private class Status implements Condition {
private boolean status = true;
@Override

View File

@ -0,0 +1,122 @@
package pw.yumc.MiaoBoard.scoreboard.core;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
*/
public abstract class Board implements Iterable<Player> {
private final Plugin plugin;
private int taskId;
private final HashMap<Player, BoardPage> targets = new HashMap<>();
private final Set<Player> removeQueue = new HashSet<>();
private final BoardUpdateFunction updateFunction;
public Board(final Plugin plugin, final BoardUpdateFunction updateFunction) {
this.updateFunction = updateFunction;
this.plugin = plugin;
}
public boolean addTarget(final Player player) {
if (!this.isTarget(player)) {
final BoardPage boardPage = this.newPage();
this.targets.put(player, boardPage);
player.setScoreboard(boardPage.getBoard());
this.update(player);
return true;
}
return false;
}
public void cancel() {
if (taskId != 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = 0;
for (final Player player : this.targets.keySet()) {
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
}
this.targets.clear();
this.removeQueue.clear();
}
}
public BoardPage getBoardPage(final Player player) {
return this.targets.get(player);
}
public Plugin getPlugin() {
return plugin;
}
public Set<Player> getTargets() {
return targets.keySet();
}
public BoardUpdateFunction getUpdateFunction() {
return updateFunction;
}
public boolean isRunning() {
return this.taskId != 0;
}
public boolean isTarget(final Player player) {
return this.targets.containsKey(player);
}
@Override
public Iterator<Player> iterator() {
return this.targets.keySet().iterator();
}
public abstract BoardPage newPage();
public boolean removeTarget(final Player player) {
if (this.isTarget(player)) {
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
return this.removeQueue.add(player);
}
return false;
}
public void update(final Condition condition, final int interval) {
taskId = plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
@Override
public void run() {
if (condition.get()) {
final Iterator<Player> iterator = iterator();
while (iterator.hasNext()) {
final Player next = iterator.next();
if (shouldRemove(next)) {
iterator.remove();
} else {
update(next);
}
}
} else {
cancel();
}
}
}, 0, interval).getTaskId();
}
public abstract void update(Player p);
private boolean shouldRemove(final Player player) {
return this.removeQueue.remove(player);
}
}

View File

@ -0,0 +1,23 @@
package pw.yumc.MiaoBoard.scoreboard.core;
import org.bukkit.Bukkit;
import org.bukkit.scoreboard.Scoreboard;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
*/
public abstract class BoardPage {
private final Scoreboard board;
public BoardPage() {
board = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
}
public Scoreboard getBoard() {
return board;
}
}

View File

@ -0,0 +1,39 @@
package pw.yumc.MiaoBoard.scoreboard.core;
import java.util.List;
import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.callback.CallBackReturn;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
*/
public class BoardUpdateFunction {
private CallBackReturn.One<Player, String> titleFunction;
private CallBackReturn.One<Player, List<String>> bodyFunction;
public BoardUpdateFunction(final CallBackReturn.One<Player, String> titleFunction, final CallBackReturn.One<Player, List<String>> bodyFunction) {
this.titleFunction = titleFunction;
this.bodyFunction = bodyFunction;
}
public CallBackReturn.One<Player, List<String>> getBodyFunction() {
return bodyFunction;
}
public CallBackReturn.One<Player, String> getTitleFunction() {
return titleFunction;
}
public void setBodyFunction(final CallBackReturn.One<Player, List<String>> bodyFunction) {
this.bodyFunction = bodyFunction;
}
public void setTitleFunction(final CallBackReturn.One<Player, String> titleFunction) {
this.titleFunction = titleFunction;
}
}

View File

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

View File

@ -0,0 +1,45 @@
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;
}
}

View File

@ -0,0 +1,90 @@
package pw.yumc.MiaoBoard.scoreboard.core;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scoreboard.Objective;
/**
*
* @since 2016年7月4日 下午4:40:21
* @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);
}
@Override
public SiderbarBoardPage getBoardPage(final Player player) {
return (SiderbarBoardPage) super.getBoardPage(player);
}
@Override
public SiderbarBoardPage newPage() {
return new SiderbarBoardPage();
}
@Override
public void update(final Player player) {
final SiderbarBoardPage boardPage = this.getBoardPage(player);
if (boardPage == null) {
return;
}
String title = null;
if (this.getUpdateFunction().getTitleFunction() != null) {
title = this.getUpdateFunction().getTitleFunction().run(player);
} else {
this.removeTarget(player);
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);
}
}
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));
}
}
}

View File

@ -0,0 +1,36 @@
package pw.yumc.MiaoBoard.scoreboard.core;
import java.util.List;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
/**
*
* @since 2016年7月4日 下午4:40:21
* @author 尘曲
*/
public class SiderbarBoardPage extends BoardPage {
private final Objective objective;
private List<Entry> lastEntries;
public SiderbarBoardPage() {
super();
objective = getBoard().registerNewObjective("default", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
}
public List<Entry> getLastEntries() {
return lastEntries;
}
public Objective getObjective() {
return objective;
}
public void setLastEntries(final List<Entry> lastEntries) {
this.lastEntries = lastEntries;
}
}

View File

@ -2,16 +2,16 @@ package pw.yumc.MiaoBoard.scoreboard.updater;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
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.MiaoBoard.scoreboard.ScoreBoardManager;
import pw.yumc.YumCore.bukkit.P;
/**
* 记分板行更新类
@ -20,18 +20,15 @@ import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
* @author
*/
public class BodyUpdater extends CallBackReturn.One<Player, List<String>> {
MiaoBoard plugin = P.getPlugin();
@Override
public List<String> run(final Player param) {
final Iterator<BoardModel> iterator = ScoreBoardManager.getModels().iterator();
final Iterator<BoardModel> iterator = plugin.getScoreBoardManager().getModels().iterator();
while (iterator.hasNext()) {
final BoardModel bmodel = iterator.next();
if (Checker.$(param, bmodel)) {
final List<String> temp = new LinkedList<>();
for (final String line : bmodel.lines) {
temp.add(Replace.$(param, line));
}
return temp;
return Replace.$(param, bmodel.lines);
}
}
return Collections.emptyList();

View File

@ -5,10 +5,11 @@ 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.MiaoBoard.scoreboard.ScoreBoardManager;
import pw.yumc.YumCore.bukkit.P;
/**
* 记分板标题更新类
@ -17,17 +18,18 @@ import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
* @author
*/
public class TitleUpdater extends CallBackReturn.One<Player, String> {
MiaoBoard plugin = P.getPlugin();
@Override
public String run(final Player param) {
final Iterator<BoardModel> iterator = ScoreBoardManager.getModels().iterator();
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);
}
}
return "";
return null;
}
}

View File

@ -1,5 +1,5 @@
#配置文件版本号
Version: 1.1
Version: 2.0
#更新时间(单位: Tick)
UpdateTime: 10
@ -17,25 +17,30 @@ Boards:
start: '2016-01-01 00:00:00'
end: '2020-01-01 00:00:00'
#记分板标题
title: '喵式记分板简介'
title: '玩家信息'
#记分板权限
permission: mb.default
#记分板内容
#注意 不得超过38个字符 包括颜色字符 超过部分自动截取
#注意 不得超过15行 超出部分 自动忽略
#记分板内容(不得超过38个字符 包括颜色字符 超过部分自动截取)
lines:
- '&6插件名称: &a%plugin_name%'
- '&7------------------------------'
- '&6插件版本: &b%plugin_version%'
- '&7------------------------------'
- '&6插件作者: &c%plugin_author%'
- '&7------------------------------'
- '&6玩家名称: &a%player_displayname%'
- '&7------------------------------'
- '&6您所在的位置: &b%player_world% &a%player_x%,%player_y%,%player_z%'
- '&7------------------------------'
- '&6您所在的角度: &bYaw &a%player_yaw% &bPitch &a%player_pitch%'
- '&7------------------------------'
- '&6服务器使用内存: &a%server_ram_used%/%server_ram_total%'
- '&7------------------------------'
- '&6离2017年还剩: &a%time_left_2017-01-01`00:00:00%秒'
- '&6名 称: &a%player_displayname%'
- '&6世 界: &b%player_world%'
- '&6位 置: &3%player_x%,%player_y%,%player_z%'
- '&6等 级: &e%player_level%'
- '&6血 量: &c%player_health%'
- '&6饥 饿: &d%player_food_level%'
- '&6模 式: &4%player_gamemode%'
#默认记分板
admin:
#记分板顺序(将按照从小到大依次检测 比如 1-50 优先检测 1 符合则显示 不符合 检测 2 ...)
index: 49
#记分板标题
title: '服务器信息'
#记分板权限
permission: mb.reload
#记分板内容(不得超过38个字符 包括颜色字符 超过部分自动截取)
lines:
- '&6名 称: &a%plugin_name%'
- '&6版 本: &b%plugin_version%'
- '&6作 者: &c%plugin_author%'
- '&6人 数: &c%server_online%/%server_max%'
- '&6内 存: &a%server_ram_used%/%server_ram_total%/%server_ram_max%'

View File

@ -12,7 +12,6 @@ commands:
aliases:
- mb
usage: §b使用/${project.artifactId} help 查看帮助!
permission: mb.reload
permission-message: §c你没有 <permission> 的权限来执行此命令!
permissions:
mb.reload:
@ -20,4 +19,7 @@ permissions:
default: op
mb.default:
description: 默认记分板权限!
default: true
mb.toggle:
description: 开启关闭记分板!
default: true