1
0
mirror of https://e.coding.net/circlecloud/MiaoBoard.git synced 2024-11-22 01:49:05 +00:00

feat: 修复记分板不显示的BUG 多记分板功能实现

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-07 02:03:29 +08:00
parent 819929f1b1
commit 9ad060c0e5
9 changed files with 91 additions and 38 deletions

View File

@ -27,17 +27,18 @@ public class MiaoBoard extends JavaPlugin implements HandlerCommands {
public void onEnable() { public void onEnable() {
new InvokeSubCommand(this, "mb").registerCommands(this); new InvokeSubCommand(this, "mb").registerCommands(this);
new ScoreBoardManager().start(); new ScoreBoardManager().start();
ScoreBoardManager.load();
new PlayerListener(); new PlayerListener();
} }
@Override @Override
public void onLoad() { public void onLoad() {
new MiaoBoardConfig(); MiaoBoardConfig.i();
} }
@HandlerCommand(name = "reload", description = "重新载入配置文件") @HandlerCommand(name = "reload", description = "重新载入配置文件")
public void reload(final InvokeCommandEvent e) { public void reload(final InvokeCommandEvent e) {
MiaoBoardConfig.reload(); ScoreBoardManager.reload();
e.getSender().sendMessage("§a配置重载完毕!"); e.getSender().sendMessage("§a配置重载完毕!");
} }
} }

View File

@ -1,33 +1,31 @@
package pw.yumc.MiaoBoard.config; package pw.yumc.MiaoBoard.config;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import cn.citycraft.PluginHelper.config.ConfigNode;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.config.InjectConfig;
import cn.citycraft.PluginHelper.kit.PKit; import cn.citycraft.PluginHelper.kit.PKit;
import pw.yumc.MiaoBoard.model.BoardModel; import pw.yumc.MiaoBoard.MiaoBoard;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
public class MiaoBoardConfig { public class MiaoBoardConfig extends InjectConfig<MiaoBoard> {
public static FileConfig config; public static Integer UpdateTime;
public static List<String> DisableWorld = new ArrayList<>();
@ConfigNode public transient static MiaoBoardConfig instance = new MiaoBoardConfig();;
public static List<String> DisableWorld;
public MiaoBoardConfig() { public MiaoBoardConfig() {
config = new FileConfig(PKit.i()); super((MiaoBoard) PKit.i());
} }
public static BoardModel getModel(final String path) { public static MiaoBoardConfig i() {
return new BoardModel(config.getConfigurationSection(getRoot(path))); return instance;
} }
public static String getRoot(final String path) { public static void reInject() {
return "Boards." + path; instance.reload();
} }
public static void reload() { public FileConfig getConfig() {
config.reload(); return config;
ScoreBoardManager.bm = getModel("default");
} }
} }

View File

@ -1,6 +1,7 @@
package pw.yumc.MiaoBoard.listener; package pw.yumc.MiaoBoard.listener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -20,6 +21,7 @@ public class PlayerListener implements Listener {
Bukkit.getPluginManager().registerEvents(this, PKit.i()); Bukkit.getPluginManager().registerEvents(this, PKit.i());
} }
@EventHandler
public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) { public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) {
if (MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) { if (MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
ScoreBoardManager.remove(e.getPlayer()); ScoreBoardManager.remove(e.getPlayer());
@ -28,12 +30,14 @@ public class PlayerListener implements Listener {
} }
} }
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent e) { public void onPlayerJoin(final PlayerJoinEvent e) {
if (!MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) { if (!MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
ScoreBoardManager.add(e.getPlayer()); ScoreBoardManager.add(e.getPlayer());
} }
} }
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent e) { public void onPlayerQuit(final PlayerQuitEvent e) {
ScoreBoardManager.remove(e.getPlayer()); ScoreBoardManager.remove(e.getPlayer());
} }

View File

