#3665: Small improvements to TranslatableComponent

* Make TranslatableComponent format Pattern static
* Fix TranslatableComponent copy constructor not copying fallback
This commit is contained in:
Janmm14 2024-04-24 21:58:27 +00:00 committed by GitHub
parent d110f6629b
commit 336333acb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,7 +19,7 @@ import net.md_5.bungee.chat.TranslationRegistry;
public final class TranslatableComponent extends BaseComponent
{
private final Pattern format = Pattern.compile( "%(?:(\\d+)\\$)?([A-Za-z%]|$)" );
private static final Pattern FORMAT = Pattern.compile( "%(?:(\\d+)\\$)?([A-Za-z%]|$)" );
/**
* The key into the Minecraft locale files to use for the translation. The
@ -44,10 +44,11 @@ public final class TranslatableComponent extends BaseComponent
{
super( original );
setTranslate( original.getTranslate() );
setFallback( original.getFallback() );
if ( original.getWith() != null )
{
List<BaseComponent> temp = new ArrayList<BaseComponent>();
List<BaseComponent> temp = new ArrayList<>();
for ( BaseComponent baseComponent : original.getWith() )
{
temp.add( baseComponent.duplicate() );
@ -177,7 +178,7 @@ public final class TranslatableComponent extends BaseComponent
trans = fallback;
}
Matcher matcher = format.matcher( trans );
Matcher matcher = FORMAT.matcher( trans );
int position = 0;
int i = 0;
while ( matcher.find( position ) )