use of com.skelril.skree.service.internal.zone.ZoneWorldBoundingBox in project Skree by Skelril.
the class WEDecorator method pasteAt.
public <T> ZoneWorldBoundingBox pasteAt(WorldResolver world, Vector3i origin, String resourceName, Function<ZoneWorldBoundingBox, T> initMapper, Consumer<T> callback) {
EditSession transaction = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world.getWorldEditWorld(), -1);
transaction.setFastMode(true);
transaction.getChangeSet().setRecordChanges(false);
hashRefMap.computeIfAbsent(resourceName, (a) -> {
HashRef ref = new HashRef();
try {
ref.holder = getHolder(resourceName, world.getWorldEditWorld().getWorldData());
} catch (IOException e) {
e.printStackTrace();
}
return ref;
});
HashRef ref = hashRefMap.get(resourceName);
if (ref == null) {
callback.accept(null);
return null;
}
++ref.refCount;
Clipboard clipboard = ref.holder.getClipboard();
Region clipReg = clipboard.getRegion();
clipboard.setOrigin(clipReg.getMinimumPoint());
Operation operation = ref.holder.createPaste(transaction, transaction.getWorld().getWorldData()).to(new Vector(origin.getX(), origin.getY(), origin.getZ())).build();
Vector dimensions = clipboard.getDimensions();
ZoneWorldBoundingBox region = new ZoneWorldBoundingBox(world.getSpongeWorld(), origin, new Vector3i(dimensions.getX(), dimensions.getY(), dimensions.getZ()));
T returnVal = initMapper.apply(region);
RunManager.runOperation(operation, () -> {
RunManager.runOperation(transaction.commit(), () -> {
callback.accept(returnVal);
if (--ref.refCount == 0) {
hashRefMap.remove(resourceName);
System.gc();
}
});
});
return region;
}
Aggregations