Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
How do I turn off the chat for a specific player?

I am making a plugin where people can toggle the chat for themselves on the server.

What I have right now works pretty well:

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(@NotNull AsyncPlayerChatEvent e) {
    if(TOGGLED_USERS_BY_UUID.contains(e.getPlayer().getUniqueId().toString())) {
        e.setCancelled(true);
        e.getPlayer().sendRawMessage(ToggleChat.LANG.get("cannotChat"));
        return;
    }
    String message = e.getMessage();
    getLogger().info(String.format("<%s>: %s", e.getPlayer().getName(), message));
    e.setCancelled(true);
    for(Player p : getServer().getOnlinePlayers()) {
        if(!TOGGLED_USERS_BY_UUID.contains(p.getUniqueId().toString()))
            p.sendRawMessage(String.format("<%s> %s", e.getPlayer().getName(), message));
    }
}

But the problem comes when users have other things for their chat, such as a specific level for their chat message like (lvl) [username] - message or something.

How do I make it so that I don't have to re-send the message to users or just cancel the event for a specific user?

Thanks!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
    event.getRecipients().remove(/*player who shouldn't see chat*/);
}

If you want to filter players by their xp levels, you can use

getRecipients().removeIf(p -> p.getLevel() < minimumLevel)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda