Add /alertraw command + fix events

This commit is contained in:
Thinkofdeath 2013-12-07 13:35:52 +00:00
parent 2cb3b6f934
commit 60e2e6bfa4
3 changed files with 51 additions and 3 deletions

View File

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

View File

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

View File

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