1
0
mirror of https://e.coding.net/circlecloud/LuckLottery.git synced 2025-11-24 21:46:23 +00:00

clean up and use PluginHelper...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092
2015-09-30 19:59:45 +08:00
parent 9079566849
commit 7b128bd8cc
22 changed files with 674 additions and 1077 deletions

View File

@@ -0,0 +1,88 @@
package cn.citycraft.LuckLottery;
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.listen.PlayerListen;
import cn.citycraft.LuckLottery.runnable.LotteryReward;
import cn.citycraft.LuckLottery.utils.ChatUtils;
import cn.citycraft.LuckLottery.utils.LotteryUtils;
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 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() {
this.getLogger().info("保存彩票数据中...");
this.getLogger().info("保存玩家数据中...");
LotteryUtils.saveLottery();
}
@Override
public void onEnable() {
final PluginManager pm = this.getServer().getPluginManager();
if (pm.getPlugin("Vault") == null && !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;
}
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), this);
getCommand("ll").setExecutor(new LuckLotteryCommand(this));
}
@Override
public void onLoad() {
plugin = 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.getBoolean("numbersame"));
LotteryUtils.setPrice(config.getInt("price"));
}
public boolean setupEconomy() {
final RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return (economy != null);
}
}

View File

@@ -0,0 +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;
}
}

View File

@@ -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<String> messages = instance.getStringList(p);
messages.add(message);
instance.set(p, messages);
instance.save();
}
public static List<String> getMessage(final String p) {
return instance.getStringList(p);
}
}

View File

@@ -0,0 +1,99 @@
package cn.citycraft.LuckLottery.listen;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.LuckLottery.LuckLottery;
import cn.citycraft.LuckLottery.config.OfflineDate;
import cn.citycraft.LuckLottery.runnable.LaterShow;
import cn.citycraft.LuckLottery.utils.ChatUtils;
import cn.citycraft.LuckLottery.utils.InvUtils;
import cn.citycraft.LuckLottery.utils.LotteryUtils;
public class PlayerListen implements Listener {
LuckLottery plugin;
public PlayerListen(final LuckLottery luckLottery) {
this.plugin = luckLottery;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent e) {
if (InvUtils.isLotteryGUI(e.getInventory())) {
e.setCancelled(true);
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()) {
return;
}
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 + "元!");
p.closeInventory();
return;
}
final List<String> lottery = InvUtils.getLotteryNumber(inv);
LotteryUtils.addLottery(p, lottery);
ChatUtils.sendMessage(p, "§6您当前购买的彩票号码为: " + ChatColor.GREEN + lottery.toString());
ChatUtils.howToShow(p);
LuckLottery.economy.withdrawPlayer(p, LotteryUtils.getPrice());
p.closeInventory();
break;
case InvUtils.ReSet:
inv.setContents(InvUtils.getGui());
break;
default:
if (solt < 36 && InvUtils.isLotteryItem(ci)) {
if (setSelect(inv, ci)) {
inv.setItem(solt, InvUtils.A);
}
}
break;
}
if (InvUtils.selectFinish(inv)) {
inv.setItem(53, InvUtils.Creat);
} else {
inv.setItem(53, InvUtils.CantCreat);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(final PlayerJoinEvent e) {
final Player p = e.getPlayer();
final List<String> 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);
return true;
}
}
return false;
}
}

View File

@@ -0,0 +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<String> messages;
public LaterShow(Player p, List<String> messages) {
this.p = p;
this.messages = messages;
}
@Override
public void run() {
ChatUtils.sendMessage(p, ChatColor.RED + "在您离线期间彩票开奖结果:");
ChatUtils.sendMessage(p, messages);
}
}

View File

@@ -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<String, List<List<String>>> players : LotteryUtils.playerLottery.entrySet()) {
final OfflinePlayer p = Bukkit.getOfflinePlayer(players.getKey());
final List<List<String>> pl = players.getValue();
if (pl != null && !pl.isEmpty()) {
for (final List<String> 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();
}
}
}

