Problem getting data from towny .txt file

Discussion in 'Plugin Development' started by JeroenV, Dec 9, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    JeroenV

    Hey, I'm making a drop plugin based on groups made by towny and therefor I need to get the data from the playername+".txt" file. However when I use this code:

    Code:
    -snip-
            YamlConfiguration PlayerConfig = YamlConfiguration.loadConfiguration(new File(playerfolder,playername+".txt"));
         
            if(PlayerConfig.get("town=") != null){
                player.sendMessage(ChatColor.RED + "Reached code2.");
            String townname = PlayerConfig.getString("town=");
    -snip-
    It gives me an error at the first line:
    Here's the .txt file btw:
    Can anyone help out?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    tommycake50

    its a .txt file not a .yml file.
    therefore you are going to have to parse it yourself.
     
  3. Offline

    JeroenV

    How should I go about that?
     
  4. Offline

    fireblast709

    read the file line by line, and replace '=' with ': '
     
  5. Offline

    JeroenV

    Alright I checked in on how to parse files, and I know how to use .split() however I'm unsure about how to replace certain characters to get a nice hashmap as a result.
     
  6. Offline

    fireblast709

    As it contains only one level, you can split each line on '='
    Code:java
    1. String[] kv = line.split("=");
    You could just dump this into a HashMap
    Code:java
    1. // The HashMap
    2. public HashMap<String, String> values = new HashMap<String, String>();
    3. // How you store:
    4. values.put(kv[0], kv[1]);
     
Thread Status:
Not open for further replies.

Share This Page