Skip to content
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 @@ -38,6 +38,11 @@ public SendOnLogin sendOnLogin() {
return this.sendOnLogin;
}

private Chat chat = new Chat();
public Chat chat() {
return this.chat;
}

private Commands commands = new Commands();
public Commands commands() {
return this.commands;
Expand Down Expand Up @@ -105,6 +110,28 @@ public SendMode sendMode() {
}
}

@ConfigSerializable
public static class Chat {

@Comment("Enable chat filter")
private boolean enableAllowedChatPrefixes = false;
public boolean enableAllowedChatPrefixes() {
return this.enableAllowedChatPrefixes;
}

@Comment("Sets which messages players can send before they have logged in")
private List<String> allowedChatPrefixes = List.of(".l ", ".reg ", ".email ");
public List<String> allowedChatPrefixes() {
return this.allowedChatPrefixes;
}

@Comment("Sets the message to send to players who use messages that are not allowed. \\nLeave this option blank if you do not want the message to be sent.")
private String blockedChatMessage = "<red>You cannot send this message if you are not logged in yet";
public String blockedChatMessage() {
return this.blockedChatMessage;
}
}

@ConfigSerializable
public static class Commands {
@Comment("Sets the commands that users who have not yet logged in can execute")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.proxy.Player;
import io.github._4drian3d.authmevelocity.velocity.AuthMeVelocityPlugin;
import io.github._4drian3d.authmevelocity.velocity.listener.Listener;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.util.List;

public final class ChatListener implements Listener<PlayerChatEvent> {
@Inject
Expand All @@ -47,8 +51,26 @@ public EventTask executeAsync(final PlayerChatEvent event) {

plugin.logDebug(() -> "PlayerChatEvent | Player " + event.getPlayer().getUsername() + " is not logged");

if (plugin.config().get().chat().enableAllowedChatPrefixes()
&& !plugin.config().get().chat().allowedChatPrefixes().isEmpty()
&& isMessageAllowed(event.getMessage(), plugin.config().get().chat().allowedChatPrefixes())) {
plugin.logDebug(() -> "PlayerChatEvent | Allowed message: " + event.getMessage());
continuation.resume();
return;
}

plugin.logDebug(() -> "PlayerChatEvent | Blocked message: " + event.getMessage());
event.setResult(PlayerChatEvent.ChatResult.denied());
continuation.resume();
});
}

private boolean isMessageAllowed(String message, List<String> allowedPrefixes) {
for (String prefix : allowedPrefixes) {
if (message.startsWith(prefix)) {
return true;
}
}
return false;
}
}
Loading