Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.tfminecraft.activitytf.listeners;

import com.dre.brewery.BIngredients;
import com.dre.brewery.Barrel;
import com.dre.brewery.Brew;
import com.dre.brewery.api.events.IngedientAddEvent;
import com.dre.brewery.api.events.brew.BrewModifyEvent;
Expand Down Expand Up @@ -32,6 +33,10 @@
public class BreweryListener implements Listener {

static final NamespacedKey DISTILLED = new NamespacedKey("activity", "brew_distilled");
static final NamespacedKey AGED = new NamespacedKey("activity", "brew_aged");

// Brews younger than this many BreweryX years have not been aged on purpose.
static final float MIN_AGE_YEARS = 1.0f;

// Clicks that take the clicked item out of its slot.
static final Set<InventoryAction> TAKES = EnumSet.of(
Expand Down Expand Up @@ -79,9 +84,10 @@ private static int cookedMinutes(Brew brew) {
return ingredients == null ? 0 : ingredients.getCookedTime();
}

// BreweryX distils on a timer with no player attached, so the credit goes to whoever
// takes a distilled brew out of a brewing stand's bottle slots. The tag written onto
// the brew keeps it from counting again when it is put back and taken out.
// BreweryX distils and ages with no player attached, so the credit goes to whoever
// takes a distilled brew out of a brewing stand's bottle slots, or a brew aged for at
// least a year out of a barrel. The tag written onto the brew keeps it from counting
// again when it is put back and taken out.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onContainerTake(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player player) || !TAKES.contains(event.getAction())) {
Expand All @@ -98,6 +104,11 @@ public void onContainerTake(InventoryClickEvent event) {
if (brew != null && brew.getDistillRuns() > 0) {
creditOnce(player, clicked, event.getSlot(), item, DISTILLED, "brew_distill");
}
} else if (clicked.getHolder(false) instanceof Barrel) {
Brew brew = Brew.get(item);
if (brew != null && brew.getAgeTime() >= MIN_AGE_YEARS) {
creditOnce(player, clicked, event.getSlot(), item, AGED, "brew_age");
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ activities:
# every: 3
# points: 1
# daily-cap: 1
# BreweryX: brews aged at least a year taken out of a barrel, each brew once
brew_age:
display: "#e6ca40&lAge Brews"
description:
- "&7Take &a%every% &7brews aged at least a year out of a barrel."
- "&7Earn &a%points% &7activity points per completion."
- "&7"
material: BARREL
every: 3
points: 1
daily-cap: 1
# RPCharacters: profession upgrades purchased
profession_upgrade:
display: "#e6ca40&lProfession Upgrade"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ void aBrewThatNeverLeftItsSlotLosesOnlyItsOwnTag() {
assertTrue(BreweryListener.markOnce(data, BreweryListener.DISTILLED, 9L));
}

@Test
void distillingAndAgingAreTrackedSeparately() {
PersistentDataContainer data = stubData();
assertTrue(BreweryListener.markOnce(data, BreweryListener.DISTILLED, 1L));
assertTrue(BreweryListener.markOnce(data, BreweryListener.AGED, 2L));
assertFalse(BreweryListener.markOnce(data, BreweryListener.AGED, 3L));
}

@Test
void onlyClicksThatTakeTheItemCount() {
assertTrue(BreweryListener.TAKES.contains(InventoryAction.PICKUP_ALL));
Expand Down