parent
3da1306106
commit
fa9eb9a1d2
2
pom.xml
2
pom.xml
|
@ -37,7 +37,7 @@
|
|||
<dependency>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>javacord</artifactId>
|
||||
<version>0.0.2</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
|
|
|
@ -2,6 +2,7 @@ package xyz.etztech.minealert;
|
|||
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xyz.etztech.embed.Webhook;
|
||||
import xyz.etztech.minealert.commands.MainCommand;
|
||||
import xyz.etztech.minealert.listeners.BlockBreakListener;
|
||||
|
||||
|
@ -68,14 +69,14 @@ public class MineAlert extends JavaPlugin {
|
|||
return def;
|
||||
}
|
||||
|
||||
public static void sendWebhook(String webhook, String embed) throws Exception {
|
||||
URL url = new URL(webhook);
|
||||
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 = embed.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] out = webhook.toString().getBytes(StandardCharsets.UTF_8);
|
||||
int length = out.length;
|
||||
http.setFixedLengthStreamingMode(length);
|
||||
http.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
|
|
|
@ -75,7 +75,11 @@ public class MainCommand implements CommandExecutor {
|
|||
|
||||
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
MineAlert.sendWebhook(webhook, embed());
|
||||
Embed embed = new Embed()
|
||||
.color(Color.PRIMARY.getInt())
|
||||
.description("Test Message")
|
||||
.author(new Author("Console", "", "https://minotar.net/helm/Notch/100.png", ""));
|
||||
MineAlert.sendWebhook(webhook, new Webhook("", embed));
|
||||
Color.INFO.sms(commandSender, "Webhook sent!");
|
||||
} catch (Exception e) {
|
||||
Lang.WEBHOOK_FAILED.sms(commandSender);
|
||||
|
@ -83,13 +87,4 @@ public class MainCommand implements CommandExecutor {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
private String embed() {
|
||||
Embed embed = new Embed()
|
||||
.color(Color.PRIMARY.getInt())
|
||||
.description("Test Message")
|
||||
.author(new Author("Console", "", "https://minotar.net/helm/Notch/100.png", ""));
|
||||
|
||||
return new Webhook("", embed).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package xyz.etztech.minealert.listeners;
|
|||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
@ -144,10 +145,19 @@ public class BlockBreakListener implements Listener {
|
|||
String.format("ore.blocks.%s.color", Lang.getMaterialKey(event.getMaterial())),
|
||||
"ore.color"
|
||||
);
|
||||
BaseComponent[] component = new ComponentBuilder()
|
||||
.append(message).color(ChatColor.of(hexColor))
|
||||
.create();
|
||||
String usernameURL = this.plugin.getConfigStringFallback(
|
||||
"",
|
||||
String.format("ore.blocks.%s.url", Lang.getMaterialKey(event.getMaterial())),
|
||||
"ore.url",
|
||||
"url"
|
||||
).replaceAll("\\{username}", event.getPlayer().getName());
|
||||
|
||||
ComponentBuilder builder = new ComponentBuilder()
|
||||
.append(message).color(ChatColor.of(hexColor));
|
||||
if (!"".equals(usernameURL)) {
|
||||
builder.event(new ClickEvent(ClickEvent.Action.OPEN_URL, usernameURL));
|
||||
}
|
||||
BaseComponent[] component = builder.create();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.hasPermission("minealert.alert")) {
|
||||
player.spigot().sendMessage(component);
|
||||
|
@ -162,27 +172,22 @@ public class BlockBreakListener implements Listener {
|
|||
"webhook"
|
||||
);
|
||||
if (!"".equals(webhook)) {
|
||||
String embed = embed(event, message, ping, hexColor);
|
||||
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
MineAlert.sendWebhook(webhook, embed);
|
||||
} catch (Exception e) {
|
||||
this.plugin.log(Lang.WEBHOOK_FAILED.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String embed(BlockEvent event, String message, boolean ping, String hexColor) {
|
||||
Embed embed = new Embed()
|
||||
.color(Color.hexToInt(hexColor))
|
||||
.description(message)
|
||||
.timestamp(OffsetDateTime.now())
|
||||
.author(new Author(Javacord.escapeFormat(event.getPlayer().getName()),
|
||||
"",
|
||||
!"".equals(usernameURL) ? usernameURL : "",
|
||||
String.format("https://minotar.net/helm/%s/100.png", event.getPlayer().getName()),
|
||||
""));
|
||||
return new Webhook(ping ? "@here": "", embed).toString();
|
||||
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
MineAlert.sendWebhook(webhook, new Webhook(ping ? "@here" : "", embed));
|
||||
} catch (Exception e) {
|
||||
this.plugin.log(Lang.WEBHOOK_FAILED.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# Global Discord webhook
|
||||
# This can be set as a global fallback
|
||||
webhook: ''
|
||||
# The URL the message points to
|
||||
# Can use {username} as a placeholder for the player's username
|
||||
url: 'https://website.com/{username}'
|
||||
|
||||
# OreAlert
|
||||
ore:
|
||||
|
@ -22,6 +25,8 @@ ore:
|
|||
ping: 5
|
||||
# Discord webhook
|
||||
webhook: ''
|
||||
# Override
|
||||
url: ''
|
||||
|
||||
# Only blocks listed here will be monitored
|
||||
# Each of the above notify settings can be overridden per-block if needed
|
||||
|
|
Loading…
Reference in New Issue