Add Title API.
This commit is contained in:
@@ -9,6 +9,7 @@ import com.google.common.collect.Sets;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.Title;
|
||||
import net.md_5.bungee.module.ModuleManager;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@@ -636,4 +637,10 @@ public class BungeeCord extends ProxyServer
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title createTitle()
|
||||
{
|
||||
return new BungeeTitle();
|
||||
}
|
||||
}
|
||||
|
166
proxy/src/main/java/net/md_5/bungee/BungeeTitle.java
Normal file
166
proxy/src/main/java/net/md_5/bungee/BungeeTitle.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package net.md_5.bungee;
|
||||
|
||||
import net.md_5.bungee.api.Title;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.Title.Action;
|
||||
|
||||
public class BungeeTitle implements Title
|
||||
{
|
||||
private net.md_5.bungee.protocol.packet.Title title, subtitle, times, clear, reset;
|
||||
|
||||
private static net.md_5.bungee.protocol.packet.Title createPacket(Action action)
|
||||
{
|
||||
net.md_5.bungee.protocol.packet.Title title = new net.md_5.bungee.protocol.packet.Title();
|
||||
title.setAction( action );
|
||||
|
||||
if ( action == Action.TIMES )
|
||||
{
|
||||
// Set packet to default values first
|
||||
title.setFadeIn( 20 );
|
||||
title.setStay( 60 );
|
||||
title.setFadeOut( 20 );
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title title(BaseComponent text)
|
||||
{
|
||||
if ( title == null )
|
||||
{
|
||||
title = createPacket( Action.TITLE );
|
||||
}
|
||||
|
||||
title.setText( ComponentSerializer.toString( text ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title title(BaseComponent... text)
|
||||
{
|
||||
if ( title == null )
|
||||
{
|
||||
title = createPacket( Action.TITLE );
|
||||
}
|
||||
|
||||
title.setText( ComponentSerializer.toString( text ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title subTitle(BaseComponent text)
|
||||
{
|
||||
if ( subtitle == null )
|
||||
{
|
||||
subtitle = createPacket( Action.SUBTITLE );
|
||||
}
|
||||
|
||||
subtitle.setText( ComponentSerializer.toString( text ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title subTitle(BaseComponent... text)
|
||||
{
|
||||
if ( subtitle == null )
|
||||
{
|
||||
subtitle = createPacket( Action.SUBTITLE );
|
||||
}
|
||||
|
||||
subtitle.setText( ComponentSerializer.toString( text ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title fadeIn(int ticks)
|
||||
{
|
||||
if ( times == null )
|
||||
{
|
||||
times = createPacket( Action.TIMES );
|
||||
}
|
||||
|
||||
times.setFadeIn( ticks );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title stay(int ticks)
|
||||
{
|
||||
if ( times == null )
|
||||
{
|
||||
times = createPacket( Action.TIMES );
|
||||
}
|
||||
|
||||
times.setStay( ticks );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title fadeOut(int ticks)
|
||||
{
|
||||
if ( times == null )
|
||||
{
|
||||
times = createPacket( Action.TIMES );
|
||||
}
|
||||
|
||||
times.setFadeOut( ticks );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title clear()
|
||||
{
|
||||
if ( clear == null )
|
||||
{
|
||||
clear = createPacket( Action.CLEAR );
|
||||
}
|
||||
|
||||
title = null; // No need to send title if we clear it after that again
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title reset()
|
||||
{
|
||||
if ( reset == null )
|
||||
{
|
||||
reset = createPacket( Action.RESET );
|
||||
}
|
||||
|
||||
// No need to send these packets if we reset them later
|
||||
title = null;
|
||||
subtitle = null;
|
||||
times = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private static void sendPacket(ProxiedPlayer player, DefinedPacket packet)
|
||||
{
|
||||
if ( packet != null )
|
||||
{
|
||||
player.unsafe().sendPacket( packet );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title send(ProxiedPlayer player)
|
||||
{
|
||||
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
// Send the packets in the correct order
|
||||
sendPacket( player, clear );
|
||||
sendPacket( player, reset );
|
||||
sendPacket( player, times );
|
||||
sendPacket( player, subtitle );
|
||||
sendPacket( player, title );
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.Title;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@@ -504,6 +505,12 @@ public final class UserConnection implements ProxiedPlayer
|
||||
setTabHeader( (BaseComponent) null, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(Title title)
|
||||
{
|
||||
title.send( this );
|
||||
}
|
||||
|
||||
public void setCompressionThreshold(int compressionThreshold)
|
||||
{
|
||||
if ( this.compressionThreshold == -1 )
|
||||
|
Reference in New Issue
Block a user