From 65568bbe277a6e953d3f831be2b186262a0dcbc3 Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Sun, 24 Oct 2021 16:19:26 -0400 Subject: [PATCH] Add Raw Byte Entity Serialization --- .../main/java/org/bukkit/UnsafeValues.java | 8 ++++++ .../main/java/org/bukkit/entity/Entity.java | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/UnsafeValues.java b/paper-api/src/main/java/org/bukkit/UnsafeValues.java index 4cd43815c3..5be89089da 100644 --- a/paper-api/src/main/java/org/bukkit/UnsafeValues.java +++ b/paper-api/src/main/java/org/bukkit/UnsafeValues.java @@ -169,6 +169,14 @@ public interface UnsafeValues { ItemStack deserializeItem(byte[] data); + byte[] serializeEntity(org.bukkit.entity.Entity entity); + + default org.bukkit.entity.Entity deserializeEntity(byte[] data, World world) { + return deserializeEntity(data, world, false); + } + + org.bukkit.entity.Entity deserializeEntity(byte[] data, World world, boolean preserveUUID); + /** * Creates and returns the next EntityId available. *

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 3b40c63a38..464668496f 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -946,5 +946,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent */ @Deprecated @NotNull Set getTrackedPlayers(); + + /** + * Spawns the entity in the world at the given {@link Location} with the default spawn reason. + *

+ * This will not spawn the entity if the entity is already spawned or has previously been despawned. + *

+ * Also, this method will fire the same events as a normal entity spawn. + * + * @param location The location to spawn the entity at. + * @return Whether the entity was successfully spawned. + */ + public default boolean spawnAt(@NotNull Location location) { + return spawnAt(location, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); + } + + /** + * Spawns the entity in the world at the given {@link Location} with the reason given. + *

+ * This will not spawn the entity if the entity is already spawned or has previously been despawned. + *

+ * Also, this method will fire the same events as a normal entity spawn. + * + * @param location The location to spawn the entity at. + * @param reason The reason for the entity being spawned. + * @return Whether the entity was successfully spawned. + */ + public boolean spawnAt(@NotNull Location location, @NotNull org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason); // Paper end }