From 9b6664c8132fc8fd249d0983fc03d5ccc35c0f27 Mon Sep 17 00:00:00 2001
From: CitralFlo <wojtas.michal90@gmail.com>
Date: Mon, 11 Dec 2023 22:24:49 +0100
Subject: [PATCH] Add chatslowmode off messages, add support for "0" arg value
 for that command.

---
 .../core/feature/chat/ChatManagerCommand.java | 20 ++++++++++++++++++-
 .../core/translation/Translation.java         |  2 +-
 .../implementation/ENTranslation.java         |  3 +++
 .../implementation/PLTranslation.java         |  3 +++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerCommand.java
index 6def4ad47..dd4b25dd0 100644
--- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerCommand.java
+++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerCommand.java
@@ -78,7 +78,7 @@ void disable(@Context Viewer viewer, @Context CommandSender sender) {
     }
 
     @Execute(name = "slowmode")
-    @DescriptionDocs(description = "Sets slowmode for chat", arguments = "<time>")
+    @DescriptionDocs(description = "Sets SlowMode for chat", arguments = "<time>")
     void slowmode(@Context Viewer viewer, @Arg Duration duration) {
         if (duration.isNegative()) {
             this.noticeService.viewer(viewer, translation -> translation.argument().numberBiggerThanOrEqualZero());
@@ -86,6 +86,17 @@ void slowmode(@Context Viewer viewer, @Arg Duration duration) {
             return;
         }
 
+        if (duration.isZero()) {
+            this.noticeService.create()
+                    .notice(translation -> translation.chat().slowModeOff())
+                    .placeholder("{PLAYER}", viewer.getName())
+                    .viewer(viewer)
+                    .send();
+
+            this.chatManager.getChatSettings().setChatDelay(duration);
+            return;
+        }
+
         this.chatManager.getChatSettings().setChatDelay(duration);
 
         this.noticeService.create()
@@ -95,6 +106,13 @@ void slowmode(@Context Viewer viewer, @Arg Duration duration) {
             .send();
     }
 
+    @Execute(name = "slowmode 0")
+    @DescriptionDocs(description = "Disable SlowMode for chat")
+    void slowmodeOff(@Context Viewer viewer) {
+        Duration noSlowMode = Duration.ZERO;
+        this.slowmode(viewer, noSlowMode);
+    }
+
     private static Supplier<Notice> create(ChatSettings settings) {
         return () -> Notice.chat("<newline>".repeat(Math.max(0, settings.linesToClear())));
     }
diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java
index d6e1477a3..11b6f088e 100644
--- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java
+++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java
@@ -7,7 +7,6 @@
 import org.bukkit.Material;
 import org.bukkit.event.entity.EntityDamageEvent;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -114,6 +113,7 @@ interface ChatSection {
         Notice alreadyDisabled();
         Notice alreadyEnabled();
         Notice slowModeSet();
+        Notice slowModeOff();
         Notice slowMode();
         Notice disabledChatInfo();
         Notice commandNotFound();
diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java
index fabf674b0..b0082d80c 100644
--- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java
+++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java
@@ -253,6 +253,9 @@ public static class ENChatSection implements ChatSection {
         @Description({ " ", "# {SLOWMODE} - Time for next message" })
         public Notice slowModeSet = Notice.chat("<green>► <white>Slowmode set to: {SLOWMODE}");
 
+        @Description({ " ", "# {PLAYER} - Player who performed the actions for the chat" })
+        public Notice slowModeOff = Notice.chat("<green>► <white>Slowmode has been disabled by <green>{PLAYER}<white>!");
+
         @Description({ " ", "# {TIME} - Time to next use (cooldown)" })
         public Notice slowMode = Notice.chat("<red>✘ <dark_red>You can write the next message for: <red>{TIME}<dark_red>!");
 
diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java
index 7de60c4ab..a7d32f517 100644
--- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java
+++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java
@@ -256,6 +256,9 @@ public static class PLChatSection implements ChatSection {
         @Description({ " ", "# {SLOWMODE} - Czas powolnego wysyłania wiadomości" })
         public Notice slowModeSet = Notice.chat("<green>► <white>Tryb powolnego wysyłania został ustawiony na {SLOWMODE}");
 
+        @Description({ " ", "# {PLAYER} - Gracz który wyłączył tryb powolnego wysyłania wiadomości" })
+        public Notice slowModeOff = Notice.chat("<green>► <white>Tryb powolnego wysyłania został wyłączony przez <green>{PLAYER}<white>!");
+
         @Description({ " ", "# {TIME} - Czas powolnego wysyłania wiadomości" })
         public Notice slowMode = Notice.chat("<red>✘ <dark_red>Następną wiadomość możesz wysłać za: <red>{TIME}<dark_red>!");