Record Class FlagContext

java.lang.Object
java.lang.Record
de.z0rdak.yawp.core.flag.FlagContext
Record Components:
region - The protected region where the flag is being evaluated.
regionFlag - The flag being checked.
flag - The resolved flag value, if already determined (nullable).
player - The player for whom the flag is being evaluated (nullable).

public record FlagContext(IProtectedRegion region, RegionFlag regionFlag, @Nullable IFlag flag, @Nullable net.minecraft.world.entity.player.Player player) extends Record
Represents the context for evaluating a flag within a protected region.

This record stores the region being checked, the specific flag under evaluation, an optional pre-determined flag value, and the player (if applicable) for permission checks.

  • Constructor Details

    • FlagContext

      public FlagContext(IProtectedRegion region, RegionFlag regionFlag, @Nullable @Nullable IFlag flag, @Nullable @Nullable net.minecraft.world.entity.player.Player player)
      Creates an instance of a FlagContext record class.
      Parameters:
      region - the value for the region record component
      regionFlag - the value for the regionFlag record component
      flag - the value for the flag record component
      player - the value for the player record component
  • Method Details

    • resultingState

      public FlagState resultingState()
      Resolves the effective FlagState for this context, accounting for whether the flag is player-specific, beneficial, and whether the player has a bypass permission.

      The resolution logic is as follows:

      • If the flag is null, the result is FlagState.UNDEFINED.
      • If the flag is not player-specific, the result is taken directly from the region’s flag configuration via RegionFlags.flagState(String).
      • If the flag is player-specific:
        • If the flag is beneficial and the player has a bypass permission:
        • If the flag is beneficial and the player lacks a bypass permission, the result is the region’s defined FlagState.
        • If the flag is non-beneficial and the player has a bypass permission, the result is FlagState.DISABLED.
        • If the flag is non-beneficial and the player lacks a bypass permission, the result is the region’s defined FlagState.

      This method ensures that bypass permissions never result in a denied outcome, and that beneficial flags are treated permissively for players with bypass privileges.

      Returns:
      the resolved FlagState, reflecting region configuration, flag characteristics, and player permissions
    • inheritContext

      public FlagContext inheritContext(FlagContext parent)
      Determines which FlagContext should take effect by applying inheritance logic between this context and a given parent context.

      The resolution follows these rules:

      • If the parent context’s flag exists, is set, and is marked as overriding (flag.doesOverride()), the parent context takes precedence.
      • If the parent’s flag is set but the child’s flag is not set, the parent context takes precedence.
      • In all other cases (including when neither flag is set), the current context is retained.

      This method is used during recursive flag resolution to ensure that inherited or overriding flag values from parent regions take effect only when explicitly allowed.

      Parameters:
      parent - the parent FlagContext to compare against, must not be null
      Returns:
      the effective FlagContext after applying inheritance rules
    • parentOf

      public static FlagContext parentOf(IProtectedRegion region, RegionFlag regionFlag, @Nullable @Nullable net.minecraft.world.entity.player.Player player)
      Creates a FlagContext for the parent region of the given region.

      This method retrieves the parent region of the specified region and constructs a FlagContext using the parent's flag value for the given RegionFlag.

      Parameters:
      region - the region whose parent context is to be determined, must not be null
      regionFlag - the flag for which the context is being created, must not be null
      player - the player associated with this flag context, may be null
      Returns:
      a FlagContext representing the flag state in the parent region
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • region

      public IProtectedRegion region()
      Returns the value of the region record component.
      Returns:
      the value of the region record component
    • regionFlag

      public RegionFlag regionFlag()
      Returns the value of the regionFlag record component.
      Returns:
      the value of the regionFlag record component
    • flag

      @Nullable public @Nullable IFlag flag()
      Returns the value of the flag record component.
      Returns:
      the value of the flag record component
    • player

      @Nullable public @Nullable net.minecraft.world.entity.player.Player player()
      Returns the value of the player record component.
      Returns:
      the value of the player record component