diff --git a/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java index 9ef3cc30..a493332b 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java @@ -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 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() { diff --git a/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java b/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java index 55c66f30..222451d5 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java @@ -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 } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java b/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java index 57362883..16a0e2e1 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java @@ -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. *

- *

- *     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();
  * 
*

- * 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 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() ] ); } } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java b/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java index c2df8f9c..651549f7 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java @@ -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 diff --git a/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java index 9c297ecd..10b43910 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java @@ -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 ); } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java index f24d252d..900c4f36 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java @@ -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 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 diff --git a/api/src/main/java/net/md_5/bungee/api/event/PostLoginEvent.java b/api/src/main/java/net/md_5/bungee/api/event/PostLoginEvent.java index cd5e63dd..70660af3 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/PostLoginEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/PostLoginEvent.java @@ -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) diff --git a/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java index 2208b414..aea827b2 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java @@ -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 ); } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 8631e750..282a7bf0 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -33,63 +33,66 @@ public enum Protocol // Undef HANDSHAKE - { - - { - TO_SERVER.registerPacket( 0x00, Handshake.class ); - } - }, + { + + + { + TO_SERVER.registerPacket( 0x00, Handshake.class ); + } + }, // 0 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( 0x01, Chat.class ); - TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class ); - TO_SERVER.registerPacket( 0x15, ClientSettings.class ); - TO_SERVER.registerPacket( 0x17, PluginMessage.class ); - } - }, + TO_SERVER.registerPacket( 0x00, KeepAlive.class ); + TO_SERVER.registerPacket( 0x01, Chat.class ); + TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class ); + TO_SERVER.registerPacket( 0x15, ClientSettings.class ); + TO_SERVER.registerPacket( 0x17, PluginMessage.class ); + } + }, // 1 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 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 PROTOCOL_VERSION = 0x04; diff --git a/proxy/src/main/java/net/md_5/bungee/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/EntityMap.java index 26cb1616..5fa45d22 100644 --- a/proxy/src/main/java/net/md_5/bungee/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/EntityMap.java @@ -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 ); diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index b8e35b12..3fd2e982 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -68,7 +68,10 @@ public class ServerConnection implements Server @Override public void disconnect(BaseComponent reason) { - disconnect( new BaseComponent[]{reason} ); + disconnect( new BaseComponent[] + { + reason + } ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java b/proxy/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java index 7128dab9..92c13d93 100644 --- a/proxy/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java @@ -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.deserialize( event.get( "value" ), BaseComponent.class )}; + } else + { + res = new BaseComponent[] + { + context.deserialize( event.get( "value" ), BaseComponent.class ) + }; } component.setHoverEvent( new HoverEvent( HoverEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ), res ) ); } diff --git a/proxy/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java b/proxy/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java index c019f7ac..3c9df139 100644 --- a/proxy/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java @@ -30,7 +30,10 @@ public class ComponentSerializer implements JsonSerializer, 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) diff --git a/proxy/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java b/proxy/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java index 031590d6..4fc19984 100644 --- a/proxy/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java @@ -14,6 +14,7 @@ import java.lang.reflect.Type; public class TextComponentSerializer extends BaseComponentSerializer implements JsonSerializer, JsonDeserializer { + @Override public TextComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { diff --git a/proxy/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java b/proxy/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java index f48954a1..c01af268 100644 --- a/proxy/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/chat/TranslatableComponentSerializer.java @@ -15,6 +15,7 @@ import java.util.Arrays; public class TranslatableComponentSerializer extends BaseComponentSerializer implements JsonSerializer, JsonDeserializer { + @Override public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandAlertRaw.java b/proxy/src/main/java/net/md_5/bungee/command/CommandAlertRaw.java index 8b327e5c..0422e564 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandAlertRaw.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandAlertRaw.java @@ -42,10 +42,10 @@ public class CommandAlertRaw extends Command { sender.sendMessage( new ComponentBuilder( "An error occurred while parsing your message. (Hover for details)" ). - color( ChatColor.RED ).underlined( true ). - event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, + color( ChatColor.RED ).underlined( true ). + event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( error.getMessage() ).color( ChatColor.RED ).create() ) ). - create() ); + create() ); } else { sender.sendMessage( new ComponentBuilder( "An error occurred while parsing your message: " ).color( ChatColor.RED ).append( error.getMessage() ).create() ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 0e9ce932..ef930faf 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -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() ); diff --git a/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java b/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java index 898c2b5f..c206e60f 100644 --- a/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java +++ b/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java @@ -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 ) ); } }