Code format :(

This commit is contained in:
md_5
2014-01-03 19:52:35 +11:00
parent 9f8c04ef86
commit 80caa2b669
18 changed files with 249 additions and 193 deletions

View File

@@ -19,58 +19,56 @@ public abstract class BaseComponent
BaseComponent parent;
/**
* The color of this component and any child
* components (unless overridden)
* The color of this component and any child components (unless overridden)
*/
@Getter(AccessLevel.NONE)
private ChatColor color;
/**
* Whether this component and any child
* components (unless overridden) is bold
* Whether this component and any child components (unless overridden) is
* bold
*/
@Getter(AccessLevel.NONE)
private Boolean bold;
/**
* Whether this component and any child
* components (unless overridden) is italic
* Whether this component and any child components (unless overridden) is
* italic
*/
@Getter(AccessLevel.NONE)
private Boolean italic;
/**
* Whether this component and any child
* components (unless overridden) is underlined
* Whether this component and any child components (unless overridden) is
* underlined
*/
@Getter(AccessLevel.NONE)
private Boolean underlined;
/**
* Whether this component and any child
* components (unless overridden) is strikethrough
* Whether this component and any child components (unless overridden) is
* strikethrough
*/
@Getter(AccessLevel.NONE)
private Boolean strikethrough;
/**
* Whether this component and any child
* components (unless overridden) is obfuscated
* Whether this component and any child components (unless overridden) is
* obfuscated
*/
@Getter(AccessLevel.NONE)
private Boolean obfuscated;
/**
* Appended components that inherit this component's
* formatting and events
* Appended components that inherit this component's formatting and events
*/
@Getter
private List<BaseComponent> extra;
/**
* The action to preform when this component (and
* child components) are clicked
* The action to preform when this component (and child components) are
* clicked
*/
@Getter
private ClickEvent clickEvent;
/**
* The action to preform when this component (and
* child components) are hovered over
* The action to preform when this component (and child components) are
* hovered over
*/
@Getter
private HoverEvent hoverEvent;
@@ -88,8 +86,9 @@ public abstract class BaseComponent
}
/**
* Converts the components to a string that uses the
* old formatting codes ({@link net.md_5.bungee.api.ChatColor#COLOR_CHAR}
* 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
*/
@@ -104,8 +103,8 @@ public abstract class BaseComponent
}
/**
* Converts the components into a string without
* any formatting
* Converts the components into a string without any formatting
*
* @param components the components to convert
* @return the string as plain text
*/
@@ -119,10 +118,9 @@ public abstract class BaseComponent
return builder.toString();
}
/**
* Returns the color of this component. This uses the parent's color
* if this component doesn't have one. {@link net.md_5.bungee.api.ChatColor#WHITE}
* Returns the color of this component. This uses the parent's color if this
* component doesn't have one. {@link net.md_5.bungee.api.ChatColor#WHITE}
* is returned if no color is found.
*
* @return the color of this component
@@ -141,8 +139,8 @@ public abstract class BaseComponent
}
/**
* Returns the color of this component without checking the parents
* color. May return null
* Returns the color of this component without checking the parents color.
* May return null
*
* @return the color of this component
*/
@@ -152,9 +150,9 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is bold. This uses the parent's
* setting if this component hasn't been set. false is returned
* if none of the parent chain has been set.
* Returns whether this component is bold. This uses the parent's setting if
* this component hasn't been set. false is returned if none of the parent
* chain has been set.
*
* @return whether the component is bold
*/
@@ -168,8 +166,8 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is bold without checking
* the parents setting. May return null
* Returns whether this component is bold without checking the parents
* setting. May return null
*
* @return whether the component is bold
*/
@@ -179,9 +177,9 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is italic. This uses the parent's
* setting if this component hasn't been set. false is returned
* if none of the parent chain has been set.
* Returns whether this component is italic. This uses the parent's setting
* if this component hasn't been set. false is returned if none of the
* parent chain has been set.
*
* @return whether the component is italic
*/
@@ -195,8 +193,8 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is italic without checking
* the parents setting. May return null
* Returns whether this component is italic without checking the parents
* setting. May return null
*
* @return whether the component is italic
*/
@@ -207,8 +205,8 @@ public abstract class BaseComponent
/**
* Returns whether this component is underlined. This uses the parent's
* setting if this component hasn't been set. false is returned
* if none of the parent chain has been set.
* setting if this component hasn't been set. false is returned if none of
* the parent chain has been set.
*
* @return whether the component is underlined
*/
@@ -222,8 +220,8 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is underlined without checking
* the parents setting. May return null
* Returns whether this component is underlined without checking the parents
* setting. May return null
*
* @return whether the component is underlined
*/
@@ -234,8 +232,8 @@ public abstract class BaseComponent
/**
* Returns whether this component is strikethrough. This uses the parent's
* setting if this component hasn't been set. false is returned
* if none of the parent chain has been set.
* setting if this component hasn't been set. false is returned if none of
* the parent chain has been set.
*
* @return whether the component is strikethrough
*/
@@ -249,8 +247,8 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is strikethrough without checking
* the parents setting. May return null
* Returns whether this component is strikethrough without checking the
* parents setting. May return null
*
* @return whether the component is strikethrough
*/
@@ -261,8 +259,8 @@ public abstract class BaseComponent
/**
* Returns whether this component is obfuscated. This uses the parent's
* setting if this component hasn't been set. false is returned
* if none of the parent chain has been set.
* setting if this component hasn't been set. false is returned if none of
* the parent chain has been set.
*
* @return whether the component is obfuscated
*/
@@ -276,8 +274,8 @@ public abstract class BaseComponent
}
/**
* Returns whether this component is obfuscated without checking
* the parents setting. May return null
* Returns whether this component is obfuscated without checking the parents
* setting. May return null
*
* @return whether the component is obfuscated
*/
@@ -296,8 +294,8 @@ public abstract class BaseComponent
}
/**
* Appends a text element to the component. The text will
* inherit this component's formatting
* Appends a text element to the component. The text will inherit this
* component's formatting
*
* @param text the text to append
*/
@@ -307,8 +305,8 @@ public abstract class BaseComponent
}
/**
* Appends a component to the component. The text will
* inherit this component's formatting
* Appends a component to the component. The text will inherit this
* component's formatting
*
* @param component the component to append
*/
@@ -323,22 +321,21 @@ public abstract class BaseComponent
}
/**
* Returns whether the component has any formatting
* or events applied to it
* Returns whether the component has any formatting or events applied to it
*
* @return
*/
public boolean hasFormatting()
{
return color != null || bold != null ||
italic != null || underlined != null ||
strikethrough != null || obfuscated != null ||
hoverEvent != null || clickEvent != null;
return color != null || bold != null
|| italic != null || underlined != null
|| strikethrough != null || obfuscated != null
|| hoverEvent != null || clickEvent != null;
}
/**
* Converts the component into a string without
* any formatting
* Converts the component into a string without any formatting
*
* @return the string as plain text
*/
public String toPlainText()
@@ -359,10 +356,10 @@ 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}
* 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()
@@ -383,7 +380,6 @@ public abstract class BaseComponent
}
}
@Override
public String toString()
{

View File

@@ -1,6 +1,5 @@
package net.md_5.bungee.api.chat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -10,18 +9,21 @@ import lombok.Setter;
@AllArgsConstructor
final public class ClickEvent
{
/**
* The type of action to preform on click
*/
private final Action action;
/**
* Depends on action
*
* @see net.md_5.bungee.api.chat.ClickEvent.Action
*/
private final String value;
public enum Action
{
/**
* Open a url at the path given by
* {@link net.md_5.bungee.api.chat.ClickEvent#getValue()}
@@ -39,8 +41,8 @@ final public class ClickEvent
RUN_COMMAND,
/**
* Inserts the string given by
* {@link net.md_5.bungee.api.chat.ClickEvent#getValue()}
* into the players text box
* {@link net.md_5.bungee.api.chat.ClickEvent#getValue()} into the
* players text box
*/
SUGGEST_COMMAND
}

View File

@@ -7,30 +7,30 @@ import java.util.ArrayList;
import java.util.List;
/**
* ComponentBuilder simplifies creating basic messages by allowing
* the use of a chainable builder.
* ComponentBuilder simplifies creating basic messages by allowing the use of a
* chainable builder.
* <p/>
* <pre>
* new ComponentBuilder("Hello ").color(ChatColor.RED).
* append("World").color(ChatColor.BLUE).
* append("!").bold(true).create();
* <
* pre>
* new ComponentBuilder("Hello ").color(ChatColor.RED).
* append("World").color(ChatColor.BLUE). append("!").bold(true).create();
* </pre>
* <p/>
* All methods (excluding {@link #append(String)} and {@link #create()}
* work on the last part appended to the builder, so in the example
* above "Hello " would be {@link net.md_5.bungee.api.ChatColor#RED}
* and "World" would be {@link net.md_5.bungee.api.ChatColor#BLUE} but
* "!" would be bold and {@link net.md_5.bungee.api.ChatColor#BLUE}
* because append copies the previous part's formatting
* All methods (excluding {@link #append(String)} and {@link #create()} work on
* the last part appended to the builder, so in the example above "Hello " would
* be {@link net.md_5.bungee.api.ChatColor#RED} and "World" would be
* {@link net.md_5.bungee.api.ChatColor#BLUE} but "!" would be bold and
* {@link net.md_5.bungee.api.ChatColor#BLUE} because append copies the previous
* part's formatting
*/
public class ComponentBuilder
{
private TextComponent current;
private List<BaseComponent> parts = new ArrayList<>();
/**
* Creates a ComponentBuilder with the given text as the
* first part.
* Creates a ComponentBuilder with the given text as the first part.
*
* @param text the first text element
*/
@@ -40,9 +40,8 @@ public class ComponentBuilder
}
/**
* Appends the text to the builder and makes it the current
* target for formatting. The text will have all the
* formatting from the previous part.
* Appends the text to the builder and makes it the current target for
* formatting. The text will have all the formatting from the previous part.
*
* @param text the text to append
* @return this ComponentBuilder for chaining
@@ -129,7 +128,7 @@ public class ComponentBuilder
/**
* Sets the click event for the current part.
*
*
* @param clickEvent the click event
* @return this ComponentBuilder for chaining
*/
@@ -141,7 +140,7 @@ public class ComponentBuilder
/**
* Sets the hover event for the current part.
*
*
* @param hoverEvent the hover event
* @return this ComponentBuilder for chaining
*/
@@ -152,14 +151,14 @@ public class ComponentBuilder
}
/**
* Returns the components needed to display the message
* created by this builder.
*
* Returns the components needed to display the message created by this
* builder.
*
* @return the created components
*/
public BaseComponent[] create()
{
parts.add( current );
return parts.toArray( new BaseComponent[parts.size()] );
return parts.toArray( new BaseComponent[ parts.size() ] );
}
}

