From 60e2e6bfa4d3c7fe54df4ebac5d00f39b5de63cb Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Sat, 7 Dec 2013 13:35:52 +0000 Subject: [PATCH] Add /alertraw command + fix events --- .../main/java/net/md_5/bungee/BungeeCord.java | 1 + .../bungee/chat/BaseComponentSerializer.java | 8 ++-- .../md_5/bungee/command/CommandAlertRaw.java | 45 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/command/CommandAlertRaw.java diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 4b746c95..37a754ee 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -137,6 +137,7 @@ public class BungeeCord extends ProxyServer getPluginManager().registerCommand( null, new CommandPerms() ); getPluginManager().registerCommand( null, new CommandSend() ); getPluginManager().registerCommand( null, new CommandFind() ); + getPluginManager().registerCommand( null, new CommandAlertRaw() ); registerChannel( "BungeeCord" ); } 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 65c3e6a4..f8d436ce 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 @@ -107,12 +107,14 @@ public class BaseComponentSerializer JsonObject clickEvent = new JsonObject(); clickEvent.addProperty( "action", component.getClickEvent().getAction().toString().toLowerCase() ); clickEvent.addProperty( "value", component.getClickEvent().getValue() ); + object.add( "clickEvent", clickEvent ); } if ( component.getHoverEvent() != null ) { - JsonObject clickEvent = new JsonObject(); - clickEvent.addProperty( "action", component.getHoverEvent().getAction().toString().toLowerCase() ); - clickEvent.add( "value", context.serialize( component.getHoverEvent().getValue() ) ); + JsonObject hoverEvent = new JsonObject(); + hoverEvent.addProperty( "action", component.getHoverEvent().getAction().toString().toLowerCase() ); + hoverEvent.add( "value", context.serialize( component.getHoverEvent().getValue() ) ); + object.add( "hoverEvent", hoverEvent ); } } } 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 new file mode 100644 index 00000000..5467d73a --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandAlertRaw.java @@ -0,0 +1,45 @@ +package net.md_5.bungee.command; + +import com.google.common.base.Joiner; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.plugin.Command; +import net.md_5.bungee.chat.ComponentSerializer; + +public class CommandAlertRaw extends Command +{ + + public CommandAlertRaw() + { + super( "alertraw", "bungeecord.command.alert" ); + } + + @Override + public void execute(CommandSender sender, String[] args) + { + if ( args.length == 0 ) + { + sender.sendMessage( ChatColor.RED + "You must supply a message." ); + } else + { + String message = Joiner.on(' ').join( args ); + + try { + ProxyServer.getInstance().broadcast( ComponentSerializer.parse( message ) ); + } catch ( Exception e ) { + TextComponent error = new TextComponent( "An error occurred while parsing your message. (Hover for details)" ); + error.setColor( ChatColor.RED ); + error.setUnderlined( true ); + + TextComponent errorMessage = new TextComponent( e.getMessage() ); + errorMessage.setColor( ChatColor.RED ); + + error.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, errorMessage ) ); + sender.sendMessage( error ); + } + } + } +}