diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java index 5f4807a3..6864f961 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java @@ -10,7 +10,6 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.config.function.*; import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.effect.EffectModifier; -import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect; import net.momirealms.customfishing.api.mechanic.entity.EntityConfig; import net.momirealms.customfishing.api.mechanic.event.EventCarrier; import net.momirealms.customfishing.api.mechanic.hook.HookConfig; @@ -175,10 +174,6 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable { registerNodeFunction(nodes, new LootParserFunction(function)); } - public void registerBaseEffectParser(Function> function, String... nodes) { - registerNodeFunction(nodes, new BaseEffectParserFunction(function)); - } - public void registerItemParser(Function, Context>> function, int priority, String... nodes) { registerNodeFunction(nodes, new ItemParserFunction(priority, function)); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java index 62c83f5c..43e38e2a 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java @@ -37,6 +37,8 @@ public interface Effect { */ Map, Object> properties(); + Effect properties(Map, Object> properties); + /** * Sets the specified property to the given value. * @@ -258,6 +260,8 @@ public interface Effect { */ void combine(Effect effect); + Effect copy(); + /** * Creates a new instance of {@link Effect}. * diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java index dface74c..d9e2cac1 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java @@ -32,6 +32,12 @@ public class EffectImpl implements Effect { return properties; } + @Override + public Effect properties(Map, Object> properties) { + this.properties.putAll(properties); + return this; + } + @Override public EffectImpl arg(EffectProperties key, C value) { properties.put(key, value); @@ -205,4 +211,24 @@ public class EffectImpl implements Effect { this.weightOperationsIgnored.addAll(another.weightOperationsIgnored()); this.properties.putAll(another.properties()); } + + @Override + public Effect copy() { + return Effect.newInstance() + .scoreMultiplier(this.scoreMultiplier) + .scoreAdder(this.scoreAdder) + .sizeMultiplier(this.sizeMultiplier) + .sizeAdder(this.sizeAdder) + .difficultyMultiplier(this.difficultyMultiplier) + .difficultyAdder(this.difficultyAdder) + .gameTimeMultiplier(this.gameTimeMultiplier) + .gameTimeAdder(this.gameTimeAdder) + .waitTimeMultiplier(this.waitTimeMultiplier) + .waitTimeAdder(this.waitTimeAdder) + .multipleLootChance(this.multipleLootChance) + .weightOperations(this.weightOperations) + .weightOperationsIgnored(this.weightOperationsIgnored) + .properties(this.properties); + + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java index beda6c35..86a70947 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java @@ -3,10 +3,10 @@ package net.momirealms.customfishing.api.mechanic.effect; import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.item.MechanicType; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; +import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.entity.Player; import java.util.List; -import java.util.function.BiConsumer; /** * EffectModifier interface for modifying effects in the CustomFishing plugin. @@ -28,7 +28,7 @@ public interface EffectModifier { * * @return a list of effect modifiers */ - List>> modifiers(); + List, Integer>> modifiers(); /** * Creates and returns a new Builder instance for constructing EffectModifier instances. @@ -62,7 +62,7 @@ public interface EffectModifier { * @param modifiers a list of effect modifiers * @return the current Builder instance */ - Builder modifiers(List>> modifiers); + Builder modifiers(List, Integer>> modifiers); /** * Set the type of the item diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifierImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifierImpl.java index c3b79a85..54041eec 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifierImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifierImpl.java @@ -3,20 +3,25 @@ package net.momirealms.customfishing.api.mechanic.effect; import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.item.MechanicType; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; +import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; -import java.util.function.BiConsumer; public class EffectModifierImpl implements EffectModifier { private final Requirement[] requirements; - private final List>> modifiers; + private final List, Integer>> modifiers; private final String id; private final MechanicType type; - public EffectModifierImpl(String id, MechanicType type, Requirement[] requirements, List>> modifiers) { + public EffectModifierImpl( + String id, + MechanicType type, + Requirement[] requirements, + List, Integer>> modifiers + ) { this.requirements = requirements; this.modifiers = modifiers; this.id = id; @@ -34,7 +39,7 @@ public class EffectModifierImpl implements EffectModifier { } @Override - public List>> modifiers() { + public List, Integer>> modifiers() { return modifiers; } @@ -45,7 +50,7 @@ public class EffectModifierImpl implements EffectModifier { public static class BuilderImpl implements Builder { private final List> requirements = new ArrayList<>(); - private final List>> modifiers = new ArrayList<>(); + private final List, Integer>> modifiers = new ArrayList<>(); private String id; private MechanicType type; @Override @@ -59,17 +64,15 @@ public class EffectModifierImpl implements EffectModifier { return this; } @Override - public Builder modifiers(List>> modifiers) { + public Builder modifiers(List, Integer>> modifiers) { this.modifiers.addAll(modifiers); return this; } - @Override public Builder type(MechanicType type) { this.type = type; return this; } - @Override @SuppressWarnings("unchecked") public EffectModifier build() { diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java index d2c0b2b6..8ba10801 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java @@ -1,5 +1,6 @@ package net.momirealms.customfishing.api.mechanic.effect; +import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import org.bukkit.entity.Player; @@ -66,6 +67,8 @@ public interface LootBaseEffect { return new LootBaseEffectImpl.BuilderImpl(); } + Effect toEffect(Context context); + /** * Builder interface for constructing {@link LootBaseEffect} instances. */ diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java index 1d346c58..a1139914 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java @@ -1,5 +1,6 @@ package net.momirealms.customfishing.api.mechanic.effect; +import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import org.bukkit.entity.Player; @@ -58,6 +59,18 @@ public class LootBaseEffectImpl implements LootBaseEffect { return gameTimeMultiplier; } + @Override + public Effect toEffect(Context context) { + Effect effect = Effect.newInstance(); + effect.waitTimeAdder(waitTimeAdder.evaluate(context)); + effect.waitTimeMultiplier(waitTimeMultiplier.evaluate(context)); + effect.difficultyAdder(difficultyAdder.evaluate(context)); + effect.difficultyMultiplier(difficultyMultiplier.evaluate(context)); + effect.gameTimeAdder(gameTimeAdder.evaluate(context)); + effect.gameTimeMultiplier(gameTimeMultiplier.evaluate(context)); + return effect; + } + public static class BuilderImpl implements Builder { private MathValue waitTimeAdder = DEFAULT_WAIT_TIME_ADDER; private MathValue waitTimeMultiplier = DEFAULT_WAIT_TIME_MULTIPLIER; diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java new file mode 100644 index 00000000..612ae9d2 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java @@ -0,0 +1,94 @@ +package net.momirealms.customfishing.api.mechanic.fishing; + +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.effect.EffectModifier; +import net.momirealms.customfishing.api.mechanic.fishing.hook.HookMechanic; +import net.momirealms.customfishing.api.mechanic.loot.Loot; +import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; +import org.apache.logging.log4j.util.TriConsumer; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.function.Consumer; + +public class CustomFishingHook { + + private static final Consumer hookConsumer = defaultHookLogics(); + private FishHook hook; + private final SchedulerTask task; + private HookMechanic hookMechanic; + private Context context; + + public static Consumer defaultHookLogics() { + return fishHook -> { + + + }; + } + + public CustomFishingHook(FishHook hook, FishingGears gears, Context context, List enabledMechanics) { + this.hook = hook; + this.context = context; + + Effect effect = Effect.newInstance(); + for (EffectModifier modifier : gears.effectModifiers()) { + for (TriConsumer, Integer> consumer : modifier.modifiers()) { + consumer.accept(effect, context, 0); + } + } + + + + this.task = BukkitCustomFishingPlugin.getInstance().getScheduler().sync().runRepeating(() -> { + // destroy if hook is invalid + if (hook.isValid()) { + BukkitCustomFishingPlugin.getInstance().getFishingManager().destroy(hook.getOwnerUniqueId()); + return; + } + for (HookMechanic mechanic : enabledMechanics) { + if (mechanic.canStart()) { + if (hookMechanic != mechanic) { + if (hookMechanic != null) hookMechanic.destroy(); + hookMechanic = mechanic; + mechanic.preStart(); + + Effect tempEffect = effect.copy(); + + for (EffectModifier modifier : gears.effectModifiers()) { + for (TriConsumer, Integer> consumer : modifier.modifiers()) { + consumer.accept(tempEffect, context, 1); + } + } + + Loot loot = BukkitCustomFishingPlugin.getInstance().getLootManager().getNextLoot(effect, context); + if (loot == null) { + // TODO warn + return; + } + + Effect baseEffect = loot.baseEffect().toEffect(context); + tempEffect.combine(baseEffect); + + for (EffectModifier modifier : gears.effectModifiers()) { + for (TriConsumer, Integer> consumer : modifier.modifiers()) { + consumer.accept(tempEffect, context, 2); + } + } + + mechanic.start(tempEffect); + } + } + } + + + }, 1, 1, hook.getLocation()); + } + + public void cancel() { + task.cancel(); + if (hookMechanic != null) hookMechanic.destroy(); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingHookTimerTask.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingHookTimerTask.java deleted file mode 100644 index 8e1e2fa6..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingHookTimerTask.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.momirealms.customfishing.api.mechanic.fishing; - -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; -import org.bukkit.entity.FishHook; - -import java.util.function.Consumer; - -public class FishingHookTimerTask { - - private static Consumer hookConsumer = defaultHookLogics(); - private FishingManager manager; - private FishHook hook; - private final SchedulerTask task; - - public static Consumer defaultHookLogics() { - return fishHook -> { - if (fishHook.isValid()) { - BukkitCustomFishingPlugin.getInstance().getFishingManager().destroy(fishHook.getOwnerUniqueId()); - return; - } - - }; - } - - public FishingHookTimerTask(FishingManager manager, FishHook hook) { - this.manager = manager; - this.hook = hook; - this.task = BukkitCustomFishingPlugin.getInstance().getScheduler().sync().runRepeating(() -> { - hookConsumer.accept(hook); - }, 1, 1, hook.getLocation()); - } - - public void cancel() { - task.cancel(); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/HookMechanic.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/HookMechanic.java new file mode 100644 index 00000000..75baf2d7 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/HookMechanic.java @@ -0,0 +1,17 @@ +package net.momirealms.customfishing.api.mechanic.fishing.hook; + +import net.momirealms.customfishing.api.mechanic.effect.Effect; +import org.bukkit.entity.FishHook; + +public interface HookMechanic +{ + boolean canStart(); + + void preStart(); + + void start(Effect finalEffect); + + boolean isHooked(); + + void destroy(); +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/LavaFishingMechanic.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/LavaFishingMechanic.java new file mode 100644 index 00000000..7c16b0a6 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/LavaFishingMechanic.java @@ -0,0 +1,6 @@ +package net.momirealms.customfishing.api.mechanic.fishing.hook; + +public class LavaFishingMechanic { + + +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java new file mode 100644 index 00000000..c322eebb --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java @@ -0,0 +1,31 @@ +package net.momirealms.customfishing.api.mechanic.fishing.hook; + +import net.momirealms.customfishing.api.mechanic.effect.Effect; + +public class VanillaMechanic implements HookMechanic { + + @Override + public boolean canStart() { + return false; + } + + @Override + public void preStart() { + + } + + @Override + public void start(Effect finalEffect) { + + } + + @Override + public boolean isHooked() { + return false; + } + + @Override + public void destroy() { + + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VoidFishingMechanic.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VoidFishingMechanic.java new file mode 100644 index 00000000..2547b996 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VoidFishingMechanic.java @@ -0,0 +1,49 @@ +package net.momirealms.customfishing.api.mechanic.fishing.hook; + +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.context.ContextKeys; +import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.effect.EffectProperties; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.Player; + +public class VoidFishingMechanic implements HookMechanic { + + private final FishHook hook; + private final Effect gearsEffect; + private final Context context; + + public VoidFishingMechanic(FishHook hook, Effect gearsEffect, Context context) { + this.hook = hook; + this.gearsEffect = gearsEffect; + this.context = context; + } + + @Override + public boolean canStart() { + if (!(boolean) gearsEffect.properties().getOrDefault(EffectProperties.VOID_FISHING, false)) { + return false; + } + return hook.getLocation().getY() <= hook.getWorld().getMinHeight(); + } + + @Override + public void preStart() { + this.context.arg(ContextKeys.SURROUNDING, EffectProperties.VOID_FISHING.key()); + } + + @Override + public void start(Effect finalEffect) { + + } + + @Override + public boolean isHooked() { + return false; + } + + @Override + public void destroy() { + + } +} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java index 38f5f8c5..fc1dfafb 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java @@ -30,6 +30,7 @@ import net.momirealms.customfishing.common.helper.AdventureHelper; import net.momirealms.customfishing.common.util.ListUtils; import net.momirealms.customfishing.common.util.Pair; import net.momirealms.customfishing.common.util.RandomUtils; +import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.Axis; import org.bukkit.Color; import org.bukkit.Particle; @@ -215,101 +216,137 @@ public class BukkitConfigManager extends ConfigManager { }, "requirements"); this.registerEffectModifierParser(object -> { Section section = (Section) object; - ArrayList>> consumers = new ArrayList<>(); + ArrayList, Integer>> property = new ArrayList<>(); for (Map.Entry entry : section.getStringRouteMappedValues(false).entrySet()) { if (entry.getValue() instanceof Section innerSection) { - consumers.add(parseEffect(innerSection)); + property.add(parseEffect(innerSection)); } } - return builder -> builder.modifiers(consumers); + return builder -> { + builder.modifiers(property); + }; }, "effects"); } - private BiConsumer> parseEffect(Section section) { + private TriConsumer, Integer> parseEffect(Section section) { switch (section.getString("type")) { + case "lava-fishing" -> { + return (((effect, context, phase) -> { + if (phase == 0) effect.properties().put(EffectProperties.LAVA_FISHING, true); + })); + } + case "void-fishing" -> { + return (((effect, context, phase) -> { + if (phase == 0) effect.properties().put(EffectProperties.VOID_FISHING, true); + })); + } case "weight-mod" -> { var op = parseWeightOperation(section.getStringList("value")); - return (((effect, context) -> effect.weightOperations(op))); + return (((effect, context, phase) -> { + if (phase == 1) effect.weightOperations(op); + })); } case "weight-mod-ignore-conditions" -> { var op = parseWeightOperation(section.getStringList("value")); - return (((effect, context) -> effect.weightOperationsIgnored(op))); + return (((effect, context, phase) -> { + if (phase == 1) effect.weightOperationsIgnored(op); + })); } case "group-mod" -> { var op = parseGroupWeightOperation(section.getStringList("value")); - return (((effect, context) -> effect.weightOperations(op))); + return (((effect, context, phase) -> { + if (phase == 1) effect.weightOperations(op); + })); } case "group-mod-ignore-conditions" -> { var op = parseGroupWeightOperation(section.getStringList("value")); - return (((effect, context) -> effect.weightOperationsIgnored(op))); + return (((effect, context, phase) -> { + if (phase == 1) effect.weightOperationsIgnored(op); + })); } case "wait-time" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.waitTimeAdder(effect.waitTimeAdder() + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.waitTimeAdder(effect.waitTimeAdder() + value.evaluate(context)); + })); } case "hook-time", "wait-time-multiplier" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.waitTimeMultiplier(effect.waitTimeMultiplier() - 1 + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.waitTimeMultiplier(effect.waitTimeMultiplier() - 1 + value.evaluate(context)); + })); } case "difficulty" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.difficultyAdder(effect.difficultyAdder() + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.difficultyAdder(effect.difficultyAdder() + value.evaluate(context)); + })); } case "difficulty-multiplier", "difficulty-bonus" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.difficultyMultiplier(effect.difficultyMultiplier() - 1 + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.difficultyMultiplier(effect.difficultyMultiplier() - 1 + value.evaluate(context)); + })); } case "size" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.sizeAdder(effect.sizeAdder() + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.sizeAdder(effect.sizeAdder() + value.evaluate(context)); + })); } case "size-multiplier", "size-bonus" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.sizeMultiplier(effect.sizeMultiplier() - 1 + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.sizeMultiplier(effect.sizeMultiplier() - 1 + value.evaluate(context)); + })); } case "game-time" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.gameTimeAdder(effect.gameTimeAdder() + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.gameTimeAdder(effect.gameTimeAdder() + value.evaluate(context)); + })); } case "game-time-multiplier", "game-time-bonus" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.gameTimeMultiplier(effect.gameTimeMultiplier() - 1 + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.gameTimeMultiplier(effect.gameTimeMultiplier() - 1 + value.evaluate(context)); + })); } case "score" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.scoreAdder(effect.scoreAdder() + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.scoreAdder(effect.scoreAdder() + value.evaluate(context)); + })); } case "score-multiplier", "score-bonus" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.scoreMultiplier(effect.scoreMultiplier() - 1 + value.evaluate(context)))); + return (((effect, context, phase) -> { + if (phase == 2) effect.scoreMultiplier(effect.scoreMultiplier() - 1 + value.evaluate(context)); + })); } case "multiple-loot" -> { MathValue value = MathValue.auto(section.get("value")); - return (((effect, context) -> effect.multipleLootChance(effect.multipleLootChance() + value.evaluate(context)))); - } - case "lava-fishing" -> { - return (((effect, context) -> effect.properties().put(EffectProperties.LAVA_FISHING, true))); - } - case "void-fishing" -> { - return (((effect, context) -> effect.properties().put(EffectProperties.VOID_FISHING, true))); + return (((effect, context, phase) -> { + if (phase == 2) effect.multipleLootChance(effect.multipleLootChance() + value.evaluate(context)); + })); } case "conditional" -> { Requirement[] requirements = plugin.getRequirementManager().parseRequirements(section.getSection("conditions"), true); Section effectSection = section.getSection("effects"); - ArrayList>> effects = new ArrayList<>(); + ArrayList, Integer>> effects = new ArrayList<>(); if (effectSection != null) for (Map.Entry entry : effectSection.getStringRouteMappedValues(false).entrySet()) if (entry.getValue() instanceof Section inner) effects.add(parseEffect(inner)); - return (((effect, context) -> { + return (((effect, context, phase) -> { if (!RequirementManager.isSatisfied(context, requirements)) return; - for (BiConsumer> consumer : effects) { - consumer.accept(effect, context); + for (TriConsumer, Integer> consumer : effects) { + consumer.accept(effect, context, phase); } })); } default -> { - return (((effect, context) -> {})); + return (((effect, context, phase) -> {})); } } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java index 3202cbad..eecc7882 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java @@ -4,8 +4,9 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.event.RodCastEvent; import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.effect.Effect; import net.momirealms.customfishing.api.mechanic.fishing.FishingGears; -import net.momirealms.customfishing.api.mechanic.fishing.FishingHookTimerTask; +import net.momirealms.customfishing.api.mechanic.fishing.CustomFishingHook; import net.momirealms.customfishing.api.mechanic.fishing.FishingManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import org.bukkit.Bukkit; @@ -27,7 +28,7 @@ public class BukkitFishingManager implements FishingManager, Listener { private BukkitCustomFishingPlugin plugin; private final ConcurrentHashMap castHooks = new ConcurrentHashMap<>(); private final ConcurrentHashMap gears = new ConcurrentHashMap<>(); - private final ConcurrentHashMap tasks = new ConcurrentHashMap<>(); + private final ConcurrentHashMap tasks = new ConcurrentHashMap<>(); public BukkitFishingManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; @@ -124,6 +125,9 @@ public class BukkitFishingManager implements FishingManager, Listener { return; } + Effect effect = Effect.newInstance(); + + RodCastEvent rodCastEvent = new RodCastEvent(event, gears); Bukkit.getPluginManager().callEvent(rodCastEvent); if (rodCastEvent.isCancelled()) { @@ -141,7 +145,7 @@ public class BukkitFishingManager implements FishingManager, Listener { this.castHooks.remove(uuid); }); this.gears.remove(uuid); - FishingHookTimerTask task = this.tasks.remove(uuid); + CustomFishingHook task = this.tasks.remove(uuid); if (task != null) { task.cancel(); }