Hello, I have an issue with my plugin. I want to make it so when a message is more than 50% of CAPS, it will block the message. This is the code which I have at the moment: Code:java public static int getCapsSize(String[] args) { int CAPS = 0; for (int caps = 0; args.length > caps; caps++) { if (args.toString().substring(caps) == args.toString().substring(caps).toUpperCase()) caps++; CAPS = caps; } return CAPS; } This code only blocks CAPS if they are >= 2 arguments / words. I need it so it blocks CAPS for 1 argument/word too.
Just wondering why is it using "String [] args" rather than a single string? If it's to do with chat you would use an AsyncPlayerChatEvent and get the string from that, then Code:java if (getCapsSize(e.getMessage()) > e.getMessage() / 2) {e.setCancelled(true);} just change String[] args to String msg and in the for loops Code:java public static int getCapsSize(String msg) {int CAPS = 0;for (int caps = 0; msg.length() > caps; caps++) {if (msg.substring(caps, caps) == msg.substring(caps, caps).toUpperCase()) {CAPS ++;}return CAPS;}
First we get the message, let's call the string "mess". Then I'd create a new string variable and define it as "mess.toLowerCase()", let's call it "messlow". Now we create and integer called "differences". Now, I'd use a for loop and the getCharAt() method to get the letters at int "x" in both "mess" and "messlow", then compare them. If they are not equal, that means the characters are of a different case, so we add 1 to "differences". At the end, we check if "differences >= mess.length()/2" and if so, set the event as cancelled. PHP: StringBuilder stb = new StringBuilder();String mess = e.getMessage();String messlow = e.getMessage().toLowerCase();Integer differences = 0;for(int x = 0; x < mess.getLength(); x++){ if(mess.getCharAt(x) != messlow.getCharAt(x)){ differences++; }}if(differences >= mess.getLength()/2){ e.setCancelled(true);}