Add expr to get the show item hover tag for a given item.#8669
Add expr to get the show item hover tag for a given item.#8669sovdeeth wants to merge 4 commits into
Conversation
|
Why not an expression that applies the show_item hover action to a Component? |
Because that would be rather difficult to put into a string with %%. Could be a separate expression though. |
Makes sense. I was worried about the hackiness of returning a minimessage string back to the user, but that's now solved! This seems like a pretty good way of providing components to the user in general, assuming that interpolating it into a minimessage string works like you'd expect. |
This comment was marked as resolved.
This comment was marked as resolved.
|
This is because you're forcing it back into a string before reformatting. If you used component addition, this likely would not be an issue. |
Sure, but how often do you see people use |
Yeah, my point is that to put it into a string, like you're testing, it has to become a string again, there's no way around that. It would be the same if you attached the component to another like skbee does and then serialized it back into a minimessage string to put in another string. It's just unavoidable with the test you're doing. Keeping it as a component doesn't have that issue |
| public static void register(SyntaxRegistry registry) { | ||
| registry.register(SyntaxRegistry.EXPRESSION, | ||
| SyntaxInfo.Expression.builder(ExprItemHoverText.class, Component.class) | ||
| .addPattern("[a[n]] [show] item hover [text] component (for|using|from) %itemstacks%") |
There was a problem hiding this comment.
| .addPattern("[a[n]] [show] item hover [text] component (for|using|from) %itemstacks%") | |
| .addPattern("[a[n]] [show] item hover [text] component[s] (for|using|from) %itemstacks%") |
For better plurality support: item hover components for {_a} and {_b}
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| throw new IllegalStateException("toString should be overridden"); |
There was a problem hiding this comment.
| throw new IllegalStateException("toString should be overridden"); | |
| return "item hover component"; |
I don't think this would ever be called, but contractually it's probably safer to just implement it.
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return "item hover component for " + getExpr().toString(event, debug); | ||
| } |







Problem
Creating a hover:show_item tag requires the ability to get a string representation of all the necessary components of an item, which is not simple in Skript. See https://docs.papermc.io/adventure/minimessage/format/#hover for details.
Solution
Adds a property expression

item hover text of %itemstacks%that automatically produces the tag"<hover:show_item:...>"for those items.Testing Completed
Added simple regression tests.
Supporting Information
Completes: none
Related: none
AI assistance: none