mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-30 20:54:44 +02:00
progress subscriber
This commit is contained in:
@ -29,6 +29,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
@ -82,7 +83,8 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
@Assisted @Nonnull final Collection<BlockVector2> requestedChunks,
|
||||
@Assisted @Nonnull final Runnable whenDone,
|
||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter) {
|
||||
@Assisted final boolean unloadAfter,
|
||||
@Assisted @Nonnull final Collection<ProgressSubscriber> progressSubscribers) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
@ -95,6 +97,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
this.unloadAfter = unloadAfter;
|
||||
this.plugin = JavaPlugin.getPlugin(BukkitPlatform.class);
|
||||
this.bukkitWorld = Bukkit.getWorld(world.getName());
|
||||
this.progressSubscribers.addAll(progressSubscribers);
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
@ -205,21 +208,8 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
*
|
||||
* @param subscriber Subscriber
|
||||
*/
|
||||
public void subscribeToProgress(@Nonnull final BukkitChunkCoordinator.ProgressSubscriber subscriber) {
|
||||
public void subscribeToProgress(@Nonnull final ProgressSubscriber subscriber) {
|
||||
this.progressSubscribers.add(subscriber);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ProgressSubscriber {
|
||||
|
||||
/**
|
||||
* Notify about a progress update in the coordinator
|
||||
*
|
||||
* @param coordinator Coordinator instance that triggered the notification
|
||||
* @param progress Progress in the range [0, 1]
|
||||
*/
|
||||
void notifyProgress(@Nonnull final BukkitChunkCoordinator coordinator, final float progress);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -185,9 +185,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
}));
|
||||
}
|
||||
if (localChunk.getEntities().size() > 0) {
|
||||
localChunk.getEntities().forEach((location, entity) -> {
|
||||
getWorld().createEntity(location, entity);
|
||||
});
|
||||
localChunk.getEntities().forEach((location, entity) -> getWorld().createEntity(location, entity));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -198,7 +196,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
chunkCoordinator =
|
||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld()).withChunks(getBlockChunks().keySet()).withChunks(read)
|
||||
.withInitialBatchSize(3).withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace).withFinalAction(getCompleteTask())
|
||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).build();
|
||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).withProgressSubscribers(getProgressSubscribers()).build();
|
||||
return super.enqueue();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user