Class Gate

java.lang.Object
org.sgrewritten.stargate.gate.Gate
All Implemented Interfaces:
GateAPI

public class Gate extends Object implements GateAPI
Acts as an interface for portals to modify worlds
Author:
Thorin
  • Constructor Details

    • Gate

      public Gate(@NotNull @NotNull GateFormatAPI format, @NotNull @NotNull org.bukkit.Location signLocation, org.bukkit.block.BlockFace signFace, boolean alwaysOn, @NotNull @NotNull RegistryAPI registry) throws InvalidStructureException, GateConflictException
      Instantiates a new gate
      Parameters:
      format -

      The gate format used by this gate

      signLocation -

      The location of this gate's sign

      signFace -

      The direction this gate's sign is facing

      alwaysOn -

      Whether this gate has been set as always-on

      Throws:
      InvalidStructureException -

      If the physical stargate at the given location does not match the given format

      GateConflictException -

      If this gate is in conflict with an existing one

    • Gate

      public Gate(GateData gateData, @NotNull @NotNull RegistryAPI registry) throws InvalidStructureException
      Instantiates a gate from already predetermined parameters, no checking is done to see if format matches
      Parameters:
      gateData -

      Data of the gate

      Throws:
      InvalidStructureException -

      If the facing is invalid or if no format could be found

  • Method Details

    • drawControlMechanisms

      public void drawControlMechanisms(LineData[] lines)
      Description copied from interface: GateAPI
      Set button and draw sign
      Specified by:
      drawControlMechanisms in interface GateAPI
    • redrawPosition

      public void redrawPosition(PortalPosition portalPosition, @Nullable @Nullable LineData[] lines)
      Description copied from interface: GateAPI
      Update the state on the portal position according to its type
      Specified by:
      redrawPosition in interface GateAPI
      Parameters:
      portalPosition -

      The portal position to update

    • getPortalPositions

      public List<PortalPosition> getPortalPositions()
      Description copied from interface: GateAPI
      Gets a copy of this gate's portal positions
      Specified by:
      getPortalPositions in interface GateAPI
      Returns:

      A copy of this gate's portal positions

    • getLocations

      public List<BlockLocation> getLocations(GateStructureType structureType)
      Description copied from interface: GateAPI
      Gets all locations of this gate containing the given structure type
      Specified by:
      getLocations in interface GateAPI
      Parameters:
      structureType -

      The structure type to get locations of

      Returns:

      All locations containing the given structure type

    • open

      public void open()
      Description copied from interface: GateAPI
      Opens this gate
      Specified by:
      open in interface GateAPI
    • close

      public void close()
      Description copied from interface: GateAPI
      Closes this gate
      Specified by:
      close in interface GateAPI
    • getExit

      public org.bukkit.Location getExit()
      Description copied from interface: GateAPI
      Gets the exit location of this gate
      Specified by:
      getExit in interface GateAPI
      Returns:

      The exit location of this gate

    • isOpen

      public boolean isOpen()
      Description copied from interface: GateAPI
      Gets whether this gate is currently open
      Specified by:
      isOpen in interface GateAPI
      Returns:

      Whether this gate is currently open

    • getFormat

      @NotNull public @NotNull GateFormatAPI getFormat()
      Description copied from interface: GateAPI
      Gets the gate format used by this gate
      Specified by:
      getFormat in interface GateAPI
      Returns:

      The gate format used by this gate

    • getFacing

      public org.bukkit.block.BlockFace getFacing()
      Description copied from interface: GateAPI
      Gets the block face defining this gate's direction
      Specified by:
      getFacing in interface GateAPI
      Returns:

      The block face defining this gate's direction

    • getFlipZ

      public boolean getFlipZ()
      Description copied from interface: GateAPI
      Gets whether this gate has been flipped on the z-axis
      Specified by:
      getFlipZ in interface GateAPI
      Returns:

      Whether this gate has been flipped on the z-axis

    • getRelativeVector

      public org.bukkit.util.Vector getRelativeVector(org.bukkit.Location location)
      Description copied from interface: GateAPI
      Gets a vector relative to this gate's top-left location using the given location
      Specified by:
      getRelativeVector in interface GateAPI
      Parameters:
      location -

      The location to turn into a relative location

      Returns:

      A location relative to this gate's top-left location

    • getLocation

      public org.bukkit.Location getLocation(@NotNull @NotNull org.bukkit.util.Vector vector)
      Description copied from interface: GateAPI
      Gets a location from a relative vector
      Specified by:
      getLocation in interface GateAPI
      Parameters:
      vector -

      The vector defining a location

      Returns:

      The location corresponding to the given vector

    • matchesFormat

      public boolean matchesFormat(@NotNull @NotNull org.bukkit.Location location, boolean alwaysOn) throws GateConflictException
      Checks if the built stargate matches this gate's format

      This will try to match the format regardless of which control block the sign was placed on TODO: symmetric formats will be checked twice, make a way to determine if a format is symmetric to avoid this

      Parameters:
      location -

      The location of a control-block

      alwaysOn -

      Whether the new portal is set as always-on

      Returns:

      True if the built stargate matches this format

      Throws:
      GateConflictException -

      If the built stargate conflicts with another gate

    • isValid

      public boolean isValid() throws GateConflictException
      Description copied from interface: GateAPI
      Check if this gate with the current settings is valid
      Specified by:
      isValid in interface GateAPI
      Returns:

      True if this gate is valid

      Throws:
      GateConflictException -

      If this gate conflicts with another gate

    • calculatePortalPositions

      public void calculatePortalPositions(boolean alwaysOn) throws InvalidStructureException
      Description copied from interface: GateAPI
      Calculates all portal positions for this gate
      Specified by:
      calculatePortalPositions in interface GateAPI
      Parameters:
      alwaysOn -

      Whether this gate is always on

      Throws:
      InvalidStructureException
    • getTopLeft

      public org.bukkit.Location getTopLeft()
      Description copied from interface: GateAPI
      Gets this gate's top-left location
      Specified by:
      getTopLeft in interface GateAPI
      Returns:

      This gate's top-left location

    • addPortalPosition

      public PortalPosition addPortalPosition(org.bukkit.Location location, PositionType type, String pluginName)
      Description copied from interface: GateAPI
      Add a position specific for this Gate
      Specified by:
      addPortalPosition in interface GateAPI
      Parameters:
      location -

      The location of the position

      type -

      The type of position

      Returns:

      The added portal position

    • addPortalPosition

      public void addPortalPosition(PortalPosition portalPosition)
      Description copied from interface: GateAPI
      Add a position specific to this Gate
      Specified by:
      addPortalPosition in interface GateAPI
      Parameters:
      portalPosition -

      The portal position

    • removePortalPosition

      @Nullable public @Nullable PortalPosition removePortalPosition(org.bukkit.Location location)
      Description copied from interface: GateAPI
      Remove portal position at specified location
      Specified by:
      removePortalPosition in interface GateAPI
      Parameters:
      location - The location of the portal position to be removed
      Returns:

      The removed portal position

    • removePortalPosition

      public void removePortalPosition(PortalPosition portalPosition)
      Description copied from interface: GateAPI
      Remove a portal position from this gate. Does not remove the portal position in the registry or database. Please use RegistryAPI.removePortalPosition(Location) with conjunction to StorageAPI.removePortalPosition(RealPortal, StorageType, PortalPosition)
      Specified by:
      removePortalPosition in interface GateAPI
      Parameters:
      portalPosition -

      The portal position to remove

    • forceGenerateStructure

      public void forceGenerateStructure()
      Description copied from interface: GateAPI
      Modify the world such that the gate follows its gateformat
      Specified by:
      forceGenerateStructure in interface GateAPI
    • addPortalPosition

      public PortalPosition addPortalPosition(org.bukkit.util.BlockVector relativeBlockVector, PositionType type, String pluginName)
      Add a position specific for this Gate
      Parameters:
      relativeBlockVector -

      The relative position in format space

      type -

      The type of position

    • addPortalPositions

      public void addPortalPositions(List<PortalPosition> portalPositions)
      Add portal positions specific for this Gate
      Parameters:
      portalPositions -

      A list of portalPositions

    • assignPortal

      public void assignPortal(@NotNull @NotNull RealPortal realPortal)
      Description copied from interface: GateAPI
      Assign a real portal to this gate
      Specified by:
      assignPortal in interface GateAPI
      Parameters:
      realPortal -

      The portal to assign to this gate

    • getPortal

      public RealPortal getPortal()
      Description copied from interface: GateAPI
      Get the portal assigned to this portal position
      Specified by:
      getPortal in interface GateAPI
      Returns:

      The portal assigned to this portal position