Added a warning when you try to run the jar

This commit is contained in:
coolGi2007
2022-03-27 13:54:05 +10:30
parent 6f7b1ac223
commit 0b28257f2f
3 changed files with 38 additions and 15 deletions
+26 -2
View File
@@ -2,7 +2,9 @@ package com.seibel.lod.core;
import com.seibel.lod.core.jar.JarDependencySetup;
import java.io.InputStream;
import javax.swing.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
/**
* The main class when you run the standalone jar
@@ -12,9 +14,12 @@ import java.io.InputStream;
public class JarMain {
public static void main(String[] args){
JarDependencySetup.createInitialBindings();
System.out.println("Why are you running the jar, this isn't done yet >:(");
System.out.println("WARNING: The standalone jar still work in progress");
JOptionPane.showMessageDialog(null, "The GUI for the standalone jar isn't made yet\nIf you want to use the mod then put it in your mods folder", "Distant Horizons", JOptionPane.WARNING_MESSAGE);
}
/** Get a file within the mods resources */
public static InputStream accessFile(String resource) {
@@ -27,4 +32,23 @@ public class JarMain {
return input;
}
/** Convert inputStream to String. Usefull for reading .txt or .json that are inside the jar file */
public static String convertInputStreamToString(InputStream inputStream) {
final char[] buffer = new char[8192];
final StringBuilder result = new StringBuilder();
// InputStream -> Reader
try (Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
int charsRead;
while ((charsRead = reader.read(buffer, 0, buffer.length)) > 0) {
result.append(buffer, 0, charsRead);
}
} catch (Exception e) {
e.printStackTrace();
}
return result.toString();
}
}
@@ -12,7 +12,7 @@ public class ConfigWrapper implements IConfigWrapper {
public static void init() {
try {
Object obj = new JSONParser().parse(JarMain.accessFile("assets/lod/lang/en_us.json").toString());
Object obj = new JSONParser().parse(JarMain.convertInputStreamToString(JarMain.accessFile("assets/lod/lang/en_us.json")));
jsonObject = (JSONObject) obj;
} catch (ParseException e) {
e.printStackTrace();
@@ -20,19 +20,18 @@ public class ConfigWrapper implements IConfigWrapper {
}
@Override
public boolean LangExists(String str) {
try {
if (jsonObject.get(str) == null)
return false;
else
return true;
} catch (Exception e) {
public boolean langExists(String str) {
if (jsonObject.get(str) == null)
return false;
}
else
return true;
}
@Override
public String getFromLang(String str) {
return (String) jsonObject.get(str);
public String getLang(String str) {
if (jsonObject.get(str) != null)
return (String) jsonObject.get(str);
else
return str;
}
}
@@ -2,7 +2,7 @@ package com.seibel.lod.core.wrapperInterfaces.config;
public interface IConfigWrapper {
boolean LangExists(String str);
boolean langExists(String str);
String getFromLang(String str);
String getLang(String str);
}