Thread: Help With Code (Should be easy)

Results 1 to 6 of 6
  1. #1 Help With Code (Should be easy) 
    Registered Member
    Join Date
    Aug 2015
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    I need to make it so when you type ::changepass you can't type anything after it that is 3 letters or less and if you do it will say "Password must be more than 3 characters." and it won't change the password.

    Code:
    			} else if (keyword.equals("changepass")) {
    				String pass = fullString;
    				setPassword(pass);// setPassword
    				getActionSender().sendMessage(
    						"Your new password is " + pass + ".");
    				// }
    			}
    Thanks a lot to whom helps!
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    Jun 2015
    Posts
    204
    Thanks given
    19
    Thanks received
    35
    Rep Power
    0
    Code:
    } else if (keyword.equals("changepass") && playerCommand.length() > 15 && playerCommand.length() < 3) {
    				String pass = fullString;
    				setPassword(pass);// setPassword
    				getActionSender().sendMessage(
    						"Your new password is " + pass + ".");
    				} else {
                                  c.sendMessage("Your passoword must be 3-15 characters")
       }
    			}
    This might be wrong just try it
    Reply With Quote  
     

  3. #3  
    Registered Member
    _Ali's Avatar
    Join Date
    Apr 2014
    Posts
    382
    Thanks given
    67
    Thanks received
    147
    Rep Power
    252
    Quote Originally Posted by SwedenRS View Post
    I need to make it so when you type ::changepass you can't type anything after it that is 3 letters or less and if you do it will say "Password must be more than 3 characters." and it won't change the password.

    Code:
    			} else if (keyword.equals("changepass")) {
    				String pass = fullString;
    				setPassword(pass);// setPassword
    				getActionSender().sendMessage(
    						"Your new password is " + pass + ".");
    				// }
    			}
    Thanks a lot to whom helps!
    Code:
    		
    } else if (keyword.equals("changepass")) {
    	String pass = fullString;
            if (pass.length() < 4) {
               getActionSender().sendMessage("Your password needs to be longer than 3 characters.");
               return;
            }
    	setPassword(pass);
    	getActionSender().sendMessage("Your new password is " + pass + ".");
    }
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Aug 2015
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Emporio Armani View Post
    Code:
    		
    } else if (keyword.equals("changepass")) {
    	String pass = fullString;
            if (pass.length() < 4) {
               getActionSender().sendMessage("Your password needs to be longer than 3 characters.");
               return;
            }
    	setPassword(pass);
    	getActionSender().sendMessage("Your new password is " + pass + ".");
    }
    This works thank you
    Reply With Quote  
     

  5. #5  
    ¯\_(ツ)_/¯


    Join Date
    Jul 2014
    Posts
    1,810
    Thanks given
    927
    Thanks received
    546
    Rep Power
    299
    Quote Originally Posted by SwedenRS View Post
    This works thank you
    Code:
    public String[] requiredChars = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
    
    boolean has = false;
    for (int k = 0; k < requiredChars.length; k++) {
    if (pass.contains(requiredChars[k])) {
    has = true;
    break;
    }
    
    if (!has) {
    c.sendMessage("You must have a number in your password");
    return;
    }
    Reply With Quote  
     

  6. #6  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,108
    Thanks given
    2,402
    Thanks received
    2,825
    Rep Power
    4604
    Quote Originally Posted by Bumhole View Post
    Code:
    public String[] requiredChars = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
    
    boolean has = false;
    for (int k = 0; k < requiredChars.length; k++) {
    if (pass.contains(requiredChars[k])) {
    has = true;
    break;
    }
    
    if (!has) {
    c.sendMessage("You must have a number in your password");
    return;
    }
    Holy shit, I've seen it all. You're better off determining the maximum length and comparing the length of the CharSequence to that value to determine if it's more or less.

    Code:
    private static final int MAXIMUM_CHARACTERS = 15;
    
    private static final int MINIMUM_CHARACTERS = 3;
    
    ...
    } else if (keyword.equals("changepass")) {
        length = fullString.length;
        if (length < MINIMUM_CHARACTERS) {
            sendMessage("...");
            return;
        }
        if (length > MAXIMUM_CHARACTERS) {
            sendMessage("...");
            return;
        }
        setPassword(fullString);
        sendMessage("...");
    }
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Command help [should be easy?
    By BLahVLah in forum Help
    Replies: 2
    Last Post: 12-24-2012, 10:31 PM
  2. Replies: 8
    Last Post: 04-03-2012, 07:52 PM
  3. Replies: 2
    Last Post: 02-18-2010, 03:05 PM
  4. should be easy to fix...
    By Gluon in forum Help
    Replies: 0
    Last Post: 02-14-2009, 09:48 PM
  5. Help with coding server.
    By martix in forum Help
    Replies: 2
    Last Post: 01-24-2009, 11:54 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •