From 0000000000000000000000000000000000000000 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 diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java index b134d63351faa0d6e5469e0a09442ab82f8d60e3..26006c3241efc76f0bbf9ba80bfada4bbf52c278 100644 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -140,6 +140,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/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java index a06700c47c0abb55d8b971e6a85ed80be75168ce..b0a4c772f1f189991cbd6ffd13db8320decebff5 100644 --- a/src/main/java/org/bukkit/entity/Entity.java +++ b/src/main/java/org/bukkit/entity/Entity.java @@ -834,5 +834,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent * @return players in tracking range */ @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 }