Class Creator
- Direct Known Subclasses:
CreatorBigDoor, CreatorClock, CreatorDrawbridge, CreatorFlag, CreatorGarageDoor, CreatorPortcullis, CreatorSlidingDoor, CreatorWindMill
-
Nested Class Summary
Nested classes/interfaces inherited from class ToolUser
ToolUser.Context -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CommandFactoryprotected final IConfigprotected final DatabaseManagerprotected final IEconomyManagerprotected final Step.FactoryFactory for theStepthat completes this process.protected final Step.FactoryFactory for theStepthat allows the player to confirm or reject the price of the structure.protected final Step.FactoryFactory for theStepthat provides the first position of the area of the structure.protected final Step.FactoryFactory for theStepthat provides the name.protected final Step.FactoryFactory for theStepthat provides the open direction of the structure.protected final Step.FactoryFactory for theStepthat provides the open status of the structure.protected final Step.FactoryFactory for theStepthat provides the position of the structure's power block.protected final Step.FactoryFactory for theStepthat provides the position of the structure's rotation point.protected final Step.Factoryprotected final Step.FactoryFactory for theStepthat allows players to review the created structureprotected final LimitsManagerprotected final StructureBuilderprotected final StructureIDprotected final StructureTypeThe type of structure this creator will create.Fields inherited from class ToolUser
animatedArchitectureToolUtil, localizer, protectionHookManager, stepFactory, toolUserManager -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreator(ToolUser.Context context, StructureType structureType, IPlayer player, @Nullable String name) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanAttempts to buy the structure for the current player.protected booleanCompletes the creation process.protected booleancompleteNamingStep(String str) Completes the naming step for thisCreator.protected booleancompleteSetOpenDirStep(MovementDirection direction) Attempts to complete the step that provides themovementDirection.protected booleancompleteSetOpenStatusStep(boolean isOpen) Attempts to complete the step that provides the value of theProperty.OPEN_STATUS.protected CompletableFuture<Boolean> protected booleanprotected booleanconfirmPrice(boolean confirm) Attempts to buy the structure for the player and advances the procedure if successful.protected StructureConstructs the structure at the end of the creation process.protected final StructureconstructStructureData(@Nullable IStructureComponent component) Constructs theStructurefor the current structure.createCuboid(Vector3Di combinedWith) Creates a newCuboidwith the first position and the combined with position.protected final @Nullable CuboidReturns the cuboid of the structure that is to be created.protected final @Nullable Vector3DiReturns the first position of the structure that is to be created.protected final @Nullable MovementDirectionReturns the movement direction of the structure that is to be created.protected final @Nullable StringgetName()Gets the name of the structure that is to be created.protected final @Nullable Vector3DiReturns the location of the power block of the structure that is to be created.protected final @Nullable Vector3DiReturns the location of the power block of the structure that is to be created.protected OptionalDoublegetPrice()Gets the price of the structure based on its volume.protected final <T> @Nullable TgetProperty(Property<T> property) Gets a property of the structure.protected final <T> TgetRequiredProperty(Property<T> property) Gets a required property of the structure.protected final Text.ArgumentCreatorShortcut method for creating a new highlighted argument of the structure type.The type of structure this creator will create.final longGets the unregistered UID of the structure.Gets the list of valid open directions for this type.protected final @Nullable IWorldgetWorld()Returns the world in which the structure that is to be created is located.protected abstract voidgiveTool()Method used to give the AnimatedArchitecture tool to the user.protected final voidAdds the AnimatedArchitecture tool from the player's inventory.protected final voidhandleExceptional(Throwable ex, String context) Handles an exception that occurred during the creation process.protected voidinit()Basic initialization executed that should be called after the constructor.protected voidinsertStructure(Structure structure) Takes care of inserting the structure.protected final booleanisLocked()Whether the structure that is being created is locked.protected final booleanisPowerBlockWithinRangeLimit(Vector3Di pos, Cuboid cuboid) Checks if the power block is within the range limit.protected final booleanWhether the process is in a state where is may be updated outside the normal execution order.protected voidprotected voidPrepares the step that sets the open direction.protected voidPrepares the step that sets the open status.protected CompletableFuture<Boolean> provideFirstPos(ILocation loc) Provides the first location of the selection and advances the procedure if successful.protected CompletableFuture<Boolean> Provides the second location of the selection and advances the procedure if successful.protected final voidSets the name of the structure that is to be created.protected final voidsetFirstPos(Vector3Di firstPos) Sets the first position of the structure that is to be created.protected final voidsetLocked(boolean locked) Sets the locked status of the structure that is to be created.protected final voidsetMovementDirection(MovementDirection movementDirection) Sets the movement direction of the structure that is to be created.protected Textprotected Textprotected final voidsetPowerblock(Vector3Di powerblock) Sets the power block of the structure that is to be created.protected final <T> voidsetProperty(Property<T> property, T value) Sets a property of the structure.protected final voidSets the world in which the structure that is to be created is located.protected voidprotected booleanChecks if the step that asks the user to confirm that they want to buy the structure should be skipped.@NonNull StringtoString()final CompletableFuture<Boolean> Updates a step with a given name and value.protected booleanverifyWorldMatch(IWorld targetWorld) Verifies that the world of the selected location matches the world that this structure is being created in.Methods inherited from class ToolUser
abort, assertLockHeld, cleanUpProcess, generateSteps, getAllSteps, getCurrentStep, getCurrentStepMessage, getPlayer, giveTool, goToNextStep, handleInput, handleInputWithLock, insertStep, isActive, playerHasAccessToCuboid, playerHasAccessToLocation, playerHasTool, prepareCurrentStep, removeTool, runWithLock, sendMessage, sendMessage, setPlayerHasTool, skipToStep, toMinimalString
-
Field Details
-
limitsManager
-
structureBuilder
-
databaseManager
-
economyManager
-
commandFactory
-
config
-
structureID
-
factoryProvideName
Factory for theStepthat provides the name. -
factoryProvideFirstPos
Factory for theStepthat provides the first position of the area of the structure.Don't forget to set the message before using it!
-
factoryProvideSecondPos
-
factoryProvideRotationPointPos
Factory for theStepthat provides the position of the structure's rotation point.Don't forget to set the message before using it!
-
factoryProvidePowerBlockPos
Factory for theStepthat provides the position of the structure's power block. -
factoryProvideOpenStatus
Factory for theStepthat provides the open status of the structure. -
factoryProvideOpenDir
Factory for theStepthat provides the open direction of the structure. -
factoryConfirmPrice
Factory for theStepthat allows the player to confirm or reject the price of the structure. -
factoryReviewResult
Factory for theStepthat allows players to review the created structure -
factoryCompleteProcess
Factory for theStepthat completes this process.Don't forget to set the message before using it!
-
structureType
The type of structure this creator will create.
-
-
Constructor Details
-
Creator
protected Creator(ToolUser.Context context, StructureType structureType, IPlayer player, @Nullable String name)
-
-
Method Details
-
init
protected void init()Description copied from class:ToolUserBasic initialization executed that should be called after the constructor.This method will initialize the
Procedureusing the steps generated byToolUser.generateSteps()and register thisToolUserwith theToolUserManager.If this method is not called, the
ToolUserwill 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.
-
setProperty
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
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
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
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
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
CompletableFuturethat completes when the step has been updated. - Throws:
IllegalStateException- If the process is not in an updatable state.
-
handleExceptional
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
-
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 theToolUserprocess.- 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
-
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
Completes the naming step for thisCreator. 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
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
-
provideSecondPos
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 theProperty.OPEN_STATUS.- Parameters:
isOpen- True if the current status of the structure is open.- Returns:
- True if the open status was set successfully.
-
completeSetOpenDirStep
Attempts to complete the step that provides themovementDirection.If the open direction is not valid for this type, nothing changes.
- Parameters:
direction- TheMovementDirectionthat was selected by the player.- Returns:
- True if the
movementDirectionwas set successfully.
-
constructStructure
Constructs the structure at the end of the creation process.- Returns:
- The newly-created structure.
-
verifyWorldMatch
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
Takes care of inserting the structure.- Parameters:
structure- The structure to send to theDatabaseManager.
-
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
Gets the price of the structure based on its volume. If the structure is free because the price is <= 0 or theIEconomyManageris 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
Gets the list of valid open directions for this type. It returns a subset ofStructureType.getValidMovementDirections()based on the current physical aspects of theStructure.- Returns:
- The list of valid open directions for this type given its current physical dimensions.
-
isPowerBlockWithinRangeLimit
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
-
completeSetRotationPointStep
-
setOpenStatusTextSupplier
-
setOpenDirectionTextSupplier
-
getName
Gets the name of the structure that is to be created.- Returns:
- The name of the structure that is to be created.
-
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
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
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
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
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
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
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
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
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
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
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
-
getStructureType
The type of structure this creator will create.- Returns:
- The type of structure that will be created.
-