Class Region

java.lang.Object
org.empirewar.orbis.region.Region
All Implemented Interfaces:
Comparable<Region>, RegionQuery.Flag.Queryable, RegistryResolvable<String>
Direct Known Subclasses:
GlobalRegion

public sealed class Region extends Object implements RegionQuery.Flag.Queryable, Comparable<Region>, RegistryResolvable<String> permits GlobalRegion
Represents a region within a world.

Regions hold an Area to define the locations affected by the region. They also hold a set of MutableRegionFlags.

Regions may have region parents defined, where they will inherit the flags of those parents if it does not have an overriding flag set.

There is also a set of Members. Members may be influenced differently by a GroupedMutableRegionFlag. By default, flags affect all members in a region.

Multiple regions spanning the same area will be prioritised based off the priority() parameter. When querying a location for a flag, the region with the highest priority that has that flag should return the flag value.

Regions that have the same priority and conflicting flags have undefined behaviour. In these cases, admins should be warned about possible issues.

  • Field Details

    • CODEC

      public static final com.mojang.serialization.MapCodec<Region> CODEC
    • flags

      protected final Map<net.kyori.adventure.key.Key,MutableRegionFlag<?>> flags
  • Constructor Details

  • Method Details

    • name

      public String name()
      Gets the name of this region.

      A region name should never include spaces and is considered an identifier.

      Returns:
      the name
    • parents

      public Set<Region> parents()
      Gets the parents of this region.
      Returns:
      the parents
    • addParent

      public void addParent(Region region)
      Adds a parent to this region.
      Parameters:
      region - the parent to add
    • removeParent

      public void removeParent(Region region)
      Removes a parent from this region.
      Parameters:
      region - the parent to remove
    • members

      public Set<Member> members()
      Gets the members of this region.
      Returns:
      the members
    • addMember

      public void addMember(Member member)
    • removeMember

      public void removeMember(Member member)
    • area

      public Area area()
      Gets the area of this region.
      Returns:
      the area
    • priority

      public int priority()
      Gets the priority of this region.

      A priority is always positive (including zero) and a higher priority gives precedence over other regions when checking flags.

      Returns:
      the priority
    • priority

      public void priority(int priority)
      Parameters:
      priority - the priority
      See Also:
    • addFlag

      public <T> MutableRegionFlag<T> addFlag(RegistryRegionFlag<T> flag)
      Adds a flag to this region. The flag is transformed into a mutable flag.
      Parameters:
      flag - the flag to add
      Returns:
      the transformed flag instance
      See Also:
    • addGroupedFlag

      public <T> GroupedMutableRegionFlag<T> addGroupedFlag(RegistryRegionFlag<T> flag, Set<FlagMemberGroup> groups)
      Adds a grouped flag to this region with the initial set of groups.
      Parameters:
      flag - the flag to add
      groups - the groups to add to the flag
      Returns:
      the transformed flag instance
    • removeFlag

      public boolean removeFlag(RegistryRegionFlag<?> flag)
      Removes a flag from this region.
      Parameters:
      flag - the flag to remove
      Returns:
      true if flag existed and was removed
    • hasFlag

      public boolean hasFlag(RegistryRegionFlag<?> flag)
    • getFlag

      public <T> Optional<MutableRegionFlag<T>> getFlag(RegistryRegionFlag<T> flag)
    • setFlag

      public <T> void setFlag(RegistryRegionFlag<T> flag, T value)
      Sets the value of a flag.
      Type Parameters:
      T - value type
      Parameters:
      flag - the flag
      value - the value
      Throws:
      IllegalArgumentException - if the flag is not present
    • query

      public <FR> RegionQuery.Result<Optional<FR>,RegionQuery.Flag<FR>> query(RegionQuery.Flag<FR> flag)
      Specified by:
      query in interface RegionQuery.Flag.Queryable
    • isGlobal

      public boolean isGlobal()
      Gets whether this region is a "global region".

      A global region is a region that encompasses a world.

      Returns:
      true if global
    • getType

      public RegionType<?> getType()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(@NotNull @NotNull Region o)
      Specified by:
      compareTo in interface Comparable<Region>
    • key

      public String key()
      Description copied from interface: RegistryResolvable
      Gets the registry key used for this object.
      Specified by:
      key in interface RegistryResolvable<String>
      Returns:
      the registry key