public void saveRules() {
    try {
      OutputHandler.SOP("Saving rules");

      if (!rulesFile.exists()) rulesFile.createNewFile();

      // create streams
      FileOutputStream stream = new FileOutputStream(rulesFile);
      OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
      BufferedWriter writer = new BufferedWriter(streamWriter);

      writer.write("# " + rulesFile.getName() + " | numbers are automatically added");
      writer.newLine();

      for (String rule : rules) {
        writer.write(rule);
        writer.newLine();
      }

      writer.close();
      streamWriter.close();
      stream.close();

      OutputHandler.SOP("Completed saving rules file.");
    } catch (Exception e) {
      Logger lof = OutputHandler.felog;
      lof.logp(
          Level.SEVERE,
          "FEConfig",
          "Saving Rules",
          "Error writing the Rules file: " + rulesFile.getName(),
          e);
    }
  }
  // this is designed so it will work for any class.
  public FEConfig() {
    OutputHandler.SOP("Loading configs");
    config = new Configuration(FECONFIG, true);
    // config.load -- Configurations are loaded on Construction.

    // load the modules
    loadModules();
    loadCore();
    loadCmd();
    loadPerms();

    // CONFIG TESTING!!!!
    /*
     * config.addCustomCategoryComment("TEST", "this is for testing...");
     * config.addCustomCategoryComment("TEST.nestedTEST", "MORE TESTING!!!");
     * config.get("TEST", "test1", false);
     * config.get("TEST", "test2", false);
     * config.get("TEST", "test3", false);
     * config.get("TEST.nestedTEST", "test1", false);
     * config.get("TEST.nestedTEST", "test2", false);
     * config.get("TEST.nestedTEST", "test3", false);
     * config.get("TEST", "testList", new String[] {"lala", "lala", "lala"});
     * config.get("TEST.nestedTEST", "testList", new String[] {"lala", "lala", "lala"});
     */

    // Finish init and save.
    config.save();
  }
  public PacketSelectionUpdate(PlayerInfo info) {
    packet = new Packet250CustomPayload();

    ByteArrayOutputStream streambyte = new ByteArrayOutputStream();
    DataOutputStream stream = new DataOutputStream(streambyte);

    try {
      stream.write(packetID);

      if (info != null && info.getPoint1() != null) {
        Point p1 = info.getPoint1();
        stream.writeBoolean(true);
        stream.writeInt(p1.x);
        stream.writeInt(p1.y);
        stream.writeInt(p1.z);
      } else stream.writeBoolean(false);

      if (info != null && info.getPoint2() != null) {
        Point p2 = info.getPoint2();
        stream.writeBoolean(true);
        stream.writeInt(p2.x);
        stream.writeInt(p2.y);
        stream.writeInt(p2.z);
      } else stream.writeBoolean(false);

      stream.close();
      streambyte.close();

      packet.channel = FECHANNEL;
      packet.data = streambyte.toByteArray();
      packet.length = packet.data.length;
    } catch (Exception e) {
      OutputHandler.SOP("Error creating packet >> " + this.getClass());
    }
  }
  private static void writeNBT(NBTTagCompound tag, File file) {
    try {
      // create file/folders if they don;t exist..
      if (!file.getParentFile().exists()) file.getParentFile().mkdirs();

      // make temp file
      File temp = new File(file.getPath() + "_tmp");
      if (temp.exists()) temp.delete();

      // write temp file
      DataOutputStream stream =
          new DataOutputStream(new GZIPOutputStream(new FileOutputStream(temp)));
      try {
        NBTBase.writeNamedTag(tag, stream);
      } finally {
        stream.close();
      }

      // change from temp to real
      if (file.exists()) {
        file.delete();
      }

      if (file.exists()) {
        throw new IOException("Failed to delete " + file);
      } else {
        temp.renameTo(file);
      }
    } catch (Exception e) {
      OutputHandler.SOP("Writing NBT to " + file + " failed");
    }
  }
 @Override
 public void run() {
   OutputHandler.debug("Started running the logger");
   while (run) {
     try {
       Thread.sleep(1000 * ModulePlayerLogger.interval);
     } catch (final InterruptedException e) {
     }
     if (buffer.isEmpty()) {
       OutputHandler.SOP("No logs to make");
     } else {
       OutputHandler.SOP("Making logs");
       makeLogs();
       OutputHandler.SOP("Done making logs");
     }
   }
 }
 public static void logConfigChange(String category, String prop, String oldVal, String newVal) {
   SOP(
       "Config Changed: "
           + prop
           + " under "
           + "category"
           + " changed from "
           + oldVal
           + " to "
           + newVal);
 }
 public void preLoad(FMLPreInitializationEvent e) {
   OutputHandler.SOP("Commands module is enabled. Loading...");
   conf = new ConfigCmd();
 }
  public ArrayList<String> loadRules() {
    // Rules the rules file will be a flat strings file.. nothing special.
    ArrayList<String> rules = new ArrayList<String>();

    // somehow a new rules.txt is generated EVERY load.

    OutputHandler.SOP("Loading rules");
    if (!rulesFile.exists()) {
      try {
        OutputHandler.SOP("No rules file found. Generating with default rules..");

        rulesFile.createNewFile();

        // create streams
        FileOutputStream stream = new FileOutputStream(rulesFile);
        OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
        BufferedWriter writer = new BufferedWriter(streamWriter);

        writer.write("# " + rulesFile.getName() + " | numbers are automatically added");
        writer.newLine();

        writer.write("Obey the Admins");
        rules.add("Obey the Admins");
        writer.newLine();

        writer.write("Do not grief");
        rules.add("Do not grief");
        writer.newLine();

        writer.close();
        streamWriter.close();
        stream.close();

        OutputHandler.SOP("Completed generating rules file.");
      } catch (Exception e) {
        Logger lof = OutputHandler.felog;
        lof.logp(
            Level.SEVERE,
            "FEConfig",
            "Generating Rules",
            "Error writing the Rules file: " + rulesFile.getName(),
            e);
      }
    } else {
      try {
        OutputHandler.SOP("Rules file found. Reading...");

        FileInputStream stream = new FileInputStream(rulesFile);
        InputStreamReader streamReader = new InputStreamReader(stream);
        BufferedReader reader = new BufferedReader(streamReader);

        String read = reader.readLine();
        int counter = 0;

        while (read != null) {
          // ignore the comment things...
          if (read.startsWith("#")) {
            read = reader.readLine();
            continue;
          }

          // add to the rules list.
          rules.add(read);

          // read the next string
          read = reader.readLine();

          // increment counter
          counter++;
        }

        reader.close();
        streamReader.close();
        stream.close();

        OutputHandler.SOP("Completed reading rules file. " + counter + " rules read.");
      } catch (Exception e) {
        Logger lof = OutputHandler.felog;
        lof.logp(
            Level.SEVERE,
            "FEConfig",
            "Constructor-Rules",
            "Error reading or writing the Rules file: " + rulesFile.getName(),
            e);
      }
    }

    return rules;
  }
  public void preLoad(FMLPreInitializationEvent e) {
    OutputHandler.SOP("Discovering and loading modules...");
    OutputHandler.SOP(
        "If you would like to disable a module, please look in ForgeEssentials/core.cfg.");

    modules = new ArrayList<IFEModule>();
    IFEModule instance;

    /*
     * commands = new ModuleCommands();
     * permission = new ModulePermissions();
     * worldborder = new ModuleWorldBorder();
     * playerLogger = new ModulePlayerLogger();
     * economy = new ModuleEconomy();
     * chat = new ModuleChat();
     * protection = new ModuleProtection();
     * snooper = new ModuleSnooper();
     */

    try {
      instance = new ModuleWorldControl();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleBackup();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleCommands();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModulePermissions();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleWorldBorder();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModulePlayerLogger();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleEconomy();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleChat();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleProtection();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    try {
      instance = new ModuleSnooper();
      modules.add(instance);
      OutputHandler.SOP("discoverred " + instance.getClass().toString());
    } catch (NoClassDefFoundError e1) {
      // Nothing to see here, carry on, carry on
    }

    for (IFEModule module : modules) module.preLoad(e);

    boolean generate = false;
    for (IFEModule module : modules) {
      IModuleConfig cfg = module.getConfig();

      if (cfg != null) {
        File file = cfg.getFile();

        if (!file.getParentFile().exists()) {
          generate = true;
          file.getParentFile().mkdirs();
        }

        if (!generate && (!file.exists() || !file.isFile())) generate = true;

        cfg.setGenerate(generate);
        cfg.init();
      }
    }
  }
 @Override
 public void preLoad(FMLPreInitializationEvent e) {
   OutputHandler.SOP("Chat module is enabled. Loading...");
 }
 // At Dries' request
 public static void debug(Object msg) {
   if (verbose) SOP(msg);
 }