Files
src
pom.xml
Code
10 846
src/main/java/dev/antiopabuse/antiopabuse/AntiOpAbusePlugin.java
/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.bukkit.ChatColor
* org.bukkit.command.Command
* org.bukkit.command.CommandExecutor
* org.bukkit.command.CommandSender
* org.bukkit.event.Listener
* org.bukkit.plugin.Plugin
* org.bukkit.plugin.java.JavaPlugin
* org.bukkit.scheduler.BukkitRunnable
*/
package dev.antiopabuse.antiopabuse;
import dev.antiopabuse.antiopabuse.CreativeLogListener;
import dev.antiopabuse.antiopabuse.LogHistory;
import dev.antiopabuse.antiopabuse.RelayAppender;
import dev.antiopabuse.antiopabuse.WebhookDispatcher;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public final class AntiOpAbusePlugin
extends JavaPlugin
implements CommandExecutor {
private WebhookDispatcher dispatcher;
private RelayAppender appender;
private LogHistory history;
public void onLoad() {
this.saveDefaultConfig();
}
public void onEnable() {
this.reloadConfig();
String webhookUrl = this.getConfig().getString("webhook-url", "");
boolean codeBlock = this.getConfig().getBoolean("send-as-codeblock", true);
boolean commandsOnly = this.getConfig().getBoolean("commands-only", false);
if (webhookUrl.isBlank() || webhookUrl.equals("DISCORD_WEBHOOK_HERE")) {
this.getLogger().severe("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557");
this.getLogger().severe("\u2551 AntiOpAbuse: webhook-url is not configured! \u2551");
this.getLogger().severe("\u2551 Edit plugins/AntiOpAbuse/config.yml \u2551");
this.getLogger().severe("\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d");
}
this.history = new LogHistory();
this.dispatcher = new WebhookDispatcher(webhookUrl, codeBlock, this.getLogger());
RelayAppender.removeExisting();
this.appender = new RelayAppender(this.dispatcher, this.history, this.getLogger(), commandsOnly);
this.appender.install();
this.getServer().getPluginManager().registerEvents((Listener)new CreativeLogListener(this.dispatcher, this.getLogger()), (Plugin)this);
this.getServer().getPluginManager().registerEvents((Listener)new AbuseListener(), (Plugin)this);
this.getCommand("antiopabuse").setExecutor((CommandExecutor)this);
this.getLogger().info("AntiOpAbuse v" + this.getDescription().getVersion() + " enabled \u2014 forwarding console to Discord." + (commandsOnly ? " [commands-only mode]" : ""));
if (this.dispatcher.isConfigured()) {
new BukkitRunnable(){
public void run() {
AntiOpAbusePlugin.this.dispatcher.dispatch("\ud83d\udfe2 Server started \u2014 " + AntiOpAbusePlugin.this.getServer().getVersion());
}
}.runTaskLater((Plugin)this, 60L);
}
}
public void onDisable() {
if (this.dispatcher != null && this.dispatcher.isConfigured()) {
this.dispatcher.dispatchNow("\ud83d\udd34 Server stopped.");
}
if (this.appender != null) {
this.appender.uninstall();
}
if (this.dispatcher != null) {
this.dispatcher.shutdown();
}
this.getLogger().info("AntiOpAbuse disabled.");
}
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (!command.getName().equalsIgnoreCase("antiopabuse")) {
return false;
}
if (args.length > 0 && args[0].equalsIgnoreCase("logs")) {
List<LogHistory.Entry> entries = this.history.snapshot();
sender.sendMessage(String.valueOf(ChatColor.GOLD) + "\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 " + String.valueOf(ChatColor.YELLOW) + "AntiOpAbuse Logs" + String.valueOf(ChatColor.GOLD) + " \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
if (entries.isEmpty()) {
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "No logs yet \u2014 nothing suspicious has happened.");
sender.sendMessage(String.valueOf(ChatColor.GOLD) + "\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
return true;
}
for (LogHistory.Entry entry : entries) {
String line = entry.line();
ChatColor color = line.contains("[CREATIVE]") ? ChatColor.AQUA : (line.toLowerCase().contains("/op ") || line.toLowerCase().contains("/deop") ? ChatColor.RED : ChatColor.WHITE);
sender.sendMessage(String.valueOf(ChatColor.DARK_GRAY) + "[" + entry.timestamp() + "] " + String.valueOf(color) + line);
}
sender.sendMessage(String.valueOf(ChatColor.GOLD) + "\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "Showing " + entries.size() + "/50 most recent entries.");
return true;
}
if (!sender.isOp()) {
sender.sendMessage(String.valueOf(ChatColor.RED) + "You must be an operator to use this command.");
return true;
}
if (args.length == 0) {
sender.sendMessage(String.valueOf(ChatColor.GOLD) + "AntiOpAbuse " + String.valueOf(ChatColor.GRAY) + "v" + this.getDescription().getVersion());
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "Usage: " + String.valueOf(ChatColor.WHITE) + "/antiopabuse logs " + String.valueOf(ChatColor.GRAY) + "- view last 50 logs (all players)");
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "Usage: " + String.valueOf(ChatColor.WHITE) + "/antiopabuse webhook " + String.valueOf(ChatColor.GRAY) + "- test the Discord webhook");
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "Usage: " + String.valueOf(ChatColor.WHITE) + "/antiopabuse reload " + String.valueOf(ChatColor.GRAY) + "- reload config");
return true;
}
switch (args[0].toLowerCase()) {
case "webhook": {
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "[AntiOpAbuse] Testing webhook, please wait...");
new BukkitRunnable() {
@Override
public void run() {
final String result = dispatcher.testWebhook();
new BukkitRunnable() {
@Override
public void run() {
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "[AntiOpAbuse] " + result);
}
}.runTask(AntiOpAbusePlugin.this);
}
}.runTaskAsynchronously(AntiOpAbusePlugin.this);
break;
}
case "reload": {
this.reloadConfig();
String newUrl = this.getConfig().getString("webhook-url", "");
boolean newCb = this.getConfig().getBoolean("send-as-codeblock", true);
boolean newCommandsOnly = this.getConfig().getBoolean("commands-only", false);
this.dispatcher.updateSettings(newUrl, newCb);
this.appender.setCommandsOnly(newCommandsOnly);
sender.sendMessage(String.valueOf(ChatColor.GRAY) + "[AntiOpAbuse] " + String.valueOf(ChatColor.GREEN) + "Config reloaded." + (String)(newCommandsOnly ? String.valueOf(ChatColor.GRAY) + " (commands-only mode ON)" : ""));
break;
}
default: {
sender.sendMessage(String.valueOf(ChatColor.RED) + "Unknown sub-command. Use: logs | webhook | reload");
}
}
return true;
}
}