Skip to content

Commit

Permalink
Make FARM and BLOCK_LOOT trackers way more accurate (requires latest …
Browse files Browse the repository at this point in the history
…AuroraLib)
  • Loading branch information
ErikSzabo committed Nov 24, 2024
1 parent db12098 commit 7de8fbf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +41,12 @@ public void onExtraDrop(LootDropEvent e) {

Map<String, Object> 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);
Expand Down
56 changes: 24 additions & 32 deletions src/main/java/gg/auroramc/quests/listener/FarmingListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +21,7 @@ public class FarmingListener implements Listener {
private final List<Material> crops = List.of(Material.WHEAT, Material.POTATOES, Material.CARROTS, Material.BEETROOTS, Material.COCOA, Material.NETHER_WART);

private final Set<Material> blockCrops = Set.of(Material.SUGAR_CANE, Material.CACTUS, Material.BAMBOO);
private final Set<Material> specialCrops = Set.of(Material.WARPED_FUNGUS, Material.CRIMSON_FUNGUS, Material.BROWN_MUSHROOM,
public static final Set<Material> 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)
Expand All @@ -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())));
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/gg/auroramc/quests/listener/MiningListener.java
Original file line number Diff line number Diff line change
@@ -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())));
}
}

Expand Down

0 comments on commit 7de8fbf

Please sign in to comment.