Class StargatePortal

java.lang.Object
org.sgrewritten.stargate.network.portal.StargatePortal
All Implemented Interfaces:
MetadataHolder, Portal, RealPortal

public class StargatePortal extends Object implements RealPortal
An abstract implementation of a real portal
Author:
Thorin
  • Field Details

    • portalCount

      public static int portalCount
      Used in bStats metrics
    • allUsedFlags

      public static final Set<PortalFlag> allUsedFlags
      Used for bStats metrics, this is every flag that has been used by all portals
    • network

      protected Network network
    • name

      protected String name
    • openFor

      protected UUID openFor
    • overriddenDestination

      protected Portal overriddenDestination
    • activatedTime

      protected long activatedTime
    • activator

      protected UUID activator
    • isDestroyed

      protected boolean isDestroyed
    • languageManager

      protected final LanguageManager languageManager
  • Constructor Details

    • StargatePortal

      public StargatePortal(Network network, String name, Set<PortalFlag> flags, GateAPI gate, UUID ownerUUID, LanguageManager languageManager, StargateEconomyAPI economyManager, @Nullable @Nullable String metaData) throws NameLengthException
      Instantiates a new abstract portal
      Parameters:
      network -

      The network the portal belongs to

      name -

      The name of the portal

      flags -

      The flags enabled for the portal

      gate -

      The gate belonging to this portal

      ownerUUID -

      The UUID of the portal's owner

      languageManager -

      A manager able to provide localized messages

      economyManager -

      A manager able to deal with server economy

      Throws:
      NameLengthException -

      If the portal name is invalid

  • Method Details

    • getGlobalId

      public GlobalPortalId getGlobalId()
      Description copied from interface: Portal
      Gets the globally unique identifier for this portal
      Specified by:
      getGlobalId in interface Portal
      Returns:

      The globally unique identifier for this portal

    • getPortalPosition

      public List<org.bukkit.Location> getPortalPosition(PositionType type)
      Description copied from interface: RealPortal
      Gets the location of all positions of the specified portal position type
      Specified by:
      getPortalPosition in interface RealPortal
      Parameters:
      type -

      The type of portalPosition

      Returns:

      The location of this portal's signs

    • updateState

      public void updateState()
      Description copied from interface: Portal
      Looks into available portals to connect to, and updates appearance and behaviour accordingly
      Specified by:
      updateState in interface Portal
    • isOpen

      public boolean isOpen()
      Description copied from interface: Portal
      Checks whether this portal is currently open
      Specified by:
      isOpen in interface Portal
      Returns:

      True if this portal is currently open

    • open

      public void open(@Nullable @Nullable Portal destination, @Nullable @Nullable org.bukkit.entity.Player actor)
      Description copied from interface: RealPortal
      Open this portal without any checks
      Specified by:
      open in interface RealPortal
      Parameters:
      destination -

      The destination to open to

      actor -

      The player which opened this portal

    • open

      public void open(org.bukkit.entity.Player actor)
      Description copied from interface: Portal
      Opens this portal for the given player
      Specified by:
      open in interface Portal
      Parameters:
      actor -

      The player to open this portal for

    • close

      public void close(boolean forceClose)
      Description copied from interface: Portal
      Closes this portal
      Specified by:
      close in interface Portal
      Parameters:
      forceClose -

      Whether to force this portal to close, even if set to always on or similar

    • isOpenFor

      public boolean isOpenFor(org.bukkit.entity.Entity target)
      Description copied from interface: Portal
      Checks whether this portal is currently open and the given target is the one the portal opened for
      Specified by:
      isOpenFor in interface Portal
      Parameters:
      target -

      The target to check

      Returns:

      True if the portal has been opened for the given target

    • overrideDestination

      public void overrideDestination(Portal destination)
      Description copied from interface: Portal
      Forces this portal to temporarily go to the given destination regardless of the normal destination(s)
      Specified by:
      overrideDestination in interface Portal
      Parameters:
      destination -

      The destination this portal should temporarily connect ot

    • getNetwork

      public Network getNetwork()
      Description copied from interface: Portal
      Gets the network this portal belongs to
      Specified by:
      getNetwork in interface Portal
      Returns:

      The network this portal belongs to

    • setNetwork

      public void setNetwork(Network targetNetwork) throws NameConflictException
      Description copied from interface: Portal
      Changes the network this portal belongs to
      Specified by:
      setNetwork in interface Portal
      Parameters:
      targetNetwork -

      The new network this portal should belong to

      Throws:
      NameConflictException -

      If the given network name is invalid

    • setOwner

      public void setOwner(UUID targetPlayer)
      Description copied from interface: Portal
      Changes the player this portal belongs to

      DOES NOT SAVE TO DATABASE

      Specified by:
      setOwner in interface Portal
      Parameters:
      targetPlayer -

      The new player this portal should belong to

    • teleportHere

      public void teleportHere(org.bukkit.entity.Entity target, RealPortal origin)
      Description copied from interface: Portal
      Teleports an entity to this portal
      Specified by:
      teleportHere in interface Portal
      Parameters:
      target -

      The target entity to teleport

      origin -

      The origin portal the entity is teleporting from

    • doTeleport

      public void doTeleport(@NotNull @NotNull org.bukkit.entity.Entity target, @Nullable @Nullable Portal destination)
      Description copied from interface: RealPortal
      Teleports the given entity to given destination
      Specified by:
      doTeleport in interface RealPortal
      Parameters:
      target -

      The entity to teleport

    • doTeleport

      public void doTeleport(@NotNull @NotNull org.bukkit.entity.Entity target)
      Description copied from interface: RealPortal
      Teleports the given entity to stored destination
      Specified by:
      doTeleport in interface RealPortal
      Parameters:
      target -

      The entity to teleport

    • getName

      public String getName()
      Description copied from interface: Portal
      Gets the name of this portal
      Specified by:
      getName in interface Portal
      Returns:

      The name of this portal

    • hasFlag

      public boolean hasFlag(PortalFlag flag)
      Description copied from interface: Portal
      Checks whether this portal has the given portal flag enabled
      Specified by:
      hasFlag in interface Portal
      Parameters:
      flag -

      The portal flag to check for

      Returns:

      True if this portal has the given portal flag enabled

    • addFlag

      public void addFlag(PortalFlag flag) throws UnsupportedOperationException
      Description copied from interface: Portal
      Add a flag from this portal (does not do so to storage)
      Specified by:
      addFlag in interface Portal
      Parameters:
      flag -

      Flag to add

      Throws:
      UnsupportedOperationException
    • removeFlag

      public void removeFlag(PortalFlag flag) throws UnsupportedOperationException
      Description copied from interface: Portal
      Remove a flag from this portal (does not do so from storage)
      Specified by:
      removeFlag in interface Portal
      Parameters:
      flag -

      Flag to remove

      Throws:
      UnsupportedOperationException
    • getAllFlagsString

      public String getAllFlagsString()
      Description copied from interface: Portal
      Gets all of this portal's portal flags in the form of a string

      This returns the concatenation of all character representations for the flags used by this portal.

      Specified by:
      getAllFlagsString in interface Portal
      Returns:

      All of this portal's portal flags in the form of a string

    • getOwnerUUID

      public UUID getOwnerUUID()
      Description copied from interface: Portal
      Gets the UUID of this portal's owner

      A portal's owner is the player that created the portal.

      Specified by:
      getOwnerUUID in interface Portal
      Returns:

      The UUID of this portal's owner

    • setSignColor

      public void setSignColor(@Nullable @Nullable org.bukkit.DyeColor changedColor, @NotNull @NotNull PortalPosition portalPosition)
      Description copied from interface: RealPortal
      Updates the color of this portal's sign

      Replacement function for Sign.setColor(org.bukkit.DyeColor), as the portal sign is an interface that is using a combination of various colors; more has to be processed

      Specified by:
      setSignColor in interface RealPortal
      Parameters:
      changedColor -

      Color to change the sign text to. If null, then the default color will be used

    • getGate

      public GateAPI getGate()
      Description copied from interface: RealPortal
      Gets the gate belonging to this portal
      Specified by:
      getGate in interface RealPortal
      Returns:

      The gate belonging to this portal

    • destroy

      public void destroy()
      Description copied from interface: Portal
      The method used when destroying a portal

      Mainly clears the sign, see NetworkManager.destroyPortal(RealPortal) to really destroy a portal

      Specified by:
      destroy in interface Portal
    • close

      public void close(long relatedOpenTime)
      Description copied from interface: RealPortal
      Closes this portal

      Everytime most of the portals opens, there is going to be a scheduled event to close it after a specific time. If a player enters the portal before this, then it is going to close, but the scheduled close event is still going to be there. And if the portal gets activated again, it is going to close prematurely, because of this already scheduled event. Solution to avoid this is to assign an open-time for each scheduled close event and only close if the related open time matches with the most recent time the portal was opened.

      Specified by:
      close in interface RealPortal
      Parameters:
      relatedOpenTime -

      The time this portal was opened

    • getExit

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

      The exit location of this portal

    • getId

      public String getId()
      Description copied from interface: Portal
      Gets the unique identifier for this portal
      Specified by:
      getId in interface Portal
      Returns:

      The unique identifier for this portal

    • activate

      public void activate(@Nullable @Nullable org.bukkit.entity.Player player)
      Description copied from interface: RealPortal
      Activates this portal for the given player during internally specified time
      Specified by:
      activate in interface RealPortal
      Parameters:
      player -

      The player to activate this portal for

    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface RealPortal
      Returns:

      True if this portal is active

    • getActivatorUUID

      public UUID getActivatorUUID()
      Specified by:
      getActivatorUUID in interface RealPortal
      Returns:

      The uuid activator or null if portal is not active (or always on)

    • deactivate

      protected void deactivate(long activatedTime)
      De-activates this portal if necessary

      The activated time must match to make sure to skip de-activation requests except for the one cancelling the newest portal activation.

      Parameters:
      activatedTime -

      The time this portal was activated

    • deactivate

      public void deactivate()
      Description copied from interface: RealPortal
      Deactivate this portal
      Specified by:
      deactivate in interface RealPortal
    • setMetadata

      public void setMetadata(String data)
      Description copied from interface: MetadataHolder
      Set metadata for this portal. This sets all metadata for this entity, it's advised to use MetadataHolder.setMetadata(JsonElement, String)
      Specified by:
      setMetadata in interface MetadataHolder
      Parameters:
      data -

      The meta data to set

    • getMetadata

      public String getMetadata()
      Description copied from interface: MetadataHolder
      Get metadata for this portal. This gets all metadata for this entity, it's advised to use the MetadataHolder.getMetadata(String) method
      Specified by:
      getMetadata in interface MetadataHolder
      Returns:

      The meta data of this portal

    • getStorageType

      public StorageType getStorageType()
      Description copied from interface: Portal
      Gets how the portal is stored
      Specified by:
      getStorageType in interface Portal
      Returns:

      The storage type of the portal

    • setName

      public void setName(String newName)
      Description copied from interface: Portal
      Changes the name of the portal. Use NetworkManager.rename(Portal, String) instead, as this does not save to database, nor update its name to the portal network.
      Specified by:
      setName in interface Portal
      Parameters:
      newName -

      The new name of the portal

    • getExitFacing

      public org.bukkit.block.BlockFace getExitFacing()
      Description copied from interface: RealPortal
      Get the facing entities exit from this portal.
      Specified by:
      getExitFacing in interface RealPortal
      Returns:

      The facing entities exit from this portal.

    • setSavedToStorage

      public void setSavedToStorage()
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Portal
      Returns:

      True if this portal has been destroyed

    • getBehavior

      public PortalBehavior getBehavior()
      Specified by:
      getBehavior in interface RealPortal
      Returns:

      The behavior which defines this portal destination selection and sign text

    • setBehavior

      public void setBehavior(PortalBehavior portalBehavior)
      Description copied from interface: RealPortal
      Modify the behavior this portal uses
      Specified by:
      setBehavior in interface RealPortal
      Parameters:
      portalBehavior -

      New behavior this portal should follow

    • redrawSigns

      public void redrawSigns()
      Description copied from interface: RealPortal
      Redraw all signs in this portal
      Specified by:
      redrawSigns in interface RealPortal