View File

@@ -0,0 +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<String> 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);
}
}

View File

@@ -0,0 +1,277 @@
package cn.citycraft.LuckLottery.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class InvUtils {
public static final String InvName = ChatUtils.getPluginname() + " §c§l售价: "
+ LotteryUtils.getPrice() + "元一份";
public static final String NumPrefix = "§6§l";
public static final String Normal1 = "§6§l1";
public static final String Normal2 = "§6§l2";
public static final String Normal3 = "§6§l3";
public static final String Normal4 = "§6§l4";
public static final String Normal5 = "§6§l5";
public static final String Normal6 = "§6§l6";
public static final String Normal7 = "§6§l7";
public static final String Normal8 = "§6§l8";
public static final String Normal9 = "§6§l9";
public static final String Normal10 = "§6§l10";
public static final String Normal11 = "§6§l11";
public static final String Normal12 = "§6§l12";
public static final String Normal13 = "§6§l13";
public static final String Normal14 = "§6§l14";
public static final String Normal15 = "§6§l15";
public static final String Normal16 = "§6§l16";
public static final String Normal17 = "§6§l17";
public static final String Normal18 = "§6§l18";
public static final String Normal19 = "§6§l19";
public static final String Normal20 = "§6§l20";
public static final String Normal21 = "§6§l21";
public static final String Normal22 = "§6§l22";
public static final String Normal23 = "§6§l23";
public static final String Normal24 = "§6§l24";
public static final String Normal25 = "§6§l25";
public static final String Normal26 = "§6§l26";
public static final String Normal27 = "§6§l27";
public static final String Normal28 = "§6§l28";
public static final String Normal29 = "§6§l29";
public static final String Normal30 = "§6§l30";
public static final String Normal31 = "§6§l31";
public static final String Normal32 = "§6§l32";
// public static final String Special1 = "§b§l1";
// public static final String Special2 = "§b§l2";
// public static final String Special3 = "§b§l3";
// public static final String Special4 = "§b§l4";
// public static final String Special5 = "§b§l5";
// public static final String Special6 = "§b§l6";
// public static final String Special7 = "§b§l7";
// public static final String Special8 = "§b§l8";
// public static final String Special9 = "§b§l9";
public static final String WEB = "§c请选取=>§6橙色普通号码§r§l|§b蓝色特殊号码";
public static final String ReSet = "§4§l重新选取";
public static final String Create = "§a§l生成彩票";
public static final String CantCreate = "§c§l请选取§66个普通号码§b1个特殊号码§a生成彩票";
// private static final ItemStack L0 = new
// ItemStack(Material.DOUBLE_PLANT,1,(short)0);
public static final ItemStack L0 = new ItemStack(Material.WOOL);
public static final ItemStack L1 = new ItemStack(Material.WOOL, 1, (short) 1);
public static final ItemStack L2 = new ItemStack(Material.WOOL, 1, (short) 2);
public static final ItemStack L3 = new ItemStack(Material.WOOL, 1, (short) 3);
public static final ItemStack L4 = new ItemStack(Material.WOOL, 1, (short) 4);
public static final ItemStack L5 = new ItemStack(Material.WOOL, 1, (short) 5);
public static final ItemStack L6 = new ItemStack(Material.WOOL, 1, (short) 6);
public static final ItemStack L7 = new ItemStack(Material.WOOL, 1, (short) 7);
public static final ItemStack L8 = new ItemStack(Material.WOOL, 1, (short) 8);
public static final ItemStack L9 = new ItemStack(Material.WOOL, 1, (short) 9);
public static final ItemStack L10 = new ItemStack(Material.WOOL, 1, (short) 10);
public static final ItemStack L11 = new ItemStack(Material.WOOL, 1, (short) 11);
public static final ItemStack L12 = new ItemStack(Material.WOOL, 1, (short) 12);
public static final ItemStack L13 = new ItemStack(Material.WOOL, 1, (short) 13);
public static final ItemStack L14 = new ItemStack(Material.WOOL, 1, (short) 14);
public static final ItemStack L15 = new ItemStack(Material.WOOL, 1, (short) 15);
public static final ItemStack B0 = new ItemStack(Material.STAINED_GLASS);
public static final ItemStack B1 = new ItemStack(Material.STAINED_GLASS, 1, (short) 1);
public static final ItemStack B2 = new ItemStack(Material.STAINED_GLASS, 1, (short) 2);
public static final ItemStack B3 = new ItemStack(Material.STAINED_GLASS, 1, (short) 3);
public static final ItemStack B4 = new ItemStack(Material.STAINED_GLASS, 1, (short) 4);
public static final ItemStack B5 = new ItemStack(Material.STAINED_GLASS, 1, (short) 5);
public static final ItemStack B6 = new ItemStack(Material.STAINED_GLASS, 1, (short) 6);
public static final ItemStack B7 = new ItemStack(Material.STAINED_GLASS, 1, (short) 7);
public static final ItemStack B8 = new ItemStack(Material.STAINED_GLASS, 1, (short) 8);
public static final ItemStack B9 = new ItemStack(Material.STAINED_GLASS, 1, (short) 9);
public static final ItemStack B10 = new ItemStack(Material.STAINED_GLASS, 1, (short) 10);
public static final ItemStack B11 = new ItemStack(Material.STAINED_GLASS, 1, (short) 11);
public static final ItemStack B12 = new ItemStack(Material.STAINED_GLASS, 1, (short) 12);
public static final ItemStack B13 = new ItemStack(Material.STAINED_GLASS, 1, (short) 13);
public static final ItemStack B14 = new ItemStack(Material.STAINED_GLASS, 1, (short) 14);
public static final ItemStack B15 = new ItemStack(Material.STAINED_GLASS, 1, (short) 15);
public static final ItemStack W = new ItemStack(Material.SNOW_BALL);
public static final ItemStack Creat = new ItemStack(Material.MAP);
public static final ItemStack CM = new ItemStack(Material.WATER_LILY);
public static final ItemStack CantCreat = new ItemStack(Material.EMPTY_MAP);
public static final ItemStack A = new ItemStack(Material.AIR);
public static final ItemStack RT = new ItemStack(Material.LAVA_BUCKET);
static {
setDisplayName(W, WEB);
setDisplayName(L0, Normal1);
setDisplayName(L1, Normal2);
setDisplayName(L2, Normal3);
setDisplayName(L3, Normal4);
setDisplayName(L4, Normal5);
setDisplayName(L5, Normal6);
setDisplayName(L6, Normal7);
setDisplayName(L7, Normal8);
setDisplayName(L8, Normal9);
setDisplayName(L9, Normal10);
setDisplayName(L10, Normal11);
setDisplayName(L11, Normal12);
setDisplayName(L12, Normal13);
setDisplayName(L13, Normal14);
setDisplayName(L14, Normal15);
setDisplayName(L15, Normal16);
setDisplayName(B0, Normal17);
setDisplayName(B1, Normal18);
setDisplayName(B2, Normal19);
setDisplayName(B3, Normal20);
setDisplayName(B4, Normal21);
setDisplayName(B5, Normal22);
setDisplayName(B6, Normal23);
setDisplayName(B7, Normal24);
setDisplayName(B8, Normal25);
setDisplayName(B9, Normal26);
setDisplayName(B10, Normal27);
setDisplayName(B11, Normal28);
setDisplayName(B12, Normal29);
setDisplayName(B13, Normal30);
setDisplayName(B14, Normal31);
setDisplayName(B15, Normal32);
setDisplayName(CM, "§6<=普通号码§r|§b特殊号码=>");
setDisplayName(RT, ReSet);
setDisplayName(CantCreat, CantCreate);
setDisplayName(Creat, Create);
}
private static final ItemStack[] GUI_LINE1 = {
W,
L0,
L1,
L2,
L3,
L4,
L5,
L6,
W
/* 第一行结束 */};
private static final ItemStack[] GUI_LINE2 = {
L7,
L8,
L9,
L10,
L11,
L12,
L13,
L14,
L15
/* 第二行结束 */};
private static final ItemStack[] GUI_LINE3 = {
B0,
B1,
B2,
B3,
B4,
B5,
B6,
B7,
B8
/* 第三行结束 */};
private static final ItemStack[] GUI_LINE4 = {
W,
B9,
B10,
B11,
B12,
B13,
B14,
B15,
W
/* 第四行结束 */};
private static final ItemStack[] GUI_LINE5 = {
W,
W,
W,
W,
W,
W,
RT,
W,
W
/* 第五行结束 */};
private static final ItemStack[] GUI_LINE6 = {
A,
A,
A,
A,
A,
A,
CM,
A,
CantCreat
/* 第六行结束 */};
private static void setDisplayName(ItemStack item, String displayName) {
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(displayName);
item.setItemMeta(itemMeta);
}
public static ItemStack[] getGui() {
List<ItemStack> invgui = new ArrayList<ItemStack>();
invgui.addAll(Arrays.asList(GUI_LINE1));
invgui.addAll(Arrays.asList(GUI_LINE2));
invgui.addAll(Arrays.asList(GUI_LINE3));
invgui.addAll(Arrays.asList(GUI_LINE4));
invgui.addAll(Arrays.asList(GUI_LINE5));
invgui.addAll(Arrays.asList(GUI_LINE6));
return invgui.toArray(new ItemStack[0]);
}
public static void openGui(Player p) {
Inventory scrollInv = Bukkit.createInventory(null, 6 * 9, InvName);
scrollInv.setContents(getGui());
p.openInventory(scrollInv);
}
public static boolean isLotteryGUI(Inventory inv) {
if (inv == null)
return false;
return inv.getHolder() == null && inv.getTitle().equals(InvName);
}
public static boolean selectFinish(Inventory inv) {
return (inv.getItem(45) != null && inv.getItem(46) != null && inv.getItem(47) != null
&& inv.getItem(48) != null && inv.getItem(49) != null && inv.getItem(50) != null && inv
.getItem(52) != null);
}
public static List<String> getLotteryNumber(Inventory inv) {
List<String> lty = new ArrayList<String>();
for (int i = 45; i < 51; i++) {
lty.add(getItemNumber(inv.getItem(i)));
}
lty.add(getItemNumber(inv.getItem(52)));
return lty;
}
public static String getItemNumber(ItemStack item) {
String num = item.getItemMeta().getDisplayName();
if (num.startsWith(NumPrefix))
return num.substring(NumPrefix.length());
return null;
}
public static boolean isLotteryItem(ItemStack item) {
String num = item.getItemMeta().getDisplayName();
return num.startsWith(NumPrefix);
}
}

