Move sendWebhook to Javacord

Signed-off-by: Etzelia <etzelia@hotmail.com>
grief
Etzelia 2020-07-30 21:34:02 -05:00
parent 35eae83dcc
commit d7e9ce7925
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
4 changed files with 6 additions and 29 deletions

View File

@ -37,7 +37,7 @@
<dependency> <dependency>
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>javacord</artifactId> <artifactId>javacord</artifactId>
<version>0.1.0</version> <version>0.2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>

View File

@ -2,15 +2,9 @@ package xyz.etztech.minealert;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.embed.Webhook;
import xyz.etztech.minealert.commands.MainCommand; import xyz.etztech.minealert.commands.MainCommand;
import xyz.etztech.minealert.listeners.BlockBreakListener; import xyz.etztech.minealert.listeners.BlockBreakListener;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger; import java.util.logging.Logger;
public class MineAlert extends JavaPlugin { public class MineAlert extends JavaPlugin {
@ -68,23 +62,5 @@ public class MineAlert extends JavaPlugin {
} }
return def; return def;
} }
public static void sendWebhook(String webhookURL, Webhook webhook) throws Exception {
URL url = new URL(webhookURL);
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection) con;
http.setRequestMethod("POST");
http.setDoOutput(true);
byte[] out = webhook.toString().getBytes(StandardCharsets.UTF_8);
int length = out.length;
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; utf-8");
http.setRequestProperty("User-Agent", "MineAlert Agent");
try (OutputStream os = http.getOutputStream()) {
os.write(out, 0, out.length);
}
}
} }

View File

@ -6,9 +6,10 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import xyz.etztech.Javacord;
import xyz.etztech.Webhook;
import xyz.etztech.embed.Author; import xyz.etztech.embed.Author;
import xyz.etztech.embed.Embed; import xyz.etztech.embed.Embed;
import xyz.etztech.embed.Webhook;
import xyz.etztech.minealert.Color; import xyz.etztech.minealert.Color;
import xyz.etztech.minealert.Lang; import xyz.etztech.minealert.Lang;
import xyz.etztech.minealert.MineAlert; import xyz.etztech.minealert.MineAlert;
@ -79,7 +80,7 @@ public class MainCommand implements CommandExecutor {
.color(Color.PRIMARY.getInt()) .color(Color.PRIMARY.getInt())
.description("Test Message") .description("Test Message")
.author(new Author("Console", "", "https://minotar.net/helm/Notch/100.png", "")); .author(new Author("Console", "", "https://minotar.net/helm/Notch/100.png", ""));
MineAlert.sendWebhook(webhook, new Webhook("", embed)); Javacord.sendWebhook(webhook, new Webhook("", embed));
Color.INFO.sms(commandSender, "Webhook sent!"); Color.INFO.sms(commandSender, "Webhook sent!");
} catch (Exception e) { } catch (Exception e) {
Lang.WEBHOOK_FAILED.sms(commandSender); Lang.WEBHOOK_FAILED.sms(commandSender);

View File

@ -13,9 +13,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import xyz.etztech.Javacord; import xyz.etztech.Javacord;
import xyz.etztech.Webhook;
import xyz.etztech.embed.Author; import xyz.etztech.embed.Author;
import xyz.etztech.embed.Embed; import xyz.etztech.embed.Embed;
import xyz.etztech.embed.Webhook;
import xyz.etztech.minealert.Color; import xyz.etztech.minealert.Color;
import xyz.etztech.minealert.Lang; import xyz.etztech.minealert.Lang;
import xyz.etztech.minealert.MineAlert; import xyz.etztech.minealert.MineAlert;
@ -191,7 +191,7 @@ public class BlockBreakListener implements Listener {
"")); ""));
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
try { try {
MineAlert.sendWebhook(webhook, new Webhook(ping ? "@here" : "", embed)); Javacord.sendWebhook(webhook, new Webhook(ping ? "@here" : "", embed));
} catch (Exception e) { } catch (Exception e) {
this.plugin.log(Lang.WEBHOOK_FAILED.getMessage()); this.plugin.log(Lang.WEBHOOK_FAILED.getMessage());
} }