Skip to content

Commit

Permalink
Add "boat-fishing" condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Oct 5, 2024
1 parent bbc84be commit 8911e46
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -90,7 +89,7 @@ public void generate() {

// Make sure the quality is not null
List<Fish> 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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/oribuin/fishing/fish/Fish.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@ public class Condition {
private boolean iceFishing = false;
private Pair<Integer, Integer> height = null;
private Integer lightLevel = null;
private boolean boatFishing = false;

public List<Biome> biomes() {
return biomes;
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, CatchCondition> CONDITIONS = new HashMap<>();

static {
register("biome", new BiomeCondition());
register("boat", new BoatCondition());
register("depth", new DepthCondition());
register("environment", new EnvironmentCondition());
register("height", new HeightCondition());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 8911e46

Please sign in to comment.