View File

@@ -0,0 +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.runnable.LotteryReward;
import cn.citycraft.PluginHelper.config.FileConfig;
public class LotteryUtils {
public static Map<String, List<List<String>>> playerLottery = new HashMap<String, List<List<String>>>();
protected static boolean numbersame;
protected static FileConfig playerdata;
protected static LuckLottery plugin;
protected static int price;
protected static List<String> systemLottery = new ArrayList<String>();
public static List<List<String>> addLottery(final Player player, final List<String> lottery) {
List<List<String>> playerhas = playerLottery.get(player.getName());
if (playerhas == null) {
playerhas = new ArrayList<List<String>>();
}
playerhas.add(lottery);
playerLottery.put(player.getName(), playerhas);
playerdata.set(player.getName(), playerhas);
playerdata.save();
return playerhas;
}
public static void clearLottery() {
for (final Entry<String, List<List<String>>> 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<String> getRandomNumber() {
final Random rnd = new Random();
final List<String> normal = new ArrayList<String>();
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<String> lottery) {
int samenum = 0;
final List<String> 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<String> lottery, final List<String> 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<String> 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<List<String>>) pl);
}
}
@SuppressWarnings("unchecked")
public static void reloadPlayerLottery() {
final Set<String> apl = playerdata.getKeys(false);
for (final String p : apl) {
final List<?> pl = playerdata.getList(p);
if (pl != null) {
playerLottery.put(p, (List<List<String>>) pl);
}
}
}
public static void rewardLastLottery() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(LuckLottery.plugin, new LotteryReward(plugin, true));
}
public static void saveLottery() {
for (final Entry<String, List<List<String>>> pl : playerLottery.entrySet()) {
final String p = pl.getKey();
final List<List<String>> 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<String> systemLottery) {
LotteryUtils.systemLottery = systemLottery;
}
public static void showAllPlayerLottery(final CommandSender sender) {
ChatUtils.sendMessage(sender, "§c正在检索玩家彩票数据...");
boolean has = false;
for (final Entry<String, List<List<String>>> phas : playerLottery.entrySet()) {
ChatUtils.sendMessage(sender, "§6玩家: §a" + phas.getKey() + "§6购买的彩票有");
for (final List<String> 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<List<String>> playerhas = playerLottery.get(p.getName());
if (playerhas != null && !playerhas.isEmpty()) {
ChatUtils.sendMessage(p, "§6您当前购买的彩票有:");
for (final List<String> 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());
}
}

View File

@@ -0,0 +1,35 @@
package cn.citycraft.LuckLottery.utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.md_5.bungee.api.ChatColor;
public class PermissionUtils {
public static final String ShowAll = "lucklottery.showall";
public static final String Reward = "lucklottery.reward";
public static final String Random = "lucklottery.random";
public static final String Look = "lucklottery.look";
public static final String Clear = "lucklottery.clear";
public static final String Reload = "lucklottery.reload";
public static String No_Permission = ChatColor.RED + "你没有此命令的权限!";
public static boolean Check(Player p, String perm) {
if (p.hasPermission(perm)) {
return true;
} else {
ChatUtils.noPermission(p);
}
return false;
}
public static boolean Check(CommandSender p, String perm) {
if (p.hasPermission(perm)) {
return true;
} else {
ChatUtils.noPermission(p);
}
return false;
}
}

View File

@@ -0,0 +1,29 @@
#本文件为插件的主配置文件
version: 1.2
#服务器名称
servername: ''
#插件名称
pluginname: '&6[&b彩票系统&6]&r '
#每隔多久开奖一次(单位: 分钟)
RewardTime: 5
#是否需要对应彩票号码位置
numbersame: true
#单张彩票价格
price: 200
#返现金额(红色球一个代表1点,蓝色球代表10点自行相加!)
#注意:请不要删除0这一行,配置错误将默认全部返还彩票价格的金钱.
Reward:
0: 0
1: 500
2: 1000
3: 1500
4: 2000
5: 4000
6: 8000
10: 800
11: 1200
12: 1500
13: 2000
14: 3000
15: 4000
16: 10000

View File

@@ -0,0 +1,39 @@
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/${project.artifactId}/
depended: [Vault]
commands:
lucklottery:
aliases: [ll]
permissions:
lucklottery.*:
description: 允许使用所有命令!
default: op
children:
lucklottery.showall: true
lucklottery.reward: true
lucklottery.random: true
lucklottery.look: true
lucklottery.clear: true
lucklottery.reload: true
lucklottery.showall:
description: 允许查看所有已购买彩票!
default: op
lucklottery.reward:
description: 允许结算上一轮彩票!
default: op
lucklottery.random:
description: 允许重新生成本轮彩票!
default: op
lucklottery.look:
description: 允许查看本轮彩票号码!
default: op
lucklottery.clear:
description: 允许清理玩家彩票数据!
default: op
lucklottery.reload:
description: 允许重载彩票插件!
default: op