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

refactor: 代码结构优化

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-29 18:34:20 +08:00
parent f7dd78dee8
commit 5a53213666
6 changed files with 22 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import pw.yumc.YumCore.commands.CommandArgument;
import pw.yumc.YumCore.commands.CommandExecutor;
import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.commands.annotation.Sort;
@ -26,7 +27,7 @@ public class MiaoBoard extends JavaPlugin implements CommandExecutor {
return scoreBoardManager;
}
@Cmd(permission = "mb.toggle")
@Cmd(permission = "mb.toggle", executor = Executor.PLAYER)
@Help("关闭记分板")
@Sort(2)
public void off(final CommandArgument e) {
@ -34,7 +35,7 @@ public class MiaoBoard extends JavaPlugin implements CommandExecutor {
Log.toSender(e.getSender(), "§c记分板已关闭!");
}
@Cmd(permission = "mb.toggle")
@Cmd(permission = "mb.toggle", executor = Executor.PLAYER)
@Help("打开记分板")
@Sort(1)
public void on(final CommandArgument e) {

View File

@ -13,8 +13,8 @@ import pw.yumc.YumCore.config.InjectConfig;
*/
public class MiaoBoardConfig extends InjectConfig {
public transient static MiaoBoardConfig instance = new MiaoBoardConfig();
private Integer UpdateTime;
private List<String> DisableWorld;
public Integer UpdateTime;
public List<String> DisableWorld = Collections.emptyList();
public static MiaoBoardConfig i() {
return instance;
@ -23,15 +23,4 @@ public class MiaoBoardConfig extends InjectConfig {
public static void reInject() {
instance.reload();
}
public List<String> getDisableWorld() {
if (DisableWorld == null) {
DisableWorld = Collections.emptyList();
}
return DisableWorld;
}
public Integer getUpdateTime() {
return UpdateTime;
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import pw.yumc.MiaoBoard.MiaoBoard;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask;
@ -21,6 +22,7 @@ import pw.yumc.YumCore.update.SubscribeTask;
*/
public class PlayerListener implements Listener {
MiaoBoard plugin = P.getPlugin();
ScoreBoardManager manager = plugin.getScoreBoardManager();
public PlayerListener() {
Bukkit.getPluginManager().registerEvents(this, plugin);
@ -30,20 +32,20 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) {
if (MiaoBoardConfig.i().getDisableWorld().contains(e.getPlayer().getWorld().getName())) {
plugin.getScoreBoardManager().getSidebarBoard().removeTarget(e.getPlayer());
if (MiaoBoardConfig.i().DisableWorld.contains(e.getPlayer().getWorld().getName())) {
manager.removeTarget(e.getPlayer());
} else {
plugin.getScoreBoardManager().getSidebarBoard().addTarget(e.getPlayer());
manager.addTarget(e.getPlayer());
}
}
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent e) {
plugin.getScoreBoardManager().addTarget(e.getPlayer());
manager.addTarget(e.getPlayer());
}
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent e) {
plugin.getScoreBoardManager().getSidebarBoard().removeTarget(e.getPlayer());
manager.removeTarget(e.getPlayer());
}
}

View File

@ -35,7 +35,7 @@ public class ScoreBoardManager {
}
public void addTarget(final Player player) {
if (!MiaoBoardConfig.i().getDisableWorld().contains(player.getWorld().getName())) {
if (!MiaoBoardConfig.i().DisableWorld.contains(player.getWorld().getName())) {
getSidebarBoard().addTarget(player);
}
}
@ -63,8 +63,12 @@ public class ScoreBoardManager {
start();
}
public void removeTarget(final Player player) {
sbd.removeTarget(player);
}
public void start() {
sbd.update(cot.set(true), MiaoBoardConfig.i().getUpdateTime());
sbd.update(cot.set(true), MiaoBoardConfig.i().UpdateTime);
for (final Player player : C.Player.getOnlinePlayers()) {
addTarget(player);
}

View File

@ -45,7 +45,7 @@ public abstract class Board implements Iterable<Player> {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = 0;
for (final Player player : this.targets.keySet()) {
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
}
this.targets.clear();
this.removeQueue.clear();
@ -85,7 +85,7 @@ public abstract class Board implements Iterable<Player> {
public boolean removeTarget(final Player player) {
if (this.isTarget(player)) {
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
return this.removeQueue.add(player);
}
return false;
@ -93,7 +93,6 @@ public abstract class Board implements Iterable<Player> {
public void update(final Condition condition, final int interval) {
taskId = plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
@Override
public void run() {
if (condition.get()) {

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -49,7 +50,7 @@ public class SidebarBoard extends Board {
title = this.getUpdateFunction().getTitleFunction().run(player);
}
if (title == null) {
this.removeTarget(player);
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
return;
}
final List<String> newContents = this.getUpdateFunction().getBodyFunction().run(player);