Package de.z0rdak.yawp.core.flag
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 Summary
ConstructorsConstructorDescriptionFlagContext(IProtectedRegion region, RegionFlag regionFlag, @Nullable IFlag flag, @Nullable net.minecraft.world.entity.player.Player player) Creates an instance of aFlagContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.@Nullable IFlagflag()Returns the value of theflagrecord component.final inthashCode()Returns a hash code value for this object.inheritContext(FlagContext parent) Determines whichFlagContextshould take effect by applying inheritance logic between this context and a given parent context.static FlagContextparentOf(IProtectedRegion region, RegionFlag regionFlag, @Nullable net.minecraft.world.entity.player.Player player) Creates aFlagContextfor the parent region of the given region.@Nullable net.minecraft.world.entity.player.Playerplayer()Returns the value of theplayerrecord component.region()Returns the value of theregionrecord component.Returns the value of theregionFlagrecord component.Resolves the effectiveFlagStatefor this context, accounting for whether the flag is player-specific, beneficial, and whether the player has a bypass permission.final StringtoString()Returns a string representation of this record class.
-
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 aFlagContextrecord class.- Parameters:
region- the value for theregionrecord componentregionFlag- the value for theregionFlagrecord componentflag- the value for theflagrecord componentplayer- the value for theplayerrecord component
-
-
Method Details
-
resultingState
Resolves the effectiveFlagStatefor 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 isFlagState.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 region’s flag state is
FlagState.ALLOWEDorFlagState.DENIED, the result isFlagState.ALLOWED. - Otherwise, the result is
FlagState.DISABLED.
- If the region’s flag state is
- 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.
- If the flag is beneficial and the player has a bypass permission:
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
- If the flag is
-
inheritContext
Determines whichFlagContextshould 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 parentFlagContextto compare against, must not benull- Returns:
- the effective
FlagContextafter applying inheritance rules
- If the parent context’s flag exists, is set, and is marked as overriding
(
-
parentOf
public static FlagContext parentOf(IProtectedRegion region, RegionFlag regionFlag, @Nullable @Nullable net.minecraft.world.entity.player.Player player) Creates aFlagContextfor the parent region of the given region.This method retrieves the parent region of the specified
regionand constructs aFlagContextusing the parent's flag value for the givenRegionFlag.- Parameters:
region- the region whose parent context is to be determined, must not benullregionFlag- the flag for which the context is being created, must not benullplayer- the player associated with this flag context, may benull- Returns:
- a
FlagContextrepresenting the flag state in the parent region
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
region
Returns the value of theregionrecord component.- Returns:
- the value of the
regionrecord component
-
regionFlag
Returns the value of theregionFlagrecord component.- Returns:
- the value of the
regionFlagrecord component
-
flag
Returns the value of theflagrecord component.- Returns:
- the value of the
flagrecord component
-
player
@Nullable public @Nullable net.minecraft.world.entity.player.Player player()Returns the value of theplayerrecord component.- Returns:
- the value of the
playerrecord component
-