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) Resolves the effectiveFlagContextby considering whether this context should be overridden by a 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.Determines the flag resolution for this context.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
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
FlagStaterepresenting the resolved flag and its state.
-
inheritContext
Resolves the effectiveFlagContextby 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.
- Parameters:
parent- the parentFlagContextto inherit from, must not benull- Returns:
- the effective
FlagContextafter applying inheritance rules
-
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
-