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