Skip to content

Commit 477361c

Browse files
vLuckyyyRollczi
andauthored
GH-912 Respect of event modifications and improve adminchat command. (#912)
* Fix respect of event modifications and improve adminchat command. * Simplify lambda statement --------- Co-authored-by: Rollczi <[email protected]>
1 parent 1802ac8 commit 477361c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/adminchat/AdminChatCommand.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
import com.eternalcode.core.injector.annotations.Inject;
77
import com.eternalcode.core.notice.NoticeService;
88
import com.eternalcode.multification.notice.NoticeBroadcast;
9+
import dev.rollczi.litecommands.annotations.command.Command;
910
import dev.rollczi.litecommands.annotations.context.Context;
10-
import dev.rollczi.litecommands.annotations.join.Join;
1111
import dev.rollczi.litecommands.annotations.execute.Execute;
12+
import dev.rollczi.litecommands.annotations.join.Join;
1213
import dev.rollczi.litecommands.annotations.permission.Permission;
13-
import dev.rollczi.litecommands.annotations.command.Command;
1414
import org.bukkit.Server;
1515
import org.bukkit.command.CommandSender;
16-
import org.bukkit.entity.Player;
1716

1817
@Command(name = "adminchat", aliases = "ac")
1918
@Permission("eternalcore.adminchat")
2019
class AdminChatCommand {
2120

21+
private static final String ADMIN_CHAT_SPY_PERMISSION = "eternalcore.adminchat.spy";
22+
2223
private final NoticeService noticeService;
2324
private final EventCaller eventCaller;
2425
private final Server server;
@@ -39,21 +40,18 @@ void execute(@Context CommandSender sender, @Join String message) {
3940
return;
4041
}
4142

43+
String eventMessage = event.getContent();
44+
4245
NoticeBroadcast notice = this.noticeService.create()
4346
.console()
4447
.notice(translation -> translation.adminChat().format())
4548
.placeholder("{PLAYER}", sender.getName())
46-
.placeholder("{TEXT}", message);
49+
.placeholder("{TEXT}", eventMessage);
4750

48-
for (Player player : this.server.getOnlinePlayers()) {
49-
if (!player.hasPermission("eternalcore.adminchat.spy")) {
50-
continue;
51-
}
52-
53-
notice = notice.player(player.getUniqueId());
54-
}
51+
this.server.getOnlinePlayers().stream()
52+
.filter(player -> player.hasPermission(ADMIN_CHAT_SPY_PERMISSION))
53+
.forEach(player -> notice.player(player.getUniqueId()));
5554

5655
notice.send();
5756
}
58-
5957
}

0 commit comments

Comments
 (0)