Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Oct 9, 2021
1 parent 7650c2a commit f3ea7a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.dreamerzero.ClientCatcher</groupId>
<artifactId>ClientCatcher</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.dreamerzero.clientcatcher.commands;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -19,7 +18,7 @@ public class ClientCommand implements SimpleCommand {
private final ProxyServer server;
private Yaml config;
private MiniMessage mm;
public ClientCommand(ProxyServer server, Yaml config) {
public ClientCommand(ProxyServer server, Yaml config) {
this.server = server;
this.config = config;
this.mm = MiniMessage.miniMessage();
Expand Down Expand Up @@ -83,13 +82,7 @@ public void execute(final Invocation invocation) {

@Override
public List<String> suggest(final Invocation invocation) {
List<String> players = new ArrayList<>();
var allplayers = server.getAllPlayers();
for (Player player : allplayers) {
String playername = player.getUsername();
players.add(playername);
}
return players;
return server.getAllPlayers().stream().limit(30).map(player -> player.getUsername()).toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void onPlayerJoin(final PostLoginEvent event) {
final Player player = event.getPlayer();
broadcastToOp = config.getBoolean("settings.broadcast-alert-to-op");
delay = config.getLong("settings.check-delay");
List<String> blockedClients = config.getStringList("settings.blocked-clients");

// The client sends the client brand seconds after logging in,
// so you should wait a few seconds before trying to get it.
Expand All @@ -53,7 +52,7 @@ public void onPlayerJoin(final PostLoginEvent event) {
Audience ops = Audience.audience(Audience.audience(
server.getAllPlayers().stream().filter(
user -> user.hasPermission("clientcatcher.notifications")).toList()),
server.getConsoleCommandSource());
server.getConsoleCommandSource());

if (client.isEmpty() && config.getBoolean("settings.show-null-client-message")) {
server.getConsoleCommandSource().sendMessage(mm.parse(
Expand All @@ -64,24 +63,22 @@ public void onPlayerJoin(final PostLoginEvent event) {

templates.add(Template.of("client", client.get()));

for(String blockedClient : blockedClients){
if(client.get().contains(blockedClient)){
player.disconnect(mm.parse(
if(config.getStringList("settings.blocked-clients")
.stream().anyMatch(blockedClient -> client.get().contains(blockedClient))){
player.disconnect(mm.parse(
config.getString("messages.client-disconnect-message"), templates));
return;
}
}

if(player.getModInfo().isPresent()){
player.getModInfo().get().getMods().forEach(mod -> {
config.getStringList("settings.blocked-mods").forEach(blockedMod -> {
if(mod.getId().contains(blockedMod)){
player.disconnect(mm.parse(
config.getString("messages.mods-disconnect-message"), templates));
return;
}
});
});
if(player.getModInfo().get().getMods().stream()
.anyMatch(mod -> config.getStringList("settings.blocked-mods")
.contains(mod.getId()))){

player.disconnect(mm.parse(
config.getString("messages.mods-disconnect-message"), templates));
return;
}
templates.add(Template.of("mods", player.getModInfo().get().getMods().toString()));
if(broadcastToOp){
ops.sendMessage(mm.parse(
Expand Down

0 comments on commit f3ea7a3

Please sign in to comment.