diff --git a/paper-api/src/main/java/org/bukkit/Bukkit.java b/paper-api/src/main/java/org/bukkit/Bukkit.java index 2e558ebebc..c19f89f7d6 100644 --- a/paper-api/src/main/java/org/bukkit/Bukkit.java +++ b/paper-api/src/main/java/org/bukkit/Bukkit.java @@ -27,6 +27,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityFactory; +import org.bukkit.entity.EntitySnapshot; import org.bukkit.entity.Player; import org.bukkit.entity.SpawnCategory; import org.bukkit.event.inventory.InventoryType; @@ -1723,6 +1725,17 @@ public final class Bukkit { return server.getItemFactory(); } + /** + * Gets the instance of the entity factory (for {@link EntitySnapshot}). + * + * @return the entity factory + * @see EntityFactory + */ + @NotNull + public static EntityFactory getEntityFactory() { + return server.getEntityFactory(); + } + /** * Gets the instance of the scoreboard manager. * <p> diff --git a/paper-api/src/main/java/org/bukkit/Server.java b/paper-api/src/main/java/org/bukkit/Server.java index 3b8832ee40..bea7a3ccb8 100644 --- a/paper-api/src/main/java/org/bukkit/Server.java +++ b/paper-api/src/main/java/org/bukkit/Server.java @@ -27,6 +27,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityFactory; +import org.bukkit.entity.EntitySnapshot; import org.bukkit.entity.Player; import org.bukkit.entity.SpawnCategory; import org.bukkit.event.inventory.InventoryType; @@ -1461,6 +1463,15 @@ public interface Server extends PluginMessageRecipient { @NotNull ItemFactory getItemFactory(); + /** + * Gets the instance of the entity factory (for {@link EntitySnapshot}). + * + * @return the entity factory + * @see EntityFactory + */ + @NotNull + EntityFactory getEntityFactory(); + /** * Gets the instance of the scoreboard manager. * <p> diff --git a/paper-api/src/main/java/org/bukkit/entity/Entity.java b/paper-api/src/main/java/org/bukkit/entity/Entity.java index dcd2b5097f..dee99ac294 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -726,6 +726,17 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent */ boolean isInWorld(); + /** + * Get this entity as an NBT string. + * <p> + * This string should not be relied upon as a serializable value. + * + * @return the NBT string or null if one cannot be made + */ + @Nullable + @ApiStatus.Experimental + String getAsString(); + /** * Crates an {@link EntitySnapshot} representing the current state of this entity. * diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityFactory.java b/paper-api/src/main/java/org/bukkit/entity/EntityFactory.java new file mode 100644 index 0000000000..44cce12613 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/entity/EntityFactory.java @@ -0,0 +1,19 @@ +package org.bukkit.entity; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +@ApiStatus.Experimental +public interface EntityFactory { + + /** + * Create a new EntitySnapshot with the supplied input.<br> + * Accepts strings in the format output by {@link EntitySnapshot#getAsString()}. + * + * @param input the input string + * @return the created EntitySnapshot + * @throws IllegalArgumentException if the input string was provided in an invalid or unsupported format + */ + @NotNull + EntitySnapshot createEntitySnapshot(@NotNull String input) throws IllegalArgumentException; +} diff --git a/paper-api/src/main/java/org/bukkit/entity/EntitySnapshot.java b/paper-api/src/main/java/org/bukkit/entity/EntitySnapshot.java index 6f34486ab1..737e38f237 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntitySnapshot.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntitySnapshot.java @@ -2,6 +2,7 @@ package org.bukkit.entity; import org.bukkit.Location; import org.bukkit.World; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** @@ -36,4 +37,15 @@ public interface EntitySnapshot { */ @NotNull EntityType getEntityType(); + + /** + * Get this EntitySnapshot as an NBT string. + * <p> + * This string should not be relied upon as a serializable value. + * + * @return the NBT string + */ + @NotNull + @ApiStatus.Experimental + String getAsString(); }