-
-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shortened Timespans (in commands) #6786
Shortened Timespans (in commands) #6786
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests
while (matcher.find()) { | ||
int value = Integer.parseInt(matcher.group(1)); | ||
char unit = matcher.group(2).charAt(0); | ||
|
||
switch (unit) { | ||
case 'd': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this handle 15doubles
?
|
||
while (matcher.find()) { | ||
int value = Integer.parseInt(matcher.group(1)); | ||
char unit = matcher.group(2).charAt(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern will pick up a match within a larger string (e.g. abc(1d)ef
) which is good if you want to extract multiple matches (like 1d 2h
) but will also pick up things it probably shouldn't (e.g. (10m)onths
).
You can either limit this to just one match of the entire input (using the ^ and $ start and end tokens) or you can use some logic to make sure it's not the start of a larger text (e.g. (?!\\w)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sovde told me to go a different route, and add shorter versions in the default.lang, and then let the parser handle it. Which i'll try to fix up and finish today, as i didnt have much time yesterday.
Description
Adds a Utility method to the Timespan class, where a timespan gets recognised in short form (1d, 1m, etc), and only works in the form of a command argument.
Target Minecraft Versions: any
Requirements: none
Related Issues: #6327