コード例 #1
0
 AttackControlConfig(TheMonkeyPack plugin, String moduleName) {
   super();
   MODULE_NAME = moduleName;
   main = plugin;
   attackControlLogger = new AttackControlLogger(MODULE_NAME);
   mainConfig = main.getMainConfig();
   pluginPath = main.getDataFolder() + System.getProperty("file.separator");
   instance = this;
   setupConfig();
 }
コード例 #2
0
  /**
   * Method to setup the configuration. If the configuration file doesn't exist it will be created
   * by {@link #defaultConfig()} After that the configuration is loaded {@link #loadConfig()} We
   * than check if an configuration update is necessary {@link #updateNecessary()} and set {@link
   * #configAvailable} to true
   *
   * @see #defaultConfig()
   * @see #loadConfig()
   * @see #updateNecessary()
   * @see #updateConfig()
   */
  void setupConfig() {

    // Checking if config file exists, if not create it

    if (!(new File(main.getDataFolder(), configFile)).exists()) {
      attackControlLogger.info("Creating default configuration file");
      defaultConfig();
    }

    // adding the default values

    customDefaultConfig();

    try {
      config.load(pluginPath + configFile);
    } catch (IOException e) {
      attackControlLogger.severe("Can't read the " + configFile + " File!", e);
    } catch (InvalidConfigurationException e) {
      attackControlLogger.severe("Problem with the configuration in " + configFile + "!", e);
    }
    // Loading the config from file
    loadConfig();

    // Checking internal configCurrent and config file configVer

    setupCommands();
    setupListeners();

    updateNecessary();
    // If config file has new options update it if enabled
    if (mainConfig.autoUpdateConfig) {
      updateConfig();
    }
    configAvailable = true;
  }
コード例 #3
0
  private void setupCommands() {
    // registering the additional permissions

    for (ATTACK_CONTROL_PERMISSIONS perm : ATTACK_CONTROL_PERMISSIONS.values()) {
      main.getServer().getPluginManager().addPermission(perm.asPermission());
    }
  }
コード例 #4
0
  /**
   * Method for writing the configuration file. First we write the standard configuration part, than
   * we write the custom configuration part via #writeCustomConfig()
   *
   * @return true if writing the config was successful
   * @see #writeCustomConfig(java.io.PrintWriter)
   */
  public boolean writeConfig() {
    attackControlLogger.debug("creating config");
    boolean success = false;
    try {
      PrintWriter stream;
      File folder = main.getDataFolder();
      if (folder != null) {
        folder.mkdirs();
      }
      PluginDescriptionFile pdfFile = main.getDescription();
      stream = new PrintWriter(pluginPath + configFile);
      attackControlLogger.debug("starting contents");
      // Let's write our config ;)
      stream.println(
          "# "
              + pdfFile.getName()
              + " "
              + pdfFile.getVersion()
              + " by "
              + pdfFile.getAuthors().toString());
      stream.println("#");
      stream.println("# Configuration File for module [" + MODULE_NAME + "]");
      stream.println("#");
      stream.println("# For detailed assistance please visit: " + mainConfig.getPluginSlug());
      stream.println();
      stream.println("# Configuration Version");
      stream.println("configVer: \"" + configVer + "\"");
      stream.println();
      // Getting the custom config information from the top of the class
      attackControlLogger.debug("going for customConfig");
      writeCustomConfig(stream);

      stream.println();

      stream.close();

      success = true;

    } catch (FileNotFoundException e) {
      attackControlLogger.warning("Error saving the " + configFile + ".");
    }

    return success;
  }
コード例 #5
0
 private void setupListeners() {
   acEntityEvent = ACEntityEvent.getInstance(main);
   main.addRegisteredListener(acEntityEvent);
 }