aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLulonaut <lulonaut@tutanota.de>2022-05-01 09:44:34 +0200
committerLulonaut <lulonaut@tutanota.de>2022-05-01 09:44:34 +0200
commitb2ff2142a5daaaa9f71b405afac440f9008cd649 (patch)
tree968ffc8b24007ec9f022f28088a33696942e3f77 /src
parente6bc3c7398fdd019a0562a8ba9cab5ef32bfb08b (diff)
downloadNotEnoughUpdates-b2ff2142a5daaaa9f71b405afac440f9008cd649.tar.gz
NotEnoughUpdates-b2ff2142a5daaaa9f71b405afac440f9008cd649.tar.bz2
NotEnoughUpdates-b2ff2142a5daaaa9f71b405afac440f9008cd649.zip
save file
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
index 50ab5b66..7ae247bf 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -76,11 +76,11 @@ import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.text.NumberFormat;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
@@ -1104,7 +1104,7 @@ public class RenderListener {
try {
try (
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(file),
+ Files.newOutputStream(file.toPath()),
StandardCharsets.UTF_8
))
) {
@@ -1139,6 +1139,10 @@ public class RenderListener {
try {
JsonObject newNPC = new JsonObject();
String displayname = lower.getDisplayName().getUnformattedText();
+ File file = new File(
+ Minecraft.getMinecraft().mcDataDir.getAbsolutePath(),
+ "config/notenoughupdates/repo/npc/" + displayname.toUpperCase() + ".json"
+ );
newNPC.add("itemid", new JsonPrimitive("minecraft:skull"));
newNPC.add("displayname", new JsonPrimitive("ยง9" + displayname + " (NPC)"));
newNPC.add("nbttag", new JsonPrimitive("TODO"));
@@ -1228,6 +1232,23 @@ public class RenderListener {
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println(gson.toJson(newNPC));
+ try {
+ //noinspection ResultOfMethodCallIgnored
+ file.createNewFile();
+ try (
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(file.toPath()),
+ StandardCharsets.UTF_8
+ ))
+ ) {
+ writer.write(gson.toJson(newNPC));
+ Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayname));
+ }
+ } catch (IOException ignored) {
+ Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.RED + "Error while writing file."));
+ }
} catch (Exception e) {
e.printStackTrace();
mc.thePlayer.addChatMessage(new ChatComponentText(