Support printing TranslatableComponents

This commit is contained in:
Thinkofdeath 2013-12-06 23:18:10 +00:00
parent e3e551d825
commit 696679809d
2 changed files with 1720 additions and 2 deletions

View File

@ -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 );
}

File diff suppressed because it is too large Load Diff