use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class PlayerProfile method toNBT.
public CompoundTag toNBT() {
CompoundTag profileTag = new CompoundTag();
profileTag.putString("Id", uniqueId.toString());
profileTag.putString("Name", name);
CompoundTag propertiesTag = new CompoundTag();
for (PlayerProperty property : properties) {
CompoundTag propertyValueTag = new CompoundTag();
if (property.isSigned()) {
propertyValueTag.putString("Signature", property.getSignature());
}
propertyValueTag.putString("Value", property.getValue());
propertiesTag.putCompoundList(property.getName(), Arrays.asList(propertyValueTag));
}
if (!propertiesTag.isEmpty()) {
// Only add properties if not empty
profileTag.putCompound("Properties", propertiesTag);
}
return profileTag;
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class GlowMetaBanner method readNbt.
@Override
void readNbt(CompoundTag tag) {
super.readNbt(tag);
if (tag.isCompound("BlockEntityTag")) {
CompoundTag blockEntityTag = tag.getCompound("BlockEntityTag");
if (blockEntityTag.isList("Patterns", TagType.COMPOUND)) {
List<CompoundTag> patterns = blockEntityTag.getCompoundList("Patterns");
this.patterns = BlockBanner.fromNBT(patterns);
}
if (blockEntityTag.isInt("Base")) {
this.baseColor = DyeColor.getByWoolData((byte) blockEntityTag.getInt("Base"));
}
}
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class SummonCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender))
return true;
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("This command can only be executed by a player or via command blocks.");
return true;
}
Location location = null;
if (sender instanceof Player) {
location = ((Player) sender).getLocation().clone();
} else if (sender instanceof BlockCommandSender) {
location = ((BlockCommandSender) sender).getBlock().getLocation().clone();
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (args.length >= 4) {
location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
}
if (location == null) {
return false;
}
location.setYaw(0.0f);
location.setPitch(0.0f);
CompoundTag tag = null;
if (args.length >= 5) {
String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
try {
tag = Mojangson.parseCompound(data);
} catch (MojangsonParseException e) {
sender.sendMessage(ChatColor.RED + "Invalid Data Tag: " + e.getMessage());
}
}
String entityName = args[0];
if (!checkSummon(sender, entityName)) {
return true;
}
GlowEntity entity;
if (EntityType.fromName(entityName) != null) {
entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
} else {
Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
if (tag != null) {
EntityStorage.load(entity, tag);
}
sender.sendMessage("Object successfully summoned.");
return true;
}
use of net.glowstone.util.nbt.CompoundTag in project Dragonet-Legacy by DragonetMC.
the class ProtocolTestUtils method getTag.
public static CompoundTag getTag() {
CompoundTag tag = new CompoundTag();
tag.putInt("int", 5);
tag.putString("string", "text");
tag.putList("list", TagType.FLOAT, Arrays.asList(1.f, 2.f, 3.f));
tag.putCompound("compound", new CompoundTag());
return tag;
}
use of net.glowstone.util.nbt.CompoundTag in project Dragonet-Legacy by DragonetMC.
the class PEInventorySlot method readSlot.
public static PEInventorySlot readSlot(PEBinaryReader reader) throws IOException {
// Unsigned
short id = (short) (reader.readShort() & 0xFFFF);
if (id <= 0) {
return new PEInventorySlot((short) 0, (byte) 0, (short) 0);
}
byte count = reader.readByte();
short meta = reader.readShort();
short lNbt = reader.readShort();
if (lNbt <= 0) {
return new PEInventorySlot(id, count, meta);
}
byte[] nbtData = reader.read(lNbt);
NBTInputStream nbtin = new NBTInputStream(new ByteArrayInputStream(nbtData));
CompoundTag nbt = nbtin.readCompound();
nbtin.close();
return new PEInventorySlot(id, count, meta, nbt);
}
Aggregations