Table of Contents

Class PlayerVoteManager

Namespace
Uncreated.Warfare.Players
Assembly
Uncreated.Warfare.dll

Manages a generic vote operation for all players. Displayed by VoteUIDisplay<TData>.

public class PlayerVoteManager : IPlayerVoteManager, IDisposable, IEventListener<PlayerJoined>, IEventListener<PlayerLeft>
Inheritance
PlayerVoteManager
Implements
Inherited Members

Constructors

PlayerVoteManager(ILoopTickerFactory, ILogger<PlayerVoteManager>)

public PlayerVoteManager(ILoopTickerFactory loopTickerFactory, ILogger<PlayerVoteManager> logger)

Parameters

loopTickerFactory ILoopTickerFactory
logger ILogger<PlayerVoteManager>

Properties

IsVoting

If there's a vote currently active.

public bool IsVoting { get; }

Property Value

bool

VoteEnd

The time at which the vote will end (UTC).

public DateTime VoteEnd { get; }

Property Value

DateTime

Exceptions

InvalidOperationException

Not voting.

VoteStart

The time at which the vote started (UTC).

public DateTime VoteStart { get; }

Property Value

DateTime

Exceptions

InvalidOperationException

Not voting.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

EndVoteAsync(CancellationToken, bool)

Ends the current vote

public UniTask EndVoteAsync(CancellationToken token = default, bool cancelled = false)

Parameters

token CancellationToken

Cancellation token used to cancel ending the vote.

cancelled bool

If the vote should be cancelled instead of ended.

Returns

UniTask

Exceptions

InvalidOperationException

Not voting.

GetVoteCount(PlayerVoteState)

Gets the number of votes in a certain state.

public int GetVoteCount(PlayerVoteState vote)

Parameters

vote PlayerVoteState

Returns

int

Exceptions

InvalidOperationException

Not voting.

GetVoteState(CSteamID)

Gets a player's current vote state (unanswered/yes/no).

public PlayerVoteState GetVoteState(CSteamID player)

Parameters

player CSteamID

Returns

PlayerVoteState

Exceptions

InvalidOperationException

Not voting.

RegisterVote(CSteamID, PlayerVoteState)

Registers a player's vote with the system, overriding their current vote if they've already voted.

public PlayerVoteState RegisterVote(CSteamID player, PlayerVoteState vote)

Parameters

player CSteamID

The player that's voting.

vote PlayerVoteState

Their vote, or Unanswered to remove thier vote.

Returns

PlayerVoteState

Their previous vote, or Unanswered if they hadn't voted.

Exceptions

InvalidOperationException

Not voting.

ArgumentOutOfRangeException

Invalid vote.

StartVoteAsync(VoteSettings, Action<IVoteResult>?, CancellationToken)

Starts a new vote.

public UniTask StartVoteAsync(VoteSettings settings, Action<IVoteResult>? callback, CancellationToken startCancellationToken = default)

Parameters

settings VoteSettings

General settings for the vote.

callback Action<IVoteResult>

Invoked when the vote is completed or cancelled.

startCancellationToken CancellationToken

Cancellation token used to cancel starting the vote, not the same as the token used to cancel the vote.

Returns

UniTask

Exceptions

InvalidOperationException

Already voting.