onyx.scoreboard

class onyx.scoreboard.Expression(left_side, operator, right_side)

Expression - Represents a scoreboard check expression used for execute if/unless. Do not create manually. Use the expression operators on a Player object instead.

Parameters
  • left_side (str) – A stringified Player object

  • operator (str) – A string containing the operator

  • right_side (str) – A stringified Player object

Notes

Any function without an overridden operator can be added by doing the following:

from onyx.scoreboard import Player # Overload an operator for swap Player.__ior__ = Player.swap

A full list of potential operators to overload without breaking existing functionality is as follows:

  • __ipow__ (**=)

  • __ilshift__ (<<=)

  • __irshift__ (>>=)

  • __iand__ (&=)

  • __ior__ (|=)

  • __ixor__ (^=)

This list may change at any time, and this functionality is not supported. Just replace the proper things in the above example and you’re good to go.

class onyx.scoreboard.Player(parent, name)

Player - Represents a player on a scoreboard. Do not create manually. Use the Scoreboard.player method instead.

Parameters
  • parent (Scoreboard) – The parent Scoreboard object

  • name (str) – The player name. Automatically converted. A prefix of player_ is interpreted as a plain string. A prefix of _ is interpreted as a hidden player. Anything else is interpreted as a non-player player. Example: player_DoubleF3lix => DoubleF3lix, _DoubleF3lix => #DoubleF3lix, and DoubleF3lix => $DoubleF3lix.

set(value, init=False)

set - Sets the value of the scoreboard player

Parameters
  • value (int) – The value to set

  • init (bool, optional) – Whether or not this command should be put in the init function. Defaults to False.

Returns

Command

Return type

str

add(value)

add - Adds the value to the scoreboard player

Parameters

value (int) – The value to add

Returns

Command

Return type

str

subtract(value)

subtract - Subtracts the value from the scoreboard player

Parameters

value (int) – The value to subtract

Returns

Command

Return type

str

multiply(value)

multiply - Multiplies a number or another players score to the scoreboard player. If an integer is specified, a constant player will be created and that will be multiplied.

Parameters

value (int) – The value to multiply

Returns

Command

Return type

str

divide(value)

divide - Divides a number or another players score to the scoreboard player. If an integer is specified, a constant player will be created and that will be divided.

Parameters

value (int) – The value to divide

Returns

Command

Return type

str

modulo(value)

modulo - Applies a modulo a number or another players score to the scoreboard player. If an integer is specified, a constant player will be created and that will have the modulo applied. Essentially, this is self % value.

Parameters

value (int) – The value to apply a modulo with

Returns

Command

Return type

str

swap(value)

swap - Swaps the value of the scoreboard player with another player

Parameters

value (Player) – The player to swap with

Returns

Command

Return type

str

set_if_less(value)

set_if_less - Sets the scoreboard player to the value if it is less than it

Parameters

value (Player) – The value to compare against and set if it is less

Returns

Command

Return type

str

set_if_greater(value)

set_if_greater - Sets the scoreboard player to the value if it is greater than it

Parameters

value (Player) – The value to compare against and set if it is greater

Returns

Command

Return type

str

enable()

enable - Enables the scoreboard player for trigger

Returns

Command

Return type

str

get()

get - Gets the value of the scoreboard player. Only useful with execute store.

Returns

Command

Return type

str

reset()

reset - Removes the player from its parent scoreboard

Returns

Command

Return type

str

if_equal(value)

if_equal - Checks if the scoreboard player is equal to the given player. Used in execute if/unless.

Parameters

value (Union[Player, int, Range) – The scoreboard player or value to compare against

Returns

An expression object representing the comparison

Return type

Expression

if_less_than(value)

if_less_than - Checks if the scoreboard player is less than the given player. Used in execute if/unless.

Parameters

value (Player) – The scoreboard player to compare against. For checking numbers, use if_equal with a Range object.

Returns

An expression object representing the comparison

Return type

Expression

if_greater_than(value)

if_greater_than - Checks if the scoreboard player is greater than the given player. Used in execute if/unless.

Parameters

value (Player) – The scoreboard player to compare against. For checking numbers, use if_equal with a Range object.

Returns

An expression object representing the comparison

Return type

Expression

if_less_than_or_equal(value)

if_less_than_or_equal - Checks if the scoreboard player is less than or equal to the given player. Used in execute if/unless.

Parameters

value (Player) – The scoreboard player to compare against. For checking numbers, use if_equal with a Range object.

Returns

An expression object representing the comparison

Return type

Expression

if_greater_than_or_equal(value)

if_greater_than_or_equal - Checks if the scoreboard player is greater than or equal to the given player. Used in execute if/unless.

Parameters

value (Player) – The scoreboard player to compare against. For checking numbers, use if_equal with a Range object.

Returns

An expression object representing the comparison

Return type

Expression

class onyx.scoreboard.Scoreboard(name, create=False, criteria='dummy', display_name=None, players=None)

Scoreboard - Represents a scoreboard objective.

Parameters
  • name (str) – The name of the scoreboard

  • create (bool, optional) – Whether or not the scoreboard should be created. Defaults to False.

  • criteria (str, optional) – The criteria of the scoreboard. Only used if create is True. Defaults to “dummy”.

  • display_name (TextComponent, optional) – The display name of the scoreboard. Only used if create is True. Defaults to None.

  • players (dict, optional) – A dictionary of players to values. Only used if create is True. Defaults to None.

player(name)

player - Returns a player object representing the given player. See documentation for Player for more information. If an object with the same name already exists, it will be returned instead.

Parameters

name (str) – The player name. The player name. Automatically converted. A prefix of player_ is interpreted as a plain string. A prefix of _ is interpreted as a hidden player. Anything else is interpreted as a non-player player. Example: player_DoubleF3lix => DoubleF3lix, _DoubleF3lix => #DoubleF3lix, and DoubleF3lix => $DoubleF3lix.

Returns

A player object representing the given player.

Return type

Player

handle_operator(name, value)

handle_operator - Handles are player operators (except expression)

Parameters
  • name (str) – The player name

  • value (Union[Player, int]) – The value passed as the right side of the operator (with the player being the left)

Raises

ValueError – Swap operator was used with a number

Returns

Command

Return type

str

delete()

delete - Deletes the scoreboard objective

Returns

Command

Return type

str

reset()

reset - Resets all players on the scoreboard

Returns

Command

Return type

str

setdisplay(display)

setdisplay - Sets this scoreboard on a display

Parameters

display (scoreboard_display) – The display to set this scoreboard on

Returns

Command

Return type

str

modify(trait, value)

modify - Modifies a scoreboard trait

Parameters
Returns

Command

Return type

str

create(overwrite=False)

create - Creates the scoreboard

Parameters

overwrite (bool, optional) – If True, the scoreboard is deleted and then recreated. Defaults to False.

Returns

Command

Return type

str