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 either the syncData() method or the syncDataAsync() method.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this structure can move perpetually.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.getType()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.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 rotation point being loaded.voidonRedstoneChange(boolean isPowered) Handles a change in redstone power.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 pos) Updates the position of the powerblock.<T> IPropertyValue<T> setPropertyValue(Property<T> property, T value) Sets the value of the given property.syncData()Synchronizes this structure and its serialized type-specific data of anStructurewith the database.Synchronizes this structure and its serialized type-specific data of anStructurewith 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) 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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface nl.pim16aap2.animatedarchitecture.core.structures.properties.IPropertyHolderConst
getRequiredPropertyValue, hasProperties, hasPropertiesMethods inherited from interface nl.pim16aap2.animatedarchitecture.core.structures.IStructureConst
getBlockCount, getChunkId, getDimensions, getMaximum, getMinimum, getNameAndUid, getOwner, isOwner, isOwner
-
Method Details
-
getType
- 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
Finds the new minimum and maximum coordinates (represented by aCuboid) of this structure that would be the result of toggling it.- Returns:
- The
Cuboidthat would represent the structure if it was toggled right now.
-
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 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
- Specified by:
getSnapshotin interfaceIStructureConst- Returns:
- A
StructureSnapshotof thisIStructureConst.
-
syncDataAsync
Synchronizes this structure and its serialized type-specific data of anStructurewith the database.Unlike
syncData(), this method will not block the current thread to wait for 1) a read lock to be obtained, 2) the snapshot to be created, and 3) the data to be serialized. -
syncData
Synchronizes this structure and its serialized type-specific data of anStructurewith the database.- Returns:
- The result of the synchronization.
-
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
-
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
Changes the position of thisStructure. The min/max order of the positions doesn't matter.- Parameters:
newCuboid- TheCuboidrepresenting the area the structure will take up from now on.
-
setPowerBlock
Updates the position of the powerblock.- Parameters:
pos- 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
Changes the position of thisStructure. The min/max order of the positions does not matter.- Parameters:
posA- The first new position.posB- The second new position.
-
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.
-
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. May benullif the property is nullable.- Returns:
- The previous value of the property, or
nullif the property had no value set.
-
equals
- Specified by:
equalsin interfaceIStructureConst- Overrides:
equalsin classObject
-
hashCode
public int 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.
-