View File

@@ -9,11 +9,13 @@ import lombok.Setter;
@AllArgsConstructor
final public class HoverEvent
{
private final Action action;
private final BaseComponent[] value;
public enum Action
{
SHOW_TEXT,
SHOW_ACHIEVEMENT,
SHOW_ITEM

View File

@@ -20,8 +20,10 @@ public class TextComponent extends BaseComponent
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.
* 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
*/
@@ -79,7 +81,10 @@ public class TextComponent extends BaseComponent
continue;
}
int pos = message.indexOf( ' ', i );
if ( pos == -1 ) pos = message.length();
if ( pos == -1 )
{
pos = message.length();
}
if ( matcher.region( i, pos ).find() )
{ //Web link handling
@@ -112,22 +117,23 @@ public class TextComponent extends BaseComponent
}
//The client will crash if the array is empty
if ( components.size() == 0 ) {
if ( components.size() == 0 )
{
components.add( new TextComponent( "" ) );
}
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
* The text of the component that will be displayed to the client
*/
private String text;
/**
* Creates a TextComponent with formatting and text
* from the passed component
* Creates a TextComponent with formatting and text from the passed
* component
*
* @param textComponent the component to copy from
*/
public TextComponent(TextComponent textComponent)
@@ -147,11 +153,26 @@ public class TextComponent extends BaseComponent
protected void toLegacyText(StringBuilder builder)
{
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 );
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( text );
super.toLegacyText( builder );
}

View File

@@ -17,13 +17,13 @@ import java.util.regex.Pattern;
@NoArgsConstructor
public class TranslatableComponent extends BaseComponent
{
private final ResourceBundle locales = ResourceBundle.getBundle( "mojang-translations/en_US" );
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
* 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;
/**
@@ -33,11 +33,13 @@ public class TranslatableComponent extends BaseComponent
/**
* 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
* @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)
{
@@ -57,9 +59,9 @@ public class TranslatableComponent extends BaseComponent
}
/**
* Sets the translation substitutions to be used in
* this component. Removes any previously set
* substitutions
* 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)
@@ -72,8 +74,8 @@ public class TranslatableComponent extends BaseComponent
}
/**
* Adds a text substitution to the component. The text will
* inherit this component's formatting
* Adds a text substitution to the component. The text will inherit this
* component's formatting
*
* @param text the text to substitute
*/
@@ -83,8 +85,8 @@ public class TranslatableComponent extends BaseComponent
}
/**
* Adds a component substitution to the component. The text will
* inherit this component's formatting
* Adds a component substitution to the component. The text will inherit
* this component's formatting
*
* @param component the component to substitute
*/
@@ -189,11 +191,26 @@ public class TranslatableComponent extends BaseComponent
private void addFormat(StringBuilder builder)
{
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 );
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 );
}
}
@Override

View File

@@ -7,8 +7,8 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Event;
/**
* Event called as soon as a connection has a {@link ProxiedPlayer} and is
* ready to be connected to a server.
* Event called as soon as a connection has a {@link ProxiedPlayer} and is ready
* to be connected to a server.
*/
@Data
@ToString(callSuper = false)

View File

@@ -60,12 +60,14 @@ public class ServerKickEvent extends Event implements Cancellable
}
@Deprecated
public String getKickReason() {
public String getKickReason()
{
return BaseComponent.toLegacyText( kickReasonComponent );
}
@Deprecated
public void setKickReason(String reason) {
public void setKickReason(String reason)
{
kickReasonComponent = TextComponent.fromLegacyText( reason );
}
}