Skip to content

Expose certain scoreboard related argument types #12541

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Strokkur424
Copy link
Contributor

@Strokkur424 Strokkur424 commented May 10, 2025

Closes #12540

This PR exposes a few scoreboard related Vanilla arguments for use in-API.

  • OperationArgument
  • ScoreHolderArgument
  • ObjectiveArgument There is no reason to expose the Vanilla one, as that one is just a wrapper around a string argument.

Operation Argument

Example usage: Implementing a simple /compute command. Preview:

image

Code:

Commands.literal("compute")
    .then(Commands.argument("left", IntegerArgumentType.integer())
        .then(Commands.argument("operation", ArgumentTypes.operation())
            .then(Commands.argument("right", IntegerArgumentType.integer())
                .executes(ctx -> {
                    int left = IntegerArgumentType.getInteger(ctx, "left");
                    int right = IntegerArgumentType.getInteger(ctx, "right");
                    Operation operation = ctx.getArgument("operation", Operation.class);

                    ctx.getSource().getSender().sendRichMessage("The result of <left> <operation> <right> is <result>!",
                        Placeholder.component("left", Component.text(left)),
                        Placeholder.unparsed("operation", ctx.getInput().split(" ")[2]),
                        Placeholder.component("right", Component.text(right)),
                        Placeholder.component("result", Component.text(operation.apply(left, right)))
                    );
                    return Command.SINGLE_SUCCESS;
                })
            )
        )
    )
    .build();

ScoreHolder Argument

Example usage Preview:

image

Code:

Commands.literal("testscoreholder")
    .then(Commands.argument("scoreholder", ArgumentTypes.scoreHolder())
        .executes(ctx -> {
            ScoreHolder firstHolder = ctx.getArgument("scoreholder", ScoreHolderResolver.class).resolve(ctx.getSource()).stream().findFirst().get();
            ctx.getSource().getSender().sendRichMessage("Found <holder>", Placeholder.unparsed("holder", firstHolder.getScoreboardName()));
            return 1;
        })
    )
    .build();

@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue May 10, 2025
@Strokkur424 Strokkur424 changed the title Add operation argument Expose certain scoreboard related argument types May 10, 2025
@Strokkur424 Strokkur424 marked this pull request as ready for review May 10, 2025 13:24
@Strokkur424 Strokkur424 requested a review from a team as a code owner May 10, 2025 13:24
Copy link
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

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

In general, I'll poke some other team members about this, so I'd wait a bit with implementing my feedback given how drastic it is.

* @throws IllegalArgumentException if entity is null
* @see #getScores(ScoreHolder)
*/
@NotNull Set<Score> getScoresFor(@NotNull ScoreHolder holder) throws IllegalArgumentException;
Copy link
Contributor

Choose a reason for hiding this comment

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

These methods are just copies from the ones above?
What is the point of these?

* @param targetHolder The target of the operation
* @param sourceHolder The source of the operation
*/
void apply(Scoreboard scoreboard, Objective targetObjective, Objective sourceObjective, ScoreHolder targetHolder, ScoreHolder sourceHolder) throws CommandSyntaxException;
Copy link
Contributor

@lynxplay lynxplay May 11, 2025

Choose a reason for hiding this comment

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

In general I am not much of a fan of this split between SimpleOperation and Operation internally.
apply(int, int) is only defined on simple operations. This makes it seem like it is universally applicable (which it isn't, CommandSyntaxException is thrown for the swap operation).

Having to pass all this BS just to construct a ScoreAccess also seems overkill.
Plugins will not be using scoreboards to store/modify their data.
I think we'd be better off on implementing ScoreAccess in our own type with a noop display name / override.
That way we can a) have apply(int, int) be always functional and simply return the "target", or "left" side here.
We could also expose an apply(int,int)Int2IntPair that yields both for people caring about swap.

This scoreboard/objective based method seems just very very useless/cumbersome to work with.

import org.jspecify.annotations.Nullable;

@NullMarked
public class OperationImpl implements Operation {
Copy link
Contributor

Choose a reason for hiding this comment

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

All the downsides mentioned in the API type apply here but review of this without changes to the API type is pretty useless.

import org.jspecify.annotations.NullMarked;

@NullMarked
public class CraftScoreHolder implements ScoreHolder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given I believe this requires a restructure, review of this isn't needed.

@github-project-automation github-project-automation bot moved this from Awaiting review to Changes required in Paper PR Queue May 11, 2025
@Strokkur424 Strokkur424 force-pushed the feat/operation-argument branch 2 times, most recently from 9838985 to 0b2ca4b Compare May 11, 2025 13:15
This commit is a squash and fixup commit of multiple previous commits. Fixed the JavaDocs and formatting.
@Strokkur424 Strokkur424 force-pushed the feat/operation-argument branch from 0b2ca4b to 4e0ae70 Compare May 11, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Changes required
Development

Successfully merging this pull request may close these issues.

Add Brigadier ArgumentType Support for Vanilla-style Operation Symbols (+=, *=, %=, etc)
2 participants