1
0
mirror of https://e.coding.net/circlecloud/MiaoBoard.git synced 2024-11-25 02:19:07 +00:00

feat: 添加模型和配置

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-05 00:56:47 +08:00
parent e6b7bb19d6
commit b1cda6bc4e
8 changed files with 110 additions and 12 deletions

View File

@ -4,7 +4,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.commands.HandlerCommand; import cn.citycraft.PluginHelper.commands.HandlerCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommands; import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.listener.PlayerListener;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
* 喵式记分板主类 * 喵式记分板主类
@ -13,25 +17,27 @@ import cn.citycraft.PluginHelper.config.FileConfig;
* @author * @author
*/ */
public class MiaoBoard extends JavaPlugin implements HandlerCommands { public class MiaoBoard extends JavaPlugin implements HandlerCommands {
private FileConfig config;
@Override @Override
public FileConfig getConfig() { public void onDisable() {
return config; ScoreBoardManager.status = false;
} }
@Override @Override
public void onEnable() { public void onEnable() {
new InvokeSubCommand(this, "mb").registerCommands(this);
new ScoreBoardManager().start();
new PlayerListener();
} }
@Override @Override
public void onLoad() { public void onLoad() {
config = new FileConfig(this); new MiaoBoardConfig();
} }
@HandlerCommand(name = "reload", description = "重新载入配置文件") @HandlerCommand(name = "reload", description = "重新载入配置文件")
public void reload() { public void reload(final InvokeCommandEvent e) {
config.reload(); MiaoBoardConfig.reload();
e.getSender().sendMessage("§a配置重载完毕!");
} }
} }

View File

@ -0,0 +1,27 @@
package pw.yumc.MiaoBoard.config;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.kit.PKit;
import pw.yumc.MiaoBoard.model.BoardModel;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
public class MiaoBoardConfig {
public static FileConfig config;
public MiaoBoardConfig() {
config = new FileConfig(PKit.i());
}
public static BoardModel getModel(final String path) {
return new BoardModel(config.getConfigurationSection(getRoot(path)));
}
public static String getRoot(final String path) {
return "Boards." + path;
}
public static void reload() {
config.reload();
ScoreBoardManager.bm = getModel("default");
}
}

View File

@ -1,9 +1,11 @@
package pw.yumc.MiaoBoard.listener; package pw.yumc.MiaoBoard.listener;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import cn.citycraft.PluginHelper.kit.PKit;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager; import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
@ -12,6 +14,10 @@ import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
* @author * @author
*/ */
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
public PlayerListener() {
Bukkit.getPluginManager().registerEvents(this, PKit.i());
}
public void onPlayerJoin(final PlayerJoinEvent e) { public void onPlayerJoin(final PlayerJoinEvent e) {
ScoreBoardManager.add(e.getPlayer()); ScoreBoardManager.add(e.getPlayer());
} }

View File

@ -0,0 +1,22 @@
package pw.yumc.MiaoBoard.model;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
public class BoardModel {
public String title;
public String permission;
public List<String> lines = new LinkedList<>();;
public BoardModel(final ConfigurationSection config) {
this(config.getString("title"), config.getString("permission"), config.getStringList("lines"));
}
public BoardModel(final String title, final String permission, final List<String> lines) {
this.title = title;
this.permission = permission;
this.lines = lines;
}
}

View File

@ -4,7 +4,10 @@ import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.kit.PKit; import cn.citycraft.PluginHelper.kit.PKit;
import cn.citycraft.PluginHelper.scoreboard.BoardUpdateFunction; import cn.citycraft.PluginHelper.scoreboard.BoardUpdateFunction;
import cn.citycraft.PluginHelper.scoreboard.Condition;
import cn.citycraft.PluginHelper.scoreboard.SidebarBoard; import cn.citycraft.PluginHelper.scoreboard.SidebarBoard;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.model.BoardModel;
import pw.yumc.MiaoBoard.scoreboard.updater.BodyUpdater; import pw.yumc.MiaoBoard.scoreboard.updater.BodyUpdater;
import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater; import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater;
@ -13,10 +16,14 @@ import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater;
* @since 2016年6月24日 下午3:31:31 * @since 2016年6月24日 下午3:31:31
* @author * @author
*/ */
public class ScoreBoardManager { public class ScoreBoardManager implements Condition {
static SidebarBoard sbd; public static SidebarBoard sbd;
public static BoardModel bm;
public static boolean status;
public ScoreBoardManager() { public ScoreBoardManager() {
status = true;
bm = MiaoBoardConfig.getModel("default");
sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater())); sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
} }
@ -24,7 +31,20 @@ public class ScoreBoardManager {
sbd.addTarget(player); sbd.addTarget(player);
} }
public static BoardModel getModel() {
return bm;
}
public static void remove(final Player player) { public static void remove(final Player player) {
sbd.removeTarget(player); sbd.removeTarget(player);
} }
@Override
public boolean get() {
return status;
}
public void start() {
sbd.update(this, 10);
}
} }

View File

@ -1,10 +1,13 @@
package pw.yumc.MiaoBoard.scoreboard.updater; package pw.yumc.MiaoBoard.scoreboard.updater;
import java.util.LinkedList;
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 cn.citycraft.PluginHelper.callback.CallBackReturn;
import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
* *
@ -15,7 +18,11 @@ 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) {
return null; final List<String> temp = new LinkedList<>();
for (final String line : ScoreBoardManager.bm.lines) {
temp.add(PluginAPI.PlaceholderAPI(param, line));
}
return temp;
} }
} }

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.callback.CallBackReturn; import cn.citycraft.PluginHelper.callback.CallBackReturn;
import cn.citycraft.PluginHelper.pluginapi.PluginAPI; import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
* *
@ -14,7 +15,7 @@ public class TitleUpdater extends CallBackReturn.One<Player, String> {
@Override @Override
public String run(final Player param) { public String run(final Player param) {
return PluginAPI.PlaceholderAPI(param, param.getName()); return PluginAPI.PlaceholderAPI(param, ScoreBoardManager.bm.title);
} }
} }

View File

@ -1,3 +1,12 @@
#关闭记分板的世界 #关闭记分板的世界
DisableWorld: DisableWorld:
- WorldName - WorldName
#记分板
Boards:
#默认记分板
default:
title: 标题
permission: mb.default
lines:
- '这是第一行'
- ''