Search in sources :

Example 31 with CompoundTag

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

the class PaperweightGetBlocks_Copy method getEntity.

@Override
public CompoundTag getEntity(UUID uuid) {
    for (CompoundTag tag : entities) {
        UUID tagUUID;
        if (tag.containsKey("UUID")) {
            int[] arr = tag.getIntArray("UUID");
            tagUUID = new UUID((long) arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long) arr[2] << 32 | (arr[3] & 0xFFFFFFFFL));
        } else if (tag.containsKey("UUIDMost")) {
            tagUUID = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast"));
        } else if (tag.containsKey("PersistentIDMSB")) {
            tagUUID = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB"));
        } else {
            return null;
        }
        if (uuid.equals(tagUUID)) {
            return tag;
        }
    }
    return null;
}
Also used : UUID(java.util.UUID) CompoundTag(com.sk89q.jnbt.CompoundTag) PaperweightLazyCompoundTag(com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.nbt.PaperweightLazyCompoundTag)

Example 32 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project CoreProtect by PlayPro.

the class WorldEditLogger method postProcess.

protected static void postProcess(Extent extent, Actor actor, BlockVector3 position, Location location, BlockStateHolder<?> blockStateHolder, BaseBlock baseBlock, Material oldType, com.sk89q.worldedit.world.block.BlockState oldBlockState, ItemStack[] containerContents) {
    BlockData oldBlockData = BukkitAdapter.adapt(oldBlockState);
    BlockData newBlockData = BukkitAdapter.adapt(blockStateHolder.toImmutableState());
    Material newType = newBlockData.getMaterial();
    String oldBlockDataString = oldBlockData.getAsString();
    String newBlockDataString = newBlockData.getAsString();
    BlockState oldBlock = new WorldEditBlockState(location, oldType, oldBlockData);
    BlockState newBlock = new WorldEditBlockState(location, newType, newBlockData);
    int oldBlockExtraData = 0;
    int newBlockExtraData = -1;
    if (!oldType.equals(newType) || !oldBlockDataString.equals(newBlockDataString)) {
        try {
            if (baseBlock != null && baseBlock.hasNbtData()) {
                if (Config.getConfig(location.getWorld()).SIGN_TEXT && Tag.SIGNS.isTagged(oldType)) {
                    CompoundTag compoundTag = baseBlock.getNbtData();
                    String line1 = getSignText(compoundTag.getString("Text1"));
                    String line2 = getSignText(compoundTag.getString("Text2"));
                    String line3 = getSignText(compoundTag.getString("Text3"));
                    String line4 = getSignText(compoundTag.getString("Text4"));
                    int color = DyeColor.valueOf(baseBlock.getNbtData().getString("Color").toUpperCase()).getColor().asRGB();
                    boolean isGlowing = (compoundTag.getInt("GlowingText") == 1 ? true : false);
                    Queue.queueSignText(actor.getName(), location, 0, color, isGlowing, line1, line2, line3, line4, 5);
                }
                if (oldType == Material.SPAWNER) {
                    String mobType = getMobType(baseBlock);
                    if (mobType != null) {
                        try {
                            EntityType entityType = EntityType.valueOf(mobType);
                            oldBlockExtraData = Util.getSpawnerType(entityType);
                        } catch (IllegalArgumentException exception) {
                        // mobType isn't a valid enum (EntityType.class)
                        }
                    }
                }
            }
            if (containerContents != null) {
                Queue.queueContainerBreak(actor.getName(), location, oldType, containerContents);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (newType.equals(Material.SKELETON_SKULL) || newType.equals(Material.SKELETON_WALL_SKULL) || newType.equals(Material.WITHER_SKELETON_SKULL) || newType.equals(Material.WITHER_SKELETON_WALL_SKULL) || newType.equals(Material.ZOMBIE_HEAD) || newType.equals(Material.ZOMBIE_WALL_HEAD) || newType.equals(Material.PLAYER_HEAD) || newType.equals(Material.PLAYER_WALL_HEAD) || newType.equals(Material.CREEPER_HEAD) || newType.equals(Material.CREEPER_WALL_HEAD) || newType.equals(Material.DRAGON_HEAD) || newType.equals(Material.DRAGON_WALL_HEAD)) {
            // skull
            Queue.queueBlockPlaceDelayed(actor.getName(), location, newType, newBlockDataString, oldBlock, 0);
        } else if ((oldType.equals(Material.AIR) || oldType.equals(Material.CAVE_AIR)) && (!newType.equals(Material.AIR) && !newType.equals(Material.CAVE_AIR))) {
            // placed a block
            Queue.queueBlockPlace(actor.getName(), newBlock, newType, null, newType, newBlockExtraData, 0, newBlockDataString);
        } else if ((!oldType.equals(Material.AIR) && !oldType.equals(Material.CAVE_AIR)) && (!newType.equals(Material.AIR) && !newType.equals(Material.CAVE_AIR))) {
            // replaced a block
            Waterlogged waterlogged = Util.checkWaterlogged(newBlockData, oldBlock);
            if (waterlogged != null) {
                newBlockDataString = waterlogged.getAsString();
                oldBlock = null;
            }
            if (oldBlock != null) {
                Queue.queueBlockBreak(actor.getName(), oldBlock, oldBlock.getType(), oldBlockDataString, null, oldBlockExtraData, 0);
            }
            Queue.queueBlockPlace(actor.getName(), newBlock, newType, null, newType, newBlockExtraData, 0, newBlockDataString);
        } else if ((!oldType.equals(Material.AIR) && !oldType.equals(Material.CAVE_AIR)) && (newType.equals(Material.AIR) || newType.equals(Material.CAVE_AIR))) {
            // removed a block
            Queue.queueBlockBreak(actor.getName(), oldBlock, oldBlock.getType(), oldBlockDataString, null, oldBlockExtraData, 0);
            if (oldBlockData instanceof Waterlogged) {
                Waterlogged waterlogged = (Waterlogged) oldBlockData;
                if (waterlogged.isWaterlogged()) {
                    Queue.queueBlockPlace(actor.getName(), newBlock, newType, null, Material.WATER, -1, 0, null);
                }
            } else if (oldBlockData instanceof Bisected) {
                Bisected bisected = (Bisected) oldBlockData;
                Location bisectLocation = location.clone();
                if (bisected.getHalf() == Half.TOP) {
                    bisectLocation.setY(bisectLocation.getY() - 1);
                } else {
                    bisectLocation.setY(bisectLocation.getY() + 1);
                }
                int worldMaxHeight = location.getWorld().getMaxHeight();
                int worldMinHeight = net.coreprotect.bukkit.BukkitAdapter.ADAPTER.getMinHeight(location.getWorld());
                if (bisectLocation.getBlockY() >= worldMinHeight && bisectLocation.getBlockY() < worldMaxHeight) {
                    BlockState bisectBlock = location.getWorld().getBlockAt(bisectLocation).getState();
                    Queue.queueBlockBreak(actor.getName(), bisectBlock, bisectBlock.getType(), bisectBlock.getBlockData().getAsString(), null, 0, 0);
                }
            }
        }
    }
}
Also used : Material(org.bukkit.Material) EntityType(org.bukkit.entity.EntityType) BlockState(org.bukkit.block.BlockState) Waterlogged(org.bukkit.block.data.Waterlogged) BlockData(org.bukkit.block.data.BlockData) CompoundTag(com.sk89q.jnbt.CompoundTag) Bisected(org.bukkit.block.data.Bisected) Location(org.bukkit.Location)

Example 33 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project CoreProtect by PlayPro.

the class WorldEditLogger method getMobType.

private static String getMobType(BaseBlock fullBlock) {
    String mobType = null;
    try {
        CompoundTag compoundTag = NBTUtils.getChildTag(fullBlock.getNbtData().getValue(), "SpawnData", CompoundTag.class);
        mobType = compoundTag.getString("id").toUpperCase(Locale.ROOT);
        if (mobType.contains("MINECRAFT:")) {
            String[] mobTypeSplit = mobType.split(":");
            mobType = mobTypeSplit[1];
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mobType;
}
Also used : CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 34 with CompoundTag

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

the class PaperweightGetBlocks_Copy method storeEntity.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void storeEntity(Entity entity) {
    BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
    net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
    entities.add((CompoundTag) adapter.toNative(entity.save(compoundTag)));
}
Also used : BukkitImplAdapter(com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter) CompoundTag(com.sk89q.jnbt.CompoundTag) PaperweightLazyCompoundTag(com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.nbt.PaperweightLazyCompoundTag)

Example 35 with CompoundTag

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

the class PaperweightGetBlocks_Copy method getEntity.

@Override
public CompoundTag getEntity(UUID uuid) {
    for (CompoundTag tag : entities) {
        UUID tagUUID;
        if (tag.containsKey("UUID")) {
            int[] arr = tag.getIntArray("UUID");
            tagUUID = new UUID((long) arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long) arr[2] << 32 | (arr[3] & 0xFFFFFFFFL));
        } else if (tag.containsKey("UUIDMost")) {
            tagUUID = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast"));
        } else if (tag.containsKey("PersistentIDMSB")) {
            tagUUID = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB"));
        } else {
            return null;
        }
        if (uuid.equals(tagUUID)) {
            return tag;
        }
    }
    return null;
}
Also used : UUID(java.util.UUID) PaperweightLazyCompoundTag(com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.nbt.PaperweightLazyCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

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