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
Expand Up @@ -305,13 +305,23 @@ private void collectSource(Player player, UUID hunter, Location collected, Equip
dropLimits.recordCollection(player);
UsageStats.getInstance().recordSourceCollected();
Bukkit.getPluginManager().callEvent(new GeigerSourceCollectEvent(player, collected));
notifyPlayerOfCollection(player);
replaceGeigerWithDeadVersion(player, geigerSlot);
notifyPlayerOfCollection(player);
giveReward(player);
}

// One line: the find, then the spent counter. A blank half is left out.
private void notifyPlayerOfCollection(Player player) {
player.sendMessage(config.getMessages().get("player.found-source"));
String found = config.getMessages().get("player.found-source");
String spent = config.getMessages().get("player.dead-geiger");
if (found.isBlank() || spent.isBlank()) {
String only = found.isBlank() ? spent : found;
if (!only.isBlank()) {
player.sendMessage(only);
}
return;
}
player.sendMessage(found + " " + spent);
}

private void replaceGeigerWithDeadVersion(Player player, EquipmentSlot geigerSlot) {
Expand All @@ -336,7 +346,6 @@ private void replaceGeigerWithDeadVersion(Player player, EquipmentSlot geigerSlo
deadGeiger.setAmount(1);
giveItemOrDropLeftovers(player, deadGeiger);
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1f, 1f);
player.sendMessage(config.getMessages().get("player.dead-geiger"));
} catch (Exception e) {
plugin.getLogger().warning("Failed to give dead Geiger Counter to " + player.getName() + ": " + e.getMessage());
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
# PLAYER - seen by anyone hunting a source
# ====================================
player:
# Shown when a player finds their radioactive source
found-source: "&#AA00FFYou have found the source of Arcane Radiation!"
# Shown when a player finds their radioactive source, followed on the same
# line by dead-geiger. Leave either blank to drop that half.
found-source: "&#AA00FFYou found the arcane source!"

# Title of the signal bar shown while holding a detector
signal-bar: "&#AA00FFArcane signal"

# Shown when the Geiger Counter burns out after finding the source
dead-geiger: "&7Your Arcane Trace Detector has run out of fuel."
# Second half of the found-source line: the counter burns out
dead-geiger: "&7Your detector is spent."

# Shown when a player has used up their drops for the current window
# %max% = drops allowed per window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@

@Test
void rejectedCandidatesRetryThenAccept() {
when(filter.check(any())).thenReturn(SpawnLocationFilter.Rejection.LIQUID, null);

Check warning on line 192 in src/test/java/net/tfminecraft/geigercounters/handlers/SourceHandlerTest.java

View workflow job for this annotation

GitHub Actions / build

non-varargs call of varargs method with inexact argument type for last parameter;
assertNotNull(handler.placeNear(hunter, origin).join());
verify(filter, times(2)).check(any());
}
Expand Down Expand Up @@ -361,6 +361,29 @@
assertFalse(handler.isPlacing(hunter));
}

@Test
void collectionSendsTheFindAndTheSpentCounterAsOneLine() {
when(messages.get("player.found-source")).thenReturn("Found!");
when(messages.get("player.dead-geiger")).thenReturn("Spent.");
place();
collect(EquipmentSlot.HAND);
verify(player).sendMessage("Found! Spent.");
verify(player, times(1)).sendMessage(anyString());
}

@Test
void aBlankHalfOfTheCollectionLineIsLeftOut() {
when(messages.get("player.found-source")).thenReturn("Found!", " ", "");
when(messages.get("player.dead-geiger")).thenReturn("", "Spent.", "");
for (int run = 0; run < 3; run++) {
place();
collect(EquipmentSlot.HAND);
}
verify(player).sendMessage("Found!");
verify(player).sendMessage("Spent.");
verify(player, times(2)).sendMessage(anyString());
}

@Test
void offhandCollectionAlsoGrantsClonedRewardWithConfiguredAmount() {
TierReward tier = new TierReward("rare", 1);
Expand Down