public interface NucleusAFKService
Modifier and Type | Method and Description |
---|---|
boolean |
canBeKicked(org.spongepowered.api.entity.living.player.User user)
Returns whether a
User can be kicked for inactivity. |
boolean |
canGoAFK(org.spongepowered.api.entity.living.player.User user)
Returns whether the
User in question can go AFK. |
default NoExceptionAutoClosable |
disableTrackingForPlayer(org.spongepowered.api.entity.living.player.Player player)
Disables activity tracking for the specified
Player for the next
tick. |
NoExceptionAutoClosable |
disableTrackingForPlayer(org.spongepowered.api.entity.living.player.Player player,
int ticks)
Disables activity tracking for the specified
Player for up to the number of ticks specified. |
java.util.Collection<org.spongepowered.api.entity.living.player.Player> |
getAfk()
Returns a collection of players who are currently AFK.
|
void |
invalidateCachedPermissions()
Invalidates cached permissions, used to resync a player's exemption status.
|
boolean |
isAFK(org.spongepowered.api.entity.living.player.Player player)
Returns whether a player is AFK
|
java.time.Instant |
lastActivity(org.spongepowered.api.entity.living.player.Player player)
Returns the last recorded active moment of the player.
|
boolean |
setAFK(org.spongepowered.api.event.cause.Cause cause,
org.spongepowered.api.entity.living.player.Player player,
boolean isAfk)
Sets a player's AFK status, if the player can go AFK.
|
java.util.Optional<java.time.Duration> |
timeForInactivity(org.spongepowered.api.entity.living.player.User user)
Returns how long the specified
User has to be inactive before going AFK. |
java.util.Optional<java.time.Duration> |
timeForKick(org.spongepowered.api.entity.living.player.User user)
Returns how long the specified
User has to be inactive before being kicked. |
default java.time.Duration |
timeSinceLastActivity(org.spongepowered.api.entity.living.player.Player player)
Returns the
Duration since last recorded active moment of the player. |
void |
updateActivityForUser(org.spongepowered.api.entity.living.player.Player player)
Forces an activity tracking update for a
Player , such that Nucleus
thinks that the player has recently been active and resets their AFK timer. |
boolean canGoAFK(org.spongepowered.api.entity.living.player.User user)
User
in question can go AFK.user
- The User
in questionjava.util.Collection<org.spongepowered.api.entity.living.player.Player> getAfk()
Collection
of Player
sboolean isAFK(org.spongepowered.api.entity.living.player.Player player)
player
- The player in question.boolean setAFK(org.spongepowered.api.event.cause.Cause cause, org.spongepowered.api.entity.living.player.Player player, boolean isAfk)
cause
- The cause for going AFK. The root cause must be a PluginContainer
.player
- The player to set the status of.isAfk
- Whether the player should go AFK.true
if successful, otherwise false
, usually because the player is exempt from going AFK.boolean canBeKicked(org.spongepowered.api.entity.living.player.User user)
User
can be kicked for inactivity.user
- The User
in question.java.time.Instant lastActivity(org.spongepowered.api.entity.living.player.Player player)
player
- The player in questionInstant
default java.time.Duration timeSinceLastActivity(org.spongepowered.api.entity.living.player.Player player)
Duration
since last recorded active moment of the player.player
- The player in questionInstant
java.util.Optional<java.time.Duration> timeForInactivity(org.spongepowered.api.entity.living.player.User user)
User
has to be inactive before going AFK.user
- The User
in question.Duration
, or Optional.empty()
if the player cannot go AFK.java.util.Optional<java.time.Duration> timeForKick(org.spongepowered.api.entity.living.player.User user)
User
has to be inactive before being kicked.user
- The User
in question.Duration
, or Optional.empty()
if the player cannot go AFK.void invalidateCachedPermissions()
void updateActivityForUser(org.spongepowered.api.entity.living.player.Player player)
Player
, such that Nucleus
thinks that the player has recently been active and resets their AFK timer.player
- The player to update the activity of.default NoExceptionAutoClosable disableTrackingForPlayer(org.spongepowered.api.entity.living.player.Player player)
Player
for the next
tick. See disableTrackingForPlayer(Player, int)
for more
information on how to use this method.player
- Player to disable tracking for.AutoCloseable
that will re-enable the tracking when done.disableTrackingForPlayer(Player, int)
NoExceptionAutoClosable disableTrackingForPlayer(org.spongepowered.api.entity.living.player.Player player, int ticks)
Player
for up to the number of ticks specified.
This method returns an AutoCloseable
, and as such, the recommended way of using this method is using "try with resources":
try (AutoClosable dummy = disableTrackingFor(player, 1)){ // perform actions here, most likely something like: player.setLocation(location); // Any actions here will not disable the AFK timer. } // any actions here that move the player will be tracked again.
This pattern isn't strictly required, as the AutoCloseable
will close itself after the specified number of ticks. However, it's
prudent to consider the following:
disableTrackingForPlayer(Player)
for a sane
default.
If you do not use "try with resources", call the close
method upon completion to reactivate tracking.
player
- The Player
to disable tracking for.ticks
- The number of ticks to disable tracking for.AutoCloseable
that will re-enable the tracking when done.