Search in sources :

Example 66 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class BrushCache method getTool.

public static BrushTool getTool(Player player, LocalSession session, BaseItem item) {
    if (!item.hasNbtData()) {
        return null;
    }
    Object key = getKey(item);
    if (key == null) {
        return null;
    }
    BrushTool cached = brushCache.get(key);
    if (cached != null) {
        return cached;
    }
    CompoundTag nbt = item.getNbtData();
    if (nbt == null) {
        return null;
    }
    StringTag json = (StringTag) nbt.getValue().get("weBrushJson");
    /* if (json != null) {
            try {
                if (RECURSION.get() != null) return null;
                RECURSION.set(true);

                BrushTool tool = BrushTool.fromString(player, session, json.getValue());
                tool.setHolder(item);
                brushCache.put(key, tool);
                return tool;
            } catch (Exception throwable) {
                getLogger(BrushCache.class).debug("Invalid brush for " + player + " holding " + item.getType() + ": " + json.getValue(), throwable);
                item.setNbtData(null);
                brushCache.remove(key);
            } finally {
                RECURSION.remove();
            }
        }*/
    return null;
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) StringTag(com.sk89q.jnbt.StringTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 67 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class BrushCache method setTool.

public static BrushTool setTool(BaseItem item, BrushTool tool) {
    if (item.getNativeItem() == null) {
        return null;
    }
    CompoundTag nbt = item.getNbtData();
    Map<String, Tag> map;
    if (nbt == null) {
        if (tool == null) {
            item.setNbtData(null);
            return tool;
        }
        nbt = new CompoundTag(map = new HashMap<>());
    } else {
        map = nbt.getValue();
    }
    brushCache.remove(getKey(item));
    CompoundTag display = (CompoundTag) map.get("display");
    Map<String, Tag> displayMap;
    return tool;
}
Also used : CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) StringTag(com.sk89q.jnbt.StringTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 68 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class NbtValued method getNbtReference.

/**
 * Get the object's NBT data (tile entity data).
 *
 * <p>
 * This only needs to be used if you don't want to immediately resolve the data.
 * Otherwise, you probably want {@link #getNbt()}.
 * </p>
 *
 * @return compound tag, or null
 */
@NonAbstractForCompatibility(delegateName = "getNbtData", delegateParams = {})
@Nullable
default LazyReference<CompoundBinaryTag> getNbtReference() {
    DeprecationUtil.checkDelegatingOverride(getClass());
    CompoundTag nbtData = getNbtData();
    return nbtData == null ? null : LazyReference.from(nbtData::asBinaryTag);
}
Also used : CompoundTag(com.sk89q.jnbt.CompoundTag) NonAbstractForCompatibility(com.sk89q.worldedit.internal.util.NonAbstractForCompatibility) Nullable(javax.annotation.Nullable)

Example 69 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project PlotSquared by IntellectualSites.

the class SchematicHandler method writeSchematicData.

private void writeSchematicData(@NonNull final Map<String, Tag> schematic, @NonNull final Map<String, Integer> palette, @NonNull final Map<String, Integer> biomePalette, @NonNull final List<CompoundTag> tileEntities, @NonNull final ByteArrayOutputStream buffer, @NonNull final ByteArrayOutputStream biomeBuffer) {
    schematic.put("PaletteMax", new IntTag(palette.size()));
    Map<String, Tag> paletteTag = new HashMap<>();
    palette.forEach((key, value) -> paletteTag.put(key, new IntTag(value)));
    schematic.put("Palette", new CompoundTag(paletteTag));
    schematic.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
    schematic.put("BlockEntities", new ListTag(CompoundTag.class, tileEntities));
    if (biomeBuffer.size() == 0 || biomePalette.size() == 0) {
        return;
    }
    schematic.put("BiomePaletteMax", new IntTag(biomePalette.size()));
    Map<String, Tag> biomePaletteTag = new HashMap<>();
    biomePalette.forEach((key, value) -> biomePaletteTag.put(key, new IntTag(value)));
    schematic.put("BiomePalette", new CompoundTag(biomePaletteTag));
    schematic.put("BiomeData", new ByteArrayTag(biomeBuffer.toByteArray()));
}
Also used : HashMap(java.util.HashMap) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) CompoundTag(com.sk89q.jnbt.CompoundTag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) Tag(com.sk89q.jnbt.Tag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag)

Aggregations

CompoundTag (com.sk89q.jnbt.CompoundTag)69 Tag (com.sk89q.jnbt.Tag)38 StringTag (com.sk89q.jnbt.StringTag)26 HashMap (java.util.HashMap)25 IntTag (com.sk89q.jnbt.IntTag)24 ListTag (com.sk89q.jnbt.ListTag)21 ShortTag (com.sk89q.jnbt.ShortTag)16 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)16 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)14 IntArrayTag (com.sk89q.jnbt.IntArrayTag)14 IOException (java.io.IOException)14 Map (java.util.Map)13 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)11 NamedTag (com.sk89q.jnbt.NamedTag)9 Location (com.sk89q.worldedit.util.Location)9 BlockState (com.sk89q.worldedit.world.block.BlockState)9 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)8 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)6 Region (com.sk89q.worldedit.regions.Region)6 ArrayList (java.util.ArrayList)6