9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00

2.2.26 draft

This commit is contained in:
XiaoMoMi
2024-09-09 19:23:53 +08:00
parent e392ddf726
commit cac5a10752
12 changed files with 238 additions and 116 deletions

View File

@@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
public class CompetitionEvent extends Event { public class CompetitionEvent extends Event {
private static final HandlerList handlerList = new HandlerList(); private static final HandlerList handlerList = new HandlerList();
private final State state; private final State state;
private final FishingCompetition competition; private final FishingCompetition competition;

View File

@@ -28,6 +28,7 @@ import org.jetbrains.annotations.NotNull;
public class CustomFishingReloadEvent extends Event { public class CustomFishingReloadEvent extends Event {
private static final HandlerList handlerList = new HandlerList(); private static final HandlerList handlerList = new HandlerList();
private final BukkitCustomFishingPlugin plugin; private final BukkitCustomFishingPlugin plugin;
/** /**
@@ -39,6 +40,15 @@ public class CustomFishingReloadEvent extends Event {
this.plugin = plugin; 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() { public static HandlerList getHandlerList() {
return handlerList; return handlerList;
} }
@@ -48,13 +58,4 @@ public class CustomFishingReloadEvent extends Event {
public HandlerList getHandlers() { public HandlerList getHandlers() {
return getHandlerList(); 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;
}
} }

View File

@@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull;
public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellable { public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlerList = new HandlerList(); private static final HandlerList handlerList = new HandlerList();
private final ItemStack itemStack; private final ItemStack itemStack;
private boolean isCancelled; private boolean isCancelled;
private final Inventory bag; private final Inventory bag;
@@ -69,15 +70,6 @@ public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellabl
return itemStack; return itemStack;
} }
@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
public static HandlerList getHandlerList() {
return handlerList;
}
/** /**
* Gets the {@link Inventory} of the fishing bag. * Gets the {@link Inventory} of the fishing bag.
* *
@@ -87,4 +79,13 @@ public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellabl
public Inventory getBagInventory() { public Inventory getBagInventory() {
return bag; return bag;
} }
@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
public static HandlerList getHandlerList() {
return handlerList;
}
} }

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* 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 <https://www.gnu.org/licenses/>.
*/
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.
* <p>
* {@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
* <p>
* 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}
* <p>
* 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.
* <p>
* 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
}
}

View File

@@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull;
public class FishingHookStateEvent extends PlayerEvent { public class FishingHookStateEvent extends PlayerEvent {
private static final HandlerList handlerList = new HandlerList(); private static final HandlerList handlerList = new HandlerList();
private final FishHook fishHook; private final FishHook fishHook;
private final State state; private final State state;
@@ -46,10 +47,6 @@ public class FishingHookStateEvent extends PlayerEvent {
this.state = state; this.state = state;
} }
public static HandlerList getHandlerList() {
return handlerList;
}
/** /**
* Gets the {@link FishHook} involved in this event. * Gets the {@link FishHook} involved in this event.
* *
@@ -74,6 +71,10 @@ public class FishingHookStateEvent extends PlayerEvent {
return getHandlerList(); return getHandlerList();
} }
public static HandlerList getHandlerList() {
return handlerList;
}
public enum State { public enum State {
BITE, BITE,
ESCAPE, ESCAPE,

View File

@@ -57,16 +57,6 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable {
this.fishHook = fishHook; this.fishHook = fishHook;
} }
public static HandlerList getHandlerList() {
return handlerList;
}
@NotNull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return isCancelled; return isCancelled;
@@ -133,6 +123,16 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable {
return Optional.ofNullable(context.arg(ContextKeys.AMOUNT)).orElse(1); 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 { public enum Result {
SUCCESS, SUCCESS,
FAILURE FAILURE

View File

@@ -62,16 +62,6 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
this.isCancelled = cancel; this.isCancelled = cancel;
} }
public static HandlerList getHandlerList() {
return handlerList;
}
@NotNull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
/** /**
* Get the {@link FishingGears} * Get the {@link FishingGears}
* *
@@ -89,4 +79,14 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
public PlayerFishEvent getBukkitPlayerFishEvent() { public PlayerFishEvent getBukkitPlayerFishEvent() {
return event; return event;
} }
public static HandlerList getHandlerList() {
return handlerList;
}
@NotNull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
} }

View File

@@ -84,4 +84,12 @@ public class EffectProperties<T> {
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(this.key); return Objects.hashCode(this.key);
} }
@Override
public String toString() {
return "EffectProperties{" +
"key='" + key + '\'' +
", type=" + type.getSimpleName() +
'}';
}
} }

View File

@@ -18,6 +18,7 @@
package net.momirealms.customfishing.api.mechanic.fishing; package net.momirealms.customfishing.api.mechanic.fishing;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; 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.FishingLootSpawnEvent;
import net.momirealms.customfishing.api.event.FishingResultEvent; import net.momirealms.customfishing.api.event.FishingResultEvent;
import net.momirealms.customfishing.api.mechanic.MechanicType; import net.momirealms.customfishing.api.mechanic.MechanicType;
@@ -129,6 +130,10 @@ public class CustomFishingHook {
consumer.accept(effect, context, 0); consumer.accept(effect, context, 0);
} }
} }
// trigger event
EventUtils.fireAndForget(new FishingEffectApplyEvent(this, effect, FishingEffectApplyEvent.Stage.CAST));
List<HookMechanic> enabledMechanics = mechanicProviders.apply(hook, context, effect); List<HookMechanic> enabledMechanics = mechanicProviders.apply(hook, context, effect);
this.task = plugin.getScheduler().sync().runRepeating(() -> { this.task = plugin.getScheduler().sync().runRepeating(() -> {
// destroy if hook is invalid // 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_LOCATION, hook.getLocation());
context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX()); context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX());
context.arg(ContextKeys.OTHER_Y, hook.getLocation().getBlockY()); context.arg(ContextKeys.OTHER_Y, hook.getLocation().getBlockY());
@@ -199,6 +207,10 @@ public class CustomFishingHook {
consumer.accept(tempEffect, context, 2); consumer.accept(tempEffect, context, 2);
} }
} }
// trigger event
EventUtils.fireAndForget(new FishingEffectApplyEvent(this, tempEffect, FishingEffectApplyEvent.Stage.FISHING));
// start the mechanic // start the mechanic
mechanic.start(tempEffect); mechanic.start(tempEffect);
@@ -290,7 +302,7 @@ public class CustomFishingHook {
*/ */
public void cancelCurrentGame() { public void cancelCurrentGame() {
if (gamingPlayer == null || !gamingPlayer.isValid()) { 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.cancel();
gamingPlayer = null; gamingPlayer = null;
@@ -303,7 +315,7 @@ public class CustomFishingHook {
* Starts a game. * Starts a game.
*/ */
public void gameStart() { public void gameStart() {
if (isPlayingGame()) if (isPlayingGame() || !hook.isValid())
return; return;
Game nextGame = plugin.getGameManager().getNextGame(tempFinalEffect, context); Game nextGame = plugin.getGameManager().getNextGame(tempFinalEffect, context);
if (nextGame != null) { if (nextGame != null) {
@@ -347,7 +359,7 @@ public class CustomFishingHook {
* Handles the reel-in action. * Handles the reel-in action.
*/ */
public void onReelIn() { public void onReelIn() {
if (isPlayingGame()) return; if (isPlayingGame() || !hook.isValid()) return;
if (hookMechanic != null) { if (hookMechanic != null) {
if (!hookMechanic.isHooked()) { if (!hookMechanic.isHooked()) {
gears.trigger(ActionTrigger.REEL, context); gears.trigger(ActionTrigger.REEL, context);
@@ -373,7 +385,7 @@ public class CustomFishingHook {
* Handles the bite action. * Handles the bite action.
*/ */
public void onBite() { public void onBite() {
if (isPlayingGame()) return; if (isPlayingGame() || !hook.isValid()) return;
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.BITE); plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.BITE);
gears.trigger(ActionTrigger.BITE, context); gears.trigger(ActionTrigger.BITE, context);
if (RequirementManager.isSatisfied(context, ConfigManager.autoFishingRequirements())) { if (RequirementManager.isSatisfied(context, ConfigManager.autoFishingRequirements())) {
@@ -392,6 +404,7 @@ public class CustomFishingHook {
* Handles the landing action. * Handles the landing action.
*/ */
public void onLand() { public void onLand() {
if (!hook.isValid()) return;
gears.trigger(ActionTrigger.LAND, context); gears.trigger(ActionTrigger.LAND, context);
} }
@@ -399,16 +412,16 @@ public class CustomFishingHook {
* Handles the escape action. * Handles the escape action.
*/ */
public void onEscape() { public void onEscape() {
if (!isPlayingGame()) { if (isPlayingGame() || !hook.isValid()) return;
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.ESCAPE); plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.ESCAPE);
gears.trigger(ActionTrigger.ESCAPE, context); gears.trigger(ActionTrigger.ESCAPE, context);
}
} }
/** /**
* Handles the lure action. * Handles the lure action.
*/ */
public void onLure() { public void onLure() {
if (isPlayingGame() || !hook.isValid()) return;
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.LURE); plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.LURE);
gears.trigger(ActionTrigger.LURE, context); gears.trigger(ActionTrigger.LURE, context);
} }

View File

@@ -593,7 +593,7 @@ public class BukkitConfigManager extends ConfigManager {
}, "effects"); }, "effects");
} }
private TriConsumer<Effect, Context<Player>, Integer> parseEffect(Section section) { public TriConsumer<Effect, Context<Player>, Integer> parseEffect(Section section) {
if (!section.contains("type")) { if (!section.contains("type")) {
throw new RuntimeException(section.getRouteAsString()); throw new RuntimeException(section.getRouteAsString());
} }

View File

@@ -287,70 +287,70 @@ mechanics:
source: 'player' source: 'player'
volume: 1 volume: 1
pitch: 1 pitch: 1
# Sell icon for individual transactions # Sell icon for individual transactions
sell-icons: sell-icons:
symbol: 'B' symbol: 'B'
allow-icon: allow-icon:
material: IRON_BLOCK material: IRON_BLOCK
display: display:
name: '<#00CED1><b>● <!b>Sell the fish' name: '<#00CED1><b>● <!b>Sell the fish'
lore: lore:
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will earn <green>{money_formatted} coins</green> from the fish</gradient></font>' - '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will earn <green>{money_formatted} coins</green> from the fish</gradient></font>'
action: action:
sound_action: sound_action:
type: sound type: sound
value: value:
key: 'minecraft:block.amethyst_block.place' key: 'minecraft:block.amethyst_block.place'
source: 'player' source: 'player'
volume: 1 volume: 1
pitch: 1 pitch: 1
message_action: message_action:
type: message type: message
value: 'You earned {money_formatted} coins from the fish! You can still earn {rest_formatted} more coins from the market today.' value: 'You earned {money_formatted} coins from the fish! You can still earn {rest_formatted} more coins from the market today.'
money_action: money_action:
type: give-money type: give-money
value: '{money}' value: '{money}'
# Uncomment the command_action if needed # Uncomment the command_action if needed
# command_action: # command_action:
# type: command # type: command
# value: 'money give {player} {money}' # value: 'money give {player} {money}'
deny-icon: deny-icon:
material: REDSTONE_BLOCK material: REDSTONE_BLOCK
display: display:
name: '<red><b>● <!b>Trade Denied' name: '<red><b>● <!b>Trade Denied'
lore: lore:
- '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>No items available to sell!</gradient></font>' - '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>No items available to sell!</gradient></font>'
action: action:
sound_action: sound_action:
type: sound type: sound
value: value:
key: 'minecraft:entity.villager.no' key: 'minecraft:entity.villager.no'
source: 'player' source: 'player'
volume: 1 volume: 1
pitch: 1 pitch: 1
limit-icon: limit-icon:
material: REDSTONE_BLOCK material: REDSTONE_BLOCK
display: display:
name: '<red><b>● <!b>Trade Denied' name: '<red><b>● <!b>Trade Denied'
lore: lore:
- '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>The total value exceeds the daily limit for earnings!</gradient></font>' - '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>The total value exceeds the daily limit for earnings!</gradient></font>'
action: action:
sound_action: sound_action:
type: sound type: sound
value: value:
key: 'minecraft:block.anvil.land' key: 'minecraft:block.anvil.land'
source: 'player' source: 'player'
volume: 1 volume: 1
pitch: 1 pitch: 1
# Decorative icons for visual enhancement # Decorative icons for visual enhancement
decorative-icons: decorative-icons:
glass-pane: glass-pane:
symbol: 'A' symbol: 'A'
material: BLACK_STAINED_GLASS_PANE material: BLACK_STAINED_GLASS_PANE
display: display:
name: ' ' name: ' '
components: components:
minecraft:hide_tooltip: {} minecraft:hide_tooltip: {}
# This section is only effective if "override-vanilla" is set to true # This section is only effective if "override-vanilla" is set to true
# Meaning vanilla mechanics, such as lure enchantment, will no longer apply # Meaning vanilla mechanics, such as lure enchantment, will no longer apply
# You must configure their effects in CustomFishing instead # You must configure their effects in CustomFishing instead

View File

@@ -1,6 +1,6 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=2.2.25 project_version=2.2.26
config_version=36 config_version=36
project_group=net.momirealms project_group=net.momirealms