-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Strokkur424
wants to merge
19
commits into
PaperMC:main
Choose a base branch
from
Strokkur424:feat/operation-argument
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b857329
Add ScoreHolder, Operation, Objective, and Team argument types
Strokkur424 ecf402d
work on more ScoreHolder uses
Machine-Maker ee61c6a
Fix Objective
Machine-Maker da338a9
more work
Machine-Maker 456057c
add string scoreholder toString
Machine-Maker a07fe48
Rename Operation to ScoreboardOperation
Strokkur424 825579d
Preallocate outgoing array
Strokkur424 c1ad0f7
Refactor objective argument resolver
Strokkur424 550ead7
Fix invalid JD
Strokkur424 5803263
Fix JD various JD
Strokkur424 6fdccc1
Fix even more JD
Strokkur424 b0bac75
Remove unused access wideners
Strokkur424 55189f8
Reduce size of team and objective file patches
Strokkur424 68d7aee
Replace deprecation with obsolete notices
Strokkur424 1eb84d1
Add missing @return javadocs annotation
Strokkur424 eb87d6a
fix: add missing nullability annotation
Strokkur424 4619d77
Rebase onto 1.21.11
Strokkur424 8dd96e0
bump version
Lulu13022002 54e5739
tweaks
Lulu13022002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../main/java/io/papermc/paper/command/brigadier/argument/operation/ScoreboardOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package io.papermc.paper.command.brigadier.argument.operation; | ||
|
|
||
| import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Represents a simple arithmetic operation between two integers. | ||
| * A {@link ScoreboardOperation} backs an operator. | ||
| * Most arithmetic operators (like {@code +=, -=, /=, etc.}) are | ||
| * supported, alongside certain conditional operators ({@code >=, <=, ==, etc.}). | ||
| * <p> | ||
| * Note that conditional operators, instead of yielding a boolean value, return the value | ||
| * that matches the operation. | ||
| * For example, the {@code <=} operator always returns the <strong>smaller</strong> value | ||
| * of two given values. | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @NullMarked | ||
| public interface ScoreboardOperation { | ||
|
|
||
| /** | ||
| * Applies this operation to a pair of integers. | ||
| * <p> | ||
| * Arithmetic between two integers always follows this pattern: | ||
| * <pre> | ||
| * return left <operator> right | ||
| * </pre> | ||
| * On certain operators, such as division, the order matters. | ||
| * {@code 20 %= 10} yields a different result than {@code 10 %= 20}. | ||
| * | ||
| * @param left left side of the expression | ||
| * @param right right side of the expression | ||
| * @return result of this operation | ||
| * @see Result | ||
| */ | ||
| Result apply(int left, int right) throws CommandSyntaxException; | ||
|
|
||
| /** | ||
| * Represents the result of a {@link ScoreboardOperation}. | ||
| * <p> | ||
| * For arithmetical operations (+=, -=, /=, *=), {@link #result()} will yield the mathemtical result. | ||
| * {@link #other()} will return the right input integer. | ||
| * <p> | ||
| * For any conditional operations or the swap operation, {@link #result()} will yield the left side | ||
| * and {@link #other()} will yield the right side of the operation. | ||
| */ | ||
| interface Result { | ||
|
|
||
| /** | ||
| * Get the left side of the result. | ||
| * | ||
| * @return result | ||
| */ | ||
| int result(); | ||
|
|
||
| /** | ||
| * Get the right side of the result. | ||
| * | ||
| * @return other | ||
| */ | ||
| int other(); | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
...rc/main/java/io/papermc/paper/command/brigadier/argument/resolvers/ObjectiveResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package io.papermc.paper.command.brigadier.argument.resolvers; | ||
|
|
||
| import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
| import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
| import io.papermc.paper.command.brigadier.argument.ArgumentTypes; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.scoreboard.Objective; | ||
| import org.bukkit.scoreboard.Scoreboard; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * A resolver that's capable of resolving | ||
| * an {@link Objective} value using a {@link Scoreboard} and {@link CommandSourceStack}. | ||
| * | ||
| * @see ArgumentTypes#objective() | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| @NullMarked | ||
| public interface ObjectiveResolver { | ||
|
|
||
| /** | ||
| * Resolves the argument with the given command source stack. | ||
| * <p> | ||
| * This method is the same as calling {@link #resolve(CommandSourceStack, Scoreboard, boolean)} with | ||
| * the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()} and {@code false}. | ||
| * | ||
| * @param sourceStack source stack | ||
| * @return resolved objective | ||
| */ | ||
| default Objective resolve(CommandSourceStack sourceStack) throws CommandSyntaxException { | ||
| return resolve(sourceStack, Bukkit.getScoreboardManager().getMainScoreboard(), false); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the argument with the given command source stack. | ||
| * <p> | ||
| * This method is the same as calling {@link #resolve(CommandSourceStack, Scoreboard, boolean)} with | ||
| * the provided scoreboard and {@code false}. | ||
| * | ||
| * @param sourceStack source stack | ||
| * @param scoreboard scoreboard to get the objective from | ||
| * @return resolved objective | ||
| */ | ||
| default Objective resolve(CommandSourceStack sourceStack, Scoreboard scoreboard) throws CommandSyntaxException { | ||
| return resolve(sourceStack, scoreboard, false); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the argument with the given command source stack. | ||
| * <p> | ||
| * This method is the same as calling {@link #resolve(CommandSourceStack, Scoreboard, boolean)} with | ||
| * the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()}. | ||
| * | ||
| * @param sourceStack source stack | ||
| * @param onlyWritable whether to only retrieve modifiable objectives | ||
| * @return resolved objective | ||
| */ | ||
| default Objective resolve(CommandSourceStack sourceStack, boolean onlyWritable) throws CommandSyntaxException { | ||
| return resolve(sourceStack, Bukkit.getScoreboardManager().getMainScoreboard(), onlyWritable); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the argument with the given command source stack. | ||
| * | ||
| * @param sourceStack source stack | ||
| * @param scoreboard scoreboard to get the objective from | ||
| * @param onlyWritable whether to only retrieve modifiable objectives | ||
| * @return resolved objective | ||
| */ | ||
| Objective resolve(CommandSourceStack sourceStack, Scoreboard scoreboard, boolean onlyWritable) throws CommandSyntaxException; | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
.../main/java/io/papermc/paper/command/brigadier/argument/resolvers/ScoreHolderResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package io.papermc.paper.command.brigadier.argument.resolvers; | ||
|
|
||
| import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
| import io.papermc.paper.command.brigadier.argument.ArgumentTypes; | ||
| import org.bukkit.scoreboard.ScoreHolder; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * An {@link ArgumentResolver} that's capable of resolving | ||
| * an argument value using a {@link CommandSourceStack} into a | ||
| * list of {@link ScoreHolder}s. | ||
| * | ||
| * @see ArgumentTypes#scoreHolders() | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| public interface ScoreHolderResolver extends ArgumentResolver<List<ScoreHolder>> { | ||
| } |
47 changes: 47 additions & 0 deletions
47
...api/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/TeamResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.papermc.paper.command.brigadier.argument.resolvers; | ||
|
|
||
| import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
| import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
| import io.papermc.paper.command.brigadier.argument.ArgumentTypes; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.scoreboard.Scoreboard; | ||
| import org.bukkit.scoreboard.ScoreboardManager; | ||
| import org.bukkit.scoreboard.Team; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * A resolver that's capable of resolving | ||
| * a {@link Team} value using a {@link Scoreboard} and {@link CommandSourceStack}. | ||
| * | ||
| * @see ArgumentTypes#team() | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| @NullMarked | ||
| public interface TeamResolver { | ||
|
|
||
| /** | ||
| * Resolves the argument with the given command source stack. | ||
| * <p> | ||
| * This method is the same as calling {@link #resolve(Scoreboard, CommandSourceStack)} with | ||
| * the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()}. | ||
| * | ||
| * @param sourceStack source stack | ||
| * @return resolved team | ||
| * @see #resolve(Scoreboard, CommandSourceStack) | ||
| * @see ScoreboardManager#getMainScoreboard() | ||
| */ | ||
| default Team resolve(CommandSourceStack sourceStack) throws CommandSyntaxException { | ||
| return resolve(Bukkit.getScoreboardManager().getMainScoreboard(), sourceStack); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the argument with the given scoreboard and command source stack. | ||
| * | ||
| * @param scoreboard scoreboard to get the team from | ||
| * @param sourceStack source stack | ||
| * @return resolved team | ||
| */ | ||
| Team resolve(Scoreboard scoreboard, CommandSourceStack sourceStack) throws CommandSyntaxException; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.