mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
Added Entity and serialization options to the NBT
This commit is contained in:
parent
28b2d99b04
commit
f24188d3bd
@ -22,4 +22,10 @@ public interface NBTCompound {
|
||||
|
||||
NBTObject getNBTObject(String tag);
|
||||
|
||||
byte[] serialize(String... exclusions);
|
||||
|
||||
void deSerialize(byte[] serialized);
|
||||
|
||||
void addExtras();
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.songoda.core.nms.nbt;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface NBTCore {
|
||||
|
||||
NBTItem of(ItemStack item);
|
||||
|
||||
NBTCompound newCompound();
|
||||
NBTItem newItem();
|
||||
|
||||
NBTEntity of(Entity entity);
|
||||
|
||||
NBTEntity newEntity();
|
||||
|
||||
}
|
||||
|
12
NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTEntity.java
Normal file
12
NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTEntity.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.songoda.core.nms.nbt;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public interface NBTEntity extends NBTCompound {
|
||||
|
||||
Entity spawn(Location location);
|
||||
|
||||
Entity reSpawn(Location location);
|
||||
|
||||
}
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_10_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_10_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.g(); // Changed in 1.12
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_10_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.core.nms.v1_10_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_10_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
entityType, // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_10_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_10_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_10_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_10_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_11_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_11_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.g(); // Changed in 1.12
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_11_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.core.nms.v1_11_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_11_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
new MinecraftKey(entityType),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_11_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_11_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_11_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_11_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_12_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_12_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.g(); // Changed in 1.12
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_12_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.songoda.core.nms.v1_12_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
new MinecraftKey(entityType),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_12_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_12_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_12_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_12_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_13_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_13_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.clone();
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_13_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_13_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
package com.songoda.core.nms.v1_13_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_13_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = Optional.ofNullable(EntityTypes.a(entityType)); // Changed since 1.13.2
|
||||
if (optionalEntity.isPresent()) {
|
||||
Entity spawned = optionalEntity.get().spawnCreature(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
//EnumMobSpawn.COMMAND, // Changed since 1.14
|
||||
true,
|
||||
false,
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
MinecraftKey key = EntityTypes.REGISTRY.b(nmsEntity.getEntityType());
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key.toString()); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_13_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_13_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_13_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_13_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_13_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_13_R2.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.clone();
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_13_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
package com.songoda.core.nms.v1_13_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_13_R2.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = Optional.ofNullable(EntityTypes.a(entityType)); // Changed since 1.13.2
|
||||
if (optionalEntity.isPresent()) {
|
||||
Entity spawned = optionalEntity.get().spawnCreature(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
//EnumMobSpawn.COMMAND, // Changed since 1.13.2
|
||||
true,
|
||||
false,
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
MinecraftKey key = IRegistry.ENTITY_TYPE.getKey(nmsEntity.P());
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key.toString()); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_13_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_13_R2.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_13_R2.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_13_R2.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_14_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.clone();
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_14_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.songoda.core.nms.v1_14_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_14_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType);
|
||||
if (optionalEntity.isPresent()) {
|
||||
Entity spawned = optionalEntity.get().spawnCreature(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
EnumMobSpawn.COMMAND,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
compound.setString("entity_type", IRegistry.ENTITY_TYPE.getKey(nmsEntity.getEntityType()).toString());
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_14_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_14_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_14_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_14_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package com.songoda.core.nms.v1_15_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_15_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagList;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.*;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -77,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.clone();
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_15_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_15_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.songoda.core.nms.v1_15_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_15_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType);
|
||||
if (optionalEntity.isPresent()) {
|
||||
Entity spawned = optionalEntity.get().spawnCreature(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
EnumMobSpawn.COMMAND,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
compound.setString("entity_type", IRegistry.ENTITY_TYPE.getKey(nmsEntity.getEntityType()).toString());
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_15_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_15_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_15_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_15_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package com.songoda.core.nms.v1_16_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_16_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_16_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R1.NBTTagList;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -75,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.clone();
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_16_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_16_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_16_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package com.songoda.core.nms.v1_16_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_16_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType);
|
||||
if (optionalEntity.isPresent()) {
|
||||
Entity spawned = optionalEntity.get().spawnCreature(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
EnumMobSpawn.COMMAND,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.load(compound);
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
entity.teleport(location);
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
compound.setString("entity_type", IRegistry.ENTITY_TYPE.getKey(nmsEntity.getEntityType()).toString());
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_16_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_16_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_16_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_16_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_16_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package com.songoda.core.nms.v1_16_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_16_R2.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_16_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R2.NBTTagList;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -75,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = this.compound.clone();
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,12 @@ package com.songoda.core.nms.v1_16_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_16_R2.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +18,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_16_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.save(nbt);
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package com.songoda.core.nms.v1_16_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_16_R2.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType);
|
||||
if (optionalEntity.isPresent()) {
|
||||
Entity spawned = optionalEntity.get().spawnCreature(
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
compound,
|
||||
null,
|
||||
null,
|
||||
new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()),
|
||||
EnumMobSpawn.COMMAND,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.load(compound);
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
entity.teleport(location);
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
compound.setString("entity_type", IRegistry.ENTITY_TYPE.getKey(nmsEntity.getEntityType()).toString());
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package com.songoda.core.nms.v1_16_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_16_R2.IRegistry;
|
||||
import net.minecraft.server.v1_16_R2.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +12,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_16_R2.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_16_R2.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_16_R2.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_8_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_8_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = (NBTTagCompound)this.compound.clone(); // Changed in 1.12 // Changed in 1.9.4
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_8_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_8_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.songoda.core.nms.v1_8_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_8_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private static Field fieldG;
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
fieldG = EntityTypes.class.getDeclaredField("g");
|
||||
fieldG.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
try {
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
((Map<String, Integer>) fieldG.get(null)).get(entityType), // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_8_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_8_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_8_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_8_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_8_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_8_R2.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_8_R2.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = (NBTTagCompound)this.compound.clone(); // Changed in 1.12 // Changed in 1.9.4
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_8_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_8_R2.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_8_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.songoda.core.nms.v1_8_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_8_R2.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private static Field fieldG;
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
fieldG = EntityTypes.class.getDeclaredField("g");
|
||||
fieldG.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
try {
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
((Map<String, Integer>) fieldG.get(null)).get(entityType), // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_8_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_8_R2.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_8_R2.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_8_R2.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_8_R2.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_8_R3.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = (NBTTagCompound)this.compound.clone(); // Changed in 1.12 // Changed in 1.9.4
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_8_R3.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.songoda.core.nms.v1_8_R3.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private static Field fieldG;
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
fieldG = EntityTypes.class.getDeclaredField("g");
|
||||
fieldG.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
try {
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
((Map<String, Integer>) fieldG.get(null)).get(entityType), // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_8_R3.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_8_R3.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_8_R3.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_8_R3.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_9_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_9_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = (NBTTagCompound)this.compound.clone(); // Changed in 1.12 // Changed in 1.9.4
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_9_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.core.nms.v1_9_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
entityType, // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_9_R1.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_9_R1.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_9_R1.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_9_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package com.songoda.core.nms.v1_9_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTObject;
|
||||
import net.minecraft.server.v1_9_R2.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
||||
|
||||
public class NBTCompoundImpl implements NBTCompound {
|
||||
import java.io.*;
|
||||
|
||||
public abstract class NBTCompoundImpl implements NBTCompound {
|
||||
|
||||
protected NBTTagCompound compound;
|
||||
|
||||
@ -74,4 +77,33 @@ public class NBTCompoundImpl implements NBTCompound {
|
||||
return new NBTObjectImpl(compound, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(String... exclusions) {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
|
||||
addExtras();
|
||||
NBTTagCompound compound = (NBTTagCompound)this.compound.clone(); // Changed in 1.12 // Changed in 1.9.4
|
||||
|
||||
for (String exclusion : exclusions)
|
||||
compound.remove(exclusion);
|
||||
|
||||
NBTCompressedStreamTools.a(compound, (OutputStream) dataOutput);
|
||||
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialize(byte[] serialized) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
|
||||
ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
|
||||
compound = NBTCompressedStreamTools.a((InputStream) dataInput);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.core.nms.v1_9_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTCompound;
|
||||
import com.songoda.core.nms.nbt.NBTCore;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTCoreImpl implements NBTCore {
|
||||
@ -14,8 +17,21 @@ public class NBTCoreImpl implements NBTCore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTCompound newCompound() {
|
||||
return new NBTCompoundImpl();
|
||||
public NBTItem newItem() {
|
||||
return new NBTItemImpl(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity of(Entity entity) {
|
||||
net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nmsEntity.e(nbt); // Method name changed in 1.11
|
||||
return new NBTEntityImpl(nbt, nmsEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTEntity newEntity() {
|
||||
return new NBTEntityImpl(new NBTTagCompound(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.core.nms.v1_9_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import net.minecraft.server.v1_9_R2.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity {
|
||||
|
||||
private Entity nmsEntity;
|
||||
|
||||
public NBTEntityImpl(NBTTagCompound entityNBT, Entity nmsEntity) {
|
||||
super(entityNBT);
|
||||
this.nmsEntity = nmsEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawn(Location location) {
|
||||
String entityType = getNBTObject("entity_type").asString();
|
||||
|
||||
Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14
|
||||
((CraftWorld) location.getWorld()).getHandle(),
|
||||
entityType, // Parameter simplified in 1.10
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ(),
|
||||
CreatureSpawnEvent.SpawnReason.DEFAULT
|
||||
);
|
||||
|
||||
if (spawned != null) {
|
||||
spawned.f(compound); // This changed from 1.16.1
|
||||
org.bukkit.entity.Entity entity = spawned.getBukkitEntity();
|
||||
spawned.setLocation(location.getX(), location.getY(), location.getZ(),
|
||||
location.getPitch(), location.getYaw());
|
||||
nmsEntity = spawned;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity reSpawn(Location location) {
|
||||
nmsEntity.dead = true;
|
||||
return spawn(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
String key = EntityTypes.b(nmsEntity); // Changed in 1.12
|
||||
if (key != null)
|
||||
compound.setString("entity_type", key); // Changed in 1.13
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.core.nms.v1_9_R2.nbt;
|
||||
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -10,11 +11,21 @@ public class NBTItemImpl extends NBTCompoundImpl implements NBTItem {
|
||||
private net.minecraft.server.v1_9_R2.ItemStack nmsItem;
|
||||
|
||||
public NBTItemImpl(net.minecraft.server.v1_9_R2.ItemStack nmsItem) {
|
||||
super(nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound());
|
||||
this.nmsItem = nmsItem;
|
||||
}
|
||||
|
||||
public ItemStack finish() {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
if (nmsItem == null) {
|
||||
net.minecraft.server.v1_9_R2.ItemStack itemStack = CraftItemStack.asNMSCopy(new ItemStack(Material.STONE));
|
||||
itemStack.setTag(compound);
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
} else {
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras() {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user