Giter Site home page Giter Site logo

Help Search about multiverse-core HOT 5 CLOSED

multiverse avatar multiverse commented on June 12, 2024
Help Search

from multiverse-core.

Comments (5)

AkiTensai avatar AkiTensai commented on June 12, 2024

Option 1: Search text is only ever a single word. Page number set second.
Con: goes against what the current system uses of int after help.

//To handle the following:
///mv help
///mv help [text]
///mv help [text] [number]
//where [Text] is a string without spaces and [number] is an int or treated as 1 when invalid.

String sSearchTerm;
int iPage;

if (args.size() == 0)
{
    sSearchTerm = "";
    iPage = 1;            
} else if (args.size() == 1) {
    sSearchTerm = args.get(1);
    iPage = 1;
} else if (args.size() == 2) {
    sSearchTerm = args.get(1);
    try {
         iPage = args.get(2);
    }
    catch (NumberFormatException ex) {
        iPage = 1;
    }
}

//At this point, iPage and sSearchTerm are set.
//[Insert search for relevant return results.  

from multiverse-core.

AkiTensai avatar AkiTensai commented on June 12, 2024

Option 2: Search text may be more then one word.
I don't know the syntax for getting the array of args for the foreach. From what I've read, the continue should be correctly written.

//To handle the following:
///mv help
///mv help [number]
///mv help [number] [text]
///mv help [text]
//where [Text] is a string that may contain spaces and [number] is an int or treated as 1 when invalid.

String sSearchTerm;
int iPage;
boolean isPageProvided = false;

if (args.size() == 0)
{
    sSearchTerm = "";
    iPage = 1;            
} else {

    //Get the page number.  If it is a string, then it is a search
    //term and paging defaults to first page.
    try {
         iPage = args.get(0);
         isPageProvided = true;
    }
    catch (NumberFormatException ex) {
        iPage = 1;
        isPageProvided = false;
    }

    //Bring all of the search terms together, skipping the page number if
    //it was provided.
    boolean isFirstArg = true;
    for(string sArg = args.getarray())
    {
        if(isFirstArg) {
            isFirstArg = false;

            if(isPageProvided) {
                //When page is provided, skip the first arg, as it a number
                //instead of a search term.
                continue;
            }
        } else {
            //Each additional search term needs spaced from the last.
            sSearchTerm += " ";
        }
        sSearchTerm += sArg;
    }

}

//At this point, iPage and sSearchTerm is set and ready to go.

from multiverse-core.

fernferret avatar fernferret commented on June 12, 2024

Ah yea, I was quite tired last night. If you look at the Info Command one of the params is WORLD, which if not provided is determined IF the sender was a player. That's why it was hairy... Since you've basically done all the work... I'll go add this tonight!

from multiverse-core.

AkiTensai avatar AkiTensai commented on June 12, 2024

Updated the comment. I was using base 1 instead of base 0 for the args.

//Was
iPage = args.get(1);

//Now
iPage = args.get(0);

If you ever want help hammering out variable validations from commands, ping me.

from multiverse-core.

fernferret avatar fernferret commented on June 12, 2024

Finished in: dbdc6d9

from multiverse-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.