21
21
import dev .rollczi .litecommands .annotations .permission .Permission ;
22
22
import java .time .Duration ;
23
23
import java .util .function .Supplier ;
24
+ import org .bukkit .Server ;
24
25
import org .bukkit .command .CommandSender ;
25
26
26
27
@ Command (name = "chat" )
27
28
@ Permission ("eternalcore.chat" )
28
29
class ChatCommand {
29
30
31
+ private static final String EMPTY_CHAT_STRING = " " ;
32
+
30
33
private final NoticeService noticeService ;
31
34
private final ChatSettings chatSettings ;
32
35
private final EventCaller eventCaller ;
36
+ private final Server server ;
33
37
34
38
private final PluginConfiguration config ;
35
39
private final ConfigurationManager configManager ;
36
40
private final Scheduler scheduler ;
37
41
38
- private final Supplier <Notice > clear ;
39
-
40
42
@ Inject
41
43
ChatCommand (
42
44
NoticeService noticeService ,
43
45
ChatSettings chatSettings ,
44
- EventCaller eventCaller ,
46
+ EventCaller eventCaller , Server server ,
45
47
PluginConfiguration config ,
46
48
ConfigurationManager configManager , Scheduler scheduler
47
49
) {
48
50
this .noticeService = noticeService ;
49
51
this .chatSettings = chatSettings ;
50
52
this .eventCaller = eventCaller ;
53
+ this .server = server ;
51
54
52
55
this .config = config ;
53
56
this .configManager = configManager ;
54
57
this .scheduler = scheduler ;
55
-
56
- this .clear = create (chatSettings );
57
- }
58
-
59
- private static Supplier <Notice > create (ChatSettings settings ) {
60
- return () -> Notice .chat ("<newline>" .repeat (Math .max (0 , settings .linesToClear ())));
61
58
}
62
59
63
60
@ Execute (name = "clear" , aliases = "cc" )
@@ -69,8 +66,13 @@ void clear(@Context CommandSender sender) {
69
66
return ;
70
67
}
71
68
69
+ this .server .getOnlinePlayers ().forEach (player -> {
70
+ for (int i = 0 ; i < this .chatSettings .linesToClear (); i ++) {
71
+ player .sendMessage (EMPTY_CHAT_STRING );
72
+ }
73
+ });
74
+
72
75
this .noticeService .create ()
73
- .notice (this .clear .get ())
74
76
.notice (translation -> translation .chat ().cleared ())
75
77
.placeholder ("{PLAYER}" , sender .getName ())
76
78
.onlinePlayers ()
0 commit comments