Repository navigation
Add helper methods for vanilla-style command feedback #14331
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
35129eb
033263f
55f3592
05f3801
f1a5d1f
e086eba
24b8acd
5339b2d
c217fb8
f4479ae
8f03253
e98d48c
eb68e6c
64891cb
238c370
3e15338
2880b2a
9294d7c
ebce958
73822d7
07b5445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
| import com.mojang.brigadier.RedirectModifier; | ||
| import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
| import com.mojang.brigadier.tree.CommandNode; | ||
| import net.kyori.adventure.text.ComponentLike; | ||
| import net.kyori.adventure.text.minimessage.MiniMessage; | ||
| import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; | ||
| import org.bukkit.GameRules; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Entity; | ||
|
|
@@ -81,4 +85,119 @@ public interface CommandSourceStack { | |
| * @see com.mojang.brigadier.builder.ArgumentBuilder#fork(CommandNode, RedirectModifier) | ||
| */ | ||
| CommandSourceStack withExecutor(Entity executor); | ||
|
|
||
| /** | ||
| * Sends a system message to the {@link #getExecutor()} if it is a {@link Player}, | ||
| * otherwise sends a system message to the {@link #getSender()}. | ||
| * | ||
| * @param message the message to send | ||
| */ | ||
| void sendReply(ComponentLike message); | ||
|
|
||
| /** | ||
| * Sends a system message with the MiniMessage format to the {@link #getExecutor()} | ||
| * if it is a {@link Player}, otherwise sends it to the {@link #getSender()}. | ||
| * | ||
| * <p>See <a href="https://docs.advntr.dev/minimessage/">MiniMessage docs</a> and | ||
| * <a href="https://docs.advntr.dev/minimessage/dynamic-replacements">MiniMessage Placeholders docs</a> | ||
| * for more information on the format.</p> | ||
| * | ||
| * @param message the MiniMessage message to send | ||
| * @param resolvers resolvers to use | ||
| */ | ||
| default void sendRichReply(String message, TagResolver... resolvers) { | ||
| sendReply(MiniMessage.miniMessage().deserialize(message, resolvers)); | ||
| } | ||
|
|
||
| /** | ||
| * Sends a system message to the {@link #getSender()}, admins, and console indicating successful command execution | ||
| * according to vanilla semantics. | ||
| * | ||
| * <p>This currently includes checking for environments with suppressed output, | ||
| * {@link GameRules#SEND_COMMAND_FEEDBACK}, and {@link GameRules#LOG_ADMIN_COMMANDS}.</p> | ||
| * | ||
| * @param message the message to send | ||
| * @param allowInformingAdmins whether admins and console may be informed of this success | ||
| */ | ||
| void sendSuccess(ComponentLike message, boolean allowInformingAdmins); | ||
|
|
||
| /** | ||
| * Sends a system message to the {@link #getSender()}, admins, and console indicating successful command execution | ||
| * according to vanilla semantics. This method informs admins and the console of this success. | ||
| * | ||
| * <p>This currently includes checking for environments with suppressed output, | ||
| * {@link GameRules#SEND_COMMAND_FEEDBACK}, and {@link GameRules#LOG_ADMIN_COMMANDS}.</p> | ||
| * | ||
| * @param message the message to send | ||
| * @see #sendSuccess(ComponentLike, boolean) to disable if admins and console should be informed | ||
| */ | ||
| default void sendSuccess(ComponentLike message) { | ||
| sendSuccess(message, true); | ||
|
Strokkur424 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * Sends a system message with the MiniMessage format to the {@link #getSender()}, admins, and console indicating | ||
| * successful command execution according to vanilla semantics. | ||
| * | ||
| * <p>This currently includes checking for environments with suppressed output, | ||
| * {@link GameRules#SEND_COMMAND_FEEDBACK}, and {@link GameRules#LOG_ADMIN_COMMANDS}.</p> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can extend a little this? (where this is mentioned) maybe can be to much info but the logic for admins and console... its like
but maybe its to much info for this... and maybe can be just a mention in the docs rather than here (?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've spent some time thinking about how one could properly word this, and I have come to the evaluation that I think the current paragraph for this is already good enough. Generally, I think it's logical that command feedback is only sent for players with the relevant permission (the docs have that permission documented, albeit the description is outdated). |
||
| * | ||
| * <p>See <a href="https://docs.advntr.dev/minimessage/">MiniMessage docs</a> and | ||
| * <a href="https://docs.advntr.dev/minimessage/dynamic-replacements">MiniMessage Placeholders docs</a> | ||
| * for more information on the format.</p> | ||
| * | ||
| * @param message the MiniMessage message to send | ||
| * @param allowInformingAdmins whether admins and console may be informed of this success | ||
| * @param resolvers resolvers to use | ||
| */ | ||
| default void sendRichSuccess(String message, boolean allowInformingAdmins, TagResolver... resolvers) { | ||
|
Strokkur424 marked this conversation as resolved.
Outdated
|
||
| sendSuccess(MiniMessage.miniMessage().deserialize(message, getSender(), resolvers), allowInformingAdmins); | ||
| } | ||
|
|
||
| /** | ||
| * Sends a system message with the MiniMessage format to the {@link #getSender()}, admins, and console indicating | ||
| * successful command execution according to vanilla semantics. This method informs admins and the console of | ||
| * this success. | ||
| * | ||
| * <p>This currently includes checking for environments with suppressed output, | ||
| * {@link GameRules#SEND_COMMAND_FEEDBACK}, and {@link GameRules#LOG_ADMIN_COMMANDS}.</p> | ||
| * | ||
| * <p>See <a href="https://docs.advntr.dev/minimessage/">MiniMessage docs</a> and | ||
| * <a href="https://docs.advntr.dev/minimessage/dynamic-replacements">MiniMessage Placeholders docs</a> | ||
| * for more information on the format.</p> | ||
| * | ||
| * @param message the MiniMessage message to send | ||
| * @param resolvers resolvers to use | ||
| * @see #sendSuccess(ComponentLike, boolean) to disable if admins and console should be informed | ||
| */ | ||
| default void sendRichSuccess(String message, TagResolver... resolvers) { | ||
| sendRichSuccess(message, true, resolvers); | ||
| } | ||
|
|
||
| /** | ||
| * Sends a system message indicating a failed command execution to the {@link #getSender()}. | ||
| * Does not apply red styling to the message as vanilla does to allow for custom failure message styling. | ||
| * | ||
| * <p>Respects vanilla semantics for accepting failure output and suppressed output environments.</p> | ||
| * | ||
| * @param message the message to send | ||
| */ | ||
| void sendFailure(ComponentLike message); | ||
|
|
||
| /** | ||
| * Sends a system message with the MiniMessage format indicating a failed command execution to the{@link #getSender()}. | ||
| * Does not apply red styling to the message as vanilla does to allow for custom failure message styling. | ||
| * | ||
| * <p>Respects vanilla semantics for accepting failure output and suppressed output environments.</p> | ||
| * | ||
| * <p>See <a href="https://docs.advntr.dev/minimessage/">MiniMessage docs</a> and | ||
| * <a href="https://docs.advntr.dev/minimessage/dynamic-replacements">MiniMessage Placeholders docs</a> | ||
| * for more information on the format.</p> | ||
| * | ||
| * @param message the MiniMessage message to send | ||
| * @param resolvers resolvers to use | ||
| */ | ||
| default void sendRichFailure(String message, TagResolver... resolvers) { | ||
| sendFailure(MiniMessage.miniMessage().deserialize(message, getSender(), resolvers)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; | ||
| import com.google.common.base.Preconditions; | ||
| import io.papermc.paper.adventure.PaperAdventure; | ||
| import net.kyori.adventure.text.ComponentLike; | ||
| import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
| import net.minecraft.world.level.Level; | ||
| import net.minecraft.world.phys.Vec2; | ||
|
|
@@ -49,6 +51,24 @@ default CommandSourceStack withExecutor(Entity executor) { | |
| return this.getHandle().withEntity(((CraftEntity) executor).getHandle()); | ||
| } | ||
|
|
||
| @Override | ||
| default void sendReply(final ComponentLike message) { | ||
| Preconditions.checkNotNull(message, "message cannot be null."); | ||
|
Strokkur424 marked this conversation as resolved.
Outdated
|
||
| this.getHandle().sendSystemMessage(PaperAdventure.asVanilla(message.asComponent())); | ||
| } | ||
|
|
||
| @Override | ||
| default void sendSuccess(final ComponentLike message, final boolean allowInformingAdmins) { | ||
| Preconditions.checkNotNull(message, "message cannot be null."); | ||
| this.getHandle().sendSuccess(() -> PaperAdventure.asVanilla(message.asComponent()), allowInformingAdmins); | ||
| } | ||
|
|
||
| @Override | ||
| default void sendFailure(final ComponentLike message) { | ||
| Preconditions.checkNotNull(message, "message cannot be null."); | ||
| this.getHandle().sendFailure(PaperAdventure.asVanilla(message.asComponent()), false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well this comes from the base PR but not sure about ignore the default style used in vanilla, but its more a opinion... most of people who use this wanna custom messages so...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could theoretically just add an overload that does apply the style too. Maybe |
||
| } | ||
|
|
||
| @Override | ||
| default Player getPlayerOrThrow() throws CommandSyntaxException { | ||
| return this.getHandle().getPlayerOrException().getBukkitEntity(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.