-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a83f54
commit ddfa049
Showing
2 changed files
with
223 additions
and
124 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package Util; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import javax.swing.Spring; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
|
||
public class Config { | ||
|
||
public static Object config = null; | ||
public static JSONObject objconfig = null; | ||
|
||
public static void readConfig() throws FileNotFoundException, IOException, ParseException { | ||
File dir = new File("tmp"); | ||
dir.mkdir(); | ||
JSONParser parser = new JSONParser(); | ||
Object obj = null; | ||
obj = parser.parse(new FileReader("config.json")); | ||
config = obj; | ||
JSONObject jsonObject = (JSONObject) obj; | ||
objconfig = jsonObject; | ||
System.out.println("[INFO]: Successfully loaded"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static void createConfig() { | ||
// https://marc.enjuu.click/download/4986555.json | ||
File f = new File("config.json"); | ||
if(f.exists()) { | ||
System.out.println("[INFO]: Found Config! No one must be created"); | ||
}else{ | ||
System.out.println("[WARNING]: No Config Found! Create one..."); | ||
JSONObject obj = new JSONObject(); | ||
obj.put("name", "Enjuu"); | ||
obj.put("apiprotocol", "https"); | ||
obj.put("api", "enjuu.click"); | ||
obj.put("webprotocol", "https"); | ||
obj.put("web", "enjuu.click"); | ||
obj.put("token", "NaN"); | ||
obj.put("status", "on Enjuu"); | ||
|
||
|
||
try (FileWriter file = new FileWriter("config.json")) { | ||
file.write(obj.toJSONString()); | ||
System.out.println("[INFO]: Successfully created Config..."); | ||
} catch (IOException e) { | ||
System.err.println("[ERROR]: Can't create Config..."); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
|
||
public static String getString(String string) { | ||
try{ | ||
String result = (String) objconfig.get(string); | ||
return result; | ||
}catch (Exception e){ | ||
return "Error Load "+string+ " in config.json! Is it possible that your String ins't a String?"; | ||
} | ||
} | ||
|
||
public static int getInt(Spring path) { | ||
try{ | ||
int result = (int) objconfig.get(path); | ||
return result; | ||
}catch (Exception e){ | ||
System.out.println("I can't load the int! Maybe the in the Config the Number ins't a int. Try use a Long"); | ||
return 404; | ||
} | ||
} | ||
|
||
public static Boolean getBool(String string) { | ||
try{ | ||
Boolean result = (Boolean) objconfig.get(string); | ||
return result; | ||
}catch (Exception e){ | ||
System.out.println("Error Loading the Config"); | ||
return false; | ||
} | ||
} | ||
|
||
public static Long getLong(Long string) { | ||
try{ | ||
Long result = (Long) objconfig.get(string); | ||
return result; | ||
}catch (Exception e){ | ||
System.out.println("Error Loading the Config"); | ||
return null; | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,124 @@ | ||
package Util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
public class User { | ||
|
||
public static String ID_TO_USER(Long id) { | ||
|
||
String getter = null; | ||
URL u = null; | ||
try { | ||
u = new URL("https://enjuu.click/api/v1/users?id="+id); | ||
} catch (MalformedURLException e1) { | ||
e1.printStackTrace(); | ||
} | ||
try{ | ||
URLConnection urlConnection = u.openConnection(); | ||
urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0"); | ||
|
||
try (InputStream stream = urlConnection.getInputStream(); | ||
InputStreamReader inputStreamReader = new InputStreamReader(stream); | ||
BufferedReader reader = new BufferedReader(inputStreamReader)) { | ||
|
||
StringBuilder result = new StringBuilder(); | ||
String tmp; | ||
while ((tmp = reader.readLine()) != null) { | ||
result.append(tmp).append("\n"); | ||
} | ||
getter = result.toString(); | ||
} | ||
}catch (Exception e){ | ||
|
||
} | ||
JSONParser parser = new JSONParser(); | ||
try { | ||
|
||
File file = new File("idtouser.json"); | ||
|
||
file.delete(); | ||
|
||
|
||
|
||
PrintWriter writer = new PrintWriter("idtouser.json", "UTF-8"); | ||
writer.println(getter); | ||
writer.close(); | ||
|
||
Object obj = parser.parse(new FileReader( | ||
"idtouser.json")); | ||
|
||
JSONObject jsonObject = (JSONObject) obj; | ||
String username = (String) jsonObject.get("username"); | ||
return username; | ||
}catch (Exception e){ | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
public static Long USER_TO_ID(String user){ | ||
|
||
String getter = null; | ||
URL u = null; | ||
try { | ||
u = new URL("https://enjuu.click/api/v1/users?name="+user); | ||
} catch (MalformedURLException e1) { | ||
e1.printStackTrace(); | ||
} | ||
try{ | ||
URLConnection urlConnection = u.openConnection(); | ||
urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0"); | ||
|
||
try (InputStream stream = urlConnection.getInputStream(); | ||
InputStreamReader inputStreamReader = new InputStreamReader(stream); | ||
BufferedReader reader = new BufferedReader(inputStreamReader)) { | ||
|
||
StringBuilder result = new StringBuilder(); | ||
String tmp; | ||
while ((tmp = reader.readLine()) != null) { | ||
result.append(tmp).append("\n"); | ||
} | ||
getter = result.toString(); | ||
} | ||
}catch (Exception e){ | ||
|
||
} | ||
JSONParser parser = new JSONParser(); | ||
try { | ||
|
||
File file = new File("usertoid.json"); | ||
|
||
file.delete(); | ||
|
||
|
||
|
||
PrintWriter writer = new PrintWriter("usertoid.json", "UTF-8"); | ||
writer.println(getter); | ||
writer.close(); | ||
|
||
Object obj = parser.parse(new FileReader( | ||
"usertoid.json")); | ||
|
||
JSONObject jsonObject = (JSONObject) obj; | ||
Long id = (Long) jsonObject.get("id"); | ||
return id; | ||
}catch (Exception e){ | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
} | ||
package Util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
public class User { | ||
|
||
public static String ID_TO_USER(Long id) { | ||
|
||
String getter = null; | ||
URL u = null; | ||
try { | ||
u = new URL("https://enjuu.click/api/v1/users?id="+id); | ||
} catch (MalformedURLException e1) { | ||
e1.printStackTrace(); | ||
} | ||
try{ | ||
URLConnection urlConnection = u.openConnection(); | ||
urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0"); | ||
|
||
try (InputStream stream = urlConnection.getInputStream(); | ||
InputStreamReader inputStreamReader = new InputStreamReader(stream); | ||
BufferedReader reader = new BufferedReader(inputStreamReader)) { | ||
|
||
StringBuilder result = new StringBuilder(); | ||
String tmp; | ||
while ((tmp = reader.readLine()) != null) { | ||
result.append(tmp).append("\n"); | ||
} | ||
getter = result.toString(); | ||
} | ||
}catch (Exception e){ | ||
|
||
} | ||
JSONParser parser = new JSONParser(); | ||
try { | ||
|
||
File file = new File("idtouser.json"); | ||
|
||
file.delete(); | ||
|
||
|
||
|
||
PrintWriter writer = new PrintWriter("idtouser.json", "UTF-8"); | ||
writer.println(getter); | ||
writer.close(); | ||
|
||
Object obj = parser.parse(new FileReader( | ||
"idtouser.json")); | ||
|
||
JSONObject jsonObject = (JSONObject) obj; | ||
String username = (String) jsonObject.get("username"); | ||
return username; | ||
}catch (Exception e){ | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
public static Long USER_TO_ID(String user){ | ||
|
||
String getter = null; | ||
URL u = null; | ||
try { | ||
u = new URL("https://enjuu.click/api/v1/users?name="+user); | ||
} catch (MalformedURLException e1) { | ||
e1.printStackTrace(); | ||
} | ||
try{ | ||
URLConnection urlConnection = u.openConnection(); | ||
urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0"); | ||
|
||
try (InputStream stream = urlConnection.getInputStream(); | ||
InputStreamReader inputStreamReader = new InputStreamReader(stream); | ||
BufferedReader reader = new BufferedReader(inputStreamReader)) { | ||
|
||
StringBuilder result = new StringBuilder(); | ||
String tmp; | ||
while ((tmp = reader.readLine()) != null) { | ||
result.append(tmp).append("\n"); | ||
} | ||
getter = result.toString(); | ||
} | ||
}catch (Exception e){ | ||
|
||
} | ||
JSONParser parser = new JSONParser(); | ||
try { | ||
|
||
File file = new File("usertoid.json"); | ||
|
||
file.delete(); | ||
|
||
|
||
|
||
PrintWriter writer = new PrintWriter("usertoid.json", "UTF-8"); | ||
writer.println(getter); | ||
writer.close(); | ||
|
||
Object obj = parser.parse(new FileReader( | ||
"usertoid.json")); | ||
|
||
JSONObject jsonObject = (JSONObject) obj; | ||
Long id = (Long) jsonObject.get("id"); | ||
return id; | ||
}catch (Exception e){ | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
} |