init project...

Signed-off-by: j502647092 <jtb1@163.com>
Custom
j502647092 2015-05-20 23:30:56 +08:00
commit b7318b8f98
21 changed files with 1522 additions and 0 deletions

40
.gitignore vendored Normal file
View File

@ -0,0 +1,40 @@
# Eclipse stuff
/.classpath
/.project
/.settings
# netbeans
/nbproject
# we use maven!
/build.xml
# maven
/target
/repo
# vim
.*.sw[a-p]
# various other potential build files
/build
/bin
/dist
/manifest.mf
/world
# Mac filesystem dust
*.DS_Store
# intellij
*.iml
*.ipr
*.iws
.idea/
# Project Stuff
/src/main/resources/Soulbound
# Atlassian Stuff
/atlassian-ide-plugin.xml

BIN
lib/Vault-1.4.1.jar Normal file

Binary file not shown.

BIN
lib/Vault.jar Normal file

Binary file not shown.

56
pom.xml Normal file
View File

@ -0,0 +1,56 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.CityCraft</groupId>
<artifactId>LuckLottery</artifactId>
<version>0.0.3-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.8.3-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/Vault-1.4.1.jar</systemPath>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,96 @@
package cn.citycraft.LuckLottery;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
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;
public class LuckLottery extends JavaPlugin {
public static boolean isEconomy;
public static Permission permission = null;
public static Economy economy = null;
public static Chat chat = null;
public static LuckLottery plugin;
public void onLoad() {
plugin = this;
Config.load(this, "1.1");
OfflineDate.load(this);
PlayerDate.load(this);
ChatUtils.setPluginname(Config.getMessage("pluginname"));
LotteryUtils.setNumbersame(Config.getInstance().getBoolean("numbersame"));
}
public void onEnable() {
PluginManager pm = this.getServer().getPluginManager();
if (!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;
}
this.getServer().getScheduler()
.runTaskTimer(plugin, new LotteryReward(true), 10, 10 * 60 * 20);
this.getLogger().info("彩票系统已开启...");
pm.registerEvents(new PlayerListen(), this);
getCommand("ll").setExecutor(new LuckLotteryCommand(this));
}
public void onDisable() {
this.getLogger().info("保存彩票数据中...");
LotteryUtils.saveLottery();
this.getLogger().info("保存玩家数据中...");
PlayerDate.save();
}
public boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer()
.getServicesManager().getRegistration(
net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
public boolean setupChat() {
RegisteredServiceProvider<Chat> chatProvider = getServer()
.getServicesManager().getRegistration(
net.milkbowl.vault.chat.Chat.class);
if (chatProvider != null) {
chat = chatProvider.getProvider();
}
return (chat != null);
}
public boolean setupEconomy() {
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,88 @@
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 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)){
Player p = (Player) sender;
if (LuckLottery.economy.hasAccount(p)
&& LuckLottery.economy.has(p, 200)) {
InvUtils.openGui(p);
} else {
ChatUtils.sendMessage(p, ChatColor.GOLD
+ "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + "200"
+ 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 "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 "help":
ChatUtils.sendHelp(sender);
return true;
}
break;
case 2:
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 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;
}
}

View File

@ -0,0 +1,102 @@
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() + "保存错误...");
}
}

View File

@ -0,0 +1,88 @@
package cn.citycraft.LuckLottery.config;
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.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 {
protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(),
yamlRepresenter, yamlOptions);
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;
}
@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;
}
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));
}
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();
}
}
}

View File

@ -0,0 +1,47 @@
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<String> getMessage(String p) {
return instance.getStringList(p);
}
public static void addMessage(String p, String message) {
List<String> 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();
}
}
}

View File

@ -0,0 +1,48 @@
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();
}
}
}

View File

@ -0,0 +1,35 @@
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();
}
}
}

View File

