diff --git a/.classpath b/.classpath index aff554c..2c705bb 100644 --- a/.classpath +++ b/.classpath @@ -1,20 +1,16 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 7515985..138d1d2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,16 +3,13 @@ 4.0.0 cn.CityCraft LuckLottery - 0.0.7-SNAPSHOT + 1.0 ${project.name} - src - src - - **/*.java - + src/main/resources + true @@ -24,6 +21,39 @@ 1.7 + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + true + + + cn.citycraft:PluginHelper + org.mcstats.*:* + + + + + org.mcstats + ${project.groupId}.${project.artifactId}.mcstats + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + + + + + package + + shade + + + + @@ -39,6 +69,14 @@ vault-repo http://nexus.theyeticave.net/content/repositories/pub_releases + + citycraft-repo + http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/ + + + Plugin Metrics + http://repo.mcstats.org/content/repositories/public + @@ -47,6 +85,12 @@ jar 1.8.3-R0.1-SNAPSHOT + + cn.citycraft + PluginHelper + jar + 1.0 + net.milkbowl.vault VaultAPI @@ -54,6 +98,12 @@ system ${project.basedir}/lib/Vault.jar + + org.mcstats.bukkit + metrics + R8-SNAPSHOT + compile + UTF-8 diff --git a/src/cn/citycraft/LuckLottery/config/Config.java b/src/cn/citycraft/LuckLottery/config/Config.java deleted file mode 100644 index d27f57b..0000000 --- a/src/cn/citycraft/LuckLottery/config/Config.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.citycraft.LuckLottery.config; - -import org.bukkit.plugin.Plugin; - -public class Config extends ConfigLoader { - private static String CONFIG_NAME = "config.yml"; - private static FileConfig instance; - - public Config(Plugin p, String ver) { - super(p, CONFIG_NAME, ver); - instance = super.getInstance(); - } - - public static void load(Plugin p, String ver) { - new Config(p, ver); - } - - public static FileConfig getInstance() { - return instance; - } - - public static String getMessage(String path) { - String message = instance.getString(path).replaceAll("&", "§"); - return message; - } - -} diff --git a/src/cn/citycraft/LuckLottery/config/ConfigLoader.java b/src/cn/citycraft/LuckLottery/config/ConfigLoader.java deleted file mode 100644 index fb0a17d..0000000 --- a/src/cn/citycraft/LuckLottery/config/ConfigLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.citycraft.LuckLottery.config; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.plugin.Plugin; - -public class ConfigLoader extends FileConfig { - protected static FileConfig config; - protected static boolean tip = true; - protected static Plugin plugin; - - public ConfigLoader(Plugin p, File file) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, null, true); - } - - public ConfigLoader(Plugin p, File file, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, null, res); - } - - public ConfigLoader(Plugin p, File file, String ver) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, ver, true); - } - - public ConfigLoader(Plugin p, File file, String ver, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, ver, res); - } - - public ConfigLoader(Plugin p, String filename) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), null, - true); - } - - public ConfigLoader(Plugin p, String filename, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), null, res); - } - - public ConfigLoader(Plugin p, String filename, String ver) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); - } - - public ConfigLoader(Plugin p, String filename, String ver, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), ver, res); - } - - public static FileConfig getInstance() { - return config; - } - - public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) { - tip = res ; - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "..."); - } - if (!file.exists()) { - fileCreate(p, file, res); - } else { - if (ver != null) { - FileConfig configcheck = init(file); - String version = configcheck.getString("version"); - if (version == null || !version.equals(ver)) { - p.saveResource(file.getName(), true); - p.getLogger().warning( - "配置文件: " + file.getName() + " 版本过低 正在升级..."); - } - } - } - if (tip) - p.getLogger().info( - "载入配置文件: " + file.getName() - + (ver != null ? " 版本: " + ver : "")); - return init(file); - } - - private void fileCreate(Plugin p, File file, boolean res) { - if (res) { - p.saveResource(file.getName(), false); - } else { - try { - p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "..."); - file.createNewFile(); - } catch (IOException e) { - p.getLogger().info("配置文件" + file.getName() + "创建失败..."); - e.printStackTrace(); - } - } - } - - public static void saveError(File file) { - plugin.getLogger().info("配置文件" + file.getName() + "保存错误..."); - } - -} diff --git a/src/cn/citycraft/LuckLottery/config/FileConfig.java b/src/cn/citycraft/LuckLottery/config/FileConfig.java deleted file mode 100644 index 7055167..0000000 --- a/src/cn/citycraft/LuckLottery/config/FileConfig.java +++ /dev/null @@ -1,110 +0,0 @@ -package cn.citycraft.LuckLottery.config; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.logging.Level; - -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.configuration.Configuration; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.file.YamlConstructor; -import org.bukkit.configuration.file.YamlRepresenter; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.representer.Representer; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; - -/** - * An implementation of {@link Configuration} which saves all files in Yaml. - * Note that this implementation is not synchronized. - */ -public class FileConfig extends YamlConfiguration { - - 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; - } - - 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 load(Reader reader) throws IOException, InvalidConfigurationException { - BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader - : new BufferedReader(reader); - StringBuilder builder = new StringBuilder(); - try { - String line; - while ((line = input.readLine()) != null) { - builder.append(line); - builder.append('\n'); - } - } finally { - input.close(); - } - loadFromString(builder.toString()); - } - @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; - } -} diff --git a/src/cn/citycraft/LuckLottery/config/OfflineDate.java b/src/cn/citycraft/LuckLottery/config/OfflineDate.java deleted file mode 100644 index 7b9a046..0000000 --- a/src/cn/citycraft/LuckLottery/config/OfflineDate.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.citycraft.LuckLottery.config; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.bukkit.plugin.Plugin; - -public class OfflineDate extends ConfigLoader { - private static String CONFIG_NAME = "offlinedate.yml"; - private static FileConfig instance; - private static File file; - public OfflineDate(Plugin p) { - super(p, CONFIG_NAME, false); - file = new File(p.getDataFolder(), CONFIG_NAME); - instance = super.getInstance(); - } - - public static void load(Plugin p) { - new OfflineDate(p); - } - - public static FileConfig getInstance() { - return instance; - } - - public static List getMessage(String p) { - return instance.getStringList(p); - } - - public static void addMessage(String p, String message) { - List messages = instance.getStringList(p); - messages.add(message); - instance.set(p, messages); - save(); - } - - public static void save(){ - try { - instance.save(file); - } catch (IOException e) { - saveError(file); - e.printStackTrace(); - } - } - -} diff --git a/src/cn/citycraft/LuckLottery/config/PlayerConfig.java b/src/cn/citycraft/LuckLottery/config/PlayerConfig.java deleted file mode 100644 index e9f7b6c..0000000 --- a/src/cn/citycraft/LuckLottery/config/PlayerConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.citycraft.LuckLottery.config; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class PlayerConfig extends ConfigLoader { - private static String CONFIG_FOLDER = "userdate"; - private static FileConfig instance; - private static File file; - - public PlayerConfig(Plugin p, String player) { - super(p, CONFIG_FOLDER + File.separator + player + ".yml", false); - file = new File(p.getDataFolder(), CONFIG_FOLDER + File.separator - + player + ".yml"); - instance = super.getInstance(); - } - - public static FileConfig getInstance(Plugin p, Player player) { - new PlayerConfig(p, player.getName()); - return instance; - } - - public static FileConfig getInstance(Plugin p, String player) { - new PlayerConfig(p, player); - return instance; - } - - public static String getMessage(String path) { - String message = instance.getString(path).replaceAll("&", "§"); - return message; - } - - public static String[] getStringArray(String path) { - return instance.getStringList(path).toArray(new String[0]); - } - - public static void save() { - try { - instance.save(file); - } catch (IOException e) { - saveError(file); - e.printStackTrace(); - } - } -} diff --git a/src/cn/citycraft/LuckLottery/config/PlayerDate.java b/src/cn/citycraft/LuckLottery/config/PlayerDate.java deleted file mode 100644 index 317f5cd..0000000 --- a/src/cn/citycraft/LuckLottery/config/PlayerDate.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.citycraft.LuckLottery.config; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.plugin.Plugin; - -public class PlayerDate extends ConfigLoader { - private static String CONFIG_NAME = "playerdate.yml"; - private static FileConfig instance; - private static File file; - - public PlayerDate(Plugin p) { - super(p, CONFIG_NAME, false); - file = new File(p.getDataFolder(), CONFIG_NAME); - instance = super.getInstance(); - } - - public static void load(Plugin p) { - new PlayerDate(p); - } - - public static FileConfig getInstance() { - return instance; - } - - public static void save() { - try { - instance.save(file); - } catch (IOException e) { - saveError(file); - e.printStackTrace(); - } - } -} diff --git a/src/cn/citycraft/LuckLottery/runnable/LotteryReward.java b/src/cn/citycraft/LuckLottery/runnable/LotteryReward.java deleted file mode 100644 index 5129628..0000000 --- a/src/cn/citycraft/LuckLottery/runnable/LotteryReward.java +++ /dev/null @@ -1,71 +0,0 @@ -package cn.citycraft.LuckLottery.runnable; - -import java.util.List; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; - -import cn.citycraft.LuckLottery.LuckLottery; -import cn.citycraft.LuckLottery.config.Config; -import cn.citycraft.LuckLottery.config.OfflineDate; -import cn.citycraft.LuckLottery.utils.ChatUtils; -import cn.citycraft.LuckLottery.utils.LotteryUtils; - -public class LotteryReward implements Runnable { - - boolean update; - - public LotteryReward(boolean b) { - update = b; - } - - @SuppressWarnings("deprecation") - @Override - public void run() { - if (LotteryUtils.getSystemLottery() == null - || LotteryUtils.getSystemLottery().isEmpty()) { - LotteryUtils.updateSystemLottery(); - return; - } - ChatUtils.broadcastMessage(ChatColor.GOLD + "本轮彩票开奖: " + ChatColor.RED - + LotteryUtils.getSystemLottery().toString()); - ChatUtils.broadcastMessage(ChatColor.BLUE + "使用命令: " + ChatColor.RED - + "/ll" + ChatColor.BLUE + " 或闹钟菜单可以购买彩票!"); - for (Entry>> players : LotteryUtils.playerLottery - .entrySet()) { - OfflinePlayer p = Bukkit.getOfflinePlayer(players.getKey()); - List> pl = players.getValue(); - if (pl != null && !pl.isEmpty()) - for (List playerlottery : pl) { - int win = LotteryUtils.getSameNumber(playerlottery); - int winprices = 0; - winprices = Config.getInstance().getInt("Reward." + win, - 200); - if (winprices > 0) { - ChatUtils.broadcastMessage(ChatColor.GREEN - + p.getName() + "的彩票: " + ChatColor.YELLOW - + playerlottery.toString() + ChatColor.GREEN - + "获得了" + ChatColor.GOLD + winprices - + ChatColor.GREEN + "元!"); - String message = ChatColor.GREEN + "您的彩票: " - + ChatColor.YELLOW + playerlottery.toString() - + ChatColor.GREEN + "获得了" + ChatColor.GOLD - + winprices + ChatColor.GREEN + "元!"; - if (p.isOnline()) { - // ChatUtils.sendMessage((Player) p, message); - } else { - OfflineDate.addMessage(p.getName(), message); - } - LuckLottery.economy.depositPlayer(p, winprices); - } - } - LotteryUtils.playerLottery.put(players.getKey(), null); - } - LotteryUtils.clearLottery(); - if (update) - LotteryUtils.updateSystemLottery(); - } - -} diff --git a/src/cn/citycraft/LuckLottery/utils/VersionChecker.java b/src/cn/citycraft/LuckLottery/utils/VersionChecker.java deleted file mode 100644 index b111cf9..0000000 --- a/src/cn/citycraft/LuckLottery/utils/VersionChecker.java +++ /dev/null @@ -1,112 +0,0 @@ -package cn.citycraft.LuckLottery.utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.Plugin; - -import com.google.common.base.Charsets; - -/** - * 自动更新类 - * - * @author 蒋天蓓 - * 2015年8月14日下午4:01:15 - */ -public class VersionChecker implements Listener { - Plugin plugin; - public String checkurl = "https://coding.net/u/502647092/p/%s/git/raw/%s/src/plugin.yml"; - public String branch = "master"; - - /** - * @param plugin - * - 插件 - */ - public VersionChecker(Plugin plugin) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.versioncheck(null); - } - - /** - * @param plugin - * - 插件 - * @param branch - * - 分支名称 - */ - public VersionChecker(Plugin plugin, String branch) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.branch = branch; - this.versioncheck(null); - } - - /** - * 获取插件更新链接 - * - * @param pluginName - * - 插件名称 - * @param branch - * - 插件分支 - * @return 更新链接 - */ - public String getCheckUrl(String pluginName, String branch) { - return String.format(checkurl, pluginName, branch); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - if (e.getPlayer().isOp()) { - this.versioncheck(e.getPlayer()); - } - } - - /** - * 开始更新 - * - * @param player - * - 获取更新的玩家(null则默认为控制台) - */ - public void versioncheck(final Player player) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - String readURL = getCheckUrl(plugin.getName(), branch); - FileConfiguration config; - String currentVersion = plugin.getDescription().getVersion(); - try { - URL url = new URL(readURL); - BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8)); - config = YamlConfiguration.loadConfiguration(br); - String newVersion = config.getString("version"); - br.close(); - if (!newVersion.equals(currentVersion)) { - String[] msg = new String[] { - ChatColor.GREEN + plugin.getName() + " 插件最新版本 v" + newVersion, - ChatColor.RED + "服务器运行版本: v" + currentVersion, - ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + plugin.getDescription().getWebsite() - }; - if (player != null) { - player.sendMessage(msg); - } else { - plugin.getServer().getConsoleSender().sendMessage(msg); - } - } - } catch (IOException e) { - plugin.getLogger().warning("版本更新检查失败!"); - } - } - }); - } - -} diff --git a/src/cn/citycraft/LuckLottery/LuckLottery.java b/src/main/java/cn/citycraft/LuckLottery/LuckLottery.java similarity index 59% rename from src/cn/citycraft/LuckLottery/LuckLottery.java rename to src/main/java/cn/citycraft/LuckLottery/LuckLottery.java index 11381d7..b567996 100644 --- a/src/cn/citycraft/LuckLottery/LuckLottery.java +++ b/src/main/java/cn/citycraft/LuckLottery/LuckLottery.java @@ -1,25 +1,38 @@ package cn.citycraft.LuckLottery; -import net.milkbowl.vault.economy.Economy; - import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.LuckLottery.command.LuckLotteryCommand; -import cn.citycraft.LuckLottery.config.Config; -import cn.citycraft.LuckLottery.config.OfflineDate; -import cn.citycraft.LuckLottery.config.PlayerDate; import cn.citycraft.LuckLottery.listen.PlayerListen; import cn.citycraft.LuckLottery.runnable.LotteryReward; import cn.citycraft.LuckLottery.utils.ChatUtils; import cn.citycraft.LuckLottery.utils.LotteryUtils; -import cn.citycraft.LuckLottery.utils.VersionChecker; +import cn.citycraft.PluginHelper.config.FileConfig; +import cn.citycraft.PluginHelper.utils.VersionChecker; +import net.milkbowl.vault.economy.Economy; public class LuckLottery extends JavaPlugin { - public static boolean isEconomy; public static Economy economy = null; + public static boolean isEconomy; public static LuckLottery plugin; + protected FileConfig config; + protected FileConfig offlinedata; + protected FileConfig playerdata; + + @Override + public FileConfig getConfig() { + return config; + } + + public FileConfig getOfflinedata() { + return offlinedata; + } + + public FileConfig getPlayerdata() { + return playerdata; + } @Override public void onDisable() { @@ -30,7 +43,7 @@ public class LuckLottery extends JavaPlugin { @Override public void onEnable() { - PluginManager pm = this.getServer().getPluginManager(); + final PluginManager pm = this.getServer().getPluginManager(); if (pm.getPlugin("Vault") == null && !pm.getPlugin("Vault").isEnabled()) { this.getLogger().warning("未找到前置插件Vault 关闭插件..."); this.getServer().getPluginManager().disablePlugin(this); @@ -44,30 +57,29 @@ public class LuckLottery extends JavaPlugin { 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); + final int rewardtime = config.getInt("RewardTime", 10); + this.getServer().getScheduler().runTaskTimer(plugin, new LotteryReward(this, true), 10, rewardtime * 60 * 20); this.getLogger().info("彩票系统已开启..."); new VersionChecker(this); - pm.registerEvents(new PlayerListen(), this); + pm.registerEvents(new PlayerListen(this), this); getCommand("ll").setExecutor(new LuckLotteryCommand(this)); } @Override public void onLoad() { plugin = this; - Config.load(this, "1.2"); - OfflineDate.load(this); - PlayerDate.load(this); + config = new FileConfig(this); + offlinedata = new FileConfig(this, "offlinedata"); + playerdata = new FileConfig(this, "playerdate.yml"); + LotteryUtils.init(this); LotteryUtils.reloadPlayerLottery(); - ChatUtils.setPluginname(Config.getMessage("pluginname")); - LotteryUtils.setNumbersame(Config.getInstance().getBoolean("numbersame")); - LotteryUtils.setPrice(Config.getInstance().getInt("price")); + ChatUtils.setPluginname(config.getMessage("pluginname")); + LotteryUtils.setNumbersame(config.getBoolean("numbersame")); + LotteryUtils.setPrice(config.getInt("price")); } public boolean setupEconomy() { - RegisteredServiceProvider economyProvider = getServer().getServicesManager() - .getRegistration(net.milkbowl.vault.economy.Economy.class); + final RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { economy = economyProvider.getProvider(); } diff --git a/src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java b/src/main/java/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java similarity index 96% rename from src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java rename to src/main/java/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java index 3fb67d0..5e5bef1 100644 --- a/src/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java +++ b/src/main/java/cn/citycraft/LuckLottery/command/LuckLotteryCommand.java @@ -1,121 +1,121 @@ -package cn.citycraft.LuckLottery.command; - -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; - -import cn.citycraft.LuckLottery.LuckLottery; -import cn.citycraft.LuckLottery.utils.ChatUtils; -import cn.citycraft.LuckLottery.utils.InvUtils; -import cn.citycraft.LuckLottery.utils.LotteryUtils; -import cn.citycraft.LuckLottery.utils.PermissionUtils; - -public class LuckLotteryCommand implements CommandExecutor { - - LuckLottery plugin; - - public LuckLotteryCommand(LuckLottery main) { - plugin = main; - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String string, - String[] args) { - switch (args.length) { - case 0: - if (isPlayer(sender)) { - final Player p = (Player) sender; - int price = LotteryUtils.getPrice(); - if (LuckLottery.economy.hasAccount(p) - && LuckLottery.economy.has(p, price)) { - InvUtils.openGui(p); - } else { - ChatUtils.sendMessage(p, ChatColor.GOLD - + "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + price - + ChatColor.GOLD + "元!"); - } - } - return true; - case 1: - switch (args[0]) { - case "load": - if (isPlayer(sender)) { - Player p = (Player) sender; - LotteryUtils.loadPlayerLottery(p); - ChatUtils.sendMessage(p, ChatColor.BLUE + "已加载您的彩票数据..."); - } - return true; - case "show": - if (isPlayer(sender)) { - Player p = (Player) sender; - LotteryUtils.showPlayerLottery(p); - } - return true; - case "clear": - if (PermissionUtils.Check(sender, PermissionUtils.Clear)) { - ChatUtils.sendMessage(sender, ChatColor.LIGHT_PURPLE - + "警告: 即将清理所有彩票数据,此操作将无法取消!"); - ChatUtils.sendMessage(sender, ChatColor.RED - + "命令: 请使用/ll clear confirm 确定清理!"); - } - return true; - case "showall": - if (PermissionUtils.Check(sender, PermissionUtils.ShowAll)) { - LotteryUtils.showAllPlayerLottery(sender); - } - return true; - case "random": - if (PermissionUtils.Check(sender, PermissionUtils.Random)) { - LotteryUtils.updateSystemLottery(sender); - } - return true; - case "reward": - if (PermissionUtils.Check(sender, PermissionUtils.Reward)) { - LotteryUtils.rewardLastLottery(); - ChatUtils - .sendMessage(sender, ChatColor.GREEN + "已结算上一轮彩票!"); - } - return true; - case "look": - if (PermissionUtils.Check(sender, PermissionUtils.Reward)) { - LotteryUtils.showSystemLottery(sender); - } - return true; - case "reload": - if (PermissionUtils.Check(sender, PermissionUtils.Reload)) { - PluginManager pm = plugin.getServer().getPluginManager(); - ChatUtils.sendMessage(sender, ChatColor.GREEN + "配置文件已重载!"); - pm.disablePlugin(plugin); - pm.enablePlugin(plugin); - } - return true; - case "help": - ChatUtils.sendHelp(sender); - return true; - } - break; - case 2: - switch (args[0]) { - case "clear": - if (PermissionUtils.Check(sender, PermissionUtils.Clear)) { - ChatUtils.sendMessage(sender, ChatColor.DARK_RED - + "警告: 已经清理所有彩票数据,此操作无法撤销!"); - LotteryUtils.clearPlayerLottery(sender); - } - return true; - } - default: - } - return false; - } - - public boolean isPlayer(CommandSender p) { - if (p instanceof Player) - return true; - return false; - } - -} +package cn.citycraft.LuckLottery.command; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; + +import cn.citycraft.LuckLottery.LuckLottery; +import cn.citycraft.LuckLottery.utils.ChatUtils; +import cn.citycraft.LuckLottery.utils.InvUtils; +import cn.citycraft.LuckLottery.utils.LotteryUtils; +import cn.citycraft.LuckLottery.utils.PermissionUtils; + +public class LuckLotteryCommand implements CommandExecutor { + + LuckLottery plugin; + + public LuckLotteryCommand(LuckLottery main) { + plugin = main; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String string, + String[] args) { + switch (args.length) { + case 0: + if (isPlayer(sender)) { + final Player p = (Player) sender; + int price = LotteryUtils.getPrice(); + if (LuckLottery.economy.hasAccount(p) + && LuckLottery.economy.has(p, price)) { + InvUtils.openGui(p); + } else { + ChatUtils.sendMessage(p, ChatColor.GOLD + + "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + price + + ChatColor.GOLD + "元!"); + } + } + return true; + case 1: + switch (args[0]) { + case "load": + if (isPlayer(sender)) { + Player p = (Player) sender; + LotteryUtils.loadPlayerLottery(p); + ChatUtils.sendMessage(p, ChatColor.BLUE + "已加载您的彩票数据..."); + } + return true; + case "show": + if (isPlayer(sender)) { + Player p = (Player) sender; + LotteryUtils.showPlayerLottery(p); + } + return true; + case "clear": + if (PermissionUtils.Check(sender, PermissionUtils.Clear)) { + ChatUtils.sendMessage(sender, ChatColor.LIGHT_PURPLE + + "警告: 即将清理所有彩票数据,此操作将无法取消!"); + ChatUtils.sendMessage(sender, ChatColor.RED + + "命令: 请使用/ll clear confirm 确定清理!"); + } + return true; + case "showall": + if (PermissionUtils.Check(sender, PermissionUtils.ShowAll)) { + LotteryUtils.showAllPlayerLottery(sender); + } + return true; + case "random": + if (PermissionUtils.Check(sender, PermissionUtils.Random)) { + LotteryUtils.updateSystemLottery(sender); + } + return true; + case "reward": + if (PermissionUtils.Check(sender, PermissionUtils.Reward)) { + LotteryUtils.rewardLastLottery(); + ChatUtils + .sendMessage(sender, ChatColor.GREEN + "已结算上一轮彩票!"); + } + return true; + case "look": + if (PermissionUtils.Check(sender, PermissionUtils.Reward)) { + LotteryUtils.showSystemLottery(sender); + } + return true; + case "reload": + if (PermissionUtils.Check(sender, PermissionUtils.Reload)) { + PluginManager pm = plugin.getServer().getPluginManager(); + ChatUtils.sendMessage(sender, ChatColor.GREEN + "配置文件已重载!"); + pm.disablePlugin(plugin); + pm.enablePlugin(plugin); + } + return true; + case "help": + ChatUtils.sendHelp(sender); + return true; + } + break; + case 2: + switch (args[0]) { + case "clear": + if (PermissionUtils.Check(sender, PermissionUtils.Clear)) { + ChatUtils.sendMessage(sender, ChatColor.DARK_RED + + "警告: 已经清理所有彩票数据,此操作无法撤销!"); + LotteryUtils.clearPlayerLottery(sender); + } + return true; + } + default: + } + return false; + } + + public boolean isPlayer(CommandSender p) { + if (p instanceof Player) + return true; + return false; + } + +} diff --git a/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java b/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java new file mode 100644 index 0000000..3483482 --- /dev/null +++ b/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java @@ -0,0 +1,27 @@ +package cn.citycraft.LuckLottery.config; + +import java.util.List; + +import org.bukkit.plugin.Plugin; + +import cn.citycraft.PluginHelper.config.FileConfig; + +public class OfflineDate { + private static String CONFIG_NAME = "offlinedate.yml"; + private static FileConfig instance; + + public OfflineDate(final Plugin p) { + instance = new FileConfig(p, CONFIG_NAME); + } + + public static void addMessage(final String p, final String message) { + final List messages = instance.getStringList(p); + messages.add(message); + instance.set(p, messages); + instance.save(); + } + + public static List getMessage(final String p) { + return instance.getStringList(p); + } +} diff --git a/src/cn/citycraft/LuckLottery/listen/PlayerListen.java b/src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java similarity index 56% rename from src/cn/citycraft/LuckLottery/listen/PlayerListen.java rename to src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java index 41fb108..a9967d6 100644 --- a/src/cn/citycraft/LuckLottery/listen/PlayerListen.java +++ b/src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java @@ -22,45 +22,35 @@ import cn.citycraft.LuckLottery.utils.InvUtils; import cn.citycraft.LuckLottery.utils.LotteryUtils; public class PlayerListen implements Listener { + LuckLottery plugin; - @EventHandler( - priority = EventPriority.HIGH) - public void onPlayerInteract(PlayerJoinEvent e) { - Player p = e.getPlayer(); - List messages = OfflineDate.getMessage(p.getName()); - if (messages != null && !messages.isEmpty()) { - Bukkit.getServer().getScheduler() - .runTaskLaterAsynchronously(LuckLottery.plugin, new LaterShow(p, messages), 5); - OfflineDate.getInstance().set(p.getName(), null); - OfflineDate.save(); - } + public PlayerListen(final LuckLottery luckLottery) { + this.plugin = luckLottery; } - @EventHandler( - priority = EventPriority.HIGHEST, - ignoreCancelled = true) - public void onInventoryClick(InventoryClickEvent e) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onInventoryClick(final InventoryClickEvent e) { if (InvUtils.isLotteryGUI(e.getInventory())) { e.setCancelled(true); - Player p = (Player) e.getWhoClicked(); - ItemStack ci = e.getCurrentItem(); - Inventory inv = e.getInventory(); - int solt = e.getRawSlot(); - if (ci == null || ci.getType() == Material.AIR) + final Player p = (Player) e.getWhoClicked(); + final ItemStack ci = e.getCurrentItem(); + final Inventory inv = e.getInventory(); + final int solt = e.getRawSlot(); + if (ci == null || ci.getType() == Material.AIR) { return; - if (!ci.getItemMeta().hasDisplayName()) + } + if (!ci.getItemMeta().hasDisplayName()) { return; - String clickName = ci.getItemMeta().getDisplayName(); + } + final String clickName = ci.getItemMeta().getDisplayName(); switch (clickName) { case InvUtils.Create: - if (!LuckLottery.economy.hasAccount(p) - || !LuckLottery.economy.has(p, LotteryUtils.getPrice())) { - ChatUtils.sendMessage(p, ChatColor.GOLD + "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED - + LotteryUtils.getPrice() + ChatColor.GOLD + "元!"); + if (!LuckLottery.economy.hasAccount(p) || !LuckLottery.economy.has(p, LotteryUtils.getPrice())) { + ChatUtils.sendMessage(p, ChatColor.GOLD + "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + LotteryUtils.getPrice() + ChatColor.GOLD + "元!"); p.closeInventory(); return; } - List lottery = InvUtils.getLotteryNumber(inv); + final List lottery = InvUtils.getLotteryNumber(inv); LotteryUtils.addLottery(p, lottery); ChatUtils.sendMessage(p, "§6您当前购买的彩票号码为: " + ChatColor.GREEN + lottery.toString()); ChatUtils.howToShow(p); @@ -72,8 +62,9 @@ public class PlayerListen implements Listener { break; default: if (solt < 36 && InvUtils.isLotteryItem(ci)) { - if (setSelect(inv, ci)) + if (setSelect(inv, ci)) { inv.setItem(solt, InvUtils.A); + } } break; } @@ -85,7 +76,18 @@ public class PlayerListen implements Listener { } } - private boolean setSelect(Inventory inv, ItemStack is) { + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerInteract(final PlayerJoinEvent e) { + final Player p = e.getPlayer(); + final List messages = OfflineDate.getMessage(p.getName()); + if (messages != null && !messages.isEmpty()) { + Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(LuckLottery.plugin, new LaterShow(p, messages), 5); + plugin.getOfflinedata().set(p.getName(), null); + plugin.getOfflinedata().save(); + } + } + + private boolean setSelect(final Inventory inv, final ItemStack is) { for (int i = 45; i < 53; i++) { if (inv.getItem(i) == null) { inv.setItem(i, is); diff --git a/src/cn/citycraft/LuckLottery/runnable/LaterShow.java b/src/main/java/cn/citycraft/LuckLottery/runnable/LaterShow.java similarity index 95% rename from src/cn/citycraft/LuckLottery/runnable/LaterShow.java rename to src/main/java/cn/citycraft/LuckLottery/runnable/LaterShow.java index eed96bb..512308f 100644 --- a/src/cn/citycraft/LuckLottery/runnable/LaterShow.java +++ b/src/main/java/cn/citycraft/LuckLottery/runnable/LaterShow.java @@ -1,26 +1,26 @@ -package cn.citycraft.LuckLottery.runnable; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import cn.citycraft.LuckLottery.utils.ChatUtils; - -public class LaterShow implements Runnable { - - Player p; - List messages; - - public LaterShow(Player p, List messages) { - this.p = p; - this.messages = messages; - } - - @Override - public void run() { - ChatUtils.sendMessage(p, ChatColor.RED + "在您离线期间彩票开奖结果:"); - ChatUtils.sendMessage(p, messages); - } - -} +package cn.citycraft.LuckLottery.runnable; + +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import cn.citycraft.LuckLottery.utils.ChatUtils; + +public class LaterShow implements Runnable { + + Player p; + List messages; + + public LaterShow(Player p, List messages) { + this.p = p; + this.messages = messages; + } + + @Override + public void run() { + ChatUtils.sendMessage(p, ChatColor.RED + "在您离线期间彩票开奖结果:"); + ChatUtils.sendMessage(p, messages); + } + +} diff --git a/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java b/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java new file mode 100644 index 0000000..bec05e5 --- /dev/null +++ b/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java @@ -0,0 +1,62 @@ +package cn.citycraft.LuckLottery.runnable; + +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; + +import cn.citycraft.LuckLottery.LuckLottery; +import cn.citycraft.LuckLottery.config.OfflineDate; +import cn.citycraft.LuckLottery.utils.ChatUtils; +import cn.citycraft.LuckLottery.utils.LotteryUtils; + +public class LotteryReward implements Runnable { + LuckLottery plugin; + boolean update; + + public LotteryReward(final LuckLottery plugin, final boolean b) { + this.plugin = plugin; + update = b; + } + + @SuppressWarnings("deprecation") + @Override + public void run() { + if (LotteryUtils.getSystemLottery() == null || LotteryUtils.getSystemLottery().isEmpty()) { + LotteryUtils.updateSystemLottery(); + return; + } + ChatUtils.broadcastMessage(ChatColor.GOLD + "本轮彩票开奖: " + ChatColor.RED + LotteryUtils.getSystemLottery().toString()); + ChatUtils.broadcastMessage(ChatColor.BLUE + "使用命令: " + ChatColor.RED + "/ll" + ChatColor.BLUE + " 或闹钟菜单可以购买彩票!"); + for (final Entry>> players : LotteryUtils.playerLottery.entrySet()) { + final OfflinePlayer p = Bukkit.getOfflinePlayer(players.getKey()); + final List> pl = players.getValue(); + if (pl != null && !pl.isEmpty()) { + for (final List playerlottery : pl) { + final int win = LotteryUtils.getSameNumber(playerlottery); + int winprices = 0; + winprices = plugin.getConfig().getInt("Reward." + win, 200); + if (winprices > 0) { + ChatUtils.broadcastMessage( + ChatColor.GREEN + p.getName() + "的彩票: " + ChatColor.YELLOW + playerlottery.toString() + ChatColor.GREEN + "获得了" + ChatColor.GOLD + winprices + ChatColor.GREEN + "元!"); + final String message = ChatColor.GREEN + "您的彩票: " + ChatColor.YELLOW + playerlottery.toString() + ChatColor.GREEN + "获得了" + ChatColor.GOLD + winprices + ChatColor.GREEN + "元!"; + if (p.isOnline()) { + // ChatUtils.sendMessage((Player) p, message); + } else { + OfflineDate.addMessage(p.getName(), message); + } + LuckLottery.economy.depositPlayer(p, winprices); + } + } + } + LotteryUtils.playerLottery.put(players.getKey(), null); + } + LotteryUtils.clearLottery(); + if (update) { + LotteryUtils.updateSystemLottery(); + } + } + +} diff --git a/src/cn/citycraft/LuckLottery/utils/ChatUtils.java b/src/main/java/cn/citycraft/LuckLottery/utils/ChatUtils.java similarity index 96% rename from src/cn/citycraft/LuckLottery/utils/ChatUtils.java rename to src/main/java/cn/citycraft/LuckLottery/utils/ChatUtils.java index 7819e9e..1ad79cb 100644 --- a/src/cn/citycraft/LuckLottery/utils/ChatUtils.java +++ b/src/main/java/cn/citycraft/LuckLottery/utils/ChatUtils.java @@ -1,77 +1,77 @@ -package cn.citycraft.LuckLottery.utils; - -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class ChatUtils { - protected static String pluginname = ""; - public static String[] helps = new String[]{ - "§6=========彩票插件帮助========", - "§a/ll 打开彩票购买界面", - "§b/ll show 查看已购买彩票", - "§3/ll showall查看所以玩家已购买彩票§4(管理员命令)", - "§c/ll random 重新生成彩票§4(管理员命令)", - "§d/ll reward 结算上一轮彩票§4(管理员命令)", - "§e/ll clear 清除所有已购买彩票§4(管理员命令)", - "§5/ll look 查看本轮彩票号码§4(管理员命令)", - "§c/ll reload 重载彩票插件§4(管理员命令)" - }; - - public static String getPluginname() { - return pluginname; - } - - public static void setPluginname(String pluginname) { - ChatUtils.pluginname = pluginname; - } - - public static void sendMessage(Player p, String message) { - p.sendMessage(pluginname + message); - } - - public static void sendMessage(CommandSender p, String message) { - p.sendMessage(pluginname + message); - } - - public static void sendMessage(Player p, String[] messages) { - for (String msg : messages) { - sendMessage(p, msg); - } - } - - public static void sendMessage(Player p, List messages) { - for (String msg : messages) { - sendMessage(p, msg); - } - } - - public static void sendHelp(Player p){ - p.sendMessage(helps); - } - - public static void sendHelp(CommandSender sender) { - sender.sendMessage(helps); - } - - public static void broadcastMessage(String message) { - Bukkit.broadcastMessage(pluginname + message); - } - - public static void howToShow(Player p) { - sendMessage(p, ChatColor.GOLD + "命令: " + ChatColor.RED + "/ll show " - + ChatColor.GOLD + "查看已购买彩票!"); - } - - public static void noPermission(Player p) { - ChatUtils.sendMessage(p, PermissionUtils.No_Permission); - } - - public static void noPermission(CommandSender p) { - ChatUtils.sendMessage(p, PermissionUtils.No_Permission); - } - -} +package cn.citycraft.LuckLottery.utils; + +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ChatUtils { + protected static String pluginname = ""; + public static String[] helps = new String[]{ + "§6=========彩票插件帮助========", + "§a/ll 打开彩票购买界面", + "§b/ll show 查看已购买彩票", + "§3/ll showall查看所以玩家已购买彩票§4(管理员命令)", + "§c/ll random 重新生成彩票§4(管理员命令)", + "§d/ll reward 结算上一轮彩票§4(管理员命令)", + "§e/ll clear 清除所有已购买彩票§4(管理员命令)", + "§5/ll look 查看本轮彩票号码§4(管理员命令)", + "§c/ll reload 重载彩票插件§4(管理员命令)" + }; + + public static String getPluginname() { + return pluginname; + } + + public static void setPluginname(String pluginname) { + ChatUtils.pluginname = pluginname; + } + + public static void sendMessage(Player p, String message) { + p.sendMessage(pluginname + message); + } + + public static void sendMessage(CommandSender p, String message) { + p.sendMessage(pluginname + message); + } + + public static void sendMessage(Player p, String[] messages) { + for (String msg : messages) { + sendMessage(p, msg); + } + } + + public static void sendMessage(Player p, List messages) { + for (String msg : messages) { + sendMessage(p, msg); + } + } + + public static void sendHelp(Player p){ + p.sendMessage(helps); + } + + public static void sendHelp(CommandSender sender) { + sender.sendMessage(helps); + } + + public static void broadcastMessage(String message) { + Bukkit.broadcastMessage(pluginname + message); + } + + public static void howToShow(Player p) { + sendMessage(p, ChatColor.GOLD + "命令: " + ChatColor.RED + "/ll show " + + ChatColor.GOLD + "查看已购买彩票!"); + } + + public static void noPermission(Player p) { + ChatUtils.sendMessage(p, PermissionUtils.No_Permission); + } + + public static void noPermission(CommandSender p) { + ChatUtils.sendMessage(p, PermissionUtils.No_Permission); + } + +} diff --git a/src/cn/citycraft/LuckLottery/utils/InvUtils.java b/src/main/java/cn/citycraft/LuckLottery/utils/InvUtils.java similarity index 100% rename from src/cn/citycraft/LuckLottery/utils/InvUtils.java rename to src/main/java/cn/citycraft/LuckLottery/utils/InvUtils.java diff --git a/src/cn/citycraft/LuckLottery/utils/LotteryUtils.java b/src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java similarity index 54% rename from src/cn/citycraft/LuckLottery/utils/LotteryUtils.java rename to src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java index c8bb0e9..e6c7cf5 100644 --- a/src/cn/citycraft/LuckLottery/utils/LotteryUtils.java +++ b/src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java @@ -1,222 +1,221 @@ -package cn.citycraft.LuckLottery.utils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Random; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import cn.citycraft.LuckLottery.LuckLottery; -import cn.citycraft.LuckLottery.config.PlayerDate; -import cn.citycraft.LuckLottery.runnable.LotteryReward; - -public class LotteryUtils { - protected static List systemLottery = new ArrayList(); - - public static Map>> playerLottery = new HashMap>>(); - - protected static boolean numbersame; - - protected static int price; - - public static List> addLottery(Player player, - List lottery) { - List> playerhas = playerLottery.get(player.getName()); - if (playerhas == null) { - playerhas = new ArrayList>(); - } - playerhas.add(lottery); - playerLottery.put(player.getName(), playerhas); - PlayerDate.getInstance().set(player.getName(), playerhas); - PlayerDate.save(); - return playerhas; - } - - public static void saveLottery() { - for (Entry>> pl : playerLottery.entrySet()) { - String p = pl.getKey(); - List> l = pl.getValue(); - PlayerDate.getInstance().set(p, l); - } - PlayerDate.save(); - } - - @SuppressWarnings("unchecked") - public static void loadPlayerLottery(Player p) { - List pl = PlayerDate.getInstance().getList(p.getName()); - if (pl != null) { - playerLottery.put(p.getName(), (List>) pl); - } - } - - @SuppressWarnings("unchecked") - public static void reloadPlayerLottery() { - Set apl = PlayerDate.getInstance().getKeys(false); - for (String p : apl) { - List pl = PlayerDate.getInstance().getList(p); - if (pl != null) { - playerLottery.put(p, (List>) pl); - } - } - } - - public static void showPlayerLottery(Player p) { - List> playerhas = playerLottery.get(p.getName()); - if (playerhas != null && !playerhas.isEmpty()) { - ChatUtils.sendMessage(p, "§6您当前购买的彩票有:"); - for (List lry : playerhas) { - ChatUtils.sendMessage(p, "§a" + lry.toString()); - } - } else { - ChatUtils.sendMessage(p, "§c您当前没有购买的彩票!"); - } - } - - public static void showAllPlayerLottery(CommandSender sender) { - ChatUtils.sendMessage(sender, "§c正在检索玩家彩票数据..."); - boolean has = false; - for (Entry>> phas : playerLottery.entrySet()) { - ChatUtils.sendMessage(sender, "§6玩家: §a" + phas.getKey() - + "§6购买的彩票有"); - for (List lry : phas.getValue()) { - has = true; - ChatUtils.sendMessage(sender, "§a" + lry.toString()); - } - } - if (!has) { - ChatUtils.sendMessage(sender, "§d没有玩家购买本轮彩票..."); - } - } - - public static void clearLottery() { - for (Entry>> pl : playerLottery.entrySet()) { - String p = pl.getKey(); - PlayerDate.getInstance().set(p, null); - } - playerLottery.clear(); - PlayerDate.save(); - } - - public static void clearPlayerLottery(CommandSender sender) { - ChatUtils.sendMessage(sender, "§c提示: 以清除所有玩家彩票数据..."); - clearLottery(); - } - - public static void rewardLastLottery() { - Bukkit.getServer() - .getScheduler() - .runTaskAsynchronously(LuckLottery.plugin, - new LotteryReward(true)); - } - - public static List getSystemLottery() { - return systemLottery; - } - - public static void setSystemLottery(List systemLottery) { - LotteryUtils.systemLottery = systemLottery; - } - - public static int getPrice() { - return price; - } - - public static void setPrice(int price) { - LotteryUtils.price = price; - } - - public static void updateSystemLottery() { - LotteryUtils.systemLottery = LotteryUtils.getRandomNumber(); - } - - public static void updateSystemLottery(CommandSender p) { - LotteryUtils.systemLottery = LotteryUtils.getRandomNumber(); - ChatUtils.sendMessage(p, ChatColor.BLUE + "已随机生成彩票: " - + ChatColor.YELLOW + LotteryUtils.systemLottery.toString()); - } - - public static void showSystemLottery(CommandSender p) { - ChatUtils.sendMessage(p, ChatColor.DARK_PURPLE + "此轮彩票号码为: " - + ChatColor.YELLOW + LotteryUtils.systemLottery.toString()); - } - - public static int getSameNumber(List lottery) { - int samenum = 0; - List system = systemLottery; - if (numbersame) { - for (int i = 0; i < lottery.size(); i++) { - if (lottery.get(i).equals(system.get(i))) { - samenum++; - } - } - } else { - for (String pn : lottery) { - for (String sn : system) { - if (pn.equals(sn)) - samenum++; - } - } - } - if (lottery.get(lottery.size() - 1).equalsIgnoreCase( - system.get(system.size() - 1))) - samenum += 9; - return samenum; - } - - /** - * @return numbersame - */ - public static boolean isNumbersame() { - return numbersame; - } - - /** - * @param numbersame - * 要设置的 numbersame - */ - public static void setNumbersame(boolean numbersame) { - LotteryUtils.numbersame = numbersame; - } - - public static int getSameNumber(List lottery, List system) { - int samenum = 0; - if (numbersame) { - for (int i = 0; i < lottery.size(); i++) { - if (lottery.get(i).equals(system.get(i))) { - samenum++; - } - } - } else { - for (String pn : lottery) { - for (String sn : system) { - if (pn.equals(sn)) - samenum++; - } - } - } - if (lottery.get(lottery.size() - 1).equalsIgnoreCase( - system.get(system.size() - 1))) - samenum += 9; - return samenum; - } - - public static List getRandomNumber() { - Random rnd = new Random(); - List normal = new ArrayList(); - for (int i = 1; i < 8; i++) { - String rr = rnd.nextInt(32) + 1 + ""; - while (normal.contains(rr)) { - rr = rnd.nextInt(32) + 1 + ""; - } - normal.add(rr); - } - return normal; - } -} +package cn.citycraft.LuckLottery.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import cn.citycraft.LuckLottery.LuckLottery; +import cn.citycraft.LuckLottery.runnable.LotteryReward; +import cn.citycraft.PluginHelper.config.FileConfig; + +public class LotteryUtils { + public static Map>> playerLottery = new HashMap>>(); + protected static boolean numbersame; + protected static FileConfig playerdata; + protected static LuckLottery plugin; + protected static int price; + protected static List systemLottery = new ArrayList(); + + public static List> addLottery(final Player player, final List lottery) { + List> playerhas = playerLottery.get(player.getName()); + if (playerhas == null) { + playerhas = new ArrayList>(); + } + playerhas.add(lottery); + playerLottery.put(player.getName(), playerhas); + playerdata.set(player.getName(), playerhas); + playerdata.save(); + return playerhas; + } + + public static void clearLottery() { + for (final Entry>> pl : playerLottery.entrySet()) { + final String p = pl.getKey(); + playerdata.set(p, null); + } + playerLottery.clear(); + playerdata.save(); + } + + public static void clearPlayerLottery(final CommandSender sender) { + ChatUtils.sendMessage(sender, "§c提示: 以清除所有玩家彩票数据..."); + clearLottery(); + } + + public static int getPrice() { + return price; + } + + public static List getRandomNumber() { + final Random rnd = new Random(); + final List normal = new ArrayList(); + for (int i = 1; i < 8; i++) { + String rr = rnd.nextInt(32) + 1 + ""; + while (normal.contains(rr)) { + rr = rnd.nextInt(32) + 1 + ""; + } + normal.add(rr); + } + return normal; + } + + public static int getSameNumber(final List lottery) { + int samenum = 0; + final List system = systemLottery; + if (numbersame) { + for (int i = 0; i < lottery.size(); i++) { + if (lottery.get(i).equals(system.get(i))) { + samenum++; + } + } + } else { + for (final String pn : lottery) { + for (final String sn : system) { + if (pn.equals(sn)) { + samenum++; + } + } + } + } + if (lottery.get(lottery.size() - 1).equalsIgnoreCase(system.get(system.size() - 1))) { + samenum += 9; + } + return samenum; + } + + public static int getSameNumber(final List lottery, final List system) { + int samenum = 0; + if (numbersame) { + for (int i = 0; i < lottery.size(); i++) { + if (lottery.get(i).equals(system.get(i))) { + samenum++; + } + } + } else { + for (final String pn : lottery) { + for (final String sn : system) { + if (pn.equals(sn)) { + samenum++; + } + } + } + } + if (lottery.get(lottery.size() - 1).equalsIgnoreCase(system.get(system.size() - 1))) { + samenum += 9; + } + return samenum; + } + + public static List getSystemLottery() { + return systemLottery; + } + + public static void init(final LuckLottery luckLottery) { + plugin = luckLottery; + playerdata = plugin.getPlayerdata(); + } + + /** + * @return numbersame + */ + public static boolean isNumbersame() { + return numbersame; + } + + @SuppressWarnings("unchecked") + public static void loadPlayerLottery(final Player p) { + final List pl = playerdata.getList(p.getName()); + if (pl != null) { + playerLottery.put(p.getName(), (List>) pl); + } + } + + @SuppressWarnings("unchecked") + public static void reloadPlayerLottery() { + final Set apl = playerdata.getKeys(false); + for (final String p : apl) { + final List pl = playerdata.getList(p); + if (pl != null) { + playerLottery.put(p, (List>) pl); + } + } + } + + public static void rewardLastLottery() { + Bukkit.getServer().getScheduler().runTaskAsynchronously(LuckLottery.plugin, new LotteryReward(plugin, true)); + } + + public static void saveLottery() { + for (final Entry>> pl : playerLottery.entrySet()) { + final String p = pl.getKey(); + final List> l = pl.getValue(); + playerdata.set(p, l); + } + playerdata.save(); + } + + /** + * @param numbersame + * 要设置的 numbersame + */ + public static void setNumbersame(final boolean numbersame) { + LotteryUtils.numbersame = numbersame; + } + + public static void setPrice(final int price) { + LotteryUtils.price = price; + } + + public static void setSystemLottery(final List systemLottery) { + LotteryUtils.systemLottery = systemLottery; + } + + public static void showAllPlayerLottery(final CommandSender sender) { + ChatUtils.sendMessage(sender, "§c正在检索玩家彩票数据..."); + boolean has = false; + for (final Entry>> phas : playerLottery.entrySet()) { + ChatUtils.sendMessage(sender, "§6玩家: §a" + phas.getKey() + "§6购买的彩票有"); + for (final List lry : phas.getValue()) { + has = true; + ChatUtils.sendMessage(sender, "§a" + lry.toString()); + } + } + if (!has) { + ChatUtils.sendMessage(sender, "§d没有玩家购买本轮彩票..."); + } + } + + public static void showPlayerLottery(final Player p) { + final List> playerhas = playerLottery.get(p.getName()); + if (playerhas != null && !playerhas.isEmpty()) { + ChatUtils.sendMessage(p, "§6您当前购买的彩票有:"); + for (final List lry : playerhas) { + ChatUtils.sendMessage(p, "§a" + lry.toString()); + } + } else { + ChatUtils.sendMessage(p, "§c您当前没有购买的彩票!"); + } + } + + public static void showSystemLottery(final CommandSender p) { + ChatUtils.sendMessage(p, ChatColor.DARK_PURPLE + "此轮彩票号码为: " + ChatColor.YELLOW + LotteryUtils.systemLottery.toString()); + } + + public static void updateSystemLottery() { + LotteryUtils.systemLottery = LotteryUtils.getRandomNumber(); + } + + public static void updateSystemLottery(final CommandSender p) { + LotteryUtils.systemLottery = LotteryUtils.getRandomNumber(); + ChatUtils.sendMessage(p, ChatColor.BLUE + "已随机生成彩票: " + ChatColor.YELLOW + LotteryUtils.systemLottery.toString()); + } +} diff --git a/src/cn/citycraft/LuckLottery/utils/PermissionUtils.java b/src/main/java/cn/citycraft/LuckLottery/utils/PermissionUtils.java similarity index 100% rename from src/cn/citycraft/LuckLottery/utils/PermissionUtils.java rename to src/main/java/cn/citycraft/LuckLottery/utils/PermissionUtils.java diff --git a/src/config.yml b/src/main/resources/config.yml similarity index 100% rename from src/config.yml rename to src/main/resources/config.yml diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 79% rename from src/plugin.yml rename to src/main/resources/plugin.yml index 4ce3c78..88dec0c 100644 --- a/src/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,9 @@ -name: LuckLottery -main: cn.citycraft.LuckLottery.LuckLottery +name: ${project.artifactId} +description: ${project.description} +main: ${project.groupId}.${project.artifactId}.${project.artifactId} +version: ${project.version} author: 喵♂呜 -website: http://ci.citycraft.cn:8800/jenkins/job/LuckLottery/ -version: 0.1.0 +website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/ depended: [Vault] commands: lucklottery: