2021-09-24 23:56:42 +00:00
|
|
|
package com.alttd;
|
|
|
|
|
|
|
|
|
|
import com.alttd.GUI.GUIListener;
|
|
|
|
|
import com.alttd.commands.CommandManager;
|
2021-12-18 00:34:42 +00:00
|
|
|
import com.alttd.database.Database;
|
2021-09-24 23:56:42 +00:00
|
|
|
import com.alttd.config.Config;
|
|
|
|
|
import com.alttd.config.VillagerConfig;
|
|
|
|
|
import com.alttd.config.WorthConfig;
|
2021-12-22 20:02:29 +00:00
|
|
|
import com.alttd.events.LoginEvent;
|
|
|
|
|
import com.alttd.events.LogoutEvent;
|
2021-12-23 02:15:38 +00:00
|
|
|
import com.alttd.events.VillagerEvents;
|
2021-12-23 01:18:07 +00:00
|
|
|
import com.alttd.objects.EconUser;
|
2021-11-03 15:54:12 +00:00
|
|
|
import com.alttd.util.Logger;
|
2021-11-07 17:10:50 +00:00
|
|
|
import net.milkbowl.vault.economy.Economy;
|
2021-11-10 19:29:27 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2021-11-07 17:10:50 +00:00
|
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
2021-09-24 23:56:42 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2021-12-23 01:18:07 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2021-09-24 23:56:42 +00:00
|
|
|
|
|
|
|
|
public class VillagerUI extends JavaPlugin {
|
|
|
|
|
|
|
|
|
|
public static VillagerUI instance;
|
2021-11-10 19:29:27 +00:00
|
|
|
private Economy economy = null;
|
2021-09-24 23:56:42 +00:00
|
|
|
|
|
|
|
|
public static VillagerUI getInstance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoad() {
|
|
|
|
|
instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onEnable() {
|
|
|
|
|
registerEvents();
|
|
|
|
|
new CommandManager();
|
|
|
|
|
Config.reload();
|
|
|
|
|
VillagerConfig.reload();
|
|
|
|
|
WorthConfig.reload();
|
2021-11-10 19:29:27 +00:00
|
|
|
if (!setupEconomy())
|
2021-11-07 17:10:50 +00:00
|
|
|
return;
|
2021-11-17 18:32:21 +00:00
|
|
|
Database.getDatabase().init();
|
2021-12-23 01:18:07 +00:00
|
|
|
scheduleTasks();
|
2021-11-03 15:54:12 +00:00
|
|
|
Logger.info("--------------------------------------------------");
|
|
|
|
|
Logger.info("Villager UI started");
|
|
|
|
|
Logger.info("--------------------------------------------------");
|
2021-09-24 23:56:42 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-23 01:18:07 +00:00
|
|
|
private void scheduleTasks() {
|
|
|
|
|
new BukkitRunnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
2021-12-23 02:14:08 +00:00
|
|
|
if (Config.DEBUG)
|
|
|
|
|
Logger.info("Syncing users.");
|
2021-12-23 01:18:07 +00:00
|
|
|
EconUser.getEconUsers().forEach(econUser -> {
|
|
|
|
|
econUser.removePoints();
|
|
|
|
|
econUser.syncPoints();
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-23 01:18:23 +00:00
|
|
|
}.runTaskTimerAsynchronously(getInstance(), 0L, 10 * 60 * 20L);
|
2021-12-23 01:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-24 23:56:42 +00:00
|
|
|
private void registerEvents() {
|
|
|
|
|
getServer().getPluginManager().registerEvents(new GUIListener(), this);
|
2021-12-23 02:15:38 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new VillagerEvents(), this);
|
2021-12-22 20:02:29 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new LogoutEvent(), this);
|
|
|
|
|
getServer().getPluginManager().registerEvents(new LoginEvent(), this);
|
2021-09-24 23:56:42 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 19:29:27 +00:00
|
|
|
public Economy getEconomy() {
|
|
|
|
|
if(economy == null)
|
|
|
|
|
setupEconomy();
|
|
|
|
|
return economy;
|
|
|
|
|
}
|
2021-11-07 17:10:50 +00:00
|
|
|
|
2021-11-10 19:29:27 +00:00
|
|
|
private boolean setupEconomy() {
|
|
|
|
|
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
|
|
|
|
this.getLogger().severe("Vault was not found. Please download vault.");
|
|
|
|
|
Bukkit.getPluginManager().disablePlugin(this);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(Economy.class);
|
|
|
|
|
if (rsp == null) {
|
|
|
|
|
this.getLogger().severe("Can't find economy! Disabling plugin.");
|
|
|
|
|
Bukkit.getPluginManager().disablePlugin(this);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
this.economy = (Economy)rsp.getProvider();
|
|
|
|
|
return this.economy != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-07 17:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-24 23:56:42 +00:00
|
|
|
}
|