Package io.github.kosmx.emotes.api.proxy
Class AbstractNetworkInstance
java.lang.Object
io.github.kosmx.emotes.api.proxy.AbstractNetworkInstance
- All Implemented Interfaces:
INetworkInstance
Implement this if you want to act as a proxy for EmoteX
This has most of the functions implemented as you might want, but you can override any.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidWhen the network instance disconnects...seeINetworkInstance.getRemoteVersions()it is just a default implementationbooleanDoes the track the emote play state of every player -> true The client has to resend the emote if a new player get close -> falsevoidreceiveMessage(byte[] bytes) Receive message, but you don't know who sent this The bytes data has to contain the identity of the senderINetworkInstance.trustReceivedPlayer()should return true as you don't have your own identifier system as alternativevoidreceiveMessage(byte[] bytes, UUID player) Receive message with or without the sender's identitystatic byte[]safeGetBytesFromBuffer(ByteBuffer byteBuffer) IfByteBufferis wrapped, it is safe to get the array but if is direct manual read is required.voidsendC2SConfig(Consumer<EmotePacket.Builder> consumer) Client is sending config message to server.protected voidsendMessage(byte[] bytes, @Nullable UUID target) If you want to send byte arrayvoidsendMessage(EmotePacket.Builder builder, @Nullable UUID target) Send not prepared message, if you want to modify the message before sending, override this.voidsendMessage(ByteBuffer byteBuffer, @Nullable UUID target) Send a ByteBuffervoidsetVersions(HashMap<Byte, Byte> map) Default client-side version config, Please call super if you override it.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.kosmx.emotes.api.proxy.INetworkInstance
isActive, maxDataSize, presenceResponse, receiveMessage, sendPlayerID, trustReceivedPlayer
-
Constructor Details
-
AbstractNetworkInstance
public AbstractNetworkInstance()
-
-
Method Details
-
sendMessage
If you want to send byte arrayYou can wrap bytes to Netty
Unpooled.wrappedBuffer(bytes)or to Minecraft's PacketByteBuf (yarn mappings) / FriendlyByteBuf (official mappings)new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes))- Parameters:
bytes- bytes to sendtarget- target to send message, if null, everyone in the view distance
-
sendMessage
Send a ByteBuffer- Parameters:
byteBuffer- buffer to sendtarget- target to send message, if null, everyone in the view distance
-
sendMessage
public void sendMessage(EmotePacket.Builder builder, @Nullable @Nullable UUID target) throws IOException Send not prepared message, if you want to modify the message before sending, override this. You can call the super, but if you do, you'll need to override another.For example, you want to manipulate the data, before sending, override this, edit the builder, call its super then override
sendMessage(byte[], UUID)to send the bytes data- Specified by:
sendMessagein interfaceINetworkInstance- Parameters:
builder- EmotePacket buildertarget- target to send message, if null, everyone in the view distance- Throws:
IOException- throws IOException if packet writing has failed
-
receiveMessage
public void receiveMessage(byte[] bytes) Receive message, but you don't know who sent this The bytes data has to contain the identity of the senderINetworkInstance.trustReceivedPlayer()should return true as you don't have your own identifier system as alternative- Parameters:
bytes- message
-
receiveMessage
Receive message with or without the sender's identityYou can convert Netty ByteBuf (or Minecraft's packet buffer) to bytes[] with this snippet
if(byteBuf.isDirect() || byteBuf.isReadOnly()){ byte[] bytes = new byte[byteBuf.readableBytes()]; byteBuf.getBytes(byteBuf.readerIndex(), bytes); return bytes; } else { return byteBuf.array(); }- Parameters:
bytes- messageplayer- the sender player, null if unknown
-
disconnect
protected void disconnect()When the network instance disconnects... -
safeGetBytesFromBuffer
IfByteBufferis wrapped, it is safe to get the array but if is direct manual read is required.- Parameters:
byteBuffer- get the bytes from- Returns:
- the byte array
-
setVersions
Default client-side version config, Please call super if you override it.- Specified by:
setVersionsin interfaceINetworkInstance- Parameters:
map- version/config map
-
getRemoteVersions
seeINetworkInstance.getRemoteVersions()it is just a default implementation- Specified by:
getRemoteVersionsin interfaceINetworkInstance- Returns:
- maybe null
-
isServerTrackingPlayState
public boolean isServerTrackingPlayState()Description copied from interface:INetworkInstanceDoes the track the emote play state of every player -> true The client has to resend the emote if a new player get close -> false- Specified by:
isServerTrackingPlayStatein interfaceINetworkInstance
-
sendC2SConfig
Description copied from interface:INetworkInstanceClient is sending config message to server. Vanilla clients will answer to the server configuration phase message. This might get invoked multiple times on the same network instance.- Specified by:
sendC2SConfigin interfaceINetworkInstance
-