Class FlagEvaluator

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

public class FlagEvaluator extends Object
  • Constructor Details

    • FlagEvaluator

      public FlagEvaluator()
  • Method Details

    • 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
    • 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)