@ -0,0 +1,123 @@
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 {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerJoinEvent e) {
LotteryUtils.loadPlayerLottery(e.getPlayer());
Player p = e.getPlayer();
List<String> 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();
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(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)
return;
if (!ci.getItemMeta().hasDisplayName())
return;
String clickName = ci.getItemMeta().getDisplayName();
switch (clickName) {
case InvUtils.Create:
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, 200);
p.closeInventory();
break;
case InvUtils.ReSet:
inv.setContents(InvUtils.getGui());
break;
case InvUtils.Normal1:
case InvUtils.Normal2:
case InvUtils.Normal3:
case InvUtils.Normal4:
case InvUtils.Normal5:
case InvUtils.Normal6:
case InvUtils.Normal7:
case InvUtils.Normal8:
case InvUtils.Normal9:
case InvUtils.Normal10:
case InvUtils.Normal11:
case InvUtils.Normal12:
case InvUtils.Normal13:
case InvUtils.Normal14:
case InvUtils.Normal15:
case InvUtils.Normal16:
case InvUtils.Normal17:
case InvUtils.Normal18:
case InvUtils.Normal19:
case InvUtils.Normal20:
case InvUtils.Normal21:
case InvUtils.Normal22:
case InvUtils.Normal23:
case InvUtils.Normal24:
case InvUtils.Normal25:
case InvUtils.Normal26:
case InvUtils.Normal27:
case InvUtils.Normal28:
case InvUtils.Normal29:
case InvUtils.Normal30:
case InvUtils.Normal31:
case InvUtils.Normal32:
if (solt < 36) {
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);
}
}
}
private boolean setSelect(Inventory inv, 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,121 @@
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 org.bukkit.entity.Player;
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 {
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());
for (Entry<String, List<List<String>>> players : LotteryUtils
.getPlayerLottery().entrySet()) {
OfflinePlayer p = Bukkit.getOfflinePlayer(players.getKey());
List<List<String>> pl = players.getValue();
if (pl != null && !pl.isEmpty())
for (List<String> playerlottery : pl) {
int win = LotteryUtils.getSameNumber(playerlottery);
int winprices = 0;
switch (win) {
case 10:
case 11:
winprices = 500;
break;
case 12:
winprices = 1000;
break;
case 3:
case 13:
winprices = 3000;
break;
case 14:
case 5:
case 15:
winprices = 5000;
break;
// case 0:
// case 1:
// winprices = 0;
// break;
// case 2:
// winprices = 500;
// break;
// case 3:
// winprices = 1000;
// break;
// case 4:
// winprices = 3000;
// break;
// case 5:
// winprices = 5000;
// break;
// case 6:
// winprices = 10000;
// break;
// case 10:
// winprices = 0;
// break;
// case 11:
// winprices = 500;
// break;
// case 12:
// winprices = 1000;
// break;
// case 13:
// winprices = 3000;
// break;
// case 14:
// winprices = 5000;
// break;
// case 15:
// winprices = 10000;
// break;
// case 16:
// winprices = 50000;
// break;
default:
}
if (winprices > 0) {
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.getPlayerLottery().remove(p.getName());
LotteryUtils.saveLottery();
}
if (update)
LotteryUtils.updateSystemLottery();
}
}

View File

@ -0,0 +1,74 @@
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 查看已购买彩票",
"§c/ll random 重新生成彩票§4(管理员命令)",
"§d/ll reward 结算上一轮彩票§4(管理员命令)",
"§5/ll look 查看本轮彩票号码§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,312 @@
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 = "§6[§3§l彩票系统§6]§c点击选取号码";
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生成彩票 §c§l200元一份";
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);
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(B0, Normal16);
setDisplayName(B1, Normal17);
setDisplayName(B2, Normal18);
setDisplayName(B3, Normal19);
setDisplayName(B4, Normal20);
setDisplayName(B5, Normal21);
setDisplayName(B6, Normal22);
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(item2number(inv.getItem(i)));
}
lty.add(item2number(inv.getItem(52)));
return lty;
}
public static String item2number(ItemStack item) {
return name2number(item.getItemMeta().getDisplayName());
}
public static String name2number(String name) {
switch (name) {
case Normal1:
return "1";
case Normal2:
return "2";
case Normal3:
return "3";
case Normal4:
return "4";
case Normal5:
return "5";
case Normal6:
return "6";
case Normal7:
return "7";
case Normal8:
return "8";
case Normal9:
return "9";
case Normal10:
return "10";
case Normal11:
return "11";
case Normal12:
return "12";
case Normal13:
return "13";
case Normal14:
return "14";
case Normal15:
return "15";
case Normal16:
return "16";
case Normal17:
return "17";
case Normal18:
return "18";
case Normal19:
return "19";
case Normal20:
return "20";
case Normal21:
return "21";
case Normal22:
return "22";
case Normal23:
return "23";
case Normal24:
return "24";
case Normal25:
return "25";
case Normal26:
return "26";
case Normal27:
return "27";
case Normal28:
return "28";
case Normal29:
return "29";
case Normal30:
return "30";
case Normal31:
return "31";
case Normal32:
return "32";
}
return "";
}
}

