86 lines
3.1 KiB
Java
86 lines
3.1 KiB
Java
package pw.yumc.LuckLottery;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
import pw.yumc.LuckLottery.command.LuckLotteryCommand;
|
|
import pw.yumc.LuckLottery.config.OfflineDate;
|
|
import pw.yumc.LuckLottery.config.PlayerData;
|
|
import pw.yumc.LuckLottery.listen.PlayerListen;
|
|
import pw.yumc.LuckLottery.runnable.LotteryReward;
|
|
import pw.yumc.LuckLottery.utils.ChatUtils;
|
|
import pw.yumc.LuckLottery.utils.LotteryUtils;
|
|
import pw.yumc.YumCore.config.FileConfig;
|
|
import pw.yumc.YumCore.statistic.Statistics;
|
|
import pw.yumc.YumCore.update.SubscribeTask;
|
|
|
|
public class LuckLottery extends JavaPlugin {
|
|
public static Economy economy = null;
|
|
public static boolean isEconomy;
|
|
public static LuckLottery plugin;
|
|
protected FileConfig config;
|
|
protected OfflineDate offlinedata;
|
|
|
|
@Override
|
|
public FileConfig getConfig() {
|
|
return config;
|
|
}
|
|
|
|
public OfflineDate getOfflineData() {
|
|
return offlinedata;
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
this.getLogger().info("保存彩票数据中...");
|
|
this.getLogger().info("保存玩家数据中...");
|
|
PlayerData.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().runTaskTimerAsynchronously(plugin, new LotteryReward(this, true), 10, rewardtime * 60 * 20);
|
|
this.getLogger().info("彩票系统已开启...");
|
|
pm.registerEvents(new PlayerListen(this), this);
|
|
new LuckLotteryCommand();
|
|
new Statistics();
|
|
new SubscribeTask(true, true);
|
|
}
|
|
|
|
@Override
|
|
public void onLoad() {
|
|
plugin = this;
|
|
config = new FileConfig();
|
|
offlinedata = new OfflineDate(this);
|
|
PlayerData.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);
|
|
}
|
|
}
|