Can't Use Banned Words List in Config File

Discussion in 'Plugin Development' started by AHarmlessKitten, Mar 27, 2014.

?

Should I also add a command that lets users list, add, or remove banned words ingame?

  1. Yes Yes and I'll help you learn how to make it

    50.0%
  2. Yes but I don't know how to help you learn to make it

    0 vote(s)
    0.0%
  3. No, thats too hard for you at the moment

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

    AHarmlessKitten

    I'm making a plugin that uses a list of banned words that it searches for in chat to punish players for using them. However, i want server owners to be able to configure these words but can't seem to pull more than one word from the config file at a time! Please help!

    Code:
    Code:java
    1. package me.ArrowSniped.insultsnomore;
    2.  
    3. import java.util.List;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Damageable;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.EventPriority;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.player.PlayerChatEvent;
    16. import org.bukkit.plugin.PluginDescriptionFile;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. @SuppressWarnings({ "deprecation", "unused" })
    20. public class InsultsNoMore extends JavaPlugin implements Listener {
    21. public final Logger logger = Logger.getLogger("Minecraft");
    22. public static InsultsNoMore plugin;
    23. String pt = "[InsultsNoMore] "; // The plugin tag to be put infront of messages
    24.  
    25. public void onDisable(){
    26. PluginDescriptionFile pdfFile = this.getDescription();
    27. this.logger.info(pdfFile.getName() + " has been disabled!");
    28. }
    29.  
    30. public void onEnable(){
    31. PluginDescriptionFile pdfFile = this.getDescription();
    32. this.logger.info(pdfFile.getName() + " has been enabled!");
    33. getServer().getPluginManager().registerEvents(this, this);
    34. getConfig().options().copyDefaults(true);
    35. saveConfig();
    36. }
    37.  
    38. @EventHandler(priority = EventPriority.NORMAL)
    39. public void onPlayerChat(PlayerChatEvent event){
    40. Player player = event.getPlayer();
    41.  
    42. if(player.hasPermission("InsultsNoMore.immune")){}else{
    43. if(event.getMessage().toLowerCase().contains(getConfig().getString("BannedWords"))){
    44. Damageable d = (Damageable) player;
    45. FileConfiguration cf = getConfig();
    46. int dmg = cf.getInt("DamageDone");
    47. String deathMessage = cf.getString("DeathMessage");
    48. // String bannedWords[] = {cf.getString("BannedWords")};
    49. double ch = d.getHealth();
    50. double nh = ch - dmg;
    51. if(nh <= 0){
    52. nh = 0;
    53. player.setHealth(nh);
    54. event.setMessage(deathMessage);
    55. } else {
    56. player.sendMessage(ChatColor.DARK_RED + pt + cf.getString("WarningMessage"));
    57. event.setMessage(cf.getString("ForcedMessage"));
    58. player.setHealth(nh);
    59.  
    60. }
    61. }
    62. }
    63. }
    64. }
    65.  


    Config:

    Code:
    #############################
    # Config For InsultsNoMore! #
    #############################
     
    # BannedWords:
    # These are the banned words, please use comas and a space in between words. (BETA BUILD, ONLY ONE WORD WILL WORK AT THE MOMENT)
    # EX: punk, kid, bad, butt
     
    # DamageDone:
    # This is the damage done per banned word said.
    # EX: 4
    # This will do 4 half hearts of damage or 2 full hearts
     
    # DeathMessage:
    # This is the death message, this will be forced out of their grimy "mouth" if they die from this plugin
    # EX: I was a dumbass for swearing!
     
    # WarningMessage
    # This warning message is whispered to the player when they use a banned word
    # EX: Cut the shit bub!
     
    # ForcedMessage
    # What the offending player's message is changed to once the plugin catches a banned word!
    # EX: Silly me, I can't just go around insulting people!
     
    BannedWords: faggot
     
    DamageDone: 6
     
    DeathMessage: I was a complete idiot for insulting myself to death!
     
    WarningMessage: You might not want to do that...
     
    ForcedMessage: I just tried to insult you, my bad!
     
  2. Offline

    Azubuso

    AHarmlessKitten
    Have "Banned Words" be a string list, then just iterate over it and check if the message contains any of the words in the list.
     
  3. Offline

    MrCodeMiner

    AHarmlessKitten
    Change:
    Code:
    BannedWords: faggot
    To:
    Code:
    BannedWords:
        - faggot
        - word2
        - word3
    I haven't tested this but I think that this should work.
     
  4. Offline

    AHarmlessKitten

    If I change getString("BannedWords") to getStringList("BannedWords") it claims that it all needs to be a char sequence.

    Azubuso
    See earlier post, forgot to tahg you

    NEVERMIND FOUND MY ANSWER HERE :D
    https://forums.bukkit.org/threads/problems-with-getstringlist.114890/

    Could still use some help with that pole question though if anyone is willing

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page