Пример #1
0
  /** Loads or reloads the mod */
  public final void load() {
    if (properties == null) {
      properties = new PropertiesFile("server.properties");
    } else {
      try {
        properties.load();
      } catch (IOException e) {
        log.log(Level.SEVERE, "Exception while reading from server.properties", e);
      }
    }

    try {
      dataSourceType = properties.getString("data-source", "flatfile");

      allowedItems = properties.getString("alloweditems", "").split(",");
      disallowedItems = properties.getString("disalloweditems", "").split(",");
      itemSpawnBlacklist = properties.getString("itemspawnblacklist", "").split(",");
      motd = properties.getString("motd", "Type /help for a list of commands.").split("@");
      playerLimit = properties.getInt("max-players", 20);
      saveHomes = properties.getBoolean("save-homes", true);
      whitelistEnabled = properties.getBoolean("whitelist", false);
      whitelistMessage = properties.getString("whitelist-message", "Not on whitelist.");
      if (dataSourceType.equalsIgnoreCase("flatfile")) {
        usersLoc = properties.getString("admintxtlocation", "users.txt");
        kitsLoc = properties.getString("kitstxtlocation", "kits.txt");
        homeLoc = properties.getString("homelocation", "homes.txt");
        warpLoc = properties.getString("warplocation", "warps.txt");
        itemLoc = properties.getString("itemstxtlocation", "items.txt");
        groupLoc = properties.getString("group-txt-location", "groups.txt");
        whitelistLoc = properties.getString("whitelist-txt-location", "whitelist.txt");
        reservelistLoc = properties.getString("reservelist-txt-location", "reservelist.txt");
      } else {
        PropertiesFile sql = new PropertiesFile("mysql.properties");
        driver = sql.getString("driver", "com.mysql.jdbc.Driver");
        username = sql.getString("user", "root");
        password = sql.getString("pass", "root");
        db = sql.getString("db", "jdbc:mysql://localhost:3306/minecraft");
      }
      spawnProtectionSize = properties.getInt("spawn-protection-size", 16);
      logging = properties.getBoolean("logging", false);
      enableHealth = properties.getBoolean("enable-health", true);

      String autoHealString = properties.getString("auto-heal", "default");
      if (autoHealString.equalsIgnoreCase("true")) {
        autoHeal = PluginLoader.HookResult.ALLOW_ACTION;
      } else if (autoHealString.equalsIgnoreCase("false")) {
        autoHeal = PluginLoader.HookResult.PREVENT_ACTION;
      }

      showUnknownCommand = properties.getBoolean("show-unknown-command", true);
      URL url = this.getClass().getResource("/version.txt");
      if (url != null) {
        InputStreamReader ins = new InputStreamReader(url.openStream());
        BufferedReader bufferedReader = new BufferedReader(ins);
        String versionParam = bufferedReader.readLine();
        if (versionParam.startsWith(
            "git-")) { // recommended version.txt for git builds: git-<gituser>-<shorttag>
          // example: git-sk89q-591c662cf4afc8e3e09a
          version = -1;
          versionStr = versionParam;
          tainted = true;
        } else {
          version = Integer.parseInt(versionParam);
          versionStr = Integer.toString(version); // and back to a string.
          tainted = false; // looks official. We hope.
        }
      } else {
        // I'm a tainted build, probably.
        version = -1;
        versionStr = "Undefined version";
        tainted = true;
        // If any mods check the version.. #@!$
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, "Exception while reading from server.properties", e);
      // Just in case...
      disallowedItems = new String[] {""};
      allowedItems = new String[] {""};
      itemSpawnBlacklist = new String[] {""};
      motd = new String[] {"Type /help for a list of commands."};
    }
  }