Skip to content

Commit e072cbd

Browse files
authored
GH-976 Fix chat clear logic to directly send empty messages. (#1047)
* Fix chat clear logic to directly send empty messages. * Set default lines to clear to 256.
1 parent e054a21 commit e072cbd

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static class Chat implements ChatSettings {
193193
public Duration chatDelay = Duration.ofSeconds(5);
194194

195195
@Description({ " ", "# Number of lines that will be cleared when using the /chat clear command" })
196-
public int linesToClear = 128;
196+
public int linesToClear = 256;
197197

198198
@Description({ " ", "# Chat should be enabled?" })
199199
public boolean chatEnabled = true;

eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatCommand.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,40 @@
2121
import dev.rollczi.litecommands.annotations.permission.Permission;
2222
import java.time.Duration;
2323
import java.util.function.Supplier;
24+
import org.bukkit.Server;
2425
import org.bukkit.command.CommandSender;
2526

2627
@Command(name = "chat")
2728
@Permission("eternalcore.chat")
2829
class ChatCommand {
2930

31+
private static final String EMPTY_CHAT_STRING = " ";
32+
3033
private final NoticeService noticeService;
3134
private final ChatSettings chatSettings;
3235
private final EventCaller eventCaller;
36+
private final Server server;
3337

3438
private final PluginConfiguration config;
3539
private final ConfigurationManager configManager;
3640
private final Scheduler scheduler;
3741

38-
private final Supplier<Notice> clear;
39-
4042
@Inject
4143
ChatCommand(
4244
NoticeService noticeService,
4345
ChatSettings chatSettings,
44-
EventCaller eventCaller,
46+
EventCaller eventCaller, Server server,
4547
PluginConfiguration config,
4648
ConfigurationManager configManager, Scheduler scheduler
4749
) {
4850
this.noticeService = noticeService;
4951
this.chatSettings = chatSettings;
5052
this.eventCaller = eventCaller;
53+
this.server = server;
5154

5255
this.config = config;
5356
this.configManager = configManager;
5457
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())));
6158
}
6259

6360
@Execute(name = "clear", aliases = "cc")
@@ -69,8 +66,13 @@ void clear(@Context CommandSender sender) {
6966
return;
7067
}
7168

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+
7275
this.noticeService.create()
73-
.notice(this.clear.get())
7476
.notice(translation -> translation.chat().cleared())
7577
.placeholder("{PLAYER}", sender.getName())
7678
.onlinePlayers()

0 commit comments

Comments
 (0)