/*
 * Copyright 2015 John "LuaMilkshake" Marion
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.pktr.smartbackup;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import org.apache.logging.log4j.Logger;

/**
 * Main SmartBackup mod class.
 */
@Mod(modid = SmartBackup.MOD_ID,
    name = SmartBackup.MOD_NAME,
    version = SmartBackup.VERSION,
    acceptableRemoteVersions = "*")
public class SmartBackup {
  public static final String MOD_ID = "SmartBackup";
  public static final String MOD_NAME = MOD_ID;

  // These are filled in by the build process.
  public static final String VERSION = "$VERSION$";
  public static final String SOURCE_REVISION = "$SOURCE_REVISION$";
  public static final String BUILD_TIMESTAMP = "$BUILD_TIMESTAMP$";

  private static Logger logger = null;
  private BackupManager manager;
  private static BackupConfiguration config = null;
  private static Messenger messenger = null;

  @EventHandler
  public void preInitializationEvent(FMLPreInitializationEvent event) {
    logger = event.getModLog();
    config = new BackupConfiguration(event.getSuggestedConfigurationFile());
    messenger = new Messenger();
  }

  @EventHandler
  public void initializationEvent(FMLInitializationEvent event) {
    manager = new BackupManager();
  }

  @EventHandler
  public void serverStartingEvent(FMLServerStartingEvent event) {
    event.registerServerCommand(new BackupCommand(manager));
  }

  @EventHandler
  public void serverStoppingEvent(FMLServerStoppingEvent event) {
    manager.interruptBackups();
    try {
      manager.waitForBackups();
    } catch (InterruptedException e) {
      return;
    }
  }

  /**
   * Get SmartBackup's configuration.
   *
   * @return SmartBackup's configuration.
   */
  public static BackupConfiguration getConfiguration() {
    return config;
  }

  /**
   * Get SmartBackup's logger.
   *
   * @return SmartBackup's logger.
   */
  public static Logger getLogger() {
    return logger;
  }

  /**
   * Get SmartBackup's messenger.
   *
   * @return SmartBackup's messenger.
   */
  public static Messenger getMessenger() {
    return messenger;
  }
}

@@ -2435,27 +2435,34 @@
   * 
-Get Smart
+Returns the %7B@link 
 Backup
-'s c
+C
 onfi
@@ -2473,41 +2473,95 @@
 tion
-.%0A   *%0A   * @return SmartBackup's
+%7D object providing config support.%0A   *%0A   * @return %7B@link BackupConfiguration%7D to get
  con
@@ -2570,16 +2570,23 @@
 guration
+ values
 .%0A   */%0A
@@ -2681,72 +2681,145 @@
   * 
-Get SmartBackup's logger.%0A   *%0A   * @return SmartBackup's
+Returns the %7B@code Logger%7D handed to SmartBackup from FML initialization.%0A   *%0A   * @return %7B@code Logger%7D to use for mod-related
  logg
-er
+ing
 .%0A  
@@ -2898,35 +2898,85 @@
   * 
-Get SmartBackup's messeng
+Returns the %7B@link Messenger%7D to use when sending messages to command send
 er
+s
 .%0A  
@@ -2995,31 +2995,61 @@
 urn 
-SmartBackup's messeng
+%7B@link Messenger%7D to send messages to command send
 er
+s
 .%0A  

Improve JavaDoc on getters in main mod class