Thread: [Asteria] spawn-config converter, to .json

Results 1 to 6 of 6
  1. #1 [Asteria] spawn-config converter, to .json 
    Registered Member
    CTucker's Avatar
    Join Date
    Oct 2008
    Posts
    2,422
    Thanks given
    263
    Thanks received
    281
    Rep Power
    343
    For anyone using Asteria, you will know it uses JSON, and I didn't feel like writing 5000000 npcs out, so I just wrote something up in about two minutes that will copy the contents of a .CFG file into the JSON format.

    Here you go..

    This code is not at all great, it's just something I wrote in a few minutes to get an end result and figured someone else might have a use for it.

    Code:
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    
    
    public class Main {
    
    	BufferedReader fileReader;
    	BufferedWriter fileWriter;
    	
    	private Main() {
    		try {
    			fileReader = new BufferedReader(new FileReader("File/spawn-config.cfg"));
    			fileWriter = new BufferedWriter(new FileWriter("Dumped/world_npcs.json"));
    			loadFile();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	private void loadFile() {
    		String currentLine;
    		try {
    			fileWriter.write("[\n");
    			while((currentLine = fileReader.readLine()) != null) {
    				if(!currentLine.startsWith("//") && !currentLine.startsWith("[")
    						&& !currentLine.startsWith("/*")) {
    					System.err.println(currentLine);
    					String[] array = currentLine.split("\\t");
    					String npcID = array[0].substring(7);
    					String xPos = array[1];
    					String yPos = array[2];
    					String zPos = array[3];
    					String walk = "false";
    					String radius = "0";
    					//-----------------------
    					fileWriter.write("\t{\n");
    					fileWriter.write("\t\t\"npc-id\": "+npcID+",\n");
    					fileWriter.write("\t\t\"position\": {\n");
    					fileWriter.write("\t\t\t\"x\": " + xPos + "\n,");
    					fileWriter.write("\t\t\t\"y\": " + yPos + "\n,");
    					fileWriter.write("\t\t\t\"z\": " + zPos + "\n");
    					fileWriter.write("\t\t},\n");
    					fileWriter.write("\t\t\"walking-policy\": {\n");
    					fileWriter.write("\t\t\t\"coordinate\": false, \"radius\": 0\n");
    					fileWriter.write("\t\t}\n\t},\n");
    				}				
    			}
    			
    			fileWriter.write("]");
    			fileWriter.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		
    	}
    		
    	public static void main(String[] params) {
    		new Main();
    	}
    	
    }
    Reply With Quote  
     

  2. #2  
    Номер 1


    Leanbow's Avatar
    Join Date
    Feb 2008
    Posts
    5,895
    Thanks given
    1,564
    Thanks received
    2,624
    Rep Power
    5000
    Pretty sure you can use gson.toJson(object), don't need to write it your self.
    Reply With Quote  
     

  3. #3  
    Registered Member
    CTucker's Avatar
    Join Date
    Oct 2008
    Posts
    2,422
    Thanks given
    263
    Thanks received
    281
    Rep Power
    343
    Quote Originally Posted by Leanbow View Post
    Pretty sure you can use gson.toJson(object), don't need to write it your self.
    If this is the case...
    Fml.
    >_>

    I don't know much about Json, but everyone talks about it all over the place, so I figured I'd keep it.
    Reply With Quote  
     

  4. #4  
    Banned [Asteria] spawn-config converter, to .json Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    looooooooooooool yeah im pretty sure as well that you could have used gson.toJson, but on the bright side I wrote something similar earlier on when I didn't know either
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jan 2014
    Posts
    813
    Thanks given
    69
    Thanks received
    47
    Rep Power
    9
    Code:
     so I just wrote something up in about two minutes
    Reply With Quote  
     

  6. #6  
    Donator


    Join Date
    Feb 2014
    Posts
    611
    Thanks given
    122
    Thanks received
    207
    Rep Power
    117
    cool




    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 5
    Last Post: 01-02-2014, 09:13 PM
  2. Converting a spawn-based server to economy
    By Cryptic7th in forum Buying
    Replies: 11
    Last Post: 05-19-2013, 04:43 PM
  3. Replies: 2
    Last Post: 04-20-2011, 05:48 PM
  4. Replies: 1
    Last Post: 09-11-2010, 01:27 PM
  5. p16 V6 converted to SQL
    By PrimEviL in forum Downloads
    Replies: 8
    Last Post: 10-07-2007, 06:43 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •