Class Structure
- All Implemented Interfaces:
IStructureConst, IPropertyHolder, IPropertyHolderConst
Please read the documentation of nl.pim16aap2.animatedarchitecture.core.structures for more information about
the structure system.
Changes made to this class will not automatically be updated in the database. To update the state in the database,
you can use the syncData() method.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this structure can move perpetually.booleancanRemoveProperty(Property<?> property) Checks if a property can be removed from this property holder.booleanChecks if this structure can be opened instantly (i.e. skip the animation).Constructs a new animation component for this structure.booleandoubleGets the distance traveled per animation by the animated block that travels the furthest.Gets the rectangle describing the limits within an animation of this door takes place.doubleGets the base animation time for this structure.Gets the basic information of this structure.Gets theCuboidrepresenting the area taken up by this structure.Cycle theMovementDirectiondirection thisStructurewill open in.doubleGets the lower time limit for an animation.getName()Gets the name of this structure.Gets theMovementDirectionthisStructurewill open if currently closed.Attempts to get theStructureOwnerof this structure represented by the UUID of a player.Gets allStructureOwners of this structure, including the original creator.Finds the new minimum and maximum coordinates (represented by aCuboid) of this structure that would be the result of toggling it.Gets the position of power block of this structure.Gets the prime owner (permission = 0) of this structure.Gets thePropertyContainerSnapshotof this structure.<T> IPropertyValue<T> getPropertyValue(Property<T> property) Gets the value of the given property.Returns a (read-only)StructureSnapshotof this structure.getType()Returns theStructureTypeof this structure.longgetUid()Gets the UID of theStructureas used in the database.getWorld()Gets the IWorld thisStructureexists in.inthashCode()booleanhasProperties(Collection<Property<?>> properties) Checks if this property holder has all the given properties.booleanhasProperty(Property<?> property) Checks if the given property has a value set.booleanChecks if the current thread holds a write lock.booleanisLocked()Represents the locked status of this structure.booleanChecks if a player with a given UUID is a (co-)owner of this structure with any level of ownership.booleanisOwner(UUID uuid, PermissionLevel permissionLevel) Checks if a player with a given UUID is a (co-)owner of this structure with a given level of ownership.voidHandles the chunk of the power block (or rotation point) being loaded.voidonRedstoneChange(boolean isPowered) Handles a change in redstone power.intGets the number of properties in this property container.<T> IPropertyValue<T> removeProperty(Property<T> property) Removes the given property from this property container.voidsetCoordinates(Cuboid newCuboid) Changes the position of thisStructure.voidsetCoordinates(Vector3Di posA, Vector3Di posB) Changes the position of thisStructure.voidsetLocked(boolean locked) Changes the lock status of this structure.voidChanges the name of the structure.voidsetOpenDirection(MovementDirection openDir) Sets theMovementDirectionthisStructurewill open if currently closed.voidsetPowerBlock(Vector3Di newPos) Updates the position of the powerblock.<T> IPropertyValue<T> setPropertyValue(Property<T> property, @Nullable T value) Sets the value of the given property.syncData()Synchronizes this structure with the database.syncData(boolean handleException) Synchronizes this structure with the database.toString()voidVerifies the redstone state of this structure.voidwithReadLock(Runnable runnable) Executes a Runnable under a read lock.<T> TwithReadLock(Supplier<T> supplier) Executes a supplier under a read lock.<T> TwithWriteLock(boolean resetAnimationData, Supplier<T> supplier) Executes a supplier under a write lock.voidwithWriteLock(Runnable runnable) Executes a Runnable under a write lock.<T> TwithWriteLock(Supplier<T> supplier) Executes a supplier under a write lock.Methods inherited from interface IPropertyHolderConst
getRequiredPropertyValue, hasProperties, hasPropertiesMethods inherited from interface IStructureConst
getBlockCount, getChunkId, getDimensions, getMaximum, getMinimum, getNameAndUid, getOwner, getPermissionLevel, getPermissionLevel, isOwner, isOwner
-
Method Details
-
getType
Description copied from interface:IStructureConstReturns theStructureTypeof this structure.- Specified by:
getTypein interfaceIStructureConst- Returns:
- The
StructureTypeof this structure.
-
getCycledOpenDirection
Description copied from interface:IStructureConstCycle theMovementDirectiondirection thisStructurewill open in. By default, it will loop over all valid directions. SeeStructureType.getValidOpenDirectionsList(). However, subclasses may override this behavior.Note that this does not actually change the open direction; it merely tells you which direction comes next!
- Specified by:
getCycledOpenDirectionin interfaceIStructureConst- Returns:
- The new
MovementDirectiondirection thisStructurewill open in.
-
canMovePerpetually
public boolean canMovePerpetually()Description copied from interface:IStructureConstChecks if this structure can move perpetually.- Specified by:
canMovePerpetuallyin interfaceIStructureConst- Returns:
- True if this structure can move perpetually.
-
constructAnimationComponent
Constructs a new animation component for this structure.- Parameters:
data- The data to construct the animation component with.- Returns:
- The constructed animation component.
-
getPotentialNewCoordinates
-
getAnimationCycleDistance
public double getAnimationCycleDistance()Gets the distance traveled per animation by the animated block that travels the furthest.For example, for a circular object, this will be a block on the edge, as these blocks travel further per revolution than the blocks closer to the center of the circle.
This method looks at the distance per animation cycle. The exact definition of a cycle depends on the implementation of the structure. For a big door, for example, a cycle could be a single toggle, or a quarter circle. To keep things easy, a revolving structure (which may not have a definitive end to its animation) could define a cycle as quarter circle as well.
The distance value is used to calculate
getMinimumAnimationTime()andgetBaseAnimationTime().- Returns:
- The longest distance traveled by an animated block measured in blocks.
-
getAnimationRange
Gets the rectangle describing the limits within an animation of this door takes place.At no point during an animation will any animated block leave this cuboid, though not guarantees are given regarding how tight the cuboid fits around the animated blocks.
- Specified by:
getAnimationRangein interfaceIStructureConst- Returns:
- The animation range.
-
getMinimumAnimationTime
public double getMinimumAnimationTime()Gets the lower time limit for an animation.Because animated blocks have a speed limit, as determined by
IConfig.maxBlockSpeed(), there is also a minimum amount of time for its animation.The exact time limit depends on the shape, size, and type of structure.
- Specified by:
getMinimumAnimationTimein interfaceIStructureConst- Returns:
- The lower animation time limit for this structure in seconds.
-
getBaseAnimationTime
public double getBaseAnimationTime()Gets the base animation time for this structure.This is the animation time without any multipliers applied to it.
- Returns:
- The base animation time for this structure in seconds.
-
canSkipAnimation
public boolean canSkipAnimation()Checks if this structure can be opened instantly (i.e. skip the animation).This describes whether skipping the animation actually does anything. When a structure can skip its animation, it means that the actual toggle has an effect on the world and as such toggling it without an animation does something.
Structures that do not have any effect other than their animation because all their blocks start and stop at exactly the same place (i.e. flags) cannot skip their animation because skipping the animation would mean removing the blocks of the structure from their locations and then placing them back at exactly the same position. This would be a waste of performance for both the server and the client and as such should be prevented.
- Returns:
- True, if this structure can skip its animation.
-
onChunkLoad
public void onChunkLoad()Handles the chunk of the power block (or rotation point) being loaded. -
verifyRedstoneState
public void verifyRedstoneState()Verifies the redstone state of this structure.This method will compare the current redstone state of the power block to the current state of this structure and act accordingly.
For example, if the structure is powered and this structure is currently closed, it will open the structure.
Or, if this is a structure that can move perpetually (e.g. a flag), it will stop the animation if the power block is no longer powered.
-
onRedstoneChange
public void onRedstoneChange(boolean isPowered) Handles a change in redstone power.This method makes two assumptions:
- The chunk containing the power block is loaded.
- The provided
isPoweredvalue reflects the power state of the power block in the world
If you cannot guarantee these assumptions, use
verifyRedstoneState()instead.- Parameters:
isPowered- The power state of the power block in the world.
-
getSnapshot
Description copied from interface:IStructureConstReturns a (read-only)StructureSnapshotof this structure.Repeated calls to this method may or may not return the same instance unless the underlying structure has been modified, in which case a new snapshot reflecting the changes will be returned.
- Specified by:
getSnapshotin interfaceIStructureConst- Returns:
- A
StructureSnapshotof this structure.
-
syncData
Synchronizes this structure with the database.- Parameters:
handleException- Whether to handle exceptions or not. When set totrue, exceptions that occur during the synchronization process will be caught and logged and the result will beDatabaseManager.ActionResult.FAIL.When set to
false, exceptions will not be handled and will be propagated to the caller.- Returns:
- The result of the synchronization.
-
syncData
Synchronizes this structure with the database.- Returns:
- The result of the synchronization.
-
hasWriteLock
public boolean hasWriteLock()Checks if the current thread holds a write lock.This method is intended for diagnostic assertions only (e.g., verifying that a caller already holds the write lock before performing a mutation). It should not be used for control-flow decisions outside of assertion contexts.
- Returns:
trueif the current thread holds a write lock.
-
withWriteLock
Executes a supplier under a write lock.- Type Parameters:
T- The return type of the supplier.- Parameters:
supplier- The supplier to execute under the write lock.- Returns:
- The value returned by the supplier.
- Throws:
IllegalStateException- When the current thread may is not allowed to obtain a write lock.
-
withWriteLock
Executes a supplier under a write lock.- Type Parameters:
T- The return type of the supplier.- Parameters:
resetAnimationData- Whether to reset the cached animation data after the supplier has been executed.This is useful when the supplier modifies the structure in a way that affects the animation data.
supplier- The supplier to execute under the write lock.- Returns:
- The value returned by the supplier.
- Throws:
IllegalStateException- When the current thread may is not allowed to obtain a write lock.
-
withWriteLock
Executes a Runnable under a write lock.- Throws:
IllegalStateException- When the current thread may is not allowed to obtain a write lock.
-
withReadLock
Executes a supplier under a read lock.- Type Parameters:
T- The return type of the supplier.- Parameters:
supplier- The supplier to execute under the read lock.- Returns:
- The value returned by the supplier.
-
withReadLock
Executes a Runnable under a read lock. -
getBasicInfo
Description copied from interface:IStructureConstGets the basic information of this structure.This includes the name, UID, type, and prime owner of this structure.
- Specified by:
getBasicInfoin interfaceIStructureConst- Returns:
- The basic information of this structure.
-
toString
-
getOwners
Description copied from interface:IStructureConstGets allStructureOwners of this structure, including the original creator.- Specified by:
getOwnersin interfaceIStructureConst- Returns:
- All
StructureOwners of this structure, including the original creator.
-
getOwner
Description copied from interface:IStructureConstAttempts to get theStructureOwnerof this structure represented by the UUID of a player.- Specified by:
getOwnerin interfaceIStructureConst- Parameters:
uuid- The UUID of the player that may or may not be an owner of this structure.- Returns:
- The
StructureOwnerof this structure for the given player, if this player is aStructureOwnerof this structure.
-
isOwner
Description copied from interface:IStructureConstChecks if a player with a given UUID is a (co-)owner of this structure with any level of ownership.If the level of ownership matters, use
IStructureConst.getOwner(UUID)instead.- Specified by:
isOwnerin interfaceIStructureConst- Parameters:
uuid- The UUID of a player.- Returns:
- True if the player with the given UUID is an owner of this structure with any level of ownership.
-
isOwner
Description copied from interface:IStructureConstChecks if a player with a given UUID is a (co-)owner of this structure with a given level of ownership.- Specified by:
isOwnerin interfaceIStructureConst- Parameters:
uuid- The UUID of a player.permissionLevel- The maximum level of ownership the player may have.E.g. when permissionLevel is
PermissionLevel.ADMIN, this method will return true if the player has admin access or lower (PermissionLevel.ADMINorPermissionLevel.CREATOR).- Returns:
- True if the player with the given UUID is an owner of this structure with the given level of ownership (or lower).
-
setCoordinates
-
setPowerBlock
Updates the position of the powerblock.- Parameters:
newPos- The new position.
-
setName
Changes the name of the structure.- Parameters:
name- The new name of this structure.
-
setOpenDirection
Sets theMovementDirectionthisStructurewill open if currently closed.Note that if it's currently in the open status, it is supposed go in the opposite direction, as the closing direction is the opposite of the opening direction.
- Parameters:
openDir- TheMovementDirectionthisStructurewill open in.
-
setLocked
public void setLocked(boolean locked) Changes the lock status of this structure. Locked structures cannot be opened.- Parameters:
locked- New lock status.
-
setCoordinates
-
getPropertyContainerSnapshot
Description copied from interface:IStructureConstGets thePropertyContainerSnapshotof this structure.- Specified by:
getPropertyContainerSnapshotin interfaceIStructureConst- Returns:
- The
PropertyContainerSnapshotof this structure.
-
getPropertyValue
Description copied from interface:IPropertyHolderConstGets the value of the given property.- Specified by:
getPropertyValuein interfaceIPropertyHolderConst- Type Parameters:
T- The type of the property.- Parameters:
property- The property to get the value of.- Returns:
- The value of the property.
-
hasProperty
Description copied from interface:IPropertyHolderConstChecks if the given property has a value set.- Specified by:
hasPropertyin interfaceIPropertyHolderConst- Parameters:
property- The property to check.- Returns:
trueif the property has a value set,falseotherwise.
-
hasProperties
Description copied from interface:IPropertyHolderConstChecks if this property holder has all the given properties.- Specified by:
hasPropertiesin interfaceIPropertyHolderConst- Parameters:
properties- The properties to check.- Returns:
trueif this property holder has all the given properties,falseotherwise.
-
propertyCount
public int propertyCount()Description copied from interface:IPropertyHolderConstGets the number of properties in this property container.This is the number of entries in the property map.
- Specified by:
propertyCountin interfaceIPropertyHolderConst- Returns:
- The number of properties in this property container.
-
canRemoveProperty
Description copied from interface:IPropertyHolderChecks if a property can be removed from this property holder.A property can not be removed under the following conditions:
-
The property is required (e.g. defined by
StructureType.getProperties()). - The property does not exist in this property holder.
- Specified by:
canRemovePropertyin interfaceIPropertyHolder- Parameters:
property- The property to check.- Returns:
trueif the property can be removed from this property holder,falseotherwise.
-
The property is required (e.g. defined by
-
removeProperty
Description copied from interface:IPropertyHolderRemoves the given property from this property container.Properties cannot be removed under certain conditions. When in doubt, check
IPropertyHolder.canRemoveProperty(Property).- Specified by:
removePropertyin interfaceIPropertyHolder- Type Parameters:
T- The type of the property.- Parameters:
property- The property to remove.- Returns:
- The previous value of the property, or
PropertyContainer.UnsetPropertyValue.INSTANCEif the property was not set. - Throws:
IllegalArgumentException- Thrown if;-
the property cannot be removed (i.e. it is specified by
StructureType.getProperties()). - the type of the removed property does not match the type of the property specified by the property.
-
the property cannot be removed (i.e. it is specified by
-
setPropertyValue
Description copied from interface:IPropertyHolderSets the value of the given property.- Specified by:
setPropertyValuein interfaceIPropertyHolder- Type Parameters:
T- The type of the property.- Parameters:
property- The property to set the value for.value- The value to set.If this is
null, the property will be removed.- Returns:
- The previous value of the property, or
nullif the property had no value set.
-
equals
- Specified by:
equalsin interfaceIStructureConst- Overrides:
equalsin classObject
-
hashCode
-
getUid
public long getUid()Description copied from interface:IStructureConstGets the UID of theStructureas used in the database. Guaranteed to be unique and available.- Specified by:
getUidin interfaceIStructureConst- Returns:
- The UID of the
Structureas used in the database.
-
getWorld
Description copied from interface:IStructureConstGets the IWorld thisStructureexists in.- Specified by:
getWorldin interfaceIStructureConst- Returns:
- The IWorld this
Structureexists in
-
getPowerBlock
Description copied from interface:IStructureConstGets the position of power block of this structure.- Specified by:
getPowerBlockin interfaceIStructureConst- Returns:
- The position of the power block of this structure.
-
getName
Description copied from interface:IStructureConstGets the name of this structure.- Specified by:
getNamein interfaceIStructureConst- Returns:
- The name of this structure.
-
getCuboid
Description copied from interface:IStructureConstGets theCuboidrepresenting the area taken up by this structure.- Specified by:
getCuboidin interfaceIStructureConst- Returns:
- The
Cuboidrepresenting the area taken up by this structure.
-
getOpenDirection
Description copied from interface:IStructureConstGets theMovementDirectionthisStructurewill open if currently closed.Note that if it's currently in the open status, it is supposed go in the opposite direction, as the closing direction is the opposite of the opening direction. This isn't taken into account by this method.
- Specified by:
getOpenDirectionin interfaceIStructureConst- Returns:
- The
MovementDirectionthisStructurewill open in.
-
isLocked
public boolean isLocked()Represents the locked status of this structure. True = locked, False = unlocked.- Specified by:
isLockedin interfaceIStructureConst- Returns:
- True if the
Structureis locked
-
getPrimeOwner
Description copied from interface:IStructureConstGets the prime owner (permission = 0) of this structure. In most cases, this will be the original creator of the structure.- Specified by:
getPrimeOwnerin interfaceIStructureConst- Returns:
- The prime owner of this structure.
-