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>
* <
* pre>
* new ComponentBuilder("Hello ").color(ChatColor.RED).
* append("World").color(ChatColor.BLUE).
* append("!").bold(true).create();
* 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
@ -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 );
}
}

View File

@ -35,6 +35,7 @@ public enum Protocol
HANDSHAKE
{
{
TO_SERVER.registerPacket( 0x00, Handshake.class );
}
@ -43,6 +44,7 @@ public enum Protocol
GAME
{
{
TO_CLIENT.registerPacket( 0x00, KeepAlive.class );
TO_CLIENT.registerPacket( 0x01, Login.class );
@ -57,7 +59,6 @@ public enum Protocol
TO_CLIENT.registerPacket( 0x3F, PluginMessage.class );
TO_CLIENT.registerPacket( 0x40, Kick.class );
TO_SERVER.registerPacket( 0x00, KeepAlive.class );
TO_SERVER.registerPacket( 0x01, Chat.class );
TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class );
@ -69,6 +70,7 @@ public enum Protocol
STATUS
{
{
TO_CLIENT.registerPacket( 0x00, StatusResponse.class );
TO_CLIENT.registerPacket( 0x01, PingPacket.class );
@ -81,6 +83,7 @@ public enum Protocol
LOGIN
{
{
TO_CLIENT.registerPacket( 0x00, Kick.class );
TO_CLIENT.registerPacket( 0x01, EncryptionRequest.class );

View File

@ -10,11 +10,11 @@ import net.md_5.bungee.protocol.PacketWrapper;
public class EntityMap
{
private final static boolean[] clientboundInts = new boolean[256];
private final static boolean[] clientboundVarInts = new boolean[256];
private final static boolean[] clientboundInts = new boolean[ 256 ];
private final static boolean[] clientboundVarInts = new boolean[ 256 ];
private final static boolean[] serverboundInts = new boolean[256];
private final static boolean[] serverboundVarInts = new boolean[256];
private final static boolean[] serverboundInts = new boolean[ 256 ];
private final static boolean[] serverboundVarInts = new boolean[ 256 ];
static
{
@ -50,12 +50,12 @@ public class EntityMap
public static void rewriteServerbound(ByteBuf packet, int serverEntityId, int clientEntityId)
{
rewrite(packet, serverEntityId, clientEntityId, serverboundInts, serverboundVarInts);
rewrite( packet, serverEntityId, clientEntityId, serverboundInts, serverboundVarInts );
}
public static void rewriteClientbound(ByteBuf packet, int serverEntityId, int clientEntityId)
{
rewrite(packet, serverEntityId, clientEntityId, clientboundInts, clientboundVarInts);
rewrite( packet, serverEntityId, clientEntityId, clientboundInts, clientboundVarInts );
//Special cases
int readerIndex = packet.readerIndex();
@ -76,7 +76,7 @@ public class EntityMap
int count = packet.getByte( packetIdLength );
for ( int i = 0; i < count; i++ )
{
int readId = packet.getInt( packetIdLength + 1 + i * 4);
int readId = packet.getInt( packetIdLength + 1 + i * 4 );
if ( readId == serverEntityId )
{
packet.setInt( packetIdLength + 1 + i * 4, clientEntityId );

View File

@ -68,7 +68,10 @@ public class ServerConnection implements Server
@Override
public void disconnect(BaseComponent reason)
{
disconnect( new BaseComponent[]{reason} );
disconnect( new BaseComponent[]
{
reason
} );
}
@Override

View File

@ -56,10 +56,15 @@ public class BaseComponentSerializer
{
JsonObject event = object.getAsJsonObject( "hoverEvent" );
BaseComponent[] res;
if (event.get("value").isJsonArray()) {
if ( event.get( "value" ).isJsonArray() )
{
res = context.deserialize( event.get( "value" ), BaseComponent[].class );
} else {
res = new BaseComponent[]{context.<BaseComponent>deserialize( event.get( "value" ), BaseComponent.class )};
} else
{
res = new BaseComponent[]
{
context.<BaseComponent>deserialize( event.get( "value" ), BaseComponent.class )
};
}
component.setHoverEvent( new HoverEvent( HoverEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ), res ) );
}

View File

@ -30,7 +30,10 @@ public class ComponentSerializer implements JsonSerializer<BaseComponent>, JsonD
{ //Array
return gson.fromJson( json, BaseComponent[].class );
}
return new BaseComponent[]{gson.fromJson( json, BaseComponent.class )};
return new BaseComponent[]
{
gson.fromJson( json, BaseComponent.class )
};
}
public static String toString(BaseComponent component)

View File

@ -14,6 +14,7 @@ import java.lang.reflect.Type;
public class TextComponentSerializer extends BaseComponentSerializer implements JsonSerializer<TextComponent>, JsonDeserializer<TextComponent>
{
@Override
public TextComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{

View File

@ -15,6 +15,7 @@ import java.util.Arrays;
public class TranslatableComponentSerializer extends BaseComponentSerializer implements JsonSerializer<TranslatableComponent>, JsonDeserializer<TranslatableComponent>
{
@Override
public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{

View File

@ -325,7 +325,7 @@ public class DownstreamBridge extends PacketHandler
out.writeUTF( "UUID" );
out.writeUTF( con.getUUID() );
}
if ( subChannel.equals("UUIDOther") )
if ( subChannel.equals( "UUIDOther" ) )
{
ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
if ( player != null )
@ -356,7 +356,7 @@ public class DownstreamBridge extends PacketHandler
{
def = null;
}
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, ComponentSerializer.parse(kick.getMessage()), def, ServerKickEvent.State.CONNECTED ) );
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTED ) );
if ( event.isCancelled() && event.getCancelServer() != null )
{
con.connectNow( event.getCancelServer() );

View File

@ -11,6 +11,7 @@ import org.junit.Test;
public class ComponentsTest
{
@Test
public void testBasicComponent()
{
@ -75,8 +76,8 @@ public class ComponentsTest
append( "!" ).color( ChatColor.YELLOW ).create();
Assert.assertEquals( "Hello World!", BaseComponent.toPlainText( components ) );
Assert.assertEquals( ChatColor.RED + "Hello " + ChatColor.BLUE + ChatColor.BOLD +
"World" + ChatColor.YELLOW + ChatColor.BOLD + "!", BaseComponent.toLegacyText( components ) );
Assert.assertEquals( ChatColor.RED + "Hello " + ChatColor.BLUE + ChatColor.BOLD
+ "World" + ChatColor.YELLOW + ChatColor.BOLD + "!", BaseComponent.toLegacyText( components ) );
}
}