Add missing documentation
This commit is contained in:
parent
c17fa03ccd
commit
3f9ca85831
@ -19,28 +19,61 @@ public abstract class BaseComponent
|
|||||||
@Setter(AccessLevel.NONE)
|
@Setter(AccessLevel.NONE)
|
||||||
BaseComponent parent;
|
BaseComponent parent;
|
||||||
|
|
||||||
//Formatting
|
/**
|
||||||
|
* The color of this component and any child
|
||||||
|
* components (unless overridden)
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private ChatColor color;
|
private ChatColor color;
|
||||||
|
/**
|
||||||
|
* Whether this component and any child
|
||||||
|
* components (unless overridden) is bold
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Boolean bold;
|
private Boolean bold;
|
||||||
|
/**
|
||||||
|
* Whether this component and any child
|
||||||
|
* components (unless overridden) is italic
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Boolean italic;
|
private Boolean italic;
|
||||||
|
/**
|
||||||
|
* Whether this component and any child
|
||||||
|
* components (unless overridden) is underlined
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Boolean underlined;
|
private Boolean underlined;
|
||||||
|
/**
|
||||||
|
* Whether this component and any child
|
||||||
|
* components (unless overridden) is strikethrough
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Boolean strikethrough;
|
private Boolean strikethrough;
|
||||||
|
/**
|
||||||
|
* Whether this component and any child
|
||||||
|
* components (unless overridden) is obfuscated
|
||||||
|
*/
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Boolean obfuscated;
|
private Boolean obfuscated;
|
||||||
|
|
||||||
//Appended components
|
/**
|
||||||
|
* Appended components that inherit this component's
|
||||||
|
* formatting and events
|
||||||
|
*/
|
||||||
private List<BaseComponent> extra;
|
private List<BaseComponent> extra;
|
||||||
|
|
||||||
//Events
|
/**
|
||||||
|
* The action to preform when this component (and
|
||||||
|
* child components) are clicked
|
||||||
|
*/
|
||||||
private ClickEvent clickEvent;
|
private ClickEvent clickEvent;
|
||||||
|
/**
|
||||||
|
* The action to preform when this component (and
|
||||||
|
* child components) are hovered over
|
||||||
|
*/
|
||||||
private HoverEvent hoverEvent;
|
private HoverEvent hoverEvent;
|
||||||
|
|
||||||
public BaseComponent(BaseComponent old)
|
protected BaseComponent(BaseComponent old)
|
||||||
{
|
{
|
||||||
setColor( old.getColorRaw() );
|
setColor( old.getColorRaw() );
|
||||||
setBold( old.isBoldRaw() );
|
setBold( old.isBoldRaw() );
|
||||||
@ -50,6 +83,12 @@ public abstract class BaseComponent
|
|||||||
setObfuscated( old.isObfuscatedRaw() );
|
setObfuscated( old.isObfuscatedRaw() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the components to a string that uses the
|
||||||
|
* old formatting codes ({@link net.md_5.bungee.api.ChatColor#COLOR_CHAR}
|
||||||
|
* @param components the components to convert
|
||||||
|
* @return the string in the old format
|
||||||
|
*/
|
||||||
public static String toLegacyText(BaseComponent... components)
|
public static String toLegacyText(BaseComponent... components)
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -60,6 +99,12 @@ public abstract class BaseComponent
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the components into a string without
|
||||||
|
* any formatting
|
||||||
|
* @param components the components to convert
|
||||||
|
* @return the string as plain text
|
||||||
|
*/
|
||||||
public static String toPlainText(BaseComponent... components)
|
public static String toPlainText(BaseComponent... components)
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -273,6 +318,11 @@ public abstract class BaseComponent
|
|||||||
extra.add( component );
|
extra.add( component );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the component has any formatting
|
||||||
|
* or events applied to it
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean hasFormatting()
|
public boolean hasFormatting()
|
||||||
{
|
{
|
||||||
return color != null || bold != null ||
|
return color != null || bold != null ||
|
||||||
@ -281,6 +331,12 @@ public abstract class BaseComponent
|
|||||||
hoverEvent != null || clickEvent != null;
|
hoverEvent != null || clickEvent != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the component into a string without
|
||||||
|
* any formatting
|
||||||
|
* @return the string as plain text
|
||||||
|
*/
|
||||||
public String toPlainText()
|
public String toPlainText()
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -299,6 +355,12 @@ public abstract class BaseComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the component to a string that uses the
|
||||||
|
* old formatting codes ({@link net.md_5.bungee.api.ChatColor#COLOR_CHAR}
|
||||||
|
* @return the string in the old format
|
||||||
|
*/
|
||||||
public String toLegacyText()
|
public String toLegacyText()
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
@ -12,19 +12,44 @@ import lombok.Setter;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class ClickEvent
|
public class ClickEvent
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The type of action to preform on click
|
||||||
|
*/
|
||||||
private Action action;
|
private Action action;
|
||||||
|
/**
|
||||||
|
* Depends on action
|
||||||
|
* @see net.md_5.bungee.api.chat.ClickEvent.Action
|
||||||
|
*/
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public enum Action
|
public enum Action
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Open a url at the path given by
|
||||||
|
* {@link net.md_5.bungee.api.chat.ClickEvent#setValue(String)}
|
||||||
|
*/
|
||||||
OPEN_URL,
|
OPEN_URL,
|
||||||
|
/**
|
||||||
|
* Open a file at the path given by
|
||||||
|
* {@link net.md_5.bungee.api.chat.ClickEvent#setValue(String)}
|
||||||
|
*/
|
||||||
OPEN_FILE,
|
OPEN_FILE,
|
||||||
|
/**
|
||||||
|
* Run the command given by
|
||||||
|
* {@link net.md_5.bungee.api.chat.ClickEvent#setValue(String)}
|
||||||
|
*/
|
||||||
RUN_COMMAND,
|
RUN_COMMAND,
|
||||||
|
/**
|
||||||
|
* Inserts the string given by
|
||||||
|
* {@link net.md_5.bungee.api.chat.ClickEvent#setValue(String)}
|
||||||
|
* into the players text box
|
||||||
|
*/
|
||||||
SUGGEST_COMMAND
|
SUGGEST_COMMAND
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
return String.format( "ClickEvent{action=%s, value=%s}", action, value );
|
return String.format( "ClickEvent{action=%s, value=%s}", action, value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ public class HoverEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
return String.format( "HoverEvent{action=%s, value=%s}", action, value );
|
return String.format( "HoverEvent{action=%s, value=%s}", action, value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,12 @@ public class TextComponent extends BaseComponent
|
|||||||
|
|
||||||
private static final Pattern url = Pattern.compile( "^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,4})(/\\S*)?$" );
|
private static final Pattern url = Pattern.compile( "^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,4})(/\\S*)?$" );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the old formatting system that used {@link net.md_5.bungee.api.ChatColor#COLOR_CHAR}
|
||||||
|
* into the new json based system.
|
||||||
|
* @param message the text to convert
|
||||||
|
* @return the components needed to print the message to the client
|
||||||
|
*/
|
||||||
public static BaseComponent[] fromLegacyText(String message)
|
public static BaseComponent[] fromLegacyText(String message)
|
||||||
{
|
{
|
||||||
ArrayList<BaseComponent> components = new ArrayList<>();
|
ArrayList<BaseComponent> components = new ArrayList<>();
|
||||||
@ -116,12 +122,21 @@ public class TextComponent extends BaseComponent
|
|||||||
return components.toArray( new BaseComponent[components.size()] );
|
return components.toArray( new BaseComponent[components.size()] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The text of the component that will be
|
||||||
|
* displayed to the client
|
||||||
|
*/
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
public TextComponent(TextComponent old)
|
/**
|
||||||
|
* Creates a TextComponent with formatting and text
|
||||||
|
* from the passed component
|
||||||
|
* @param textComponent the component to copy from
|
||||||
|
*/
|
||||||
|
public TextComponent(TextComponent textComponent)
|
||||||
{
|
{
|
||||||
super( old );
|
super( textComponent );
|
||||||
setText( old.getText() );
|
setText( textComponent.getText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,12 +17,28 @@ import java.util.regex.Pattern;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class TranslatableComponent extends BaseComponent
|
public class TranslatableComponent extends BaseComponent
|
||||||
{
|
{
|
||||||
public final ResourceBundle locales = ResourceBundle.getBundle( "mojang-translations/en_US" );
|
private final ResourceBundle locales = ResourceBundle.getBundle( "mojang-translations/en_US" );
|
||||||
private final Pattern format = Pattern.compile( "%(?:(\\d+)\\$)?([A-Za-z%]|$)" );
|
private final Pattern format = Pattern.compile( "%(?:(\\d+)\\$)?([A-Za-z%]|$)" );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key into the Minecraft locale files to use for the
|
||||||
|
* translation. The text depends on the client's locale setting.
|
||||||
|
* The console is always en_US
|
||||||
|
*/
|
||||||
private String translate;
|
private String translate;
|
||||||
|
/**
|
||||||
|
* The components to substitute into the translation
|
||||||
|
*/
|
||||||
private List<BaseComponent> with;
|
private List<BaseComponent> with;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a translatable component with the passed substitutions
|
||||||
|
* @see #setTranslate(String)
|
||||||
|
* @see #setWith(java.util.List)
|
||||||
|
* @param translate the translation key
|
||||||
|
* @param with the {@link java.lang.String}s and {@link net.md_5.bungee.api.chat.BaseComponent}s
|
||||||
|
* to use into the translation
|
||||||
|
*/
|
||||||
public TranslatableComponent(String translate, Object... with)
|
public TranslatableComponent(String translate, Object... with)
|
||||||
{
|
{
|
||||||
setTranslate( translate );
|
setTranslate( translate );
|
||||||
@ -40,6 +56,12 @@ public class TranslatableComponent extends BaseComponent
|
|||||||
setWith( temp );
|
setWith( temp );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the translation substitutions to be used in
|
||||||
|
* this component. Removes any previously set
|
||||||
|
* substitutions
|
||||||
|
* @param components the components to substitute
|
||||||
|
*/
|
||||||
public void setWith(List<BaseComponent> components)
|
public void setWith(List<BaseComponent> components)
|
||||||
{
|
{
|
||||||
for ( BaseComponent component : components )
|
for ( BaseComponent component : components )
|
||||||
@ -49,6 +71,33 @@ public class TranslatableComponent extends BaseComponent
|
|||||||
with = components;
|
with = components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a text substitution to the component. The text will
|
||||||
|
* inherit this component's formatting
|
||||||
|
*
|
||||||
|
* @param text the text to substitute
|
||||||
|
*/
|
||||||
|
public void addWith(String text)
|
||||||
|
{
|
||||||
|
addWith( new TextComponent( text ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a component substitution to the component. The text will
|
||||||
|
* inherit this component's formatting
|
||||||
|
*
|
||||||
|
* @param component the component to substitute
|
||||||
|
*/
|
||||||
|
public void addWith(BaseComponent component)
|
||||||
|
{
|
||||||
|
if ( with == null )
|
||||||
|
{
|
||||||
|
with = new ArrayList<>();
|
||||||
|
}
|
||||||
|
component.parent = this;
|
||||||
|
with.add( component );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void toPlainText(StringBuilder builder)
|
protected void toPlainText(StringBuilder builder)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user