Record Class FlagEvaluator

java.lang.Object
java.lang.Record
de.z0rdak.yawp.api.FlagEvaluator

public record FlagEvaluator(FlagCheckResult result) extends Record
  • Constructor Details

    • FlagEvaluator

      public FlagEvaluator(FlagCheckResult result)
      Creates an instance of a FlagEvaluator record class.
      Parameters:
      result - the value for the result record component
  • Method Details

    • state

      public FlagState state()
    • onAllow

      public FlagEvaluator onAllow(Consumer<FlagCheckResult> action)
    • onDeny

      public FlagEvaluator onDeny(Consumer<FlagCheckResult> action)
    • onDenyWithMsg

      public FlagEvaluator onDenyWithMsg(Consumer<FlagCheckResult> action)
    • onDefault

      public FlagEvaluator onDefault(Consumer<FlagCheckResult> action)
    • processCheck

      public static FlagState processCheck(@NotNull @NotNull FlagCheckEvent checkEvent, @Nullable @Nullable Consumer<FlagCheckResult> onAllow, @Nullable @Nullable Consumer<FlagCheckResult> onDeny)
      Processes a flag check event and executes the corresponding consumer based on the result.

      The given flag check event is evaluated to determine the flag state and then posted to the event bus for further processing. If the flag state is ALLOWED, the onAllow consumer is executed. If the flag state is DENIED, the onDeny consumer is executed.

      Parameters:
      checkEvent - the flag check event to process, must not be null
      onAllow - the consumer to execute if the flag is allowed, may be null
      onDeny - the consumer to execute if the flag is denied, may be null
      Returns:
      the resulting FlagState after processing the event
    • process

      public static FlagEvaluator process(@NotNull @NotNull FlagCheckEvent checkEvent)
    • processCheckF

      public static FlagState processCheckF(@NotNull @NotNull FlagCheckEvent checkEvent, @Nullable @Nullable Function<FlagCheckResult,FlagState> handleResult)
    • processCheck

      public static FlagState processCheck(@NotNull @NotNull FlagCheckEvent checkEvent, @Nullable @Nullable Consumer<FlagCheckResult> onDeny)
      Processes the given flag check event and executes the given consumer if the flag is denied.

      This overload is equivalent to calling processCheck(FlagCheckEvent, Consumer, Consumer) with onAllow set to null.

      Parameters:
      checkEvent - the flag check event to process, must not be null
      onDeny - the consumer to execute if the flag is denied
      Returns:
      the resulting FlagState after processing
      See Also:
    • processCheck

      public static FlagState processCheck(@NotNull @NotNull FlagCheckEvent checkEvent)
      Processes the given flag check event with default behavior.

      This overload is equivalent to calling processCheck(FlagCheckEvent, Consumer, Consumer) with both consumers set to null.

      Parameters:
      checkEvent - the flag check event to process, must not be null
      Returns:
      the resulting FlagState after processing
      See Also:
    • evaluate

      public static FlagCheckResult evaluate(FlagCheckEvent checkEvent)
      Evaluates a flag check event by determining the responsible region, resolving the flag context, and computing the resulting flag state.

      The evaluation follows these steps:

      • Finds the responsible region for the given target and dimension.
      • If no region is found, returns an undefined FlagCheckResult.
      • Constructs a FlagContext using the region, flag, and player information.
      • Resolves the effective flag context by considering inheritance and overrides.
      • Returns a FlagCheckResult containing the determined flag state and context details.
      Parameters:
      checkEvent - the flag check event containing information about the target, dimension, and flag.
      Returns:
      a FlagCheckResult representing the evaluated flag state and context.
    • resolveFlag

      public static FlagContext resolveFlag(IProtectedRegion region, FlagContext flagContext)
      Resolves the final FlagContext for a given region by considering flag inheritance from parent regions. The initial flag context needs to be the flag context corresponding to the given region.

      This method follows a recursive approach to determine the effective flag context:

      Parameters:
      region - the region for which the flag context is being resolved.
      flagContext - the initial flag context for the region.
      Returns:
      the resolved FlagContext, considering inheritance from parent regions.
    • isRootRegion

      public static boolean isRootRegion(@NotNull @NotNull IProtectedRegion region)
      Checks whether the given region is its own parent. This indicates that the region is the global region.
      Parameters:
      region - the region to check, must not be null
      Returns:
      true if the region's parent is itself, otherwise false
    • findResponsibleRegion

      @Nullable public static @Nullable IProtectedRegion findResponsibleRegion(@NotNull @NotNull net.minecraft.core.BlockPos pos, @NotNull @NotNull net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Determines the region responsible for the given position and dimension. The responsible region is the one with the highest priority among all regions that cover the specified location.

      If no specific region is found, this method falls back to the dimensional region. If the dimensional region is inactive, it further falls back to the global region if it is active.

      Parameters:
      pos - the position for which to find the responsible region, must not be null
      dim - the dimension in which to search for the responsible region, must not be null
      Returns:
      the highest-priority active region covering the given position and dimension, or null if no active region is found
    • checkMobGrief

      public static void checkMobGrief(net.minecraft.world.entity.Entity entity, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci)
    • checkMobGrief

      public static void checkMobGrief(net.minecraft.world.entity.Entity entity, org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable<Boolean> cir)
    • checkMobGrief

      public static void checkMobGrief(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci)
    • checkMobGrief

      public static void checkMobGrief(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable<Boolean> cir)
    • 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.
    • result

      public FlagCheckResult result()
      Returns the value of the result record component.
      Returns:
      the value of the result record component