From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: EOT3000 Date: Sat, 10 Jun 2023 20:27:14 -0400 Subject: [PATCH] Stored Bee API diff --git a/src/main/java/org/bukkit/block/EntityBlockStorage.java b/src/main/java/org/bukkit/block/EntityBlockStorage.java index 739911cda33b373f99df627a3a378b37d7d461aa..51e78c22cd021722b963fe31d1d9175d141add1a 100644 --- a/src/main/java/org/bukkit/block/EntityBlockStorage.java +++ b/src/main/java/org/bukkit/block/EntityBlockStorage.java @@ -47,6 +47,24 @@ public interface EntityBlockStorage extends TileState { @NotNull List releaseEntities(); + // Purpur start + /** + * Releases a stored entity, and returns the entity in the world. + * + * @param entity Entity to release + * @return The entity which was released, or null if the stored entity is not in the hive + */ + @org.jetbrains.annotations.Nullable + T releaseEntity(@NotNull org.purpurmc.purpur.entity.StoredEntity entity); + + /** + * Gets all the entities currently stored in the block. + * + * @return List of all entities which are stored in the block + */ + @NotNull + List> getEntities(); + //Purpur end /** * Add an entity to the block. * diff --git a/src/main/java/org/purpurmc/purpur/entity/StoredEntity.java b/src/main/java/org/purpurmc/purpur/entity/StoredEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..29540d55532197d2381a52ea9222b5785d224ef8 --- /dev/null +++ b/src/main/java/org/purpurmc/purpur/entity/StoredEntity.java @@ -0,0 +1,52 @@ +package org.purpurmc.purpur.entity; + +import org.bukkit.Nameable; +import org.bukkit.block.EntityBlockStorage; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.persistence.PersistentDataHolder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents an entity stored in a block + * + * @see org.bukkit.block.EntityBlockStorage + */ +public interface StoredEntity extends PersistentDataHolder, Nameable { + /** + * Checks if this entity has been released yet + * + * @return if this entity has been released + */ + boolean hasBeenReleased(); + + /** + * Releases the entity from its stored block + * + * @return the released entity, or null if unsuccessful (including if this entity has already been released) + */ + @Nullable + T release(); + + /** + * Returns the block in which this entity is stored + * + * @return the EntityBlockStorage in which this entity is stored, or null if it has been released + */ + @Nullable + EntityBlockStorage getBlockStorage(); + + /** + * Gets the entity type of this stored entity + * + * @return the type of entity this stored entity represents + */ + @NotNull + EntityType getType(); + + /** + * Writes data to the block entity snapshot. {@link EntityBlockStorage#update()} must be run in order to update the block in game. + */ + void update(); +}