aboutsummaryrefslogtreecommitdiffstats
path: root/bukkit/src/main
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2024-01-08 13:42:36 +0100
committerLeonardo Bishop <13875753+LMBishop@users.noreply.github.com>2024-01-09 15:58:15 +0000
commitb1bf53962b5db4a138e8e2b0d86e119a62513783 (patch)
tree4da016c356a879d3b1c4e7130a57798bf2d26536 /bukkit/src/main
parent3551c1ed8b4e364eda3111ff422ad2ced575b9f6 (diff)
Add WildStacker support to mob killing and breeding task types
Closes https://github.com/LMBishop/Quests/issues/584
Diffstat (limited to 'bukkit/src/main')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java11
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/AbstractWildStackerHook.java8
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/WildStackerHook.java12
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BreedingTaskType.java8
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java42
-rw-r--r--bukkit/src/main/resources/plugin.yml2
6 files changed, 75 insertions, 8 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 3a976cde..40a35179 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -38,6 +38,8 @@ import com.leonardobishop.quests.bukkit.hook.versionspecific.VersionSpecificHand
import com.leonardobishop.quests.bukkit.hook.versionspecific.VersionSpecificHandler20;
import com.leonardobishop.quests.bukkit.hook.versionspecific.VersionSpecificHandler8;
import com.leonardobishop.quests.bukkit.hook.versionspecific.VersionSpecificHandler9;
+import com.leonardobishop.quests.bukkit.hook.wildstacker.AbstractWildStackerHook;
+import com.leonardobishop.quests.bukkit.hook.wildstacker.WildStackerHook;
import com.leonardobishop.quests.bukkit.item.ParsedQuestItem;
import com.leonardobishop.quests.bukkit.item.QuestItem;
import com.leonardobishop.quests.bukkit.item.QuestItemRegistry;
@@ -177,6 +179,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
private AbstractCoreProtectHook coreProtectHook;
private AbstractEssentialsHook essentialsHook;
private AbstractPlayerBlockTrackerHook playerBlockTrackerHook;
+ private AbstractWildStackerHook wildStackerHook;
private ItemGetter itemGetter;
private SkullGetter skullGetter;
private QuestsTitle titleHandle;
@@ -386,6 +389,10 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
} catch (ClassCastException | ClassNotFoundException | NoSuchMethodException ignored) {
}
+ if (CompatUtils.isPluginEnabled("WildStacker")) {
+ this.wildStackerHook = new WildStackerHook();
+ }
+
// Register task types without compatibility requirement
taskTypeManager.registerTaskType(new BreedingTaskType(this));
taskTypeManager.registerTaskType(new BucketEmptyTaskType(this));
@@ -755,6 +762,10 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
return playerBlockTrackerHook;
}
+ public @Nullable AbstractWildStackerHook getWildStackerHook() {
+ return wildStackerHook;
+ }
+
public ItemGetter getItemGetter() {
return itemGetter;
}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/AbstractWildStackerHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/AbstractWildStackerHook.java
new file mode 100644
index 00000000..119b44a8
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/AbstractWildStackerHook.java
@@ -0,0 +1,8 @@
+package com.leonardobishop.quests.bukkit.hook.wildstacker;
+
+import org.bukkit.entity.LivingEntity;
+
+public interface AbstractWildStackerHook {
+
+ int getEntityAmount(LivingEntity entity);
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/WildStackerHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/WildStackerHook.java
new file mode 100644
index 00000000..8c17689b
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/wildstacker/WildStackerHook.java
@@ -0,0 +1,12 @@
+package com.leonardobishop.quests.bukkit.hook.wildstacker;
+
+import com.bgsoftware.wildstacker.api.WildStackerAPI;
+import org.bukkit.entity.LivingEntity;
+
+public class WildStackerHook implements AbstractWildStackerHook {
+
+ @Override
+ public int getEntityAmount(LivingEntity entity) {
+ return WildStackerAPI.getEntityAmount(entity);
+ }
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BreedingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BreedingTaskType.java
index 3fd0e081..efcc5e79 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BreedingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BreedingTaskType.java
@@ -1,6 +1,7 @@
package com.leonardobishop.quests.bukkit.tasktype.type;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.hook.wildstacker.AbstractWildStackerHook;
import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
import com.leonardobishop.quests.bukkit.util.TaskUtils;
import com.leonardobishop.quests.bukkit.util.constraint.TaskConstraintSet;
@@ -81,7 +82,7 @@ public final class BreedingTaskType extends BukkitTaskType {
}
}
- private void handle(Player player, Entity entity) {
+ private void handle(Player player, LivingEntity entity) {
if (player.hasMetadata("NPC")) {
return;
}
@@ -91,6 +92,9 @@ public final class BreedingTaskType extends BukkitTaskType {
return;
}
+ AbstractWildStackerHook wildStackerHook = this.plugin.getWildStackerHook();
+ int eventAmount = (wildStackerHook != null) ? wildStackerHook.getEntityAmount(entity) : 1;
+
for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
@@ -103,7 +107,7 @@ public final class BreedingTaskType extends BukkitTaskType {
continue;
}
- int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress);
+ int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress, eventAmount);
super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId());
int amount = (int) task.getConfigValue("amount");
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java
index 06402754..19265f92 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java
@@ -12,11 +12,13 @@ import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
import com.leonardobishop.quests.common.quest.Quest;
import com.leonardobishop.quests.common.quest.Task;
import org.bukkit.entity.Animals;
+import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
@@ -36,6 +38,14 @@ public final class MobkillingTaskType extends BukkitTaskType {
super.addConfigValidator(TaskUtils.useItemStackConfigValidator(this, "item"));
super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "data"));
super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "exact-match"));
+
+ try {
+ Class.forName("com.bgsoftware.wildstacker.api.events.EntityUnstackEvent");
+ plugin.getServer().getPluginManager().registerEvents(new MobkillingTaskType.EntityUnstackListener(), plugin);
+ return;
+ } catch (ClassNotFoundException ignored) { } // there is no entity unstack available so we use EntityDeathEvent instead
+
+ plugin.getServer().getPluginManager().registerEvents(new MobkillingTaskType.EntityDeathListener(), plugin);
}
@Override
@@ -43,9 +53,32 @@ public final class MobkillingTaskType extends BukkitTaskType {
fixedQuestItemCache.clear();
}
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onEntityDeath(EntityDeathEvent event) {
- Player player = event.getEntity().getKiller();
+ private final class EntityDeathListener implements Listener {
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onEntityDeath(EntityDeathEvent event) {
+ LivingEntity entity = event.getEntity();
+ Player player = entity.getKiller();
+
+ handle(player, entity, 1);
+ }
+ }
+
+ private final class EntityUnstackListener implements Listener {
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onEntityUnstack(com.bgsoftware.wildstacker.api.events.EntityUnstackEvent event) {
+ Entity source = event.getUnstackSource();
+ if (!(source instanceof Player player)) {
+ return;
+ }
+
+ LivingEntity entity = event.getEntity().getLivingEntity();
+ int eventAmount = event.getAmount();
+
+ handle(player, entity, eventAmount);
+ }
+ }
+
+ private void handle(Player player, LivingEntity entity, int eventAmount) {
if (player == null) {
return;
}
@@ -59,7 +92,6 @@ public final class MobkillingTaskType extends BukkitTaskType {
return;
}
- LivingEntity entity = event.getEntity();
if (entity instanceof Player) {
return;
}
@@ -121,7 +153,7 @@ public final class MobkillingTaskType extends BukkitTaskType {
}
}
- int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress);
+ int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress, eventAmount);
super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId());
int amount = (int) task.getConfigValue("amount");
diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml
index 80fb1149..b135cef4 100644
--- a/bukkit/src/main/resources/plugin.yml
+++ b/bukkit/src/main/resources/plugin.yml
@@ -6,7 +6,7 @@ version: "${version}"
main: com.leonardobishop.quests.bukkit.BukkitQuestsPlugin
website: https://github.com/LMBishop/Quests
author: "LMBishop & contributors"
-softdepend: [ASkyBlock, BentoBox, Citizens, CoreProtect, Essentials, FabledSkyBlock, IridiumSkyblock, MythicMobs, PlaceholderAPI, PlayerBlockTracker, PlayerPoints, ShopGUIPlus, SuperiorSkyblock2, uSkyBlock, Votifier, VotingPlugin]
+softdepend: [ASkyBlock, BentoBox, Citizens, CoreProtect, Essentials, FabledSkyBlock, IridiumSkyblock, MythicMobs, PlaceholderAPI, PlayerBlockTracker, PlayerPoints, ShopGUIPlus, SuperiorSkyblock2, uSkyBlock, Votifier, VotingPlugin, WildStacker]
prefix: Quests
api-version: "1.13" # allows new API features but Quests will still work pre-1.13
folia-supported: true