kenshinshideandseek/src/main/java/net/tylermurphy/hideAndSeek/Main.java

106 lines
2.7 KiB
Java
Raw Normal View History

2021-08-13 20:49:36 +00:00
package net.tylermurphy.hideAndSeek;
2021-10-27 23:57:44 +00:00
import static net.tylermurphy.hideAndSeek.configuration.Config.spawnWorld;
2021-08-27 21:20:07 +00:00
import java.io.File;
2021-10-21 00:14:01 +00:00
import java.util.HashMap;
import java.util.List;
2021-10-21 00:14:01 +00:00
import java.util.Map;
2021-12-26 04:46:22 +00:00
import net.tylermurphy.hideAndSeek.database.Database;
2021-12-25 14:16:03 +00:00
import net.tylermurphy.hideAndSeek.game.Status;
2021-12-26 04:46:22 +00:00
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
2021-08-13 20:49:36 +00:00
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
2021-10-21 00:14:01 +00:00
import org.bukkit.entity.Player;
2021-08-13 20:49:36 +00:00
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
2021-09-01 01:55:27 +00:00
import org.bukkit.scheduler.BukkitTask;
2021-08-13 20:49:36 +00:00
2021-12-25 14:16:03 +00:00
import net.tylermurphy.hideAndSeek.util.CommandHandler;
import net.tylermurphy.hideAndSeek.game.EventListener;
import net.tylermurphy.hideAndSeek.util.TabCompleter;
import net.tylermurphy.hideAndSeek.game.Game;
2021-10-23 00:03:15 +00:00
import net.tylermurphy.hideAndSeek.configuration.Config;
import net.tylermurphy.hideAndSeek.configuration.Localization;
2021-10-31 15:25:27 +00:00
import net.tylermurphy.hideAndSeek.configuration.Items;
2021-10-21 00:14:01 +00:00
import net.tylermurphy.hideAndSeek.util.Board;
2021-10-27 23:57:44 +00:00
import net.tylermurphy.hideAndSeek.world.WorldLoader;
2021-08-13 20:49:36 +00:00
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
2021-10-23 00:03:15 +00:00
public static File root, data;
2021-08-13 20:49:36 +00:00
2021-12-25 14:16:03 +00:00
public Game game;
2021-10-21 00:14:01 +00:00
public Board board;
2021-10-27 23:57:44 +00:00
public WorldLoader worldLoader;
2021-12-25 14:16:03 +00:00
public Status status = Status.STANDBY;
2021-12-26 04:46:22 +00:00
public Database database;
2021-09-01 01:55:27 +00:00
private BukkitTask onTickTask;
2021-12-25 14:16:03 +00:00
2021-08-13 20:49:36 +00:00
public void onEnable() {
plugin = this;
2021-12-25 14:16:03 +00:00
// Setup Event Listener
getServer().getPluginManager().registerEvents(new EventListener(), this);
2021-08-13 20:49:36 +00:00
2021-10-23 00:03:15 +00:00
// Get Data Folder
root = this.getServer().getWorldContainer();
data = this.getDataFolder();
2021-08-13 20:49:36 +00:00
// Init Configuration
2021-10-21 00:14:01 +00:00
Config.loadConfig();
2021-10-29 03:09:28 +00:00
Localization.loadLocalization();
2021-10-31 15:25:27 +00:00
Items.loadItems();
2021-08-13 20:49:36 +00:00
2021-10-27 23:57:44 +00:00
// Create World Loader
worldLoader = new WorldLoader(spawnWorld);
2021-08-13 20:49:36 +00:00
// Register Commands
CommandHandler.registerCommands();
2021-08-13 20:49:36 +00:00
2021-10-21 00:14:01 +00:00
//Board
board = new Board();
2021-10-21 01:37:38 +00:00
board.reload();
2021-12-26 04:46:22 +00:00
//Database
database = new Database();
database.init();
//UUIDFetcher Cache
UUIDFetcher.init();
//Init game
game = new Game();
2021-08-13 20:49:36 +00:00
// Start Tick Timer
2021-11-08 20:53:13 +00:00
onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
try{
2021-12-25 14:16:03 +00:00
game.onTick();
2021-11-08 20:53:13 +00:00
} catch (Exception e) {
e.printStackTrace();
}
},0,1);
2021-08-13 20:49:36 +00:00
}
2021-09-01 01:55:27 +00:00
public void onDisable() {
2021-12-20 21:51:44 +00:00
if(onTickTask != null)
onTickTask.cancel();
2021-12-26 04:46:22 +00:00
UUIDFetcher.cleanup();
2021-09-01 01:55:27 +00:00
}
2021-12-25 14:29:31 +00:00
public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) {
return CommandHandler.handleCommand(sender, cmd, label, args);
}
2021-12-25 14:29:31 +00:00
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
2021-09-01 01:55:27 +00:00
return TabCompleter.handleTabComplete(sender, command, label, args);
2021-08-13 20:49:36 +00:00
}
}