/Core/src/main/java/com/spleefleague/core/SpleefLeague.java
https://bitbucket.org/DarthAffe/spleefleague · Java · 156 lines · 116 code · 19 blank · 21 comment · 1 complexity · f21b19ceb215e4cb881f75437942d048 MD5 · raw file
- /*
- * Spleefleague
- * Copyright (C) 2012 Darth Affe <http://spleefleague.com> and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.spleefleague.core;
- import com.spleefleague.core.messages.MessageProvider;
- import com.spleefleague.core.player.UserManager;
- import com.spleefleague.core.event.SpleefLeagueEventHandler;
- import com.spleefleague.core.game.GameHistoryManager;
- import com.spleefleague.core.game.GeneralQueue;
- import com.spleefleague.core.game.GeneralQueueContainer;
- import com.spleefleague.core.game.Signs;
- import com.spleefleague.core.io.DatabaseConnector;
- import com.spleefleague.core.io.MySQLConnector;
- import com.spleefleague.core.repositorys.*;
- import java.util.logging.Logger;
- import org.bukkit.plugin.java.JavaPlugin;
- /**
- *
- * @author samiraagabi
- */
- public class SpleefLeague extends JavaPlugin {
- public static final String LOG_PREFIX = "[SpleefLeague] ";
- public static final Logger LOG = Logger.getLogger("Minecraft");
- private static SpleefLeague spleefleague;
- private SpleefLeagueEventHandler eventHandler;
- private EventListener eventListener;
- private CommandHandler commandHandler;
- private DatabaseConnector databaseConnector;
- private EntityBuilder entityBuilder;
- private GameModeRepository gameModeRepository = new GameModeRepository();
- private AreaRepository areaRepository = new AreaRepository();
- private PlayerRepository playerRepository = new PlayerRepository();
- private SignRepository signRepository = new SignRepository();
- private RegistrationQueryRepository registrationQueryRepository = new RegistrationQueryRepository();
- private UserManager userManager;
- private MessageProvider messageProvider;
- private GeneralQueueContainer generalQueues;
- private GameHistoryManager gameHistoryManager;
- public SpleefLeagueEventHandler getEventHandler() {
- return eventHandler;
- }
- @Override
- public void onEnable() {
- long startTime = System.nanoTime();
- SpleefLeague.spleefleague = this;
- Config.loadConfig();
- this.databaseConnector = new MySQLConnector();
- this.databaseConnector.init();
- this.entityBuilder = new EntityBuilder(databaseConnector);
- this.gameModeRepository.initialize(this, entityBuilder);
- this.eventHandler = new SpleefLeagueEventHandler(this);
- this.areaRepository.initialize(this, entityBuilder);
- this.playerRepository.initialize(this, entityBuilder);
- this.generalQueues = new GeneralQueueContainer(this);
- this.signRepository.initialize(this, entityBuilder);
- this.registrationQueryRepository.initialize(this, entityBuilder);
- this.messageProvider = new MessageProvider(entityBuilder);
- this.userManager = new UserManager(playerRepository, databaseConnector);
- this.eventListener = new EventListener(this);
- this.getServer().getPluginManager().registerEvents(eventListener, this);
- LOG.info(LOG_PREFIX + "EventHandler/-Listener initialized");
- this.commandHandler = new CommandHandler(gameModeRepository, areaRepository, userManager, eventHandler);
- LOG.info(LOG_PREFIX + "CommandHandler initialized");
- this.gameHistoryManager = new GameHistoryManager(this.databaseConnector, this);
- registerCommands();
- long elapsedTime = System.nanoTime() - startTime;
- LOG.info(LOG_PREFIX + "Done after " + String.format("%.3f", (double) elapsedTime / 1000000000.0) + " seconds");
- }
- private void registerCommands() {
- getCommand("join").setExecutor(commandHandler);
- getCommand("j").setExecutor(commandHandler);
- getCommand("position").setExecutor(commandHandler);
- getCommand("surrender").setExecutor(commandHandler);
- getCommand("leave").setExecutor(commandHandler);
- getCommand("l").setExecutor(commandHandler);
- getCommand("match").setExecutor(commandHandler);
- getCommand("m").setExecutor(commandHandler);
- getCommand("pause").setExecutor(commandHandler);
- getCommand("unpause").setExecutor(commandHandler);
- getCommand("fly").setExecutor(commandHandler);
- }
- @Override
- public void onDisable() {
- }
- public void updateAllSigns() {
- for (Signs s : signRepository.getAll()) {
- s.update();
- }
- }
- public UserManager getUserManager() {
- return this.userManager;
- }
- public GameModeRepository getGameModeRepository() {
- return gameModeRepository;
- }
- public AreaRepository getAreaRepository() {
- return areaRepository;
- }
- public PlayerRepository getPlayerRepository() {
- return playerRepository;
- }
- public RegistrationQueryRepository getRegistrationQueryRepository() {
- return registrationQueryRepository;
- }
- public GeneralQueue getGeneralQueue(int gameModeId) {
- return generalQueues.getForGameModeId(gameModeId);
- }
- public EntityBuilder getEntityBuilder() {
- return entityBuilder;
- }
- public GameHistoryManager getGameHistoryManager() {
- return gameHistoryManager;
- }
- public MessageProvider getMessageProvider() {
- return messageProvider;
- }
- public int getGameModeId() {
- return 0;
- }
- public static SpleefLeague getInstance() {
- return spleefleague;
- }
- }