mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 12:25:46 +01:00
Fix the injection
This commit is contained in:
parent
914429ab4f
commit
a451d2d6f2
@ -29,6 +29,7 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.google.inject.assistedinject.FactoryProvider;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
|
||||
@ -96,6 +97,7 @@ public class BukkitModule extends AbstractModule {
|
||||
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
|
||||
bind(SetupUtils.class).to(BukkitSetupUtils.class);
|
||||
bind(WorldUtil.class).to(BukkitUtil.class);
|
||||
install(new FactoryModuleBuilder().implement(ProgressSubscriber.class, DefaultProgressSubscriber.class).build(ProgressSubscriberFactory.class));
|
||||
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class)));
|
||||
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
||||
bind(RegionManager.class).to(BukkitRegionManager.class);
|
||||
@ -108,7 +110,6 @@ public class BukkitModule extends AbstractModule {
|
||||
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
||||
install(new FactoryModuleBuilder().implement(ChunkCoordinator.class, BukkitChunkCoordinator.class).build(ChunkCoordinatorFactory.class));
|
||||
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
|
||||
install(new FactoryModuleBuilder().implement(ProgressSubscriber.class, DefaultProgressSubscriber.class).build(ProgressSubscriberFactory.class));
|
||||
}
|
||||
|
||||
@Provides @Singleton @Nonnull EconHandler provideEconHandler() {
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.bukkit.schematic;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
@ -39,8 +40,8 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
@Singleton public class BukkitSchematicHandler extends SchematicHandler {
|
||||
|
||||
@Inject public BukkitSchematicHandler(@Nonnull final WorldUtil worldUtil) {
|
||||
super(worldUtil);
|
||||
@Inject public BukkitSchematicHandler(@Nonnull final WorldUtil worldUtil, @Nonnull ProgressSubscriberFactory subscriberFactory) {
|
||||
super(worldUtil, subscriberFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,7 @@ package com.plotsquared.bukkit.util;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.PlotLoc;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -74,8 +75,9 @@ public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
|
||||
@Inject public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
|
||||
super(worldUtil, blockQueue);
|
||||
@Inject public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue, @Nonnull
|
||||
ProgressSubscriberFactory subscriberFactory) {
|
||||
super(worldUtil, blockQueue, subscriberFactory);
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.generator;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.location.Direction;
|
||||
@ -56,12 +57,13 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
|
||||
private final ClassicPlotWorld classicPlotWorld;
|
||||
private final RegionManager regionManager;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
private final ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
@Inject public ClassicPlotManager(@Nonnull final ClassicPlotWorld classicPlotWorld, @Nonnull final RegionManager regionManager) {
|
||||
super(classicPlotWorld, regionManager);
|
||||
this.classicPlotWorld = classicPlotWorld;
|
||||
this.regionManager = regionManager;
|
||||
this.subscriberFactory = PlotSquared.platform().getInjector().getInstance(ProgressSubscriberFactory.class);
|
||||
}
|
||||
|
||||
@Override public boolean setComponent(@Nonnull PlotId plotId,
|
||||
@ -232,7 +234,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
queue = classicPlotWorld.getQueue();
|
||||
enqueue = true;
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +313,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
queue = classicPlotWorld.getQueue();
|
||||
enqueue = true;
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,7 +383,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
enqueue = true;
|
||||
queue = classicPlotWorld.getQueue();
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,19 +29,19 @@ import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface ProgressSubscriberFactory {
|
||||
|
||||
@Nonnull ProgressSubscriber create(@Nonnull @Assisted("subscriber") PlotPlayer<?> actor);
|
||||
@Nonnull ProgressSubscriber create();
|
||||
|
||||
@Nonnull ProgressSubscriber create(@Nonnull @Assisted("subscriber") PlotPlayer<?> actor,
|
||||
@Nonnull TaskManager taskManager,
|
||||
@Nonnull ProgressSubscriber createWithActor(@Nullable @Assisted("subscriber") PlotPlayer<?> actor);
|
||||
|
||||
@Nonnull ProgressSubscriber createFull(@Nullable @Assisted("subscriber") PlotPlayer<?> actor,
|
||||
@Assisted("progressInterval") final long interval,
|
||||
@Assisted("progressInterval") final long wait,
|
||||
@Assisted("waitBeforeStarting") final long wait,
|
||||
@Nullable @Assisted("caption") Caption caption);
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.inject.modules;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.intellectualsites.services.ServicePipeline;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
@ -34,7 +35,10 @@ import com.plotsquared.core.inject.annotations.ConfigFile;
|
||||
import com.plotsquared.core.inject.annotations.ImpromptuPipeline;
|
||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.listener.PlotListener;
|
||||
import com.plotsquared.core.queue.subscriber.DefaultProgressSubscriber;
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
@ -78,10 +78,11 @@ public final class PlotModificationManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotModificationManager.class.getSimpleName());
|
||||
|
||||
private final Plot plot;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
private final ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
@Inject PlotModificationManager(@Nonnull final Plot plot) {
|
||||
this.plot = plot;
|
||||
this.subscriberFactory = PlotSquared.platform().getInjector().getInstance(ProgressSubscriberFactory.class);
|
||||
}
|
||||
|
||||
|
||||
@ -239,7 +240,7 @@ public final class PlotModificationManager {
|
||||
}
|
||||
}
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
@ -597,7 +598,7 @@ public final class PlotModificationManager {
|
||||
}
|
||||
}
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
|
@ -28,6 +28,8 @@ package com.plotsquared.core.queue.subscriber;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
@ -55,10 +57,15 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
|
||||
@Nonnull private final TaskTime wait;
|
||||
@Nonnull private final PlotPlayer<?> actor;
|
||||
@Nonnull private final Caption caption;
|
||||
@Inject @Nonnull private TaskManager taskManager;
|
||||
private PlotSquaredTask task;
|
||||
|
||||
@Inject public DefaultProgressSubscriber(@Nonnull final PlotPlayer<?> actor) {
|
||||
@AssistedInject
|
||||
public DefaultProgressSubscriber() {
|
||||
throw new UnsupportedOperationException("DefaultProgressSubscriber cannot be used without an actor.");
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
public DefaultProgressSubscriber(@Nullable @Assisted("subscriber") final PlotPlayer<?> actor) {
|
||||
Preconditions.checkNotNull(actor,
|
||||
"Actor cannot be null when using DefaultProgressSubscriber! Make sure if attempting to use custom Subscribers it is correctly parsed to the queue!");
|
||||
this.actor = actor;
|
||||
@ -67,17 +74,16 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
|
||||
this.caption = TranslatableCaption.of("working.progress");
|
||||
}
|
||||
|
||||
public DefaultProgressSubscriber(@Nonnull final PlotPlayer<?> actor,
|
||||
@Nonnull final TaskManager taskManager,
|
||||
final long interval,
|
||||
final long wait,
|
||||
@Nullable final Caption caption) {
|
||||
@AssistedInject
|
||||
public DefaultProgressSubscriber(@Nullable @Assisted("subscriber") final PlotPlayer<?> actor,
|
||||
@Assisted("progressInterval") final long interval,
|
||||
@Assisted("waitBeforeStarting") final long wait,
|
||||
@Nullable @Assisted("caption") final Caption caption) {
|
||||
Preconditions.checkNotNull(actor,
|
||||
"Actor cannot be null when using DefaultProgressSubscriber! Make sure if attempting to use custom Subscribers it is correctly parsed to the queue!");
|
||||
this.actor = actor;
|
||||
this.interval = TaskTime.ms(interval);
|
||||
this.wait = TaskTime.ms(wait);
|
||||
this.taskManager = taskManager;
|
||||
if (caption == null) {
|
||||
this.caption = TranslatableCaption.of("working.progress");
|
||||
} else {
|
||||
@ -92,7 +98,7 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
|
||||
task.cancel();
|
||||
}
|
||||
} else if (started.compareAndSet(false, true)) {
|
||||
taskManager.taskLater(() -> task = taskManager.taskRepeat(() -> {
|
||||
TaskManager.getPlatformImplementation().taskLater(() -> task = TaskManager.getPlatformImplementation().taskRepeat(() -> {
|
||||
if (!started.get()) {
|
||||
return;
|
||||
}
|
||||
|
@ -63,12 +63,12 @@ public abstract class RegionManager {
|
||||
public static RegionManager manager = null;
|
||||
private final WorldUtil worldUtil;
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
@Inject private TaskManager taskManager;
|
||||
private final ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
@Inject public RegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
|
||||
@Inject public RegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue, @Nonnull ProgressSubscriberFactory subscriberFactory) {
|
||||
this.worldUtil = worldUtil;
|
||||
this.blockQueue = blockQueue;
|
||||
this.subscriberFactory = subscriberFactory;
|
||||
}
|
||||
|
||||
public static BlockVector2 getRegion(Location location) {
|
||||
@ -129,7 +129,7 @@ public abstract class RegionManager {
|
||||
queue = area.getQueue();
|
||||
enqueue = true;
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
}
|
||||
for (CuboidRegion region : regions) {
|
||||
@ -188,14 +188,14 @@ public abstract class RegionManager {
|
||||
copyFromTo(pos1, pos2, relX, relZ, oldWorld, copyFrom, copyTo, false);
|
||||
copyFrom.setCompleteTask(copyTo::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
copyFrom.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
copyFrom.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current copy progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
copyFrom
|
||||
.addReadChunks(new CuboidRegion(BlockVector3.at(pos1.getX(), 0, pos1.getZ()), BlockVector3.at(pos2.getX(), 0, pos2.getZ())).getChunks());
|
||||
copyTo.setCompleteTask(whenDone);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
copyTo.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
copyTo.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current paste progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
return copyFrom.enqueue();
|
||||
@ -246,22 +246,22 @@ public abstract class RegionManager {
|
||||
copyFromTo(pos1, pos2, relX, relZ, world1, fromQueue2, toQueue1, true);
|
||||
fromQueue1.setCompleteTask(fromQueue2::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
fromQueue1.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
fromQueue1.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 1 copy progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
fromQueue2.setCompleteTask(toQueue1::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
fromQueue2.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
fromQueue2.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 2 copy progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
toQueue1.setCompleteTask(toQueue2::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
toQueue1.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
toQueue1.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 1 paste progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
toQueue2.setCompleteTask(whenDone);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
toQueue2.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
toQueue2.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 2 paste progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
fromQueue1.enqueue();
|
||||
|
@ -114,10 +114,11 @@ public abstract class SchematicHandler {
|
||||
public static SchematicHandler manager;
|
||||
private final WorldUtil worldUtil;
|
||||
private boolean exportAll = false;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
private final ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
@Inject public SchematicHandler(@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject public SchematicHandler(@Nonnull final WorldUtil worldUtil, @Nonnull ProgressSubscriberFactory subscriberFactory) {
|
||||
this.worldUtil = worldUtil;
|
||||
this.subscriberFactory = subscriberFactory;
|
||||
}
|
||||
|
||||
public static void upload(@Nullable UUID uuid,
|
||||
@ -353,7 +354,7 @@ public abstract class SchematicHandler {
|
||||
whenDone.value = true;
|
||||
}
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
|
||||
}
|
||||
queue.setCompleteTask(whenDone);
|
||||
queue.enqueue();
|
||||
|
Loading…
Reference in New Issue
Block a user