97 lines
3.1 KiB
Java
97 lines
3.1 KiB
Java
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);
|
|
}
|
|
|
|
}
|