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;
}
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);
}
}
}
}
}
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;
}
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)));
}
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;
}
Aggregations