@ -1,6 +1,5 @@
package pw.yumc.MiaoBoard.model; package pw.yumc.MiaoBoard.model;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -10,11 +9,11 @@ import cn.citycraft.PluginHelper.config.InjectConfigurationSection;
public class BoardModel extends InjectConfigurationSection { public class BoardModel extends InjectConfigurationSection {
public String title; public String title;
public String permission; public String permission;
public List<String> lines = new LinkedList<>(); public List<String> lines;
/** /**
* 自动载入配置 * 自动载入配置
* *
* @param config * @param config
*/ */
public BoardModel(final ConfigurationSection config) { public BoardModel(final ConfigurationSection config) {

View File

@ -1,7 +1,11 @@
package pw.yumc.MiaoBoard.scoreboard; package pw.yumc.MiaoBoard.scoreboard;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.config.FileConfig;
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.Condition;
@ -17,13 +21,16 @@ import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater;
* @author * @author
*/ */
public class ScoreBoardManager implements Condition { public class ScoreBoardManager implements Condition {
public static SidebarBoard sbd; public static Condition cot;
public static BoardModel bm;
public static boolean status; public static boolean status;
public static SidebarBoard sbd;
public static FileConfig config;
public static List<BoardModel> bms = new ArrayList<>();
public ScoreBoardManager() { public ScoreBoardManager() {
status = true; status = true;
bm = MiaoBoardConfig.getModel("default"); cot = this;
config = MiaoBoardConfig.i().getConfig();
sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater())); sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
} }
@ -31,8 +38,20 @@ public class ScoreBoardManager implements Condition {
sbd.addTarget(player); sbd.addTarget(player);
} }
public static BoardModel getModel() { public static List<BoardModel> getModels() {
return bm; return bms;
}
public static void load() {
bms.clear();
for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) {
bms.add(new BoardModel(config.getConfigurationSection("Boards." + bmn)));
}
}
public static void reload() {
MiaoBoardConfig.reInject();
load();
} }
public static void remove(final Player player) { public static void remove(final Player player) {
@ -45,6 +64,6 @@ public class ScoreBoardManager implements Condition {
} }
public void start() { public void start() {
sbd.update(this, 10); sbd.update(cot, MiaoBoardConfig.UpdateTime);
} }
} }

View File

@ -1,5 +1,7 @@
package pw.yumc.MiaoBoard.scoreboard.updater; package pw.yumc.MiaoBoard.scoreboard.updater;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -7,6 +9,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.model.BoardModel;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager; import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
@ -18,11 +21,18 @@ 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 List<String> temp = new LinkedList<>(); final Iterator<BoardModel> iterator = ScoreBoardManager.getModels().iterator();
for (final String line : ScoreBoardManager.bm.lines) { while (iterator.hasNext()) {
temp.add(PluginAPI.PlaceholderAPI(param, line)); final BoardModel bmodel = iterator.next();
if (param.hasPermission(bmodel.permission)) {
final List<String> temp = new LinkedList<>();
for (final String line : bmodel.lines) {
temp.add(PluginAPI.PlaceholderAPI(param, line));
}
return temp;
}
} }
return temp; return Collections.emptyList();
} }
} }

View File

@ -1,9 +1,12 @@
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 cn.citycraft.PluginHelper.callback.CallBackReturn;
import cn.citycraft.PluginHelper.pluginapi.PluginAPI; import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
import pw.yumc.MiaoBoard.model.BoardModel;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager; import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
@ -15,7 +18,14 @@ 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, ScoreBoardManager.bm.title); final Iterator<BoardModel> iterator = ScoreBoardManager.getModels().iterator();
while (iterator.hasNext()) {
final BoardModel bmodel = iterator.next();
if (param.hasPermission(bmodel.permission)) {
return PluginAPI.PlaceholderAPI(param, bmodel.title);
}
}
return "";
} }
} }

View File

@ -1,3 +1,8 @@
#配置文件版本号
Version: 1.0
#更新时间(单位: Tick)
UpdateTime: 10
#关闭记分板的世界 #关闭记分板的世界
DisableWorld: DisableWorld:
- WorldName - WorldName
@ -5,8 +10,12 @@ DisableWorld:
Boards: Boards:
#默认记分板 #默认记分板
default: default:
title: 标题 title: '玩家信息'
permission: mb.default permission: mb.default
lines: lines:
- '这是第一行' - '&6玩家名称: &a%player_displayname%'
- '' - '&7------------------------------'
- '&6您所在的位置: &b%player_world% &a%player_x%,%player_y%,%player_z%'
- '&7------------------------------'
- '&6服务器使用内存: &a%server_ram_used%/%server_ram_total%'

View File

@ -10,9 +10,12 @@ commands:
aliases: aliases:
- mb - mb
usage: §b使用/${project.artifactId} help 查看帮助! usage: §b使用/${project.artifactId} help 查看帮助!
permission: ${project.artifactId}.reload permission: mb.reload
permission-message: §c你没有 <permission> 的权限来执行此命令! permission-message: §c你没有 <permission> 的权限来执行此命令!
permissions: permissions:
${project.artifactId}.reload: mb.reload:
description: 重新载入插件! description: 重新载入插件!
default: op default: op
mb.default:
description: 默认记分板权限!
default: true