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:
parent
819929f1b1
commit
9ad060c0e5
@ -27,17 +27,18 @@ public class MiaoBoard extends JavaPlugin implements HandlerCommands {
|
||||
public void onEnable() {
|
||||
new InvokeSubCommand(this, "mb").registerCommands(this);
|
||||
new ScoreBoardManager().start();
|
||||
ScoreBoardManager.load();
|
||||
new PlayerListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
new MiaoBoardConfig();
|
||||
MiaoBoardConfig.i();
|
||||
}
|
||||
|
||||
@HandlerCommand(name = "reload", description = "重新载入配置文件")
|
||||
public void reload(final InvokeCommandEvent e) {
|
||||
MiaoBoardConfig.reload();
|
||||
ScoreBoardManager.reload();
|
||||
e.getSender().sendMessage("§a配置重载完毕!");
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,31 @@
|
||||
package pw.yumc.MiaoBoard.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.ConfigNode;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.config.InjectConfig;
|
||||
import cn.citycraft.PluginHelper.kit.PKit;
|
||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
||||
import pw.yumc.MiaoBoard.MiaoBoard;
|
||||
|
||||
public class MiaoBoardConfig {
|
||||
public static FileConfig config;
|
||||
|
||||
@ConfigNode
|
||||
public static List<String> DisableWorld;
|
||||
public class MiaoBoardConfig extends InjectConfig<MiaoBoard> {
|
||||
public static Integer UpdateTime;
|
||||
public static List<String> DisableWorld = new ArrayList<>();
|
||||
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();;
|
||||
|
||||
public MiaoBoardConfig() {
|
||||
config = new FileConfig(PKit.i());
|
||||
super((MiaoBoard) PKit.i());
|
||||
}
|
||||
|
||||
public static BoardModel getModel(final String path) {
|
||||
return new BoardModel(config.getConfigurationSection(getRoot(path)));
|
||||
public static MiaoBoardConfig i() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static String getRoot(final String path) {
|
||||
return "Boards." + path;
|
||||
public static void reInject() {
|
||||
instance.reload();
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
config.reload();
|
||||
ScoreBoardManager.bm = getModel("default");
|
||||
public FileConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package pw.yumc.MiaoBoard.listener;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@ -20,6 +21,7 @@ public class PlayerListener implements Listener {
|
||||
Bukkit.getPluginManager().registerEvents(this, PKit.i());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) {
|
||||
if (MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
|
||||
ScoreBoardManager.remove(e.getPlayer());
|
||||
@ -28,12 +30,14 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent e) {
|
||||
if (!MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
|
||||
ScoreBoardManager.add(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent e) {
|
||||
ScoreBoardManager.remove(e.getPlayer());
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package pw.yumc.MiaoBoard.model;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -10,7 +9,7 @@ import cn.citycraft.PluginHelper.config.InjectConfigurationSection;
|
||||
public class BoardModel extends InjectConfigurationSection {
|
||||
public String title;
|
||||
public String permission;
|
||||
public List<String> lines = new LinkedList<>();
|
||||
public List<String> lines;
|
||||
|
||||
/**
|
||||
* 自动载入配置
|
||||
|
@ -1,7 +1,11 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.kit.PKit;
|
||||
import cn.citycraft.PluginHelper.scoreboard.BoardUpdateFunction;
|
||||
import cn.citycraft.PluginHelper.scoreboard.Condition;
|
||||
@ -17,13 +21,16 @@ import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class ScoreBoardManager implements Condition {
|
||||
public static SidebarBoard sbd;
|
||||
public static BoardModel bm;
|
||||
public static Condition cot;
|
||||
public static boolean status;
|
||||
public static SidebarBoard sbd;
|
||||
public static FileConfig config;
|
||||
public static List<BoardModel> bms = new ArrayList<>();
|
||||
|
||||
public ScoreBoardManager() {
|
||||
status = true;
|
||||
bm = MiaoBoardConfig.getModel("default");
|
||||
cot = this;
|
||||
config = MiaoBoardConfig.i().getConfig();
|
||||
sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
|
||||
}
|
||||
|
||||
@ -31,8 +38,20 @@ public class ScoreBoardManager implements Condition {
|
||||
sbd.addTarget(player);
|
||||
}
|
||||
|
||||
public static BoardModel getModel() {
|
||||
return bm;
|
||||
public static List<BoardModel> getModels() {
|
||||
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) {
|
||||
@ -45,6 +64,6 @@ public class ScoreBoardManager implements Condition {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
sbd.update(this, 10);
|
||||
sbd.update(cot, MiaoBoardConfig.UpdateTime);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.updater;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@ -7,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
||||
import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
|
||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
||||
|
||||
/**
|
||||
@ -18,11 +21,18 @@ public class BodyUpdater extends CallBackReturn.One<Player, List<String>> {
|
||||
|
||||
@Override
|
||||
public List<String> run(final Player param) {
|
||||
final List<String> temp = new LinkedList<>();
|
||||
for (final String line : ScoreBoardManager.bm.lines) {
|
||||
temp.add(PluginAPI.PlaceholderAPI(param, line));
|
||||
final Iterator<BoardModel> iterator = ScoreBoardManager.getModels().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package pw.yumc.MiaoBoard.scoreboard.updater;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.callback.CallBackReturn;
|
||||
import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
|
||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
||||
|
||||
/**
|
||||
@ -15,7 +18,14 @@ public class TitleUpdater extends CallBackReturn.One<Player, String> {
|
||||
|
||||
@Override
|
||||
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 "";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
#配置文件版本号
|
||||
Version: 1.0
|
||||
|
||||
#更新时间(单位: Tick)
|
||||
UpdateTime: 10
|
||||
#关闭记分板的世界
|
||||
DisableWorld:
|
||||
- WorldName
|
||||
@ -5,8 +10,12 @@ DisableWorld:
|
||||
Boards:
|
||||
#默认记分板
|
||||
default:
|
||||
title: 标题
|
||||
title: '玩家信息'
|
||||
permission: mb.default
|
||||
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%'
|
||||
|
@ -10,9 +10,12 @@ commands:
|
||||
aliases:
|
||||
- mb
|
||||
usage: §b使用/${project.artifactId} help 查看帮助!
|
||||
permission: ${project.artifactId}.reload
|
||||
permission: mb.reload
|
||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||
permissions:
|
||||
${project.artifactId}.reload:
|
||||
mb.reload:
|
||||
description: 重新载入插件!
|
||||
default: op
|
||||
mb.default:
|
||||
description: 默认记分板权限!
|
||||
default: true
|
Loading…
Reference in New Issue
Block a user