Skip to content

Commit 7c1db90

Browse files
committed
make it rain augm + many fixes
Took 1 hour 50 minutes
1 parent 12a27e1 commit 7c1db90

20 files changed

Lines changed: 440 additions & 43 deletions

.idea/codeStyles/Project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/dev/oribuin/fishing/api/event/FishEventHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public static <T extends FishEventHandler, Z extends Event> void callEvents(Map<
3030
applicable.keySet().removeIf(x -> !x.applicable(event));
3131

3232
// Sort the events by their priority and call them
33-
applicable.entrySet().stream().map(x -> new MutableEventWrapper<>(x, event)).sorted(MutableEventWrapper::compare).forEachOrdered(x -> x.type().callEvent(event, x.level()));
33+
applicable.entrySet().stream().map(x -> new MutableEventWrapper<>(x, event))
34+
.sorted(MutableEventWrapper::compare)
35+
.forEachOrdered(x -> x.type().callEvent(event, x.level()));
3436
}
3537

3638
/**

src/main/java/dev/oribuin/fishing/api/event/def/FishingEvents.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import dev.oribuin.fishing.api.event.impl.FishGenerateEvent;
88
import dev.oribuin.fishing.api.event.impl.FishGutEvent;
99
import dev.oribuin.fishing.api.event.impl.InitialFishCatchEvent;
10+
import org.bukkit.event.player.PlayerFishEvent;
1011

1112
/**
1213
* A global list of methods that can be used to modify all the relevant events in the plugin
@@ -77,4 +78,11 @@ default void onFishGut(FishGutEvent event, int level) {}
7778
*/
7879
default void onConditionCheck(ConditionCheckEvent event, int level) {}
7980

81+
/**
82+
* The functionality provided when a fish bites the rod before it is caught
83+
* @param event The fishing event
84+
* @param level The level of the ability that was used, if applicable (0 if not)
85+
*/
86+
default void onBite(PlayerFishEvent event, int level) {}
87+
8088
}

