Solved Unsure of error

Discussion in 'Spigot Plugin Development' started by TecRyan, May 30, 2016.

Thread Status:
Not open for further replies.
  1. Hey,

    I am currently developing a plugin. I am making one that stops players using caps. I have started the code, tested it, but it doesn't work. I am not receiving any errors in the console. What have I done wrong?

    Here's the code: http://pastebin.com/s0u66DT9
     
  2. OMG, please, do not use == when you compare strings. It can be done like this: msg.equals(msg.toUpperCase())
     
    • Agree Agree x 1
  3. What you're doing will only work when the whole message is in CAPS.
    Lets says that I type "HELLO my NAME IS JAMES" in the chat... clearly thats caps but your plugin will only convert it to lowercase if the whole message is caps not just part of it.

    I'd personally count how many uppercase letters there are in the message and work out the percentage of uppercase letters then allow the server admin to set a percent in the config. If the percent of caps is equal to or grater than the percent in the config then convert the message to lowercase.
     
  4. Thanks, I'll test this out.
     
  5. Also, delete this, if you don't use it:

    public String uppercase;

    @SuppressWarnings("unused")
    private boolean isUppercase(String string) {
    return this.uppercase.contains(string)
    }
     
  6. And onEnable method mustn't have name "onEnable1"
    Rename to onEnable
     
  7. Gotcha! Thanks!
     
  8. That still doesn't solve the problem that I pointed out. #JustSayin'
     
  9. I see, thank you! Do you know how I would do it if I wanted to block it like "HELLO my NAME IS JAMES" without a config?
     
  10. Well if you wanted to convert all uppercase messages to lowercase (apart from the first letter) you could try something like this.
    Code (Text):
    e.setMessage(msg.toLowerCase().replaceFirst(msg.substring(0, 1), msg.substring(0, 1).toUpperCase()));
    HELLO my NAME IS JAMES! would be come Hello my name is james!.

    But there are more advanced ways of blocking caps that I would recommend checking out... there are others that have asked how to block caps before just take a look around the forums.
     
    • Informative Informative x 1
  11. You can count the percent of caps in the message like this, and, for example, if it more than 50, you can set all your message to lower case

    Code (Java):
            String s = "TEst";

            int count = 0;

            for(char c : s.toCharArray()) {
                if(c == Character.toUpperCase(c)) count++;
            }

            double percent = (100 * count) / s.length();
    P.S. You can use == for chars, but not for Strings
     
    • Informative Informative x 1
  12. Legend! Thank you sooo much!! :D
     
  13. Thanks :)
    If it's working fine for you now could you please post your working code? It just helps others with the same question as they can find how to do it here instead of making a new thread.
     
Thread Status:
Not open for further replies.