Help me pls

Discussion in 'Plugin Development' started by Walruski, Jul 6, 2014.

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

    Walruski

    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
    1. public static int getCapsSize(String[] args) {
    2. int CAPS = 0;
    3. for (int caps = 0; args.length > caps; caps++) {
    4. if (args.toString().substring(caps) == args.toString().substring(caps).toUpperCase())
    5. caps++;
    6. CAPS = caps;
    7. }
    8. return CAPS;
    9. }

    This code only blocks CAPS if they are >= 2 arguments / words. I need it so it blocks CAPS for 1 argument/word too.
     
  2. Offline

    61352151511

    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
    1. if (getCapsSize(e.getMessage()) > e.getMessage() / 2) {
    2. e.setCancelled(true);
    3. }



    just change String[] args to String msg and in the for loops

    Code:java
    1. public static int getCapsSize(String msg) {
    2. int CAPS = 0;
    3. for (int caps = 0; msg.length() > caps; caps++) {
    4. if (msg.substring(caps, caps) == msg.substring(caps, caps).toUpperCase()) {
    5. CAPS ++;
    6. }
    7. return CAPS;
    8. }
     
  3. Offline

    mine-care

    And why static :3
     
  4. Offline

    JBoss925

    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 0mess.getLength(); x++){
        if(
    mess.getCharAt(x) != messlow.getCharAt(x)){
            
    differences++;
        }
    }
    if(
    differences >= mess.getLength()/2){
        
    e.setCancelled(true);
    }
     
Thread Status:
Not open for further replies.

Share This Page