TabComplete Engine

TabComplete Engine 1.4

Denizen Version
1.2.0
Tired of having to figure out how to write a good tab complete script for your new fancy command script? With this procedure script you just have to provide the structure of the command and let the script do the work for you.

As an example, lets set up a warp command as so
Code:
WarpTabComplete:
    type: data
    warps:
        set: end
        remove:
            _warp: end
        goto:
            spawn: end
            _warp: end
where each indent level indicates the allowed argument at that position. adding a _ at the start of a parameter indicates default parameter. this will ignore the actual input and will allow any input (as a result you should only have one _ line per level)

but what if you want more parameters that are dynamic and not just static names? You can define extra procedure scripts to be executed at that parameter.
For instance
Code:
/warps goto (warp)
we know all the valid warps we can go to since its all stored in a server flag so we should add a * in between _ and warp and define a procedure script as such
Code:
WarpTabComplete:
    type: data
    warps:
        set: end
        remove:
            _*warp: end
        goto:
            _*warp: end
WarpTabComplete_warp:
    type: procedure
    script:
        - determine <server.flag[warps]>
And thats it. Only thing to keep in mind the name of the procedure must be NameofContainer_PamaterName.
The script will pass in all the previous arguments the player had typed in already as context to the procedure.
For instance for
Code:
/warp remove (warp)
we never want to allow the player to remove the spawn warp, instead of writing a whole new procedure we can define the procedure as such
Code:
WarpTabComplete_warp:
    type: procedure
    definitions: arg
    script:
        - define warps:|:<server.flag[warps]>
        - if <[arg]> == remove:
            - define warps:<-:spawn
        - determine <[warps]>
This will mean though, if you only care about the 3rd argument, you would need to define the first 2 in the definitions key of the procedure script.


Now what about permissions? you may be wondering. Granted you can show off all those fancy options only admins get to use but you do have the option to permission lock branches. For instance we want only users with the warps.admin permission to be able to use /warps set and /warps remove. The result would be as such:
Code:
WarpTabComplete:
    type: data
    warps:
        ?warps.admin set: end
        ?warps.admin remove:
            _*warp: end
        goto:
            _*warp: end
WarpTabComplete_warp:
    type: procedure
    script:
        - determine <server.flag[warps]>
Thats it. All you have to do is insert ?(permission node) at the front of a branch to permission lock it. You are unable to lock default branches (ones that start in _). You can just check for permissions in the procedure script at that point if you need it.
After you have set it up, all you need to type in your tab complete section is
Code:
- determine <proc[TabComplete].context[<list[commandName|ConatinerName].include_single[<context.raw_args>]>]>

for instance with our warp command, this is what the script could look like
Code:
warpcommand:
    type: command
    name: warps
    description: warp to another location
    usage: /warps
    tab complete:
        - determine <proc[TabComplete].context[<list[warps|WarpTabComplete].include_single[<context.raw_args>]>]>
    script:
        #my code

Note: as a reminder, this is all for tab completion and does not impact the actual script of the command script. You do still need to do that part yourself
Author
zozer_firehood
Downloads
1,168
Views
1,564
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from zozer_firehood

Share this resource

Latest updates

  1. Minor bug fix

    fix bug where it would break if user kept typing past the end fix bug of it breaking if user...
  2. Minor bug fix to minor bug fix

    previous bug fix was not complete, this now works
  3. Minor bug fix

    permissions get escaped when parsing the data, make sure that it checks against unescaped...