Expand streams a little bit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MinecraftInput
|
||||
{
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public byte readByte()
|
||||
{
|
||||
return buf.readByte();
|
||||
}
|
||||
|
||||
public short readUnisgnedByte()
|
||||
{
|
||||
return buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
public int readInt()
|
||||
{
|
||||
return buf.readInt();
|
||||
}
|
||||
|
||||
public String readString()
|
||||
{
|
||||
short len = buf.readShort();
|
||||
char[] c = new char[ len ];
|
||||
for ( int i = 0; i < c.length; i++ )
|
||||
{
|
||||
c[i] = buf.readChar();
|
||||
}
|
||||
|
||||
return new String( c );
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MinecraftOutput
|
||||
{
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public MinecraftOutput()
|
||||
{
|
||||
buf = Unpooled.buffer();
|
||||
}
|
||||
|
||||
public byte[] toArray()
|
||||
{
|
||||
if ( buf.hasArray() )
|
||||
{
|
||||
return Arrays.copyOfRange( buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.writerIndex() );
|
||||
} else
|
||||
{
|
||||
byte[] b = new byte[ buf.writerIndex() ];
|
||||
buf.readBytes( b );
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public MinecraftOutput writeByte(byte b)
|
||||
{
|
||||
buf.writeByte( b );
|
||||
return this;
|
||||
}
|
||||
|
||||
public void writeInt(int i)
|
||||
{
|
||||
buf.writeInt( i );
|
||||
}
|
||||
|
||||
public void writeString(String s)
|
||||
{
|
||||
char[] cc = s.toCharArray();
|
||||
buf.writeShort( cc.length );
|
||||
for ( char c : cc )
|
||||
{
|
||||
buf.writeChar( c );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MinecraftStream
|
||||
{
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public byte readByte()
|
||||
{
|
||||
return buf.readByte();
|
||||
}
|
||||
|
||||
public MinecraftStream writeByte(byte b)
|
||||
{
|
||||
buf.writeByte( b );
|
||||
return this;
|
||||
}
|
||||
/*========================================================================*/
|
||||
|
||||
public short readUnisgnedByte()
|
||||
{
|
||||
return buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
/*========================================================================*/
|
||||
public int readInt()
|
||||
{
|
||||
return buf.readInt();
|
||||
}
|
||||
|
||||
public void writeInt(int i)
|
||||
{
|
||||
buf.writeInt( i );
|
||||
}
|
||||
/*========================================================================*/
|
||||
|
||||
public String readString()
|
||||
{
|
||||
short len = buf.readShort();
|
||||
char[] c = new char[ len ];
|
||||
for ( int i = 0; i < c.length; i++ )
|
||||
{
|
||||
c[i] = buf.readChar();
|
||||
}
|
||||
|
||||
return new String( c );
|
||||
}
|
||||
|
||||
public void writeString(String s)
|
||||
{
|
||||
char[] cc = s.toCharArray();
|
||||
buf.writeShort( cc.length );
|
||||
for ( char c : cc )
|
||||
{
|
||||
buf.writeChar( c );
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,7 +8,8 @@ import java.io.DataInputStream;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.protocol.MinecraftStream;
|
||||
import net.md_5.bungee.protocol.MinecraftInput;
|
||||
import net.md_5.bungee.protocol.MinecraftOutput;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@@ -56,8 +57,8 @@ public class PacketFAPluginMessage extends DefinedPacket
|
||||
return new DataInputStream( new ByteArrayInputStream( data ) );
|
||||
}
|
||||
|
||||
public MinecraftStream getMCStream()
|
||||
public MinecraftInput getMCStream()
|
||||
{
|
||||
return new MinecraftStream( Unpooled.wrappedBuffer( data ) );
|
||||
return new MinecraftInput( Unpooled.wrappedBuffer( data ) );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user