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 void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { int index = readVarInt( buf ); // If we're working on 1.10 or lower, increment the value of the index so we pull out the correct value. if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_10 && index >= 2 ) { index++; } action = Action.values()[index]; switch ( action ) { case TITLE: case SUBTITLE: case ACTIONBAR: text = readString( buf ); break; case TIMES: fadeIn = buf.readInt(); stay = buf.readInt(); fadeOut = buf.readInt(); break; } }
@Override public Title subTitle(BaseComponent text) { if ( subtitle == null ) { subtitle = createPacket( Action.SUBTITLE ); } subtitle.setText( ComponentSerializer.toString( text ) ); return this; }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { int index = action.ordinal(); // If we're working on 1.10 or lower, increment the value of the index so we pull out the correct value. if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_10 && index >= 2 ) { index--; } writeVarInt( index, buf ); switch ( action ) { case TITLE: case SUBTITLE: case ACTIONBAR: writeString( text, buf ); break; case TIMES: buf.writeInt( fadeIn ); buf.writeInt( stay ); buf.writeInt( fadeOut ); break; } }
@Override public Title fadeOut(int ticks) { if ( times == null ) { times = createPacket( Action.TIMES ); } times.setFadeOut( ticks ); return this; }
@Override public Title stay(int ticks) { if ( times == null ) { times = createPacket( Action.TIMES ); } times.setStay( ticks ); return this; }
@Override public Title fadeIn(int ticks) { if ( times == null ) { times = createPacket( Action.TIMES ); } times.setFadeIn( ticks ); return this; }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeVarInt( action.ordinal(), buf ); switch ( action ) { case TITLE: case SUBTITLE: writeString( text, buf ); break; case TIMES: buf.writeInt( fadeIn ); buf.writeInt( stay ); buf.writeInt( fadeOut ); break; } }
@Override public Title fadeOut(int ticks) { if ( times == null ) { times = createPacket( Action.TIMES ); } times.setFadeOut( ticks ); return this; }
@Override public Title stay(int ticks) { if ( times == null ) { times = createPacket( Action.TIMES ); } times.setStay( ticks ); return this; }
@Override public Title fadeIn(int ticks) { if ( times == null ) { times = createPacket( Action.TIMES ); } times.setFadeIn( ticks ); return this; }
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 void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { action = Action.values()[readVarInt( buf )]; switch ( action ) { case TITLE: case SUBTITLE: text = readString( buf ); break; case TIMES: fadeIn = buf.readInt(); stay = buf.readInt(); fadeOut = buf.readInt(); break; } }
@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 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 title(BaseComponent text) { if ( title == null ) { title = createPacket( Action.TITLE ); } title.setText( ComponentSerializer.toString( text ) ); return this; }