1
1
package com .eternalcode .core .feature .chat ;
2
2
3
3
import com .eternalcode .annotations .scan .command .DescriptionDocs ;
4
+ import com .eternalcode .commons .scheduler .Scheduler ;
5
+ import com .eternalcode .core .configuration .ConfigurationManager ;
6
+ import com .eternalcode .core .configuration .implementation .PluginConfiguration ;
4
7
import com .eternalcode .core .event .EventCaller ;
5
8
import com .eternalcode .core .feature .chat .event .ClearChatEvent ;
6
9
import com .eternalcode .core .feature .chat .event .DisableChatEvent ;
@@ -28,19 +31,33 @@ class ChatCommand {
28
31
private final ChatSettings chatSettings ;
29
32
private final EventCaller eventCaller ;
30
33
34
+ private final PluginConfiguration config ;
35
+ private final ConfigurationManager configManager ;
36
+ private final Scheduler scheduler ;
37
+
31
38
private final Supplier <Notice > clear ;
32
39
33
40
@ Inject
34
41
ChatCommand (
35
42
NoticeService noticeService ,
36
43
ChatSettings chatSettings ,
37
- EventCaller eventCaller
44
+ EventCaller eventCaller ,
45
+ PluginConfiguration config ,
46
+ ConfigurationManager configManager , Scheduler scheduler
38
47
) {
39
48
this .noticeService = noticeService ;
40
49
this .chatSettings = chatSettings ;
50
+ this .eventCaller = eventCaller ;
51
+
52
+ this .config = config ;
53
+ this .configManager = configManager ;
54
+ this .scheduler = scheduler ;
41
55
42
56
this .clear = create (chatSettings );
43
- this .eventCaller = eventCaller ;
57
+ }
58
+
59
+ private static Supplier <Notice > create (ChatSettings settings ) {
60
+ return () -> Notice .chat ("<newline>" .repeat (Math .max (0 , settings .linesToClear ())));
44
61
}
45
62
46
63
@ Execute (name = "clear" , aliases = "cc" )
@@ -111,30 +128,30 @@ void disable(@Context Viewer viewer, @Context CommandSender sender) {
111
128
void slowmode (@ Context Viewer viewer , @ Arg Duration duration ) {
112
129
if (duration .isNegative ()) {
113
130
this .noticeService .viewer (viewer , translation -> translation .argument ().numberBiggerThanOrEqualZero ());
131
+ return ;
132
+ }
114
133
134
+ Duration currentDelay = this .chatSettings .getChatDelay ();
135
+ EditSlowModeEvent event =
136
+ this .eventCaller .callEvent (new EditSlowModeEvent (currentDelay , duration , viewer .getUniqueId ()));
137
+
138
+ if (event .isCancelled ()) {
115
139
return ;
116
140
}
117
141
142
+ this .chatSettings .setChatDelay (duration );
143
+ this .scheduler .runAsync (() -> this .configManager .save (this .config ));
144
+
118
145
if (duration .isZero ()) {
119
146
this .noticeService .create ()
120
147
.notice (translation -> translation .chat ().slowModeOff ())
121
148
.placeholder ("{PLAYER}" , viewer .getName ())
122
149
.onlinePlayers ()
123
150
.send ();
124
151
125
- this .chatSettings .setChatDelay (duration );
126
- return ;
127
- }
128
-
129
- Duration chatDelay = this .chatSettings .getChatDelay ();
130
- EditSlowModeEvent event = this .eventCaller .callEvent (new EditSlowModeEvent (chatDelay , duration , viewer .getUniqueId ()));
131
-
132
- if (event .isCancelled ()) {
133
152
return ;
134
153
}
135
154
136
- this .chatSettings .setChatDelay (duration );
137
-
138
155
this .noticeService .create ()
139
156
.notice (translation -> translation .chat ().slowModeSet ())
140
157
.placeholder ("{SLOWMODE}" , DurationUtil .format (duration , true ))
@@ -148,9 +165,5 @@ void slowmodeOff(@Context Viewer viewer) {
148
165
Duration noSlowMode = Duration .ZERO ;
149
166
this .slowmode (viewer , noSlowMode );
150
167
}
151
-
152
- private static Supplier <Notice > create (ChatSettings settings ) {
153
- return () -> Notice .chat ("<newline>" .repeat (Math .max (0 , settings .linesToClear ())));
154
- }
155
168
}
156
169
0 commit comments