diff --git a/src/cn/citycraft/ResFly/ResFly.java b/src/cn/citycraft/ResFly/ResFly.java index 962f62b..52cb312 100644 --- a/src/cn/citycraft/ResFly/ResFly.java +++ b/src/cn/citycraft/ResFly/ResFly.java @@ -1,50 +1,52 @@ -package cn.citycraft.ResFly; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import cn.citycraft.ResFly.config.Config; -import cn.citycraft.ResFly.listen.PlayerListen; - -import com.bekvon.bukkit.residence.protection.FlagPermissions; - -public class ResFly extends JavaPlugin { - - public String servername; - public String pluginname; - - public void onLoad() { - Config.load(this); - servername = getmessage("servername"); - pluginname = getmessage("pluginname"); - } - - public void onEnable() { - PluginManager pm = this.getServer().getPluginManager(); - Plugin res = pm.getPlugin("Residence"); - if (Config.getInstance().getBoolean("ResFly.Enable", true)) { - if (res != null && res.isEnabled()) { - FlagPermissions.addFlag("fly"); - FlagPermissions.addResidenceOnlyFlag("fly"); - Bukkit.getPluginManager() - .registerEvents(new PlayerListen(this), this); - getLogger().info("玩家领地飞行控制已加载!"); - } else { - getLogger().info("未找到领地插件停止加载领地飞行!"); - pm.disablePlugin(this); - return; - } - } - } - - public String getfullmsg(String path) { - return servername + pluginname + " " + getmessage(path); - } - - public String getmessage(String path) { - return Config.getMessage(path); - } - -} +package cn.citycraft.ResFly; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import cn.citycraft.ResFly.config.Config; +import cn.citycraft.ResFly.listen.PlayerListen; + +import com.bekvon.bukkit.residence.protection.FlagPermissions; + +public class ResFly extends JavaPlugin { + + public String servername; + public String pluginname; + + public String getfullmsg(String path) { + return servername + pluginname + " " + getmessage(path); + } + + public String getmessage(String path) { + return Config.getMessage(path); + } + + @Override + public void onEnable() { + PluginManager pm = this.getServer().getPluginManager(); + Plugin res = pm.getPlugin("Residence"); + if (Config.getInstance().getBoolean("ResFly.Enable", true)) { + if (res != null && res.isEnabled()) { + FlagPermissions.addFlag("fly"); + FlagPermissions.addResidenceOnlyFlag("fly"); + Bukkit.getPluginManager() + .registerEvents(new PlayerListen(this), this); + getLogger().info("玩家领地飞行控制已加载!"); + } else { + getLogger().info("未找到领地插件停止加载领地飞行!"); + pm.disablePlugin(this); + return; + } + } + } + + @Override + public void onLoad() { + Config.load(this); + servername = getmessage("servername"); + pluginname = getmessage("pluginname"); + } + +} diff --git a/src/cn/citycraft/ResFly/config/FileConfig.java b/src/cn/citycraft/ResFly/config/FileConfig.java index 7d52895..eba628f 100644 --- a/src/cn/citycraft/ResFly/config/FileConfig.java +++ b/src/cn/citycraft/ResFly/config/FileConfig.java @@ -30,15 +30,9 @@ import com.google.common.io.Files; */ public class FileConfig extends YamlConfiguration { - protected final DumperOptions yamlOptions = new DumperOptions(); - protected final Representer yamlRepresenter = new YamlRepresenter(); - protected final Yaml yaml = new Yaml(new YamlConstructor(), - yamlRepresenter, yamlOptions); - public static FileConfig init(File file) { return FileConfig.loadConfiguration(file); } - public static FileConfig loadConfiguration(File file) { Validate.notNull(file, "File cannot be null"); FileConfig config = new FileConfig(); @@ -52,6 +46,34 @@ public class FileConfig extends YamlConfiguration { } return config; } + protected final DumperOptions yamlOptions = new DumperOptions(); + + protected final Representer yamlRepresenter = new YamlRepresenter(); + + protected final Yaml yaml = new Yaml(new YamlConstructor(), + yamlRepresenter, yamlOptions); + + @Override + public void load(File file) throws FileNotFoundException, IOException, + InvalidConfigurationException { + Validate.notNull(file, "File cannot be null"); + final FileInputStream stream = new FileInputStream(file); + load(new InputStreamReader(stream, Charsets.UTF_8)); + } + + @Override + public void save(File file) throws IOException { + Validate.notNull(file, "File cannot be null"); + Files.createParentDirs(file); + String data = saveToString(); + Writer writer = new OutputStreamWriter(new FileOutputStream(file), + Charsets.UTF_8); + try { + writer.write(data); + } finally { + writer.close(); + } + } @Override public String saveToString() { @@ -65,24 +87,4 @@ public class FileConfig extends YamlConfiguration { } return header + dump; } - - public void load(File file) throws FileNotFoundException, IOException, - InvalidConfigurationException { - Validate.notNull(file, "File cannot be null"); - final FileInputStream stream = new FileInputStream(file); - load(new InputStreamReader(stream, Charsets.UTF_8)); - } - - public void save(File file) throws IOException { - Validate.notNull(file, "File cannot be null"); - Files.createParentDirs(file); - String data = saveToString(); - Writer writer = new OutputStreamWriter(new FileOutputStream(file), - Charsets.UTF_8); - try { - writer.write(data); - } finally { - writer.close(); - } - } }