pass args with dm open command - #259
Conversation
|
Hello @BlitzOffline , as you said i break down each change into its own PR, this one need to be accepted because default value is on top of this |
|
hello @BlitzOffline , what you think ? |
|
hi @BlitzOffline , any news ? |
|
Hi. I will take a look at this by the end of the week. |
this should respect command schema
|
what you think about this @BlitzOffline |
|
Hi. There's still a problem with this. the command can't tell the difference between a So this breaks Also, if an arg happens to start with My suggestion would be that we add a clear marker before |
|
dats a bettr idea. im on it |
|
this should do it @BlitzOffline , what you think |
| // Once -args: is seen, everything after it is taken as key=value pairs and | ||
| if (index < arguments.size() && arguments.get(index).equals(ARGS_MARKER)) { | ||
| index++; | ||
| menuArgs = new HashMap<>(); | ||
|
|
||
| for (int i = index; i < arguments.size(); i++) { | ||
| final String token = arguments.get(i); | ||
| final int equalsPos = token.indexOf('='); | ||
|
|
||
| if (equalsPos <= 0) { | ||
| // Malformed token (no "=" or starts with "="): skip rather than fail the command. | ||
| continue; | ||
| } | ||
|
|
||
| viewer = Bukkit.getPlayerExact(arguments.get(1)); | ||
| final String key = token.substring(0, equalsPos); | ||
| final String value = token.substring(equalsPos + 1); | ||
| menuArgs.put(key, value); | ||
| } | ||
| } | ||
|
|
||
| } else { | ||
| if (arguments.size() >= 3) { | ||
| if (!sender.hasPermission("deluxemenus.open.others")) { | ||
| plugin.sms(sender, Messages.NO_PERMISSION); | ||
| return; | ||
| } | ||
| Player viewer; |
There was a problem hiding this comment.
Arguments are parsed as key=value pairs, but menu arguments are positional values.
We should use the same parsing we already use everywhere else: the menu commands (/<menu-command> <args>) and the [openguimenu] <menu-name> [args] action — rather than introducing a second format here. Reference for the action:
added arguments to /dm open command so you can pass arguments for that player
like this:
/dm open punish_menu target -p:me arg1 arg2 arg3 ...
or
/dm open punish_menu target arg1 arg2 arg3 -p:me ...