parent
b7375b0794
commit
a731758f12
|
@ -1,5 +1,9 @@
|
|||
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;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -57,42 +61,48 @@ public class GriefAlertListener implements Listener {
|
|||
).replaceAll("\\{username}", playerName);
|
||||
|
||||
int threshold = this.plugin.getConfig().getInt("grief.threshold", 5);
|
||||
if (dates.size() < threshold) {
|
||||
sendAlert(alert, color);
|
||||
} else if (dates.size() == threshold) {
|
||||
StringBuilder extra = new StringBuilder(" Suppressing more alerts for a while");
|
||||
String webhook = this.plugin.getConfigStringFallback(
|
||||
"",
|
||||
"grief.webhook",
|
||||
"webhook"
|
||||
);
|
||||
if (!"".equals(webhook)) {
|
||||
extra.append(" and pinging Discord");
|
||||
Embed embed = new Embed()
|
||||
.color(color.getInt())
|
||||
.description(alert)
|
||||
.timestamp(OffsetDateTime.now())
|
||||
.author(new Author(Javacord.escapeFormat(playerName),
|
||||
!"".equals(usernameURL) ? usernameURL : "",
|
||||
String.format("https://minotar.net/helm/%s/100.png", playerName),
|
||||
""));
|
||||
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
Javacord.sendWebhook(webhook, new Webhook("@here", embed));
|
||||
} catch (Exception e) {
|
||||
this.plugin.log(Lang.WEBHOOK_FAILED.getMessage());
|
||||
}
|
||||
});
|
||||
if (dates.size() <= threshold) {
|
||||
StringBuilder extra = new StringBuilder();
|
||||
if (dates.size() == threshold) {
|
||||
extra.append(" Suppressing more alerts for a while");
|
||||
String webhook = this.plugin.getConfigStringFallback(
|
||||
"",
|
||||
"grief.webhook",
|
||||
"webhook"
|
||||
);
|
||||
if (!"".equals(webhook)) {
|
||||
extra.append(" and pinging Discord");
|
||||
Embed embed = new Embed()
|
||||
.color(color.getInt())
|
||||
.description(alert)
|
||||
.timestamp(OffsetDateTime.now())
|
||||
.author(new Author(Javacord.escapeFormat(playerName),
|
||||
!"".equals(usernameURL) ? usernameURL : "",
|
||||
String.format("https://minotar.net/helm/%s/100.png", playerName),
|
||||
""));
|
||||
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
Javacord.sendWebhook(webhook, new Webhook("@here", embed));
|
||||
} catch (Exception e) {
|
||||
this.plugin.log(Lang.WEBHOOK_FAILED.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
extra.append("...");
|
||||
}
|
||||
extra.append("...");
|
||||
sendAlert(alert + extra.toString(), color);
|
||||
ComponentBuilder builder = new ComponentBuilder()
|
||||
.append(alert + extra.toString()).color(color.getChatColor());
|
||||
if (!"".equals(usernameURL)) {
|
||||
builder.event(new ClickEvent(ClickEvent.Action.OPEN_URL, usernameURL));
|
||||
}
|
||||
sendAlert(builder.create());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAlert(String alert, Color color) {
|
||||
public void sendAlert(BaseComponent[] message) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.hasPermission("minealert.alert")) {
|
||||
color.sms(player, alert);
|
||||
player.spigot().sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue