mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-30 14:13:47 +01:00
Support printing TranslatableComponents
This commit is contained in:
parent
e3e551d825
commit
696679809d
@ -3,15 +3,18 @@ package net.md_5.bungee.api.chat;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class TranslatableComponent extends BaseComponent
|
||||
{
|
||||
public final ResourceBundle locales = ResourceBundle.getBundle( "en_US" );
|
||||
|
||||
private String translate;
|
||||
private List<BaseComponent> with;
|
||||
@ -44,14 +47,44 @@ public class TranslatableComponent extends BaseComponent
|
||||
@Override
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
//TODO
|
||||
String[] parts = translate.split( "((?<=%s)|(?=%s))" );
|
||||
int i = 0;
|
||||
for ( String part : parts )
|
||||
{
|
||||
if ( part.equals( "%s" ) )
|
||||
{
|
||||
with.get( i ).toPlainText( builder );
|
||||
i++;
|
||||
} else
|
||||
{
|
||||
builder.append( part );
|
||||
}
|
||||
}
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
//TODO
|
||||
String[] parts = locales.getString( translate ).split( "((?<=%s)|(?=%s))" );
|
||||
int i = 0;
|
||||
for ( String part : parts )
|
||||
{
|
||||
if ( part.equals( "%s" ) )
|
||||
{
|
||||
with.get( i ).toLegacyText( builder );
|
||||
i++;
|
||||
} else
|
||||
{
|
||||
builder.append( getColor() );
|
||||
if ( isBold() ) builder.append( ChatColor.BOLD );
|
||||
if ( isItalic() ) builder.append( ChatColor.ITALIC );
|
||||
if ( isUnderlined() ) builder.append( ChatColor.UNDERLINE );
|
||||
if ( isStrikethrough() ) builder.append( ChatColor.STRIKETHROUGH );
|
||||
if ( isObfuscated() ) builder.append( ChatColor.MAGIC );
|
||||
builder.append( part );
|
||||
}
|
||||
}
|
||||
super.toLegacyText( builder );
|
||||
}
|
||||
|
||||
|
1685
proxy/src/main/resources/en_US.properties
Normal file
1685
proxy/src/main/resources/en_US.properties
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user