Fix events not working when no formatting is used

This commit is contained in:
Thinkofdeath 2013-12-07 13:59:00 +00:00
parent 60e2e6bfa4
commit 0040955204
5 changed files with 22 additions and 13 deletions

View File

@ -277,7 +277,8 @@ public abstract class BaseComponent
{ {
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;
} }
public String toPlainText() public String toPlainText()
@ -320,6 +321,6 @@ public abstract class BaseComponent
@Override @Override
public String toString() public String toString()
{ {
return String.format( "BaseComponent{color=%s, bold=%b, italic=%b, underlined=%b, strikethrough=%b, obfuscated=%b}", getColor().getName(), isBold(), isItalic(), isUnderlined(), isStrikethrough(), isObfuscated() ); return String.format( "BaseComponent{color=%s, bold=%b, italic=%b, underlined=%b, strikethrough=%b, obfuscated=%b, clickEvent=%s, hoverEvent=%s}", getColor().getName(), isBold(), isItalic(), isUnderlined(), isStrikethrough(), isObfuscated(), getClickEvent(), getHoverEvent() );
} }
} }

View File

@ -22,4 +22,9 @@ public class ClickEvent
RUN_COMMAND, RUN_COMMAND,
SUGGEST_COMMAND SUGGEST_COMMAND
} }
@Override
public String toString() {
return String.format( "ClickEvent{action=%s, value=%s}", action, value );
}
} }

View File

@ -42,4 +42,9 @@ public class HoverEvent
SHOW_ACHIEVEMENT, SHOW_ACHIEVEMENT,
SHOW_ITEM SHOW_ITEM
} }
@Override
public String toString() {
return String.format( "HoverEvent{action=%s, value=%s}", action, value );
}
} }

View File

@ -41,7 +41,7 @@ public class BaseComponentSerializer
} }
if ( object.has( "extra" ) ) if ( object.has( "extra" ) )
{ {
component.setExtra( Arrays.asList( (BaseComponent[]) context.deserialize( object.get( "extra" ), BaseComponent[].class ) ) ); component.setExtra( Arrays.<BaseComponent>asList( context.<BaseComponent[]>deserialize( object.get( "extra" ), BaseComponent[].class ) ) );
} }
//Events //Events
@ -57,14 +57,8 @@ public class BaseComponentSerializer
JsonObject event = object.getAsJsonObject( "hoverEvent" ); JsonObject event = object.getAsJsonObject( "hoverEvent" );
HoverEvent hoverEvent = new HoverEvent(); HoverEvent hoverEvent = new HoverEvent();
hoverEvent.setAction( HoverEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ) ); hoverEvent.setAction( HoverEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ) );
Object res = context.deserialize( event.get( "value" ), BaseComponent.class ); BaseComponent res = context.deserialize( event.get( "value" ), BaseComponent.class );
if ( res instanceof String ) hoverEvent.setValue( res );
{
hoverEvent.setValue( (String) res );
} else
{
hoverEvent.setValue( (BaseComponent) res );
}
component.setHoverEvent( hoverEvent ); component.setHoverEvent( hoverEvent );
} }
} }

View File

@ -9,6 +9,8 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.ComponentSerializer;
import java.util.Arrays;
public class CommandAlertRaw extends Command public class CommandAlertRaw extends Command
{ {
@ -27,9 +29,11 @@ public class CommandAlertRaw extends Command
{ {
String message = Joiner.on(' ').join( args ); String message = Joiner.on(' ').join( args );
try { try
{
ProxyServer.getInstance().broadcast( ComponentSerializer.parse( message ) ); ProxyServer.getInstance().broadcast( ComponentSerializer.parse( message ) );
} catch ( Exception e ) { } catch ( Exception e )
{
TextComponent error = new TextComponent( "An error occurred while parsing your message. (Hover for details)" ); TextComponent error = new TextComponent( "An error occurred while parsing your message. (Hover for details)" );
error.setColor( ChatColor.RED ); error.setColor( ChatColor.RED );
error.setUnderlined( true ); error.setUnderlined( true );