forked from Minecraft/Hush
Added configurable webhook cooldown (#9)
Added configurable webhook cooldown + A webhook cooldown can be set in minutes + During the cooldown, commands are still run but the user does cause more webhooks to be sent + Bumped version Co-authored-by: Joey Hines <joey@ahines.net> Reviewed-on: https://git.etztech.xyz/Minecraft/Hush/pulls/9 Reviewed-by: Etzelia <etzelia@hotmail.com>master
parent
8cd551112e
commit
25d280ed55
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = 'com.zerohighdef'
|
||||
version = '0.2.0'
|
||||
version = '0.2.1'
|
||||
|
||||
sourceCompatibility = '8'
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@ package com.zerohighdef.hush;
|
|||
import com.zerohighdef.hush.commands.MainCommand;
|
||||
import com.zerohighdef.hush.listeners.HushAsyncChatListener;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class Hush extends JavaPlugin {
|
||||
private final Logger log = Logger.getLogger("Minecraft");
|
||||
private HashMap<String, List<WatchCategory>> watchLists;
|
||||
private final HashMap<UUID, OffsetDateTime> cooldowns = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
@ -57,4 +57,17 @@ public final class Hush extends JavaPlugin {
|
|||
public Map<String, List<WatchCategory>> getWatchLists() {
|
||||
return watchLists;
|
||||
}
|
||||
|
||||
public void addCoolDown(Player player) {
|
||||
cooldowns.put(player.getUniqueId(), OffsetDateTime.now());
|
||||
}
|
||||
|
||||
public boolean isInCoolDown(Player player) {
|
||||
if (cooldowns.containsKey(player.getUniqueId())) {
|
||||
int cooldownTime = getConfig().getInt("cooldown", 5);
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
return now.minusMinutes(cooldownTime).compareTo(cooldowns.get(player.getUniqueId())) < 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,10 @@ public class HushAsyncChatListener implements Listener {
|
|||
runCommand(command.replace("{player}", playerName));
|
||||
}
|
||||
|
||||
if (webhookURL != null) {
|
||||
plugin.log(String.format("%s matched filter in %s.%s", playerName, watchList, category.getCategoryName()));
|
||||
|
||||
if (webhookURL != null && !plugin.isInCoolDown(player)) {
|
||||
plugin.addCoolDown(player);
|
||||
chatMessage = match.replaceAll("**$0**");
|
||||
String message = Javacord.escapeFormat(playerName) + " said: " + chatMessage;
|
||||
Embed embed = new Embed()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Discord webhook
|
||||
webhook: ""
|
||||
# Webhook cool down in minutes
|
||||
cooldown: 5
|
||||
|
||||
watch_lists:
|
||||
# Permission to check
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: Hush
|
||||
version: 0.2.0
|
||||
version: 0.2.1
|
||||
main: com.zerohighdef.hush.Hush
|
||||
api-version: "1.16"
|
||||
authors: [ZeroHighDef]
|
||||
|
|
Loading…
Reference in New Issue