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

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,7 +117,8 @@ 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( "" ) );
} }
@ -120,14 +126,14 @@ public class TextComponent extends BaseComponent
} }
/** /**
* 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

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

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

@ -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 ) );
} }
} }