Class Creator

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.tooluser.ToolUser
nl.pim16aap2.animatedarchitecture.core.tooluser.creator.Creator
Direct Known Subclasses:
CreatorBigDoor, CreatorClock, CreatorDrawbridge, CreatorFlag, CreatorGarageDoor, CreatorPortcullis, CreatorSlidingDoor, CreatorWindMill

public abstract class Creator extends ToolUser
Represents a specialization of the ToolUser that is used for creating new Structures.
  • Field Details

    • limitsManager

      protected final LimitsManager limitsManager
    • structureBuilder

      protected final StructureBuilder structureBuilder
    • databaseManager

      protected final DatabaseManager databaseManager
    • economyManager

      protected final IEconomyManager economyManager
    • commandFactory

      protected final CommandFactory commandFactory
    • config

      protected final IConfig config
    • structureID

      protected final StructureID structureID
    • factoryProvideName

      protected final Step.Factory factoryProvideName
      Factory for the Step that provides the name.
    • factoryProvideFirstPos

      protected final Step.Factory factoryProvideFirstPos
      Factory for the Step that provides the first position of the area of the structure.

      Don't forget to set the message before using it!

    • factoryProvideSecondPos

      protected final Step.Factory factoryProvideSecondPos
      Factory for the Step that provides the second position of the area of the structure, thus completing the Cuboid.

      Don't forget to set the message before using it!

    • factoryProvideRotationPointPos

      protected final Step.Factory factoryProvideRotationPointPos
      Factory for the Step that provides the position of the structure's rotation point.

      Don't forget to set the message before using it!

    • factoryProvidePowerBlockPos

      protected final Step.Factory factoryProvidePowerBlockPos
      Factory for the Step that provides the position of the structure's power block.
    • factoryProvideOpenStatus

      protected final Step.Factory factoryProvideOpenStatus
      Factory for the Step that provides the open status of the structure.
    • factoryProvideOpenDir

      protected final Step.Factory factoryProvideOpenDir
      Factory for the Step that provides the open direction of the structure.
    • factoryConfirmPrice

      protected final Step.Factory factoryConfirmPrice
      Factory for the Step that allows the player to confirm or reject the price of the structure.
    • factoryReviewResult

      protected final Step.Factory factoryReviewResult
      Factory for the Step that allows players to review the created structure
    • factoryCompleteProcess

      protected final Step.Factory factoryCompleteProcess
      Factory for the Step that completes this process.

      Don't forget to set the message before using it!

    • structureType

      protected final StructureType structureType
      The type of structure this creator will create.
  • Constructor Details

  • Method Details

    • init

      protected void init()
      Description copied from class: ToolUser
      Basic initialization executed that should be called after the constructor.

      This method will initialize the Procedure using the steps generated by ToolUser.generateSteps() and register this ToolUser with the ToolUserManager.

      If this method is not called, the ToolUser will be considered uninitialized and any method that requires the procedure (e.g. handling input) will throw an exception.

      If this method is called more than once, an exception will be thrown.

      Overrides:
      init in class ToolUser
    • setProperty

      protected final <T> void setProperty(Property<T> property, T value)
      Sets a property of the structure.
      Type Parameters:
      T - The type of the property.
      Parameters:
      property - The property to set.
      value - The value to set the property to.
      Throws:
      IllegalArgumentException - If the property is not valid for the structure type this property container was created for.
    • getProperty

      protected final <T> @Nullable T getProperty(Property<T> property)
      Gets a property of the structure.
      Type Parameters:
      T - The type of the property.
      Parameters:
      property - The property to get.
      Returns:
      The value of the property.
    • getRequiredProperty

      protected final <T> T getRequiredProperty(Property<T> property)
      Gets a required property of the structure.
      Type Parameters:
      T - The type of the property.
      Parameters:
      property - The property to get.
      Returns:
      The value of the property.
      Throws:
      NullPointerException - If the property is not set.
    • getStructureArg

      protected final Text.ArgumentCreator getStructureArg()
      Shortcut method for creating a new highlighted argument of the structure type.

      Can be used for Text object.

      Returns:
      The function that creates a new structure arg.
    • update

      public final CompletableFuture<Boolean> update(String stepName, @Nullable Object stepValue)
      Updates a step with a given name and value.
      Parameters:
      stepName - The name of the step to update.
      stepValue - The value to update the step with.
      Returns:
      A CompletableFuture that completes when the step has been updated.
      Throws:
      IllegalStateException - If the process is not in an updatable state.
    • handleExceptional

      protected final void handleExceptional(Throwable ex, String context)
      Handles an exception that occurred during the creation process.

      This method will handle the situation as follows:

      • Log the exception at SEVERE level.
      • Send an error message to the player.
      • Abort the creation process.
      Parameters:
      ex - The exception that occurred.
      context - The context in which the exception occurred. E.g. "prepare_set_open_status".
    • prepareSetOpenStatus

      protected void prepareSetOpenStatus()
      Prepares the step that sets the open status.
    • prepareSetOpenDirection

      protected void prepareSetOpenDirection()
      Prepares the step that sets the open direction.
    • constructStructureData

      protected final Structure constructStructureData(@Nullable IStructureComponent component)
      Constructs the Structure for the current structure. This is the same for all structures.
      Parameters:
      component - The component to use for the structure. Leave null to use the default component.
      Returns:
      The Structure for the current structure.
    • showPreview

      protected void showPreview()
    • prepareReviewResult

      protected void prepareReviewResult()
    • completeCreationProcess

      protected boolean completeCreationProcess()
      Completes the creation process. It'll construct and insert the structure and complete the ToolUser process.
      Returns:
      True, so that it fits the functional interface being used for the steps.

      If the insertion fails for whatever reason, it'll just be ignored, because at that point, there's no sense in continuing the creation process anyway.

    • giveTool

      protected final void giveTool(String nameKey, String loreKey)
      Adds the AnimatedArchitecture tool from the player's inventory.
      Parameters:
      nameKey - The localization key of the name of the tool.
      loreKey - The localization key of the lore of the tool.
    • giveTool

      protected abstract void giveTool()
      Method used to give the AnimatedArchitecture tool to the user.

      Overriding methods may call ToolUser.giveTool(String, String, Text).

    • completeNamingStep

      protected boolean completeNamingStep(String str)
      Completes the naming step for this Creator. This means that it'll set the name, go to the next step, and give the user the creator tool.

      Note that there are some requirements that the name must meet. See StringUtil.isValidStructureName(String).

      Parameters:
      str - The desired name of the structure.
      Returns:
      True if the naming step was finished successfully.
    • provideFirstPos

      protected CompletableFuture<Boolean> provideFirstPos(ILocation loc)
      Provides the first location of the selection and advances the procedure if successful.
      Parameters:
      loc - The first location of the cuboid.
      Returns:
      True if setting the location was successful.
    • createCuboid

      protected final Optional<Cuboid> createCuboid(Vector3Di combinedWith)
      Creates a new Cuboid with the first position and the combined with position.

      If the created Cuboid exceeds the size limit, the player will be informed and the result will be empty.

      Parameters:
      combinedWith - The position to combine with the first position.
      Returns:
      The newly-created Cuboid if the volume is within the limits, otherwise an empty Optional.
    • provideSecondPos

      protected CompletableFuture<Boolean> provideSecondPos(ILocation loc)
      Provides the second location of the selection and advances the procedure if successful.
      Parameters:
      loc - The second location of the cuboid.
      Returns:
      True if setting the location was successful.
    • confirmPrice

      protected boolean confirmPrice(boolean confirm)
      Attempts to buy the structure for the player and advances the procedure if successful.

      Note that if the player does not end up buying the structure, either because of insufficient funds or because they rejected the offer, the current step is NOT advanced!

      Parameters:
      confirm - Whether the player confirmed they want to buy this structure.
      Returns:
      Always returns true, because either they can and do buy the structure, or they cannot or refuse to buy the structure and the process is aborted.
    • completeSetOpenStatusStep

      protected boolean completeSetOpenStatusStep(boolean isOpen)
      Attempts to complete the step that provides the value of the Property.OPEN_STATUS.
      Parameters:
      isOpen - True if the current status of the structure is open.
      Returns:
      True if the open status was set successfully.
    • completeSetOpenDirStep

      protected boolean completeSetOpenDirStep(MovementDirection direction)
      Attempts to complete the step that provides the movementDirection.

      If the open direction is not valid for this type, nothing changes.

      Parameters:
      direction - The MovementDirection that was selected by the player.
      Returns:
      True if the movementDirection was set successfully.
    • constructStructure

      protected Structure constructStructure()
      Constructs the structure at the end of the creation process.
      Returns:
      The newly-created structure.
    • verifyWorldMatch

      protected boolean verifyWorldMatch(IWorld targetWorld)
      Verifies that the world of the selected location matches the world that this structure is being created in.
      Parameters:
      targetWorld - The world to check.
      Returns:
      True if the world is the same world this structure is being created in.
    • insertStructure

      protected void insertStructure(Structure structure)
      Takes care of inserting the structure.
      Parameters:
      structure - The structure to send to the DatabaseManager.
    • buyStructure

      protected boolean buyStructure()
      Attempts to buy the structure for the current player.
      Returns:
      True if the player has bought the structure or if the economy is not enabled.
    • getPrice

      protected OptionalDouble getPrice()
      Gets the price of the structure based on its volume. If the structure is free because the price is <= 0 or the IEconomyManager is disabled, the price will be empty.
      Returns:
      The price of the structure if a positive price could be found.
    • skipConfirmPrice

      protected boolean skipConfirmPrice()
      Checks if the step that asks the user to confirm that they want to buy the structure should be skipped.

      It should be skipped if the structure is free for whatever reason. See getPrice().

      Returns:
      True if the step that asks the user to confirm that they want to buy the structure should be skipped.
    • getValidOpenDirections

      public Set<MovementDirection> getValidOpenDirections()
      Gets the list of valid open directions for this type. It returns a subset of StructureType.getValidMovementDirections() based on the current physical aspects of the Structure.
      Returns:
      The list of valid open directions for this type given its current physical dimensions.
    • isPowerBlockWithinRangeLimit

      protected final boolean isPowerBlockWithinRangeLimit(Vector3Di pos, Cuboid cuboid)
      Checks if the power block is within the range limit.

      If the power block is too far away, the player will be informed and the method will return false.

      If the distance limit is not set, the method will return true.

      If the power block is inside the structure, the player will be informed and the method will return false.

      Parameters:
      pos - The position of the power block.
      cuboid - The cuboid that defines the structure.
      Returns:
      True if the power block is within the range limit.
    • completeSetPowerBlockStep

      protected CompletableFuture<Boolean> completeSetPowerBlockStep(ILocation loc)
      Attempts to complete the step in the Procedure that sets the second position of the Structure that is being created.
      Parameters:
      loc - The selected location of the rotation point.
      Returns:
      True if the location of the area was set successfully.
    • completeSetRotationPointStep

      protected boolean completeSetRotationPointStep(ILocation loc)
      Attempts to complete the step in the Procedure that sets the location of the rotation point for the Structure that is being created.
      Parameters:
      loc - The selected location of the rotation point.
      Returns:
      True if the location of the rotation point was set successfully.
    • setOpenStatusTextSupplier

      protected Text setOpenStatusTextSupplier(Text text)
    • setOpenDirectionTextSupplier

      protected Text setOpenDirectionTextSupplier(Text text)
    • getName

      protected final @Nullable String getName()
      Gets the name of the structure that is to be created.
      Returns:
      The name of the structure that is to be created.
    • getCuboid

      protected final @Nullable Cuboid getCuboid()
      Returns the cuboid of the structure that is to be created.
      Returns:
      The cuboid of the structure that is to be created or null if it has not been set yet.
    • getMovementDirection

      protected final @Nullable MovementDirection getMovementDirection()
      Returns the movement direction of the structure that is to be created.
      Returns:
      The movement direction of the structure that is to be created or null if it has not been set yet.
    • getPowerBlock

      protected final @Nullable Vector3Di getPowerBlock()
      Returns the location of the power block of the structure that is to be created.
      Returns:
      The power block of the structure that is to be created or null if it has not been set yet.
    • getFirstPos

      protected final @Nullable Vector3Di getFirstPos()
      Returns the first position of the structure that is to be created.

      This is used together with a second position to construct cuboid.

      Returns:
      The first position of the structure that is to be created or null if it has not been set yet.
    • getPowerblock

      protected final @Nullable Vector3Di getPowerblock()
      Returns the location of the power block of the structure that is to be created.
      Returns:
      The location of the power block of the structure that is to be created or null if it has not been set yet.
    • getWorld

      protected final @Nullable IWorld getWorld()
      Returns the world in which the structure that is to be created is located.
      Returns:
      The world in which the structure that is to be created is located or null if it has not been set yet.
    • isLocked

      protected final boolean isLocked()
      Whether the structure that is being created is locked.
      Returns:
      True if the structure that is being created is locked, false otherwise.

      This may not have been set yet, in which case it defaults to false.

    • isProcessIsUpdatable

      protected final boolean isProcessIsUpdatable()
      Whether the process is in a state where is may be updated outside the normal execution order.
      Returns:
      True if the process is in a state where is may be updated outside the normal execution order, false otherwise.
    • setCuboid

      protected final void setCuboid(Cuboid cuboid)
      Sets the name of the structure that is to be created.

      Note that this method sets it directly without any processing or validation. Use provideSecondPos(ILocation) to set it properly.

      Parameters:
      cuboid - The cuboid of the structure that is to be created.
    • setPowerblock

      protected final void setPowerblock(Vector3Di powerblock)
      Sets the power block of the structure that is to be created.

      Note that this method sets it directly without any processing or validation. Use completeSetPowerBlockStep(ILocation) to set it properly.

      Parameters:
      powerblock - The power block of the structure that is to be created.
    • setMovementDirection

      protected final void setMovementDirection(MovementDirection movementDirection)
      Sets the movement direction of the structure that is to be created.

      Note that this method sets it directly without any processing or validation. Use completeSetOpenDirStep(MovementDirection) to set it properly.

      Parameters:
      movementDirection - The movement direction of the structure that is to be created.
    • setWorld

      protected final void setWorld(IWorld world)
      Sets the world in which the structure that is to be created is located.

      Note that this method sets it directly without any processing or validation. Use provideFirstPos(ILocation) to set it properly.

      Parameters:
      world - The world in which the structure that is to be created is located.
    • setFirstPos

      protected final void setFirstPos(Vector3Di firstPos)
      Sets the first position of the structure that is to be created.

      Note that this method sets it directly without any processing or validation. Use provideFirstPos(ILocation) to set it properly.

      Parameters:
      firstPos - The first position of the structure that is to be created.
    • setLocked

      protected final void setLocked(boolean locked)
      Sets the locked status of the structure that is to be created.

      Note that this method sets it directly without any processing or validation. Use completeSetOpenStatusStep(boolean) to set it properly.

      Parameters:
      locked - True if the structure that is to be created is locked, false otherwise.
    • getUnregisteredUID

      public final long getUnregisteredUID()
      Gets the unregistered UID of the structure.

      This is a unique ID that is used to identify the structure before it is registered in the database.

      Returns:
      The unregistered UID of the structure.
    • toString

      public @NonNull String toString()
      Overrides:
      toString in class ToolUser
    • getStructureType

      public StructureType getStructureType()
      The type of structure this creator will create.
      Returns:
      The type of structure that will be created.