Example #1
0
  public void onEnable() {
    setupEconomy();
    initializeLanguageFile();
    Language lang = new Language(this);
    lang.languageInitialize();

    File forumConfig = new File(getDataFolder(), "forumConfig.yml");
    File economyConfigFile = new File(getDataFolder(), "economy.yml");
    List<String> ranks = new ArrayList<String>();
    File file = new File(getDataFolder() + File.separator + "config.yml");
    File packagesFolder = new File(getDataFolder() + "/packages" + File.separator);
    File existingRanks = new File(this.getDataFolder() + File.separator, "packages.yml");

    if (!file.exists()) {
      getDataFolder().mkdirs();

      getLogger().info("Configuration not found. Generating...");
      this.saveDefaultConfig();
    }
    if (!packagesFolder.exists()) {
      packagesFolder.mkdirs();
    }
    if (!existingRanks.exists()) {
      try {
        existingRanks.createNewFile();
      } catch (IOException e) {

        e.printStackTrace();
      }
    }
    if (!forumConfig.exists()) {
      getLogger().info("Forum Configuration not found. Generating...");

      try {
        getDataFolder().mkdirs();
        ranks = this.getConfig().getStringList("ranks");

        if (existingRanks.exists()) {
          FileConfiguration existingRanksConfig = null;
          existingRanksConfig = new YamlConfiguration();
          existingRanksConfig.load(existingRanks);
          existingRanksConfig.createSection("packages");
          existingRanksConfig.set("packages", ranks);
          existingRanksConfig.save(existingRanks);
        }
      } catch (IOException | InvalidConfigurationException e1) {
        e1.printStackTrace();
      }

      OutputStream out = null;
      InputStream defaultStream = this.getResource("configs/forumConfig.yml");
      try {
        out = new FileOutputStream(forumConfig);
        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = defaultStream.read(bytes)) != -1) {
          out.write(bytes, 0, read);
        }
        out.close();
      } catch (IOException e1) {
        e1.printStackTrace();
      }

      for (String s : ranks) {
        setForumConfig(s);
      }
    }
    if (!economyConfigFile.exists()) {
      getLogger().info("Economy Configuration not found. Generating...");

      OutputStream out = null;
      InputStream defaultStream = this.getResource("configs/economy.yml");
      try {
        out = new FileOutputStream(economyConfigFile);
        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = defaultStream.read(bytes)) != -1) {
          out.write(bytes, 0, read);
        }
        out.close();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
    getCommand("donate").setExecutor(new CommandListener(this));

    // Used to initialize the constructor
    @SuppressWarnings("unused")
    Database testConnect = new Database(this);

    Bukkit.getPluginManager().registerEvents(this, this);
    Bukkit.getPluginManager().registerEvents(new SignEvent(this), this);
    Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);

    if (this.getConfig().getString("metrics").equals("true")) {
      try {
        Metrics metrics = new Metrics(this);
        metrics.start();
        Logger.getLogger("").log(Level.INFO, "Metrics Enabled for DonatorExpress");
      } catch (IOException e) {
        // Failed to submit the stats :-(
      }

    } else {

    }
  }