parent
480f9dd280
commit
fb26e39e5d
|
@ -18,85 +18,88 @@ import cn.citycraft.LuckLottery.utils.ChatUtils;
|
||||||
import cn.citycraft.LuckLottery.utils.LotteryUtils;
|
import cn.citycraft.LuckLottery.utils.LotteryUtils;
|
||||||
|
|
||||||
public class LuckLottery extends JavaPlugin {
|
public class LuckLottery extends JavaPlugin {
|
||||||
public static boolean isEconomy;
|
public static boolean isEconomy;
|
||||||
public static Permission permission = null;
|
public static Permission permission = null;
|
||||||
public static Economy economy = null;
|
public static Economy economy = null;
|
||||||
public static Chat chat = null;
|
public static Chat chat = null;
|
||||||
public static LuckLottery plugin;
|
public static LuckLottery plugin;
|
||||||
|
|
||||||
public void onLoad() {
|
@Override
|
||||||
plugin = this;
|
public void onDisable() {
|
||||||
Config.load(this, "1.2");
|
this.getLogger().info("保存彩票数据中...");
|
||||||
OfflineDate.load(this);
|
this.getLogger().info("保存玩家数据中...");
|
||||||
PlayerDate.load(this);
|
LotteryUtils.saveLottery();
|
||||||
LotteryUtils.reloadPlayerLottery();
|
}
|
||||||
ChatUtils.setPluginname(Config.getMessage("pluginname"));
|
|
||||||
|
|
||||||
LotteryUtils.setNumbersame(Config.getInstance()
|
@Override
|
||||||
.getBoolean("numbersame"));
|
public void onEnable() {
|
||||||
LotteryUtils.setPrice(Config.getInstance().getInt("price"));
|
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;
|
||||||
|
}
|
||||||
|
int rewardtime = Config.getInstance().getInt("RewardTime", 10);
|
||||||
|
this.getServer()
|
||||||
|
.getScheduler()
|
||||||
|
.runTaskTimer(plugin, new LotteryReward(true), 10,
|
||||||
|
rewardtime * 60 * 20);
|
||||||
|
this.getLogger().info("彩票系统已开启...");
|
||||||
|
pm.registerEvents(new PlayerListen(), this);
|
||||||
|
getCommand("ll").setExecutor(new LuckLotteryCommand(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
plugin = this;
|
||||||
|
Config.load(this, "1.2");
|
||||||
|
OfflineDate.load(this);
|
||||||
|
PlayerDate.load(this);
|
||||||
|
LotteryUtils.reloadPlayerLottery();
|
||||||
|
ChatUtils.setPluginname(Config.getMessage("pluginname"));
|
||||||
|
|
||||||
|
LotteryUtils.setNumbersame(Config.getInstance()
|
||||||
|
.getBoolean("numbersame"));
|
||||||
|
LotteryUtils.setPrice(Config.getInstance().getInt("price"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setupChat() {
|
||||||
|
RegisteredServiceProvider<Chat> chatProvider = getServer()
|
||||||
|
.getServicesManager().getRegistration(
|
||||||
|
net.milkbowl.vault.chat.Chat.class);
|
||||||
|
if (chatProvider != null) {
|
||||||
|
chat = chatProvider.getProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
return (chat != null);
|
||||||
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;
|
|
||||||
}
|
|
||||||
int rewardtime = Config.getInstance().getInt("RewardTime", 10);
|
|
||||||
this.getServer()
|
|
||||||
.getScheduler()
|
|
||||||
.runTaskTimer(plugin, new LotteryReward(true), 10,
|
|
||||||
rewardtime * 60 * 20);
|
|
||||||
this.getLogger().info("彩票系统已开启...");
|
|
||||||
pm.registerEvents(new PlayerListen(), this);
|
|
||||||
getCommand("ll").setExecutor(new LuckLotteryCommand(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisable() {
|
public boolean setupEconomy() {
|
||||||
this.getLogger().info("保存彩票数据中...");
|
RegisteredServiceProvider<Economy> economyProvider = getServer()
|
||||||
this.getLogger().info("保存玩家数据中...");
|
.getServicesManager().getRegistration(
|
||||||
LotteryUtils.saveLottery();
|
net.milkbowl.vault.economy.Economy.class);
|
||||||
|
if (economyProvider != null) {
|
||||||
|
economy = economyProvider.getProvider();
|
||||||
}
|
}
|
||||||
|
return (economy != null);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setupPermissions() {
|
public boolean setupPermissions() {
|
||||||
RegisteredServiceProvider<Permission> permissionProvider = getServer()
|
RegisteredServiceProvider<Permission> permissionProvider = getServer()
|
||||||
.getServicesManager().getRegistration(
|
.getServicesManager().getRegistration(
|
||||||
net.milkbowl.vault.permission.Permission.class);
|
net.milkbowl.vault.permission.Permission.class);
|
||||||
if (permissionProvider != null) {
|
if (permissionProvider != null) {
|
||||||
permission = permissionProvider.getProvider();
|
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);
|
|
||||||
}
|
}
|
||||||
|
return (permission != null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,15 +31,7 @@ public class LuckLotteryCommand implements CommandExecutor {
|
||||||
int price = LotteryUtils.getPrice();
|
int price = LotteryUtils.getPrice();
|
||||||
if (LuckLottery.economy.hasAccount(p)
|
if (LuckLottery.economy.hasAccount(p)
|
||||||
&& LuckLottery.economy.has(p, price)) {
|
&& LuckLottery.economy.has(p, price)) {
|
||||||
// p.closeInventory();
|
|
||||||
// plugin.getServer().getScheduler()
|
|
||||||
// .runTaskLaterAsynchronously(plugin, new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
InvUtils.openGui(p);
|
InvUtils.openGui(p);
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }, 2);
|
|
||||||
} else {
|
} else {
|
||||||
ChatUtils.sendMessage(p, ChatColor.GOLD
|
ChatUtils.sendMessage(p, ChatColor.GOLD
|
||||||
+ "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + price
|
+ "你没有足够的金钱购买彩票,每张彩票" + ChatColor.RED + price
|
||||||
|
@ -95,9 +87,9 @@ public class LuckLotteryCommand implements CommandExecutor {
|
||||||
case "reload":
|
case "reload":
|
||||||
if (PermissionUtils.Check(sender, PermissionUtils.Reload)) {
|
if (PermissionUtils.Check(sender, PermissionUtils.Reload)) {
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
ChatUtils.sendMessage(sender, ChatColor.GREEN + "配置文件已重载!");
|
||||||
pm.disablePlugin(plugin);
|
pm.disablePlugin(plugin);
|
||||||
pm.enablePlugin(plugin);
|
pm.enablePlugin(plugin);
|
||||||
ChatUtils.sendMessage(sender, ChatColor.GREEN + "配置文件已重载!");
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case "help":
|
case "help":
|
||||||
|
|
|
@ -30,59 +30,63 @@ import com.google.common.io.Files;
|
||||||
*/
|
*/
|
||||||
public class FileConfig extends YamlConfiguration {
|
public class FileConfig extends YamlConfiguration {
|
||||||
|
|
||||||
protected final DumperOptions yamlOptions = new DumperOptions();
|
public static FileConfig init(File file) {
|
||||||
protected final Representer yamlRepresenter = new YamlRepresenter();
|
return FileConfig.loadConfiguration(file);
|
||||||
protected final Yaml yaml = new Yaml(new YamlConstructor(),
|
}
|
||||||
yamlRepresenter, yamlOptions);
|
|
||||||
|
|
||||||
public static FileConfig init(File file) {
|
public static FileConfig loadConfiguration(File file) {
|
||||||
return FileConfig.loadConfiguration(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;
|
||||||
|
}
|
||||||
|
|
||||||
public static FileConfig loadConfiguration(File file) {
|
protected final DumperOptions yamlOptions = new DumperOptions();
|
||||||
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
|
protected final Representer yamlRepresenter = new YamlRepresenter();
|
||||||
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,
|
protected final Yaml yaml = new Yaml(new YamlConstructor(),
|
||||||
InvalidConfigurationException {
|
yamlRepresenter, yamlOptions);
|
||||||
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 {
|
@Override
|
||||||
Validate.notNull(file, "File cannot be null");
|
public void load(File file) throws FileNotFoundException, IOException,
|
||||||
Files.createParentDirs(file);
|
InvalidConfigurationException {
|
||||||
String data = saveToString();
|
Validate.notNull(file, "File cannot be null");
|
||||||
Writer writer = new OutputStreamWriter(new FileOutputStream(file),
|
final FileInputStream stream = new FileInputStream(file);
|
||||||
Charsets.UTF_8);
|
load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||||
try {
|
}
|
||||||
writer.write(data);
|
|
||||||
} finally {
|
@Override
|
||||||
writer.close();
|
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();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue