From 32887212590cbb51897c93fc19c79d45631c1461 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 28 Jul 2020 08:34:14 +0100 Subject: [PATCH] Better constructor error handling in QueueProvider. Add back default constructor requiring world to QueueCoordinator to indicate extents require this constructor --- .../plotsquared/core/queue/BasicQueueCoordinator.java | 1 + .../core/queue/DelegateQueueCoordinator.java | 1 + .../com/plotsquared/core/queue/QueueCoordinator.java | 5 ++++- .../com/plotsquared/core/queue/QueueProvider.java | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java index 684eea7f6..cca1899fe 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/BasicQueueCoordinator.java @@ -69,6 +69,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator { private Runnable whenDone; public BasicQueueCoordinator(@Nonnull World world) { + super(world); this.world = world; this.modified = System.currentTimeMillis(); } diff --git a/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java index 6520a64fc..b3dea64e9 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/DelegateQueueCoordinator.java @@ -50,6 +50,7 @@ public class DelegateQueueCoordinator extends QueueCoordinator { private final QueueCoordinator parent; public DelegateQueueCoordinator(QueueCoordinator parent) { + super(parent == null ? null : parent.getWorld()); this.parent = parent; if (parent != null) { diff --git a/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java b/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java index 91738bd40..b6a838990 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java +++ b/Core/src/main/java/com/plotsquared/core/queue/QueueCoordinator.java @@ -52,7 +52,10 @@ public abstract class QueueCoordinator { @Inject private GlobalBlockQueue blockQueue; - public QueueCoordinator() { + /** + * Default constructor requires world to indicate any extents given to {@link QueueCoordinator} also need this constructor. + */ + public QueueCoordinator(@Nullable World world) { PlotSquared.platform().getInjector().injectMembers(this); } diff --git a/Core/src/main/java/com/plotsquared/core/queue/QueueProvider.java b/Core/src/main/java/com/plotsquared/core/queue/QueueProvider.java index d1ee80029..5fbe4289e 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/QueueProvider.java +++ b/Core/src/main/java/com/plotsquared/core/queue/QueueProvider.java @@ -25,11 +25,17 @@ */ package com.plotsquared.core.queue; +import com.plotsquared.core.PlotSquared; import com.sk89q.worldedit.world.World; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; public abstract class QueueProvider { + + private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName()); + public static QueueProvider of(@Nonnull final Class primary) { return new QueueProvider() { @@ -37,6 +43,11 @@ public abstract class QueueProvider { try { return (QueueCoordinator) primary.getConstructors()[0].newInstance(world); } catch (Throwable e) { + logger.info("Error creating Queue: " + primary.getName() + " - Does it have the correct constructor(s)?"); + if (!primary.getName().contains("com.plotsquared")) { + logger.info("It looks like " + primary.getSimpleName() + + " is a custom queue. Please look for a plugin in its classpath and report to themm"); + } e.printStackTrace(); } return null;