mirror of
https://e.coding.net/circlecloud/MiaoBoard.git
synced 2024-12-22 06:49:02 +00:00
feat: 代码优化
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
6541699798
commit
d427e2e8d0
@ -1,12 +1,15 @@
|
||||
package pw.yumc.MiaoBoard;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.HandlerCommand;
|
||||
import cn.citycraft.PluginHelper.commands.HandlerCommands;
|
||||
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
|
||||
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
|
||||
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
|
||||
import cn.citycraft.PluginHelper.kit.PluginKit;
|
||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
import pw.yumc.MiaoBoard.listener.PlayerListener;
|
||||
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
|
||||
|
||||
@ -20,20 +23,25 @@ public class MiaoBoard extends JavaPlugin implements HandlerCommands {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
ScoreBoardManager.status = false;
|
||||
ScoreBoardManager.getSidebarBoard().cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new InvokeSubCommand(this, "mb").registerCommands(this);
|
||||
new ScoreBoardManager().start();
|
||||
ScoreBoardManager.load();
|
||||
new PlayerListener();
|
||||
try {
|
||||
new VersionChecker(this, "aHR0cDovL2NpLnl1bWMucHcvam9iL01pYW9Cb2FyZC9sYXN0U3VjY2Vzc2Z1bEJ1aWxkL2FydGlmYWN0L3BvbS54bWw=".getBytes());
|
||||
ScoreBoardManager.start();
|
||||
} catch (final MalformedURLException e) {
|
||||
PluginKit.disable("DON'T TRY TO CHANGE THE URL...");
|
||||
throw new IllegalAccessError("Access Check Failed...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
MiaoBoardConfig.i();
|
||||
ScoreBoardManager.load();
|
||||
}
|
||||
|
||||
@HandlerCommand(name = "reload", description = "重新载入配置文件")
|
||||
|
@ -3,20 +3,13 @@ package pw.yumc.MiaoBoard.config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.config.InjectConfig;
|
||||
import cn.citycraft.PluginHelper.kit.PKit;
|
||||
import pw.yumc.MiaoBoard.MiaoBoard;
|
||||
|
||||
public class MiaoBoardConfig extends InjectConfig<MiaoBoard> {
|
||||
public class MiaoBoardConfig extends InjectConfig {
|
||||
public static Integer UpdateTime;
|
||||
public static List<String> DisableWorld = new ArrayList<>();
|
||||
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();;
|
||||
|
||||
public MiaoBoardConfig() {
|
||||
super((MiaoBoard) PKit.i());
|
||||
}
|
||||
|
||||
public static MiaoBoardConfig i() {
|
||||
return instance;
|
||||
}
|
||||
@ -24,8 +17,4 @@ public class MiaoBoardConfig extends InjectConfig<MiaoBoard> {
|
||||
public static void reInject() {
|
||||
instance.reload();
|
||||
}
|
||||
|
||||
public FileConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -24,21 +24,21 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) {
|
||||
if (MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
|
||||
ScoreBoardManager.remove(e.getPlayer());
|
||||
ScoreBoardManager.getSidebarBoard().removeTarget(e.getPlayer());
|
||||
} else {
|
||||
ScoreBoardManager.add(e.getPlayer());
|
||||
ScoreBoardManager.getSidebarBoard().addTarget(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent e) {
|
||||
if (!MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
|
||||
ScoreBoardManager.add(e.getPlayer());
|
||||
ScoreBoardManager.getSidebarBoard().addTarget(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent e) {
|
||||
ScoreBoardManager.remove(e.getPlayer());
|
||||
ScoreBoardManager.getSidebarBoard().removeTarget(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import cn.citycraft.PluginHelper.kit.PKit;
|
||||
import cn.citycraft.PluginHelper.scoreboard.BoardUpdateFunction;
|
||||
import cn.citycraft.PluginHelper.scoreboard.Condition;
|
||||
import cn.citycraft.PluginHelper.scoreboard.SidebarBoard;
|
||||
import cn.citycraft.PluginHelper.utils.CompatibleUtil;
|
||||
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
|
||||
import pw.yumc.MiaoBoard.model.BoardModel;
|
||||
import pw.yumc.MiaoBoard.scoreboard.updater.BodyUpdater;
|
||||
@ -20,28 +21,20 @@ import pw.yumc.MiaoBoard.scoreboard.updater.TitleUpdater;
|
||||
* @since 2016年6月24日 下午3:31:31
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class ScoreBoardManager implements Condition {
|
||||
public static Condition cot;
|
||||
public static boolean status;
|
||||
public static SidebarBoard sbd;
|
||||
public static FileConfig config;
|
||||
public class ScoreBoardManager {
|
||||
public static Status cot = new Status();
|
||||
public static SidebarBoard sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
|
||||
public static FileConfig config = MiaoBoardConfig.i().getConfig();;
|
||||
public static List<BoardModel> bms = new ArrayList<>();
|
||||
|
||||
public ScoreBoardManager() {
|
||||
status = true;
|
||||
cot = this;
|
||||
config = MiaoBoardConfig.i().getConfig();
|
||||
sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
|
||||
}
|
||||
|
||||
public static void add(final Player player) {
|
||||
sbd.addTarget(player);
|
||||
}
|
||||
|
||||
public static List<BoardModel> getModels() {
|
||||
return bms;
|
||||
}
|
||||
|
||||
public static SidebarBoard getSidebarBoard() {
|
||||
return sbd;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
bms.clear();
|
||||
for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) {
|
||||
@ -50,20 +43,30 @@ public class ScoreBoardManager implements Condition {
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
sbd.cancel();
|
||||
MiaoBoardConfig.reInject();
|
||||
load();
|
||||
start();
|
||||
}
|
||||
|
||||
public static void remove(final Player player) {
|
||||
sbd.removeTarget(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean get() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
public static void start() {
|
||||
sbd.update(cot, MiaoBoardConfig.UpdateTime);
|
||||
for (final Player player : CompatibleUtil.getOnlinePlayers()) {
|
||||
sbd.addTarget(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Status implements Condition {
|
||||
private boolean status = true;
|
||||
|
||||
@Override
|
||||
public boolean get() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public Status set(final boolean status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user