diff --git a/build.gradle.kts b/build.gradle.kts index f00fd04..a01be9b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,7 +43,7 @@ repositories { dependencies { compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") - compileOnly("gg.auroramc:Aurora:2.0.0-SNAPSHOT") + compileOnly("gg.auroramc:Aurora:2.0.5-SNAPSHOT") compileOnly("gg.auroramc:AuroraLevels:1.5.1") compileOnly("net.luckperms:api:5.4") compileOnly("dev.aurelium:auraskills-api-bukkit:2.2.0") diff --git a/src/main/java/gg/auroramc/quests/hooks/auraskills/AuraSkillsListener.java b/src/main/java/gg/auroramc/quests/hooks/auraskills/AuraSkillsListener.java index b40d514..012449e 100644 --- a/src/main/java/gg/auroramc/quests/hooks/auraskills/AuraSkillsListener.java +++ b/src/main/java/gg/auroramc/quests/hooks/auraskills/AuraSkillsListener.java @@ -6,6 +6,7 @@ import gg.auroramc.aurora.api.AuroraAPI; import gg.auroramc.quests.AuroraQuests; import gg.auroramc.quests.api.quest.TaskType; +import gg.auroramc.quests.listener.FarmingListener; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; @@ -40,6 +41,12 @@ public void onExtraDrop(LootDropEvent e) { Map params = Map.of("type", typeId); + // mushrooms are probably triggered by foraging luck would be from foraging luck + if(FarmingListener.specialCrops.contains(item.getType()) && typeId.namespace().equals("minecraft")) { + manager.progress(e.getPlayer(), TaskType.FARM, item.getAmount(), params); + return; + } + switch (e.getCause()) { case FARMING_LUCK, FARMING_OTHER_LOOT -> manager.progress(e.getPlayer(), TaskType.FARM, item.getAmount(), params); diff --git a/src/main/java/gg/auroramc/quests/listener/FarmingListener.java b/src/main/java/gg/auroramc/quests/listener/FarmingListener.java index c242ce9..e150ac3 100644 --- a/src/main/java/gg/auroramc/quests/listener/FarmingListener.java +++ b/src/main/java/gg/auroramc/quests/listener/FarmingListener.java @@ -6,13 +6,11 @@ import gg.auroramc.quests.AuroraQuests; import gg.auroramc.quests.api.quest.TaskType; import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.block.data.Ageable; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.player.PlayerHarvestBlockEvent; import java.util.List; @@ -23,7 +21,7 @@ public class FarmingListener implements Listener { private final List crops = List.of(Material.WHEAT, Material.POTATOES, Material.CARROTS, Material.BEETROOTS, Material.COCOA, Material.NETHER_WART); private final Set blockCrops = Set.of(Material.SUGAR_CANE, Material.CACTUS, Material.BAMBOO); - private final Set specialCrops = Set.of(Material.WARPED_FUNGUS, Material.CRIMSON_FUNGUS, Material.BROWN_MUSHROOM, + public static final Set specialCrops = Set.of(Material.WARPED_FUNGUS, Material.CRIMSON_FUNGUS, Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, Material.BROWN_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK, Material.MUSHROOM_STEM, Material.MELON, Material.PUMPKIN); @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -35,44 +33,38 @@ public void onPlayerHarvest(PlayerHarvestBlockEvent e) { } } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerBlockBreakHarvest(BlockBreakEvent e) { - if (!crops.contains(e.getBlock().getType())) return; - - if (e.getBlock().getBlockData() instanceof Ageable ageable) { - if (ageable.getAge() != ageable.getMaximumAge()) return; - for (var drop : e.getBlock().getDrops(e.getPlayer().getInventory().getItemInMainHand())) { - AuroraQuests.getInstance().getQuestManager() - .progress(e.getPlayer(), TaskType.FARM, drop.getAmount(), Map.of("type", TypeId.from(drop.getType()))); - } - } - } - @EventHandler public void onBlockBreak(RegionBlockBreakEvent e) { if (!e.isNatural()) return; + var block = e.getBlock(); - handleBreak(e.getPlayerWhoBroke(), e.getBlock()); - } + if (specialCrops.contains(e.getBlock().getType())) return; - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onBlockBreak2(BlockBreakEvent e) { - // We don't care if region manager is enabled - if (AuroraAPI.getRegionManager() != null) return; - if (e.getBlock().hasMetadata("aurora_placed")) return; - - handleBreak(e.getPlayer(), e.getBlock()); + if (blockCrops.contains(block.getType())) { + AuroraQuests.getInstance().getQuestManager().progress(e.getPlayerWhoBroke(), TaskType.FARM, 1, Map.of("type", TypeId.from(block.getType()))); + } } - private void handleBreak(Player player, Block block) { - if (blockCrops.contains(block.getType())) { - AuroraQuests.getInstance().getQuestManager().progress(player, TaskType.FARM, 1, Map.of("type", TypeId.from(block.getType()))); + @EventHandler + public void onBlockDrop(BlockDropItemEvent event) { + if (crops.contains(event.getBlockState().getType())) { + if (event.getBlock().getBlockData() instanceof Ageable ageable) { + if (ageable.getAge() != ageable.getMaximumAge()) return; + for (var drop : event.getItems()) { + var item = drop.getItemStack(); + AuroraQuests.getInstance().getQuestManager() + .progress(event.getPlayer(), TaskType.FARM, item.getAmount(), Map.of("type", TypeId.from(item.getType()))); + } + } return; } - if (specialCrops.contains(block.getType())) { - for (var drop : block.getDrops(player.getInventory().getItemInMainHand())) { - AuroraQuests.getInstance().getQuestManager().progress(player, TaskType.FARM, drop.getAmount(), Map.of("type", TypeId.from(drop.getType()))); + if (AuroraAPI.getRegionManager().isPlacedBlock(event.getBlock())) return; + + if (specialCrops.contains(event.getBlockState().getType())) { + for (var drop : event.getItems()) { + var item = drop.getItemStack(); + AuroraQuests.getInstance().getQuestManager().progress(event.getPlayer(), TaskType.FARM, item.getAmount(), Map.of("type", TypeId.from(item.getType()))); } } } diff --git a/src/main/java/gg/auroramc/quests/listener/MiningListener.java b/src/main/java/gg/auroramc/quests/listener/MiningListener.java index 72df7a0..2e8ef8b 100644 --- a/src/main/java/gg/auroramc/quests/listener/MiningListener.java +++ b/src/main/java/gg/auroramc/quests/listener/MiningListener.java @@ -1,24 +1,26 @@ package gg.auroramc.quests.listener; +import gg.auroramc.aurora.api.AuroraAPI; import gg.auroramc.aurora.api.events.region.RegionBlockBreakEvent; import gg.auroramc.aurora.api.item.TypeId; import gg.auroramc.quests.AuroraQuests; import gg.auroramc.quests.api.quest.TaskType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockDropItemEvent; import java.util.Map; public class MiningListener implements Listener { @EventHandler - public void onBlockBreak(RegionBlockBreakEvent e) { - if (!e.isNatural()) return; - var player = e.getPlayerWhoBroke(); - + public void onBlockBreak(BlockDropItemEvent e) { + if (AuroraAPI.getRegionManager().isPlacedBlock(e.getBlock())) return; + var player = e.getPlayer(); - for (var drop : e.getBlock().getDrops(player.getInventory().getItemInMainHand())) { - AuroraQuests.getInstance().getQuestManager().progress(player, TaskType.BLOCK_LOOT, drop.getAmount(), Map.of("type", TypeId.from(drop.getType()))); + for (var drop : e.getItems()) { + var item = drop.getItemStack(); + AuroraQuests.getInstance().getQuestManager().progress(player, TaskType.BLOCK_LOOT, item.getAmount(), Map.of("type", TypeId.from(item.getType()))); } }