Class AbstractNetworkInstance

java.lang.Object
io.github.kosmx.emotes.api.proxy.AbstractNetworkInstance
All Implemented Interfaces:
INetworkInstance

public abstract class AbstractNetworkInstance extends Object implements 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 Details

    • AbstractNetworkInstance

      public AbstractNetworkInstance()
  • Method Details

    • sendMessage

      protected void sendMessage(byte[] bytes, @Nullable @Nullable UUID target)
      If you want to send byte array

      You 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 send
      target - target to send message, if null, everyone in the view distance
    • sendMessage

      public void sendMessage(ByteBuffer byteBuffer, @Nullable @Nullable UUID target)
      Send a ByteBuffer
      Parameters:
      byteBuffer - buffer to send
      target - 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:
      sendMessage in interface INetworkInstance
      Parameters:
      builder - EmotePacket builder
      target - 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 sender INetworkInstance.trustReceivedPlayer() should return true as you don't have your own identifier system as alternative
      Parameters:
      bytes - message
    • receiveMessage

      public void receiveMessage(byte[] bytes, UUID player)
      Receive message with or without the sender's identity

      You 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 - message
      player - the sender player, null if unknown
    • disconnect

      protected void disconnect()
      When the network instance disconnects...
    • safeGetBytesFromBuffer

      public static byte[] safeGetBytesFromBuffer(ByteBuffer byteBuffer)
      If ByteBuffer is 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

      public void setVersions(HashMap<Byte,Byte> map)
      Default client-side version config, Please call super if you override it.
      Specified by:
      setVersions in interface INetworkInstance
      Parameters:
      map - version/config map
    • getRemoteVersions

      public HashMap<Byte,Byte> getRemoteVersions()
      see INetworkInstance.getRemoteVersions() it is just a default implementation
      Specified by:
      getRemoteVersions in interface INetworkInstance
      Returns:
      maybe null
    • isServerTrackingPlayState

      public boolean isServerTrackingPlayState()
      Description copied from interface: INetworkInstance
      Does 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:
      isServerTrackingPlayState in interface INetworkInstance
    • sendC2SConfig

      public void sendC2SConfig(Consumer<EmotePacket.Builder> consumer)
      Description copied from interface: INetworkInstance
      Client 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:
      sendC2SConfig in interface INetworkInstance