From cac5a10752ed2bd2af5dea72906a2145b5a3dd6c Mon Sep 17 00:00:00 2001 From: XiaoMoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:23:53 +0800 Subject: [PATCH] 2.2.26 draft --- .../api/event/CompetitionEvent.java | 1 + .../api/event/CustomFishingReloadEvent.java | 19 +-- .../api/event/FishingBagPreCollectEvent.java | 19 +-- .../api/event/FishingEffectApplyEvent.java | 97 +++++++++++++ .../api/event/FishingHookStateEvent.java | 9 +- .../api/event/FishingResultEvent.java | 20 +-- .../customfishing/api/event/RodCastEvent.java | 20 +-- .../api/mechanic/effect/EffectProperties.java | 8 ++ .../mechanic/fishing/CustomFishingHook.java | 29 ++-- .../bukkit/config/BukkitConfigManager.java | 2 +- core/src/main/resources/config.yml | 128 +++++++++--------- gradle.properties | 2 +- 12 files changed, 238 insertions(+), 116 deletions(-) create mode 100644 api/src/main/java/net/momirealms/customfishing/api/event/FishingEffectApplyEvent.java diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java index 6a88af27..45f8993f 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java @@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull; public class CompetitionEvent extends Event { private static final HandlerList handlerList = new HandlerList(); + private final State state; private final FishingCompetition competition; diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java index 72b9082f..3d2a5ad4 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.NotNull; public class CustomFishingReloadEvent extends Event { private static final HandlerList handlerList = new HandlerList(); + private final BukkitCustomFishingPlugin plugin; /** @@ -39,6 +40,15 @@ public class CustomFishingReloadEvent extends Event { this.plugin = plugin; } + /** + * Gets the instance of the {@link BukkitCustomFishingPlugin} that is being reloaded. + * + * @return The instance of the Custom Fishing plugin + */ + public BukkitCustomFishingPlugin getPluginInstance() { + return plugin; + } + public static HandlerList getHandlerList() { return handlerList; } @@ -48,13 +58,4 @@ public class CustomFishingReloadEvent extends Event { public HandlerList getHandlers() { return getHandlerList(); } - - /** - * Gets the instance of the {@link BukkitCustomFishingPlugin} that is being reloaded. - * - * @return The instance of the Custom Fishing plugin - */ - public BukkitCustomFishingPlugin getPluginInstance() { - return plugin; - } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java index 05374f7a..432c515f 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull; public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlerList = new HandlerList(); + private final ItemStack itemStack; private boolean isCancelled; private final Inventory bag; @@ -69,15 +70,6 @@ public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellabl return itemStack; } - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } - - public static HandlerList getHandlerList() { - return handlerList; - } - /** * Gets the {@link Inventory} of the fishing bag. * @@ -87,4 +79,13 @@ public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellabl public Inventory getBagInventory() { return bag; } + + @Override + public @NotNull HandlerList getHandlers() { + return handlerList; + } + + public static HandlerList getHandlerList() { + return handlerList; + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingEffectApplyEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingEffectApplyEvent.java new file mode 100644 index 00000000..0e7571f3 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishingEffectApplyEvent.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.api.event; + +import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.fishing.CustomFishingHook; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * This class provides + */ +public class FishingEffectApplyEvent extends Event { + + private static final HandlerList handlerList = new HandlerList(); + + private final Stage stage; + private final Effect effect; + private final CustomFishingHook hook; + + public FishingEffectApplyEvent(CustomFishingHook hook, Effect effect, Stage stage) { + this.hook = hook; + this.effect = effect; + this.stage = stage; + } + + /** + * Get the current stage. + *

+ * {@link Stage#CAST}: The effect at this stage determines whether the player can perform a certain mechanism for instance lava fishing. + * {@link Stage#LOOT}: The effect at this stage play a crucial role in what loot will appear next, and weighted effects should be applied at this stage. + * {@link Stage#FISHING}: The effects at this stage affect the hook time, game difficulty and other fishing-related attributes + *

+ * For developers, {@link Stage#CAST} will only be triggered once, while the other two stages will be triggered multiple times + * + * @return the stage + */ + public Stage getStage() { + return stage; + } + + /** + * Get the {@link Effect} + *

+ * Effects at stage {@link Stage#CAST} are constant because this stage only affects what mechanics the player can play. + * Effects at stage {@link Stage#LOOT}/{@link Stage#FISHING} are temporary because the fishhook could move. For example, it flows from the water into the lava or another biome, + * causing some conditional effects changing. + *

+ * For developers, {@link Stage#CAST} will only be triggered once, while the other two stages will be triggered multiple times + * + * @return the effect + */ + public Effect getEffect() { + return effect; + } + + /** + * Get the Custom Fishing hook + * + * @return the fishing hook + */ + public CustomFishingHook getHook() { + return hook; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public static HandlerList getHandlerList() { + return handlerList; + } + + public enum Stage { + CAST, + LOOT, + FISHING + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingHookStateEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingHookStateEvent.java index abcba26a..7e46e0ef 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingHookStateEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishingHookStateEvent.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull; public class FishingHookStateEvent extends PlayerEvent { private static final HandlerList handlerList = new HandlerList(); + private final FishHook fishHook; private final State state; @@ -46,10 +47,6 @@ public class FishingHookStateEvent extends PlayerEvent { this.state = state; } - public static HandlerList getHandlerList() { - return handlerList; - } - /** * Gets the {@link FishHook} involved in this event. * @@ -74,6 +71,10 @@ public class FishingHookStateEvent extends PlayerEvent { return getHandlerList(); } + public static HandlerList getHandlerList() { + return handlerList; + } + public enum State { BITE, ESCAPE, diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java index 112f8c71..86a5714a 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java @@ -57,16 +57,6 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable { this.fishHook = fishHook; } - public static HandlerList getHandlerList() { - return handlerList; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - @Override public boolean isCancelled() { return isCancelled; @@ -133,6 +123,16 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable { return Optional.ofNullable(context.arg(ContextKeys.AMOUNT)).orElse(1); } + public static HandlerList getHandlerList() { + return handlerList; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + public enum Result { SUCCESS, FAILURE diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java index ff44a8f8..84fbcfc4 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java @@ -62,16 +62,6 @@ public class RodCastEvent extends PlayerEvent implements Cancellable { this.isCancelled = cancel; } - public static HandlerList getHandlerList() { - return handlerList; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - /** * Get the {@link FishingGears} * @@ -89,4 +79,14 @@ public class RodCastEvent extends PlayerEvent implements Cancellable { public PlayerFishEvent getBukkitPlayerFishEvent() { return event; } + + public static HandlerList getHandlerList() { + return handlerList; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java index ec5aa8f8..abeb7803 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java @@ -84,4 +84,12 @@ public class EffectProperties { public final int hashCode() { return Objects.hashCode(this.key); } + + @Override + public String toString() { + return "EffectProperties{" + + "key='" + key + '\'' + + ", type=" + type.getSimpleName() + + '}'; + } } 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 index b401c714..9c5f170a 100644 --- 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 @@ -18,6 +18,7 @@ package net.momirealms.customfishing.api.mechanic.fishing; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.event.FishingEffectApplyEvent; import net.momirealms.customfishing.api.event.FishingLootSpawnEvent; import net.momirealms.customfishing.api.event.FishingResultEvent; import net.momirealms.customfishing.api.mechanic.MechanicType; @@ -129,6 +130,10 @@ public class CustomFishingHook { consumer.accept(effect, context, 0); } } + + // trigger event + EventUtils.fireAndForget(new FishingEffectApplyEvent(this, effect, FishingEffectApplyEvent.Stage.CAST)); + List enabledMechanics = mechanicProviders.apply(hook, context, effect); this.task = plugin.getScheduler().sync().runRepeating(() -> { // destroy if hook is invalid @@ -168,6 +173,9 @@ public class CustomFishingHook { } } + // trigger event + EventUtils.fireAndForget(new FishingEffectApplyEvent(this, tempEffect, FishingEffectApplyEvent.Stage.LOOT)); + context.arg(ContextKeys.OTHER_LOCATION, hook.getLocation()); context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX()); context.arg(ContextKeys.OTHER_Y, hook.getLocation().getBlockY()); @@ -199,6 +207,10 @@ public class CustomFishingHook { consumer.accept(tempEffect, context, 2); } } + + // trigger event + EventUtils.fireAndForget(new FishingEffectApplyEvent(this, tempEffect, FishingEffectApplyEvent.Stage.FISHING)); + // start the mechanic mechanic.start(tempEffect); @@ -290,7 +302,7 @@ public class CustomFishingHook { */ public void cancelCurrentGame() { if (gamingPlayer == null || !gamingPlayer.isValid()) { - throw new RuntimeException("You can't call this method if the player is not playing the game"); + return; } gamingPlayer.cancel(); gamingPlayer = null; @@ -303,7 +315,7 @@ public class CustomFishingHook { * Starts a game. */ public void gameStart() { - if (isPlayingGame()) + if (isPlayingGame() || !hook.isValid()) return; Game nextGame = plugin.getGameManager().getNextGame(tempFinalEffect, context); if (nextGame != null) { @@ -347,7 +359,7 @@ public class CustomFishingHook { * Handles the reel-in action. */ public void onReelIn() { - if (isPlayingGame()) return; + if (isPlayingGame() || !hook.isValid()) return; if (hookMechanic != null) { if (!hookMechanic.isHooked()) { gears.trigger(ActionTrigger.REEL, context); @@ -373,7 +385,7 @@ public class CustomFishingHook { * Handles the bite action. */ public void onBite() { - if (isPlayingGame()) return; + if (isPlayingGame() || !hook.isValid()) return; plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.BITE); gears.trigger(ActionTrigger.BITE, context); if (RequirementManager.isSatisfied(context, ConfigManager.autoFishingRequirements())) { @@ -392,6 +404,7 @@ public class CustomFishingHook { * Handles the landing action. */ public void onLand() { + if (!hook.isValid()) return; gears.trigger(ActionTrigger.LAND, context); } @@ -399,16 +412,16 @@ public class CustomFishingHook { * Handles the escape action. */ public void onEscape() { - if (!isPlayingGame()) { - plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.ESCAPE); - gears.trigger(ActionTrigger.ESCAPE, context); - } + if (isPlayingGame() || !hook.isValid()) return; + plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.ESCAPE); + gears.trigger(ActionTrigger.ESCAPE, context); } /** * Handles the lure action. */ public void onLure() { + if (isPlayingGame() || !hook.isValid()) return; plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.LURE); gears.trigger(ActionTrigger.LURE, context); } 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 94b2b7de..4ab42a34 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 @@ -593,7 +593,7 @@ public class BukkitConfigManager extends ConfigManager { }, "effects"); } - private TriConsumer, Integer> parseEffect(Section section) { + public TriConsumer, Integer> parseEffect(Section section) { if (!section.contains("type")) { throw new RuntimeException(section.getRouteAsString()); } diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index f4b23a0f..7d7442a0 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -287,70 +287,70 @@ mechanics: source: 'player' volume: 1 pitch: 1 - # Sell icon for individual transactions - sell-icons: - symbol: 'B' - allow-icon: - material: IRON_BLOCK - display: - name: '<#00CED1>Sell the fish' - lore: - - 'You will earn {money_formatted} coins from the fish' - action: - sound_action: - type: sound - value: - key: 'minecraft:block.amethyst_block.place' - source: 'player' - volume: 1 - pitch: 1 - message_action: - type: message - value: 'You earned {money_formatted} coins from the fish! You can still earn {rest_formatted} more coins from the market today.' - money_action: - type: give-money - value: '{money}' - # Uncomment the command_action if needed - # command_action: - # type: command - # value: 'money give {player} {money}' - deny-icon: - material: REDSTONE_BLOCK - display: - name: 'Trade Denied' - lore: - - 'No items available to sell!' - action: - sound_action: - type: sound - value: - key: 'minecraft:entity.villager.no' - source: 'player' - volume: 1 - pitch: 1 - limit-icon: - material: REDSTONE_BLOCK - display: - name: 'Trade Denied' - lore: - - 'The total value exceeds the daily limit for earnings!' - action: - sound_action: - type: sound - value: - key: 'minecraft:block.anvil.land' - source: 'player' - volume: 1 - pitch: 1 - # Decorative icons for visual enhancement - decorative-icons: - glass-pane: - symbol: 'A' - material: BLACK_STAINED_GLASS_PANE - display: - name: ' ' - components: - minecraft:hide_tooltip: {} + # Sell icon for individual transactions + sell-icons: + symbol: 'B' + allow-icon: + material: IRON_BLOCK + display: + name: '<#00CED1>Sell the fish' + lore: + - 'You will earn {money_formatted} coins from the fish' + action: + sound_action: + type: sound + value: + key: 'minecraft:block.amethyst_block.place' + source: 'player' + volume: 1 + pitch: 1 + message_action: + type: message + value: 'You earned {money_formatted} coins from the fish! You can still earn {rest_formatted} more coins from the market today.' + money_action: + type: give-money + value: '{money}' + # Uncomment the command_action if needed + # command_action: + # type: command + # value: 'money give {player} {money}' + deny-icon: + material: REDSTONE_BLOCK + display: + name: 'Trade Denied' + lore: + - 'No items available to sell!' + action: + sound_action: + type: sound + value: + key: 'minecraft:entity.villager.no' + source: 'player' + volume: 1 + pitch: 1 + limit-icon: + material: REDSTONE_BLOCK + display: + name: 'Trade Denied' + lore: + - 'The total value exceeds the daily limit for earnings!' + action: + sound_action: + type: sound + value: + key: 'minecraft:block.anvil.land' + source: 'player' + volume: 1 + pitch: 1 + # Decorative icons for visual enhancement + decorative-icons: + glass-pane: + symbol: 'A' + material: BLACK_STAINED_GLASS_PANE + display: + name: ' ' + components: + minecraft:hide_tooltip: {} # This section is only effective if "override-vanilla" is set to true # Meaning vanilla mechanics, such as lure enchantment, will no longer apply # You must configure their effects in CustomFishing instead diff --git a/gradle.properties b/gradle.properties index 91fc6aef..b0b7977c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=2.2.25 +project_version=2.2.26 config_version=36 project_group=net.momirealms