mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-23 18:55:22 +01:00
#3558: Add Translatable interface for fluid creation of TranslatableComponents
This commit is contained in:
parent
39b10c0b16
commit
16298a75f2
@ -204,6 +204,33 @@ public final class ComponentBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the {@link TranslationProvider} object to the builder and makes
|
||||
* the last element the current target for formatting. The components will
|
||||
* have all the formatting from previous part.
|
||||
*
|
||||
* @param translatable the translatable object to append
|
||||
* @return this ComponentBuilder for chaining
|
||||
*/
|
||||
public ComponentBuilder append(TranslationProvider translatable)
|
||||
{
|
||||
return append( translatable, FormatRetention.ALL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the {@link TranslationProvider} object to the builder and makes
|
||||
* the last element the current target for formatting. You can specify the
|
||||
* amount of formatting retained from previous part.
|
||||
*
|
||||
* @param translatable the translatable object to append
|
||||
* @param retention the formatting to retain
|
||||
* @return this ComponentBuilder for chaining
|
||||
*/
|
||||
public ComponentBuilder append(TranslationProvider translatable, FormatRetention retention)
|
||||
{
|
||||
return append( translatable.asTranslatableComponent(), retention );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text to the builder and makes it the current target for
|
||||
* formatting. The text will have all the formatting from previous part.
|
||||
|
@ -86,6 +86,21 @@ public final class TranslatableComponent extends BaseComponent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translatable component with the passed substitutions
|
||||
*
|
||||
* @param translatable the translatable object
|
||||
* @param with the {@link java.lang.String}s and
|
||||
* {@link net.md_5.bungee.api.chat.BaseComponent}s to use into the
|
||||
* translation
|
||||
* @see #translate
|
||||
* @see #setWith(java.util.List)
|
||||
*/
|
||||
public TranslatableComponent(TranslationProvider translatable, Object... with)
|
||||
{
|
||||
this( translatable.getTranslationKey(), with );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a duplicate of this TranslatableComponent.
|
||||
*
|
||||
|
@ -0,0 +1,38 @@
|
||||
package net.md_5.bungee.api.chat;
|
||||
|
||||
/**
|
||||
* An object capable of being translated by the client in a
|
||||
* {@link TranslatableComponent}.
|
||||
*/
|
||||
public interface TranslationProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the translation key.
|
||||
*
|
||||
* @return the translation key
|
||||
*/
|
||||
String getTranslationKey();
|
||||
|
||||
/**
|
||||
* Get this translatable object as a {@link TranslatableComponent}.
|
||||
*
|
||||
* @return the translatable component
|
||||
*/
|
||||
default TranslatableComponent asTranslatableComponent()
|
||||
{
|
||||
return asTranslatableComponent( (Object[]) null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this translatable object as a {@link TranslatableComponent}.
|
||||
*
|
||||
* @param with the {@link String Strings} and
|
||||
* {@link BaseComponent BaseComponents} to use in the translation
|
||||
* @return the translatable component
|
||||
*/
|
||||
default TranslatableComponent asTranslatableComponent(Object... with)
|
||||
{
|
||||
return new TranslatableComponent( this, with );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user