/** * Removes unnecessary/duplicate data from a BlockSnapshot's DataContainer. * * @param blockSnapshot Block Snapshot. * @return DataContainer Formatted Data Container. */ private DataContainer formatBlockDataContainer(BlockSnapshot blockSnapshot) { DataContainer block = blockSnapshot.toContainer(); block.remove(DataQueries.WorldUuid); block.remove(DataQueries.Position); Optional<Object> optionalUnsafeData = block.get(DataQueries.UnsafeData); if (optionalUnsafeData.isPresent()) { DataView unsafeData = (DataView) optionalUnsafeData.get(); unsafeData.remove(DataQueries.X); unsafeData.remove(DataQueries.Y); unsafeData.remove(DataQueries.Z); block.set(DataQueries.UnsafeData, unsafeData); } return block; } }
/** * Helper method for formatting entity container data. * @param entity */ private void writeEntity(Entity entity) { checkNotNull(entity); DataContainer entityData = entity.toContainer(); Optional<DataView> position = entityData.getView(DataQueries.Position); if (position.isPresent()) { position.get().set(DataQueries.WorldUuid, entityData.get(DataQueries.WorldUuid).get()); data.set(DataQueries.Location, position.get()); entityData.remove(DataQueries.Position); entityData.remove(DataQueries.WorldUuid); } Optional<DataView> optionalUnsafeData = entityData.getView(DataQueries.UnsafeData); if (optionalUnsafeData.isPresent()) { DataView unsafeData = optionalUnsafeData.get(); unsafeData.remove(DataQueries.Rotation); unsafeData.remove(DataQueries.Pos); entityData.set(DataQueries.UnsafeData, unsafeData); } data.set(DataQueries.Target, entity.getType().getId().replace("_", " ")); data.set(DataQueries.Entity, entityData); }
/** * Helper method for writing block transaction data, using only * the final replacement value. We must alter the data structure * slightly to avoid duplication, decoupling location from blocks, etc. * * @param transaction BlockTransaction representing a block change in the world. */ private void writeBlockTransaction(Transaction<BlockSnapshot> transaction) { checkNotNull(transaction); // Location DataContainer location = transaction.getOriginal().getLocation().get().toContainer(); location.remove(DataQueries.BlockType); location.remove(DataQueries.WorldName); location.remove(DataQueries.ContentVersion); data.set(DataQueries.Location, location); // Storing the state only, so we don't also get location data.set(DataQueries.OriginalBlock, formatBlockDataContainer(transaction.getOriginal())); data.set(DataQueries.ReplacementBlock, formatBlockDataContainer(transaction.getFinal())); // Use the transaction data directly, so we never worry about different data formats if (this.eventName.equals("place")) { data.set(DataQueries.Target, transaction.getFinal().getState().getType().getId().replace("_", " ")); } else { data.set(DataQueries.Target, transaction.getOriginal().getState().getType().getId().replace("_", " ")); } }