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

feat: 代码优化

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-07 20:53:56 +08:00
parent 6541699798
commit d427e2e8d0
4 changed files with 47 additions and 47 deletions

View File

@ -1,12 +1,15 @@
package pw.yumc.MiaoBoard; package pw.yumc.MiaoBoard;
import java.net.MalformedURLException;
import org.bukkit.plugin.java.JavaPlugin; 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.commands.InvokeCommandEvent; import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand; 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.listener.PlayerListener;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager; import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
@ -20,20 +23,25 @@ public class MiaoBoard extends JavaPlugin implements HandlerCommands {
@Override @Override
public void onDisable() { public void onDisable() {
ScoreBoardManager.status = false; ScoreBoardManager.getSidebarBoard().cancel();
} }
@Override @Override
public void onEnable() { public void onEnable() {
new InvokeSubCommand(this, "mb").registerCommands(this); new InvokeSubCommand(this, "mb").registerCommands(this);
new ScoreBoardManager().start();
ScoreBoardManager.load();
new PlayerListener(); 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 @Override
public void onLoad() { public void onLoad() {
MiaoBoardConfig.i(); ScoreBoardManager.load();
} }
@HandlerCommand(name = "reload", description = "重新载入配置文件") @HandlerCommand(name = "reload", description = "重新载入配置文件")

View File

@ -3,20 +3,13 @@ package pw.yumc.MiaoBoard.config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.config.InjectConfig; 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 Integer UpdateTime;
public static List<String> DisableWorld = new ArrayList<>(); public static List<String> DisableWorld = new ArrayList<>();
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();; public transient static MiaoBoardConfig instance = new MiaoBoardConfig();;
public MiaoBoardConfig() {
super((MiaoBoard) PKit.i());
}
public static MiaoBoardConfig i() { public static MiaoBoardConfig i() {
return instance; return instance;
} }
@ -24,8 +17,4 @@ public class MiaoBoardConfig extends InjectConfig<MiaoBoard> {
public static void reInject() { public static void reInject() {
instance.reload(); instance.reload();
} }
public FileConfig getConfig() {
return config;
}
} }

View File

@ -24,21 +24,21 @@ public class PlayerListener implements Listener {
@EventHandler @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.getSidebarBoard().removeTarget(e.getPlayer());
} else { } else {
ScoreBoardManager.add(e.getPlayer()); ScoreBoardManager.getSidebarBoard().addTarget(e.getPlayer());
} }
} }
@EventHandler @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.getSidebarBoard().addTarget(e.getPlayer());
} }
} }
@EventHandler @EventHandler
public void onPlayerQuit(final PlayerQuitEvent e) { public void onPlayerQuit(final PlayerQuitEvent e) {
ScoreBoardManager.remove(e.getPlayer()); ScoreBoardManager.getSidebarBoard().removeTarget(e.getPlayer());
} }
} }

View File

@ -10,6 +10,7 @@ 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;
import cn.citycraft.PluginHelper.scoreboard.SidebarBoard; import cn.citycraft.PluginHelper.scoreboard.SidebarBoard;
import cn.citycraft.PluginHelper.utils.CompatibleUtil;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig; import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.model.BoardModel; import pw.yumc.MiaoBoard.model.BoardModel;
import pw.yumc.MiaoBoard.scoreboard.updater.BodyUpdater; 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 * @since 2016年6月24日 下午3:31:31
* @author * @author
*/ */
public class ScoreBoardManager implements Condition { public class ScoreBoardManager {
public static Condition cot; public static Status cot = new Status();
public static boolean status; public static SidebarBoard sbd = new SidebarBoard(PKit.i(), new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
public static SidebarBoard sbd; public static FileConfig config = MiaoBoardConfig.i().getConfig();;
public static FileConfig config;
public static List<BoardModel> bms = new ArrayList<>(); 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() { public static List<BoardModel> getModels() {
return bms; return bms;
} }
public static SidebarBoard getSidebarBoard() {
return sbd;
}
public static void load() { public static void load() {
bms.clear(); bms.clear();
for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) { for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) {
@ -50,20 +43,30 @@ public class ScoreBoardManager implements Condition {
} }
public static void reload() { public static void reload() {
sbd.cancel();
MiaoBoardConfig.reInject(); MiaoBoardConfig.reInject();
load(); load();
start();
} }
public static void remove(final Player player) { public static void start() {
sbd.removeTarget(player);
}
@Override
public boolean get() {
return status;
}
public void start() {
sbd.update(cot, MiaoBoardConfig.UpdateTime); 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;
}
} }
} }