Anti Swear Config

Discussion in 'Plugin Development' started by CaptainXD, Mar 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    CaptainXD

    So pretty much I am making an anti-swear plugin. Simple right? XD
    I have the listener set up and everything, but I am wondering how I can get a list of data (swear words lol) imported into my plugin. Otherwise, I will have to do a long, tedious, "if" statement that has

    stringContains "F***" || stringContains "S***"

    etc, etc, etc.

    Thanks guys
     
  2. Offline

    chasechocolate

    Code:java
    1. for(String word : this.getConfig().getStringList("swearwords")){
    2. if(msg.contains(word)){
    3. //There is a swear word
    4. }
    5. }
     
    CaptainXD likes this.
  3. Offline

    CaptainXD

    Thanks a bunch. I want to have it temp-ban after repeated attempts. How would I implement this (3 warnings, then tempban)

    Thanks! Also, how do you get the text all formatted for java on the forums like you did??
     
  4. Offline

    chasechocolate

    CaptainXD
    Code:
    [syntax=java]code[/syntax]
     
  5. Offline

    CaptainXD

    So, one more thing. I was messing around with the bit of code you gave me, and it said "The method getConfig() is undefined for the type SwearListener"
    Here is my code:

    Code:java
    1.  
    2. package me.CaptainXD.iTitanium;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerChatEvent;
    9.  
    10. @SuppressWarnings("deprecation")
    11. public class SwearListener implements Listener {
    12. @EventHandler
    13. public void onSwear(PlayerChatEvent event) {
    14.  
    15. Player player = event.getPlayer();
    16.  
    17. for(String word : this.getConfig().getStringList("SwearWords")){
    18. if(event.getMessage().toLowerCase().contains(word)) {
    19. event.setCancelled(true);
    20. event.getPlayer().kickPlayer("Swearing is " + ChatColor.DARK_RED + "NOT" + ChatColor.GRAY + " allowed");
    21. //There is a swear word
    22. }
    23. }
    24. }
    25. }
    26.  


    Does the fact that the config is empty trigger this? Or is it something else? Thanks
     
  6. Offline

    Rhino390

    Sorry to jump in on a random topic, but i think i see whats wrong with it. I believe you need to add a constructor to your listener class, so you can get methods such as getConfig(), getServer(), etc..., out of your main class. Here's the code:
    Code:java
    1.  
    2. public nameOfMainClass plugin;
    3.  
    4. public void nameOfYourListener(nameOfMainClass i) {
    5. i = plugin;
    6. }
    7.  

    Then just use plugin.getConfig(), plugin.getServer(), or for any other methods you need. Hope this helps! :)
     
  7. Offline

    Compressions

    CaptainXD Learn some very basic Java before jumping into a plugin. I recommend using the Bukkit Wiki.
     
  8. Offline

    Hitechwizard

    We developed our Swear.jar for Drewpercraft about two years ago. It lets you manage the swear words and implements a smart filter to keep the potty mouths from using punctuation, spacing, etc to avoid exact matches, while also allowing you to whitelist words like assassin.

    Source.Jar can be downloaded from http://www.drewpercraft.com/index.php?board=11.0

    Hitechwizard
     
Thread Status:
Not open for further replies.

Share This Page