Implement a notification to an asyncplayerchatevent

Discussion in 'Spigot Plugin Development' started by JuanDouCore_, Jun 2, 2017.

  1. I have the following code with which I censor certain words that other players will say:
    Code (Text):

      public void alHablar(AsyncPlayerChatEvent e)
        String mensaje = e.getMessage();
        for (String listItem : this.listpalabras)
            if (e.getMessage().toLowerCase().contains(listItem)) {
    (I am new with this programming) then what I would like to do is give a notification to the players that have certain permission informing him that such player tries to say such thing
    If you help me I would thank you
  2. Try Bukkit.broadcast("Message","permissionString"); as it would send the message to everyone that has the permission.
  3. Mas


    This won't send to players who opped but don't explicitly have the permission. For this reason I find it is best to make a utility method to actually accomplish this.
  4. No, it does not work :/
  5. Mas


  6. An idea of a method?
  7. Mas


    Loop through Bukkit.getOnlinePlayers() and if the player is op (Player#isOp()) or the player has the desired permission (Player#hasPermission(String)) then send them the message.
  8. Or you set up a proper permission, which defaults to true for operators (either through plugin.yml, or registering it manually)
  9. @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
    String nocaps = e.getMessage().toLowerCase();
    for (String word : nocaps.split(" ")) {
    String NoSwear = "Do Not Swear!";
    String Swearer = e.getPlayer().getName();
    String Report = ChatColor.RED + Swearer + ", said: " + "word";
    Bukkit.getServer().broadcast(Report), "Test.Test"); //Everyone with Test.Test permission will recieve message

    This worked for me when i made my antiswear, you still need to make a array i nthe config named Badwords containing all your swear words