Class StargateRegistry

java.lang.Object
org.sgrewritten.stargate.network.StargateRegistry
All Implemented Interfaces:
RegistryAPI

public class StargateRegistry extends Object implements RegistryAPI
Registry of all portals and networks
Author:
Thorin (idea from EpicKnarvik)
  • Constructor Details

    • StargateRegistry

      public StargateRegistry(StorageAPI storageAPI, BlockHandlerResolver blockHandlerResolver)
      Instantiates a new Stargate registry
      Parameters:
      storageAPI -

      The database API to use for interfacing with the database

  • Method Details

    • unregisterPortal

      public void unregisterPortal(Portal portal)
      Description copied from interface: RegistryAPI
      Removes the given portal from registry. Only modifies this registry, use NetworkManager.destroyPortal(RealPortal) instead
      Specified by:
      unregisterPortal in interface RegistryAPI
      Parameters:
      portal -

      The portal to remove

    • registerPortal

      public void registerPortal(@NotNull @NotNull RealPortal portal)
      Description copied from interface: RegistryAPI
      Register a portal to this registry
      Specified by:
      registerPortal in interface RegistryAPI
      Parameters:
      portal -

      The portal to register

    • networkExists

      public boolean networkExists(String networkName, StorageType storageType)
      Description copied from interface: RegistryAPI
      Checks whether the given network name exists
      Specified by:
      networkExists in interface RegistryAPI
      Parameters:
      networkName -

      The network name to check

      storageType -

      The storage type of the network

      Returns:

      True if the network exists

    • getNetworkRegistry

      public NetworkRegistry getNetworkRegistry(StorageType storageType)
      Description copied from interface: RegistryAPI
      Get the network registry
      Specified by:
      getNetworkRegistry in interface RegistryAPI
      Parameters:
      storageType -
      Returns:
    • getNetwork

      @Nullable public @Nullable Network getNetwork(String id, StorageType storageType)
      Description copied from interface: RegistryAPI
      Gets the network with the given
      Specified by:
      getNetwork in interface RegistryAPI
      Parameters:
      id -

      The id of the network to get

      storageType -

      Whether the network is a BungeeCord network

      Returns:

      The network with the given name

    • updateAllPortals

      public void updateAllPortals()
      Description copied from interface: RegistryAPI
      Update all portals handled by this registry
      Specified by:
      updateAllPortals in interface RegistryAPI
    • getPortal

      public RealPortal getPortal(BlockLocation blockLocation, GateStructureType structureType)
      Description copied from interface: RegistryAPI
      Get the portal with the given structure type at the given location
      Specified by:
      getPortal in interface RegistryAPI
      Parameters:
      blockLocation -

      The location the portal is located at

      structureType -

      The structure type to look for

      Returns:

      The found portal, or null if no such portal exists

    • getPortal

      public RealPortal getPortal(BlockLocation blockLocation, GateStructureType[] structureTypes)
      Description copied from interface: RegistryAPI
      Get the portal with any of the given structure types at the given location
      Specified by:
      getPortal in interface RegistryAPI
      Parameters:
      blockLocation -

      The location the portal is located at

      structureTypes -

      The structure types to look for

      Returns:

      The found portal, or null if no such portal exists

    • getPortal

      public RealPortal getPortal(org.bukkit.Location location, GateStructureType structureType)
      Description copied from interface: RegistryAPI
      Gets the portal with the given structure type at the given location
      Specified by:
      getPortal in interface RegistryAPI
      Parameters:
      location -

      The location to check for portal structures

      structureType -

      The structure type to look for

      Returns:

      The found portal, or null if no portal was found

    • getPortal

      public RealPortal getPortal(org.bukkit.Location location, GateStructureType[] structureTypes)
      Description copied from interface: RegistryAPI
      Gets the portal with any of the given structure types at the given location
      Specified by:
      getPortal in interface RegistryAPI
      Parameters:
      location -

      The location to check for portal structures

      structureTypes -

      The structure types to look for

      Returns:

      The found portal, or null if no portal was found

    • getPortal

      public RealPortal getPortal(org.bukkit.Location location)
      Description copied from interface: RegistryAPI
      Get the portal at the given location
      Specified by:
      getPortal in interface RegistryAPI
      Parameters:
      location -

      The location to check for portal structures

      Returns:

      The found portal, or null if no portal was found

    • isPartOfPortal

      public boolean isPartOfPortal(List<org.bukkit.block.Block> blocks)
      Description copied from interface: RegistryAPI
      Checks if any of the given blocks belong to a portal
      Specified by:
      isPartOfPortal in interface RegistryAPI
      Parameters:
      blocks -

      The blocks to check

      Returns:

      True if any of the given blocks belong to a portal

    • isNextToPortal

      public boolean isNextToPortal(org.bukkit.Location location, GateStructureType structureType)
      Description copied from interface: RegistryAPI
      Checks one block away from the given location to check if it's adjacent to a portal structure

      Checks North, west, south, east direction. Not up / down, as it is currently not necessary and a waste of resources.

      Specified by:
      isNextToPortal in interface RegistryAPI
      Parameters:
      location -

      The location to check for adjacency

      structureType -

      The structure type to look for

      Returns:

      True if the given location is adjacent to a location containing the given structure type

    • getPortalsFromTouchingBlock

      public List<RealPortal> getPortalsFromTouchingBlock(org.bukkit.Location location, GateStructureType structureType)
      Description copied from interface: RegistryAPI
      Get portal from block next to portal, will randomly choose one portal if block is next to two portals
      Specified by:
      getPortalsFromTouchingBlock in interface RegistryAPI
      Parameters:
      location -

      The location to check for

      structureType -

      The structure type to check for

      Returns:
    • registerLocations

      public void registerLocations(GateStructureType structureType, Map<BlockLocation,RealPortal> locationsMap)
      Description copied from interface: RegistryAPI
      Registers the existence of the given structure type in the given locations

      Stores the portals that exist at the given locations, but using the structure type as the key to be able to check locations for the given structure type.

      Does not save to storage!

      Specified by:
      registerLocations in interface RegistryAPI
      Parameters:
      structureType -

      The structure type to register

      locationsMap -

      The locations and the corresponding portals to register

    • registerLocation

      public void registerLocation(GateStructureType structureType, BlockLocation location, RealPortal portal)
      Description copied from interface: RegistryAPI
      Registers a location with attached portal and structure type to this registry
      Specified by:
      registerLocation in interface RegistryAPI
      Parameters:
      structureType -

      The structure type to register

      location -

      The location to register

      portal -

      The portal to register

    • unRegisterLocation

      public void unRegisterLocation(GateStructureType structureType, BlockLocation blockLocation)
      Description copied from interface: RegistryAPI
      Un-registers all portal blocks with the given structure type, at the given block location
      Specified by:
      unRegisterLocation in interface RegistryAPI
      Parameters:
      structureType -

      The type of structure to un-register

      blockLocation -

      The location to un-register

    • clear

      public void clear()
      Clear this registry
    • getValidNewName

      public String getValidNewName(Network network) throws InvalidNameException
      Description copied from interface: RegistryAPI
      Get a non-clashing name close to the current name of the network.
      Specified by:
      getValidNewName in interface RegistryAPI
      Parameters:
      network -

      The network to rename

      Throws:
      InvalidNameException -

      If the name is a uuid

    • getPortalPositions

      public Map<BlockLocation,PortalPosition> getPortalPositions()
      Description copied from interface: RegistryAPI
      Get all portal positions
      Specified by:
      getPortalPositions in interface RegistryAPI
      Returns:

      Data on all portal positions

    • getPortalPositionsOwnedByPlugin

      public Map<BlockLocation,PortalPosition> getPortalPositionsOwnedByPlugin(org.bukkit.plugin.Plugin plugin)
      Specified by:
      getPortalPositionsOwnedByPlugin in interface RegistryAPI
      Parameters:
      plugin -

      The plugin owning the positions

      Returns:

      Data on the portal positions owned by specified plugin

    • savePortalPosition

      public PortalPosition savePortalPosition(RealPortal portal, org.bukkit.Location location, PositionType type, org.bukkit.plugin.Plugin plugin)
      Description copied from interface: RegistryAPI
      Save given portal position to storage and register it to the registry
      Specified by:
      savePortalPosition in interface RegistryAPI
      Parameters:
      portal -

      The portal the position is linked to

      location -

      The location of the position

      type -

      The type of the position

      plugin -

      The plugin this position relates to

    • removePortalPosition

      public void removePortalPosition(org.bukkit.Location location)
      Description copied from interface: RegistryAPI
      Remove portal position from registry
      Specified by:
      removePortalPosition in interface RegistryAPI
      Parameters:
      location -

      The location of the portal position

    • registerPortalPosition

      public void registerPortalPosition(PortalPosition portalPosition, org.bukkit.Location location, RealPortal portal)
      Description copied from interface: RegistryAPI
      Register given portal position to registry. Does not save to database, therefore internal
      Specified by:
      registerPortalPosition in interface RegistryAPI
      Parameters:
      portalPosition -

      The portal position

      location -

      The location of the position

      portal -

      The portal of the position

    • getPortalPosition

      public PortalPosition getPortalPosition(org.bukkit.Location location)
      Description copied from interface: RegistryAPI
      Gets the portal position at given location
      Specified by:
      getPortalPosition in interface RegistryAPI
      Parameters:
      location -

      The location of the portal position

      Returns:

      The portal position, or null if none was found

    • registerNetwork

      public void registerNetwork(Network network)
      Description copied from interface: RegistryAPI
      Use NetworkManager instead. This does not save to database, and is not cross server compatible
      Specified by:
      registerNetwork in interface RegistryAPI
      Parameters:
      network -

      The network to register

    • renameNetwork

      public void renameNetwork(String newId, String oldId, StorageType storageType) throws InvalidNameException, UnimplementedFlagException, NameLengthException
      Description copied from interface: RegistryAPI
      Use NetworkManager instead. This does not save to database, and is not cross server compatible
      Specified by:
      renameNetwork in interface RegistryAPI
      Parameters:
      newId -

      The new id of the network

      oldId -

      The old id of the network

      Throws:
      InvalidNameException
      UnimplementedFlagException
      NameLengthException
    • getPortalsInChunk

      @NotNull public @NotNull Set<RealPortal> getPortalsInChunk(StargateChunk chunk)
      Description copied from interface: RegistryAPI
      Get all the portals in a chunk
      Specified by:
      getPortalsInChunk in interface RegistryAPI
      Parameters:
      chunk -

      The chunk to retrieve portals from

      Returns:

      The portals in the chunk