Skip to content

Commit

Permalink
#3665: Small improvements to TranslatableComponent
Browse files Browse the repository at this point in the history
* Make TranslatableComponent format Pattern static
* Fix TranslatableComponent copy constructor not copying fallback
  • Loading branch information
Janmm14 committed Apr 24, 2024
1 parent d110f66 commit 336333a
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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
Expand All @@ -44,10 +44,11 @@ public TranslatableComponent(TranslatableComponent original)
{
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() );
Expand Down Expand Up @@ -177,7 +178,7 @@ private void convert(StringBuilder builder, boolean applyFormat)
trans = fallback;
}

Matcher matcher = format.matcher( trans );
Matcher matcher = FORMAT.matcher( trans );
int position = 0;
int i = 0;
while ( matcher.find( position ) )
Expand Down

0 comments on commit 336333a

Please sign in to comment.