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>>
Same as a
PlayerBadgeHandler
, but it also keeps track
of which ServerPlayerEntity
it is assigned to.-
Field Summary
Modifier and TypeFieldDescriptionprotected 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
TheServerPlayerEntity
thisServerPlayerBadgeHandler
is associated with.Fields inherited from class io.github.thecsdev.tcdcommons.api.badge.PlayerBadgeHandler
PBH_CUSTOM_DATA_ID, statMap
-
Constructor Summary
ConstructorDescriptionServerPlayerBadgeHandler
(net.minecraft.server.network.ServerPlayerEntity player) -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
announceEarnedBadge
(net.minecraft.server.network.ServerPlayerEntity player, net.minecraft.util.Identifier badgeId) Broadcasts a server-wide message announcing aServerPlayerEntity
earning aPlayerBadge
.net.minecraft.server.network.ServerPlayerEntity
Returns theServerPlayerEntity
associated with thisServerPlayerBadgeHandler
.static ServerPlayerBadgeHandler
getServerBadgeHandler
(net.minecraft.server.network.ServerPlayerEntity player) Retrieves thePlayerBadgeHandler
for a givenServerPlayerEntity
.
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 currentServerPlayerEntity
.final net.minecraft.nbt.NbtCompound
saveToPlayerNbt
(net.minecraft.nbt.NbtCompound nbt) Used to save badge data for the currentServerPlayerEntity
.final boolean
sendStats
(net.minecraft.server.network.ServerPlayerEntity player) Sends a givenServerPlayerEntity
a list of theirPlayerBadge
s that have been assigned to them.final void
setValue
(net.minecraft.util.Identifier badgeId, int value) protected final it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.util.Identifier>
Collects pending statistics entries and clears thependingStatMap
.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 it.unimi.dsi.fastutil.objects.ObjectIterable
spliterator
-
Field Details
-
player
protected final net.minecraft.server.network.ServerPlayerEntity playerTheServerPlayerEntity
thisServerPlayerBadgeHandler
is associated with. -
pendingStatMap
protected final it.unimi.dsi.fastutil.objects.Object2IntMap<net.minecraft.util.Identifier> pendingStatMapFor 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 theServerPlayerEntity
associated with thisServerPlayerBadgeHandler
. -
setValue
public final void setValue(net.minecraft.util.Identifier badgeId, int value) throws NullPointerException Description copied from class:PlayerBadgeHandler
- Overrides:
setValue
in classPlayerBadgeHandler
- Parameters:
badgeId
- ThePlayerBadge
's uniqueIdentifier
.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 thependingStatMap
.- 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 currentServerPlayerEntity
.- Parameters:
nbt
- TheNbtCompound
that belongs to theplayer
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 currentServerPlayerEntity
.- Parameters:
nbt
- TheNbtCompound
that belongs to theplayer
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 givenServerPlayerEntity
a list of theirPlayerBadge
s that have been assigned to them.- Parameters:
player
- The targetServerPlayerEntity
.- Returns:
- True if the packet was sent, and false if the packet was not sent
because the player doesn't have any
PlayerBadge
s assigned to them.
-
getServerBadgeHandler
public static ServerPlayerBadgeHandler getServerBadgeHandler(net.minecraft.server.network.ServerPlayerEntity player) Retrieves thePlayerBadgeHandler
for a givenServerPlayerEntity
.
If one doesn't exist, a new one is created, assigned, and then returned.- Parameters:
player
- TheServerPlayerEntity
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 aServerPlayerEntity
earning aPlayerBadge
.- Parameters:
player
- The player in question.badgeId
- TheIdentifier
of thePlayerBadge
they earned.- Returns:
true
if theCONFIG
does not block the broadcast.
-