/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

  1. /*
  2. * Spleefleague
  3. * Copyright (C) 2012 Darth Affe <http://spleefleague.com> and contributors
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. package com.spleefleague.core;
  19. import com.spleefleague.core.messages.MessageProvider;
  20. import com.spleefleague.core.player.UserManager;
  21. import com.spleefleague.core.event.SpleefLeagueEventHandler;
  22. import com.spleefleague.core.game.GameHistoryManager;
  23. import com.spleefleague.core.game.GeneralQueue;
  24. import com.spleefleague.core.game.GeneralQueueContainer;
  25. import com.spleefleague.core.game.Signs;
  26. import com.spleefleague.core.io.DatabaseConnector;
  27. import com.spleefleague.core.io.MySQLConnector;
  28. import com.spleefleague.core.repositorys.*;
  29. import java.util.logging.Logger;
  30. import org.bukkit.plugin.java.JavaPlugin;
  31. /**
  32. *
  33. * @author samiraagabi
  34. */
  35. public class SpleefLeague extends JavaPlugin {
  36. public static final String LOG_PREFIX = "[SpleefLeague] ";
  37. public static final Logger LOG = Logger.getLogger("Minecraft");
  38. private static SpleefLeague spleefleague;
  39. private SpleefLeagueEventHandler eventHandler;
  40. private EventListener eventListener;
  41. private CommandHandler commandHandler;
  42. private DatabaseConnector databaseConnector;
  43. private EntityBuilder entityBuilder;
  44. private GameModeRepository gameModeRepository = new GameModeRepository();
  45. private AreaRepository areaRepository = new AreaRepository();
  46. private PlayerRepository playerRepository = new PlayerRepository();
  47. private SignRepository signRepository = new SignRepository();
  48. private RegistrationQueryRepository registrationQueryRepository = new RegistrationQueryRepository();
  49. private UserManager userManager;
  50. private MessageProvider messageProvider;
  51. private GeneralQueueContainer generalQueues;
  52. private GameHistoryManager gameHistoryManager;
  53. public SpleefLeagueEventHandler getEventHandler() {
  54. return eventHandler;
  55. }
  56. @Override
  57. public void onEnable() {
  58. long startTime = System.nanoTime();
  59. SpleefLeague.spleefleague = this;
  60. Config.loadConfig();
  61. this.databaseConnector = new MySQLConnector();
  62. this.databaseConnector.init();
  63. this.entityBuilder = new EntityBuilder(databaseConnector);
  64. this.gameModeRepository.initialize(this, entityBuilder);
  65. this.eventHandler = new SpleefLeagueEventHandler(this);
  66. this.areaRepository.initialize(this, entityBuilder);
  67. this.playerRepository.initialize(this, entityBuilder);
  68. this.generalQueues = new GeneralQueueContainer(this);
  69. this.signRepository.initialize(this, entityBuilder);
  70. this.registrationQueryRepository.initialize(this, entityBuilder);
  71. this.messageProvider = new MessageProvider(entityBuilder);
  72. this.userManager = new UserManager(playerRepository, databaseConnector);
  73. this.eventListener = new EventListener(this);
  74. this.getServer().getPluginManager().registerEvents(eventListener, this);
  75. LOG.info(LOG_PREFIX + "EventHandler/-Listener initialized");
  76. this.commandHandler = new CommandHandler(gameModeRepository, areaRepository, userManager, eventHandler);
  77. LOG.info(LOG_PREFIX + "CommandHandler initialized");
  78. this.gameHistoryManager = new GameHistoryManager(this.databaseConnector, this);
  79. registerCommands();
  80. long elapsedTime = System.nanoTime() - startTime;
  81. LOG.info(LOG_PREFIX + "Done after " + String.format("%.3f", (double) elapsedTime / 1000000000.0) + " seconds");
  82. }
  83. private void registerCommands() {
  84. getCommand("join").setExecutor(commandHandler);
  85. getCommand("j").setExecutor(commandHandler);
  86. getCommand("position").setExecutor(commandHandler);
  87. getCommand("surrender").setExecutor(commandHandler);
  88. getCommand("leave").setExecutor(commandHandler);
  89. getCommand("l").setExecutor(commandHandler);
  90. getCommand("match").setExecutor(commandHandler);
  91. getCommand("m").setExecutor(commandHandler);
  92. getCommand("pause").setExecutor(commandHandler);
  93. getCommand("unpause").setExecutor(commandHandler);
  94. getCommand("fly").setExecutor(commandHandler);
  95. }
  96. @Override
  97. public void onDisable() {
  98. }
  99. public void updateAllSigns() {
  100. for (Signs s : signRepository.getAll()) {
  101. s.update();
  102. }
  103. }
  104. public UserManager getUserManager() {
  105. return this.userManager;
  106. }
  107. public GameModeRepository getGameModeRepository() {
  108. return gameModeRepository;
  109. }
  110. public AreaRepository getAreaRepository() {
  111. return areaRepository;
  112. }
  113. public PlayerRepository getPlayerRepository() {
  114. return playerRepository;
  115. }
  116. public RegistrationQueryRepository getRegistrationQueryRepository() {
  117. return registrationQueryRepository;
  118. }
  119. public GeneralQueue getGeneralQueue(int gameModeId) {
  120. return generalQueues.getForGameModeId(gameModeId);
  121. }
  122. public EntityBuilder getEntityBuilder() {
  123. return entityBuilder;
  124. }
  125. public GameHistoryManager getGameHistoryManager() {
  126. return gameHistoryManager;
  127. }
  128. public MessageProvider getMessageProvider() {
  129. return messageProvider;
  130. }
  131. public int getGameModeId() {
  132. return 0;
  133. }
  134. public static SpleefLeague getInstance() {
  135. return spleefleague;
  136. }
  137. }