File tree Expand file tree Collapse file tree
cloud-bukkit/src/main/java/org/incendo/cloud/bukkit/internal
cloud-paper/src/main/java/org/incendo/cloud/paper Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727import java .util .Optional ;
2828import java .util .concurrent .Executor ;
2929import org .apiguardian .api .API ;
30+ import org .bukkit .Bukkit ;
3031import org .bukkit .Server ;
3132import org .bukkit .plugin .Plugin ;
3233import org .checkerframework .checker .nullness .qual .NonNull ;
@@ -131,4 +132,12 @@ private BukkitHelper() {
131132 server .getScheduler ().runTask (plugin , task );
132133 };
133134 }
135+
136+ public static void ensurePluginEnabledOrEnabling (final @ NonNull Plugin plugin ) {
137+ final Plugin fromManager = Bukkit .getServer ().getPluginManager ().getPlugin (plugin .getName ());
138+ if (!plugin .equals (fromManager ) || !plugin .isEnabled ()) {
139+ throw new IllegalStateException ("The plugin '" + plugin + "' is not (yet?) valid per the PluginManager."
140+ + " Try calling this method from onEnable rather than in the plugin constructor or onLoad." );
141+ }
142+ }
134143}
Original file line number Diff line number Diff line change 4545import org .incendo .cloud .bukkit .BukkitParsers ;
4646import org .incendo .cloud .bukkit .CloudBukkitCapabilities ;
4747import org .incendo .cloud .bukkit .PluginHolder ;
48+ import org .incendo .cloud .bukkit .internal .BukkitHelper ;
4849import org .incendo .cloud .execution .ExecutionCoordinator ;
4950import org .incendo .cloud .internal .CommandRegistrationHandler ;
5051
@@ -186,6 +187,7 @@ private Bootstrapped(
186187 * <p>This method must be called in {@link Plugin#onEnable()} for some features to work.</p>
187188 */
188189 public void onEnable () {
190+ BukkitHelper .ensurePluginEnabledOrEnabling (this .owningPlugin ());
189191 /*
190192 ((ModernPaperBrigadier<CommandSourceStack, C>) this.commandRegistrationHandler())
191193 .registerPlugin(this.owningPlugin());
@@ -246,6 +248,7 @@ private CoordinatedBuilder(
246248 final PaperCommandManager <C > mgr =
247249 new PaperCommandManager <>(plugin .getPluginMeta (), this .executionCoordinator , this .senderMapper );
248250 ((ModernPaperBrigadier <CommandSourceStack , C >) mgr .commandRegistrationHandler ()).registerPlugin (plugin );
251+ BukkitHelper .ensurePluginEnabledOrEnabling (plugin );
249252 return mgr ;
250253 }
251254
You can’t perform that action at this time.
0 commit comments