#994: Add methods to convert between an entity and a string

By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
Bukkit/Spigot
2024-04-24 01:15:00 +10:00
parent d9a704e3f6
commit bfd5351193
5 changed files with 66 additions and 0 deletions

View File

@@ -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.
*

View File

@@ -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;
}

View File

@@ -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();
}