AntiCurse - String reading wrong

Discussion in 'Plugin Development' started by YoloSanta, May 28, 2017.

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

    YoloSanta

    Hey I was developing a plugin, and it's very basic when a player curses it cancels the message and sends them a message, but when I set the config for example,

    My config.yml
    Click Here

    My main class (only class)
    Click Here

    When I type one of the bad words in mc chat it says
    PHP:
    [Cursing is not allowed on this server!]
    ^How can I fix that^

    Also when I add a color code EX &c
    It removes the word for example when I do
    PHP:
    &cCursing is not allowed on this server!
    It shows up as
    Code:
    [is not allowed on this server]
    So those are the 2 problems I have.
     
    Last edited by a moderator: May 28, 2017
  2. Offline

    Zombie_Striker

    @YoloSanta
    1. I do not know what you are trying to fix; Do you not want that message to be sent when they curse?
    2. Use ChatColor.translateAlternateColorCodes(THE-MESSAGE) to change &c to a color code. This may fix the colorcode problem.
    3. BTW: You are continuing to loop even after a curse word has been found. If the player has two curse words in the post, two messages will be sent. Break out of the loop if a curse world has been found.
     
  3. Offline

    timtower Administrator Administrator Moderator

    @YoloSanta your warning message is a list. Turn it into a single string by removing the - and putting the string after the key.
     
  4. Offline

    YoloSanta

    I know you probably really dont want to spoon feed me this but where exactly do I insert that? I really just want to get over this.

    Would I need to add apostrophe on both sides of the message?
    PHP:
    package me.imanthe.plugins.anticurse;

    import java.util.List;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    @
    SuppressWarnings("unused")
    public class 
    Main extends JavaPlugin implements Listener
    {
      @
    EventHandler
      
    public void onPlayerChat(AsyncPlayerChatEvent e)
      {
        
    String[] arrayOfString;
        
    int j = (arrayOfString e.getMessage().split(" ")).length;
        for (
    int i 0ji++)
        {
          
    String word arrayOfString;
          if (
    getConfig().getStringList("badwords").contains(word))
          {
            
    e.setCancelled(true);
            
    e.getPlayer().sendMessage(getConfig().getString("warning"));
          }
        }
      }

      public 
    void onEnable()
      {
        
    getConfig().options().copyDefaults(true);
        
    saveConfig();
        
    Bukkit.getServer().getPluginManager().registerEvents(thisthis);
      }
    }
     
    Last edited: May 29, 2017
  5. Offline

    Zombie_Striker

    @YoloSanta
    Please don't use the center-format for your posts; your code is hard to read.

    Replace "The_String" with "getConfig().getString(....)"

    Yes, you will need to add apostrophes.
     
  6. Offline

    Caderape2

  7. Offline

    YoloSanta

    Fixed the format, but I need help with figuring out on where to insert the ChatColor.translateAlternateColorCodes(THE-MESSAGE) code, I'm not sure where it goes.
     
  8. Offline

    Zombie_Striker

     
  9. Offline

    YoloSanta

    I still get this error
    Click Here

    Also if it helps I have this class as a 2nd one
    Click Here
     
    Last edited: May 29, 2017
  10. Offline

    Zombie_Striker

    @YoloSanta
    Do not build your own color code class. Bukkit already has this with the translateAlternateColorCode method.

    The first hyper link directs to another forum post. Can you re-post the error you are getting?
     
  11. Offline

    YoloSanta

    Okay, I'll delete the class, but the first hyperlink and the second should both be redirected to an External link showing screenshots, of the underlined error
     
  12. Offline

    Caderape2

    @YoloSanta You need to tell the char to translate. ctrl + space while writing the method will show you what to do.
    Actaully it's the &
     
  13. Offline

    YoloSanta

  14. Offline

    Zombie_Striker

  15. Offline

    YoloSanta

    And what about arg0?
    Click Here
     
  16. Offline

    Zombie_Striker

    @YoloSanta
    Your code should look like:
    Code:
     e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',getConfig().getString("warning")));
     
Thread Status:
Not open for further replies.

Share This Page