From 19dcc4c482af22e922e6a351c9c6d6165e0de8c3 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Tue, 4 Dec 2018 14:02:05 -0600 Subject: [PATCH] Added GriefAlert Fixes #22 --- docs/source/changelog/index.rst | 3 +- docs/source/changelog/v1.6.rst | 16 ++++++ docs/source/misc.rst | 5 ++ pom.xml | 2 +- src/main/java/xyz/etztech/qol/QoL.java | 13 +++++ .../qol/listeners/BlockIgniteListener.java | 4 ++ .../qol/listeners/BlockPlaceListener.java | 26 +++++++++ .../listeners/PlayerBucketEmptyListener.java | 26 +++++++++ .../xyz/etztech/qol/other/GriefAlert.java | 57 +++++++++++++++++++ src/main/resources/config.yml | 4 ++ src/main/resources/plugin.yml | 3 + 11 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 docs/source/changelog/v1.6.rst create mode 100644 src/main/java/xyz/etztech/qol/listeners/BlockPlaceListener.java create mode 100644 src/main/java/xyz/etztech/qol/listeners/PlayerBucketEmptyListener.java create mode 100644 src/main/java/xyz/etztech/qol/other/GriefAlert.java diff --git a/docs/source/changelog/index.rst b/docs/source/changelog/index.rst index 2378709..3ad6100 100644 --- a/docs/source/changelog/index.rst +++ b/docs/source/changelog/index.rst @@ -10,4 +10,5 @@ Changelogs v1.3 v1.4 - v1.5 \ No newline at end of file + v1.5 + v1.6 \ No newline at end of file diff --git a/docs/source/changelog/v1.6.rst b/docs/source/changelog/v1.6.rst new file mode 100644 index 0000000..b4c06dc --- /dev/null +++ b/docs/source/changelog/v1.6.rst @@ -0,0 +1,16 @@ +.. include:: ../common.rst + +.. _qol_v1.6: + +QoL v1.6 +======== + +Additions +--------- +* `Grief Alert`_ - Monitors for actions (starting a fire, dumping lava, or placing TnT) and alerts when encountered + +.. _Grief Alert: https://git.etztech.xyz/Etzelia/QoL/issues/22 + +Bug Fixes +--------- +None \ No newline at end of file diff --git a/docs/source/misc.rst b/docs/source/misc.rst index 639ecc4..d340076 100644 --- a/docs/source/misc.rst +++ b/docs/source/misc.rst @@ -48,3 +48,8 @@ Auto Dynmap Hide If Dynmap is detected on the server, QoL will hide a user on the dynmap when they spec. When they come out of spec, their previous visibility state will be restored. + +Grief Alert +----------- + +If a player places TnT, starts a fire, or dumps lava, everyone with the ``qol.griefalert`` permission is notified as well as an optional Discord ping. \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2b4272..bb29ef3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.5 + 1.6 jar diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 48507c4..0cfe70a 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -9,6 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.DynmapAPI; import xyz.etztech.qol.commands.*; import xyz.etztech.qol.listeners.*; +import xyz.etztech.qol.other.GriefAlert; import xyz.etztech.qol.other.LinkCommand; import xyz.etztech.qol.other.TPSRunnable; @@ -32,6 +33,7 @@ public class QoL extends JavaPlugin { private static boolean timeout = false; private static List audits = new ArrayList<>(); private static List links = new ArrayList<>(); + private GriefAlert griefAlert; public void onEnable() { instance = this; @@ -68,6 +70,10 @@ public class QoL extends JavaPlugin { getServer().getPluginManager().registerEvents(commandPreprocessListener, this); DeathListener deathListener = new DeathListener(this); getServer().getPluginManager().registerEvents(deathListener, this); + PlayerBucketEmptyListener playerBucketEmptyListener = new PlayerBucketEmptyListener(this); + getServer().getPluginManager().registerEvents(playerBucketEmptyListener, this); + BlockPlaceListener blockPlaceListener = new BlockPlaceListener(this); + getServer().getPluginManager().registerEvents(blockPlaceListener, this); // Add commands MainCommand mainCommand = new MainCommand(this); @@ -143,6 +149,9 @@ public class QoL extends JavaPlugin { // TPS Check Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new TPSRunnable(this), 0, EtzTechUtil.minutesToTicks(1)); + // Grief Alert + griefAlert = new GriefAlert(this); + Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), griefAlert, 0, EtzTechUtil.minutesToTicks(10)); } } @@ -266,6 +275,10 @@ public class QoL extends JavaPlugin { public DynmapAPI getDynmap() { return dynmap; } + public GriefAlert getGriefAlert() { + return griefAlert; + } + private void runTask(final String command) { Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)); diff --git a/src/main/java/xyz/etztech/qol/listeners/BlockIgniteListener.java b/src/main/java/xyz/etztech/qol/listeners/BlockIgniteListener.java index 1e4cb51..5b06043 100644 --- a/src/main/java/xyz/etztech/qol/listeners/BlockIgniteListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/BlockIgniteListener.java @@ -19,5 +19,9 @@ public class BlockIgniteListener implements Listener { if (plugin.getConfig().getBoolean("disable-fire." + cause.name().toLowerCase())) { event.setCancelled(true); } + + if (event.getPlayer() != null && (cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL || cause == BlockIgniteEvent.IgniteCause.FIREBALL)) { + plugin.getGriefAlert().addAlert(event.getPlayer().getName() + " started a fire."); + } } } diff --git a/src/main/java/xyz/etztech/qol/listeners/BlockPlaceListener.java b/src/main/java/xyz/etztech/qol/listeners/BlockPlaceListener.java new file mode 100644 index 0000000..c5309a9 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/listeners/BlockPlaceListener.java @@ -0,0 +1,26 @@ +package xyz.etztech.qol.listeners; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import xyz.etztech.qol.QoL; + +public class BlockPlaceListener implements Listener { + + QoL plugin; + + public BlockPlaceListener(QoL plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + Player player = event.getPlayer(); + if( event.getBlockPlaced().getType() == Material.TNT) { + plugin.getGriefAlert().addAlert(player.getName() + " placed TnT."); + } + } +} diff --git a/src/main/java/xyz/etztech/qol/listeners/PlayerBucketEmptyListener.java b/src/main/java/xyz/etztech/qol/listeners/PlayerBucketEmptyListener.java new file mode 100644 index 0000000..1acfbbf --- /dev/null +++ b/src/main/java/xyz/etztech/qol/listeners/PlayerBucketEmptyListener.java @@ -0,0 +1,26 @@ +package xyz.etztech.qol.listeners; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import xyz.etztech.qol.QoL; + +public class PlayerBucketEmptyListener implements Listener { + + QoL plugin; + + public PlayerBucketEmptyListener(QoL plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { + Player player = event.getPlayer(); + if( event.getBucket() == Material.LAVA_BUCKET) { + plugin.getGriefAlert().addAlert(player.getName() + " poured lava."); + } + } +} diff --git a/src/main/java/xyz/etztech/qol/other/GriefAlert.java b/src/main/java/xyz/etztech/qol/other/GriefAlert.java new file mode 100644 index 0000000..da692de --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/GriefAlert.java @@ -0,0 +1,57 @@ +package xyz.etztech.qol.other; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import xyz.etztech.core.web.CoreWeb; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.QoL; + +import java.util.HashMap; +import java.util.Map; + +public class GriefAlert implements Runnable { + private Map alerts; + + private QoL plugin; + + public GriefAlert(QoL plugin) { + this.plugin = plugin; + } + + + @Override + public void run() { + alerts = new HashMap<>(); + } + + public void addAlert(String alert) { + int num = alerts.getOrDefault(alert, 0); + alerts.put(alert, ++num); + int lines = plugin.getConfig().getInt("grief-alert.lines", 5); + if (num < lines) { + alert(alert); + if (num == 1) { + String webhook = plugin.getConfig().getString("grief-alert.webhook", ""); + String message = "@here " + alert; + if (StringUtils.isNotEmpty(webhook)) { + Map data = new HashMap<>(); + data.put("username", "Grief Alert"); + data.put("content", message); + CoreWeb.asyncPost(plugin, webhook, data); + } + } + } else if (num == lines) { + alert(alert + " Suppressing more alerts for a while..."); + } + } + + private void alert(String alert) { + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.hasPermission("qol.griefalert")) { + EtzTechUtil.sms(player, ChatColor.RED + alert); + } + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3e19f32..f359ff6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -40,6 +40,10 @@ tps: threshold: 12 webhook: '' +grief-alert: + lines: 5 + webhook: '' + # The range after which a player will be marked as "outside the border" worldinfo: world: 5000 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9e95ebe..bfdc19c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -86,6 +86,9 @@ permissions: qol.tpconfirm: description: Makes the user confirm they want to TP out of spec default: op + qol.griefalert: + description: Alerts the user when monitored actions are encountered + default: op qol.whitelist.bypass: description: Allows someone into the server when Whitelist is enabled default: op