Basically i created this code, which i run every 6 seconds, if the Queue Data is not empty.
base on some performance measuring the getResponceCode causing lag. Not sure why π¦
any idea how to improve this code for Java 8
public static void SEND(String webhookurl,String data) {
if (webhookurl != null) {
if (webhookurl.contains("EXAMPLE")) {return;}
if (!webhookurl.startsWith("https://discord.com/api/webhooks")) {return;}
JsonObject json = new JsonObject();
json.addProperty("content",data);
json.addProperty("username","Janna-Log");
try {
URL url = new URL(webhookurl);
HttpsURLConnection web = (HttpsURLConnection) url.openConnection();
web.setRequestProperty("Content-Type", "application/json");
web.setRequestMethod("POST");
web.setDoOutput(true);
OutputStream stream = web.getOutputStream();
stream.write(json.toString().getBytes(StandardCharsets.UTF_8));
stream.flush();
stream.close();
int wcode = web.getResponseCode();
int rlr = web.getHeaderFieldInt("X-RateLimit-Remaining",-1);
int rls = web.getHeaderFieldInt("X-RateLimit-Reset-After",-1);
if (wcode>204 || wcode<200) {
ModFile.LOGGER.error("Error: Discord Webhook HTTP CODE: "+wcode);
ModFile.LOGGER.warn("Remaining Requests:"+rlr+" (Reset in: "+rls+"s)");
}
web.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}