#Paper staff chat plugin issue

1 messages · Page 1 of 1 (latest)

pallid lintel
#

Hi, i have an issue with my paper staff chat plugin. The chat doesnt display messages and players who sent the message, though it displays the [staffchat] prefix.

I'll send my src and config in a sec
(im kinda new to minecraft plugins so don't yell at me lol)

heavy granite
#

your screenshot doesn't work

pallid lintel
#

ill fix lemme just

#


public class AsyncChatListener implements Listener {
  private Staffchat plugin;
  
  public AsyncChatListener(Staffchat plugin) {
    this.plugin = plugin;
  }
  
  @EventHandler
  public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    String message = event.getMessage();
    String FULL_MESSAGE = ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("settings.PREFIX").replace("{msg}", message).replace("{player}", player.getName()));
    String PERMISSION = ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("settings.PERMISSION"));
    if (this.plugin.scUsers.contains(player.getUniqueId())) {
      event.setCancelled(true);
      for (Player online : Bukkit.getOnlinePlayers()) {
        if (online.hasPermission(PERMISSION))
          online.sendMessage(FULL_MESSAGE); 
      } 
    } else if (!this.plugin.scUsers.contains(player.getUniqueId())) {
      event.setCancelled(false);
    } 
  }
}```
pallid lintel
#
# - {msg} -> Player Message
# - {player} -> Player Name

settings:
  ENABLED: '&9You have &a&lenabled &9staff chat.'
  DISABLED: '&9You have &c&ldisabled &9staff chat.'
  PERMISSION: ' {player}  {msg} '
  BE_A_PLAYER: please stop using the f*cking staff chat on console ok thx
  MISSING_PERMISSIONS: no perm lol                   
  PREFIX: '&8[&3Staff&8] '

ignore the stupid messages lol

edit: it might be the deprecated AsyncPlayerChatEvent, i'll try using AsyncChatEvent instead

heavy granite
#

AsyncPlayerChatEvent is not deprecated

#

erm what exactly is the problem? I don't quite get it

#

ah I see, [Staff] shows no message

pallid lintel
pallid lintel
heavy granite
#

maybe it is in paper, but this is spigot's discord

#

paper marks almost everything as deprecated

#

well your whole code is messed up

#

why do you cancel the event?

pallid lintel
heavy granite
#

you should much rather just change the event's format instead of cancelling the event

#

e.g. event.setFormat("[STAFF] %s");

pallid lintel
#

ill try doing that

heavy granite
#

instead of cancelling it and resending the message

#

you basically ONLY want to cancel the event if you want noone to see the message

#

to change the format etc, use setFormat

#

IIRC the first %s is the player name and the second %s is the message

#

so you can do something like this as general idea:

public void onChat(AsyncPlayerChatEvent event) {
  Player player = event.getPlayer();
  String prefix = ...; // get your prefix, e.g. "Staff", or "Member"
  event.setFormat("[" + prefix + "] %s > %s");
#

this will result in a chat like this:

[Member] mfnalex > Yo wassup
[Staff] Iki > Nothing