Skip to content

GH-976 Fix chat clear logic to directly send empty messages. #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static class Chat implements ChatSettings {
public Duration chatDelay = Duration.ofSeconds(5);

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

@Description({ " ", "# Chat should be enabled?" })
public boolean chatEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,40 @@
import dev.rollczi.litecommands.annotations.permission.Permission;
import java.time.Duration;
import java.util.function.Supplier;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;

@Command(name = "chat")
@Permission("eternalcore.chat")
class ChatCommand {

private static final String EMPTY_CHAT_STRING = " ";

private final NoticeService noticeService;
private final ChatSettings chatSettings;
private final EventCaller eventCaller;
private final Server server;

private final PluginConfiguration config;
private final ConfigurationManager configManager;
private final Scheduler scheduler;

private final Supplier<Notice> clear;

@Inject
ChatCommand(
NoticeService noticeService,
ChatSettings chatSettings,
EventCaller eventCaller,
EventCaller eventCaller, Server server,
PluginConfiguration config,
ConfigurationManager configManager, Scheduler scheduler
) {
this.noticeService = noticeService;
this.chatSettings = chatSettings;
this.eventCaller = eventCaller;
this.server = server;

this.config = config;
this.configManager = configManager;
this.scheduler = scheduler;

this.clear = create(chatSettings);
}

private static Supplier<Notice> create(ChatSettings settings) {
return () -> Notice.chat("<newline>".repeat(Math.max(0, settings.linesToClear())));
}

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

this.server.getOnlinePlayers().forEach(player -> {
for (int i = 0; i < this.chatSettings.linesToClear(); i++) {
player.sendMessage(EMPTY_CHAT_STRING);
}
});

this.noticeService.create()
.notice(this.clear.get())
.notice(translation -> translation.chat().cleared())
.placeholder("{PLAYER}", sender.getName())
.onlinePlayers()
Expand Down