mirror of
https://e.coding.net/circlecloud/LuckLottery.git
synced 2024-11-16 09:58:50 +00:00
fix: 修复随机数BUG 调整数量显示
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
46760c331e
commit
518a5edb90
@ -6,6 +6,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cn.citycraft.LuckLottery.LuckLottery;
|
import cn.citycraft.LuckLottery.LuckLottery;
|
||||||
@ -53,11 +54,15 @@ public class PlayerData {
|
|||||||
return playerLottery;
|
return playerLottery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void loadPlayerLottery(final String p) {
|
public static void loadPlayerLottery(final String p) {
|
||||||
final Map<String, Integer> pl = (Map<String, Integer>) playerdata.get(p);
|
final ConfigurationSection pcfg = playerdata.getConfigurationSection(p);
|
||||||
|
final Set<String> pl = pcfg.getKeys(false);
|
||||||
if (pl != null) {
|
if (pl != null) {
|
||||||
playerLottery.put(p, pl);
|
final Map<String, Integer> 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 np = 0;
|
||||||
int ncc = 0;
|
int ncc = 0;
|
||||||
for (final Map<String, Integer> lls : playerLottery.values()) {
|
for (final Map<String, Integer> lls : playerLottery.values()) {
|
||||||
|
if (lls == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (final Entry<String, Integer> a : lls.entrySet()) {
|
for (final Entry<String, Integer> a : lls.entrySet()) {
|
||||||
nc += a.getValue();
|
nc += a.getValue();
|
||||||
np += LotteryUtils.getPrice() * a.getValue();
|
np += LotteryUtils.getPrice() * a.getValue();
|
||||||
@ -107,8 +115,7 @@ public class PlayerData {
|
|||||||
final Map<String, Integer> pls = phas.getValue();
|
final Map<String, Integer> pls = phas.getValue();
|
||||||
for (final String lry : pls.keySet()) {
|
for (final String lry : pls.keySet()) {
|
||||||
has = true;
|
has = true;
|
||||||
final int count = pls.get(lry);
|
showToPlayer(sender, lry, pls.get(lry));
|
||||||
ChatUtils.sendMessage(sender, "§a" + lry + (count > 1 ? "*" + count : ""));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!has) {
|
if (!has) {
|
||||||
@ -121,11 +128,14 @@ public class PlayerData {
|
|||||||
if (playerhas != null && !playerhas.isEmpty()) {
|
if (playerhas != null && !playerhas.isEmpty()) {
|
||||||
ChatUtils.sendMessage(p, "§6您当前购买的彩票有:");
|
ChatUtils.sendMessage(p, "§6您当前购买的彩票有:");
|
||||||
for (final String lry : playerhas.keySet()) {
|
for (final String lry : playerhas.keySet()) {
|
||||||
final int count = playerhas.get(lry);
|
showToPlayer(p, lry, playerhas.get(lry));
|
||||||
ChatUtils.sendMessage(p, "§a" + lry + (count > 1 ? "*" + count : ""));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ChatUtils.sendMessage(p, "§c您当前没有购买的彩票!");
|
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 : ""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.citycraft.LuckLottery.utils;
|
package cn.citycraft.LuckLottery.utils;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,9 +19,10 @@ public class LotteryUtils {
|
|||||||
protected static List<String> systemLottery = new ArrayList<String>();
|
protected static List<String> systemLottery = new ArrayList<String>();
|
||||||
protected static boolean numbersame;
|
protected static boolean numbersame;
|
||||||
protected static int price;
|
protected static int price;
|
||||||
|
protected final static Random rnd = new SecureRandom();
|
||||||
|
|
||||||
public static void clearPlayerLottery(final CommandSender sender) {
|
public static void clearPlayerLottery(final CommandSender sender) {
|
||||||
ChatUtils.sendMessage(sender, "§c提示: 以清除所有玩家彩票数据...");
|
ChatUtils.sendMessage(sender, "§c提示: 已清除所有玩家彩票数据...");
|
||||||
PlayerData.clearLottery();
|
PlayerData.clearLottery();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +31,6 @@ public class LotteryUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getRandomNumber() {
|
public static List<String> getRandomNumber() {
|
||||||
final Random rnd = new Random();
|
|
||||||
final List<String> normal = new ArrayList<String>();
|
final List<String> normal = new ArrayList<String>();
|
||||||
for (int i = 1; i < 8; i++) {
|
for (int i = 1; i < 8; i++) {
|
||||||
String rr = rnd.nextInt(32) + 1 + "";
|
String rr = rnd.nextInt(32) + 1 + "";
|
||||||
|
Loading…
Reference in New Issue
Block a user