Bungee join / part messages

This commit is contained in:
md_5 2013-04-13 18:17:08 +10:00
parent ac1119bef8
commit 7108bd4deb
4 changed files with 37 additions and 3 deletions

View File

@ -247,4 +247,11 @@ public abstract class ProxyServer
* @return the server's {@link AsyncHttpClient} instance
*/
public abstract AsyncHttpClient getHttpClient();
/**
* Send a message to all connected players.
*
* @param message the message to send
*/
public abstract void broadcast(String message);
}

View File

@ -403,4 +403,13 @@ public class BungeeCord extends ProxyServer
{
return ConsoleCommandSender.getInstance();
}
@Override
public void broadcast(String message)
{
for ( ProxiedPlayer player : getPlayers() )
{
player.sendMessage( message );
}
}
}

View File

@ -10,6 +10,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioSocketChannel;
import java.net.InetSocketAddress;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@ -85,6 +86,9 @@ public final class UserConnection implements ProxiedPlayer
{
addGroups( s );
}
//TODO: Here?
bungee.broadcast( MessageFormat.format( BungeeCord.getInstance().config.getJoinMessage(), getDisplayName() ) );
}
public void sendPacket(DefinedPacket p)
@ -188,6 +192,8 @@ public final class UserConnection implements ProxiedPlayer
{
server.disconnect( "Quitting" );
}
bungee.broadcast( MessageFormat.format( BungeeCord.getInstance().config.getPartMessage(), getDisplayName() ) );
}
}
@ -195,14 +201,20 @@ public final class UserConnection implements ProxiedPlayer
public void chat(String message)
{
Preconditions.checkState( server != null, "Not connected to server" );
if ( message != null && !message.isEmpty() )
{
server.getCh().write( new Packet3Chat( message ) );
}
}
@Override
public void sendMessage(String message)
{
if ( message != null && !message.isEmpty() )
{
ch.write( new Packet3Chat( message ) );
}
}
@Override
public void sendMessages(String... messages)

View File

@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.Map;
import java.util.UUID;
import lombok.Getter;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.config.ListenerInfo;
@ -49,6 +50,8 @@ public class Configuration
*/
private boolean onlineMode = true;
private int playerLimit = -1;
private String joinMessage = "&b{0} has joined the network";
private String partMessage = "&b{0} has left the network";
public void load()
{
@ -60,7 +63,10 @@ public class Configuration
onlineMode = adapter.getBoolean( "online_mode", onlineMode );
playerLimit = adapter.getInt( "player_limit", playerLimit );
DefaultTabList tab = DefaultTabList.valueOf( adapter.getString( "tab_list", "GLOBAL_PING" ) );
joinMessage = ChatColor.translateAlternateColorCodes( '&', adapter.getString( "messages.join", joinMessage ) );
partMessage = ChatColor.translateAlternateColorCodes( '&', adapter.getString( "messages.part", partMessage ) );
DefaultTabList tab = DefaultTabList.valueOf( adapter.getString( "tab_list", "GLOBAL_PING" ).toUpperCase() );
if ( tab == null )
{
tab = DefaultTabList.GLOBAL_PING;