|
CommandAPI 12.1.0
An API for the command UI introduced in Minecraft 1.13
|
A sequence of bytes that can be written to and read from. More...
Public Member Functions | |
| FriendlyByteBuffer () | |
Creates a new FriendlyByteBuffer with no bytes, ready to be written to. | |
| FriendlyByteBuffer (byte[] bytes) | |
Creates a new FriendlyByteBuffer with the given bytes already written, ready to be read from. | |
| void | checkReadIndexIsInBounds () throws IllegalStateException |
Checks if the current readIndex for this buffer is out of bounds. | |
| void | checkReadIndexIsInBounds (int readIndex) throws IllegalStateException |
Checks if the given readIndex is out of bounds. | |
| boolean | isReadIndexOutOfBounds () |
Evaluates if the current readIndex for this buffer is out of bounds. | |
| boolean | isReadIndexOutOfBounds (int readIndex) |
Evaluates if the given readIndex is out of bounds. | |
| void | checkWriteIndexIsInBounds () throws IllegalStateException |
Checks if the current writeIndex for this buffer is out of bounds. | |
| void | checkWriteIndexIsInBounds (int writeIndex) throws IllegalStateException |
Checks if the given writeIndex is out of bounds. | |
| boolean | isWriteIndexOutOfBounds () |
Evaluates if the current writeIndex for this buffer is out of bounds. | |
| boolean | isWriteIndexOutOfBounds (int writeIndex) |
Evaluates if the given writeIndex is out of bounds. | |
| int | getReadIndex () |
| void | setReadIndex (int index) throws IllegalStateException |
Sets the readIndex for this buffer. | |
| int | getWriteIndex () |
| void | setWriteIndex (int index) throws IllegalStateException |
Sets the writeIndex for this buffer. | |
| void | resetIndices () |
Sets the readIndex and writeIndex to 0. | |
| byte[] | toByteArray () throws IllegalStateException |
| byte[] | getRemainingBytes () throws IllegalStateException |
| int | countTotalBytes () |
| int | countReadableBytes () |
| void | writeByte (byte b) throws IllegalStateException |
| Writes a single byte (8 bits) into this buffer. | |
| void | writeByte (int i) throws IllegalStateException |
Writes a single byte (8 bits) into this buffer using writeByte(byte). | |
| byte | readByte () throws IllegalStateException |
| Reads a single byte (8 bits) from this buffer. | |
| void | writeBytes (byte... bytes) throws IllegalStateException |
| Writes multiple bytes to this buffer. | |
| byte[] | readBytes (int n) throws IllegalStateException |
Reads n bytes from this buffer. | |
| void | writeInt (int i) throws IllegalStateException |
| Writes a 32 bit int to this buffer. | |
| int | readInt () throws IllegalStateException |
| Reads a 32 bit int from this buffer. | |
| void | writeVarInt (int value) throws IllegalStateException |
| Writes a 32 bit int to this buffer using between 1 and 5 bytes, with small positive numbers using fewer bytes. | |
| int | readVarInt () throws IllegalStateException |
| Reads a 32 bit int from this buffer, encoded as a VarInt. | |
| void | writeString (String string, int maxLength) |
| Writes a String to this buffer. | |
| String | readString (int maxLength) throws IllegalStateException |
| Reads a String from this buffer. | |
A sequence of bytes that can be written to and read from.
Reading and writing is handled by two ints, the readIndex and writeIndex, which can be accessed using getReadIndex() and getWriteIndex() respectively. These indices are automatically incremented when reading and writing bytes. If the readIndex is ever greater than or equal to the writeIndex when a byte is read, an IllegalStateException will be thrown for attempting to read out of bounds.
This class provides methods that make it easier to read and write certain data types, using methods like readVarInt() and writeVarInt(int). These methods handle formatting the bytes correctly, letting developers simply worry about the structure of their data. If a specific method has a problem while reading bytes, an appropriate IllegalStateException will be thrown to indicate something is misformatted.
This buffer can be created empty (FriendlyByteBuffer()), or pre-written with a byte array (FriendlyByteBuffer(byte[])).
| dev.jorel.commandapi.network.FriendlyByteBuffer.FriendlyByteBuffer | ( | byte[] | bytes | ) |
Creates a new FriendlyByteBuffer with the given bytes already written, ready to be read from.
| bytes | The initial bytes to put in this buffer. This array is written to the buffer using writeBytes(byte...). |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.checkReadIndexIsInBounds | ( | ) | throws IllegalStateException |
Checks if the current readIndex for this buffer is out of bounds.
| IllegalStateException | If isReadIndexOutOfBounds() returns true. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.checkReadIndexIsInBounds | ( | int | readIndex | ) | throws IllegalStateException |
Checks if the given readIndex is out of bounds.
| readIndex | The index to check. |
| IllegalStateException | If isReadIndexOutOfBounds(int) returns true for the given readIndex. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.checkWriteIndexIsInBounds | ( | ) | throws IllegalStateException |
Checks if the current writeIndex for this buffer is out of bounds.
| IllegalStateException | If isWriteIndexOutOfBounds() returns true. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.checkWriteIndexIsInBounds | ( | int | writeIndex | ) | throws IllegalStateException |
Checks if the given writeIndex is out of bounds.
| writeIndex | The index to check. |
| IllegalStateException | If isWriteIndexOutOfBounds(int) returns true for the given writeIndex. |
| int dev.jorel.commandapi.network.FriendlyByteBuffer.countReadableBytes | ( | ) |
| int dev.jorel.commandapi.network.FriendlyByteBuffer.countTotalBytes | ( | ) |
| int dev.jorel.commandapi.network.FriendlyByteBuffer.getReadIndex | ( | ) |
readIndex for this buffer. | byte[] dev.jorel.commandapi.network.FriendlyByteBuffer.getRemainingBytes | ( | ) | throws IllegalStateException |
| IllegalStateException | If the current writeIndex is out of bounds according to checkWriteIndexIsInBounds(), or if the current readIndex is out of bounds according to checkReadIndexIsInBounds(). |
| int dev.jorel.commandapi.network.FriendlyByteBuffer.getWriteIndex | ( | ) |
writeIndex for this buffer. | boolean dev.jorel.commandapi.network.FriendlyByteBuffer.isReadIndexOutOfBounds | ( | ) |
Evaluates if the current readIndex for this buffer is out of bounds.
this.readIndex < 0 || this.readIndex >= this.writeIndex, and false otherwise. | boolean dev.jorel.commandapi.network.FriendlyByteBuffer.isReadIndexOutOfBounds | ( | int | readIndex | ) |
Evaluates if the given readIndex is out of bounds.
| readIndex | The index to check. |
readIndex < 0 || readIndex >= this.writeIndex, and false otherwise. | boolean dev.jorel.commandapi.network.FriendlyByteBuffer.isWriteIndexOutOfBounds | ( | ) |
Evaluates if the current writeIndex for this buffer is out of bounds.
this.writeIndex < 0, and false otherwise. | boolean dev.jorel.commandapi.network.FriendlyByteBuffer.isWriteIndexOutOfBounds | ( | int | writeIndex | ) |
Evaluates if the given writeIndex is out of bounds.
| writeIndex | The index to check. |
writeIndex < 0, and false otherwise. | byte dev.jorel.commandapi.network.FriendlyByteBuffer.readByte | ( | ) | throws IllegalStateException |
Reads a single byte (8 bits) from this buffer.
| IllegalStateException | If the readIndex is out of bounds according to checkReadIndexIsInBounds(). |
| byte[] dev.jorel.commandapi.network.FriendlyByteBuffer.readBytes | ( | int | n | ) | throws IllegalStateException |
Reads n bytes from this buffer.
This happens one at a time using readByte().
| n | The number of bytes to read. |
n bytes in this buffer. | IllegalStateException | If the read index goes out of bounds while reading bytes. |
| int dev.jorel.commandapi.network.FriendlyByteBuffer.readInt | ( | ) | throws IllegalStateException |
Reads a 32 bit int from this buffer.
This method assumes the int was written by writeInt(int).
| IllegalStateException | If the read index goes out of bounds while reading bytes. |
| String dev.jorel.commandapi.network.FriendlyByteBuffer.readString | ( | int | maxLength | ) | throws IllegalStateException |
Reads a String from this buffer.
This method assumes the String was written by writeString(String, int).
| maxLength | The length of the longest String that is allowed. |
| IllegalStateException | If the read String is longer than the given maximum length. |
| int dev.jorel.commandapi.network.FriendlyByteBuffer.readVarInt | ( | ) | throws IllegalStateException |
Reads a 32 bit int from this buffer, encoded as a VarInt.
This method assumes the VarInt was written by writeVarInt(int).
| IllegalStateException | If the read index goes out of bounds while reading bytes or if the VarInt is improperly formatted. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.resetIndices | ( | ) |
Sets the readIndex and writeIndex to 0.
This effectively clears this buffer, since future writes will overwrite the old bytes. The bytes are not actually forgotten, since if the write index is jumped forward, the bytes can still be read.
| void dev.jorel.commandapi.network.FriendlyByteBuffer.setReadIndex | ( | int | index | ) | throws IllegalStateException |
Sets the readIndex for this buffer.
This method checks the given index using isReadIndexOutOfBounds(int) to make sure it is not out of bounds before setting the index of this buffer.
| index | The new readIndex. |
| IllegalStateException | If the given index is out of bounds. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.setWriteIndex | ( | int | index | ) | throws IllegalStateException |
Sets the writeIndex for this buffer.
This method checks the given index using isWriteIndexOutOfBounds(int) to make sure it is not out of bounds before setting the index of this buffer.
| index | The new writeIndex. |
| IllegalStateException | If the given index is out of bounds. |
| byte[] dev.jorel.commandapi.network.FriendlyByteBuffer.toByteArray | ( | ) | throws IllegalStateException |
| IllegalStateException | If the current writeIndex is out of bounds according to checkWriteIndexIsInBounds(). |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.writeByte | ( | byte | b | ) | throws IllegalStateException |
Writes a single byte (8 bits) into this buffer.
| b | The byte to write. |
| IllegalStateException | If the writeIndex is out of bounds according to checkWriteIndexIsInBounds(). |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.writeByte | ( | int | i | ) | throws IllegalStateException |
Writes a single byte (8 bits) into this buffer using writeByte(byte).
| i | The byte to write, given as a 32-bit integer. Only the 8 least significant bits are written. |
| IllegalStateException | If the write index goes out of bounds while writing the byte. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.writeBytes | ( | byte... | bytes | ) | throws IllegalStateException |
Writes multiple bytes to this buffer.
This happens one at a time using writeByte(byte).
| bytes | An array of bytes to write. |
| IllegalStateException | If the write index goes out of bounds while writing bytes. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.writeInt | ( | int | i | ) | throws IllegalStateException |
Writes a 32 bit int to this buffer.
This method writes the int as 4 bytes, starting with the 8 most significant bits.
| i | The int to write. |
| IllegalStateException | If the write index goes out of bounds while writing bytes. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.writeString | ( | String | string, |
| int | maxLength ) |
Writes a String to this buffer.
The String is encoded as an array of bytes using the UTF-8 encoding. For the details of this encoding, see UTF-8 - Wikipedia
| string | The String to write. |
| maxLength | The length of the longest String that is allowed. |
| IllegalStateException | If the given String is longer than the given maximum length. |
| void dev.jorel.commandapi.network.FriendlyByteBuffer.writeVarInt | ( | int | value | ) | throws IllegalStateException |
Writes a 32 bit int to this buffer using between 1 and 5 bytes, with small positive numbers using fewer bytes.
For the details of this encoding, see VarInt and VarLong.
| value | The int to write. |
| IllegalStateException | If the write index goes out of bounds while writing bytes. |