Constructors

  • Parameters

    • code: string
    • OptionalsavedDetails: {
          expirationTime: number;
          id: string;
          maxUses: bigint;
          redeemers: string[];
          uses: bigint;
      }

    Returns Globals.modules.main.RedeemableCode

Properties

code: string

The code that users enter to redeem this code.

expirationTime: number = -1

When this code should expire.

Set it to -1 to make it never expire.

id: string

The super unique ID of this code.

maxUses: bigint = -1n

The maximum number of uses allowed for this code.

Set it to -1n to make the max uses infinite.

redeemers: string[] = []

List of UUIDs of players who have redeemed this code.

[]
uses: bigint = 0n

How many times this code has been used.

0n

Methods

  • Retrieves the saved item linked to this code.

    This method places a structure at the given location, searches for an entity with a specific dynamic property, retrieves the item from the entity's inventory, and then removes the entity.

    Parameters

    • loadLocation: DimensionLocation

      The location in the dimension where the structure containing the item storage entity is to be spawned.

    Returns ItemStack

    The item stack retrieved from the entity's inventory.

    If no entity with the specified dynamic property is found.

  • Redeems a code for the given player. This method checks if the code has reached its maximum number of uses or if the player has already redeemed the code. If neither condition is met, it spawns the item for the player, adds the player to the list of redeemers, and saves the state.

    Parameters

    • player: Player

      The player who is redeeming the code.

    Returns void

    If the code has reached the maximum number of uses.

    If the player has already redeemed the code.

  • Removes the current redeemable code from the list of codes, saves the updated list, and deletes the corresponding structure in the world structure manager.

    Returns void

    This method filters out the current code from the codes array, saves the updated list of codes by calling RedeemableCode.saveCodes(), and deletes the structure associated with this redeemable code using the world.structureManager.delete method.

  • Saves the current redeemable code instance.

    This method performs the following actions:

    1. Filters out any existing code that matches the current instance's code or id.
    2. Adds the current instance to the list of codes.
    3. Calls the static method saveCodes to persist the updated list of codes.

    Returns void

  • Sets the item linked to this code.

    Parameters

    • item: ItemStack

      The item to be set in the storage entity.

    • saveLocation: DimensionLocation

      The location where the item should be saved, including the dimension.

      This method performs the following steps:

      1. Retrieves and temporarily teleports other entities away from the save location.
      2. Spawns a storage entity at the save location and sets the item in its inventory.
      3. Saves the storage entity to the world structure manager.
      4. Removes the storage entity after saving.
      5. Teleports the other entities back to their original locations.

    Returns void

  • Converts the RedeemableCode instance to a JSONB object.

    Returns {
        code: string;
        expirationTime: number;
        id: string;
        maxUses: bigint;
        redeemers: string[];
        uses: bigint;
    }

    An object containing the code, id, redeemers, uses, max uses, and expiration time of the RedeemableCode instance.

  • Returns void

  • Parameters

    Returns void

  • Parameters

    • code: string

    Returns void

  • Returns void