summaryrefslogtreecommitdiffstats
path: root/bukkit
diff options
context:
space:
mode:
Diffstat (limited to 'bukkit')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java179
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java3
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/BentoBoxLevelTaskType.java1
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/MythicMobsKillingTaskType.java5
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusBuyTaskType.java4
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusInteractionTaskType.java5
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusSellTaskType.java4
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CompatUtils.java35
8 files changed, 120 insertions, 116 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
index 706b9175..901cee71 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -100,6 +100,7 @@ import com.leonardobishop.quests.bukkit.tasktype.type.dependent.SuperiorSkyblock
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.SuperiorSkyblockWorthType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.VotingPluginVoteType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.uSkyBlockLevelTaskType;
+import com.leonardobishop.quests.bukkit.util.CompatUtils;
import com.leonardobishop.quests.bukkit.util.LogHistory;
import com.leonardobishop.quests.common.config.ConfigProblem;
import com.leonardobishop.quests.common.config.ConfigProblemDescriptions;
@@ -354,17 +355,20 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
// Register task types after the server has fully started
getScheduler().doSync(() -> {
// Setup external plugin hooks
- if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
+ if (CompatUtils.isPluginEnabled("PlaceholderAPI")) {
this.placeholderAPIHook = new PlaceholderAPIHook();
this.placeholderAPIHook.registerExpansion(this);
this.placeholderAPIProcessor = (player, s) -> placeholderAPIHook.replacePlaceholders(player, s);
}
- if (Bukkit.getPluginManager().isPluginEnabled("CoreProtect")) {
+
+ if (CompatUtils.isPluginEnabled("CoreProtect")) {
this.coreProtectHook = new CoreProtectHook(this);
}
- if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
+
+ if (CompatUtils.isPluginEnabled("Essentials")) {
this.essentialsHook = new EssentialsHook();
}
+
try {
String className = questsConfig.getString("options.playerblocktracker-class-name", "com.gestankbratwurst.playerblocktracker.PlayerBlockTracker");
@@ -375,119 +379,82 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
} catch (ClassCastException | ClassNotFoundException | NoSuchMethodException ignored) {
}
- taskTypeManager.registerTaskType(new MiningTaskType(this));
+ // Register task types without compatibility requirement
+ taskTypeManager.registerTaskType(new BreedingTaskType(this));
+ taskTypeManager.registerTaskType(new BucketEmptyTaskType(this));
+ taskTypeManager.registerTaskType(new BucketFillTaskType(this));
taskTypeManager.registerTaskType(new BuildingTaskType(this));
- taskTypeManager.registerTaskType(new MobkillingTaskType(this));
- taskTypeManager.registerTaskType(new PlayerkillingTaskType(this));
- taskTypeManager.registerTaskType(new FishingTaskType(this));
- taskTypeManager.registerTaskType(new SmeltingTaskType(this));
- taskTypeManager.registerTaskType(new InventoryTaskType(this));
+ taskTypeManager.registerTaskType(new CommandTaskType(this));
taskTypeManager.registerTaskType(new ConsumeTaskType(this));
- taskTypeManager.registerTaskType(new WalkingTaskType(this));
- taskTypeManager.registerTaskType(new TamingTaskType(this));
- taskTypeManager.registerTaskType(new MilkingTaskType(this));
- taskTypeManager.registerTaskType(new ShearingTaskType(this));
- taskTypeManager.registerTaskType(new PositionTaskType(this));
- taskTypeManager.registerTaskType(new PlaytimeTaskType(this));
- taskTypeManager.registerTaskType(new ExpEarnTaskType(this));
- taskTypeManager.registerTaskType(new BreedingTaskType(this));
- taskTypeManager.registerTaskType(new EnchantingTaskType(this));
+ taskTypeManager.registerTaskType(new CraftingTaskType(this));
taskTypeManager.registerTaskType(new DealDamageTaskType(this));
- taskTypeManager.registerTaskType(new PermissionTaskType(this));
taskTypeManager.registerTaskType(new DistancefromTaskType(this));
- taskTypeManager.registerTaskType(new CommandTaskType(this));
- taskTypeManager.registerTaskType(new CraftingTaskType(this));
- taskTypeManager.registerTaskType(new BucketEmptyTaskType(this));
- taskTypeManager.registerTaskType(new BucketFillTaskType(this));
+ taskTypeManager.registerTaskType(new EnchantingTaskType(this));
+ taskTypeManager.registerTaskType(new ExpEarnTaskType(this));
+ taskTypeManager.registerTaskType(new FishingTaskType(this));
taskTypeManager.registerTaskType(new InteractTaskType(this));
- try {
- Class.forName("org.bukkit.event.inventory.BrewEvent").getMethod("getResults");
- taskTypeManager.registerTaskType(new BrewingTaskType(this));
- } catch (ClassNotFoundException | NoSuchMethodException ignored) { } // server version cannot support task type
- try {
- Class.forName("org.bukkit.event.inventory.SmithItemEvent");
- taskTypeManager.registerTaskType(new SmithingTaskType(this));
- } catch (ClassNotFoundException ignored) { } // server version cannot support task type
- try {
- Class.forName("org.bukkit.block.data.Ageable");
- taskTypeManager.registerTaskType(new FarmingTaskType(this));
- } catch (ClassNotFoundException ignored) { } // server version cannot support task type
- try {
- Class.forName("io.papermc.paper.event.block.PlayerShearBlockEvent");
- taskTypeManager.registerTaskType(new BlockshearingTaskType(this));
- } catch (ClassNotFoundException ignored) { } // server version cannot support task type
- try {
- Class.forName("com.destroystokyo.paper.loottable.LootableInventoryReplenishEvent");
- taskTypeManager.registerTaskType(new ReplenishingTaskType(this));
- } catch (ClassNotFoundException ignored) { } // server version cannot support task type
- try {
- Class.forName("org.bukkit.event.block.BlockDropItemEvent");
- taskTypeManager.registerTaskType(new BlockItemdroppingTaskType(this));
- } catch (ClassNotFoundException ignored) { } // server version cannot support task type
- if (Bukkit.getPluginManager().isPluginEnabled("ASkyBlock")) {
- taskTypeManager.registerTaskType(new ASkyBlockLevelTaskType(this));
- }
+ taskTypeManager.registerTaskType(new InventoryTaskType(this));
+ taskTypeManager.registerTaskType(new MilkingTaskType(this));
+ taskTypeManager.registerTaskType(new MiningTaskType(this));
+ taskTypeManager.registerTaskType(new MobkillingTaskType(this));
+ taskTypeManager.registerTaskType(new PermissionTaskType(this));
+ taskTypeManager.registerTaskType(new PlayerkillingTaskType(this));
+ taskTypeManager.registerTaskType(new PlaytimeTaskType(this));
+ taskTypeManager.registerTaskType(new PositionTaskType(this));
+ taskTypeManager.registerTaskType(new ShearingTaskType(this));
+ taskTypeManager.registerTaskType(new SmeltingTaskType(this));
+ taskTypeManager.registerTaskType(new TamingTaskType(this));
+ taskTypeManager.registerTaskType(new WalkingTaskType(this));
+
+ // Register task types with class/method compatibility requirement
+ taskTypeManager.registerTaskType(new BrewingTaskType(this), () -> CompatUtils.classWithMethodExists("org.bukkit.event.inventory.BrewEvent", "getResults"));
+ taskTypeManager.registerTaskType(new SmithingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.inventory.SmithItemEvent"));
+ taskTypeManager.registerTaskType(new FarmingTaskType(this), () -> CompatUtils.classExists("org.bukkit.block.data.Ageable"));
+ taskTypeManager.registerTaskType(new BlockshearingTaskType(this), () -> CompatUtils.classExists("io.papermc.paper.event.block.PlayerShearBlockEvent"));
+ taskTypeManager.registerTaskType(new ReplenishingTaskType(this), () -> CompatUtils.classExists("com.destroystokyo.paper.loottable.LootableInventoryReplenishEvent"));
+ taskTypeManager.registerTaskType(new BlockItemdroppingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.block.BlockDropItemEvent"));
+
+ // Register task types with enabled plugin compatibility requirement
+ taskTypeManager.registerTaskType(new ASkyBlockLevelTaskType(this), () -> CompatUtils.isPluginEnabled("ASkyBlock"));
+ taskTypeManager.registerTaskType(new CitizensDeliverTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
+ taskTypeManager.registerTaskType(new CitizensInteractTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
+ taskTypeManager.registerTaskType(new EcoBossesKillingTaskType(this), () -> CompatUtils.isPluginEnabled("EcoBosses"));
+ taskTypeManager.registerTaskType(new EssentialsBalanceTaskType(this), () -> CompatUtils.isPluginEnabled("Essentials"));
+ taskTypeManager.registerTaskType(new EssentialsMoneyEarnTaskType(this), () -> CompatUtils.isPluginEnabled("Essentials"));
+ taskTypeManager.registerTaskType(new FabledSkyblockLevelTaskType(this), () -> CompatUtils.isPluginEnabled("FabledSkyblock")); // not tested
+ taskTypeManager.registerTaskType(new PlaceholderAPIEvaluateTaskType(this), () -> CompatUtils.isPluginEnabled("PlaceholderAPI"));
+ taskTypeManager.registerTaskType(new PlayerPointsEarnTaskType(this), () -> CompatUtils.isPluginEnabled("PlayerPoints"));
+ taskTypeManager.registerTaskType(new ShopGUIPlusBuyTaskType(this), () -> CompatUtils.isPluginEnabled("ShopGUIPlus")); // not tested
+ taskTypeManager.registerTaskType(new ShopGUIPlusSellTaskType(this), () -> CompatUtils.isPluginEnabled("ShopGUIPlus")); // not tested
+ taskTypeManager.registerTaskType(new SuperiorSkyblockLevelType(this), () -> CompatUtils.isPluginEnabled("SuperiorSkyblock2")); // not tested
+ taskTypeManager.registerTaskType(new SuperiorSkyblockWorthType(this), () -> CompatUtils.isPluginEnabled("SuperiorSkyblock2")); // not tested
+ taskTypeManager.registerTaskType(new uSkyBlockLevelTaskType(this), () -> CompatUtils.isPluginEnabled("uSkyBlock"));
+ taskTypeManager.registerTaskType(new NuVotifierVoteTaskType(this), () -> CompatUtils.isPluginEnabled("Votifier")); // not tested
+ taskTypeManager.registerTaskType(new VotingPluginVoteType(this), () -> CompatUtils.isPluginEnabled("VotingPlugin")); // not tested
+
+ // Register task types with enabled specific version plugin compatibility requirement
+ taskTypeManager.registerTaskType(new IridiumSkyblockValueTaskType(this), () -> { // TODO FIX
+ String pluginVersion = CompatUtils.getPluginVersion("IridiumSkyblock");
+ return pluginVersion != null && pluginVersion.startsWith("2");
+ });
+ taskTypeManager.registerTaskType(new MythicMobsKillingTaskType(this), () -> {
+ String pluginVersion = CompatUtils.getPluginVersion("MythicMobs");
+ return pluginVersion != null && (pluginVersion.startsWith("4") || pluginVersion.startsWith("5"));
+ });
+
+ // Register task types with even more weird requirements
if (Bukkit.getPluginManager().isPluginEnabled("BentoBox")) {
BentoBoxLevelTaskType.register(this, taskTypeManager);
}
- //TODO FIX
- if (Bukkit.getPluginManager().isPluginEnabled("IridiumSkyblock")
- && Bukkit.getPluginManager().getPlugin("IridiumSkyblock").getDescription().getVersion().startsWith("2")) {
- taskTypeManager.registerTaskType(new IridiumSkyblockValueTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("uSkyBlock")) {
- taskTypeManager.registerTaskType(new uSkyBlockLevelTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("Citizens")) {
- taskTypeManager.registerTaskType(new CitizensDeliverTaskType(this));
- taskTypeManager.registerTaskType(new CitizensInteractTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("MythicMobs")) {
- String mythicMobsVersion = Bukkit.getPluginManager().getPlugin("MythicMobs").getDescription().getVersion();
- if (mythicMobsVersion.startsWith("4") || mythicMobsVersion.startsWith("5")) {
- taskTypeManager.registerTaskType(new MythicMobsKillingTaskType(this, mythicMobsVersion));
- }
- }
- if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
- taskTypeManager.registerTaskType(new PlaceholderAPIEvaluateTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("EcoBosses")) {
- taskTypeManager.registerTaskType(new EcoBossesKillingTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
- taskTypeManager.registerTaskType(new EssentialsMoneyEarnTaskType(this));
- taskTypeManager.registerTaskType(new EssentialsBalanceTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
- taskTypeManager.registerTaskType(new PlayerPointsEarnTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("ShopGUIPlus")) {
- // not tested
- String shopGUIPlusVersion = Bukkit.getPluginManager().getPlugin("ShopGUIPlus").getDescription().getVersion();
- taskTypeManager.registerTaskType(new ShopGUIPlusBuyTaskType(this, shopGUIPlusVersion));
- taskTypeManager.registerTaskType(new ShopGUIPlusSellTaskType(this, shopGUIPlusVersion));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("FabledSkyblock")) {
- // not tested
- taskTypeManager.registerTaskType(new FabledSkyblockLevelTaskType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("SuperiorSkyblock2")) {
- // not tested
- taskTypeManager.registerTaskType(new SuperiorSkyblockLevelType(this));
- taskTypeManager.registerTaskType(new SuperiorSkyblockWorthType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("VotingPlugin")) {
- // not tested
- taskTypeManager.registerTaskType(new VotingPluginVoteType(this));
- }
- if (Bukkit.getPluginManager().isPluginEnabled("Votifier")) {
- // not tested
- taskTypeManager.registerTaskType(new NuVotifierVoteTaskType(this));
- }
+ // Close task type registrations
taskTypeManager.closeRegistrations();
- questsLogger.info(taskTypeManager.getTaskTypes().size() + " task types have been registered"
- + (taskTypeManager.getSkipped() > 0 ? " (" + taskTypeManager.getSkipped() + " skipped due to exclusions or conflicting names)." : "."));
+
+ // Inform about registered task types
+ String registrationMessage = taskTypeManager.getTaskTypes().size() + " task types have been registered";
+ int skipped = taskTypeManager.getSkipped();
+ registrationMessage += (skipped > 0) ? " (" + skipped + " skipped due to exclusions or conflicting names)." : ".";
+ questsLogger.info(registrationMessage);
if (playerBlockTrackerHook != null) {
this.playerBlockTrackerHook.fixPlayerBlockTracker();
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java
index ec41039d..cf747cd1 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.UUID;
+import java.util.function.BooleanSupplier;
public class BukkitTaskTypeManager extends TaskTypeManager {
@@ -27,7 +28,7 @@ public class BukkitTaskTypeManager extends TaskTypeManager {
}
@Override
- public boolean registerTaskType(@NotNull TaskType taskType) {
+ public boolean registerTaskType(@NotNull TaskType taskType, @NotNull BooleanSupplier... suppliers) {
if (!(taskType instanceof BukkitTaskType bukkitTaskType)) throw new RuntimeException("BukkitTaskTypeManager implementation can only accept instances of BukkitTaskType!");
if (super.registerTaskType(taskType)) {
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/BentoBoxLevelTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/BentoBoxLevelTaskType.java
index a641acdd..233b78da 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/BentoBoxLevelTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/BentoBoxLevelTaskType.java
@@ -29,7 +29,6 @@ public final class BentoBoxLevelTaskType extends BukkitTaskType {
super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "level"));
}
-
public static void register(BukkitQuestsPlugin plugin, TaskTypeManager manager) {
if (BentoBox.getInstance().getAddonsManager().getAddonByName("Level").isPresent()) {
manager.registerTaskType(new BentoBoxLevelTaskType(plugin));
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/MythicMobsKillingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/MythicMobsKillingTaskType.java
index a3e95202..5f86774e 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/MythicMobsKillingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/MythicMobsKillingTaskType.java
@@ -2,6 +2,7 @@ package com.leonardobishop.quests.bukkit.tasktype.type.dependent;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
+import com.leonardobishop.quests.bukkit.util.CompatUtils;
import com.leonardobishop.quests.bukkit.util.TaskUtils;
import com.leonardobishop.quests.common.player.QPlayer;
import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
@@ -20,7 +21,7 @@ public final class MythicMobsKillingTaskType extends BukkitTaskType {
private final BukkitQuestsPlugin plugin;
- public MythicMobsKillingTaskType(BukkitQuestsPlugin plugin, String mythicMobsVersion) {
+ public MythicMobsKillingTaskType(BukkitQuestsPlugin plugin) {
super("mythicmobs_killing", TaskUtils.TASK_ATTRIBUTION_STRING, "Kill a set amount of a MythicMobs entity.");
this.plugin = plugin;
@@ -45,7 +46,7 @@ public final class MythicMobsKillingTaskType extends BukkitTaskType {
} catch (ClassNotFoundException ignored) { } // MythicMobs version cannot support task type
plugin.getLogger().severe("Failed to register event handler for MythicMobs task type!");
- plugin.getLogger().severe("MythicMobs version detected: " + mythicMobsVersion);
+ plugin.getLogger().severe("MythicMobs version detected: " + CompatUtils.getPluginVersion("MythicMobs"));
}
private final class MythicMobs4Listener implements Listener {
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusBuyTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusBuyTaskType.java
index bb1e6d4d..1e894d8b 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusBuyTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusBuyTaskType.java
@@ -7,8 +7,8 @@ import net.brcdev.shopgui.shop.ShopTransactionResult;
public final class ShopGUIPlusBuyTaskType extends ShopGUIPlusInteractionTaskType {
- public ShopGUIPlusBuyTaskType(BukkitQuestsPlugin plugin, String shopGUIPlusVersion) {
- super(plugin, shopGUIPlusVersion, "shopguiplus_buy", TaskUtils.TASK_ATTRIBUTION_STRING, "Purchase a given item from a ShopGUIPlus shop", "shopguiplus_buycertain");
+ public ShopGUIPlusBuyTaskType(BukkitQuestsPlugin plugin) {
+ super(plugin, "shopguiplus_buy", TaskUtils.TASK_ATTRIBUTION_STRING, "Purchase a given item from a ShopGUIPlus shop", "shopguiplus_buycertain");
}
@Override
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusInteractionTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusInteractionTaskType.java
index 21627a89..f6c877f5 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusInteractionTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusInteractionTaskType.java
@@ -2,6 +2,7 @@ package com.leonardobishop.quests.bukkit.tasktype.type.dependent;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
+import com.leonardobishop.quests.bukkit.util.CompatUtils;
import com.leonardobishop.quests.bukkit.util.TaskUtils;
import com.leonardobishop.quests.bukkit.util.constraint.TaskConstraintSet;
import com.leonardobishop.quests.common.player.QPlayer;
@@ -26,7 +27,7 @@ public abstract class ShopGUIPlusInteractionTaskType extends BukkitTaskType {
private Method getShopMethod;
private Method getIdMethod;
- public ShopGUIPlusInteractionTaskType(BukkitQuestsPlugin plugin, String shopGUIPlusVersion, @NotNull String type, String author, String description, String... aliases) {
+ public ShopGUIPlusInteractionTaskType(BukkitQuestsPlugin plugin, @NotNull String type, String author, String description, String... aliases) {
super(type, author, description, aliases);
this.plugin = plugin;
@@ -47,7 +48,7 @@ public abstract class ShopGUIPlusInteractionTaskType extends BukkitTaskType {
} catch (ClassNotFoundException | NoSuchMethodException ignored) { }
plugin.getLogger().severe("Failed to register event handler for ShopGUIPlus task type!");
- plugin.getLogger().severe("ShopGUIPlus version detected: " + shopGUIPlusVersion);
+ plugin.getLogger().severe("ShopGUIPlus version detected: " + CompatUtils.getPluginVersion("ShopGUIPlus"));
}
public abstract boolean isCorrectInteraction(ShopTransactionResult result);
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusSellTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusSellTaskType.java
index 2faf59ef..29f3308a 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusSellTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ShopGUIPlusSellTaskType.java
@@ -7,8 +7,8 @@ import net.brcdev.shopgui.shop.ShopTransactionResult;
public final class ShopGUIPlusSellTaskType extends ShopGUIPlusInteractionTaskType {
- public ShopGUIPlusSellTaskType(BukkitQuestsPlugin plugin, String shopGUIPlusVersion) {
- super(plugin, shopGUIPlusVersion, "shopguiplus_sell", TaskUtils.TASK_ATTRIBUTION_STRING, "Sell a given item to a ShopGUIPlus shop", "shopguiplus_sellcertain");
+ public ShopGUIPlusSellTaskType(BukkitQuestsPlugin plugin) {
+ super(plugin, "shopguiplus_sell", TaskUtils.TASK_ATTRIBUTION_STRING, "Sell a given item to a ShopGUIPlus shop", "shopguiplus_sellcertain");
}
@Override
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CompatUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CompatUtils.java
new file mode 100644
index 00000000..e550c509
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CompatUtils.java
@@ -0,0 +1,35 @@
+package com.leonardobishop.quests.bukkit.util;
+
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+
+public class CompatUtils {
+
+ public static boolean classExists(String className) {
+ try {
+ Class.forName(className);
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
+ public static boolean classWithMethodExists(String className, String methodName, Class<?>... methodParameterTypes) {
+ try {
+ Class.forName(className).getMethod(methodName, methodParameterTypes);
+ return true;
+ } catch (ClassNotFoundException | NoSuchMethodException e) {
+ return false;
+ }
+ }
+
+ public static boolean isPluginEnabled(String pluginName) {
+ return Bukkit.getPluginManager().isPluginEnabled(pluginName);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static String getPluginVersion(String pluginName) {
+ Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
+ return plugin != null ? plugin.getDescription().getVersion() : null;
+ }
+}