Repository navigation
Add bog monster kill and lure rewards #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,660
−13
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9d28e0
Add bog monster kill and lure rewards
ryanbarlow97 509dfea
Drop ambient rewards into the world so MythicMobs PreventOtherDrops k…
ryanbarlow97 c432395
Tie lure rewards to the joining character and prune idle key caps
ryanbarlow97 337746b
Reset lure kills when a different character joins
ryanbarlow97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/net/tfminecraft/infestations/reward/KeyCap.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package net.tfminecraft.infestations.reward; | ||
|
|
||
| import java.util.ArrayDeque; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Counts ambient key drops per player over a rolling hour. | ||
| */ | ||
| final class KeyCap { | ||
|
|
||
| static final long WINDOW_MS = 3_600_000L; | ||
|
|
||
| private final Map<UUID, ArrayDeque<Long>> given = new HashMap<>(); | ||
| private long lastSweep; | ||
|
|
||
| /** How many of {@code wanted} keys the player may still get. A cap of 0 or less means no cap. */ | ||
| int allow(UUID player, int wanted, int cap, long now) { | ||
| if (wanted <= 0) { | ||
| return 0; | ||
| } | ||
| if (cap <= 0) { | ||
| return wanted; | ||
| } | ||
| sweep(now); | ||
| ArrayDeque<Long> times = given.computeIfAbsent(player, k -> new ArrayDeque<>()); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| expire(times, now); | ||
| int allowed = Math.min(wanted, cap - times.size()); | ||
| for (int i = 0; i < allowed; i++) { | ||
| times.addLast(now); | ||
| } | ||
| return Math.max(0, allowed); | ||
| } | ||
|
|
||
| /** Forgets players whose drops have all left the window, at most once per window. */ | ||
| private void sweep(long now) { | ||
| if (now - lastSweep < WINDOW_MS) { | ||
| return; | ||
| } | ||
| lastSweep = now; | ||
| given.values().removeIf(times -> { | ||
| expire(times, now); | ||
| return times.isEmpty(); | ||
| }); | ||
| } | ||
|
|
||
| private static void expire(ArrayDeque<Long> times, long now) { | ||
| while (!times.isEmpty() && times.peekFirst() <= now - WINDOW_MS) { | ||
| times.pollFirst(); | ||
| } | ||
| } | ||
|
|
||
| int tracked() { | ||
| return given.size(); | ||
| } | ||
|
|
||
| void clear() { | ||
| given.clear(); | ||
| } | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
src/main/java/net/tfminecraft/infestations/reward/PermadeathZones.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package net.tfminecraft.infestations.reward; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| import net.tfminecraft.infestations.Infestations; | ||
|
|
||
| /** | ||
| * Asks RPCharacters whether a location is inside a permadeath zone. Uses reflection so Infestations | ||
| * never depends on RPCharacters. Without RPCharacters, or on any error, the location is outside a zone. | ||
| */ | ||
| public final class PermadeathZones { | ||
|
|
||
| static final String LOOKUP = "net.tfminecraft.rpcharacters.permadeath.PermadeathAreaLookup"; | ||
|
|
||
| private static ClassLoader loader; | ||
| private static Method lookup; | ||
| private static boolean warned; | ||
|
|
||
| private PermadeathZones() {} | ||
|
|
||
| public static boolean inZone(Location location) { | ||
| if (location == null) { | ||
| return false; | ||
| } | ||
| Plugin plugin = Bukkit.getPluginManager().getPlugin("RPCharacters"); | ||
| if (plugin == null || !plugin.isEnabled()) { | ||
| return false; | ||
| } | ||
| try { | ||
| return method(plugin.getClass().getClassLoader()).invoke(null, location) != null; | ||
| } catch (ReflectiveOperationException | RuntimeException | LinkageError ex) { | ||
| if (!warned) { | ||
| warned = true; | ||
| Infestations.plugin.getLogger().warning( | ||
| "[Infestations] Permadeath zone lookup failed, treating locations as outside zones: " + ex); | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| static Method method(ClassLoader classLoader) throws ReflectiveOperationException { | ||
| if (lookup == null || loader != classLoader) { | ||
| lookup = Class.forName(LOOKUP, true, classLoader).getMethod("getPermadeathZoneAt", Location.class); | ||
| loader = classLoader; | ||
| } | ||
| return lookup; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.