-
Notifications
You must be signed in to change notification settings - Fork 1
Real Brigadier Commands #64
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
Draft
The-Epic
wants to merge
5
commits into
dev
Choose a base branch
from
feat/brigadier-commands
base: dev
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.
Draft
Changes from all commits
Commits
Show all changes
5 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
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
108 changes: 108 additions & 0 deletions
108
pineapple-core/src/main/java/sh/miles/pineapple/command/AdvancedCommand.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,108 @@ | ||
| package sh.miles.pineapple.command; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.mojang.brigadier.arguments.ArgumentType; | ||
| import com.mojang.brigadier.context.CommandContext; | ||
| import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class AdvancedCommand { | ||
|
|
||
| private final CommandLabel label; | ||
| private final CommandSettings.Settings settings; | ||
| private final List<AdvancedCommand> subcommands; | ||
| private final Map<String, ArgumentType<?>> arguments; | ||
|
|
||
| /** | ||
| * Creates Command | ||
| * | ||
| * @param label label | ||
| * @param settings settings | ||
| * @since 1.0.0-SNAPSHOT | ||
| */ | ||
| public AdvancedCommand(@NotNull final CommandLabel label, @NotNull final CommandSettings.Settings settings) { | ||
| Preconditions.checkNotNull(label); | ||
| Preconditions.checkNotNull(settings); | ||
|
|
||
| this.label = label; | ||
| this.settings = settings; | ||
| this.subcommands = new ArrayList<>(); | ||
| this.arguments = new LinkedHashMap<>(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates Command | ||
| * | ||
| * @param label label | ||
| * @since 1.0.0-SNAPSHOT | ||
| */ | ||
| public AdvancedCommand(@NotNull final CommandLabel label) { | ||
| this(label, CommandSettings.DEFAULT_COMMAND_SETTINGS); | ||
| } | ||
|
|
||
| public void execute(@NotNull CommandContext<@NotNull CommandSourceStack> context) { | ||
| } | ||
|
|
||
| /** | ||
| * Register an argument for a command | ||
| * Use {@link io.papermc.paper.command.brigadier.argument.ArgumentTypes} for built-in or implement {@link ArgumentType} | ||
| * | ||
| * @param name argument name | ||
| * @param argumentType argument type | ||
| * @since 1.0.0-SNAPSHOT | ||
| */ | ||
| public void registerArgument(@NotNull String name, @NotNull ArgumentType<?> argumentType) { | ||
| this.arguments.put(name, argumentType); | ||
| } | ||
|
|
||
| /** | ||
| * Registers a command under this command. (sub-command) | ||
| * | ||
| * @param command the command to register | ||
| * @since 1.0.0-SNAPSHOT | ||
| */ | ||
| public void registerSubcommand(@NotNull AdvancedCommand command) { | ||
| this.subcommands.add(command); | ||
| } | ||
|
|
||
| public boolean canUse(CommandSender sender) { | ||
| return sender.hasPermission(label.getPermission()); | ||
| } | ||
|
|
||
| public CommandLabel getCommandLabel() { | ||
| return label; | ||
| } | ||
|
|
||
| public CommandSettings.Settings getSettings() { | ||
| return settings; | ||
| } | ||
|
|
||
| /** | ||
| * Get the subcommands | ||
| * | ||
| * @return the commands | ||
| * @since 1.0.0-SNAPSHOT | ||
| */ | ||
| @ApiStatus.Internal | ||
| public List<AdvancedCommand> getSubcommands() { | ||
| return new ArrayList<>(subcommands); | ||
| } | ||
|
|
||
| /** | ||
| * Get the arguments | ||
| * | ||
| * @return the commands | ||
| * @since 1.0.0-SNAPSHOT | ||
| */ | ||
| @ApiStatus.Internal | ||
| public Map<String, ArgumentType<?>> getArguments() { | ||
| return new LinkedHashMap<>(arguments); | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Uncomment to enable | ||
| // include(":test-plugin") |
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,23 @@ | ||
| plugins { | ||
| kotlin("jvm") | ||
| id("com.gradleup.shadow") | ||
| id("xyz.jpenilla.run-paper") version "2.3.1" | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly(libs.paper.api) | ||
| implementation(project(":pineapple-core")) | ||
| implementation(project(":pineapple-common")) | ||
| implementation(project(":pineapple-nms:api")) | ||
| } | ||
|
|
||
| tasks.runServer { | ||
| minecraftVersion("1.21.4") | ||
|
|
||
| workingDir = file("run") | ||
| systemProperty("net.kyori.adventure.text.warnWhenLegacyFormattingDetected", true) | ||
|
|
||
| doFirst { | ||
| workingDir.mkdirs() | ||
| } | ||
| } |
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.
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 would it feel to wrap CommandContext in this case? I feel like this API could be nicer if we served something "easier" Paper has a lot of these really annoying inbetween types, which if we wrap, we could resolve in a more "beautiful manner" Mainly what comes to my mind is any form of Registry entry or Location is absolutely annoying to resolve.
It's also nice because we know we'll always have a CommandSourceStack so we can chuck away that annoying generic too
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.
It depends on the info we actually end up needing from the context, we could technically use the arguments the command knows about to pass a CommandSourceStack with some form of argument collection, just depends on how we handle the generics on that collection
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.
Perhaps I'll try building something out this weekend and we see how we like it?
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.
Sounds good to me, lmk if there's any ideas you have that I could attempt