Class ServerPlayerBadgeHandler

java.lang.Object
io.github.thecsdev.tcdcommons.api.badge.PlayerBadgeHandler
io.github.thecsdev.tcdcommons.api.badge.ServerPlayerBadgeHandler
All Implemented Interfaces:
it.unimi.dsi.fastutil.objects.ObjectIterable<it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<net.minecraft.util.Identifier>>, Iterable<it.unimi.dsi.fastutil.objects.Object2IntMap.Entry<net.minecraft.util.Identifier>>

public final class ServerPlayerBadgeHandler extends PlayerBadgeHandler
Same as a PlayerBadgeHandler, but it also keeps track of which ServerPlayerEntity it is assigned to.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.util.Identifier>
    For network optimization purposes, this map will keep track of entries that are yet to be sent to the client in a stats packet.
    protected final net.minecraft.server.network.ServerPlayerEntity
    The ServerPlayerEntity this ServerPlayerBadgeHandler is associated with.

    Fields inherited from class io.github.thecsdev.tcdcommons.api.badge.PlayerBadgeHandler

    PBH_CUSTOM_DATA_ID, statMap
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServerPlayerBadgeHandler(net.minecraft.server.network.ServerPlayerEntity player)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    announceEarnedBadge(net.minecraft.server.network.ServerPlayerEntity player, net.minecraft.util.Identifier badgeId)
    Broadcasts a server-wide message announcing a ServerPlayerEntity earning a PlayerBadge.
    net.minecraft.server.network.ServerPlayerEntity
    Returns the ServerPlayerEntity associated with this ServerPlayerBadgeHandler.
    getServerBadgeHandler(net.minecraft.server.network.ServerPlayerEntity player)
    Retrieves the PlayerBadgeHandler for a given ServerPlayerEntity.
    If one doesn't exist, a new one is created, assigned, and then returned.
    final void
    loadFromPlayerNbt(net.minecraft.nbt.NbtCompound nbt)
    Used to load badge data for the current ServerPlayerEntity.
    final net.minecraft.nbt.NbtCompound
    saveToPlayerNbt(net.minecraft.nbt.NbtCompound nbt)
    Used to save badge data for the current ServerPlayerEntity.
    final boolean
    sendStats(net.minecraft.server.network.ServerPlayerEntity player)
    Sends a given ServerPlayerEntity a list of their PlayerBadges that have been assigned to them.
    final void
    setValue(net.minecraft.util.Identifier badgeId, int value)
    Sets the Integer value associated with a PlayerBadge's Identifier.
    protected final it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.util.Identifier>
    Collects pending statistics entries and clears the pendingStatMap.

    Methods inherited from class io.github.thecsdev.tcdcommons.api.badge.PlayerBadgeHandler

    clearBadges, getValue, increaseValue, iterator, toMapByModId

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface it.unimi.dsi.fastutil.objects.ObjectIterable

    spliterator
  • Field Details

    • player

      protected final net.minecraft.server.network.ServerPlayerEntity player
      The ServerPlayerEntity this ServerPlayerBadgeHandler is associated with.
    • pendingStatMap

      protected final it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.util.Identifier> pendingStatMap
      For network optimization purposes, this map will keep track of entries that are yet to be sent to the client in a stats packet.
  • Constructor Details

    • ServerPlayerBadgeHandler

      public ServerPlayerBadgeHandler(net.minecraft.server.network.ServerPlayerEntity player)
  • Method Details

    • getPlayer

      public net.minecraft.server.network.ServerPlayerEntity getPlayer()
      Returns the ServerPlayerEntity associated with this ServerPlayerBadgeHandler.
    • setValue

      public final void setValue(net.minecraft.util.Identifier badgeId, int value) throws NullPointerException
      Description copied from class: PlayerBadgeHandler
      Sets the Integer value associated with a PlayerBadge's Identifier.
      Overrides:
      setValue in class PlayerBadgeHandler
      Parameters:
      badgeId - The PlayerBadge's unique Identifier.
      value - The new value.
      Throws:
      NullPointerException
    • takePendingStats

      protected final it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.util.Identifier> takePendingStats()
      Collects pending statistics entries and clears the pendingStatMap.
      Returns:
      A copy of the pending statistics entries.
    • loadFromPlayerNbt

      public final void loadFromPlayerNbt(net.minecraft.nbt.NbtCompound nbt)
      Used to load badge data for the current ServerPlayerEntity.
      Parameters:
      nbt - The NbtCompound that belongs to the player that is about to be loaded.
      Throws:
      NullPointerException - when an argument is null.
      See Also:
    • saveToPlayerNbt

      public final net.minecraft.nbt.NbtCompound saveToPlayerNbt(net.minecraft.nbt.NbtCompound nbt)
      Used to save badge data for the current ServerPlayerEntity.
      Parameters:
      nbt - The NbtCompound that belongs to the player that is about to be saved.
      Returns:
      The NbtCompound that was passed as the argument.
      Throws:
      NullPointerException - when an argument is null.
      See Also:
    • sendStats

      public final boolean sendStats(net.minecraft.server.network.ServerPlayerEntity player)
      Sends a given ServerPlayerEntity a list of their PlayerBadges that have been assigned to them.
      Parameters:
      player - The target ServerPlayerEntity.
      Returns:
      True if the packet was sent, and false if the packet was not sent because the player doesn't have any PlayerBadges assigned to them.
    • getServerBadgeHandler

      public static ServerPlayerBadgeHandler getServerBadgeHandler(net.minecraft.server.network.ServerPlayerEntity player)
      Retrieves the PlayerBadgeHandler for a given ServerPlayerEntity.
      If one doesn't exist, a new one is created, assigned, and then returned.
      Parameters:
      player - The ServerPlayerEntity in question.
      Throws:
      NullPointerException - When an argument is null.
    • announceEarnedBadge

      public static boolean announceEarnedBadge(net.minecraft.server.network.ServerPlayerEntity player, net.minecraft.util.Identifier badgeId)
      Broadcasts a server-wide message announcing a ServerPlayerEntity earning a PlayerBadge.
      Parameters:
      player - The player in question.
      badgeId - The Identifier of the PlayerBadge they earned.
      Returns:
      true if the CONFIG does not block the broadcast.