geforkt von Mirrors/Paper
#1378: Add methods to convert between an entity and a SNBT string
By: Jishuna <joshl5324@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
760899464e
Commit
85591014c5
@ -157,6 +157,7 @@ import org.bukkit.craftbukkit.boss.CraftKeyedBossbar;
|
|||||||
import org.bukkit.craftbukkit.command.BukkitCommandWrapper;
|
import org.bukkit.craftbukkit.command.BukkitCommandWrapper;
|
||||||
import org.bukkit.craftbukkit.command.CraftCommandMap;
|
import org.bukkit.craftbukkit.command.CraftCommandMap;
|
||||||
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntityFactory;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
import org.bukkit.craftbukkit.generator.CraftWorldInfo;
|
import org.bukkit.craftbukkit.generator.CraftWorldInfo;
|
||||||
@ -305,6 +306,7 @@ public final class CraftServer implements Server {
|
|||||||
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
||||||
ConfigurationSerialization.registerClass(CraftPlayerProfile.class);
|
ConfigurationSerialization.registerClass(CraftPlayerProfile.class);
|
||||||
CraftItemFactory.instance();
|
CraftItemFactory.instance();
|
||||||
|
CraftEntityFactory.instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftServer(DedicatedServer console, PlayerList playerList) {
|
public CraftServer(DedicatedServer console, PlayerList playerList) {
|
||||||
@ -2179,6 +2181,11 @@ public final class CraftServer implements Server {
|
|||||||
return CraftItemFactory.instance();
|
return CraftItemFactory.instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntityFactory getEntityFactory() {
|
||||||
|
return CraftEntityFactory.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CraftScoreboardManager getScoreboardManager() {
|
public CraftScoreboardManager getScoreboardManager() {
|
||||||
return scoreboardManager;
|
return scoreboardManager;
|
||||||
|
@ -780,6 +780,16 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|||||||
return getHandle().inWorld;
|
return getHandle().inWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAsString() {
|
||||||
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
if (!getHandle().saveAsPassenger(tag, false)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag.getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntitySnapshot createSnapshot() {
|
public EntitySnapshot createSnapshot() {
|
||||||
return CraftEntitySnapshot.create(this);
|
return CraftEntitySnapshot.create(this);
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
package org.bukkit.craftbukkit.entity;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import net.minecraft.nbt.MojangsonParser;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import org.bukkit.entity.EntityFactory;
|
||||||
|
import org.bukkit.entity.EntitySnapshot;
|
||||||
|
|
||||||
|
public class CraftEntityFactory implements EntityFactory {
|
||||||
|
|
||||||
|
private static final CraftEntityFactory instance;
|
||||||
|
|
||||||
|
static {
|
||||||
|
instance = new CraftEntityFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CraftEntityFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntitySnapshot createEntitySnapshot(String input) {
|
||||||
|
Preconditions.checkArgument(input != null, "Input string cannot be null");
|
||||||
|
|
||||||
|
NBTTagCompound tag;
|
||||||
|
try {
|
||||||
|
tag = MojangsonParser.parseTag(input);
|
||||||
|
} catch (CommandSyntaxException e) {
|
||||||
|
throw new IllegalArgumentException("Could not parse Entity: " + input, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityTypes<?> type = EntityTypes.by(tag).orElse(null);
|
||||||
|
if (type == null) {
|
||||||
|
throw new IllegalArgumentException("Could not parse Entity: " + input);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CraftEntitySnapshot.create(tag, CraftEntityType.minecraftToBukkit(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftEntityFactory instance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
@ -42,6 +42,11 @@ public class CraftEntitySnapshot implements EntitySnapshot {
|
|||||||
return location.getWorld().addEntity(internal.getBukkitEntity());
|
return location.getWorld().addEntity(internal.getBukkitEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAsString() {
|
||||||
|
return data.getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
private net.minecraft.world.entity.Entity createInternal(World world) {
|
private net.minecraft.world.entity.Entity createInternal(World world) {
|
||||||
net.minecraft.world.level.World nms = ((CraftWorld) world).getHandle();
|
net.minecraft.world.level.World nms = ((CraftWorld) world).getHandle();
|
||||||
net.minecraft.world.entity.Entity internal = EntityTypes.loadEntityRecursive(data, nms, Function.identity());
|
net.minecraft.world.entity.Entity internal = EntityTypes.loadEntityRecursive(data, nms, Function.identity());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren