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

I don't want to waste time on resolving conflicts

This commit is contained in:
XiaoMoMi
2024-07-10 03:24:56 +08:00
parent 0ed5d5745a
commit 80594731e6
551 changed files with 29876 additions and 31172 deletions

View File

@@ -9,7 +9,7 @@
<img src="https://img.shields.io/badge/docs-gitbook-brightgreen" alt="Gitbook"/>
</a>
CustomFishing is a Paper plugin that provides minigames and a powerful condition & action library for fishing.
CustomFishing is a Paper plugin that provides minigames and a powerful condition & action system for fishing.
With the new concept of weight system, CustomFishing brings unlimited customization possibilities and best performance.
## How to build

View File

@@ -1,11 +1,48 @@
plugins {
id("io.github.goooler.shadow") version "8.1.7"
}
repositories {
maven("https://jitpack.io/") // rtag
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // papi
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
compileOnly("de.tr7zw:item-nbt-api:2.12.4")
implementation(project(":common"))
implementation("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}")
implementation("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}") {
exclude(module = "adventure-bom")
exclude(module = "checker-qual")
exclude(module = "annotations")
}
implementation("com.saicone.rtag:rtag:${rootProject.properties["rtag_version"]}")
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
compileOnly("dev.folia:folia-api:${rootProject.properties["paper_version"]}-R0.1-SNAPSHOT")
compileOnly("com.google.code.gson:gson:${rootProject.properties["gson_version"]}")
compileOnly("me.clip:placeholderapi:${rootProject.properties["placeholder_api_version"]}")
compileOnly("com.github.Xiao-MoMi:Sparrow-Heart:${rootProject.properties["sparrow_heart_version"]}")
// compileOnly(files("libs/Sparrow-Heart-${rootProject.properties["sparrow_heart_version"]}.jar"))
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(17)
dependsOn(tasks.clean)
}
tasks {
shadowJar {
relocate ("de.tr7zw.changeme", "net.momirealms.customfishing.libraries")
relocate("net.kyori", "net.momirealms.customfishing.libraries")
relocate("dev.dejvokep", "net.momirealms.customfishing.libraries")
relocate ("com.saicone.rtag", "net.momirealms.customfishing.libraries.rtag")
}
}

View File

@@ -0,0 +1,215 @@
/*
* Copyright (C) <2022> <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;
import net.momirealms.customfishing.api.integration.IntegrationManager;
import net.momirealms.customfishing.api.mechanic.action.ActionManager;
import net.momirealms.customfishing.api.mechanic.bag.BagManager;
import net.momirealms.customfishing.api.mechanic.block.BlockManager;
import net.momirealms.customfishing.api.mechanic.competition.CompetitionManager;
import net.momirealms.customfishing.api.mechanic.config.ConfigManager;
import net.momirealms.customfishing.api.mechanic.effect.EffectManager;
import net.momirealms.customfishing.api.mechanic.entity.EntityManager;
import net.momirealms.customfishing.api.mechanic.event.EventManager;
import net.momirealms.customfishing.api.mechanic.fishing.FishingManager;
import net.momirealms.customfishing.api.mechanic.game.GameManager;
import net.momirealms.customfishing.api.mechanic.hook.HookManager;
import net.momirealms.customfishing.api.mechanic.item.ItemManager;
import net.momirealms.customfishing.api.mechanic.loot.LootManager;
import net.momirealms.customfishing.api.mechanic.market.MarketManager;
import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager;
import net.momirealms.customfishing.api.mechanic.misc.placeholder.PlaceholderManager;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager;
import net.momirealms.customfishing.api.mechanic.totem.TotemManager;
import net.momirealms.customfishing.api.storage.StorageManager;
import net.momirealms.customfishing.common.dependency.DependencyManager;
import net.momirealms.customfishing.common.locale.TranslationManager;
import net.momirealms.customfishing.common.plugin.CustomFishingPlugin;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import net.momirealms.customfishing.common.plugin.scheduler.AbstractJavaScheduler;
import net.momirealms.customfishing.common.sender.SenderFactory;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.io.File;
public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin, Reloadable {
private static BukkitCustomFishingPlugin instance;
private final Plugin boostrap;
protected EventManager eventManager;
protected ConfigManager configManager;
protected RequirementManager<Player> requirementManager;
protected ActionManager<Player> actionManager;
protected SenderFactory<BukkitCustomFishingPlugin, CommandSender> senderFactory;
protected PlaceholderManager placeholderManager;
protected AbstractJavaScheduler<Location> scheduler;
protected ItemManager itemManager;
protected IntegrationManager integrationManager;
protected CompetitionManager competitionManager;
protected MarketManager marketManager;
protected StorageManager storageManager;
protected LootManager lootManager;
protected CoolDownManager coolDownManager;
protected EntityManager entityManager;
protected BlockManager blockManager;
protected StatisticsManager statisticsManager;
protected EffectManager effectManager;
protected HookManager hookManager;
protected BagManager bagManager;
protected DependencyManager dependencyManager;
protected TranslationManager translationManager;
protected TotemManager totemManager;
protected FishingManager fishingManager;
protected GameManager gameManager;
public BukkitCustomFishingPlugin(Plugin boostrap) {
if (!boostrap.getName().equals("CustomFishing")) {
throw new IllegalArgumentException("CustomFishing plugin requires custom fishing plugin");
}
this.boostrap = boostrap;
instance = this;
}
public static BukkitCustomFishingPlugin getInstance() {
if (instance == null) {
throw new IllegalArgumentException("Plugin not initialized");
}
return instance;
}
public EventManager getEventManager() {
return eventManager;
}
@Override
public ConfigManager getConfigManager() {
return configManager;
}
public RequirementManager<Player> getRequirementManager() {
return requirementManager;
}
public ActionManager<Player> getActionManager() {
return actionManager;
}
public SenderFactory<BukkitCustomFishingPlugin, CommandSender> getSenderFactory() {
return senderFactory;
}
public File getDataFolder() {
return boostrap.getDataFolder();
}
public PlaceholderManager getPlaceholderManager() {
return placeholderManager;
}
public ItemManager getItemManager() {
return itemManager;
}
public IntegrationManager getIntegrationManager() {
return integrationManager;
}
@Override
public AbstractJavaScheduler<Location> getScheduler() {
return scheduler;
}
public CompetitionManager getCompetitionManager() {
return competitionManager;
}
public MarketManager getMarketManager() {
return marketManager;
}
public StorageManager getStorageManager() {
return storageManager;
}
public LootManager getLootManager() {
return lootManager;
}
public EntityManager getEntityManager() {
return entityManager;
}
public HookManager getHookManager() {
return hookManager;
}
public BlockManager getBlockManager() {
return blockManager;
}
public CoolDownManager getCoolDownManager() {
return coolDownManager;
}
public StatisticsManager getStatisticsManager() {
return statisticsManager;
}
public EffectManager getEffectManager() {
return effectManager;
}
public BagManager getBagManager() {
return bagManager;
}
public TotemManager getTotemManager() {
return totemManager;
}
public FishingManager getFishingManager() {
return fishingManager;
}
public GameManager getGameManager() {
return gameManager;
}
public Plugin getBoostrap() {
return boostrap;
}
@Override
public DependencyManager getDependencyManager() {
return dependencyManager;
}
@Override
public TranslationManager getTranslationManager() {
return translationManager;
}
public abstract void enable();
public abstract void debug(Object message);
}

View File

@@ -1,162 +0,0 @@
/*
* Copyright (C) <2022> <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;
import net.momirealms.customfishing.api.manager.*;
import net.momirealms.customfishing.api.scheduler.Scheduler;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class CustomFishingPlugin extends JavaPlugin {
protected boolean initialized;
protected Scheduler scheduler;
protected CommandManager commandManager;
protected VersionManager versionManager;
protected ItemManager itemManager;
protected RequirementManager requirementManager;
protected ActionManager actionManager;
protected LootManager lootManager;
protected FishingManager fishingManager;
protected EffectManager effectManager;
protected EntityManager entityManager;
protected BlockManager blockManager;
protected AdventureManager adventure;
protected BagManager bagManager;
protected GameManager gameManager;
protected MarketManager marketManager;
protected IntegrationManager integrationManager;
protected CompetitionManager competitionManager;
protected StorageManager storageManager;
protected PlaceholderManager placeholderManager;
protected StatisticsManager statisticsManager;
protected TotemManager totemManager;
protected HookManager hookManager;
private static CustomFishingPlugin instance;
public CustomFishingPlugin() {
instance = this;
}
public static CustomFishingPlugin get() {
return getInstance();
}
@NotNull
public static CustomFishingPlugin getInstance() {
return instance;
}
public Scheduler getScheduler() {
return scheduler;
}
public CommandManager getCommandManager() {
return commandManager;
}
public VersionManager getVersionManager() {
return versionManager;
}
public RequirementManager getRequirementManager() {
return requirementManager;
}
public ActionManager getActionManager() {
return actionManager;
}
public GameManager getGameManager() {
return gameManager;
}
public BlockManager getBlockManager() {
return blockManager;
}
public EntityManager getEntityManager() {
return entityManager;
}
public ItemManager getItemManager() {
return itemManager;
}
public EffectManager getEffectManager() {
return effectManager;
}
public MarketManager getMarketManager() {
return marketManager;
}
public FishingManager getFishingManager() {
return fishingManager;
}
public AdventureManager getAdventure() {
return adventure;
}
public BagManager getBagManager() {
return bagManager;
}
public LootManager getLootManager() {
return lootManager;
}
public StorageManager getStorageManager() {
return storageManager;
}
public TotemManager getTotemManager() {
return totemManager;
}
public HookManager getHookManager() {
return hookManager;
}
public IntegrationManager getIntegrationManager() {
return integrationManager;
}
public StatisticsManager getStatisticsManager() {
return statisticsManager;
}
public PlaceholderManager getPlaceholderManager() {
return placeholderManager;
}
public CompetitionManager getCompetitionManager() {
return competitionManager;
}
public abstract void reload();
public abstract YamlConfiguration getConfig(String file);
public abstract boolean isHookedPluginEnabled(String plugin);
public abstract void debug(String message);
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) <2022> <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.common;
public class Tuple<L, M, R> {
private L left;
private M mid;
private R right;
public Tuple(L left, M mid, R right) {
this.left = left;
this.mid = mid;
this.right = right;
}
public static <L, M, R> Tuple<L, M, R> of(final L left, final M mid, final R right) {
return new Tuple<>(left, mid, right);
}
public L getLeft() {
return left;
}
public void setLeft(L left) {
this.left = left;
}
public M getMid() {
return mid;
}
public void setMid(M mid) {
this.mid = mid;
}
public R getRight() {
return right;
}
public void setRight(R right) {
this.right = right;
}
}

View File

@@ -1,99 +0,0 @@
/*
* Copyright (C) <2022> <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.data;
import net.momirealms.customfishing.api.data.user.OfflineUser;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface DataStorageInterface {
/**
* Initialize the data resource
*/
void initialize();
/**
* Close the data resource
*/
void disable();
/**
* Get the storage data source type
*
* @return {@link StorageType}
*/
StorageType getStorageType();
/**
* Retrieve a player's data
*
* @param uuid The UUID of the player.
* @param lock Whether to lock the player data during retrieval.
* @return A CompletableFuture containing the optional player data.
*/
CompletableFuture<Optional<PlayerData>> getPlayerData(UUID uuid, boolean lock);
/**
* Update a player's data
*
* @param uuid The UUID of the player.
* @param playerData The player data to update.
* @param unlock Whether to unlock the player data after updating.
* @return A CompletableFuture indicating the success of the update.
*/
CompletableFuture<Boolean> updatePlayerData(UUID uuid, PlayerData playerData, boolean unlock);
/**
* Update or insert a player's data into the SQL database.
*
* @param uuid The UUID of the player.
* @param playerData The player data to update or insert.
* @param unlock Whether to unlock the player data after updating or inserting.
* @return A CompletableFuture indicating the success of the operation.
*/
CompletableFuture<Boolean> updateOrInsertPlayerData(UUID uuid, PlayerData playerData, boolean unlock);
/**
* Update data for multiple players
*
* @param users A collection of OfflineUser objects representing players.
* @param unlock Whether to unlock the player data after updating.
*/
void updateManyPlayersData(Collection<? extends OfflineUser> users, boolean unlock);
/**
* Lock or unlock a player's data in the SQL database.
*
* @param uuid The UUID of the player.
* @param lock Whether to lock or unlock the player data.
*/
void lockOrUnlockPlayerData(UUID uuid, boolean lock);
/**
* Get a set of unique user UUIDs
*
* @param legacy Whether to include legacy data in the retrieval.
* @return A set of unique user UUIDs.
*/
Set<UUID> getUniqueUsers(boolean legacy);
}

View File

@@ -1,106 +0,0 @@
/*
* Copyright (C) <2022> <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.data;
import com.google.gson.annotations.SerializedName;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PlayerData {
@SerializedName("name")
protected String name;
@SerializedName("stats")
protected StatisticData statisticsData;
@SerializedName("bag")
protected InventoryData bagData;
@SerializedName("trade")
protected EarningData earningData;
public static PlayerData LOCKED = empty();
public static Builder builder() {
return new Builder();
}
public static PlayerData empty() {
return new Builder()
.setBagData(InventoryData.empty())
.setEarningData(EarningData.empty())
.setStats(StatisticData.empty())
.build();
}
public static class Builder {
private final PlayerData playerData;
public Builder() {
this.playerData = new PlayerData();
}
@NotNull
public Builder setName(@Nullable String name) {
this.playerData.name = name;
return this;
}
@NotNull
public Builder setStats(@Nullable StatisticData statisticsData) {
this.playerData.statisticsData = statisticsData;
return this;
}
@NotNull
public Builder setBagData(@Nullable InventoryData inventoryData) {
this.playerData.bagData = inventoryData;
return this;
}
@NotNull
public Builder setEarningData(@Nullable EarningData earningData) {
this.playerData.earningData = earningData;
return this;
}
@NotNull
public PlayerData build() {
return this.playerData;
}
}
public StatisticData getStatistics() {
return statisticsData;
}
public InventoryData getBagData() {
return bagData;
}
public EarningData getEarningData() {
return earningData;
}
public String getName() {
return name;
}
public boolean isLocked() {
return this == LOCKED;
}
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright (C) <2022> <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.data.user;
import net.momirealms.customfishing.api.data.EarningData;
import net.momirealms.customfishing.api.data.PlayerData;
import net.momirealms.customfishing.api.mechanic.bag.FishingBagHolder;
import net.momirealms.customfishing.api.mechanic.statistic.Statistics;
import java.util.UUID;
public interface OfflineUser {
/**
* Get the username
*
* @return user name
*/
String getName();
/**
* Get the user's uuid
*
* @return uuid
*/
UUID getUUID();
/**
* Get the fishing bag holder
*
* @return fishing bag holder
*/
FishingBagHolder getHolder();
/**
* Get the player's earning data
*
* @return earning data
*/
EarningData getEarningData();
/**
* Get the player's statistics
*
* @return statistics
*/
Statistics getStatistics();
/**
* If the user is online on current server
*
* @return online or not
*/
boolean isOnline();
/**
* Get the data in another minimized format that can be saved
*
* @return player data
*/
PlayerData getPlayerData();
}

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -25,9 +25,9 @@ import org.jetbrains.annotations.NotNull;
public class CustomFishingReloadEvent extends Event {
private static final HandlerList handlerList = new HandlerList();
private final CustomFishingPlugin plugin;
private final BukkitCustomFishingPlugin plugin;
public CustomFishingReloadEvent(CustomFishingPlugin plugin) {
public CustomFishingReloadEvent(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
}
@@ -41,7 +41,7 @@ public class CustomFishingReloadEvent extends Event {
return getHandlerList();
}
public CustomFishingPlugin getPluginInstance() {
public BukkitCustomFishingPlugin getPluginInstance() {
return plugin;
}
}

View File

@@ -1,105 +0,0 @@
/*
* Copyright (C) <2022> <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 org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
/**
* This class represents an event that occurs when a fishing hook lands in either lava or water.
*/
public class FishHookLandEvent extends PlayerEvent {
private static final HandlerList handlerList = new HandlerList();
private final Target target;
private final FishHook fishHook;
private final Effect effect;
private boolean isFirst;
/**
* Constructs a new FishHookLandEvent.
*
* @param who The player who triggered the event.
* @param target The target where the fishing hook has landed (LAVA or WATER).
* @param hook The fishing hook entity.
* @param initialEffect The initial effect
*/
public FishHookLandEvent(@NotNull Player who, Target target, FishHook hook, boolean isFirst, Effect initialEffect) {
super(who);
this.target = target;
this.fishHook = hook;
this.effect = initialEffect;
this.isFirst = isFirst;
}
/**
* Gets the target where the fishing hook has landed.
*
* @return The target, which can be either LAVA or WATER.
*/
public Target getTarget() {
return target;
}
/**
* Gets the fish hook bukkit entity
*
* @return fish hook
*/
public FishHook getFishHook() {
return fishHook;
}
public static HandlerList getHandlerList() {
return handlerList;
}
/**
* Is the first try of one fishing catch
*
* @return is first try
*/
public boolean isFirst() {
return isFirst;
}
/**
* Get the fishing effect
* It's not advised to modify this value without checking "isFirst()" since this event can be trigger multiple times in one fishing catch
*
* @return fishing effect
*/
public Effect getEffect() {
return effect;
}
@NotNull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
public enum Target {
LAVA,
WATER
}
}

View File

@@ -17,52 +17,46 @@
package net.momirealms.customfishing.api.event;
import org.bukkit.Location;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class FishingLootPreSpawnEvent extends PlayerEvent implements Cancellable {
public class FishingHookStateEvent extends PlayerEvent {
private static final HandlerList handlerList = new HandlerList();
private final Location location;
private final ItemStack itemStack;
private boolean isCancelled;
private final FishHook fishHook;
private final State state;
public FishingLootPreSpawnEvent(@NotNull Player who, Location location, ItemStack itemStack) {
public FishingHookStateEvent(@NotNull Player who, FishHook hook, State state) {
super(who);
this.itemStack = itemStack;
this.location = location;
this.isCancelled = false;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancel) {
isCancelled = cancel;
}
public Location getLocation() {
return location;
}
public ItemStack getItemStack() {
return itemStack;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
this.fishHook = hook;
this.state = state;
}
public static HandlerList getHandlerList() {
return handlerList;
}
public FishHook getFishHook() {
return fishHook;
}
public State getState() {
return state;
}
@NotNull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
public enum State {
BITE,
ESCAPE,
LURE,
LAND
}
}

View File

@@ -17,44 +17,73 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.Location;
import org.bukkit.entity.Item;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable {
public class FishingLootSpawnEvent extends PlayerEvent {
private static final HandlerList handlerList = new HandlerList();
private final Location location;
private final Item item;
private boolean isCancelled;
private final Entity entity;
private final Loot loot;
private final Context<Player> context;
private boolean skipActions;
private boolean summonEntity;
public FishingLootSpawnEvent(@NotNull Player who, Location location, Item item) {
super(who);
this.item = item;
public FishingLootSpawnEvent(@NotNull Context<Player> context, Location location, Loot loot, @Nullable Entity entity) {
super(context.getHolder());
this.entity = entity;
this.loot = loot;
this.location = location;
this.isCancelled = false;
this.skipActions = false;
this.summonEntity = true;
this.context = context;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancel) {
isCancelled = cancel;
public Context<Player> getContext() {
return context;
}
public Location getLocation() {
return location;
}
public Item getItem() {
return item;
/**
* Get the loot entity
*
* @return entity
*/
@Nullable
public Entity getEntity() {
return entity;
}
@NotNull
public Loot getLoot() {
return loot;
}
public boolean summonEntity() {
return summonEntity;
}
public void summonEntity(boolean summonEntity) {
this.summonEntity = summonEntity;
}
public boolean skipActions() {
return skipActions;
}
public void skipActions(boolean skipActions) {
this.skipActions = skipActions;
}
@Override

View File

@@ -17,6 +17,8 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
@@ -24,14 +26,9 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Optional;
/**
* This class represents an event that occurs when a player gets a result from fishing.
*/
public class FishingResultEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlerList = new HandlerList();
@@ -39,21 +36,12 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable {
private final Result result;
private final Loot loot;
private final FishHook fishHook;
private final Map<String, String> args;
private Context<Player> context;
/**
* Constructs a new FishingResultEvent.
*
* @param who The player who triggered the event.
* @param result The result of the fishing action (SUCCESS or FAILURE).
* @param loot The loot received from fishing.
* @param args A map of placeholders and their corresponding values.
*/
public FishingResultEvent(@NotNull Player who, Result result, FishHook fishHook, Loot loot, Map<String, String> args) {
super(who);
public FishingResultEvent(@NotNull Context<Player> context, Result result, FishHook fishHook, Loot loot) {
super(context.getHolder());
this.result = result;
this.loot = loot;
this.args = args;
this.fishHook = fishHook;
}
@@ -77,87 +65,31 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable {
isCancelled = cancel;
}
/**
* Gets the value associated with a specific argument key.
* Usage example event.getArg("{x}")
*
* @param key The argument key enclosed in curly braces, e.g., "{amount}".
* @return The value associated with the argument key, or null if not found.
*/
public String getArg(String key) {
return args.get(key);
}
/**
* Set the value associated with a specific argument key.
* @param key key
* @param value value
* @return previous value
*/
@Nullable
public String setArg(String key, String value) {
return args.put(key, value);
}
/**
* Gets the result of the fishing action.
*
* @return The fishing result, which can be either SUCCESS or FAILURE.
*/
public Result getResult() {
return result;
}
/**
* Get the fish hook entity.
*
* @return fish hook
*/
public FishHook getFishHook() {
return fishHook;
}
/**
* Gets the loot received from fishing.
*
* @return The loot obtained from the fishing action.
*/
public Loot getLoot() {
return loot;
}
/**
* Gets the amount of loot received.
* This value is determined by the "multiple-loot" effect.
* If you want to get the amount of item spawned, listen to FishingLootSpawnEvent
*
* @return The amount of loot received, or 1 if the loot is block or entity
*/
public int getAmount() {
return Integer.parseInt(Optional.ofNullable(getArg("{amount}")).orElse("1"));
}
/**
* Set the loot amount (Only works for items)
*
* @param amount amount
*/
public void setAmount(int amount) {
setArg("{amount}", String.valueOf(amount));
}
/**
* Set the score to get in competition
*
* @param score score
*/
public void setScore(double score) {
setArg("{SCORE}", String.valueOf(score));
context.arg(ContextKeys.CUSTOM_SCORE, score);
}
public Context<Player> getContext() {
return context;
}
public int getAmount() {
if (result == Result.FAILURE) return 0;
return Optional.ofNullable(context.arg(ContextKeys.AMOUNT)).orElse(1);
}
/**
* An enumeration representing possible fishing results (SUCCESS or FAILURE).
*/
public enum Result {
SUCCESS,
FAILURE

View File

@@ -1,97 +0,0 @@
/*
* Copyright (C) <2022> <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 org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
/**
* This class represents an event that occurs when a player fishes in lava.
*/
public class LavaFishingEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlerList = new HandlerList();
private final State state;
private boolean isCancelled;
private final FishHook hook;
/**
* Constructs a new LavaFishingEvent.
*
* @param who The player who triggered the event.
* @param state The state of the fishing action (REEL_IN, CAUGHT_FISH, or BITE).
* @param hook The FishHook entity associated with the fishing action.
*/
public LavaFishingEvent(@NotNull Player who, State state, FishHook hook) {
super(who);
this.state = state;
this.isCancelled = false;
this.hook = hook;
}
/**
* Gets the state of the fishing action.
*
* @return The fishing state, which can be REEL_IN, CAUGHT_FISH, or BITE.
*/
public State getState() {
return state;
}
/**
* Gets the FishHook entity associated with the fishing action.
*
* @return The FishHook entity used in the fishing action.
*/
public FishHook getHook() {
return hook;
}
public static HandlerList getHandlerList() {
return handlerList;
}
@NotNull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancel) {
isCancelled = cancel;
}
/**
* An enumeration representing possible states of the fishing action (REEL_IN, CAUGHT_FISH, BITE).
*/
public enum State {
REEL_IN,
CAUGHT_FISH,
BITE
}
}

View File

@@ -17,8 +17,7 @@
package net.momirealms.customfishing.api.event;
import net.momirealms.customfishing.api.mechanic.condition.FishingPreparation;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.fishing.FishingGears;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
@@ -30,24 +29,15 @@ import org.jetbrains.annotations.NotNull;
*/
public class RodCastEvent extends PlayerEvent implements Cancellable {
private final Effect effect;
private final FishingGears gears;
private boolean isCancelled;
private final PlayerFishEvent event;
private final FishingPreparation preparation;
private static final HandlerList handlerList = new HandlerList();
/**
* Constructs a new RodCastEvent.
*
* @param event The original PlayerFishEvent that triggered the rod cast.
* @param fishingPreparation The fishing preparation associated with the rod cast.
* @param effect The effect associated with the fishing rod cast.
*/
public RodCastEvent(PlayerFishEvent event, FishingPreparation fishingPreparation, Effect effect) {
public RodCastEvent(PlayerFishEvent event, FishingGears gears) {
super(event.getPlayer());
this.effect = effect;
this.gears = gears;
this.event = event;
this.preparation = fishingPreparation;
}
@Override
@@ -56,9 +46,10 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
}
/**
* Cancelling this event would not cancel the bukkit PlayerFishEvent
* Cancelling this event would disable CustomFishing mechanics
* If you want to prevent players from casting, use {@link #getBukkitPlayerFishEvent()} instead
*
* @param cancel true if you wish to cancel this event
* @param cancel true if you want to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
@@ -69,15 +60,6 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
return handlerList;
}
/**
* Gets the fishing preparation associated with the rod cast.
*
* @return The FishingPreparation associated with the rod cast.
*/
public FishingPreparation getPreparation() {
return preparation;
}
@NotNull
@Override
public HandlerList getHandlers() {
@@ -85,16 +67,16 @@ public class RodCastEvent extends PlayerEvent implements Cancellable {
}
/**
* Gets the effect associated with the fishing rod cast.
* Get the {@link FishingGears}
*
* @return The Effect associated with the rod cast.
* @return fishing gears
*/
public Effect getEffect() {
return effect;
public FishingGears getGears() {
return gears;
}
/**
* Gets the original PlayerFishEvent that triggered the rod cast.
* Gets the original PlayerFishEvent that triggered the {@link RodCastEvent}.
*
* @return The original PlayerFishEvent.
*/

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) <2022> <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.integration;
import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Interface for providing custom block data and retrieving block IDs within the CustomFishing plugin.
* Extends the ExternalProvider interface.
*/
public interface BlockProvider extends ExternalProvider {
/**
* Generates BlockData for a given player based on a block ID and a list of modifiers.
*
* @param context The player for whom the block data is generated.
* @param id The unique identifier for the block.
* @param modifiers A list of {@link BlockDataModifier} objects to apply to the block data.
* @return The generated {@link BlockData} for the specified block ID and modifiers.
*/
BlockData blockData(@NotNull Context<Player> context, @NotNull String id, List<BlockDataModifier> modifiers);
/**
* Retrieves the unique block ID associated with a given block.
*
* @param block The block for which the ID is to be retrieved.
* @return The unique block ID as a string, or null if no ID is associated with the block.
*/
@Nullable
String blockID(@NotNull Block block);
}

View File

@@ -17,19 +17,19 @@
package net.momirealms.customfishing.api.integration;
import net.momirealms.customfishing.common.util.Pair;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface EnchantmentInterface {
public interface EnchantmentProvider extends ExternalProvider {
/**
* Get a list of enchantments with level for itemStack
* format: plugin:enchantment:level
* example: minecraft:sharpness:5
*
* @param itemStack itemStack
* @return enchantment list
*/
List<String> getEnchants(ItemStack itemStack);
List<Pair<String, Short>> getEnchants(@NotNull ItemStack itemStack);
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) <2022> <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.integration;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
public interface EntityProvider extends ExternalProvider {
/**
* Spawns an entity at the specified location with the given properties.
*
* @param location The location where the entity will be spawned.
* @param id The identifier of the entity to be spawned.
* @param propertyMap A map containing additional properties for the entity.
* @return The spawned entity.
*/
@NotNull
Entity spawn(@NotNull Location location, @NotNull String id, @NotNull Map<String, Object> propertyMap);
default Entity spawn(@NotNull Location location, @NotNull String id) {
return spawn(location, id, new HashMap<>());
}
}

View File

@@ -15,16 +15,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.data.user;
package net.momirealms.customfishing.api.integration;
import org.bukkit.entity.Player;
public interface OnlineUser extends OfflineUser {
public interface ExternalProvider {
/**
* Get the bukkit player
* Gets the identification of the external provider.
*
* @return player
* @return The identification string of the external provider.
*/
Player getPlayer();
String identifier();
}

View File

@@ -0,0 +1,121 @@
/*
* Copyright (C) <2022> <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.integration;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import net.momirealms.customfishing.common.util.Pair;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Interface for managing integration providers in the custom fishing API.
* This allows for the registration and retrieval of various types of providers
* such as Leveler, Enchantment, and Season providers.
*/
public interface IntegrationManager extends Reloadable {
/**
* Registers a LevelerProvider.
*
* @param levelerProvider the LevelerProvider to register
* @return true if registration is successful, false otherwise
*/
boolean registerLevelerProvider(@NotNull LevelerProvider levelerProvider);
/**
* Unregisters a LevelerProvider by its ID.
*
* @param id the ID of the LevelerProvider to unregister
* @return true if unregistration is successful, false otherwise
*/
boolean unregisterLevelerProvider(@NotNull String id);
/**
* Registers an EnchantmentProvider.
*
* @param enchantmentProvider the EnchantmentProvider to register
* @return true if registration is successful, false otherwise
*/
boolean registerEnchantmentProvider(@NotNull EnchantmentProvider enchantmentProvider);
/**
* Unregisters an EnchantmentProvider by its ID.
*
* @param id the ID of the EnchantmentProvider to unregister
* @return true if unregistration is successful, false otherwise
*/
boolean unregisterEnchantmentProvider(@NotNull String id);
/**
* Registers a SeasonProvider.
*
* @param seasonProvider the SeasonProvider to register
* @return true if registration is successful, false otherwise
*/
boolean registerSeasonProvider(@NotNull SeasonProvider seasonProvider);
/**
* Unregisters the SeasonProvider.
*
* @return true if unregistration is successful, false otherwise
*/
boolean unregisterSeasonProvider();
boolean registerEntityProvider(@NotNull EntityProvider entityProvider);
boolean unregisterEntityProvider(@NotNull String id);
/**
* Retrieves a registered LevelerProvider by its ID.
*
* @param id the ID of the LevelerProvider to retrieve
* @return the LevelerProvider if found, or null if not found
*/
@Nullable
LevelerProvider getLevelerProvider(String id);
/**
* Retrieves a registered EnchantmentProvider by its ID.
*
* @param id the ID of the EnchantmentProvider to retrieve
* @return the EnchantmentProvider if found, or null if not found
*/
@Nullable
EnchantmentProvider getEnchantmentProvider(String id);
/**
* Retrieves a registered SeasonProvider by its ID.
*
* @return the SeasonProvider if found, or null if not found
*/
@Nullable
SeasonProvider getSeasonProvider();
List<Pair<String, Short>> getEnchantments(ItemStack itemStack);
boolean registerItemProvider(@NotNull ItemProvider itemProvider);
boolean unregisterItemProvider(@NotNull String id);
boolean registerBlockProvider(@NotNull BlockProvider block);
boolean unregisterBlockProvider(@NotNull String id);
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) <2022> <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.integration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Interface representing a provider for custom items in the Custom Fishing plugin.
* This interface allows for building items for players and retrieving item IDs from item stacks.
*/
public interface ItemProvider extends ExternalProvider {
/**
* Builds an ItemStack for a player based on a specified item ID.
*
* @param player the player for whom the item is being built.
* @param id the ID of the item to build.
* @return the built ItemStack.
*/
@NotNull
ItemStack buildItem(@NotNull Player player, @NotNull String id);
/**
* Retrieves the item ID from a given ItemStack.
*
* @param itemStack the ItemStack from which to retrieve the item ID.
* @return the item ID as a string, or null if the item stack does not have an associated ID.
*/
@Nullable
String itemID(@NotNull ItemStack itemStack);
}

View File

@@ -18,8 +18,9 @@
package net.momirealms.customfishing.api.integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public interface LevelInterface {
public interface LevelerProvider extends ExternalProvider {
/**
* Add exp to a certain skill or job
@@ -28,7 +29,7 @@ public interface LevelInterface {
* @param target the skill or job, for instance "Fishing" "fisherman"
* @param amount the exp amount
*/
void addXp(Player player, String target, double amount);
void addXp(@NotNull Player player, @NotNull String target, double amount);
/**
* Get a player's skill or job's level
@@ -37,5 +38,5 @@ public interface LevelInterface {
* @param target the skill or job, for instance "Fishing" "fisherman"
* @return level
*/
int getLevel(Player player, String target);
int getLevel(@NotNull Player player, @NotNull String target);
}

View File

@@ -17,10 +17,11 @@
package net.momirealms.customfishing.api.integration;
import net.momirealms.customfishing.api.mechanic.misc.season.Season;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
public interface SeasonInterface {
public interface SeasonProvider extends ExternalProvider {
/**
* Get a world's season
@@ -28,5 +29,6 @@ public interface SeasonInterface {
* @param world world
* @return spring, summer, autumn, winter or disabled
*/
@NotNull String getSeason(World world);
@NotNull
Season getSeason(@NotNull World world);
}

View File

@@ -1,128 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionFactory;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import org.bukkit.configuration.ConfigurationSection;
import java.util.HashMap;
public interface ActionManager {
/**
* Registers an ActionFactory for a specific action type.
* This method allows you to associate an ActionFactory with a custom action type.
*
* @param type The custom action type to register.
* @param actionFactory The ActionFactory responsible for creating actions of the specified type.
* @return True if the registration was successful (the action type was not already registered), false otherwise.
*/
boolean registerAction(String type, ActionFactory actionFactory);
/**
* Unregisters an ActionFactory for a specific action type.
* This method allows you to remove the association between an action type and its ActionFactory.
*
* @param type The custom action type to unregister.
* @return True if the action type was successfully unregistered, false if it was not found.
*/
boolean unregisterAction(String type);
/**
* Retrieves an Action object based on the configuration provided in a ConfigurationSection.
* This method reads the type of action from the section, obtains the corresponding ActionFactory,
* and builds an Action object using the specified values and chance.
* <p>
* events:
* success:
* action_1: <- section
* ...
*
* @param section The ConfigurationSection containing the action configuration.
* @return An Action object created based on the configuration, or an EmptyAction instance if the action type is invalid.
*/
Action getAction(ConfigurationSection section);
/**
* Retrieves a mapping of ActionTriggers to arrays of Actions from a ConfigurationSection.
* This method iterates through the provided ConfigurationSection to extract action triggers
* and their associated arrays of Actions.
* <p>
* events: <- section
* success:
* action_1:
* ...
*
* @param section The ConfigurationSection containing action mappings.
* @return A HashMap where keys are ActionTriggers and values are arrays of Action objects.
*/
HashMap<ActionTrigger, Action[]> getActionMap(ConfigurationSection section);
/**
* Retrieves an array of Action objects from a ConfigurationSection.
* This method iterates through the provided ConfigurationSection to extract Action configurations
* and build an array of Action objects.
* <p>
* events:
* success: <- section
* action_1:
* ...
*
* @param section The ConfigurationSection containing action configurations.
* @return An array of Action objects created based on the configurations in the section.
*/
Action[] getActions(ConfigurationSection section);
/**
* Retrieves an ActionFactory associated with a specific action type.
*
* @param type The action type for which to retrieve the ActionFactory.
* @return The ActionFactory associated with the specified action type, or null if not found.
*/
ActionFactory getActionFactory(String type);
/**
* Retrieves a mapping of success times to corresponding arrays of actions from a ConfigurationSection.
* <p>
* events:
* success-times: <- section
* 1:
* action_1:
* ...
*
* @param section The ConfigurationSection containing success times actions.
* @return A HashMap where success times associated with actions.
*/
HashMap<Integer, Action[]> getTimesActionMap(ConfigurationSection section);
/**
* Triggers a list of actions with the given condition.
* If the list of actions is not null, each action in the list is triggered.
*
* @param actions The list of actions to trigger.
* @param condition The condition associated with the actions.
*/
static void triggerActions(Condition condition, Action... actions) {
if (actions != null)
for (Action action : actions)
action.trigger(condition);
}
}

View File

@@ -1,139 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public interface AdventureManager {
/**
* Get component from text
* @param text text
* @return component
*/
Component getComponentFromMiniMessage(String text);
/**
* Send a message to a command sender
* @param sender sender
* @param msg message
*/
void sendMessage(CommandSender sender, String msg);
/**
* Send a message with prefix
*
* @param sender command sender
* @param s message
*/
void sendMessageWithPrefix(CommandSender sender, String s);
/**
* Send a message to console
* @param msg message
*/
void sendConsoleMessage(String msg);
/**
* Send a message to a player
* @param player player
* @param msg message
*/
void sendPlayerMessage(Player player, String msg);
/**
* Send a title to a player
* @param player player
* @param title title
* @param subtitle subtitle
* @param in in (ms)
* @param duration duration (ms)
* @param out out (ms)
*/
void sendTitle(Player player, String title, String subtitle, int in, int duration, int out);
/**
* Send a title to a player
* @param player player
* @param title title
* @param subtitle subtitle
* @param in in (ms)
* @param duration duration (ms)
* @param out out (ms)
*/
void sendTitle(Player player, Component title, Component subtitle, int in, int duration, int out);
/**
* Send actionbar
* @param player player
* @param msg msg
*/
void sendActionbar(Player player, String msg);
/**
* Play a sound to a player
* @param player player
* @param source sound source
* @param key sound key
* @param volume volume
* @param pitch pitch
*/
void sendSound(Player player, Sound.Source source, Key key, float volume, float pitch);
void sendSound(Player player, Sound sound);
/**
* Replace legacy color codes to MiniMessage format
* @param legacy legacy text
* @return MiniMessage format text
*/
String legacyToMiniMessage(String legacy);
/**
* if a char is legacy color code
* @param c char
* @return is legacy color
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
boolean isColorCode(char c);
/**
* Get legacy format text
* @param component component
* @return legacy format text
*/
String componentToLegacy(Component component);
/**
* Get json
* @param component component
* @return json
*/
String componentToJson(Component component);
/**
* Get paper component
* @param component shaded component
* @return paper component
*/
Object shadedComponentToOriginalComponent(Component component);
}

View File

@@ -1,104 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.data.user.OfflineUser;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import java.util.List;
import java.util.UUID;
public interface BagManager {
/**
* Is bag enabled
*
* @return enabled or not
*/
boolean isEnabled();
/**
* Retrieves the online bag inventory associated with a player's UUID.
*
* @param uuid The UUID of the player for whom the bag inventory is retrieved.
* @return The online bag inventory if the player is online, or null if not found.
*/
Inventory getOnlineBagInventory(UUID uuid);
/**
* Get the rows of a player's fishing bag
*
* @param player player who owns the bag
* @return rows
*/
int getBagInventoryRows(Player player);
/**
* Initiates the process of editing the bag inventory of an offline player by an admin.
*
* @param admin The admin player performing the edit.
* @param userData The OfflineUser data of the player whose bag is being edited.
*/
void editOfflinePlayerBag(Player admin, OfflineUser userData);
/**
* Get the actions to perform when loot is automatically collected
*
* @return actions
*/
Action[] getCollectLootActions();
/**
* Get the actions to perform when bag is full
*
* @return actions
*/
Action[] getBagFullActions();
/**
* If bag can store fishing loots
*
* @return can store or not
*/
boolean doesBagStoreLoots();
/**
* Get the fishing bag's title
*
* @return title
*/
String getBagTitle();
/**
* Get a list of allowed items in bag
*
* @return whitelisted items
*/
List<Material> getBagWhiteListItems();
/**
* Get the requirements for automatically collecting loots
*
* @return requirements
*/
Requirement[] getCollectRequirements();
}

View File

@@ -1,105 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.block.BlockDataModifierBuilder;
import net.momirealms.customfishing.api.mechanic.block.BlockLibrary;
import net.momirealms.customfishing.api.mechanic.block.BlockStateModifierBuilder;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public interface BlockManager {
/**
* Registers a BlockLibrary instance.
* This method associates a BlockLibrary with its unique identification and adds it to the registry.
*
* @param blockLibrary The BlockLibrary instance to register.
* @return True if the registration was successful (the identification is not already registered), false otherwise.
*/
boolean registerBlockLibrary(BlockLibrary blockLibrary);
/**
* Unregisters a BlockLibrary instance by its identification.
* This method removes a BlockLibrary from the registry based on its unique identification.
*
* @param identification The unique identification of the BlockLibrary to unregister.
* @return True if the BlockLibrary was successfully unregistered, false if it was not found.
*/
boolean unregisterBlockLibrary(String identification);
/**
* Registers a BlockDataModifierBuilder for a specific type.
* This method associates a BlockDataModifierBuilder with its type and adds it to the registry.
*
* @param type The type of the BlockDataModifierBuilder to register.
* @param builder The BlockDataModifierBuilder instance to register.
* @return True if the registration was successful (the type is not already registered), false otherwise.
*/
boolean registerBlockDataModifierBuilder(String type, BlockDataModifierBuilder builder);
/**
* Registers a BlockStateModifierBuilder for a specific type.
* This method associates a BlockStateModifierBuilder with its type and adds it to the registry.
*
* @param type The type of the BlockStateModifierBuilder to register.
* @param builder The BlockStateModifierBuilder instance to register.
* @return True if the registration was successful (the type is not already registered), false otherwise.
*/
boolean registerBlockStateModifierBuilder(String type, BlockStateModifierBuilder builder);
/**
* Unregisters a BlockDataModifierBuilder with the specified type.
*
* @param type The type of the BlockDataModifierBuilder to unregister.
* @return True if the BlockDataModifierBuilder was successfully unregistered, false otherwise.
*/
boolean unregisterBlockDataModifierBuilder(String type);
/**
* Unregisters a BlockStateModifierBuilder with the specified type.
*
* @param type The type of the BlockStateModifierBuilder to unregister.
* @return True if the BlockStateModifierBuilder was successfully unregistered, false otherwise.
*/
boolean unregisterBlockStateModifierBuilder(String type);
/**
* Summons a falling block at a specified location based on the provided loot.
* This method spawns a falling block at the given hookLocation with specific properties determined by the loot.
*
* @param player The player who triggered the action.
* @param hookLocation The location where the hook is positioned.
* @param playerLocation The location of the player.
* @param loot The loot to be associated with the summoned block.
*/
void summonBlock(Player player, Location hookLocation, Location playerLocation, Loot loot);
/**
* Retrieves the block ID associated with a given Block instance using block detection order.
* This method iterates through the configured block detection order to find the block's ID
* by checking different BlockLibrary instances in the specified order.
*
* @param block The Block instance for which to retrieve the block ID.
* @return The block ID
*/
@NotNull String getAnyPluginBlockID(Block block);
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfig;
import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal;
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
public interface CompetitionManager {
/**
* Retrieves a set of all competition names.
*
* @return A set of competition names.
*/
@NotNull Set<String> getAllCompetitionKeys();
/**
* Retrieves the localization key for a given competition goal.
*
* @param goal The competition goal to retrieve the localization key for.
* @return The localization key for the specified competition goal.
*/
@NotNull String getCompetitionGoalLocale(CompetitionGoal goal);
/**
* Starts a competition with the specified name, allowing for the option to force start it or apply it to the entire server.
*
* @param competition The name of the competition to start.
* @param force Whether to force start the competition even if amount of the online players is lower than the requirement
* @param serverGroup Whether to apply the competition to the servers that connected to Redis.
* @return {@code true} if the competition was started successfully, {@code false} otherwise.
*/
boolean startCompetition(String competition, boolean force, @Nullable String serverGroup);
/**
* Gets the ongoing fishing competition, if one is currently in progress.
*
* @return The ongoing fishing competition, or null if there is none.
*/
@Nullable FishingCompetition getOnGoingCompetition();
/**
* Starts a competition using the specified configuration.
*
* @param config The configuration of the competition to start.
* @param force Whether to force start the competition even if amount of the online players is lower than the requirement
* @param serverGroup Whether the competition should start across all servers that connected to Redis
* @return True if the competition was started successfully, false otherwise.
*/
boolean startCompetition(CompetitionConfig config, boolean force, @Nullable String serverGroup);
/**
* Gets the number of seconds until the next competition.
*
* @return The number of seconds until the next competition.
*/
int getNextCompetitionSeconds();
/**
* Retrieves the configuration for a competition based on its key.
*
* @param key The key of the competition configuration to retrieve.
* @return The {@link CompetitionConfig} for the specified key, or {@code null} if no configuration exists with that key.
*/
@Nullable CompetitionConfig getConfig(String key);
}

View File

@@ -1,115 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.common.Key;
import net.momirealms.customfishing.api.mechanic.effect.BaseEffect;
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.FishingEffect;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface EffectManager {
/**
* Registers an EffectCarrier with a unique Key.
*
* @param key The unique Key associated with the EffectCarrier.
* @param effect The EffectCarrier to be registered.
* @return True if the registration was successful, false if the Key already exists.
*/
boolean registerEffectCarrier(Key key, EffectCarrier effect);
/**
* Unregisters an EffectCarrier associated with the specified Key.
*
* @param key The unique Key of the EffectCarrier to unregister.
* @return True if the EffectCarrier was successfully unregistered, false if the Key does not exist.
*/
boolean unregisterEffectCarrier(Key key);
/**
* Checks if an EffectCarrier with the specified namespace and id exists.
*
* @param namespace The namespace of the EffectCarrier.
* @param id The unique identifier of the EffectCarrier.
* @return True if an EffectCarrier with the given namespace and id exists, false otherwise.
*/
boolean hasEffectCarrier(String namespace, String id);
/**
* Retrieves an EffectCarrier with the specified namespace and id.
*
* @param namespace The namespace of the EffectCarrier.
* @param id The unique identifier of the EffectCarrier.
* @return The EffectCarrier with the given namespace and id, or null if it doesn't exist.
*/
@Nullable EffectCarrier getEffectCarrier(String namespace, String id);
/**
* Parses a ConfigurationSection to create an EffectCarrier based on the specified key and configuration.
* <p>
* xxx_item: <- section
* effects:
* ...
* events:
* ...
*
* @param key The key that uniquely identifies the EffectCarrier.
* @param section The ConfigurationSection containing the EffectCarrier configuration.
* @return An EffectCarrier instance based on the key and configuration, or null if the section is null.
*/
EffectCarrier getEffectCarrierFromSection(Key key, ConfigurationSection section);
/**
* Retrieves the initial FishingEffect that represents no special effects.
*
* @return The initial FishingEffect.
*/
@NotNull FishingEffect getInitialEffect();
/**
* Parses a ConfigurationSection to retrieve an array of EffectModifiers.
* <p>
* effects: <- section
* effect_1:
* type: xxx
* value: xxx
*
* @param section The ConfigurationSection to parse.
* @return An array of EffectModifiers based on the values found in the section.
*/
@NotNull EffectModifier[] getEffectModifiers(ConfigurationSection section);
BaseEffect getBaseEffect(ConfigurationSection section);
/**
* Parses a ConfigurationSection to create an EffectModifier based on the specified type and configuration.
* <p>
* effects:
* effect_1: <- section
* type: xxx
* value: xxx
*
* @param section The ConfigurationSection containing the effect modifier configuration.
* @return An EffectModifier instance based on the type and configuration.
*/
@Nullable EffectModifier getEffectModifier(ConfigurationSection section);
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.entity.EntityLibrary;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.Location;
public interface EntityManager {
/**
* Registers an entity library for use in the plugin.
*
* @param entityLibrary The entity library to register.
* @return {@code true} if the entity library was successfully registered, {@code false} if it already exists.
*/
boolean registerEntityLibrary(EntityLibrary entityLibrary);
/**
* Unregisters an entity library by its identification key.
*
* @param identification The identification key of the entity library to unregister.
* @return {@code true} if the entity library was successfully unregistered, {@code false} if it does not exist.
*/
boolean unregisterEntityLibrary(String identification);
/**
* Summons an entity based on the given loot configuration to a specified location.
*
* @param hookLocation The location where the entity will be summoned, typically where the fishing hook is.
* @param playerLocation The location of the player who triggered the entity summoning.
* @param loot The loot configuration that defines the entity to be summoned.
*/
void summonEntity(Location hookLocation, Location playerLocation, Loot loot);
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.TempFishingState;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.game.GameInstance;
import net.momirealms.customfishing.api.mechanic.game.GameSettings;
import net.momirealms.customfishing.api.mechanic.game.GamingPlayer;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public interface FishingManager {
/**
* Removes a fishing hook entity associated with a given player's UUID.
*
* @param uuid The UUID of the player
* @return {@code true} if the fishing hook was successfully removed, {@code false} otherwise.
*/
boolean removeHook(UUID uuid);
/**
* Retrieves a FishHook object associated with the provided player's UUID
*
* @param uuid The UUID of the player
* @return fishhook entity, null if not exists
*/
@Nullable FishHook getHook(UUID uuid);
/**
* Sets the temporary fishing state for a player.
*
* @param player The player for whom to set the temporary fishing state.
* @param tempFishingState The temporary fishing state to set for the player.
*/
void setTempFishingState(Player player, TempFishingState tempFishingState);
/**
* Gets the {@link TempFishingState} object associated with the given UUID.
*
* @param uuid The UUID of the player.
* @return The {@link TempFishingState} object if found, or {@code null} if not found.
*/
@Nullable TempFishingState getTempFishingState(UUID uuid);
/**
* Removes the temporary fishing state associated with a player.
*
* @param player The player whose temporary fishing state should be removed.
*/
@Nullable TempFishingState removeTempFishingState(Player player);
/**
* Processes the game result for a gaming player
*
* @param gamingPlayer The gaming player whose game result should be processed.
*/
void processGameResult(GamingPlayer gamingPlayer);
/**
* Starts a fishing game for the specified player with the given condition and effect.
*
* @param player The player starting the fishing game.
* @param condition The condition used to determine the game.
* @param effect The effect applied to the game.
*/
boolean startFishingGame(Player player, Condition condition, Effect effect);
/**
* Starts a fishing game for the specified player with the given settings and game instance.
*
* @param player The player starting the fishing game.
* @param settings The game settings for the fishing game.
* @param gameInstance The instance of the fishing game to start.
*/
boolean startFishingGame(Player player, GameSettings settings, GameInstance gameInstance);
/**
* Checks if a player with the given UUID has cast their fishing hook.
*
* @param uuid The UUID of the player to check.
* @return {@code true} if the player has cast their fishing hook, {@code false} otherwise.
*/
boolean hasPlayerCastHook(UUID uuid);
/**
* Gets the {@link GamingPlayer} object associated with the given UUID.
*
* @param uuid The UUID of the player.
* @return The {@link GamingPlayer} object if found, or {@code null} if not found.
*/
@Nullable GamingPlayer getGamingPlayer(UUID uuid);
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.hook.HookSetting;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public interface HookManager {
/**
* Get the hook setting by its ID.
*
* @param id The ID of the hook setting to retrieve.
* @return The hook setting with the given ID, or null if not found.
*/
@Nullable HookSetting getHookSetting(String id);
/**
* Decreases the durability of a fishing hook by a specified amount and optionally updates its lore.
* The hook would be removed if its durability is lower than 0
*
* @param rod The fishing rod ItemStack to modify.
* @param amount The amount by which to decrease the durability.
* @param updateLore Whether to update the lore of the fishing rod.
*/
void decreaseHookDurability(ItemStack rod, int amount, boolean updateLore);
/**
* Increases the durability of a hook by a specified amount and optionally updates its lore.
*
* @param rod The fishing rod ItemStack to modify.
* @param amount The amount by which to increase the durability.
* @param updateLore Whether to update the lore of the fishing rod.
*/
void increaseHookDurability(ItemStack rod, int amount, boolean updateLore);
/**
* Sets the durability of a fishing hook to a specific amount and optionally updates its lore.
*
* @param rod The fishing rod ItemStack to modify.
* @param amount The new durability value to set.
* @param updateLore Whether to update the lore of the fishing rod.
*/
void setHookDurability(ItemStack rod, int amount, boolean updateLore);
/**
* Equips a fishing hook on a fishing rod.
*
* @param rod The fishing rod ItemStack.
* @param hook The fishing hook ItemStack.
* @return True if the hook was successfully equipped, false otherwise.
*/
boolean equipHookOnRod(ItemStack rod, ItemStack hook);
/**
* Removes the fishing hook from a fishing rod.
*
* @param rod The fishing rod ItemStack.
* @return The removed fishing hook ItemStack, or null if no hook was found.
*/
@Nullable ItemStack removeHookFromRod(ItemStack rod);
}

View File

@@ -1,101 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.integration.EnchantmentInterface;
import net.momirealms.customfishing.api.integration.LevelInterface;
import net.momirealms.customfishing.api.integration.SeasonInterface;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public interface IntegrationManager {
/**
* Registers a level plugin with the specified name.
*
* @param plugin The name of the level plugin.
* @param level The implementation of the LevelInterface.
* @return true if the registration was successful, false if the plugin name is already registered.
*/
boolean registerLevelPlugin(String plugin, LevelInterface level);
/**
* Unregisters a level plugin with the specified name.
*
* @param plugin The name of the level plugin to unregister.
* @return true if the unregistration was successful, false if the plugin name is not found.
*/
boolean unregisterLevelPlugin(String plugin);
/**
* Registers an enchantment provided by a plugin.
*
* @param plugin The name of the plugin providing the enchantment.
* @param enchantment The enchantment to register.
* @return true if the registration was successful, false if the enchantment name is already in use.
*/
boolean registerEnchantment(String plugin, EnchantmentInterface enchantment);
/**
* Unregisters an enchantment provided by a plugin.
*
* @param plugin The name of the plugin providing the enchantment.
* @return true if the enchantment was successfully unregistered, false if the enchantment was not found.
*/
boolean unregisterEnchantment(String plugin);
/**
* Get the LevelInterface provided by a plugin.
*
* @param plugin The name of the plugin providing the LevelInterface.
* @return The LevelInterface provided by the specified plugin, or null if the plugin is not registered.
*/
@Nullable LevelInterface getLevelPlugin(String plugin);
/**
* Get an enchantment plugin by its plugin name.
*
* @param plugin The name of the enchantment plugin.
* @return The enchantment plugin interface, or null if not found.
*/
@Nullable EnchantmentInterface getEnchantmentPlugin(String plugin);
/**
* Get a list of enchantment keys with level applied to the given ItemStack.
*
* @param itemStack The ItemStack to check for enchantments.
* @return A list of enchantment names applied to the ItemStack.
*/
List<String> getEnchantments(ItemStack itemStack);
/**
* Get the current season interface, if available.
*
* @return The current season interface, or null if not available.
*/
@Nullable SeasonInterface getSeasonInterface();
/**
* Set the current season interface.
*
* @param season The season interface to set.
*/
void setSeasonInterface(SeasonInterface season);
}

View File

@@ -1,207 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.common.Key;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.item.BuildableItem;
import net.momirealms.customfishing.api.mechanic.item.ItemBuilder;
import net.momirealms.customfishing.api.mechanic.item.ItemLibrary;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Set;
public interface ItemManager {
/**
* Build an ItemStack with a specified namespace and value for a player.
*
* @param player The player for whom the ItemStack is being built.
* @param namespace The namespace of the item.
* @param value The value of the item.
* @return The constructed ItemStack.
*/
@Nullable
ItemStack build(Player player, String namespace, String value);
/**
* Build an ItemStack with a specified namespace and value, replacing placeholders,
* for a player.
*
* @param player The player for whom the ItemStack is being built.
* @param namespace The namespace of the item.
* @param value The value of the item.
* @param placeholders The placeholders to replace in the item's attributes.
* @return The constructed ItemStack, or null if the item doesn't exist.
*/
@Nullable
ItemStack build(Player player, String namespace, String value, Map<String, String> placeholders);
/**
* Build an ItemStack using an ItemBuilder for a player.
*
* @param player The player for whom the ItemStack is being built.
* @param builder The ItemBuilder used to construct the ItemStack.
* @return The constructed ItemStack.
*/
@NotNull ItemStack build(Player player, ItemBuilder builder);
/**
* Build an ItemStack using the provided ItemBuilder, player, and placeholders.
*
* @param player The player for whom the item is being built.
* @param builder The ItemBuilder that defines the item's properties.
* @param placeholders A map of placeholders and their corresponding values to be applied to the item.
* @return The constructed ItemStack.
*/
@NotNull ItemStack build(Player player, ItemBuilder builder, Map<String, String> placeholders);
/**
* Build an ItemStack for a player based on the provided item ID.
*
* @param player The player for whom the ItemStack is being built.
* @param id The item ID, which include an identification (e.g., "Oraxen:id").
* @return The constructed ItemStack or null if the ID is not valid.
*/
@Nullable ItemStack buildAnyPluginItemByID(Player player, String id);
/**
* Get the item ID associated with the given ItemStack, if available.
*
* @param itemStack The ItemStack to retrieve the item ID from.
* @return The item ID without type or null if not found or if the ItemStack is null or empty.
*/
@Nullable String getCustomFishingItemID(ItemStack itemStack);
/**
* Get the item ID associated with the given ItemStack by checking all available item libraries.
* The detection order is determined by the configuration.
*
* @param itemStack The ItemStack to retrieve the item ID from.
* @return The item ID or "AIR" if not found or if the ItemStack is null or empty.
*/
@NotNull String getAnyPluginItemID(ItemStack itemStack);
/**
* Create a ItemBuilder instance for an item configuration section
* <p>
* xxx_item: <- section
* material: xxx
* custom-model-data: xxx
*
* @param section The configuration section containing item settings.
* @param type The type of the item (e.g., "rod", "bait").
* @param id The unique identifier for the item.
* @return A CFBuilder instance representing the configured item, or null if the section is null.
*/
@Nullable ItemBuilder getItemBuilder(ConfigurationSection section, String type, String id);
/**
* Get a set of all item keys in the CustomFishing plugin.
*
* @return A set of item keys.
*/
Set<Key> getAllItemsKey();
/**
* Retrieve a BuildableItem by its namespace and value.
*
* @param namespace The namespace of the BuildableItem.
* @param value The value of the BuildableItem.
* @return The BuildableItem with the specified namespace and value, or null if not found.
*/
@Nullable
BuildableItem getBuildableItem(String namespace, String value);
/**
* Get an itemStack's appearance (material + custom model data)
*
* @param player player
* @param material id
* @return appearance
*/
ItemStack getItemStackAppearance(Player player, String material);
/**
* Register an item library.
*
* @param itemLibrary The item library to register.
* @return True if the item library was successfully registered, false if it already exists.
*/
boolean registerItemLibrary(ItemLibrary itemLibrary);
/**
* Unregister an item library.
*
* @param identification The item library to unregister.
* @return True if the item library was successfully unregistered, false if it doesn't exist.
*/
boolean unRegisterItemLibrary(String identification);
/**
* Drops an item based on the provided loot, applying velocity from a hook location to a player location.
*
* @param player The player for whom the item is intended.
* @param hookLocation The location where the item will initially drop.
* @param playerLocation The target location towards which the item's velocity is applied.
* @param itemStack The loot to drop
* @param condition A map of placeholders for item customization.
*/
void dropItem(Player player, Location hookLocation, Location playerLocation, ItemStack itemStack, Condition condition);
/**
* Checks if the provided ItemStack is a custom fishing item
*
* @param itemStack The ItemStack to check.
* @return True if the ItemStack is a custom fishing item; otherwise, false.
*/
boolean isCustomFishingItem(ItemStack itemStack);
/**
* Decreases the durability of an ItemStack by a specified amount and optionally updates its lore.
*
* @param itemStack The ItemStack to modify.
* @param amount The amount by which to decrease the durability.
* @param updateLore Whether to update the lore of the ItemStack.
*/
void decreaseDurability(Player player, ItemStack itemStack, int amount, boolean updateLore);
/**
* Increases the durability of an ItemStack by a specified amount and optionally updates its lore.
*
* @param itemStack The ItemStack to modify.
* @param amount The amount by which to increase the durability.
* @param updateLore Whether to update the lore of the ItemStack.
*/
void increaseDurability(ItemStack itemStack, int amount, boolean updateLore);
/**
* Sets the durability of an ItemStack to a specific amount and optionally updates its lore.
*
* @param itemStack The ItemStack to modify.
* @param amount The new durability value.
* @param updateLore Whether to update the lore of the ItemStack.
*/
void setDurability(ItemStack itemStack, int amount, boolean updateLore);
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface LootManager {
/**
* Retrieves a list of loot IDs associated with a loot group key.
*
* @param key The key of the loot group.
* @return A list of loot IDs belonging to the specified loot group, or null if not found.
*/
@Nullable List<String> getLootGroup(String key);
/**
* Retrieves a loot configuration based on a provided loot key.
*
* @param key The key of the loot configuration.
* @return The Loot object associated with the specified loot key, or null if not found.
*/
@Nullable Loot getLoot(String key);
/**
* Retrieves a collection of all loot configuration keys.
*
* @return A collection of all loot configuration keys.
*/
Collection<String> getAllLootKeys();
/**
* Retrieves a collection of all loot configurations.
*
* @return A collection of all loot configurations.
*/
Collection<Loot> getAllLoots();
/**
* Retrieves loot configurations with weights based on a given condition.
*
* @param condition The condition used to filter loot configurations.
* @return A mapping of loot configuration keys to their associated weights.
*/
HashMap<String, Double> getLootWithWeight(Condition condition);
/**
* Get a collection of possible loot keys based on a given condition.
*
* @param condition The condition to determine possible loot.
* @return A collection of loot keys.
*/
Collection<String> getPossibleLootKeys(Condition condition);
/**
* Get a map of possible loot keys with their corresponding weights, considering fishing effect and condition.
*
* @param initialEffect The effect to apply weight modifiers.
* @param condition The condition to determine possible loot.
* @return A map of loot keys and their weights.
*/
@NotNull Map<String, Double> getPossibleLootKeysWithWeight(Effect initialEffect, Condition condition);
/**
* Get the next loot item based on fishing effect and condition.
*
* @param effect The effect to apply weight modifiers.
* @param condition The condition to determine possible loot.
* @return The next loot item, or null if it doesn't exist.
*/
@Nullable Loot getNextLoot(Effect effect, Condition condition);
}

View File

@@ -1,136 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
public interface MarketManager {
/**
* Open the market GUI for a player
*
* @param player player
*/
void openMarketGUI(Player player);
/**
* Retrieves the current date as an integer in the format MMDD (e.g., September 21 as 0921).
*
* @return An integer representing the current date.
*/
int getCachedDate();
/**
* Retrieves the current date as an integer in the format MMDD (e.g., September 21 as 0921).
*
* @return An integer representing the current date.
*/
int getDate();
/**
* Calculates the price of an ItemStack based on custom data or a predefined price map.
*
* @param itemStack The ItemStack for which the price is calculated.
* @return The calculated price of the ItemStack.
*/
double getItemPrice(ItemStack itemStack);
/**
* Retrieves the formula used for calculating prices.
*
* @return The pricing formula as a string.
*/
String getFormula();
/**
* Calculates the price based on a formula with provided variables.
*
* @return The calculated price based on the formula and provided variables.
*/
double getFishPrice(Player player, Map<String, String> vars);
/**
* Gets the character representing the item slot in the MarketGUI.
*
* @return The item slot character.
*/
char getItemSlot();
/**
* Gets the character representing the sell slot in the MarketGUI.
*
* @return The sell slot character.
*/
char getSellSlot();
/**
* Gets the character representing the sell-all slot in the MarketGUI.
*
* @return The sell-all slot character.
*/
char getSellAllSlot();
/**
* Gets the layout of the MarketGUI as an array of strings.
*
* @return The layout of the MarketGUI.
*/
String[] getLayout();
/**
* Gets the title of the MarketGUI.
*
* @return The title of the MarketGUI.
*/
String getTitle();
/**
* Gets the earning limit
*
* @return The earning limit
*/
double getEarningLimit(Player player);
/**
* Is market enabled
*
* @return enable or not
*/
boolean isEnable();
/**
* Should fish in bag also be sold
*
* @return sell or not
*/
boolean sellFishingBag();
/**
* Get the total worth of the items in inventory
*
* @param inventory inventory
* @return total worth
*/
double getInventoryTotalWorth(Inventory inventory);
int getInventorySellAmount(Inventory inventory);
}

View File

@@ -1,109 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
public interface PlaceholderManager {
/**
* Register a custom placeholder
*
* @param placeholder for instance {level}
* @param original for instance %player_level%
* @return success or not, it would fail if the placeholder has been registered
*/
boolean registerCustomPlaceholder(String placeholder, String original);
/**
* Set placeholders in a text string for a player.
*
* @param player The player for whom the placeholders should be set.
* @param text The text string containing placeholders.
* @return The text string with placeholders replaced if PlaceholderAPI is available; otherwise, the original text.
*/
String setPlaceholders(Player player, String text);
/**
* Set placeholders in a text string for an offline player.
*
* @param player The offline player for whom the placeholders should be set.
* @param text The text string containing placeholders.
* @return The text string with placeholders replaced if PlaceholderAPI is available; otherwise, the original text.
*/
String setPlaceholders(OfflinePlayer player, String text);
/**
* Detect and extract placeholders from a text string.
*
* @param text The text string to search for placeholders.
* @return A list of detected placeholders in the text.
*/
List<String> detectPlaceholders(String text);
/**
* Get the value associated with a single placeholder.
*
* @param player The player for whom the placeholders are being resolved (nullable).
* @param placeholder The placeholder to look up.
* @param placeholders A map of placeholders to their corresponding values.
* @return The value associated with the placeholder, or the original placeholder if not found.
*/
String getSingleValue(@Nullable Player player, String placeholder, Map<String, String> placeholders);
/**
* Parse a text string by replacing placeholders with their corresponding values.
*
* @param player The offline player for whom the placeholders are being resolved (nullable).
* @param text The text string containing placeholders.
* @param placeholders A map of placeholders to their corresponding values.
* @return The text string with placeholders replaced by their values.
*/
String parse(@Nullable OfflinePlayer player, String text, Map<String, String> placeholders);
/**
* Parse a list of text strings by replacing placeholders with their corresponding values.
*
* @param player The player for whom the placeholders are being resolved (can be null for offline players).
* @param list The list of text strings containing placeholders.
* @param replacements A map of custom replacements for placeholders.
* @return The list of text strings with placeholders replaced by their values.
*/
List<String> parse(@Nullable OfflinePlayer player, List<String> list, Map<String, String> replacements);
/**
* Get an expression's value
* @param player player
* @param formula formula
* @param vars vars
* @return result
*/
double getExpressionValue(Player player, String formula, Map<String, String> vars);
/**
* Get an expression's value
* @param formula formula
* @return result
*/
double getExpressionValue(String formula);
}

View File

@@ -1,124 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementFactory;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface RequirementManager {
/**
* Legacy format support
* @param key key
* @param requirements requirements
* @param weight weight
* @return success or not
*/
@Deprecated
boolean putLegacyLootToMap(String key, Requirement[] requirements, double weight);
/**
* Registers a custom requirement type with its corresponding factory.
*
* @param type The type identifier of the requirement.
* @param requirementFactory The factory responsible for creating instances of the requirement.
* @return True if registration was successful, false if the type is already registered.
*/
boolean registerRequirement(String type, RequirementFactory requirementFactory);
/**
* Unregisters a custom requirement type.
*
* @param type The type identifier of the requirement to unregister.
* @return True if unregistration was successful, false if the type is not registered.
*/
boolean unregisterRequirement(String type);
/**
* Retrieves an array of requirements based on a configuration section.
*
* @param section The configuration section containing requirement definitions.
* @param advanced A flag indicating whether to use advanced requirements.
* @return An array of Requirement objects based on the configuration section
*/
@Nullable Requirement[] getRequirements(ConfigurationSection section, boolean advanced);
/**
* If a requirement type exists
*
* @param type type
* @return exists or not
*/
boolean hasRequirement(String type);
/**
* Retrieves a Requirement object based on a configuration section and advanced flag.
* <p>
* requirement_1: <- section
* type: xxx
* value: xxx
*
* @param section The configuration section containing requirement definitions.
* @param advanced A flag indicating whether to use advanced requirements.
* @return A Requirement object based on the configuration section, or an EmptyRequirement if the section is null or invalid.
*/
@NotNull Requirement getRequirement(ConfigurationSection section, boolean advanced);
/**
* Gets a requirement based on the provided type and value.
* If a valid RequirementFactory is found for the type, it is used to create the requirement.
* If no factory is found, a warning is logged, and an empty requirement instance is returned.
* <p>
* world: <- type
* - world <- value
*
* @param type The type representing the requirement type.
* @param value The value associated with the requirement.
* @return A Requirement instance based on the type and value, or an EmptyRequirement if the type is invalid.
*/
@NotNull Requirement getRequirement(String type, Object value);
/**
* Retrieves a RequirementFactory based on the specified requirement type.
*
* @param type The requirement type for which to retrieve a factory.
* @return A RequirementFactory for the specified type, or null if no factory is found.
*/
@Nullable RequirementFactory getRequirementFactory(String type);
/**
* Checks if an array of requirements is met for a given condition.
*
* @param condition The Condition object to check against the requirements.
* @param requirements An array of Requirement instances to be evaluated.
* @return True if all requirements are met, false otherwise. Returns true if the requirements array is null.
*/
static boolean isRequirementMet(Condition condition, Requirement... requirements) {
if (requirements == null) return true;
for (Requirement requirement : requirements) {
if (!requirement.isConditionMet(condition)) {
return false;
}
}
return true;
}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.statistic.Statistics;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.UUID;
public interface StatisticsManager {
/**
* Get the statistics for a player with the given UUID.
*
* @param uuid The UUID of the player for whom statistics are retrieved.
* @return The player's statistics or null if the player is not found.
*/
@Nullable Statistics getStatistics(UUID uuid);
/**
* Get a list of strings associated with a specific key in a category map.
*
* @param key The key to look up in the category map.
* @return A list of strings associated with the key or null if the key is not found.
*/
@Nullable List<String> getCategory(String key);
}

View File

@@ -1,131 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.data.DataStorageInterface;
import net.momirealms.customfishing.api.data.PlayerData;
import net.momirealms.customfishing.api.data.user.OfflineUser;
import net.momirealms.customfishing.api.data.user.OnlineUser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface StorageManager {
/**
* Gets the unique server identifier.
*
* @return The unique server identifier.
*/
@NotNull String getUniqueID();
/**
* Gets an OnlineUser instance for the specified UUID.
*
* @param uuid The UUID of the player.
* @return An OnlineUser instance if the player is online, or null if not.
*/
@Nullable OnlineUser getOnlineUser(UUID uuid);
/**
* Get all the online users
*
* @return online users
*/
Collection<OnlineUser> getOnlineUsers();
/**
* Asynchronously retrieves an OfflineUser instance for the specified UUID.
* The offline user might be a locked one with no data, use isLockedData() method
* to check if it's an empty locked data
*
* @param uuid The UUID of the player.
* @param lock Whether to lock the data during retrieval.
* @return A CompletableFuture that resolves to an Optional containing the OfflineUser instance if found, or empty if not found or locked.
*/
CompletableFuture<Optional<OfflineUser>> getOfflineUser(UUID uuid, boolean lock);
/**
* If the offlineUser is locked with no data in it
* An user's data would be locked if he is playing on another server that connected
* to database. Modifying this data would actually do nothing.
*
* @param offlineUser offlineUser
* @return is locked or not
*/
boolean isLockedData(OfflineUser offlineUser);
/**
* Asynchronously saves user data for an OfflineUser.
*
* @param offlineUser The OfflineUser whose data needs to be saved.
* @param unlock Whether to unlock the data after saving.
* @return A CompletableFuture that resolves to a boolean indicating the success of the data saving operation.
*/
CompletableFuture<Boolean> saveUserData(OfflineUser offlineUser, boolean unlock);
/**
* Gets the data source used for data storage.
*
* @return The data source.
*/
DataStorageInterface getDataSource();
/**
* Checks if Redis is enabled.
*
* @return True if Redis is enabled; otherwise, false.
*/
boolean isRedisEnabled();
/**
* Converts PlayerData to bytes.
*
* @param data The PlayerData to be converted.
* @return The byte array representation of PlayerData.
*/
byte @NotNull [] toBytes(@NotNull PlayerData data);
/**
* Converts PlayerData to JSON format.
*
* @param data The PlayerData to be converted.
* @return The JSON string representation of PlayerData.
*/
@NotNull String toJson(@NotNull PlayerData data);
/**
* Converts JSON string to PlayerData.
*
* @param json The JSON string to be converted.
* @return The PlayerData object.
*/
@NotNull PlayerData fromJson(String json);
/**
* Converts bytes to PlayerData.
*
* @param data The byte array to be converted.
* @return The PlayerData object.
*/
@NotNull PlayerData fromBytes(byte[] data);
}

View File

@@ -1,32 +0,0 @@
/*
* Copyright (C) <2022> <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.manager;
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
import org.bukkit.Location;
public interface TotemManager {
/**
* Get the EffectCarrier associated with an activated totem located near the specified location.
*
* @param location The location to search for activated totems.
* @return The EffectCarrier associated with the nearest activated totem or null if none are found.
*/
EffectCarrier getTotemEffect(Location location);
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright (C) <2022> <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.mechanic;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import org.bukkit.configuration.ConfigurationSection;
import java.util.HashMap;
import java.util.Map;
/**
* Represents global settings for actions related to fishing, loot, rods, and bait.
*/
public class GlobalSettings {
private static HashMap<ActionTrigger, Action[]> lootActions = new HashMap<>();
private static HashMap<ActionTrigger, Action[]> rodActions = new HashMap<>();
private static HashMap<ActionTrigger, Action[]> baitActions = new HashMap<>();
private static HashMap<ActionTrigger, Action[]> hookActions = new HashMap<>();
private static EffectModifier[] effectModifiers;
/**
* Loads global settings from a configuration section.
*
* @param section The configuration section to load settings from.
*/
public static void loadEvents(ConfigurationSection section) {
if (section == null) return;
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
if (entry.getValue() instanceof ConfigurationSection inner) {
HashMap<ActionTrigger, Action[]> map = CustomFishingPlugin.get().getActionManager().getActionMap(inner);
switch (entry.getKey()) {
case "loot" -> lootActions = map;
case "rod" -> rodActions = map;
case "bait" -> baitActions = map;
case "hook" -> hookActions = map;
}
}
}
}
public static EffectModifier[] getEffectModifiers() {
return effectModifiers;
}
public static void setEffects(EffectModifier[] modifiers) {
effectModifiers = modifiers;
}
/**
* Unloads global settings, clearing all action maps.
*/
public static void unload() {
lootActions.clear();
rodActions.clear();
baitActions.clear();
}
/**
* Triggers loot-related actions for a specific trigger and condition.
*
* @param trigger The trigger to activate actions for.
* @param condition The condition that triggered the actions.
*/
public static void triggerLootActions(ActionTrigger trigger, Condition condition) {
Action[] actions = lootActions.get(trigger);
if (actions != null) {
for (Action action : actions) {
action.trigger(condition);
}
}
}
/**
* Triggers rod-related actions for a specific trigger and condition.
*
* @param trigger The trigger to activate actions for.
* @param condition The condition that triggered the actions.
*/
public static void triggerRodActions(ActionTrigger trigger, Condition condition) {
Action[] actions = rodActions.get(trigger);
if (actions != null) {
for (Action action : actions) {
action.trigger(condition);
}
}
}
/**
* Triggers bait-related actions for a specific trigger and condition.
*
* @param trigger The trigger to activate actions for.
* @param condition The condition that triggered the actions.
*/
public static void triggerBaitActions(ActionTrigger trigger, Condition condition) {
Action[] actions = baitActions.get(trigger);
if (actions != null) {
for (Action action : actions) {
action.trigger(condition);
}
}
}
/**
* Triggers hook-related actions for a specific trigger and condition.
*
* @param trigger The trigger to activate actions for.
* @param condition The condition that triggered the actions.
*/
public static void triggerHookActions(ActionTrigger trigger, Condition condition) {
Action[] actions = hookActions.get(trigger);
if (actions != null) {
for (Action action : actions) {
action.trigger(condition);
}
}
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) <2022> <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.mechanic;
import net.kyori.adventure.util.Index;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
public class MechanicType {
private static final HashMap<String, List<MechanicType>> types = new HashMap<>();
public static final MechanicType LOOT = of("loot");
public static final MechanicType ROD = of("rod");
public static final MechanicType UTIL = of("util");
public static final MechanicType BAIT = of("bait");
public static final MechanicType HOOK = of("hook");
public static final MechanicType TOTEM = of("totem");
public static final MechanicType ENTITY = of("entity");
public static final MechanicType BLOCK = of("block");
public static final MechanicType ENCHANT = of("enchant");
private final String type;
public MechanicType(String type) {
this.type = type;
}
public String getType() {
return type;
}
private static MechanicType of(String type) {
return new MechanicType(type);
}
public static MechanicType[] values() {
return new MechanicType[]{LOOT, ROD, UTIL, BAIT, HOOK, TOTEM, ENCHANT, ENTITY, BLOCK};
}
private static final Index<String, MechanicType> INDEX = Index.create(MechanicType::getType, values());
public static Index<String, MechanicType> index() {
return INDEX;
}
@ApiStatus.Internal
public static void register(String id, MechanicType type) {
List<MechanicType> previous = types.computeIfAbsent(id, k -> new ArrayList<>());
previous.add(type);
}
@Nullable
@ApiStatus.Internal
public static List<MechanicType> getTypeByID(String id) {
return types.get(id);
}
@ApiStatus.Internal
public static void reset() {
types.clear();
}
@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
MechanicType mechanicType = (MechanicType) object;
return Objects.equals(type, mechanicType.type);
}
@Override
public int hashCode() {
return Objects.hashCode(type);
}
@Override
public String toString() {
return type;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright (C) <2022> <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.mechanic;
import net.momirealms.customfishing.api.mechanic.condition.FishingPreparation;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
/**
* Represents a temporary state during fishing that includes an effect, preparation, and loot.
*/
public class TempFishingState {
private final Effect effect;
private final FishingPreparation preparation;
private Loot loot;
/**
* Creates a new instance of TempFishingState.
*
* @param effect The effect associated with this state.
* @param preparation The fishing preparation associated with this state.
* @param loot The loot associated with this state.
*/
public TempFishingState(Effect effect, FishingPreparation preparation, Loot loot) {
this.effect = effect;
this.preparation = preparation;
this.loot = loot;
}
/**
* Gets the effect associated with this fishing state.
*
* @return The effect.
*/
public Effect getEffect() {
return effect;
}
/**
* Gets the fishing preparation associated with this fishing state.
*
* @return The fishing preparation.
*/
public FishingPreparation getPreparation() {
return preparation;
}
/**
* Gets the loot associated with this fishing state.
*
* @return The loot.
*/
public Loot getLoot() {
return loot;
}
/**
* Set the loot associated with this fishing state.
*
*/
public void setLoot(Loot loot) {
this.loot = loot;
}
}

View File

@@ -17,10 +17,14 @@
package net.momirealms.customfishing.api.mechanic.action;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.context.Context;
public interface Action {
void trigger(Condition condition);
public interface Action<T> {
/**
* Triggers the action based on the provided condition.
*
* @param context the context
*/
void trigger(Context<T> context);
}

View File

@@ -17,13 +17,39 @@
package net.momirealms.customfishing.api.mechanic.action;
public abstract class ActionExpansion {
/**
* Abstract class representing an expansion of an action in the custom fishing API.
* This class should be extended to provide specific implementations of actions.
*
* @param <T> the type parameter for the action factory
*/
public abstract class ActionExpansion<T> {
/**
* Retrieves the version of this action expansion.
*
* @return a String representing the version of the action expansion
*/
public abstract String getVersion();
/**
* Retrieves the author of this action expansion.
*
* @return a String representing the author of the action expansion
*/
public abstract String getAuthor();
/**
* Retrieves the type of this action.
*
* @return a String representing the type of action
*/
public abstract String getActionType();
public abstract ActionFactory getActionFactory();
/**
* Retrieves the action factory associated with this action expansion.
*
* @return an ActionFactory of type T that creates instances of the action
*/
public abstract ActionFactory<T> getActionFactory();
}

View File

@@ -17,7 +17,18 @@
package net.momirealms.customfishing.api.mechanic.action;
public interface ActionFactory {
/**
* Interface representing a factory for creating actions.
*
* @param <T> the type of object that the action will operate on
*/
public interface ActionFactory<T> {
Action build(Object args, double chance);
/**
* Constructs an action based on the provided arguments.
*
* @param args the args containing the arguments needed to build the action
* @return the constructed action
*/
Action<T> process(Object args, double chance);
}

View File

@@ -0,0 +1,159 @@
/*
* Copyright (C) <2022> <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.mechanic.action;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* The ActionManager interface manages custom action types and provides methods for handling actions.
*
* @param <T> the type of the context in which the actions are triggered.
*/
public interface ActionManager<T> extends Reloadable {
/**
* Registers a custom action type with its corresponding factory.
*
* @param type The type identifier of the action.
* @param actionFactory The factory responsible for creating instances of the action.
* @return True if registration was successful, false if the type is already registered.
*/
boolean registerAction(String type, ActionFactory<T> actionFactory);
/**
* Unregisters a custom action type.
*
* @param type The type identifier of the action to unregister.
* @return True if unregistration was successful, false if the type is not registered.
*/
boolean unregisterAction(String type);
/**
* Checks if an action type is registered.
*
* @param type The type identifier of the action.
* @return True if the action type is registered, otherwise false.
*/
boolean hasAction(@NotNull String type);
/**
* Retrieves the action factory for the specified action type.
*
* @param type The type identifier of the action.
* @return The action factory for the specified type, or null if no factory is found.
*/
@Nullable
ActionFactory<T> getActionFactory(@NotNull String type);
/**
* Parses an action from a configuration section.
*
* @param section The configuration section containing the action definition.
* @return The parsed action.
*/
Action<T> parseAction(Section section);
/**
* Parses an array of actions from a configuration section.
*
* @param section The configuration section containing the action definitions.
* @return An array of parsed actions.
*/
@NotNull
Action<T>[] parseActions(Section section);
/**
* Parses an action from the given type and arguments.
*
* @param type The type identifier of the action.
* @param args The arguments for the action.
* @return The parsed action.
*/
Action<T> parseAction(@NotNull String type, @NotNull Object args);
/**
* Generates a map of actions triggered by specific events from a configuration section.
*
* @param section The configuration section containing event-action mappings.
* @return A map where the keys are action triggers and the values are arrays of actions associated with those triggers.
*/
default Map<ActionTrigger, Action<T>[]> parseEventActions(Section section) {
HashMap<ActionTrigger, Action<T>[]> actionMap = new HashMap<>();
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
if (entry.getValue() instanceof Section innerSection) {
try {
actionMap.put(
ActionTrigger.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH)),
parseActions(innerSection)
);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
}
}
}
return actionMap;
}
/**
* Parses a configuration section to generate a map of timed actions.
*
* @param section The configuration section containing time-action mappings.
* @return A TreeMap where the keys are time values (in integer form) and the values are arrays of actions associated with those times.
*/
default TreeMap<Integer, Action<T>[]> parseTimesActions(Section section) {
TreeMap<Integer, Action<T>[]> actionMap = new TreeMap<>();
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
if (entry.getValue() instanceof Section innerSection) {
actionMap.put(Integer.parseInt(entry.getKey()), parseActions(innerSection));
}
}
return actionMap;
}
/**
* Triggers a list of actions with the given context.
* If the list of actions is not null, each action in the list is triggered.
*
* @param context The context associated with the actions.
* @param actions The list of actions to trigger.
*/
static <T> void trigger(@NotNull Context<T> context, @Nullable List<Action<T>> actions) {
if (actions != null)
for (Action<T> action : actions)
action.trigger(context);
}
/**
* Triggers an array of actions with the given context.
* If the array of actions is not null, each action in the array is triggered.
*
* @param context The context associated with the actions.
* @param actions The array of actions to trigger.
*/
static <T> void trigger(@NotNull Context<T> context, @Nullable Action<T>[] actions) {
if (actions != null)
for (Action<T> action : actions)
action.trigger(context);
}
}

View File

@@ -18,7 +18,6 @@
package net.momirealms.customfishing.api.mechanic.action;
public enum ActionTrigger {
SUCCESS,
FAILURE,
HOOK,
@@ -26,8 +25,11 @@ public enum ActionTrigger {
CAST,
BITE,
LAND,
LURE,
ESCAPE,
ACTIVATE,
TIMER,
INTERACT,
REEL,
NEW_SIZE_RECORD
}

View File

@@ -15,19 +15,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.compatibility.papi;
package net.momirealms.customfishing.api.mechanic.action;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.OfflinePlayer;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.entity.Player;
public class ParseUtils {
/**
* An implementation of the Action interface that represents an empty action with no behavior.
* This class serves as a default action to prevent NPE.
*/
public class EmptyAction implements Action<Player> {
public static String setPlaceholders(Player player, String text) {
return PlaceholderAPI.setPlaceholders(player, text);
}
public static final EmptyAction INSTANCE = new EmptyAction();
public static String setPlaceholders(OfflinePlayer player, String text) {
return PlaceholderAPI.setPlaceholders(player, text);
@Override
public void trigger(Context<Player> context) {
}
}

View File

@@ -15,27 +15,26 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.manager;
package net.momirealms.customfishing.api.mechanic.bag;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface VersionManager {
public interface BagManager extends Reloadable {
boolean isVersionNewerThan1_19();
boolean isVersionNewerThan1_19_R3();
boolean isVersionNewerThan1_19_R2();
CompletableFuture<Boolean> checkUpdate();
boolean isVersionNewerThan1_20();
boolean isSpigot();
public boolean hasRegionScheduler();
String getPluginVersion();
boolean isMojmap();
static int getBagInventoryRows(Player player) {
int size = 1;
for (int i = 6; i > 1; i--) {
if (player.hasPermission("fishingbag.rows." + i)) {
size = i;
break;
}
}
return size;
}
CompletableFuture<Boolean> openBag(Player viewer, UUID owner);
}

View File

@@ -17,6 +17,8 @@
package net.momirealms.customfishing.api.mechanic.bag;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
@@ -35,6 +37,20 @@ public class FishingBagHolder implements InventoryHolder {
@Override
public @NotNull Inventory getInventory() {
Player player = Bukkit.getPlayer(owner);
if (player != null) {
int rows = BagManager.getBagInventoryRows(player);
if (rows * 9 != inventory.getSize()) {
Inventory newBag = Bukkit.createInventory(this, rows * 9);
ItemStack[] newContents = new ItemStack[rows * 9];
ItemStack[] oldContents = inventory.getContents();
for (int i = 0; i < rows * 9 && i < oldContents.length; i++) {
newContents[i] = oldContents[i];
}
newBag.setContents(newContents);
this.setInventory(newBag);
}
}
return inventory;
}
@@ -49,4 +65,12 @@ public class FishingBagHolder implements InventoryHolder {
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
public static FishingBagHolder create(UUID owner, ItemStack[] itemStacks, int size) {
FishingBagHolder holder = new FishingBagHolder(owner);
Inventory inventory = Bukkit.createInventory(holder, size);
holder.setInventory(inventory);
holder.setItems(itemStacks);
return holder;
}
}

View File

@@ -19,85 +19,80 @@ package net.momirealms.customfishing.api.mechanic.block;
import java.util.List;
public class BlockConfig implements BlockSettings {
/**
* Interface representing the configuration for a custom block in the CustomFishing plugin.
* Provides methods to access various block properties and modifiers.
*/
public interface BlockConfig {
private String blockID;
private List<BlockDataModifier> dataModifierList;
private List<BlockStateModifier> stateModifierList;
private boolean persist;
private double horizontalVector;
private double verticalVector;
String id();
@Override
public String getBlockID() {
return blockID;
/**
* Gets the unique identifier for the block.
*
* @return The block's unique identifier.
*/
String blockID();
/**
* Gets the list of data modifiers applied to the block.
*
* @return A list of {@link BlockDataModifier} objects.
*/
List<BlockDataModifier> dataModifier();
/**
* Gets the list of state modifiers applied to the block.
*
* @return A list of {@link BlockStateModifier} objects.
*/
List<BlockStateModifier> stateModifiers();
/**
* Creates a new builder instance for constructing a {@link BlockConfig}.
*
* @return A new {@link Builder} instance.
*/
static Builder builder() {
return new BlockConfigImpl.BuilderImpl();
}
@Override
public List<BlockDataModifier> getDataModifier() {
return dataModifierList;
}
/**
* Builder interface for constructing a {@link BlockConfig} instance.
*/
interface Builder {
@Override
public List<BlockStateModifier> getStateModifierList() {
return stateModifierList;
}
Builder id(String id);
@Override
public boolean isPersist() {
return persist;
}
/**
* Sets the block ID for the configuration.
*
* @param blockID The block's unique identifier.
* @return The current {@link Builder} instance.
*/
Builder blockID(String blockID);
@Override
public double getHorizontalVector() {
return horizontalVector;
}
/**
* Sets the list of data modifiers for the configuration.
*
* @param dataModifierList A list of {@link BlockDataModifier} objects.
* @return The current {@link Builder} instance.
*/
Builder dataModifierList(List<BlockDataModifier> dataModifierList);
@Override
public double getVerticalVector() {
return verticalVector;
}
/**
* Sets the list of state modifiers for the configuration.
*
* @param stateModifierList A list of {@link BlockStateModifier} objects.
* @return The current {@link Builder} instance.
*/
Builder stateModifierList(List<BlockStateModifier> stateModifierList);
public static class Builder {
private final BlockConfig config;
public Builder() {
this.config = new BlockConfig();
}
public Builder persist(boolean value) {
config.persist = value;
return this;
}
public Builder horizontalVector(double value) {
config.horizontalVector = value;
return this;
}
public Builder verticalVector(double value) {
config.verticalVector = value;
return this;
}
public Builder blockID(String value) {
config.blockID = value;
return this;
}
public Builder dataModifiers(List<BlockDataModifier> value) {
config.dataModifierList = value;
return this;
}
public Builder stateModifiers(List<BlockStateModifier> value) {
config.stateModifierList = value;
return this;
}
public BlockConfig build() {
return config;
}
/**
* Builds and returns the configured {@link BlockConfig} instance.
*
* @return The constructed {@link BlockConfig} instance.
*/
BlockConfig build();
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) <2022> <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.mechanic.block;
import java.util.ArrayList;
import java.util.List;
public class BlockConfigImpl implements BlockConfig {
private final String blockID;
private final List<BlockDataModifier> dataModifierList;
private final List<BlockStateModifier> stateModifierList;
private final String id;
public BlockConfigImpl(String id, String blockID, List<BlockDataModifier> dataModifierList, List<BlockStateModifier> stateModifierList) {
this.blockID = blockID;
this.dataModifierList = dataModifierList;
this.stateModifierList = stateModifierList;
this.id = id;
}
@Override
public String id() {
return id;
}
@Override
public String blockID() {
return blockID;
}
@Override
public List<BlockDataModifier> dataModifier() {
return dataModifierList;
}
@Override
public List<BlockStateModifier> stateModifiers() {
return stateModifierList;
}
public static class BuilderImpl implements Builder {
private String blockID;
private final List<BlockDataModifier> dataModifierList = new ArrayList<>();
private final List<BlockStateModifier> stateModifierList = new ArrayList<>();
private String id;
@Override
public Builder id(String id) {
this.id = id;
return this;
}
@Override
public Builder blockID(String blockID) {
this.blockID = blockID;
return this;
}
@Override
public Builder dataModifierList(List<BlockDataModifier> dataModifierList) {
this.dataModifierList.addAll(dataModifierList);
return this;
}
@Override
public Builder stateModifierList(List<BlockStateModifier> stateModifierList) {
this.stateModifierList.addAll(stateModifierList);
return this;
}
@Override
public BlockConfig build() {
return new BlockConfigImpl(id, blockID, dataModifierList, stateModifierList);
}
}
}

View File

@@ -17,9 +17,12 @@
package net.momirealms.customfishing.api.mechanic.block;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface BlockDataModifier {
void apply(Player player, BlockData blockData);
void apply(Context<Player> context, BlockData blockData);
}

View File

@@ -17,7 +17,8 @@
package net.momirealms.customfishing.api.mechanic.block;
public interface BlockStateModifierBuilder {
@FunctionalInterface
public interface BlockDataModifierFactory {
BlockStateModifier build(Object args);
BlockDataModifier process(Object args);
}

View File

@@ -17,19 +17,20 @@
package net.momirealms.customfishing.api.mechanic.block;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface BlockManager extends Reloadable {
public interface BlockLibrary {
boolean registerBlock(@NotNull BlockConfig block);
String identification();
@NotNull
FallingBlock summonBlockLoot(@NotNull Context<Player> context);
BlockData getBlockData(Player player, String id, List<BlockDataModifier> modifiers);
@Nullable
String getBlockID(Block block);
@NotNull
String getBlockID(@NotNull Block block);
}

View File

@@ -17,9 +17,12 @@
package net.momirealms.customfishing.api.mechanic.block;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface BlockStateModifier {
void apply(Player player, BlockState blockState);
void apply(Context<Player> context, BlockState blockState);
}

View File

@@ -17,7 +17,8 @@
package net.momirealms.customfishing.api.mechanic.block;
public interface BlockDataModifierBuilder {
@FunctionalInterface
public interface BlockStateModifierFactory {
BlockDataModifier build(Object args);
BlockStateModifier process(Object args);
}

View File

@@ -0,0 +1,14 @@
package net.momirealms.customfishing.api.mechanic.block;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
public class EmptyBlockDataModifier implements BlockDataModifier {
public static final BlockDataModifier INSTANCE = new EmptyBlockDataModifier();
@Override
public void apply(Context<Player> context, BlockData blockData) {
}
}

View File

@@ -0,0 +1,14 @@
package net.momirealms.customfishing.api.mechanic.block;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
public class EmptyBlockStateModifier implements BlockStateModifier {
public static final EmptyBlockStateModifier INSTANCE = new EmptyBlockStateModifier();
@Override
public void apply(Context<Player> context, BlockState blockState) {
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (C) <2022> <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.mechanic.competition;
public class ActionBarConfig extends AbstractCompetitionInfo {
public static class Builder {
private final ActionBarConfig config;
public Builder() {
this.config = new ActionBarConfig();
}
public Builder showToAll(boolean showToAll) {
this.config.showToAll = showToAll;
return this;
}
public Builder refreshRate(int rate) {
this.config.refreshRate = rate;
return this;
}
public Builder switchInterval(int interval) {
this.config.switchInterval = interval;
return this;
}
public Builder text(String[] texts) {
this.config.texts = texts;
return this;
}
public ActionBarConfig build() {
return this.config;
}
}
}

View File

@@ -1,85 +0,0 @@
/*
* Copyright (C) <2022> <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.mechanic.competition;
import org.bukkit.boss.BarColor;
public class BossBarConfig extends AbstractCompetitionInfo {
private BarColor color;
private Overlay overlay;
public BarColor getColor() {
return color;
}
public Overlay getOverlay() {
return overlay;
}
public static class Builder {
private final BossBarConfig config;
public Builder() {
this.config = new BossBarConfig();
}
public Builder showToAll(boolean showToAll) {
this.config.showToAll = showToAll;
return this;
}
public Builder refreshRate(int rate) {
this.config.refreshRate = rate;
return this;
}
public Builder switchInterval(int interval) {
this.config.switchInterval = interval;
return this;
}
public Builder text(String[] texts) {
this.config.texts = texts;
return this;
}
public Builder color(BarColor color) {
this.config.color = color;
return this;
}
public Builder overlay(Overlay overlay) {
this.config.overlay = overlay;
return this;
}
public BossBarConfig build() {
return this.config;
}
}
public enum Overlay {
NOTCHED_6,
NOTCHED_10,
NOTCHED_12,
NOTCHED_20,
PROGRESS
}
}

View File

@@ -18,178 +18,227 @@
package net.momirealms.customfishing.api.mechanic.competition;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig;
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.entity.Player;
import java.util.HashMap;
public class CompetitionConfig {
/**
* Interface representing the configuration for a fishing competition.
*/
public interface CompetitionConfig {
private final String key;
private int duration;
private int minPlayers;
private BossBarConfig bossBarConfig;
private ActionBarConfig actionBarConfig;
private Action[] skipActions;
private Action[] startActions;
private Action[] endActions;
private Action[] joinActions;
private Requirement[] requirements;
private CompetitionGoal goal;
private HashMap<String, Action[]> rewards;
CompetitionGoal DEFAULT_GOAL = CompetitionGoal.CATCH_AMOUNT;
int DEFAULT_DURATION = 300;
int DEFAULT_MIN_PLAYERS = 0;
Requirement<Player>[] DEFAULT_REQUIREMENTS = null;
Action<Player>[] DEFAULT_SKIP_ACTIONS = null;
Action<Player>[] DEFAULT_START_ACTIONS = null;
Action<Player>[] DEFAULT_END_ACTIONS = null;
Action<Player>[] DEFAULT_JOIN_ACTIONS = null;
HashMap<String, Action<Player>[]> DEFAULT_REWARDS = new HashMap<>();
public CompetitionConfig(String key) {
this.key = key;
}
/**
* Gets the unique key for the competition.
*
* @return the key for the competition.
*/
String key();
public String getKey() {
return key;
}
/**
* Gets the duration of the competition in seconds.
*
* @return the duration in seconds.
*/
int durationInSeconds();
public int getDurationInSeconds() {
return duration;
}
/**
* Gets the minimum number of players required to start the competition.
*
* @return the minimum number of players.
*/
int minPlayersToStart();
public int getMinPlayersToStart() {
return minPlayers;
}
/**
* Gets the actions to be performed when the competition starts.
*
* @return an array of start actions.
*/
Action<Player>[] startActions();
@Nullable
public Action[] getStartActions() {
return startActions;
}
/**
* Gets the actions to be performed when the competition ends.
*
* @return an array of end actions.
*/
Action<Player>[] endActions();
@Nullable
public Action[] getEndActions() {
return endActions;
/**
* Gets the actions to be performed when a player joins the competition.
*
* @return an array of join actions.
*/
Action<Player>[] joinActions();
/**
* Gets the actions to be performed when a player skips the competition.
*
* @return an array of skip actions.
*/
Action<Player>[] skipActions();
/**
* Gets the requirements that players must meet to join the competition.
*
* @return an array of join requirements.
*/
Requirement<Player>[] joinRequirements();
/**
* Gets the goal of the competition.
*
* @return the competition goal.
*/
CompetitionGoal goal();
/**
* Gets the rewards for the competition.
*
* @return a hashmap where the key is a string identifier and the value is an array of actions.
*/
HashMap<String, Action<Player>[]> rewards();
/**
* Gets the configuration for the boss bar during the competition.
*
* @return the boss bar configuration.
*/
BossBarConfig bossBarConfig();
/**
* Gets the configuration for the action bar during the competition.
*
* @return the action bar configuration.
*/
ActionBarConfig actionBarConfig();
/**
* Creates a new builder for the competition configuration.
*
* @return a new builder instance.
*/
static Builder builder() {
return new CompetitionConfigImpl.BuilderImpl();
}
/**
* Get the actions to perform if player joined the competition
*
* @return actions
* Builder interface for constructing a CompetitionConfig instance.
*/
@Nullable
public Action[] getJoinActions() {
return joinActions;
}
interface Builder {
/**
* Get the actions to perform if the amount of players doesn't meet the requirement
* Sets the unique key for the competition.
*
* @return actions
* @param key the key for the competition.
* @return the builder instance.
*/
@Nullable
public Action[] getSkipActions() {
return skipActions;
}
Builder key(String key);
/**
* Get the requirements for participating the competition
* Sets the goal of the competition.
*
* @return requirements
* @param goal the competition goal.
* @return the builder instance.
*/
@Nullable
public Requirement[] getRequirements() {
return requirements;
}
@NotNull
public CompetitionGoal getGoal() {
return goal;
}
Builder goal(CompetitionGoal goal);
/**
* Get the reward map
* Sets the duration of the competition.
*
* @return reward map
* @param duration the duration in seconds.
* @return the builder instance.
*/
public HashMap<String, Action[]> getRewards() {
return rewards;
}
Builder duration(int duration);
@Nullable
public BossBarConfig getBossBarConfig() {
return bossBarConfig;
}
/**
* Sets the minimum number of players required to start the competition.
*
* @param minPlayers the minimum number of players.
* @return the builder instance.
*/
Builder minPlayers(int minPlayers);
@Nullable
public ActionBarConfig getActionBarConfig() {
return actionBarConfig;
}
/**
* Sets the requirements that players must meet to join the competition.
*
* @param joinRequirements an array of join requirements.
* @return the builder instance.
*/
Builder joinRequirements(Requirement<Player>[] joinRequirements);
public static Builder builder(String key) {
return new Builder(key);
}
/**
* Sets the actions to be performed when a player skips the competition.
*
* @param skipActions an array of skip actions.
* @return the builder instance.
*/
Builder skipActions(Action<Player>[] skipActions);
public static class Builder {
/**
* Sets the actions to be performed when the competition starts.
*
* @param startActions an array of start actions.
* @return the builder instance.
*/
Builder startActions(Action<Player>[] startActions);
private final CompetitionConfig config;
/**
* Sets the actions to be performed when the competition ends.
*
* @param endActions an array of end actions.
* @return the builder instance.
*/
Builder endActions(Action<Player>[] endActions);
public Builder(String key) {
this.config = new CompetitionConfig(key);
}
/**
* Sets the actions to be performed when a player joins the competition.
*
* @param joinActions an array of join actions.
* @return the builder instance.
*/
Builder joinActions(Action<Player>[] joinActions);
public Builder duration(int duration) {
config.duration = duration;
return this;
}
/**
* Sets the rewards for the competition.
*
* @param rewards a hashmap where the key is a string identifier and the value is an array of actions.
* @return the builder instance.
*/
Builder rewards(HashMap<String, Action<Player>[]> rewards);
public Builder minPlayers(int min) {
config.minPlayers = min;
return this;
}
/**
* Sets the configuration for the boss bar during the competition.
*
* @param bossBarConfig the boss bar configuration.
* @return the builder instance.
*/
Builder bossBarConfig(BossBarConfig bossBarConfig);
public Builder startActions(Action[] startActions) {
config.startActions = startActions;
return this;
}
/**
* Sets the configuration for the action bar during the competition.
*
* @param actionBarConfig the action bar configuration.
* @return the builder instance.
*/
Builder actionBarConfig(ActionBarConfig actionBarConfig);
public Builder endActions(Action[] endActions) {
config.endActions = endActions;
return this;
}
public Builder skipActions(Action[] skipActions) {
config.skipActions = skipActions;
return this;
}
public Builder joinActions(Action[] joinActions) {
config.joinActions = joinActions;
return this;
}
@SuppressWarnings("UnusedReturnValue")
public Builder actionbar(ActionBarConfig actionBarConfig) {
config.actionBarConfig = actionBarConfig;
return this;
}
@SuppressWarnings("UnusedReturnValue")
public Builder bossbar(BossBarConfig bossBarConfig) {
config.bossBarConfig = bossBarConfig;
return this;
}
public Builder requirements(Requirement[] requirements) {
config.requirements = requirements;
return this;
}
public Builder goal(CompetitionGoal goal) {
config.goal = goal;
return this;
}
public Builder rewards(HashMap<String, Action[]> rewards) {
config.rewards = rewards;
return this;
}
public CompetitionConfig build() {
return config;
}
/**
* Builds and returns the CompetitionConfig instance.
*
* @return the constructed CompetitionConfig instance.
*/
CompetitionConfig build();
}
}

View File

@@ -0,0 +1,196 @@
/*
* Copyright (C) <2022> <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.mechanic.competition;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig;
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import org.bukkit.entity.Player;
import java.util.HashMap;
public class CompetitionConfigImpl implements CompetitionConfig {
private final String key;
private final CompetitionGoal goal;
private final int duration;
private final int minPlayers;
private final Requirement<Player>[] joinRequirements;
private final Action<Player>[] skipActions;
private final Action<Player>[] startActions;
private final Action<Player>[] endActions;
private final Action<Player>[] joinActions;
private final HashMap<String, Action<Player>[]> rewards;
private final BossBarConfig bossBarConfig;
private final ActionBarConfig actionBarConfig;
public CompetitionConfigImpl(String key, CompetitionGoal goal, int duration, int minPlayers, Requirement<Player>[] joinRequirements, Action<Player>[] skipActions, Action<Player>[] startActions, Action<Player>[] endActions, Action<Player>[] joinActions, HashMap<String, Action<Player>[]> rewards, BossBarConfig bossBarConfig, ActionBarConfig actionBarConfig) {
this.key = key;
this.goal = goal;
this.duration = duration;
this.minPlayers = minPlayers;
this.joinRequirements = joinRequirements;
this.skipActions = skipActions;
this.startActions = startActions;
this.endActions = endActions;
this.joinActions = joinActions;
this.rewards = rewards;
this.bossBarConfig = bossBarConfig;
this.actionBarConfig = actionBarConfig;
}
@Override
public String key() {
return key;
}
@Override
public int durationInSeconds() {
return duration;
}
@Override
public int minPlayersToStart() {
return minPlayers;
}
@Override
public Action<Player>[] startActions() {
return startActions;
}
@Override
public Action<Player>[] endActions() {
return endActions;
}
@Override
public Action<Player>[] joinActions() {
return joinActions;
}
@Override
public Action<Player>[] skipActions() {
return skipActions;
}
@Override
public Requirement<Player>[] joinRequirements() {
return joinRequirements;
}
@Override
public CompetitionGoal goal() {
return goal;
}
@Override
public HashMap<String, Action<Player>[]> rewards() {
return rewards;
}
@Override
public BossBarConfig bossBarConfig() {
return bossBarConfig;
}
@Override
public ActionBarConfig actionBarConfig() {
return actionBarConfig;
}
public static class BuilderImpl implements Builder {
private String key;
private CompetitionGoal goal = DEFAULT_GOAL;
private int duration = DEFAULT_DURATION;
private int minPlayers = DEFAULT_MIN_PLAYERS;
private Requirement<Player>[] joinRequirements = DEFAULT_REQUIREMENTS;
private Action<Player>[] skipActions = DEFAULT_SKIP_ACTIONS;
private Action<Player>[] startActions = DEFAULT_START_ACTIONS;
private Action<Player>[] endActions = DEFAULT_END_ACTIONS;
private Action<Player>[] joinActions = DEFAULT_JOIN_ACTIONS;
private HashMap<String, Action<Player>[]> rewards = DEFAULT_REWARDS;
private BossBarConfig bossBarConfig;
private ActionBarConfig actionBarConfig;
@Override
public Builder key(String key) {
this.key = key;
return this;
}
@Override
public Builder goal(CompetitionGoal goal) {
this.goal = goal;
return this;
}
@Override
public Builder duration(int duration) {
this.duration = duration;
return this;
}
@Override
public Builder minPlayers(int minPlayers) {
this.minPlayers = minPlayers;
return this;
}
@Override
public Builder joinRequirements(Requirement<Player>[] joinRequirements) {
this.joinRequirements = joinRequirements;
return this;
}
@Override
public Builder skipActions(Action<Player>[] skipActions) {
this.skipActions = skipActions;
return this;
}
@Override
public Builder startActions(Action<Player>[] startActions) {
this.startActions = startActions;
return this;
}
@Override
public Builder endActions(Action<Player>[] endActions) {
this.endActions = endActions;
return this;
}
@Override
public Builder joinActions(Action<Player>[] joinActions) {
this.joinActions = joinActions;
return this;
}
@Override
public Builder rewards(HashMap<String, Action<Player>[]> rewards) {
this.rewards = rewards;
return this;
}
@Override
public Builder bossBarConfig(BossBarConfig bossBarConfig) {
this.bossBarConfig = bossBarConfig;
return this;
}
@Override
public Builder actionBarConfig(ActionBarConfig actionBarConfig) {
this.actionBarConfig = actionBarConfig;
return this;
}
@Override
public CompetitionConfig build() {
return new CompetitionConfigImpl(key, goal, duration, minPlayers, joinRequirements, skipActions, startActions, endActions, joinActions, rewards, bossBarConfig, actionBarConfig);
}
}
}

View File

@@ -17,17 +17,115 @@
package net.momirealms.customfishing.api.mechanic.competition;
import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.util.Index;
import net.momirealms.customfishing.common.locale.MessageConstants;
import net.momirealms.customfishing.common.locale.TranslationManager;
import net.momirealms.customfishing.common.util.RandomUtils;
import org.apache.logging.log4j.util.Supplier;
import org.apache.logging.log4j.util.TriConsumer;
import org.bukkit.entity.Player;
public enum CompetitionGoal {
import java.util.Optional;
CATCH_AMOUNT,
TOTAL_SCORE,
MAX_SIZE,
TOTAL_SIZE,
RANDOM;
public final class CompetitionGoal {
public static final CompetitionGoal CATCH_AMOUNT = new CompetitionGoal(
"catch_amount",
((rankingProvider, player, score) -> rankingProvider.refreshData(player, 1)),
() -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_CATCH_AMOUNT.build().key())).orElse("catch_amount")
);
public static final CompetitionGoal TOTAL_SCORE = new CompetitionGoal(
"total_score",
(RankingProvider::refreshData),
() -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_TOTAL_SCORE.build().key())).orElse("total_score")
);
public static final CompetitionGoal MAX_SIZE = new CompetitionGoal(
"max_size",
((rankingProvider, player, score) -> {
if (rankingProvider.getPlayerScore(player) < score) {
rankingProvider.setData(player, score);
}
}),
() -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_MAX_SIZE.build().key())).orElse("max_size")
);
public static final CompetitionGoal MIN_SIZE = new CompetitionGoal(
"min_size",
((rankingProvider, player, score) -> {
if (rankingProvider.getPlayerScore(player) > score) {
rankingProvider.setData(player, score);
}
}),
() -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_MIN_SIZE.build().key())).orElse("min_size")
);
public static final CompetitionGoal TOTAL_SIZE = new CompetitionGoal(
"total_size",
(RankingProvider::refreshData),
() -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_TOTAL_SIZE.build().key())).orElse("total_size")
);
public static final CompetitionGoal RANDOM = new CompetitionGoal(
"random",
(rankingProvider, player, score) -> {},
() -> "random"
);
private static final CompetitionGoal[] values = new CompetitionGoal[] {
CATCH_AMOUNT, TOTAL_SCORE, MAX_SIZE, TOTAL_SIZE, RANDOM
};
private static final Index<String, CompetitionGoal> index = Index.create(CompetitionGoal::key, values());
/**
* Gets an array containing all defined competition goals.
*
* @return An array of all competition goals.
*/
public static CompetitionGoal[] values() {
return values;
}
/**
* Gets the index of competition goals by their keys.
*
* @return An index mapping keys to competition goals.
*/
public static Index<String, CompetitionGoal> index() {
return index;
}
/**
* Gets a randomly selected competition goal.
*
* @return A randomly selected competition goal.
*/
public static CompetitionGoal getRandom() {
return CompetitionGoal.values()[ThreadLocalRandom.current().nextInt(CompetitionGoal.values().length - 1)];
return CompetitionGoal.values()[RandomUtils.generateRandomInt(0, values.length - 1)];
}
private final String key;
private final TriConsumer<RankingProvider, String, Double> scoreConsumer;
private final Supplier<String> nameSupplier;
private CompetitionGoal(String key, TriConsumer<RankingProvider, String, Double> scoreConsumer, Supplier<String> nameSupplier) {
this.key = key;
this.scoreConsumer = scoreConsumer;
this.nameSupplier = nameSupplier;
}
/**
* Gets the key representing this competition goal.
*
* @return The key of the competition goal.
*/
public String key() {
return key;
}
public void refreshScore(RankingProvider ranking, Player player, Double score) {
scoreConsumer.accept(ranking, player.getName(), score);
}
@Override
public String toString() {
return nameSupplier.get();
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) <2022> <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.mechanic.competition;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public interface CompetitionManager extends Reloadable {
boolean startCompetition(String competition, boolean force, @Nullable String serverGroup);
boolean startCompetition(CompetitionConfig config, boolean force, @Nullable String serverGroup);
@Nullable
FishingCompetition getOnGoingCompetition();
int getNextCompetitionInSeconds();
@Nullable
CompetitionConfig getCompetition(String key);
Collection<String> getCompetitionIDs();
}

View File

@@ -19,52 +19,98 @@ package net.momirealms.customfishing.api.mechanic.competition;
import org.jetbrains.annotations.NotNull;
/**
* Represents a player participating in a fishing competition.
*/
public class CompetitionPlayer implements Comparable<CompetitionPlayer> {
public static CompetitionPlayer empty = new CompetitionPlayer("", 0);
private long time;
private final String player;
private long time;
private double score;
/**
* Constructs a new CompetitionPlayer with the specified player name and initial score.
*
* @param player the name of the player.
* @param score the initial score of the player.
*/
public CompetitionPlayer(String player, double score) {
this.player = player;
this.score = score;
this.time = System.currentTimeMillis();
}
/**
* Adds the specified score to the player's current score.
* If the added score is positive, updates the player's time to the current time.
*
* @param score the score to add.
*/
public void addScore(double score) {
this.score += score;
if (score <= 0) return;
this.time = System.currentTimeMillis();
}
/**
* Sets the player's score to the specified value and updates the player's time to the current time.
*
* @param score the new score for the player.
*/
public void setScore(double score) {
this.score = score;
this.time = System.currentTimeMillis();
}
/**
* Gets the time when the player's score was last updated.
*
* @return the last update time in milliseconds.
*/
public long getTime() {
return time;
return this.time;
}
/**
* Gets the player's current score.
*
* @return the current score.
*/
public double getScore() {
return this.score;
}
/**
* Gets the name of the player.
*
* @return the player's name.
*/
public String getPlayer() {
return this.player;
}
/**
* Compares this player to another CompetitionPlayer for ordering.
* Players are compared first by score, then by time if scores are equal.
*
* @param another the other player to compare to.
*/
@Override
public int compareTo(@NotNull CompetitionPlayer competitionPlayer) {
if (competitionPlayer.getScore() != this.score) {
return (competitionPlayer.getScore() > this.score) ? 1 : -1;
} else if (competitionPlayer.getTime() != this.time) {
return (competitionPlayer.getTime() > this.time) ? 1 : -1;
public int compareTo(@NotNull CompetitionPlayer another) {
if (another.getScore() != this.score) {
return (another.getScore() > this.score) ? 1 : -1;
} else if (another.getTime() != this.time) {
return (another.getTime() > this.time) ? 1 : -1;
} else {
return 0;
}
}
/**
* Returns a string representation of the CompetitionPlayer.
*
* @return a string containing the player's name, score, and last update time.
*/
@Override
public String toString() {
return "CompetitionPlayer[" +

View File

@@ -17,19 +17,17 @@
package net.momirealms.customfishing.api.mechanic.competition;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
public interface FishingCompetition {
/**
* Start the fishing competition
*/
void start();
void start(boolean triggerEvent);
/**
* Stop the fishing competition
@@ -91,34 +89,29 @@ public interface FishingCompetition {
*
* @return The configuration of the fishing competition.
*/
@NotNull CompetitionConfig getConfig();
@NotNull
CompetitionConfig getConfig();
/**
* Gets the goal of the fishing competition.
*
* @return The goal of the fishing competition.
*/
@NotNull CompetitionGoal getGoal();
@NotNull
CompetitionGoal getGoal();
/**
* Gets the ranking data for the fishing competition.
*
* @return The ranking data for the fishing competition.
*/
@NotNull Ranking getRanking();
@NotNull
RankingProvider getRanking();
/**
* Gets the cached placeholders for the fishing competition.
* Get the public context
*
* @return A ConcurrentHashMap containing cached placeholders.
* @return public context
*/
@NotNull Map<String, String> getCachedPlaceholders();
/**
* Gets a specific cached placeholder value by its key.
*
* @param papi The key of the cached placeholder.
* @return The cached placeholder value as a string, or null if not found.
*/
@Nullable String getCachedPlaceholder(String papi);
Context<Player> getPublicContext();
}

View File

@@ -17,12 +17,12 @@
package net.momirealms.customfishing.api.mechanic.competition;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.common.util.Pair;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;
public interface Ranking {
public interface RankingProvider {
/**
* Clears the list of competition players.
@@ -62,9 +62,9 @@ public interface Ranking {
void removePlayer(String player);
/**
* Returns an iterator for iterating over pairs of player names and scores.
* Returns an iterator for iterating over items of player names and scores.
*
* @return An iterator for pairs of player names and scores.
* @return An iterator for items of player names and scores.
*/
Iterator<Pair<String, Double>> getIterator();

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.competition;
package net.momirealms.customfishing.api.mechanic.competition.info;
/**
* Abstract base class for competition information.
@@ -27,13 +27,22 @@ public abstract class AbstractCompetitionInfo {
protected int switchInterval;
protected boolean showToAll;
protected String[] texts;
protected boolean enabled;
protected AbstractCompetitionInfo(boolean enabled, int refreshRate, int switchInterval, boolean showToAll, String[] texts) {
this.refreshRate = refreshRate;
this.switchInterval = switchInterval;
this.showToAll = showToAll;
this.texts = texts;
this.enabled = enabled;
}
/**
* Get the refresh rate for updating competition information.
*
* @return The refresh rate in ticks.
*/
public int getRefreshRate() {
public int refreshRate() {
return refreshRate;
}
@@ -42,7 +51,7 @@ public abstract class AbstractCompetitionInfo {
*
* @return The switch interval in ticks.
*/
public int getSwitchInterval() {
public int switchInterval() {
return switchInterval;
}
@@ -51,7 +60,7 @@ public abstract class AbstractCompetitionInfo {
*
* @return True if information is shown to all players, otherwise only to participants.
*/
public boolean isShowToAll() {
public boolean showToAll() {
return showToAll;
}
@@ -60,7 +69,16 @@ public abstract class AbstractCompetitionInfo {
*
* @return An array of competition information texts.
*/
public String[] getTexts() {
public String[] texts() {
return texts;
}
/**
* If the feature is enabled.
*
* @return enabled or not.
*/
public boolean enabled() {
return enabled;
}
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright (C) <2022> <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.mechanic.competition.info;
public interface ActionBarConfig {
int DEFAULT_REFRESH_RATE = 20;
int DEFAULT_SWITCH_INTERVAL = 200;
boolean DEFAULT_VISIBILITY = true;
String[] DEFAULT_TEXTS = new String[]{""};
/**
* Get the refresh rate for updating the competition information on the action bar.
*
* @return The refresh rate in ticks.
*/
int refreshRate();
/**
* Get the switch interval for displaying different competition texts.
*
* @return The switch interval in ticks.
*/
int switchInterval();
/**
* Check if competition information should be shown to all players.
*
* @return True if information is shown to all players, otherwise only to participants.
*/
boolean showToAll();
/**
* Get an array of competition information texts.
*
* @return An array of competition information texts.
*/
String[] texts();
/**
* Is action bar enabled
*
* @return enabled or not
*/
boolean enabled();
/**
* Creates a new builder instance for constructing {@code ActionBarConfig} objects.
*
* @return A new {@code Builder} instance.
*/
static Builder builder() {
return new ActionBarConfigImpl.BuilderImpl();
}
/**
* Builder interface for constructing {@code ActionBarConfig} objects.
*/
interface Builder {
/**
* Sets whether the competition information should be shown to all players.
*
* @param showToAll True to show information to all players, false to show only to participants.
* @return The current {@code Builder} instance.
*/
Builder showToAll(boolean showToAll);
/**
* Sets the refresh rate for updating the competition information.
*
* @param rate The refresh rate in ticks.
* @return The current {@code Builder} instance.
*/
Builder refreshRate(int rate);
/**
* Sets the interval for switching between different competition texts.
*
* @param interval The switch interval in ticks.
* @return The current {@code Builder} instance.
*/
Builder switchInterval(int interval);
/**
* Sets the texts to be displayed on the action bar during the competition.
*
* @param texts An array of competition information texts.
* @return The current {@code Builder} instance.
*/
Builder text(String[] texts);
Builder enable(boolean enable);
/**
* Builds the {@code ActionBarConfig} object with the configured settings.
*
* @return The constructed {@code ActionBarConfig} object.
*/
ActionBarConfig build();
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) <2022> <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.mechanic.competition.info;
public class ActionBarConfigImpl extends AbstractCompetitionInfo implements ActionBarConfig {
public ActionBarConfigImpl(boolean enable, int refreshRate, int switchInterval, boolean showToAll, String[] texts) {
super(enable, refreshRate, switchInterval, showToAll, texts);
}
public static class BuilderImpl implements Builder {
private int refreshRate = DEFAULT_REFRESH_RATE;
private int switchInterval = DEFAULT_SWITCH_INTERVAL;
private boolean showToAll = DEFAULT_VISIBILITY;
private String[] texts = DEFAULT_TEXTS;
private boolean enable = true;
@Override
public Builder showToAll(boolean showToAll) {
this.showToAll = showToAll;
return this;
}
@Override
public Builder refreshRate(int rate) {
this.refreshRate = rate;
return this;
}
@Override
public Builder switchInterval(int interval) {
this.switchInterval = interval;
return this;
}
@Override
public Builder text(String[] texts) {
this.texts = texts;
return this;
}
@Override
public Builder enable(boolean enable) {
this.enable = enable;
return this;
}
@Override
public ActionBarConfig build() {
return new ActionBarConfigImpl(enable, refreshRate, switchInterval, showToAll, texts);
}
}
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (C) <2022> <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.mechanic.competition.info;
import net.kyori.adventure.bossbar.BossBar;
public interface BossBarConfig {
int DEFAULT_REFRESH_RATE = 20;
int DEFAULT_SWITCH_INTERVAL = 200;
boolean DEFAULT_VISIBILITY = true;
String[] DEFAULT_TEXTS = new String[]{""};
BossBar.Color DEFAULT_COLOR = BossBar.Color.BLUE;
BossBar.Overlay DEFAULT_OVERLAY = BossBar.Overlay.PROGRESS;
/**
* Get the refresh rate for updating competition information.
*
* @return The refresh rate in ticks.
*/
int refreshRate();
/**
* Get the switch interval for displaying different competition texts.
*
* @return The switch interval in ticks.
*/
int switchInterval();
/**
* Check if competition information should be shown to all players.
*
* @return True if information is shown to all players, otherwise only to participants.
*/
boolean showToAll();
/**
* Get an array of competition information texts.
*
* @return An array of competition information texts.
*/
String[] texts();
/**
* Gets the color of the boss bar.
*
* @return The color of the boss bar.
*/
BossBar.Color color();
/**
* Gets the overlay style of the boss bar.
*
* @return The overlay style of the boss bar.
*/
BossBar.Overlay overlay();
/**
* Is boss bar enabled
*
* @return enabled or not
*/
boolean enabled();
/**
* Creates a new builder instance for constructing {@code BossBarConfig} objects.
*
* @return A new {@code Builder} instance.
*/
static Builder builder() {
return new BossBarConfigImpl.BuilderImpl();
}
/**
* Builder interface for constructing {@code BossBarConfig} objects.
*/
interface Builder {
/**
* Sets whether the competition information should be shown to all players.
*
* @param showToAll True to show information to all players, false to show only to participants.
* @return The current {@code Builder} instance.
*/
Builder showToAll(boolean showToAll);
/**
* Sets the refresh rate for updating the competition information.
*
* @param rate The refresh rate in ticks.
* @return The current {@code Builder} instance.
*/
Builder refreshRate(int rate);
/**
* Sets the interval for switching between different competition texts.
*
* @param interval The switch interval in ticks.
* @return The current {@code Builder} instance.
*/
Builder switchInterval(int interval);
/**
* Sets the texts to be displayed on the boss bar during the competition.
*
* @param texts An array of competition information texts.
* @return The current {@code Builder} instance.
*/
Builder text(String[] texts);
/**
* Sets the color of the boss bar.
*
* @param color The color of the boss bar.
* @return The current {@code Builder} instance.
*/
Builder color(BossBar.Color color);
/**
* Sets the overlay style of the boss bar.
*
* @param overlay The overlay style of the boss bar.
* @return The current {@code Builder} instance.
*/
Builder overlay(BossBar.Overlay overlay);
Builder enable(boolean enable);
/**
* Builds the {@code BossBarConfig} object with the configured settings.
*
* @return The constructed {@code BossBarConfig} object.
*/
BossBarConfig build();
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (C) <2022> <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.mechanic.competition.info;
import net.kyori.adventure.bossbar.BossBar;
public class BossBarConfigImpl extends AbstractCompetitionInfo implements BossBarConfig {
private final BossBar.Color color;
private final BossBar.Overlay overlay;
public BossBarConfigImpl(boolean enable, int refreshRate, int switchInterval, boolean showToAll, String[] texts, BossBar.Color color, BossBar.Overlay overlay) {
super(enable, refreshRate, switchInterval, showToAll, texts);
this.color = color;
this.overlay = overlay;
}
@Override
public BossBar.Color color() {
return color;
}
@Override
public BossBar.Overlay overlay() {
return overlay;
}
public static class BuilderImpl implements Builder {
private int refreshRate = DEFAULT_REFRESH_RATE;
private int switchInterval = DEFAULT_SWITCH_INTERVAL;
private boolean showToAll = DEFAULT_VISIBILITY;
private String[] texts = DEFAULT_TEXTS;
private BossBar.Overlay overlay = DEFAULT_OVERLAY;
private BossBar.Color color = DEFAULT_COLOR;
private boolean enable = true;
@Override
public Builder showToAll(boolean showToAll) {
this.showToAll = showToAll;
return this;
}
@Override
public Builder refreshRate(int rate) {
this.refreshRate = rate;
return this;
}
@Override
public Builder switchInterval(int interval) {
this.switchInterval = interval;
return this;
}
@Override
public Builder text(String[] texts) {
this.texts = texts;
return this;
}
@Override
public Builder color(BossBar.Color color) {
this.color = color;
return this;
}
@Override
public Builder overlay(BossBar.Overlay overlay) {
this.overlay = overlay;
return this;
}
@Override
public Builder enable(boolean enable) {
this.enable = enable;
return this;
}
@Override
public BossBarConfig build() {
return new BossBarConfigImpl(enable, refreshRate, switchInterval, showToAll, texts, color, overlay);
}
}
}

View File

@@ -1,148 +0,0 @@
/*
* Copyright (C) <2022> <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.mechanic.condition;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
/**
* Represents a condition with associated data
*/
public class Condition {
protected Location location;
protected final Player player;
protected final @NotNull Map<String, String> args;
/**
* Creates a new Condition object based on a player's location.
*
* @param player The player associated with this condition.
*/
public Condition(@NotNull Player player) {
this(player.getLocation(), player, new HashMap<>());
}
/**
* Creates a new Condition object with specified arguments.
*
* @param player The player associated with this condition.
* @param args A map of arguments associated with this condition.
*/
public Condition(@NotNull Player player, @NotNull Map<String, String> args) {
this(player.getLocation(), player, args);
}
/**
* Creates a new Condition object with a specific location, player, and arguments.
*
* @param location The location associated with this condition.
* @param player The player associated with this condition.
* @param args A map of arguments associated with this condition.
*/
public Condition(Location location, Player player, @NotNull Map<String, String> args) {
this.location = location;
this.player = player;
this.args = args;
if (player != null)
this.args.put("{player}", player.getName());
if (location != null) {
this.args.put("{x}", String.valueOf(location.getX()));
this.args.put("{y}", String.valueOf(location.getY()));
this.args.put("{z}", String.valueOf(location.getZ()));
this.args.put("{world}", location.getWorld().getName());
}
}
/**
* Sets the location associated with this condition.
*
* @param location The new location to set.
*/
public void setLocation(@NotNull Location location) {
this.location = location;
this.args.put("{x}", String.valueOf(location.getX()));
this.args.put("{y}", String.valueOf(location.getY()));
this.args.put("{z}", String.valueOf(location.getZ()));
this.args.put("{world}", location.getWorld().getName());
}
/**
* Gets the location associated with this condition.
*
* @return The location associated with this condition.
*/
public Location getLocation() {
return location;
}
/**
* Gets the player associated with this condition.
*
* @return The player associated with this condition.
*/
public Player getPlayer() {
return player;
}
/**
* Gets the map of arguments associated with this condition.
*
* @return A map of arguments associated with this condition.
*/
@NotNull
public Map<String, String> getArgs() {
return args;
}
/**
* Gets the value of a specific argument by its key.
*
* @param key The key of the argument to retrieve.
* @return The value of the argument or null if not found.
*/
@Nullable
public String getArg(String key) {
return args.get(key);
}
/**
* Inserts or updates an argument with the specified key and value.
*
* @param key The key of the argument to insert or update.
* @param value The value to set for the argument.
*/
public void insertArg(String key, String value) {
args.put(key, value);
}
/**
* Deletes an argument with the specified key.
*
* @param key The key of the argument to delete.
* @return The value of the deleted argument or null if not found.
*/
public String delArg(String key) {
return args.remove(key);
}
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright (C) <2022> <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.mechanic.condition;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.effect.FishingEffect;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class FishingPreparation extends Condition {
public FishingPreparation(Player player) {
super(player);
}
/**
* Retrieves the ItemStack representing the fishing rod.
*
* @return The ItemStack representing the fishing rod.
*/
@NotNull
public abstract ItemStack getRodItemStack();
/**
* Retrieves the ItemStack representing the bait (if available).
*
* @return The ItemStack representing the bait, or null if no bait is set.
*/
@Nullable
public abstract ItemStack getBaitItemStack();
/**
* Checks if player meet the requirements for fishing gears
*
* @return True if can fish, false otherwise.
*/
public abstract boolean canFish();
/**
* Merges a FishingEffect into this fishing rod, applying effect modifiers.
*
* @param effect The FishingEffect to merge into this rod.
*/
public abstract void mergeEffect(FishingEffect effect);
/**
* Triggers actions associated with a specific action trigger.
*
* @param actionTrigger The action trigger that initiates the actions.
*/
public abstract void triggerActions(ActionTrigger actionTrigger);
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
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.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class BaitConfigParser {
private final String id;
private final String material;
private final List<PriorityFunction<BiConsumer<Item<ItemStack>, Context<Player>>>> tagConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> baseEffectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
public BaitConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
this.material = section.getString("material");
if (!section.contains("tag")) section.set("tag", true);
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
baseEffectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case ITEM -> {
ItemParserFunction propertyFunction = (ItemParserFunction) function;
BiConsumer<Item<ItemStack>, Context<Player>> result = propertyFunction.accept(entry.getValue());
tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result));
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public CustomFishingItem getItem() {
return CustomFishingItem.builder()
.material(material)
.id(id)
.tagConsumers(tagConsumers)
.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.BAIT);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.BAIT);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : baseEffectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.ITEM)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.block.BlockConfig;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public class BlockConfigParser {
private final String id;
private final List<Consumer<BlockConfig.Builder>> blockBuilderConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
public BlockConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case BLOCK -> {
BlockParserFunction blockParserFunction = (BlockParserFunction) function;
Consumer<BlockConfig.Builder> consumer = blockParserFunction.accept(entry.getValue());
blockBuilderConsumers.add(consumer);
}
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public BlockConfig getBlock() {
BlockConfig.Builder builder = BlockConfig.builder()
.id(id);
for (Consumer<BlockConfig.Builder> consumer : blockBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.BLOCK)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.BLOCK);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,386 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
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.Effect;
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;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import net.momirealms.customfishing.api.mechanic.totem.TotemConfig;
import net.momirealms.customfishing.common.config.ConfigLoader;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import net.momirealms.customfishing.common.util.Pair;
import net.momirealms.customfishing.common.util.TriConsumer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
public abstract class ConfigManager implements ConfigLoader, Reloadable {
private static ConfigManager instance;
protected final BukkitCustomFishingPlugin plugin;
protected final HashMap<String, Node<ConfigParserFunction>> formatFunctions = new HashMap<>();
protected int placeholderLimit;
protected boolean redisRanking;
protected String serverGroup;
protected String[] itemDetectOrder = new String[0];
protected String[] blockDetectOrder = new String[0];
protected int dataSaveInterval;
protected boolean logDataSaving;
protected boolean lockData;
protected boolean metrics;
protected boolean checkUpdate;
protected boolean debug;
protected boolean overrideVanillaWaitTime;
protected int waterMinTime;
protected int waterMaxTime;
protected boolean enableLavaFishing;
protected int lavaMinTime;
protected int lavaMaxTime;
protected boolean enableVoidFishing;
protected int voidMinTime;
protected int voidMaxTime;
protected int multipleLootSpawnDelay;
protected boolean restrictedSizeRange;
protected List<String> durabilityLore;
protected boolean allowMultipleTotemType;
protected boolean allowSameTotemType;
protected EventPriority eventPriority;
protected Requirement<Player>[] mechanicRequirements;
protected Requirement<Player>[] skipGameRequirements;
protected Requirement<Player>[] autoFishingRequirements;
protected boolean enableBag;
protected boolean baitAnimation;
protected List<TriConsumer<Effect, Context<Player>, Integer>> globalEffects;
protected ConfigManager(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
instance = this;
}
public static boolean debug() {
return instance.debug;
}
public static int placeholderLimit() {
return instance.placeholderLimit;
}
public static boolean redisRanking() {
return instance.redisRanking;
}
public static String serverGroup() {
return instance.serverGroup;
}
public static String[] itemDetectOrder() {
return instance.itemDetectOrder;
}
public static String[] blockDetectOrder() {
return instance.blockDetectOrder;
}
public static int dataSaveInterval() {
return instance.dataSaveInterval;
}
public static boolean logDataSaving() {
return instance.logDataSaving;
}
public static boolean lockData() {
return instance.lockData;
}
public static boolean metrics() {
return instance.metrics;
}
public static boolean checkUpdate() {
return instance.checkUpdate;
}
public static boolean overrideVanillaWaitTime() {
return instance.overrideVanillaWaitTime;
}
public static int waterMinTime() {
return instance.waterMinTime;
}
public static int waterMaxTime() {
return instance.waterMaxTime;
}
public static boolean enableLavaFishing() {
return instance.enableLavaFishing;
}
public static int lavaMinTime() {
return instance.lavaMinTime;
}
public static int lavaMaxTime() {
return instance.lavaMaxTime;
}
public static boolean enableVoidFishing() {
return instance.enableVoidFishing;
}
public static int voidMinTime() {
return instance.voidMinTime;
}
public static int voidMaxTime() {
return instance.voidMaxTime;
}
public static int multipleLootSpawnDelay() {
return instance.multipleLootSpawnDelay;
}
public static boolean restrictedSizeRange() {
return instance.restrictedSizeRange;
}
public static boolean allowMultipleTotemType() {
return instance.allowMultipleTotemType;
}
public static boolean allowSameTotemType() {
return instance.allowSameTotemType;
}
public static boolean enableBag() {
return instance.enableBag;
}
public static boolean baitAnimation() {
return instance.baitAnimation;
}
public static List<String> durabilityLore() {
return instance.durabilityLore;
}
public static EventPriority eventPriority() {
return instance.eventPriority;
}
public static Requirement<Player>[] mechanicRequirements() {
return instance.mechanicRequirements;
}
public static Requirement<Player>[] autoFishingRequirements() {
return instance.autoFishingRequirements;
}
public static Requirement<Player>[] skipGameRequirements() {
return instance.skipGameRequirements;
}
public static List<TriConsumer<Effect, Context<Player>, Integer>> globalEffects() {
return instance.globalEffects;
}
public void registerHookParser(Function<Object, Consumer<HookConfig.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new HookParserFunction(function));
}
public void registerTotemParser(Function<Object, Consumer<TotemConfig.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new TotemParserFunction(function));
}
public void registerLootParser(Function<Object, Consumer<Loot.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new LootParserFunction(function));
}
public void registerItemParser(Function<Object, BiConsumer<Item<ItemStack>, Context<Player>>> function, int priority, String... nodes) {
registerNodeFunction(nodes, new ItemParserFunction(priority, function));
}
public void registerEffectModifierParser(Function<Object, Consumer<EffectModifier.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new EffectModifierParserFunction(function));
}
public void registerEntityParser(Function<Object, Consumer<EntityConfig.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new EntityParserFunction(function));
}
public void registerEventParser(Function<Object, Consumer<EventCarrier.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new EventParserFunction(function));
}
public void registerBaseEffectParser(Function<Object, Consumer<LootBaseEffect.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new BaseEffectParserFunction(function));
}
public void unregisterNodeFunction(String... nodes) {
Map<String, Node<ConfigParserFunction>> functionMap = formatFunctions;
for (int i = 0; i < nodes.length; i++) {
if (functionMap.containsKey(nodes[i])) {
Node<ConfigParserFunction> functionNode = functionMap.get(nodes[i]);
if (i != nodes.length - 1) {
if (functionNode.nodeValue() != null) {
return;
} else {
functionMap = functionNode.getChildTree();
}
} else {
if (functionNode.nodeValue() != null) {
functionMap.remove(nodes[i]);
}
}
}
}
}
public void registerNodeFunction(String[] nodes, ConfigParserFunction configParserFunction) {
Map<String, Node<ConfigParserFunction>> functionMap = formatFunctions;
for (int i = 0; i < nodes.length; i++) {
if (functionMap.containsKey(nodes[i])) {
Node<ConfigParserFunction> functionNode = functionMap.get(nodes[i]);
if (functionNode.nodeValue() != null) {
throw new IllegalArgumentException("Format function '" + nodes[i] + "' already exists");
}
functionMap = functionNode.getChildTree();
} else {
if (i != nodes.length - 1) {
Node<ConfigParserFunction> newNode = new Node<>();
functionMap.put(nodes[i], newNode);
functionMap = newNode.getChildTree();
} else {
functionMap.put(nodes[i], new Node<>(configParserFunction));
}
}
}
}
protected Path resolveConfig(String filePath) {
if (filePath == null || filePath.isEmpty()) {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}
filePath = filePath.replace('\\', '/');
Path configFile = plugin.getConfigDirectory().resolve(filePath);
// if the config doesn't exist, create it based on the template in the resources dir
if (!Files.exists(configFile)) {
try {
Files.createDirectories(configFile.getParent());
} catch (IOException e) {
// ignore
}
try (InputStream is = plugin.getResourceStream(filePath)) {
if (is == null) {
throw new IllegalArgumentException("The embedded resource '" + filePath + "' cannot be found");
}
Files.copy(is, configFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return configFile;
}
@Override
public YamlDocument loadConfig(String filePath) {
return loadConfig(filePath, '.');
}
@Override
public YamlDocument loadConfig(String filePath, char routeSeparator) {
try (InputStream inputStream = new FileInputStream(resolveConfig(filePath).toFile())) {
return YamlDocument.create(
inputStream,
plugin.getResourceStream(filePath),
GeneralSettings.builder().setRouteSeparator(routeSeparator).build(),
LoaderSettings
.builder()
.setAutoUpdate(true)
.build(),
DumperSettings.DEFAULT,
UpdaterSettings
.builder()
.setVersioning(new BasicVersioning("config-version"))
.build()
);
} catch (IOException e) {
plugin.getPluginLogger().severe("Failed to load config " + filePath, e);
throw new RuntimeException(e);
}
}
@Override
public YamlDocument loadData(File file) {
try (InputStream inputStream = new FileInputStream(file)) {
return YamlDocument.create(inputStream);
} catch (IOException e) {
plugin.getPluginLogger().severe("Failed to load config " + file, e);
throw new RuntimeException(e);
}
}
@Override
public YamlDocument loadData(File file, char routeSeparator) {
try (InputStream inputStream = new FileInputStream(file)) {
return YamlDocument.create(inputStream, GeneralSettings.builder().setRouteSeparator(routeSeparator).build());
} catch (IOException e) {
plugin.getPluginLogger().severe("Failed to load config " + file, e);
throw new RuntimeException(e);
}
}
public Map<String, Node<ConfigParserFunction>> getFormatFunctions() {
return formatFunctions;
}
public abstract List<Pair<String, BiFunction<Context<Player>, Double, Double>>> parseWeightOperation(List<String> ops);
public abstract List<Pair<String, BiFunction<Context<Player>, Double, Double>>> parseGroupWeightOperation(List<String> gops);
}

View File

@@ -0,0 +1,169 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.common.config.node.Node;
import org.apache.logging.log4j.util.TriConsumer;
import java.util.Map;
public class ConfigType {
public static final ConfigType ITEM = of(
"item",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.LOOT);
ItemConfigParser config = new ItemConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem());
BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType ENTITY = of(
"entity",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.ENTITY);
EntityConfigParser config = new EntityConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getEntityManager().registerEntity(config.getEntity());
BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType BLOCK = of(
"block",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.BLOCK);
BlockConfigParser config = new BlockConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getBlockManager().registerBlock(config.getBlock());
BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType ROD = of(
"rod",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.ROD);
RodConfigParser config = new RodConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem());
//BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.ROD);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType BAIT = of(
"bait",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.BAIT);
BaitConfigParser config = new BaitConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem());
//BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.BAIT);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType HOOK = of(
"hook",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.HOOK);
HookConfigParser config = new HookConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem());
//BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.HOOK);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
BukkitCustomFishingPlugin.getInstance().getHookManager().registerHook(config.getHook());
}
);
public static final ConfigType UTIL = of(
"util",
(id, section, functions) -> {
MechanicType.register(id, MechanicType.UTIL);
UtilConfigParser config = new UtilConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem());
//BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot());
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.UTIL);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType TOTEM = of(
"totem",
(id, section, functions) -> {
TotemConfigParser config = new TotemConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.TOTEM);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
BukkitCustomFishingPlugin.getInstance().getTotemManager().registerTotem(config.getTotemConfig());
}
);
public static final ConfigType ENCHANT = of(
"enchant",
(id, section, functions) -> {
EnchantConfigParser config = new EnchantConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.ENCHANT);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
public static final ConfigType MINI_GAME = of(
"minigame",
(id, section, functions) -> {
MiniGameConfigParser config = new MiniGameConfigParser(id, section);
BukkitCustomFishingPlugin.getInstance().getGameManager().registerGame(config.getGame());
}
);
private static final ConfigType[] values = new ConfigType[] {ITEM, ENTITY, BLOCK, HOOK, ROD, BAIT, UTIL, TOTEM, ENCHANT, MINI_GAME};
public static ConfigType[] values() {
return values;
}
private final String path;
private TriConsumer<String, Section, Map<String, Node<ConfigParserFunction>>> argumentConsumer;
public ConfigType(String path, TriConsumer<String, Section, Map<String, Node<ConfigParserFunction>>> argumentConsumer) {
this.path = path;
this.argumentConsumer = argumentConsumer;
}
public void argumentConsumer(TriConsumer<String, Section, Map<String, Node<ConfigParserFunction>>> argumentConsumer) {
this.argumentConsumer = argumentConsumer;
}
public static ConfigType of(String path, TriConsumer<String, Section, Map<String, Node<ConfigParserFunction>>> argumentConsumer) {
return new ConfigType(path, argumentConsumer);
}
public void parse(String id, Section section, Map<String, Node<ConfigParserFunction>> functions) {
argumentConsumer.accept(id, section, functions);
}
public String path() {
return path;
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EffectModifierParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EventParserFunction;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.common.config.node.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public class EnchantConfigParser {
private final String id;
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
public EnchantConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.ENCHANT);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.ENCHANT);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
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.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public class EntityConfigParser {
private final String id;
private final List<Consumer<EntityConfig.Builder>> entityBuilderConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
public EntityConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case ENTITY -> {
EntityParserFunction entityParserFunction = (EntityParserFunction) function;
Consumer<EntityConfig.Builder> consumer = entityParserFunction.accept(entry.getValue());
entityBuilderConsumers.add(consumer);
}
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public EntityConfig getEntity() {
EntityConfig.Builder builder = EntityConfig.builder()
.id(id);
for (Consumer<EntityConfig.Builder> consumer : entityBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.ENTITY)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.ENTITY);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.ItemParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.PriorityFunction;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
public class GUIItemParser {
private final String id;
private final String material;
private final List<PriorityFunction<BiConsumer<Item<ItemStack>, Context<Player>>>> tagConsumers = new ArrayList<>();
public GUIItemParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
this.material = section.getString("material");
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
if (function instanceof ItemParserFunction propertyFunction) {
BiConsumer<Item<ItemStack>, Context<Player>> result = propertyFunction.accept(entry.getValue());
tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result));
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public CustomFishingItem getItem() {
return CustomFishingItem.builder()
.material(material)
.id(id)
.tagConsumers(tagConsumers)
.build();
}
}

View File

@@ -0,0 +1,163 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
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.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.hook.HookConfig;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class HookConfigParser {
private final String id;
private final String material;
private final List<PriorityFunction<BiConsumer<Item<ItemStack>, Context<Player>>>> tagConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<HookConfig.Builder>> hookBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> baseEffectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
public HookConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
this.material = section.getString("material");
if (!section.contains("tag")) section.set("tag", true);
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
baseEffectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case ITEM -> {
ItemParserFunction propertyFunction = (ItemParserFunction) function;
BiConsumer<Item<ItemStack>, Context<Player>> result = propertyFunction.accept(entry.getValue());
tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result));
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
case HOOK -> {
HookParserFunction hookParserFunction = (HookParserFunction) function;
Consumer<HookConfig.Builder> consumer = hookParserFunction.accept(entry.getValue());
hookBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public CustomFishingItem getItem() {
return CustomFishingItem.builder()
.material(material)
.id(id)
.tagConsumers(tagConsumers)
.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.HOOK);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.HOOK);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public HookConfig getHook() {
HookConfig.Builder builder = HookConfig.builder()
.id(id);
for (Consumer<HookConfig.Builder> consumer : hookBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : baseEffectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.ITEM)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class ItemConfigParser {
private final String id;
private final String material;
private final List<PriorityFunction<BiConsumer<Item<ItemStack>, Context<Player>>>> tagConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
public ItemConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
this.material = section.getString("material");
if (!section.contains("tag")) section.set("tag", true);
if (!section.contains("nick")) {
if (section.contains("display.name")) {
section.set("nick", section.getString("display.name"));
}
}
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case ITEM -> {
ItemParserFunction propertyFunction = (ItemParserFunction) function;
BiConsumer<Item<ItemStack>, Context<Player>> result = propertyFunction.accept(entry.getValue());
tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result));
}
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public CustomFishingItem getItem() {
return CustomFishingItem.builder()
.material(material)
.id(id)
.tagConsumers(tagConsumers)
.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.ITEM)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.LOOT);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.game.Game;
import net.momirealms.customfishing.api.mechanic.game.GameFactory;
public class MiniGameConfigParser {
private final String id;
private Game game;
public MiniGameConfigParser(String id, Section section) {
this.id = id;
analyze(section);
}
private void analyze(Section section) {
String type = section.getString("game-type");
GameFactory factory = BukkitCustomFishingPlugin.getInstance().getGameManager().getGameFactory(type);
if (factory == null) {
throw new RuntimeException("Unknown game-type: " + type);
}
this.game = factory.create(id, section);
}
public Game getGame() {
return game;
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
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.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class RodConfigParser {
private final String id;
private final String material;
private final List<PriorityFunction<BiConsumer<Item<ItemStack>, Context<Player>>>> tagConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> baseEffectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
public RodConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
this.material = section.contains("material") ? section.getString("material") : Material.FISHING_ROD.name();
if (!section.contains("tag")) section.set("tag", true);
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
baseEffectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case ITEM -> {
ItemParserFunction propertyFunction = (ItemParserFunction) function;
BiConsumer<Item<ItemStack>, Context<Player>> result = propertyFunction.accept(entry.getValue());
tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result));
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public CustomFishingItem getItem() {
return CustomFishingItem.builder()
.material(material)
.id(id)
.tagConsumers(tagConsumers)
.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.ROD);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.ROD);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : baseEffectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.ITEM)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EffectModifierParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EventParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.TotemParserFunction;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.totem.TotemConfig;
import net.momirealms.customfishing.common.config.node.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public class TotemConfigParser {
private final String id;
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<TotemConfig.Builder>> totemBuilderConsumers = new ArrayList<>();
public TotemConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
case TOTEM -> {
TotemParserFunction totemParserFunction = (TotemParserFunction) function;
Consumer<TotemConfig.Builder> consumer = totemParserFunction.accept(entry.getValue());
totemBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.TOTEM);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.TOTEM);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public TotemConfig getTotemConfig() {
TotemConfig.Builder builder = TotemConfig.builder()
.id(id);
for (Consumer<TotemConfig.Builder> consumer : totemBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) <2022> <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.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
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.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class UtilConfigParser {
private final String id;
private final String material;
private final List<PriorityFunction<BiConsumer<Item<ItemStack>, Context<Player>>>> tagConsumers = new ArrayList<>();
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
private final List<Consumer<LootBaseEffect.Builder>> baseEffectBuilderConsumers = new ArrayList<>();
private final List<Consumer<Loot.Builder>> lootBuilderConsumers = new ArrayList<>();
public UtilConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
this.material = section.getString("material");
if (!section.contains("tag")) section.set("tag", true);
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case BASE_EFFECT -> {
BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function;
Consumer<LootBaseEffect.Builder> consumer = baseEffectParserFunction.accept(entry.getValue());
baseEffectBuilderConsumers.add(consumer);
}
case LOOT -> {
LootParserFunction lootParserFunction = (LootParserFunction) function;
Consumer<Loot.Builder> consumer = lootParserFunction.accept(entry.getValue());
lootBuilderConsumers.add(consumer);
}
case ITEM -> {
ItemParserFunction propertyFunction = (ItemParserFunction) function;
BiConsumer<Item<ItemStack>, Context<Player>> result = propertyFunction.accept(entry.getValue());
tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result));
}
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public CustomFishingItem getItem() {
return CustomFishingItem.builder()
.material(material)
.id(id)
.tagConsumers(tagConsumers)
.build();
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.UTIL);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
private LootBaseEffect getBaseEffect() {
LootBaseEffect.Builder builder = LootBaseEffect.builder();
for (Consumer<LootBaseEffect.Builder> consumer : baseEffectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public Loot getLoot() {
Loot.Builder builder = Loot.builder()
.id(id)
.type(LootType.ITEM)
.lootBaseEffect(getBaseEffect());
for (Consumer<Loot.Builder> consumer : lootBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import java.util.function.Consumer;
import java.util.function.Function;
public class BaseEffectParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<LootBaseEffect.Builder>> function;
public BaseEffectParserFunction(Function<Object, Consumer<LootBaseEffect.Builder>> function) {
this.function = function;
}
public Consumer<LootBaseEffect.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.BASE_EFFECT;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.block.BlockConfig;
import java.util.function.Consumer;
import java.util.function.Function;
public class BlockParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<BlockConfig.Builder>> function;
public BlockParserFunction(Function<Object, Consumer<BlockConfig.Builder>> function) {
this.function = function;
}
public Consumer<BlockConfig.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.BLOCK;
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
public interface ConfigParserFunction {
ParserType type();
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import java.util.function.Consumer;
import java.util.function.Function;
public class EffectModifierParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<EffectModifier.Builder>> function;
public EffectModifierParserFunction(Function<Object, Consumer<EffectModifier.Builder>> function) {
this.function = function;
}
public Consumer<EffectModifier.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.EFFECT_MODIFIER;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.entity.EntityConfig;
import java.util.function.Consumer;
import java.util.function.Function;
public class EntityParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<EntityConfig.Builder>> function;
public EntityParserFunction(Function<Object, Consumer<EntityConfig.Builder>> function) {
this.function = function;
}
public Consumer<EntityConfig.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.ENTITY;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import java.util.function.Consumer;
import java.util.function.Function;
public class EventParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<EventCarrier.Builder>> function;
public EventParserFunction(Function<Object, Consumer<EventCarrier.Builder>> function) {
this.function = function;
}
public Consumer<EventCarrier.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.EVENT;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.hook.HookConfig;
import java.util.function.Consumer;
import java.util.function.Function;
public class HookParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<HookConfig.Builder>> function;
public HookParserFunction(Function<Object, Consumer<HookConfig.Builder>> function) {
this.function = function;
}
public Consumer<HookConfig.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.HOOK;
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.common.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class ItemParserFunction implements ConfigParserFunction {
private final Function<Object, BiConsumer<Item<ItemStack>, Context<Player>>> function;
private final int priority;
public ItemParserFunction(int priority, Function<Object, BiConsumer<Item<ItemStack>, Context<Player>>> function) {
this.function = function;
this.priority = priority;
}
public BiConsumer<Item<ItemStack>, Context<Player>> accept(Object object) {
return function.apply(object);
}
public int getPriority() {
return priority;
}
@Override
public ParserType type() {
return ParserType.ITEM;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) <2022> <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.mechanic.config.function;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import java.util.function.Consumer;
import java.util.function.Function;
public class LootParserFunction implements ConfigParserFunction {
private final Function<Object, Consumer<Loot.Builder>> function;
public LootParserFunction(Function<Object, Consumer<Loot.Builder>> function) {
this.function = function;
}
public Consumer<Loot.Builder> accept(Object object) {
return function.apply(object);
}
@Override
public ParserType type() {
return ParserType.LOOT;
}
}

View File

@@ -15,13 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.misc;
package net.momirealms.customfishing.api.mechanic.config.function;
import org.bukkit.entity.Player;
import java.util.Map;
public interface Value {
double get(Player player, Map<String, String> values);
public enum ParserType {
ITEM,
EFFECT_MODIFIER,
BASE_EFFECT,
LOOT,
EVENT,
ENTITY,
HOOK,
BLOCK,
TOTEM
}

Some files were not shown because too many files have changed in this diff Show More