diff --git a/src/main/java/cn/citycraft/LuckLottery/config/PlayerData.java b/src/main/java/cn/citycraft/LuckLottery/config/PlayerData.java index fe2ed1c..b94a0de 100644 --- a/src/main/java/cn/citycraft/LuckLottery/config/PlayerData.java +++ b/src/main/java/cn/citycraft/LuckLottery/config/PlayerData.java @@ -6,6 +6,7 @@ import java.util.Map.Entry; import java.util.Set; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import cn.citycraft.LuckLottery.LuckLottery; @@ -53,11 +54,15 @@ public class PlayerData { return playerLottery; } - @SuppressWarnings("unchecked") public static void loadPlayerLottery(final String p) { - final Map pl = (Map) playerdata.get(p); + final ConfigurationSection pcfg = playerdata.getConfigurationSection(p); + final Set pl = pcfg.getKeys(false); if (pl != null) { - playerLottery.put(p, pl); + final Map tpl = new HashMap<>(); + for (final String ll : pl) { + tpl.put(ll, pcfg.getInt(ll, 0)); + } + playerLottery.put(p, tpl); } } @@ -66,6 +71,9 @@ public class PlayerData { int np = 0; int ncc = 0; for (final Map lls : playerLottery.values()) { + if (lls == null) { + continue; + } for (final Entry a : lls.entrySet()) { nc += a.getValue(); np += LotteryUtils.getPrice() * a.getValue(); @@ -107,8 +115,7 @@ public class PlayerData { final Map pls = phas.getValue(); for (final String lry : pls.keySet()) { has = true; - final int count = pls.get(lry); - ChatUtils.sendMessage(sender, "§a" + lry + (count > 1 ? "*" + count : "")); + showToPlayer(sender, lry, pls.get(lry)); } } if (!has) { @@ -121,11 +128,14 @@ public class PlayerData { if (playerhas != null && !playerhas.isEmpty()) { ChatUtils.sendMessage(p, "§6您当前购买的彩票有:"); for (final String lry : playerhas.keySet()) { - final int count = playerhas.get(lry); - ChatUtils.sendMessage(p, "§a" + lry + (count > 1 ? "*" + count : "")); + showToPlayer(p, lry, playerhas.get(lry)); } } else { ChatUtils.sendMessage(p, "§c您当前没有购买的彩票!"); } } + + public static void showToPlayer(final CommandSender sender, final String lry, final int count) { + ChatUtils.sendMessage(sender, "§a" + lry + (count > 1 ? " §6* §e" + count : "")); + } } diff --git a/src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java b/src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java index 19797f2..05e5685 100644 --- a/src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java +++ b/src/main/java/cn/citycraft/LuckLottery/utils/LotteryUtils.java @@ -1,5 +1,6 @@ package cn.citycraft.LuckLottery.utils; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -18,9 +19,10 @@ public class LotteryUtils { protected static List systemLottery = new ArrayList(); protected static boolean numbersame; protected static int price; + protected final static Random rnd = new SecureRandom(); public static void clearPlayerLottery(final CommandSender sender) { - ChatUtils.sendMessage(sender, "§c提示: 以清除所有玩家彩票数据..."); + ChatUtils.sendMessage(sender, "§c提示: 已清除所有玩家彩票数据..."); PlayerData.clearLottery(); } @@ -29,7 +31,6 @@ public class LotteryUtils { } 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 + "";