-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
2
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.
+668
−49
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,5 @@ aerulion <[email protected]> | |
Lukas Planz <[email protected]> | ||
granny <[email protected]> | ||
mja00 <[email protected]> | ||
Strokkur24 <[email protected]> | ||
``` |
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
57 changes: 57 additions & 0 deletions
57
paper-api/src/main/java/io/papermc/paper/command/brigadier/argument/operation/Operation.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,57 @@ | ||
package io.papermc.paper.command.brigadier.argument.operation; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import it.unimi.dsi.fastutil.ints.IntIntPair; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
/** | ||
* Represents a simple arithmetic operation between two integers. | ||
* An {@link Operation} 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 Operation { | ||
|
||
/** | ||
* 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 | ||
*/ | ||
IntIntPair apply(int left, int right) throws CommandSyntaxException; | ||
|
||
/** | ||
* 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 the left side of the result of this operation | ||
* @see #apply(int, int) | ||
*/ | ||
default int applyLeftSide(int left, int right) throws CommandSyntaxException { | ||
return apply(left, right).leftInt(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...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,66 @@ | ||
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(Scoreboard, CommandSourceStack)} with | ||
* the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()}. | ||
* | ||
* @param sourceStack source stack | ||
* @return resolved objective | ||
*/ | ||
default Objective resolve(CommandSourceStack sourceStack) throws CommandSyntaxException { | ||
return resolve(Bukkit.getScoreboardManager().getMainScoreboard(), sourceStack); | ||
} | ||
|
||
/** | ||
* 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 objective, whose criteria is writable | ||
*/ | ||
default Objective resolveWritable(CommandSourceStack sourceStack) throws CommandSyntaxException { | ||
return resolveWritable(Bukkit.getScoreboardManager().getMainScoreboard(), sourceStack); | ||
} | ||
|
||
/** | ||
* Resolves the argument with the given command source stack. | ||
* | ||
* @param scoreboard scoreboard to get the objective from | ||
* @param sourceStack source stack | ||
* @return resolved objective | ||
*/ | ||
Objective resolve(Scoreboard scoreboard, CommandSourceStack sourceStack) throws CommandSyntaxException; | ||
|
||
/** | ||
* Resolves the argument with the given command source stack. | ||
* | ||
* @param scoreboard scoreboard to get the objective from | ||
* @param sourceStack source stack | ||
* @return resolved objective, whose criteria is writable | ||
*/ | ||
Objective resolveWritable(Scoreboard scoreboard, CommandSourceStack sourceStack) 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#objective() | ||
*/ | ||
@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.
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.
Javadocs, what is an operation.
What are common usage patterns etc.
Operation also is a very broad name, idk if there a is a point in finding something more specific to what this is.
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.
This is more okay in internals, because this type lives purely as an inner type to OperationArgument.
But yea, on a top level, this doesn't mean much.
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.
Also experimental annotation
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.
@lynxplay do you perhaps have any idea what I could rename the
Operation
class to so that it makes more sense, even on a top level? I thought aboutIntegerOperation
,ScoreOperation
, or evenCommandOperation
, but all of these sounds misleading, so I am not fully happy about that yet