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

View File

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

View File

@ -7,30 +7,30 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* ComponentBuilder simplifies creating basic messages by allowing * ComponentBuilder simplifies creating basic messages by allowing the use of a
* the use of a chainable builder. * chainable builder.
* <p/> * <p/>
* <pre> * <
* new ComponentBuilder("Hello ").color(ChatColor.RED). * pre>
* append("World").color(ChatColor.BLUE). * new ComponentBuilder("Hello ").color(ChatColor.RED).
* append("!").bold(true).create(); * append("World").color(ChatColor.BLUE). append("!").bold(true).create();
* </pre> * </pre>
* <p/> * <p/>
* All methods (excluding {@link #append(String)} and {@link #create()} * All methods (excluding {@link #append(String)} and {@link #create()} work on
* work on the last part appended to the builder, so in the example * the last part appended to the builder, so in the example above "Hello " would
* above "Hello " would be {@link net.md_5.bungee.api.ChatColor#RED} * be {@link net.md_5.bungee.api.ChatColor#RED} and "World" would be
* and "World" would be {@link net.md_5.bungee.api.ChatColor#BLUE} but * {@link net.md_5.bungee.api.ChatColor#BLUE} but "!" would be bold and
* "!" would be bold and {@link net.md_5.bungee.api.ChatColor#BLUE} * {@link net.md_5.bungee.api.ChatColor#BLUE} because append copies the previous
* because append copies the previous part's formatting * part's formatting
*/ */
public class ComponentBuilder public class ComponentBuilder
{ {
private TextComponent current; private TextComponent current;
private List<BaseComponent> parts = new ArrayList<>(); private List<BaseComponent> parts = new ArrayList<>();
/** /**
* Creates a ComponentBuilder with the given text as the * Creates a ComponentBuilder with the given text as the first part.
* first part.
* *
* @param text the first text element * @param text the first text element
*/ */
@ -40,9 +40,8 @@ public class ComponentBuilder
} }
/** /**
* Appends the text to the builder and makes it the current * Appends the text to the builder and makes it the current target for
* target for formatting. The text will have all the * formatting. The text will have all the formatting from the previous part.
* formatting from the previous part.
* *
* @param text the text to append * @param text the text to append
* @return this ComponentBuilder for chaining * @return this ComponentBuilder for chaining
@ -129,7 +128,7 @@ public class ComponentBuilder
/** /**
* Sets the click event for the current part. * Sets the click event for the current part.
* *
* @param clickEvent the click event * @param clickEvent the click event
* @return this ComponentBuilder for chaining * @return this ComponentBuilder for chaining
*/ */
@ -141,7 +140,7 @@ public class ComponentBuilder
/** /**
* Sets the hover event for the current part. * Sets the hover event for the current part.
* *
* @param hoverEvent the hover event * @param hoverEvent the hover event
* @return this ComponentBuilder for chaining * @return this ComponentBuilder for chaining
*/ */
@ -152,14 +151,14 @@ public class ComponentBuilder
} }
/** /**
* Returns the components needed to display the message * Returns the components needed to display the message created by this
* created by this builder. * builder.
* *
* @return the created components * @return the created components
*/ */
public BaseComponent[] create() public BaseComponent[] create()
{ {
parts.add( current ); 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 @AllArgsConstructor
final public class HoverEvent final public class HoverEvent
{ {
private final Action action; private final Action action;
private final BaseComponent[] value; private final BaseComponent[] value;
public enum Action public enum Action
{ {
SHOW_TEXT, SHOW_TEXT,
SHOW_ACHIEVEMENT, SHOW_ACHIEVEMENT,
SHOW_ITEM 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*)?$" ); 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} * Converts the old formatting system that used
* into the new json based system. * {@link net.md_5.bungee.api.ChatColor#COLOR_CHAR} into the new json based
* system.
*
* @param message the text to convert * @param message the text to convert
* @return the components needed to print the message to the client * @return the components needed to print the message to the client
*/ */
@ -79,7 +81,10 @@ public class TextComponent extends BaseComponent
continue; continue;
} }
int pos = message.indexOf( ' ', i ); int pos = message.indexOf( ' ', i );
if ( pos == -1 ) pos = message.length(); if ( pos == -1 )
{
pos = message.length();
}
if ( matcher.region( i, pos ).find() ) if ( matcher.region( i, pos ).find() )
{ //Web link handling { //Web link handling
@ -112,22 +117,23 @@ public class TextComponent extends BaseComponent
} }
//The client will crash if the array is empty //The client will crash if the array is empty
if ( components.size() == 0 ) { if ( components.size() == 0 )
{
components.add( new TextComponent( "" ) ); 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 * The text of the component that will be displayed to the client
* displayed to the client
*/ */
private String text; private String text;
/** /**
* Creates a TextComponent with formatting and text * Creates a TextComponent with formatting and text from the passed
* from the passed component * component
*
* @param textComponent the component to copy from * @param textComponent the component to copy from
*/ */
public TextComponent(TextComponent textComponent) public TextComponent(TextComponent textComponent)
@ -147,11 +153,26 @@ public class TextComponent extends BaseComponent
protected void toLegacyText(StringBuilder builder) protected void toLegacyText(StringBuilder builder)
{ {
builder.append( getColor() ); builder.append( getColor() );
if ( isBold() ) builder.append( ChatColor.BOLD ); if ( isBold() )
if ( isItalic() ) builder.append( ChatColor.ITALIC ); {
if ( isUnderlined() ) builder.append( ChatColor.UNDERLINE ); builder.append( ChatColor.BOLD );
if ( isStrikethrough() ) builder.append( ChatColor.STRIKETHROUGH ); }
if ( isObfuscated() ) builder.append( ChatColor.MAGIC ); 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 ); builder.append( text );
super.toLegacyText( builder ); super.toLegacyText( builder );
} }

View File

@ -17,13 +17,13 @@ import java.util.regex.Pattern;
@NoArgsConstructor @NoArgsConstructor
public class TranslatableComponent extends BaseComponent public class TranslatableComponent extends BaseComponent
{ {
private 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 * The key into the Minecraft locale files to use for the translation. The
* translation. The text depends on the client's locale setting. * text depends on the client's locale setting. The console is always en_US
* The console is always en_US
*/ */
private String translate; private String translate;
/** /**
@ -33,11 +33,13 @@ public class TranslatableComponent extends BaseComponent
/** /**
* Creates a translatable component with the passed substitutions * Creates a translatable component with the passed substitutions
*
* @see #setTranslate(String) * @see #setTranslate(String)
* @see #setWith(java.util.List) * @see #setWith(java.util.List)
* @param translate the translation key * @param translate the translation key
* @param with the {@link java.lang.String}s and {@link net.md_5.bungee.api.chat.BaseComponent}s * @param with the {@link java.lang.String}s and
* to use into the translation * {@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)
{ {
@ -57,9 +59,9 @@ public class TranslatableComponent extends BaseComponent
} }
/** /**
* Sets the translation substitutions to be used in * Sets the translation substitutions to be used in this component. Removes
* this component. Removes any previously set * any previously set substitutions
* substitutions *
* @param components the components to substitute * @param components the components to substitute
*/ */
public void setWith(List<BaseComponent> components) 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 * Adds a text substitution to the component. The text will inherit this
* inherit this component's formatting * component's formatting
* *
* @param text the text to substitute * @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 * Adds a component substitution to the component. The text will inherit
* inherit this component's formatting * this component's formatting
* *
* @param component the component to substitute * @param component the component to substitute
*/ */
@ -189,11 +191,26 @@ public class TranslatableComponent extends BaseComponent
private void addFormat(StringBuilder builder) private void addFormat(StringBuilder builder)
{ {
builder.append( getColor() ); builder.append( getColor() );
if ( isBold() ) builder.append( ChatColor.BOLD ); if ( isBold() )
if ( isItalic() ) builder.append( ChatColor.ITALIC ); {
if ( isUnderlined() ) builder.append( ChatColor.UNDERLINE ); builder.append( ChatColor.BOLD );
if ( isStrikethrough() ) builder.append( ChatColor.STRIKETHROUGH ); }
if ( isObfuscated() ) builder.append( ChatColor.MAGIC ); 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 @Override

View File

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

View File

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

View File

@ -33,63 +33,66 @@ public enum Protocol
// Undef // Undef
HANDSHAKE HANDSHAKE
{ {
{
TO_SERVER.registerPacket( 0x00, Handshake.class ); {
} TO_SERVER.registerPacket( 0x00, Handshake.class );
}, }
},
// 0 // 0
GAME GAME
{ {
{
TO_CLIENT.registerPacket( 0x00, KeepAlive.class );
TO_CLIENT.registerPacket( 0x01, Login.class );
TO_CLIENT.registerPacket( 0x02, Chat.class );
TO_CLIENT.registerPacket( 0x07, Respawn.class );
TO_CLIENT.registerPacket( 0x38, PlayerListItem.class );
TO_CLIENT.registerPacket( 0x3A, TabCompleteResponse.class );
TO_CLIENT.registerPacket( 0x3B, ScoreboardObjective.class );
TO_CLIENT.registerPacket( 0x3C, ScoreboardScore.class );
TO_CLIENT.registerPacket( 0x3D, ScoreboardDisplay.class );
TO_CLIENT.registerPacket( 0x3E, Team.class );
TO_CLIENT.registerPacket( 0x3F, PluginMessage.class );
TO_CLIENT.registerPacket( 0x40, Kick.class );
{
TO_CLIENT.registerPacket( 0x00, KeepAlive.class );
TO_CLIENT.registerPacket( 0x01, Login.class );
TO_CLIENT.registerPacket( 0x02, Chat.class );
TO_CLIENT.registerPacket( 0x07, Respawn.class );
TO_CLIENT.registerPacket( 0x38, PlayerListItem.class );
TO_CLIENT.registerPacket( 0x3A, TabCompleteResponse.class );
TO_CLIENT.registerPacket( 0x3B, ScoreboardObjective.class );
TO_CLIENT.registerPacket( 0x3C, ScoreboardScore.class );
TO_CLIENT.registerPacket( 0x3D, ScoreboardDisplay.class );
TO_CLIENT.registerPacket( 0x3E, Team.class );
TO_CLIENT.registerPacket( 0x3F, PluginMessage.class );
TO_CLIENT.registerPacket( 0x40, Kick.class );
TO_SERVER.registerPacket( 0x00, KeepAlive.class ); TO_SERVER.registerPacket( 0x00, KeepAlive.class );
TO_SERVER.registerPacket( 0x01, Chat.class ); TO_SERVER.registerPacket( 0x01, Chat.class );
TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class ); TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class );
TO_SERVER.registerPacket( 0x15, ClientSettings.class ); TO_SERVER.registerPacket( 0x15, ClientSettings.class );
TO_SERVER.registerPacket( 0x17, PluginMessage.class ); TO_SERVER.registerPacket( 0x17, PluginMessage.class );
} }
}, },
// 1 // 1
STATUS STATUS
{ {
{
TO_CLIENT.registerPacket( 0x00, StatusResponse.class );
TO_CLIENT.registerPacket( 0x01, PingPacket.class );
TO_SERVER.registerPacket( 0x00, StatusRequest.class );
TO_SERVER.registerPacket( 0x01, PingPacket.class ); {
} TO_CLIENT.registerPacket( 0x00, StatusResponse.class );
}, TO_CLIENT.registerPacket( 0x01, PingPacket.class );
TO_SERVER.registerPacket( 0x00, StatusRequest.class );
TO_SERVER.registerPacket( 0x01, PingPacket.class );
}
},
//2 //2
LOGIN LOGIN
{ {
{
TO_CLIENT.registerPacket( 0x00, Kick.class );
TO_CLIENT.registerPacket( 0x01, EncryptionRequest.class );
TO_CLIENT.registerPacket( 0x02, LoginSuccess.class );
TO_SERVER.registerPacket( 0x00, LoginRequest.class );
TO_SERVER.registerPacket( 0x01, EncryptionResponse.class ); {
} TO_CLIENT.registerPacket( 0x00, Kick.class );
}; TO_CLIENT.registerPacket( 0x01, EncryptionRequest.class );
TO_CLIENT.registerPacket( 0x02, LoginSuccess.class );
TO_SERVER.registerPacket( 0x00, LoginRequest.class );
TO_SERVER.registerPacket( 0x01, EncryptionResponse.class );
}
};
/*========================================================================*/ /*========================================================================*/
public static final int MAX_PACKET_ID = 0xFF; public static final int MAX_PACKET_ID = 0xFF;
public static final int PROTOCOL_VERSION = 0x04; public static final int PROTOCOL_VERSION = 0x04;

View File

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

View File

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

View File

@ -56,10 +56,15 @@ public class BaseComponentSerializer
{ {
JsonObject event = object.getAsJsonObject( "hoverEvent" ); JsonObject event = object.getAsJsonObject( "hoverEvent" );
BaseComponent[] res; BaseComponent[] res;
if (event.get("value").isJsonArray()) { if ( event.get( "value" ).isJsonArray() )
{
res = context.deserialize( event.get( "value" ), BaseComponent[].class ); res = context.deserialize( event.get( "value" ), BaseComponent[].class );
} else { } else
res = new BaseComponent[]{context.<BaseComponent>deserialize( event.get( "value" ), BaseComponent.class )}; {
res = new BaseComponent[]
{
context.<BaseComponent>deserialize( event.get( "value" ), BaseComponent.class )
};
} }
component.setHoverEvent( new HoverEvent( HoverEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ), res ) ); 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 { //Array
return gson.fromJson( json, BaseComponent[].class ); 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) 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> public class TextComponentSerializer extends BaseComponentSerializer implements JsonSerializer<TextComponent>, JsonDeserializer<TextComponent>
{ {
@Override @Override
public TextComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException 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> public class TranslatableComponentSerializer extends BaseComponentSerializer implements JsonSerializer<TranslatableComponent>, JsonDeserializer<TranslatableComponent>
{ {
@Override @Override
public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{ {

View File

@ -42,10 +42,10 @@ public class CommandAlertRaw extends Command
{ {
sender.sendMessage( sender.sendMessage(
new ComponentBuilder( "An error occurred while parsing your message. (Hover for details)" ). new ComponentBuilder( "An error occurred while parsing your message. (Hover for details)" ).
color( ChatColor.RED ).underlined( true ). color( ChatColor.RED ).underlined( true ).
event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, event( new HoverEvent( HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder( error.getMessage() ).color( ChatColor.RED ).create() ) ). new ComponentBuilder( error.getMessage() ).color( ChatColor.RED ).create() ) ).
create() ); create() );
} else } else
{ {
sender.sendMessage( new ComponentBuilder( "An error occurred while parsing your message: " ).color( ChatColor.RED ).append( error.getMessage() ).create() ); sender.sendMessage( new ComponentBuilder( "An error occurred while parsing your message: " ).color( ChatColor.RED ).append( error.getMessage() ).create() );

View File

@ -325,7 +325,7 @@ public class DownstreamBridge extends PacketHandler
out.writeUTF( "UUID" ); out.writeUTF( "UUID" );
out.writeUTF( con.getUUID() ); out.writeUTF( con.getUUID() );
} }
if ( subChannel.equals("UUIDOther") ) if ( subChannel.equals( "UUIDOther" ) )
{ {
ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
if ( player != null ) if ( player != null )
@ -356,7 +356,7 @@ public class DownstreamBridge extends PacketHandler
{ {
def = null; 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 ) if ( event.isCancelled() && event.getCancelServer() != null )
{ {
con.connectNow( event.getCancelServer() ); con.connectNow( event.getCancelServer() );

View File

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