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-05 20:59:29 +08:00
parent b1cda6bc4e
commit 819929f1b1
3 changed files with 29 additions and 10 deletions

View File

@ -1,5 +1,8 @@
package pw.yumc.MiaoBoard.config; package pw.yumc.MiaoBoard.config;
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.kit.PKit; import cn.citycraft.PluginHelper.kit.PKit;
import pw.yumc.MiaoBoard.model.BoardModel; import pw.yumc.MiaoBoard.model.BoardModel;
@ -8,6 +11,9 @@ import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
public class MiaoBoardConfig { public class MiaoBoardConfig {
public static FileConfig config; public static FileConfig config;
@ConfigNode
public static List<String> DisableWorld;
public MiaoBoardConfig() { public MiaoBoardConfig() {
config = new FileConfig(PKit.i()); config = new FileConfig(PKit.i());
} }

View File

@ -2,10 +2,12 @@ package pw.yumc.MiaoBoard.listener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import cn.citycraft.PluginHelper.kit.PKit; import cn.citycraft.PluginHelper.kit.PKit;
import pw.yumc.MiaoBoard.config.MiaoBoardConfig;
import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager; import pw.yumc.MiaoBoard.scoreboard.ScoreBoardManager;
/** /**
@ -18,8 +20,18 @@ public class PlayerListener implements Listener {
Bukkit.getPluginManager().registerEvents(this, PKit.i()); Bukkit.getPluginManager().registerEvents(this, PKit.i());
} }
public void onPlayerChangeWorld(final PlayerChangedWorldEvent e) {
if (MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
ScoreBoardManager.remove(e.getPlayer());
} else {
ScoreBoardManager.add(e.getPlayer());
}
}
public void onPlayerJoin(final PlayerJoinEvent e) { public void onPlayerJoin(final PlayerJoinEvent e) {
ScoreBoardManager.add(e.getPlayer()); if (!MiaoBoardConfig.DisableWorld.contains(e.getPlayer().getWorld().getName())) {
ScoreBoardManager.add(e.getPlayer());
}
} }
public void onPlayerQuit(final PlayerQuitEvent e) { public void onPlayerQuit(final PlayerQuitEvent e) {

View File

@ -5,18 +5,19 @@ import java.util.List;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class BoardModel { import cn.citycraft.PluginHelper.config.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 = new LinkedList<>();
/**
* 自动载入配置
*
* @param config
*/
public BoardModel(final ConfigurationSection config) { public BoardModel(final ConfigurationSection config) {
this(config.getString("title"), config.getString("permission"), config.getStringList("lines")); super(config);
}
public BoardModel(final String title, final String permission, final List<String> lines) {
this.title = title;
this.permission = permission;
this.lines = lines;
} }
} }