diff --git a/bukkit/src/main/java/net/william278/husksync/api/BukkitHuskSyncAPI.java b/bukkit/src/main/java/net/william278/husksync/api/BukkitHuskSyncAPI.java index 362a8958..1021229b 100644 --- a/bukkit/src/main/java/net/william278/husksync/api/BukkitHuskSyncAPI.java +++ b/bukkit/src/main/java/net/william278/husksync/api/BukkitHuskSyncAPI.java @@ -28,6 +28,7 @@ import net.william278.husksync.user.OnlineUser; import net.william278.husksync.user.User; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -59,6 +60,10 @@ public class BukkitHuskSyncAPI extends HuskSyncAPI { */ @NotNull public static BukkitHuskSyncAPI getInstance() { + if (!JavaPlugin.getProvidingPlugin(BukkitHuskSyncAPI.class).getName().equals("HuskSync")) { + throw new NotRegisteredException("This is likely because you have shaded HuskSync into your plugin JAR " + + "and need to fix your maven/gradle/build script so that it *compiles against* HuskSync instead."); + } if (instance == null) { throw new NotRegisteredException(); } diff --git a/common/src/main/java/net/william278/husksync/api/HuskSyncAPI.java b/common/src/main/java/net/william278/husksync/api/HuskSyncAPI.java index d55f3ad9..106f5efe 100644 --- a/common/src/main/java/net/william278/husksync/api/HuskSyncAPI.java +++ b/common/src/main/java/net/william278/husksync/api/HuskSyncAPI.java @@ -511,17 +511,19 @@ public class HuskSyncAPI { */ static final class NotRegisteredException extends IllegalStateException { - private static final String MESSAGE = """ - Could not access the HuskSync API as it has not yet been registered. This could be because: + private static final String REASONS = """ + This may be because: 1) HuskSync has failed to enable successfully 2) Your plugin isn't set to load after HuskSync has (Check if it set as a (soft)depend in plugin.yml or to load: BEFORE in paper-plugin.yml?) - 3) You are attempting to access HuskSync on plugin construction/before your plugin has enabled. - 4) You have shaded HuskSync into your plugin jar and need to fix your maven/gradle/build script - to only include HuskSync as a dependency and not as a shaded dependency."""; + 3) You are attempting to access HuskSync on plugin construction/before your plugin has enabled."""; + + NotRegisteredException(@NotNull String reasons) { + super("Could not access the HuskSync API as it has not yet been registered. %s".formatted(REASONS)); + } NotRegisteredException() { - super(MESSAGE); + this(REASONS); } }