77 lines
2.6 KiB
Java
77 lines
2.6 KiB
Java
package cn.citycraft.LuckLottery;
|
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
|
|
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;
|
|
import cn.citycraft.LuckLottery.utils.VersionChecker;
|
|
|
|
public class LuckLottery extends JavaPlugin {
|
|
public static boolean isEconomy;
|
|
public static Economy economy = null;
|
|
public static LuckLottery plugin;
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
this.getLogger().info("保存彩票数据中...");
|
|
this.getLogger().info("保存玩家数据中...");
|
|
LotteryUtils.saveLottery();
|
|
}
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
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;
|
|
}
|
|
int rewardtime = Config.getInstance().getInt("RewardTime", 10);
|
|
this.getServer().getScheduler()
|
|
.runTaskTimer(plugin, new LotteryReward(true), 10, rewardtime * 60 * 20);
|
|
this.getLogger().info("彩票系统已开启...");
|
|
new VersionChecker(this);
|
|
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 setupEconomy() {
|
|
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager()
|
|
.getRegistration(net.milkbowl.vault.economy.Economy.class);
|
|
if (economyProvider != null) {
|
|
economy = economyProvider.getProvider();
|
|
}
|
|
return (economy != null);
|
|
}
|
|
}
|