Skip to content
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

Closed

Conversation

Asleeepp
Copy link
Contributor

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

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests

Comment on lines +218 to +223
while (matcher.find()) {
int value = Integer.parseInt(matcher.group(1));
char unit = matcher.group(2).charAt(0);

switch (unit) {
case 'd':
Copy link
Member

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);
Copy link
Member

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).
image
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)).

Copy link
Contributor Author

@Asleeepp Asleeepp Jun 14, 2024

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.

@sovdeeth sovdeeth added enhancement Feature request, an issue about something that could be improved, or a PR improving something. up for debate When the decision is yet to be debated on the issue in question labels Jun 28, 2024
@Asleeepp Asleeepp closed this Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something. up for debate When the decision is yet to be debated on the issue in question
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants