Solved Problem with my AntiSwear plugin.

Discussion in 'Plugin Development' started by Kody_Jay, Oct 21, 2016.

Thread Status:
Not open for further replies.
  1. I have made an antiswear plugin, as I was learning from Pogo, but there is a crucial error that I cannot seem to fix, if you type a certain letter, for example, 'U' it blocks it, thinking you're swearing. Here is my code:
    Code:
    package me.kody_jay.montrealcraftantiswear;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e) {
            for (String word : e.getMessage().split(" ")) {
                if (getConfig().getString("blockedwords").contains(word.toLowerCase())) {
                    e.setCancelled(true);
                    e.getPlayer().sendMessage("§8[§dMontreal§fCraft§8] §cPlease do not curse.");
                    return;
                }
            }
        }
       
    }
    Here is my plugin.yml:
    Code:
    name: MontrealCraftAntiSwear
    version: 1.0
    main: me.kody_jay.montrealcraftantiswear.Main
    description: Blocks all cursing
    author: Kody_Jay
    I would post my config.yml but it consists of bad words of which isn't allowed to be posted.
    Thank you for taking the time to read this.
     
  2. Offline

    RenditionsRule

    @Kody_Jay
    Why aren't you using a string list? Currently, you're looping through all the words they say, and then checking if one string in the config, contains them. This is definitely the cause of the error, because if that string contained a word like "Alphabet", all the letters used in that word would not be able to be typed individually.
     
  3. Offline

    Zombie_Striker

    @Kody_Jay
    Change your one String to a List of Strings. After that , check if the List contains the banned word.
     
  4. Offline

    Zombie_Striker

    @Kody_Jay
    1. Wherever you save the blacklist string, change it to a List. If you manually put in the string, add a bit to your plugin so it saves over your String with a new List.
    2. Make sure the String in the config is now a List.
    3. Re-add all the words to the list.
    4. Change all the lines that have "config.getString()" to "config.getStringList()"
     
  5. Offline

    RenditionsRule

    Personally, I'd use RegEx to match the swears and filter them correctly. "AntiSwear" plugins that uses contains() tend to have glitches/bugs.
     
  6. Offline

    mythbusterma

    @RenditionsRule

    I don't see how and regular expression would work better, certainly be harder to write.

    All "anti swear" plugins are equally worthless, in my opinion. They do nothing.
     
Thread Status:
Not open for further replies.

Share This Page