src/main/java/dev/oribuin/fishing/api/event/impl/FishCatchEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public FishCatchEvent(@NotNull Player who, @NotNull ItemStack rod, @NotNull Fish
5252
this.rod = rod;
5353
this.hook = hook;
5454
this.fish = fish;
55-
55+
this.cancelled = false;
56+
5657
// Set the base values for the fish
5758
Tier tier = this.fish.tier();
5859
this.baseEntropy = tier.entropy();

src/main/java/dev/oribuin/fishing/api/event/impl/FishGenerateEvent.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package dev.oribuin.fishing.api.event.impl;
22

33
import dev.oribuin.fishing.FishingPlugin;
4+
import dev.oribuin.fishing.manager.TierManager;
45
import dev.oribuin.fishing.model.augment.Augment;
56
import dev.oribuin.fishing.model.augment.AugmentRegistry;
6-
import dev.oribuin.fishing.manager.TierManager;
7+
import dev.oribuin.fishing.model.condition.ConditionRegistry;
78
import dev.oribuin.fishing.model.fish.Fish;
89
import dev.oribuin.fishing.model.fish.Tier;
9-
import dev.oribuin.fishing.model.condition.ConditionRegistry;
1010
import dev.oribuin.fishing.util.FishUtils;
1111
import org.bukkit.Bukkit;
1212
import org.bukkit.entity.FishHook;
@@ -101,10 +101,14 @@ public void generate() {
101101
.filter(x -> ConditionRegistry.check(x, player, rod, hook))
102102
.toList();
103103

104+
System.out.println("Total fish that can be caught: " + canCatch.size());
104105
if (canCatch.isEmpty()) return;
105106

106107
// Pick a random fish from the list
107-
this.fish = canCatch.get(FishUtils.RANDOM.nextInt(canCatch.size()));
108+
int index = FishUtils.RANDOM.nextInt(canCatch.size());
109+
System.out.println("Chosen Index: " + index);
110+
this.fish = canCatch.get(index);
111+
System.out.println("Chosen Fish: " + this.fish);
108112
}
109113

110114
/**

src/main/java/dev/oribuin/fishing/listener/FishListener.java

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22

33
import dev.oribuin.fishing.FishingPlugin;
44
import dev.oribuin.fishing.api.event.FishEventHandler;
5+
import dev.oribuin.fishing.api.event.def.FishingEvents;
56
import dev.oribuin.fishing.api.event.impl.FishCatchEvent;
6-
import dev.oribuin.fishing.model.augment.AugmentRegistry;
7+
import dev.oribuin.fishing.api.event.impl.InitialFishCatchEvent;
78
import dev.oribuin.fishing.manager.DataManager;
89
import dev.oribuin.fishing.manager.FishManager;
910
import dev.oribuin.fishing.manager.LocaleManager;
10-
import dev.oribuin.fishing.model.economy.CurrencyRegistry;
11+
import dev.oribuin.fishing.manager.TotemManager;
12+
import dev.oribuin.fishing.model.augment.Augment;
13+
import dev.oribuin.fishing.model.augment.AugmentRegistry;
1114
import dev.oribuin.fishing.model.fish.Fish;
15+
import dev.oribuin.fishing.model.totem.Totem;
1216
import dev.oribuin.fishing.storage.Fisher;
17+
import net.kyori.adventure.text.Component;
1318
import org.bukkit.event.EventHandler;
1419
import org.bukkit.event.Listener;
1520
import org.bukkit.event.player.PlayerFishEvent;
1621
import org.bukkit.inventory.ItemStack;
1722
import org.bukkit.inventory.PlayerInventory;
1823

24+
import java.util.ArrayList;
1925
import java.util.List;
26+
import java.util.Map;
2027

2128
public class FishListener implements Listener {
2229

@@ -30,16 +37,46 @@ public FishListener(FishingPlugin plugin) {
3037

3138
@EventHandler(ignoreCancelled = true)
3239
public void onFish(PlayerFishEvent event) {
33-
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return;
3440
if (event.getHand() == null) return;
3541

3642
ItemStack hand = event.getPlayer().getInventory().getItem(event.getHand()).clone();
43+
Map<Augment, Integer> augments = AugmentRegistry.from(hand);
44+
45+
switch (event.getState()) {
46+
case CAUGHT_FISH -> this.catchNewFish(event, hand, augments);
47+
// todo: allow bite actual modification
48+
}
49+
50+
}
51+
52+
/**
53+
* Catch a new type of fish
54+
*
55+
* @param event The catching event
56+
*/
57+
private void catchNewFish(PlayerFishEvent event, ItemStack rod, Map<Augment, Integer> augments) {
3758
FishManager manager = this.plugin.getManager(FishManager.class);
59+
TotemManager totemProvider = this.plugin.getManager(TotemManager.class);
3860

3961
// If caught no fish, do nothing
40-
List<Fish> caught = manager.tryCatch(event);
41-
if (caught.isEmpty()) return;
62+
List<Fish> caught = new ArrayList<>();
63+
InitialFishCatchEvent catchEvent = new InitialFishCatchEvent(event.getPlayer(), rod, event.getHook());
64+
Totem nearest = totemProvider.getClosestActive(event.getHook().getLocation());
4265

66+
// Run the augments onInitialCatch method
67+
FishEventHandler.callEvents(augments, catchEvent);
68+
69+
// Run Totem Stuff
70+
if (nearest != null) {
71+
FishEventHandler.callEvents(nearest.upgrades(), catchEvent);
72+
}
73+
74+
// Cancel the event if it is cancelled
75+
if (catchEvent.isCancelled()) return;
76+
77+
for (int i = 0; i < catchEvent.getAmountToCatch(); i++) {
78+
caught.add(manager.generateFish(augments, event.getPlayer().getPlayer(), rod, event.getHook()));
79+
}
4380
// Add the fish into the player inventory
4481
float naturalExp = event.getExpToDrop();
4582
int newFishExp = 0;
@@ -48,11 +85,11 @@ public void onFish(PlayerFishEvent event) {
4885
for (Fish fish : caught) {
4986
if (fish == null) continue;
5087

51-
FishCatchEvent fishCatchEvent = new FishCatchEvent(event.getPlayer(), hand, event.getHook(), fish);
88+
FishCatchEvent fishCatchEvent = new FishCatchEvent(event.getPlayer(), rod, event.getHook(), fish);
5289
fishCatchEvent.naturalExp(naturalExp); // Set the base experience gained
90+
fishCatchEvent.callEvent(); // call through bukkit
5391

54-
FishEventHandler.callEvents(AugmentRegistry.from(hand), fishCatchEvent);
55-
92+
FishEventHandler.callEvents(augments, fishCatchEvent);
5693
if (fishCatchEvent.isCancelled()) continue; // If the event is cancelled, do nothing
5794

5895
// Use the event values because they could have been modified
@@ -61,10 +98,11 @@ public void onFish(PlayerFishEvent event) {
6198
newEntropy += fishCatchEvent.entropy();
6299

63100
// Tell the player they caught a fish
64-
event.getPlayer().sendMessage("You caught a " + fish.displayName() + "!"); // TODO: Replace with locale message
65101
// locale.sendMessage(event.getPlayer(), "fish-caught", StringPlaceholders.of("fish", fish.displayName()));
66102

67103
ItemStack resultItem = fish.createItemStack();
104+
Component message = Component.text("You have caught a ").append(resultItem.displayName()); // TODO: Replace with locale message
105+
event.getPlayer().sendMessage(message);
68106

69107
// Give the fish to the player
70108
PlayerInventory inv = event.getPlayer().getInventory();
@@ -75,7 +113,7 @@ public void onFish(PlayerFishEvent event) {
75113

76114
inv.addItem(resultItem);
77115
}
78-
116+
79117
Fisher fisher = this.plugin.getManager(DataManager.class).get(event.getPlayer().getUniqueId());
80118
if (fisher == null) return;
81119

src/main/java/dev/oribuin/fishing/manager/FishManager.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.oribuin.fishing.manager;
22

3-
import dev.oribuin.fishing.FishingPlugin;
43
import dev.oribuin.fishing.api.event.FishEventHandler;
54
import dev.oribuin.fishing.api.event.impl.FishGenerateEvent;
65
import dev.oribuin.fishing.api.event.impl.InitialFishCatchEvent;
@@ -10,9 +9,9 @@
109
import dev.oribuin.fishing.model.totem.Totem;
1110
import dev.rosewood.rosegarden.RosePlugin;
1211
import dev.rosewood.rosegarden.manager.Manager;
12+
import org.bukkit.Bukkit;
1313
import org.bukkit.entity.FishHook;
1414
import org.bukkit.entity.Player;
15-
import org.bukkit.event.Event;
1615
import org.bukkit.event.player.PlayerFishEvent;
1716
import org.bukkit.inventory.ItemStack;
1817

@@ -44,32 +43,24 @@ public List<Fish> tryCatch(PlayerFishEvent event) {
4443
ItemStack rod = event.getPlayer().getInventory().getItem(event.getHand());
4544
Map<Augment, Integer> augments = AugmentRegistry.from(rod);
4645
Totem nearest = this.rosePlugin.getManager(TotemManager.class).getClosestActive(event.getHook().getLocation());
47-
48-
FishEventHandler.callEvents(augments, event);
49-
50-
if (nearest != null) {
51-
FishEventHandler.callEvents(nearest.upgrades(), event);
52-
}
53-
5446
if (event.isCancelled()) return result; // Cancel the event if it is cancelled
55-
47+
5648
InitialFishCatchEvent catchEvent = new InitialFishCatchEvent(event.getPlayer(), rod, event.getHook());
5749

5850
// Run the augments onInitialCatch method
5951
FishEventHandler.callEvents(augments, catchEvent);
60-
52+
6153
// Run Totem Stuff
6254
if (nearest != null) {
6355
FishEventHandler.callEvents(nearest.upgrades(), catchEvent);
6456
}
65-
57+
6658
// Cancel the event if it is cancelled
6759
if (catchEvent.isCancelled()) return result;
6860

6961
for (int i = 0; i < catchEvent.getAmountToCatch(); i++) {
7062
result.add(this.generateFish(augments, event.getPlayer().getPlayer(), rod, event.getHook()));
7163
}
72-
7364
return result;
7465
}
7566

src/main/java/dev/oribuin/fishing/model/augment/Augment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import dev.rosewood.rosegarden.config.CommentedFileConfiguration;
1313
import dev.rosewood.rosegarden.utils.StringPlaceholders;
1414
import org.apache.commons.lang3.StringUtils;
15+
import org.bukkit.Bukkit;
1516
import org.bukkit.Material;
1617
import org.bukkit.NamespacedKey;
1718
import org.bukkit.event.Event;
@@ -20,6 +21,9 @@
2021
import java.nio.file.Path;
2122
import java.util.ArrayList;
2223
import java.util.List;
24+
import java.util.Random;
25+
import java.util.concurrent.ThreadLocalRandom;
26+
import java.util.logging.Logger;
2327

2428
/**
2529
* Augments are upgrades that can be crafted and applied to fishing rods to give them unique abilities to help the player produce more fish.
@@ -30,6 +34,9 @@
3034
*/
3135
public abstract class Augment extends FishEventHandler implements Configurable {
3236

37+
protected final Random random = ThreadLocalRandom.current();
38+
39+
protected final Logger logger;
3340
private final String name;
3441
private boolean enabled;
3542
private List<String> description;
@@ -58,6 +65,8 @@ public Augment(String name, String... description) {
5865
this.displayLine = "&c" + StringUtils.capitalize(this.name.replace("_", " ")) + " %level_roman%";
5966
this.permission = "fishing.augment." + name;
6067
this.price = Cost.of(CurrencyRegistry.ENTROPY, 25000);
68+
69+
this.logger = Logger.getLogger("fishing-augment:" + this.name);
6170
}
6271

6372
/**

src/main/java/dev/oribuin/fishing/model/augment/AugmentRegistry.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import dev.oribuin.fishing.model.augment.impl.AugmentHotspot;
1111
import dev.oribuin.fishing.model.augment.impl.AugmentIndulge;
1212
import dev.oribuin.fishing.model.augment.impl.AugmentIntuition;
13+
import dev.oribuin.fishing.model.augment.impl.AugmentMakeItRain;
1314
import dev.oribuin.fishing.model.augment.impl.AugmentRainDance;
1415
import dev.oribuin.fishing.util.math.RomanNumber;
1516
import dev.rosewood.rosegarden.utils.HexUtils;
@@ -48,13 +49,14 @@ private AugmentRegistry() {}
4849

4950
static {
5051
register(AugmentBiomeBlend::new);
51-
register(AugmentRainDance::new);
52-
register(AugmentHotspot::new);
53-
register(AugmentGenius::new);
54-
register(AugmentIntuition::new);
55-
register(AugmentFineSlicing::new);
5652
register(AugmentEnlightened::new);
53+
register(AugmentFineSlicing::new);
54+
register(AugmentGenius::new);
55+
register(AugmentHotspot::new);
5756
register(AugmentIndulge::new);
57+
register(AugmentIntuition::new);
58+
register(AugmentMakeItRain::new);
59+
register(AugmentRainDance::new);
5860
}
5961

6062
/**

src/main/java/dev/oribuin/fishing/model/augment/impl/AugmentBiomeBlend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void onConditionCheck(ConditionCheckEvent event, int level) {
4747

4848
StringPlaceholders plc = StringPlaceholders.of("level", level);
4949
double chance = FishUtils.evaluate(plc.apply(this.chanceFormula));
50-
if (Math.random() > chance) return;
50+
if (this.random.nextDouble(100) <= chance) return;
5151

5252
event.result(true);
5353
}

0 commit comments

Comments
 (0)