Class BetterStatsServerPlayNetworkHandler

java.lang.Object
io.github.thecsdev.betterstats.network.BetterStatsServerPlayNetworkHandler

@Internal public final class BetterStatsServerPlayNetworkHandler extends Object
Better statistics screen server play network handler.
Keeps track of ServerPlayerEntity data that is related to BetterStats.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.minecraft.util.Identifier
    The unique Identifier for obtaining an instance of this network handler for a given player entity, via EntityHooks.getCustomData(Entity).
    boolean
    When set to true, this should never be switched back to false.
    Indicates whether or not the associated player has BetterStats installed.
    long
    The timestamp at which the last live stats update was performed.
    boolean
    When set to true, the BetterStatsNetwork will automatically update the client on their stats changes, live.
    boolean
    The player's preference on having their statistics shared with third-party sources such as other players.
  • Method Summary

    Modifier and Type
    Method
    Description
    final net.minecraft.server.network.ServerPlayerEntity
     
    of(net.minecraft.server.network.ServerPlayerEntity player)
    Returns an instance of BetterStatsServerPlayNetworkHandler for a given ServerPlayerEntity.
    final void
    onIHaveBss(io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetworkReceiver.PacketContext ctx)
    Handles the player letting this server know they have BetterStats installed.
    final void
    onMcbsRequest(io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetworkReceiver.PacketContext ctx)
    Handles player's requests for MCBS files.
    final void
    Handles the player joining event.
    final void
    onPreferences(io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetworkReceiver.PacketContext ctx)
    Handles the player's preference changes for things like the "live hud stats updates" feature.
    final void
    Tells the player that this server has BetterStats installed.
    final boolean
    Makes an attempt to send a live statistics update to the player.
    final void
    Sends an indicator that the MCBS for a given player is "null".
    final boolean
    sendPlayerMcbs(net.minecraft.server.network.ServerPlayerEntity targetPlayer, boolean force)
    Sends an MCBS file of a given ServerPlayerEntity, to the player.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CUSTOM_DATA_ID

      public static final net.minecraft.util.Identifier CUSTOM_DATA_ID
      The unique Identifier for obtaining an instance of this network handler for a given player entity, via EntityHooks.getCustomData(Entity).
    • hasBssInstalled

      public boolean hasBssInstalled
      When set to true, this should never be switched back to false.
      Indicates whether or not the associated player has BetterStats installed.
    • netPref_enableLiveStats

      public boolean netPref_enableLiveStats
      When set to true, the BetterStatsNetwork will automatically update the client on their stats changes, live.
    • liveStatsLastUpdate

      public long liveStatsLastUpdate
      The timestamp at which the last live stats update was performed. Used to avoid packet spam.
    • netPref_statsSharingConsent

      public boolean netPref_statsSharingConsent
      The player's preference on having their statistics shared with third-party sources such as other players.
  • Method Details

    • getPlayer

      public final net.minecraft.server.network.ServerPlayerEntity getPlayer()
    • onPlayerConnected

      public final void onPlayerConnected()
      Handles the player joining event.
    • onIHaveBss

      public final void onIHaveBss(io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetworkReceiver.PacketContext ctx)
      Handles the player letting this server know they have BetterStats installed.
    • onPreferences

      public final void onPreferences(io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetworkReceiver.PacketContext ctx)
      Handles the player's preference changes for things like the "live hud stats updates" feature.
    • onMcbsRequest

      public final void onMcbsRequest(io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetworkReceiver.PacketContext ctx)
      Handles player's requests for MCBS files.
    • sendIHaveBss

      public final void sendIHaveBss()
      Tells the player that this server has BetterStats installed.
    • sendLiveStatsAttepmt

      public final boolean sendLiveStatsAttepmt()
      Makes an attempt to send a live statistics update to the player. The attempt may fail if the player does not have BetterStats installed or if this method is being called too frequently.
    • sendPlayerMcbs

      public final boolean sendPlayerMcbs(net.minecraft.server.network.ServerPlayerEntity targetPlayer, boolean force) throws NullPointerException
      Sends an MCBS file of a given ServerPlayerEntity, to the player.
      Parameters:
      targetPlayer - The ServerPlayerEntity whose MCBS is to be sent.
      force - When true, this will ignore the ServerPlayerEntity lack of consent.
      Throws:
      NullPointerException
    • sendNullPlayerMcbs

      public final void sendNullPlayerMcbs(String playerName) throws NullPointerException
      Sends an indicator that the MCBS for a given player is "null". The purpose of this is usually to let the client know that a given player's statistics cannot be shared because said player is currently offline.
      Throws:
      NullPointerException
      See Also:
    • of

      public static final BetterStatsServerPlayNetworkHandler of(net.minecraft.server.network.ServerPlayerEntity player) throws NullPointerException
      Returns an instance of BetterStatsServerPlayNetworkHandler for a given ServerPlayerEntity. Creates one if it doesn't exist yet.
      Parameters:
      player - The ServerPlayerEntity.
      Throws:
      NullPointerException