From fb26e39e5dadab65971b9177acb4f44093eaa4d8 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Thu, 28 May 2015 20:58:21 +0800 Subject: [PATCH] rebuild priject... Signed-off-by: j502647092 --- src/cn/citycraft/LuckLottery/LuckLottery.java | 147 +++++++++--------- .../command/LuckLotteryCommand.java | 10 +- .../LuckLottery/config/FileConfig.java | 100 ++++++------ 3 files changed, 128 insertions(+), 129 deletions(-) diff --git a/src/cn/citycraft/LuckLottery/LuckLottery.java b/src/cn/citycraft/LuckLottery/LuckLottery.java index b76a67f..9d8479b 100644 --- a/src/cn/citycraft/LuckLottery/LuckLottery.java +++ b/src/cn/citycraft/LuckLottery/LuckLottery.java @@ -18,85 +18,88 @@ import cn.citycraft.LuckLottery.utils.ChatUtils; import cn.citycraft.LuckLottery.utils.LotteryUtils; public class LuckLottery extends JavaPlugin { - public static boolean isEconomy; - public static Permission permission = null; - public static Economy economy = null; - public static Chat chat = null; - public static LuckLottery plugin; + public static boolean isEconomy; + public static Permission permission = null; + public static Economy economy = null; + public static Chat chat = null; + public static LuckLottery plugin; - public void onLoad() { - plugin = this; - Config.load(this, "1.2"); - OfflineDate.load(this); - PlayerDate.load(this); - LotteryUtils.reloadPlayerLottery(); - ChatUtils.setPluginname(Config.getMessage("pluginname")); + @Override + public void onDisable() { + this.getLogger().info("保存彩票数据中..."); + this.getLogger().info("保存玩家数据中..."); + LotteryUtils.saveLottery(); + } - LotteryUtils.setNumbersame(Config.getInstance() - .getBoolean("numbersame")); - LotteryUtils.setPrice(Config.getInstance().getInt("price")); + @Override + public void onEnable() { + PluginManager pm = this.getServer().getPluginManager(); + if (!pm.getPlugin("Vault").isEnabled()) { + this.getLogger().warning("未找到前置插件Vault 关闭插件..."); + this.getServer().getPluginManager().disablePlugin(this); + return; + } + if (setupEconomy()) { + LuckLottery.isEconomy = true; + this.getLogger().info("发现Vault 载入数据..."); + } else { + this.getLogger().warning("发现Vault 但是无法找到经济插件 关闭插件..."); + this.getServer().getPluginManager().disablePlugin(this); + return; + } + int rewardtime = Config.getInstance().getInt("RewardTime", 10); + this.getServer() + .getScheduler() + .runTaskTimer(plugin, new LotteryReward(true), 10, + rewardtime * 60 * 20); + this.getLogger().info("彩票系统已开启..."); + pm.registerEvents(new PlayerListen(), this); + getCommand("ll").setExecutor(new LuckLotteryCommand(this)); + } + + @Override + public void onLoad() { + plugin = this; + Config.load(this, "1.2"); + OfflineDate.load(this); + PlayerDate.load(this); + LotteryUtils.reloadPlayerLottery(); + ChatUtils.setPluginname(Config.getMessage("pluginname")); + + LotteryUtils.setNumbersame(Config.getInstance() + .getBoolean("numbersame")); + LotteryUtils.setPrice(Config.getInstance().getInt("price")); + } + + public boolean setupChat() { + RegisteredServiceProvider chatProvider = getServer() + .getServicesManager().getRegistration( + net.milkbowl.vault.chat.Chat.class); + if (chatProvider != null) { + chat = chatProvider.getProvider(); } - public void onEnable() { - PluginManager pm = this.getServer().getPluginManager(); - if (!pm.getPlugin("Vault").isEnabled()) { - this.getLogger().warning("未找到前置插件Vault 关闭插件..."); - this.getServer().getPluginManager().disablePlugin(this); - return; - } - if (setupEconomy()) { - LuckLottery.isEconomy = true; - this.getLogger().info("发现Vault 载入数据..."); - } else { - this.getLogger().warning("发现Vault 但是无法找到经济插件 关闭插件..."); - this.getServer().getPluginManager().disablePlugin(this); - return; - } - int rewardtime = Config.getInstance().getInt("RewardTime", 10); - this.getServer() - .getScheduler() - .runTaskTimer(plugin, new LotteryReward(true), 10, - rewardtime * 60 * 20); - this.getLogger().info("彩票系统已开启..."); - pm.registerEvents(new PlayerListen(), this); - getCommand("ll").setExecutor(new LuckLotteryCommand(this)); - } + return (chat != null); + } - public void onDisable() { - this.getLogger().info("保存彩票数据中..."); - this.getLogger().info("保存玩家数据中..."); - LotteryUtils.saveLottery(); + public boolean setupEconomy() { + RegisteredServiceProvider economyProvider = getServer() + .getServicesManager().getRegistration( + net.milkbowl.vault.economy.Economy.class); + if (economyProvider != null) { + economy = economyProvider.getProvider(); } + return (economy != null); + } - public boolean setupPermissions() { - RegisteredServiceProvider permissionProvider = getServer() - .getServicesManager().getRegistration( - net.milkbowl.vault.permission.Permission.class); - if (permissionProvider != null) { - permission = permissionProvider.getProvider(); - } - return (permission != null); - } - - public boolean setupChat() { - RegisteredServiceProvider chatProvider = getServer() - .getServicesManager().getRegistration( - net.milkbowl.vault.chat.Chat.class); - if (chatProvider != null) { - chat = chatProvider.getProvider(); - } - - return (chat != null); - } - - public boolean setupEconomy() { - RegisteredServiceProvider economyProvider = getServer() - .getServicesManager().getRegistration( - net.milkbowl.vault.economy.Economy.class); - if (economyProvider != null) { - economy = economyProvider.getProvider(); - } - return (economy != null); + public boolean setupPermissions() { + RegisteredServiceProvider permissionProvider = getServer() + .getServicesManager().getRegistration( + net.milkbowl.vault.permission.Permission.class); + if (permissionProvider != null) { + permission = permissionProvider.getProvider(); } + return (permission != null); + } } diff --git a/src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java b/src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java index fef63c2..3fb67d0 100644 --- a/src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java +++ b/src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java @@ -31,15 +31,7 @@ public class LuckLotteryCommand implements CommandExecutor { int price = LotteryUtils.getPrice(); if (LuckLottery.economy.hasAccount(p) && LuckLottery.economy.has(p, price)) { - // p.closeInventory(); - // plugin.getServer().getScheduler() - // .runTaskLaterAsynchronously(plugin, new Runnable() { - // @Override - // public void run() { InvUtils.openGui(p); - // } - // - // }, 2); } else { ChatUtils.sendMessage(p, ChatColor.GOLD + "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + price @@ -95,9 +87,9 @@ public class LuckLotteryCommand implements CommandExecutor { case "reload": if (PermissionUtils.Check(sender, PermissionUtils.Reload)) { PluginManager pm = plugin.getServer().getPluginManager(); + ChatUtils.sendMessage(sender, ChatColor.GREEN + "配置文件已重载!"); pm.disablePlugin(plugin); pm.enablePlugin(plugin); - ChatUtils.sendMessage(sender, ChatColor.GREEN + "配置文件已重载!"); } return true; case "help": diff --git a/src/cn/citycraft/LuckLottery/config/FileConfig.java b/src/cn/citycraft/LuckLottery/config/FileConfig.java index 6f341e7..84d4dcf 100644 --- a/src/cn/citycraft/LuckLottery/config/FileConfig.java +++ b/src/cn/citycraft/LuckLottery/config/FileConfig.java @@ -30,59 +30,63 @@ 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 init(File file) { - return FileConfig.loadConfiguration(file); + public static FileConfig loadConfiguration(File file) { + Validate.notNull(file, "File cannot be null"); + FileConfig config = new FileConfig(); + try { + config.load(file); + } catch (FileNotFoundException ex) { + } catch (IOException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); + } catch (InvalidConfigurationException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); } + return config; + } - public static FileConfig loadConfiguration(File file) { - Validate.notNull(file, "File cannot be null"); - FileConfig config = new FileConfig(); - try { - config.load(file); - } catch (FileNotFoundException ex) { - } catch (IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); - } catch (InvalidConfigurationException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); - } - return config; - } + protected final DumperOptions yamlOptions = new DumperOptions(); - @Override - public String saveToString() { - yamlOptions.setIndent(options().indent()); - yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - String header = buildHeader(); - String dump = yaml.dump(getValues(false)); - if (dump.equals(BLANK_CONFIG)) { - dump = ""; - } - return header + dump; - } + protected final Representer yamlRepresenter = new YamlRepresenter(); - 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)); - } + protected final Yaml yaml = new Yaml(new YamlConstructor(), + yamlRepresenter, yamlOptions); - 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 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() { + yamlOptions.setIndent(options().indent()); + yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + String header = buildHeader(); + String dump = yaml.dump(getValues(false)); + if (dump.equals(BLANK_CONFIG)) { + dump = ""; + } + return header + dump; + } }