63 lines
2.7 KiB
Java
63 lines
2.7 KiB
Java
package pw.yumc.LuckLottery.runnable;
|
|
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import pw.yumc.LuckLottery.LuckLottery;
|
|
import pw.yumc.LuckLottery.config.PlayerData;
|
|
import pw.yumc.LuckLottery.utils.ChatUtils;
|
|
import pw.yumc.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 + " 或闹钟菜单可以购买彩票!");
|
|
int priceTotal = 0;
|
|
for (final Entry<String, Map<String, Integer>> players : PlayerData.playerLottery.entrySet()) {
|
|
final OfflinePlayer p = Bukkit.getOfflinePlayer(players.getKey());
|
|
final Map<String, Integer> pl = players.getValue();
|
|
if (pl != null && !pl.isEmpty()) {
|
|
for (final String playerlottery : pl.keySet()) {
|
|
final int win = LotteryUtils.getSameNumber(playerlottery);
|
|
int winprices = 0;
|
|
winprices = plugin.getConfig().getInt("Reward." + win, 200) * pl.get(playerlottery);
|
|
if (winprices > 0) {
|
|
priceTotal += winprices;
|
|
ChatUtils.broadcastMessage(String.format("§a%s的彩票: §e%s §a获得了 §e%s §a元!", p.getName(), playerlottery.toString(), winprices));
|
|
final String message = ChatColor.GREEN + "您的彩票: " + ChatColor.YELLOW + playerlottery.toString() + ChatColor.GREEN + "获得了" + ChatColor.GOLD + winprices + ChatColor.GREEN + "元!";
|
|
if (!p.isOnline()) {
|
|
plugin.getOfflineData().addMessage(p.getName(), message);
|
|
}
|
|
LuckLottery.economy.depositPlayer(p, winprices);
|
|
}
|
|
}
|
|
}
|
|
PlayerData.reward(priceTotal);
|
|
PlayerData.playerLottery.put(players.getKey(), null);
|
|
}
|
|
PlayerData.clearLottery();
|
|
if (update) {
|
|
LotteryUtils.updateSystemLottery();
|
|
}
|
|
}
|
|
|
|
}
|