View File

@ -0,0 +1,191 @@
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<String> systemLottery = new ArrayList<String>();
protected static Map<String, List<List<String>>> playerLottery = new HashMap<String, List<List<String>>>();
protected static boolean numbersame;
public static List<List<String>> addLottery(Player player,
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);
PlayerDate.getInstance().set(player.getName(), playerhas);
PlayerDate.save();
return playerhas;
}
public static void saveLottery() {
for (Entry<String, List<List<String>>> pl : playerLottery.entrySet()) {
String p = pl.getKey();
List<List<String>> 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<List<String>>) pl);
}
}
@SuppressWarnings("unchecked")
public static void reloadPlayerLottery() {
Set<String> apl = PlayerDate.getInstance().getKeys(false);
for (String p : apl) {
List<?> pl = PlayerDate.getInstance().getList(p);
if (pl != null) {
playerLottery.put(p, (List<List<String>>) pl);
}
}
}
public static void showPlayerLottery(Player p) {
List<List<String>> playerhas = playerLottery.get(p.getName());
if (playerhas != null && !playerhas.isEmpty()) {
ChatUtils.sendMessage(p, "§6您当前购买的彩票有:");
for (List<String> lry : playerhas) {
ChatUtils.sendMessage(p, "§a" + lry.toString());
}
} else {
ChatUtils.sendMessage(p, "§c您当前没有购买的彩票");
}
}
public static void rewardLastLottery() {
Bukkit.getServer()
.getScheduler()
.runTaskAsynchronously(LuckLottery.plugin,
new LotteryReward(true));
}
public static List<String> getSystemLottery() {
return systemLottery;
}
public static void setSystemLottery(List<String> systemLottery) {
LotteryUtils.systemLottery = systemLottery;
}
public static Map<String, List<List<String>>> getPlayerLottery() {
return playerLottery;
}
public static void setPlayerLottery(
HashMap<String, List<List<String>>> playerLottery) {
LotteryUtils.playerLottery = playerLottery;
}
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<String> lottery) {
int samenum = 0;
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 (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<String> lottery, 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 (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<String> getRandomNumber() {
Random rnd = new Random();
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;
}
}

View File

@ -0,0 +1,32 @@
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 String Reward = "lucklottery.reward";
public static String Random = "lucklottery.random";
public static String Look = "lucklottery.look";
// public static String Reward = "lucklottery.reward";
// public static String Reward = "lucklottery.reward";
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;
}
}

8
src/config.yml Normal file
View File

@ -0,0 +1,8 @@
#本文件为插件的主配置文件
version: 1.0
#服务器名称
servername: ''
#插件名称
pluginname: '&6[&b彩票系统&6]&r '
#是否需要对应彩票号码位置
numbersame: true

8
src/plugin.yml Normal file
View File

@ -0,0 +1,8 @@
name: LuckLottery
main: cn.citycraft.LuckLottery.LuckLottery
author: 喵♂呜
version: 0.0.1
depended: [BVLib,Vault]
commands:
lucklottery:
aliases: [ll]