diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-08-09 20:46:00 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-08-09 20:46:00 +0200 |
commit | 2cd5f8e6bd42a084022028adcc24ef566fddab95 (patch) | |
tree | e06a18df40629371c33b9efce971489812696ac0 /src/main/java/de/hype/bbsentials/api | |
download | BBsentials-2cd5f8e6bd42a084022028adcc24ef566fddab95.tar.gz BBsentials-2cd5f8e6bd42a084022028adcc24ef566fddab95.tar.bz2 BBsentials-2cd5f8e6bd42a084022028adcc24ef566fddab95.zip |
Initial commit
Diffstat (limited to 'src/main/java/de/hype/bbsentials/api')
-rw-r--r-- | src/main/java/de/hype/bbsentials/api/Discord.java | 70 | ||||
-rw-r--r-- | src/main/java/de/hype/bbsentials/api/ISimpleOption.java | 5 | ||||
-rw-r--r-- | src/main/java/de/hype/bbsentials/api/Options.java | 13 |
3 files changed, 88 insertions, 0 deletions
diff --git a/src/main/java/de/hype/bbsentials/api/Discord.java b/src/main/java/de/hype/bbsentials/api/Discord.java new file mode 100644 index 0000000..e8c8887 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/api/Discord.java @@ -0,0 +1,70 @@ +package de.hype.bbsentials.api; + +import de.hype.bbsentials.chat.Chat; +import de.hype.bbsentials.client.BBsentials; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +public class Discord { + public static void sendWebhookMessage(String message) { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + sendWebhookMessageNoThread(message); + } + }); + thread.start(); + } + + + public static void sendWebhookMessageNoThread(String message) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String WEBHOOK_URL = "https://discord.com/api/v8/webhooks/1127524566407860276/" + BBsentials.getConfig().getApiKey(); + + + try { + HttpPost httpPost = new HttpPost(WEBHOOK_URL); + + StringEntity jsonEntity = new StringEntity("{\"content\": \"" + message + "\"}", StandardCharsets.UTF_8); + jsonEntity.setContentType("application/json"); + httpPost.setEntity(jsonEntity); + + CloseableHttpResponse response = httpClient.execute(httpPost); + HttpEntity responseEntity = response.getEntity(); + + if (responseEntity != null) { + InputStream inputStream = responseEntity.getContent(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + + String line; + StringBuilder responseBuilder = new StringBuilder(); + while ((line = reader.readLine()) != null) { + responseBuilder.append(line); + } + + String responseString = responseBuilder.toString(); + Chat.sendPrivateMessageToSelf(responseString); + } + + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + httpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/de/hype/bbsentials/api/ISimpleOption.java b/src/main/java/de/hype/bbsentials/api/ISimpleOption.java new file mode 100644 index 0000000..c6e1158 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/api/ISimpleOption.java @@ -0,0 +1,5 @@ +package de.hype.bbsentials.api; + +public interface ISimpleOption { + void set(Object value); +} diff --git a/src/main/java/de/hype/bbsentials/api/Options.java b/src/main/java/de/hype/bbsentials/api/Options.java new file mode 100644 index 0000000..7dc4b0d --- /dev/null +++ b/src/main/java/de/hype/bbsentials/api/Options.java @@ -0,0 +1,13 @@ +package de.hype.bbsentials.api; + +import net.minecraft.client.MinecraftClient; + +public class Options{ + public static void setFov(int value) { + ((ISimpleOption) (Object) MinecraftClient.getInstance().options.getFov()).set(value); + } + public static void setGamma(double value) { + ((ISimpleOption) (Object) MinecraftClient.getInstance().options.getGamma()).set(value); + } +} + |