mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
Make ComponentBuilder clonable
This commit is contained in:
parent
0d174b51c5
commit
9fc862cb74
@ -80,6 +80,13 @@ public abstract class BaseComponent
|
||||
setHoverEvent( old.getHoverEvent() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the BaseComponent and returns the clone.
|
||||
*
|
||||
* @return The duplicate of this BaseComponent
|
||||
*/
|
||||
public abstract BaseComponent duplicate();
|
||||
|
||||
/**
|
||||
* Converts the components to a string that uses the old formatting codes
|
||||
* ({@link net.md_5.bungee.api.ChatColor#COLOR_CHAR}
|
||||
|
@ -28,6 +28,21 @@ public class ComponentBuilder
|
||||
private TextComponent current;
|
||||
private final List<BaseComponent> parts = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a ComponentBuilder from the other given ComponentBuilder to clone it.
|
||||
*
|
||||
* @param original the original for the new ComponentBuilder.
|
||||
*/
|
||||
public ComponentBuilder(ComponentBuilder original)
|
||||
{
|
||||
current = new TextComponent( original.current );
|
||||
for ( BaseComponent baseComponent : original.parts )
|
||||
{
|
||||
parts.add( baseComponent.duplicate() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ComponentBuilder with the given text as the first part.
|
||||
*
|
||||
|
@ -159,6 +159,17 @@ public class TextComponent extends BaseComponent
|
||||
setExtra( Arrays.asList( extras ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a duplicate of this TextComponent.
|
||||
*
|
||||
* @return the duplicate of this TextComponent.
|
||||
*/
|
||||
@Override
|
||||
public BaseComponent duplicate()
|
||||
{
|
||||
return new TextComponent( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
|
@ -32,6 +32,21 @@ public class TranslatableComponent extends BaseComponent
|
||||
*/
|
||||
private List<BaseComponent> with;
|
||||
|
||||
/**
|
||||
* Creates a translatable component from the original to clone it.
|
||||
*
|
||||
* @param original the original for the new translatable component.
|
||||
*/
|
||||
public TranslatableComponent(TranslatableComponent original)
|
||||
{
|
||||
super( original );
|
||||
setTranslate( original.getTranslate() );
|
||||
for ( BaseComponent baseComponent : original.getWith() )
|
||||
{
|
||||
with.add( baseComponent.duplicate() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translatable component with the passed substitutions
|
||||
*
|
||||
@ -59,6 +74,17 @@ public class TranslatableComponent extends BaseComponent
|
||||
setWith( temp );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a duplicate of this TranslatableComponent.
|
||||
*
|
||||
* @return the duplicate of this TranslatableComponent.
|
||||
*/
|
||||
@Override
|
||||
public BaseComponent duplicate()
|
||||
{
|
||||
return new TranslatableComponent( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the translation substitutions to be used in this component. Removes
|
||||
* any previously set substitutions
|
||||
|
Loading…
Reference in New Issue
Block a user