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()
      Determines the flag resolution for this context.

      If the player has bypass permissions in the region, the flag state is set to ALLOWED. Otherwise, the flag state is determined by the region's flag settings.

      Returns:
      The FlagState representing the resolved flag and its state.
    • inheritContext

      public FlagContext inheritContext(FlagContext parent)
      Resolves the effective FlagContext by considering whether this context should be overridden by a parent context. This method resolves flag inheritance based on the following rules:
      • If the parent flag has an override, the parent context is returned.
      • If the parent flag is set, the child flag is not set, and the player does not have a bypass permission, the parent context is returned.
      • Otherwise, the current context is retained.
      This method is typically used in recursive flag resolution, ensuring that higher-priority regions or inherited flag settings take effect when applicable.
      Parameters:
      parent - the parent FlagContext to inherit from, 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