Thread: [PI] ::openshop [PI]

Results 1 to 6 of 6
  1. #1 [PI] ::openshop [PI] 
    Registered Member farmerscape's Avatar
    Join Date
    Jul 2010
    Posts
    165
    Thanks given
    16
    Thanks received
    0
    Rep Power
    5
    if (playerCommand.equalsIgnoreCase("openshop")) {
    String[] args = playerCommand.split(" ");
    if (args.length == 2) {
    int shopToOpen = Integer.parseInt(args[1]);
    c.getShops().openShop(shopToOpen);
    } else {
    c.sendMessage("Shop not found.");
    }
    }
    What's wrong with this? Compiled fine, but nothing happened when I used it. This is the first thing I've done from scratch so yeah...

    Edit:
    Tried this, still didn't work:
    if (playerCommand.equalsIgnoreCase("openshop")) {
    try {
    String[] args = playerCommand.split(" ");
    if (args.length == 2) {
    int shopToOpen = Integer.parseInt(args[1]);
    c.getShops().openShop(shopToOpen);
    } else {
    c.sendMessage("Shop not found.");
    }
    } catch(Exception e) {

    }
    }
    ~PROJECT FARMERSCAPE~

    - Hello i already add the ::item but now i want to add :: pickup command if someone can help me ?

    - We were all new before.. Help him!

    - We were all new, not stupid.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Core's Avatar
    Join Date
    Sep 2007
    Posts
    4,194
    Thanks given
    11
    Thanks received
    393
    Rep Power
    1985
    Code:
    if(playerCommand.startsWith("openshop")) {
        int shop = Integer.parseInt(playerCommand.substring(9));
        c.getShops().openShop(shop);
    }
    Reply With Quote  
     

  3. #3  
    Registered Member farmerscape's Avatar
    Join Date
    Jul 2010
    Posts
    165
    Thanks given
    16
    Thanks received
    0
    Rep Power
    5
    Quote Originally Posted by Core View Post
    Code:
    if(playerCommand.startsWith("openshop")) {
        int shop = Integer.parseInt(playerCommand.substring(9));
        c.getShops().openShop(shop);
    }
    Repped +

    Mind telling me what I had wrong?
    ~PROJECT FARMERSCAPE~

    - Hello i already add the ::item but now i want to add :: pickup command if someone can help me ?

    - We were all new before.. Help him!

    - We were all new, not stupid.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Core's Avatar
    Join Date
    Sep 2007
    Posts
    4,194
    Thanks given
    11
    Thanks received
    393
    Rep Power
    1985
    Well the main reason was
    Code:
    if (playerCommand.equalsIgnoreCase("openshop")) {
    The method equalsIgnoreCase in the String class only reads the words between the quotation marks.
    Code:
    if(playerCommand.startsWith("openshop")) {
    This just checks if the string starts with that.

    Also you shouldn't only use
    Code:
    playerCommand.split(" ");
    if you are using a command with multiple values like pickup or tele, if it is a command that only has one value like this, :penshop 1, then you use the substring method.
    Code:
    playerCommand.substring(COMMAND_LETTER_AMOUNT + SPACE(1));
    so if the command is
    Code:
    if(playerCommand.startsWith("height")) {
    then you use
    Code:
    String height = playerCommand.substring(7);
    7 because height is 6 letters + 1 from the space.
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Feb 2008
    Posts
    384
    Thanks given
    30
    Thanks received
    26
    Rep Power
    0
    I disagree with you, Core

    When you do
    Code:
    String[] cmd = playerCommand.split(" ");
    you are dividing the string by the space which would give you an array of strings. then for each for just
    Code:
    cmd[integer]
    So much easier than substring.

    also you should just use the

    Code:
    String[] cmd = playerCommand.split(" ");
    at the top and then you can use

    Code:
    cmd[0].equalsIgnoreCase("another string");
    imo its a lot easier.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Core's Avatar
    Join Date
    Sep 2007
    Posts
    4,194
    Thanks given
    11
    Thanks received
    393
    Rep Power
    1985
    Really no different, same exact outcome just using a different route.
    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

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