Comments (15)
Yes, it is working as intended -- if you look at the above JSON you'll see that the second-last object has empty (""
) text and green
colouring - this is your last &a
in the prefix. To continue with that formatting, you'd need to be appending to the last child component, not the root component itself.
from adventure.
Could you provide the code you're using, please? Which version of text are you using?
from adventure.
Velocity version: 1.0.0-SNAPSHOT (Latest)
Text version: 1.12-1.6.5 (Packaged with Velocity)
Specific code chunks: https://pastebin.com/DULhHL7J
Appending in code: https://github.com/Crypnotic/Neutron/blob/refactor/announcement/src/main/java/me/crypnotic/neutron/module/announcement/Announcement.java#L65
Color method for serializing: https://github.com/Crypnotic/Neutron/blob/refactor/announcement/src/main/java/me/crypnotic/neutron/util/StringHelper.java#L37-L44
TypeSerializer that is used to load from config: https://github.com/Crypnotic/Neutron/blob/refactor/announcement/src/main/java/me/crypnotic/neutron/api/serializer/TextComponentSerializer.java
from adventure.
Text values used in the screenshot
Prefix text: &7[&bPrefix&7] &a
Message text: This entire messages should be &agreen
from adventure.
This is actually how this is intended to work:
color("&7[&bPrefix&7] &a").append(color("This entire messages should be &agreen"))
{
"text": "",
"extra": [
{
"text": "[",
"color": "gray"
},
{
"text": "Prefix",
"color": "aqua"
},
{
"text": "] ",
"color": "gray"
},
{
"text": "",
"color": "green"
},
{
"text": "This entire messages should be ",
"extra": [
{
"text": "green",
"color": "green"
}
]
}
]
}
The "prefix" is part of one root, and the root doesn't have any style - the last child, which has empty content
, is styled with green.
from adventure.
So you're saying this is working as intended? That's strange since the same string appended beforehand would yield the proper result
from adventure.
Component children are immutable. When appending onto a child component, would it return the child component or the root component?
from adventure.
It would return the child component.
This is one of the reasons that use of the legacy serialiser is discouraged, in favour of the JSON serialiser (or custom ones - YAML, XML, etc).
from adventure.
So there is essentially no way to apply a prefix with a trailing color code to a TextComponent without creating multiple new components just to get there?
from adventure.
Side note: I would use JSON, but I can't expect most people to take the time to create a proper JSON message just to send announcements. That's just opening an avenue to get littered with issues that are user error
from adventure.
You can deserialise all as one (color(prefix + message)
) to create a component, otherwise you'll have to do a dance.
from adventure.
Which means if I want to support JSON messages also, I would have to serialize, deserialize into legacy, append, reserialize. Either direction requires a dance
from adventure.
Assuming the last bit of the prefix defines the colour for the text coming up, yes, you'd need to do a dance still:
final Component prefix = color("&7[&bPrefix&7] &a");
final List<Component> prefixChildren = prefix.children();
final Style prefixLastChildStyle = prefixChildren.get(prefixChildren.size() - 1).style();
final Component message = color("This entire messages should be &agreen");
final Component result = prefix.append(TextComponent.builder().style(prefixLastChildStyle).append(message));
results in a component that serialises into the following JSON:
{
"text": "",
"extra": [
{
"text": "[",
"color": "gray"
},
{
"text": "Prefix",
"color": "aqua"
},
{
"text": "] ",
"color": "gray"
},
{
"text": "",
"color": "green"
},
{
"text": "",
"extra": [
{
"text": "This entire messages should be ",
"extra": [
{
"text": "green",
"color": "green"
}
]
}
],
"color": "green"
}
]
}
and into the following legacy text:
§7[§bPrefix§7] §aThis entire messages should be green
The above code is based on text 3.0.0 - if you're on a previous version you'll have to manually apply any colouring + decorations, as Style
does not exist in previous versions.
from adventure.
It's a good thing Velocity packages 1.6.5 🥇
from adventure.
Solved for now I guess. In case anyone needs a method that works on versions < 3.0.0
Neutron - StringHelper#append()
from adventure.
Related Issues (20)
- Support new item hover format in 24w09+
- Particle Interfaces?
- Phase issues with <gradient> and more than 2 colors HOT 4
- BinaryTagIO.Reader & BinaryTagIO.Writer other tag support HOT 1
- Make `BinaryTagType.binaryTagType(int)` public HOT 1
- Emptying BossBar flags always calls bossBarFlagsChanged, even if nothing was changed
- Filtering tag provider
- Generic character mapping MiniMessage tag (for small caps)
- Default value for unresolved tags
- API for "caching" MiniMessage strings (or other serializer specific data) for ease of sending
- `CompoundBinaryTag#getBoolean` with default is incorrect
- `ListBinaryTag` is weakly immutable HOT 3
- NPE while sending a resource pack with no prompt HOT 1
- Adventure weighs hue too heavily when comparing colors HOT 3
- MiniMessage strips "redundant" tags which does not allow me to set prefixes as I can with legacy color codes HOT 1
- show_item client safety HOT 1
- NBT: NumberBinaryTag should have access to Number HOT 2
- Best practices in regex matching and editing the entire component content HOT 1
- Failed to parse the hoverableText for an enchanted item.
- Minimessage::escapeTags does not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adventure.