Creating an Anti-Swear Listener

May 16, 2021
Creating an Anti-Swear Listener
  • Download the Antiswear API by the #1 Antiswearing plugin ( )

    Code (Text):

    import java.util.List;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.permissions.Permission;
    import org.bukkit.configuration.file.FileConfiguration;

    //The Antiswear API classes
    import io.github.bswearteam.bswearapi.AntiswearAPI;

    Code (Text):


    // Put the imports from the 'Show java imports' button here!!!!

    * @Author The BSwear Team
    public class SwearBlocker implements Listener {

       public final Permission BYPASS_PERM = new Permission("bswear.bypass"); // If the user has this permission then the blocker will be canceled

       public void OnChat(AsyncPlayerChatEvent event) {
          Player player = event.getPlayer();
          if (!player.hasPermission(BYPASS_PERM)) {
             String msg = event.getMessage().toLowerCase().replaceAll("[-_*. ]", "");

             for (String words : getConfig().getStringList("words")) {
                 BlockWord(event, words); // Use this if you what to block just that word in the chat msg
                 BlockMessage(event, words); // Use this if you what to block the whole chat msg with that word
                 ReplaceWord(event, words, "text to replace the word with"); // Use this if you what to replace the word in the chat with an new one

  • Loading...
  • Loading...