Last active
January 14, 2018 08:03
-
-
Save tterrag1098/b0f98649380cde794594fc9a153288ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"item.chisel.chisel_iron.name": "Chisel", | |
"item.chisel.chisel_diamond.name": "Diamond Chisel", | |
"item.chisel.chisel_hitech.name": "iChisel", | |
"item.chisel.offsettool.name": "Ender Offset Wand", | |
"__comment": "Test comment!", | |
"item.chisel.chisel.desc.gui": "%sRight-click%s to open GUI", | |
"item.chisel.chisel.desc.lc1": "%sLeft-click%s to chisel blocks in the world", | |
"item.chisel.chisel.desc.lc2": "%sTarget a block%s by leaving it in the inventory" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
item.chisel.chisel_iron.name=Chisel | |
item.chisel.chisel_diamond.name=Diamond Chisel | |
item.chisel.chisel_hitech.name=iChisel | |
item.chisel.offsettool.name=Ender Offset Wand | |
# Test comment! | |
invalid line | |
item.chisel.chisel.desc.gui=%sRight-click%s to open GUI | |
item.chisel.chisel.desc.lc1=%sLeft-click%s to chisel blocks in the world | |
item.chisel.chisel.desc.lc2=%sTarget a block%s by leaving it in the inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chisel.scripts; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import org.apache.commons.io.FileUtils; | |
import com.google.common.base.Charsets; | |
import com.google.gson.stream.JsonWriter; | |
public class Lang2Json { | |
public static void main(String[] args) throws IOException { | |
File file = new File(args[0]); | |
File outfile = new File(args[0].replace(".lang", ".json")); | |
Pattern MAPPING_PATTERN = Pattern.compile("^(\\S+)=(.+)$"); | |
try (JsonWriter out = new JsonWriter(new FileWriter(outfile))) { | |
out.setIndent(" "); | |
out.beginObject(); | |
for (String s : FileUtils.readLines(file, Charsets.UTF_8)) { | |
s = s.trim(); | |
if (s.startsWith("#")) { | |
out.name("__comment").value(s.substring(1).trim()); | |
} else { | |
Matcher m = MAPPING_PATTERN.matcher(s); | |
if (m.matches()) { | |
out.name(m.group(1)).value(m.group(2)); | |
} | |
} | |
} | |
out.endObject(); | |
} | |
} | |
} |
Actually it's not needed at all. I had already changed it locally just forgot to update this :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 29 should be
} else if (!s.isEmpty()) {
, no?