diff --git a/src/main/java/xyz/oribuin/fishing/api/event/FishGenerateEvent.java b/src/main/java/xyz/oribuin/fishing/api/event/FishGenerateEvent.java index 21f04fe..65c9643 100644 --- a/src/main/java/xyz/oribuin/fishing/api/event/FishGenerateEvent.java +++ b/src/main/java/xyz/oribuin/fishing/api/event/FishGenerateEvent.java @@ -10,12 +10,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.oribuin.fishing.FishingPlugin; -import xyz.oribuin.fishing.api.condition.ConditionProvider; +import xyz.oribuin.fishing.fish.condition.ConditionRegistry; import xyz.oribuin.fishing.augment.Augment; import xyz.oribuin.fishing.augment.AugmentRegistry; import xyz.oribuin.fishing.fish.Fish; import xyz.oribuin.fishing.fish.Tier; -import xyz.oribuin.fishing.manager.FishManager; import xyz.oribuin.fishing.manager.TierManager; import xyz.oribuin.fishing.util.FishUtils; @@ -90,7 +89,7 @@ public void generate() { // Make sure the quality is not null List canCatch = quality.fish().values().stream() - .filter(x -> ConditionProvider.check(x, player, rod, hook)) + .filter(x -> ConditionRegistry.check(x, player, rod, hook)) .toList(); if (canCatch.isEmpty()) return; diff --git a/src/main/java/xyz/oribuin/fishing/fish/Fish.java b/src/main/java/xyz/oribuin/fishing/fish/Fish.java index 1a21187..cde5dbc 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/Fish.java +++ b/src/main/java/xyz/oribuin/fishing/fish/Fish.java @@ -78,6 +78,7 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { condition.iceFishing(config.getBoolean("ice-fishing")); condition.lightLevel((Integer) config.get("light-level")); condition.height(FishUtils.getHeight(config.getString("height"))); + condition.boatFishing(config.getBoolean("boat-fishing")); fish.condition(condition); } @@ -98,6 +99,7 @@ public void saveSettings(@NotNull CommentedConfigurationSection config) { config.set(this.name + ".biomes", this.condition.biomes().stream().map(Enum::name).toList()); config.set(this.name + ".worlds", this.condition.worlds()); config.set(this.name + ".ice-fishing", this.condition.iceFishing()); + config.set(this.name + "boat-fishing", this.condition.boatFishing()); // ugly :) if (this.condition.weather() != null) config.set(this.name + ".weather", this.condition.weather().name()); diff --git a/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java b/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java index 4614262..242dbe6 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java +++ b/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java @@ -3,6 +3,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.bukkit.World; import org.bukkit.block.Biome; +import xyz.oribuin.fishing.fish.condition.impl.BoatCondition; import java.util.ArrayList; import java.util.List; @@ -21,6 +22,7 @@ public class Condition { private boolean iceFishing = false; private Pair height = null; private Integer lightLevel = null; + private boolean boatFishing = false; public List biomes() { return biomes; @@ -103,4 +105,12 @@ public Condition lightLevel(Integer lightLevel) { return this; } + public boolean boatFishing() { + return this.boatFishing; + } + + public void boatFishing(boolean boatFishing) { + this.boatFishing = boatFishing; + } + } \ No newline at end of file diff --git a/src/main/java/xyz/oribuin/fishing/api/condition/ConditionProvider.java b/src/main/java/xyz/oribuin/fishing/fish/condition/ConditionRegistry.java similarity index 93% rename from src/main/java/xyz/oribuin/fishing/api/condition/ConditionProvider.java rename to src/main/java/xyz/oribuin/fishing/fish/condition/ConditionRegistry.java index 868e0fe..5b243cc 100644 --- a/src/main/java/xyz/oribuin/fishing/api/condition/ConditionProvider.java +++ b/src/main/java/xyz/oribuin/fishing/fish/condition/ConditionRegistry.java @@ -1,9 +1,13 @@ -package xyz.oribuin.fishing.api.condition; +package xyz.oribuin.fishing.fish.condition; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import xyz.oribuin.fishing.api.condition.CatchCondition; +import xyz.oribuin.fishing.api.event.ConditionCheckEvent; +import xyz.oribuin.fishing.fish.Fish; import xyz.oribuin.fishing.fish.condition.impl.BiomeCondition; +import xyz.oribuin.fishing.fish.condition.impl.BoatCondition; import xyz.oribuin.fishing.fish.condition.impl.DepthCondition; import xyz.oribuin.fishing.fish.condition.impl.EnvironmentCondition; import xyz.oribuin.fishing.fish.condition.impl.HeightCondition; @@ -12,18 +16,17 @@ import xyz.oribuin.fishing.fish.condition.impl.TimeCondition; import xyz.oribuin.fishing.fish.condition.impl.WeatherCondition; import xyz.oribuin.fishing.fish.condition.impl.WorldCondition; -import xyz.oribuin.fishing.api.event.ConditionCheckEvent; -import xyz.oribuin.fishing.fish.Fish; import java.util.HashMap; import java.util.Map; -public class ConditionProvider { +public class ConditionRegistry { private static final Map CONDITIONS = new HashMap<>(); static { register("biome", new BiomeCondition()); + register("boat", new BoatCondition()); register("depth", new DepthCondition()); register("environment", new EnvironmentCondition()); register("height", new HeightCondition()); diff --git a/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BoatCondition.java b/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BoatCondition.java new file mode 100644 index 0000000..0d9f733 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BoatCondition.java @@ -0,0 +1,43 @@ +package xyz.oribuin.fishing.fish.condition.impl; + +import org.bukkit.entity.Boat; +import org.bukkit.entity.Entity; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import xyz.oribuin.fishing.api.condition.CatchCondition; +import xyz.oribuin.fishing.fish.Fish; + +public class BoatCondition implements CatchCondition { + + /** + * Check if the requirements are met to run the condition + * + * @param fish The fish to check + * + * @return Results in true if the condition should run + */ + @Override + public boolean shouldRun(Fish fish) { + return fish.condition().boatFishing(); + } + + /** + * Check if the player can catch the fish with the current conditions + * + * @param fish The fish the player is trying to catch + * @param player The player to check + * @param rod The fishing rod the player is using + * @param hook The fishhook the player is using + * + * @return Results in true if the player can catch the fish + */ + @Override + public boolean check(Fish fish, Player player, ItemStack rod, FishHook hook) { + if (!player.isInsideVehicle()) return false; + + Entity vehicle = player.getVehicle(); + return vehicle instanceof Boat; + } + +}