Fix TranslatableComponent's handling of missing translations

This commit is contained in:
Thinkofdeath 2014-07-12 10:34:10 +01:00
parent a0e8b172ef
commit 02e219262a

View File

@ -6,6 +6,7 @@ import lombok.Setter;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -103,13 +104,8 @@ public class TranslatableComponent extends BaseComponent
@Override @Override
protected void toPlainText(StringBuilder builder) protected void toPlainText(StringBuilder builder)
{ {
try {
String trans = locales.getString( translate ); String trans = locales.getString( translate );
// TODO: Yell @ Thinkofdeath, this is impossible. getString(..) actually throws an exception when there is no string.
if ( trans == null )
{
builder.append( translate );
} else
{
Matcher matcher = format.matcher( trans ); Matcher matcher = format.matcher( trans );
int position = 0; int position = 0;
int i = 0; int i = 0;
@ -139,7 +135,11 @@ public class TranslatableComponent extends BaseComponent
{ {
builder.append( trans.substring( position, trans.length() ) ); builder.append( trans.substring( position, trans.length() ) );
} }
} catch ( MissingResourceException e )
{
builder.append( translate );
} }
super.toPlainText( builder ); super.toPlainText( builder );
} }