diff --git a/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java b/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java index 3e64b622..6827a778 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java +++ b/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java @@ -17,155 +17,34 @@ package net.momirealms.customfishing.api; -import net.momirealms.customfishing.api.integration.IntegrationManager; -import net.momirealms.customfishing.api.manager.*; -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.effect.EffectManager; -import net.momirealms.customfishing.api.mechanic.entity.EntityManager; -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.requirement.RequirementManager; -import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager; -import net.momirealms.customfishing.api.mechanic.totem.TotemManager; -import net.momirealms.customfishing.common.command.CustomFishingCommandManager; +import net.momirealms.customfishing.api.mechanic.config.ConfigManager; +import net.momirealms.customfishing.api.mechanic.event.EventManager; import net.momirealms.customfishing.common.plugin.CustomFishingPlugin; -import net.momirealms.customfishing.common.plugin.scheduler.SchedulerAdapter; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; -public abstract class BukkitCustomFishingPlugin extends JavaPlugin implements CustomFishingPlugin { - - protected boolean initialized; - protected SchedulerAdapter scheduler; - protected CustomFishingCommandManager 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 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; +public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin { private static BukkitCustomFishingPlugin instance; + protected EventManager eventManager; + protected ConfigManager configManager; + public BukkitCustomFishingPlugin() { instance = this; } - public static BukkitCustomFishingPlugin get() { - return getInstance(); - } - public static BukkitCustomFishingPlugin getInstance() { + if (instance == null) { + throw new IllegalArgumentException("Plugin not initialized"); + } return instance; } - public VersionManager getVersionManager() { - return versionManager; + public EventManager getEventManager() { + return eventManager; } - public RequirementManager getRequirementManager() { - return requirementManager; + @Override + public ConfigManager getConfigManager() { + return configManager; } - - 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); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/PlayerData.java b/api/src/main/java/net/momirealms/customfishing/api/data/PlayerData.java deleted file mode 100644 index 78e1c7b5..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/data/PlayerData.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.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; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/user/OnlineUser.java b/api/src/main/java/net/momirealms/customfishing/api/data/user/OnlineUser.java deleted file mode 100644 index a26fe65a..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/data/user/OnlineUser.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.data.user; - -import org.bukkit.entity.Player; - -public interface OnlineUser extends OfflineUser { - - /** - * Get the bukkit player - * - * @return player - */ - Player getPlayer(); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java deleted file mode 100644 index 7a539585..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/CompetitionEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; - -public class CompetitionEvent extends Event { - - private static final HandlerList handlerList = new HandlerList(); - private final State state; - private final FishingCompetition competition; - - public CompetitionEvent(State state, FishingCompetition competition) { - super(true); - this.state = state; - this.competition = competition; - } - - public State getState() { - return state; - } - - public FishingCompetition getCompetition() { - return competition; - } - - public static HandlerList getHandlerList() { - return handlerList; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - - public static enum State { - END, - STOP, - START - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java deleted file mode 100644 index 41defa68..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/CustomFishingReloadEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; - -public class CustomFishingReloadEvent extends Event { - - private static final HandlerList handlerList = new HandlerList(); - private final BukkitCustomFishingPlugin plugin; - - public CustomFishingReloadEvent(BukkitCustomFishingPlugin plugin) { - this.plugin = plugin; - } - - public static HandlerList getHandlerList() { - return handlerList; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - - public BukkitCustomFishingPlugin getPluginInstance() { - return plugin; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java deleted file mode 100644 index dc9a1daa..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import net.momirealms.customfishing.api.mechanic.effect.Effect; -import 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 final 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 - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java deleted file mode 100644 index 7883b947..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingBagPreCollectEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellable { - - private static final HandlerList handlerList = new HandlerList(); - private final ItemStack itemStack; - private boolean isCancelled; - private final Inventory bag; - - public FishingBagPreCollectEvent(@NotNull Player who, ItemStack itemStack, Inventory bag) { - super(who); - this.itemStack = itemStack; - this.isCancelled = false; - this.bag = bag; - } - - @Override - public boolean isCancelled() { - return isCancelled; - } - - @Override - public void setCancelled(boolean cancel) { - isCancelled = cancel; - } - - public ItemStack getItemStack() { - return itemStack; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } - - public static HandlerList getHandlerList() { - return handlerList; - } - - public Inventory getBagInventory() { - return bag; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootPreSpawnEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootPreSpawnEvent.java deleted file mode 100644 index 41409832..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootPreSpawnEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import org.bukkit.Location; -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 { - - private static final HandlerList handlerList = new HandlerList(); - private final Location location; - private final ItemStack itemStack; - private boolean isCancelled; - - public FishingLootPreSpawnEvent(@NotNull Player who, Location location, ItemStack itemStack) { - 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; - } - - public static HandlerList getHandlerList() { - return handlerList; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java deleted file mode 100644 index 0e067137..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import org.bukkit.Location; -import org.bukkit.entity.Item; -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; - -public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable { - - private static final HandlerList handlerList = new HandlerList(); - private final Location location; - private final Item item; - private boolean isCancelled; - - public FishingLootSpawnEvent(@NotNull Player who, Location location, Item item) { - super(who); - this.item = item; - 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 Item getItem() { - return item; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } - - public static HandlerList getHandlerList() { - return handlerList; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java deleted file mode 100644 index 2b2b96ee..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import net.momirealms.customfishing.api.mechanic.loot.Loot; -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; -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(); - private boolean isCancelled; - private final Result result; - private final Loot loot; - private final FishHook fishHook; - private final Map args; - - /** - * 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 args) { - super(who); - this.result = result; - this.loot = loot; - this.args = args; - this.fishHook = fishHook; - } - - 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; - } - - /** - * 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)); - } - - /** - * An enumeration representing possible fishing results (SUCCESS or FAILURE). - */ - public enum Result { - SUCCESS, - FAILURE - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/LavaFishingEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/LavaFishingEvent.java deleted file mode 100644 index bc961c17..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/LavaFishingEvent.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import 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 - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java deleted file mode 100644 index c8980d0d..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/RodCastEvent.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import net.momirealms.customfishing.api.mechanic.effect.Effect; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.event.player.PlayerFishEvent; -import org.jetbrains.annotations.NotNull; - -/** - * This class represents an event that occurs when a player casts a fishing rod. - */ -public class RodCastEvent extends PlayerEvent implements Cancellable { - - private final Effect effect; - 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) { - super(event.getPlayer()); - this.effect = effect; - this.event = event; - this.preparation = fishingPreparation; - } - - @Override - public boolean isCancelled() { - return this.isCancelled; - } - - /** - * Cancelling this event would not cancel the bukkit PlayerFishEvent - * - * @param cancel true if you wish to cancel this event - */ - @Override - public void setCancelled(boolean cancel) { - this.isCancelled = cancel; - } - - public static HandlerList getHandlerList() { - 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() { - return getHandlerList(); - } - - /** - * Gets the effect associated with the fishing rod cast. - * - * @return The Effect associated with the rod cast. - */ - public Effect getEffect() { - return effect; - } - - /** - * Gets the original PlayerFishEvent that triggered the rod cast. - * - * @return The original PlayerFishEvent. - */ - public PlayerFishEvent getBukkitPlayerFishEvent() { - return event; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/TotemActivateEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/TotemActivateEvent.java deleted file mode 100644 index f1d7cbf6..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/event/TotemActivateEvent.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.event; - -import net.momirealms.customfishing.api.mechanic.totem.TotemConfig; -import org.bukkit.Location; -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 activates a totem. - */ -public class TotemActivateEvent extends PlayerEvent implements Cancellable { - - private static final HandlerList handlerList = new HandlerList(); - private final Location coreLocation; - private boolean isCancelled; - private final TotemConfig config; - - /** - * Constructs a new TotemActivateEvent. - * - * @param who The player who activated the totem. - * @param location The location of the totem's core. - * @param config The configuration of the totem being activated. - */ - public TotemActivateEvent(@NotNull Player who, Location location, TotemConfig config) { - super(who); - this.coreLocation = location; - this.config = config; - } - - /** - * Gets the location of the totem's core. - * - * @return The location of the totem's core. - */ - public Location getCoreLocation() { - return coreLocation; - } - - /** - * Gets the configuration of the totem being activated. - * - * @return The TotemConfig of the totem being activated. - */ - public TotemConfig getConfig() { - return config; - } - - @Override - public boolean isCancelled() { - return isCancelled; - } - - @Override - public void setCancelled(boolean cancel) { - isCancelled = cancel; - } - - @Override - public @NotNull HandlerList getHandlers() { - return handlerList; - } - - public static HandlerList getHandlerList() { - return handlerList; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/manager/VersionManager.java b/api/src/main/java/net/momirealms/customfishing/api/manager/VersionManager.java deleted file mode 100644 index bb3a0c67..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/manager/VersionManager.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.manager; - -import java.util.concurrent.CompletableFuture; - -public interface VersionManager { - - boolean isVersionNewerThan1_19(); - - boolean isVersionNewerThan1_19_4(); - - boolean isVersionNewerThan1_19_3(); - - CompletableFuture checkUpdate(); - - boolean isVersionNewerThan1_20(); - - boolean isNewerThan1_20_5(); - - boolean isSpigot(); - - public boolean hasRegionScheduler(); - - String getPluginVersion(); - - boolean isMojmap(); - - String getServerVersion(); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java deleted file mode 100644 index bc87b73f..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic; - -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -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 lootActions = new HashMap<>(); - private static HashMap rodActions = new HashMap<>(); - private static HashMap baitActions = new HashMap<>(); - private static HashMap 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 entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection inner) { - HashMap map = BukkitCustomFishingPlugin.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 playerContext The condition that triggered the actions. - */ - public static void triggerLootActions(ActionTrigger trigger, PlayerContext playerContext) { - Action[] actions = lootActions.get(trigger); - if (actions != null) { - for (Action action : actions) { - action.trigger(playerContext); - } - } - } - - /** - * Triggers rod-related actions for a specific trigger and condition. - * - * @param trigger The trigger to activate actions for. - * @param playerContext The condition that triggered the actions. - */ - public static void triggerRodActions(ActionTrigger trigger, PlayerContext playerContext) { - Action[] actions = rodActions.get(trigger); - if (actions != null) { - for (Action action : actions) { - action.trigger(playerContext); - } - } - } - - /** - * Triggers bait-related actions for a specific trigger and condition. - * - * @param trigger The trigger to activate actions for. - * @param playerContext The condition that triggered the actions. - */ - public static void triggerBaitActions(ActionTrigger trigger, PlayerContext playerContext) { - Action[] actions = baitActions.get(trigger); - if (actions != null) { - for (Action action : actions) { - action.trigger(playerContext); - } - } - } - - /** - * Triggers hook-related actions for a specific trigger and condition. - * - * @param trigger The trigger to activate actions for. - * @param playerContext The condition that triggered the actions. - */ - public static void triggerHookActions(ActionTrigger trigger, PlayerContext playerContext) { - Action[] actions = hookActions.get(trigger); - if (actions != null) { - for (Action action : actions) { - action.trigger(playerContext); - } - } - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/TempFishingState.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/TempFishingState.java deleted file mode 100644 index c3e8a898..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/TempFishingState.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic; - -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; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java index 7ef3913e..7e516897 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; +import java.util.List; public interface ActionManager { @@ -122,7 +123,13 @@ public interface ActionManager { * @param actions The list of actions to trigger. * @param context The context associated with the actions. */ - static void trigger(@NotNull Context context, @Nullable Action... actions) { + static void trigger(@NotNull Context context, @Nullable List> actions) { + if (actions != null) + for (Action action : actions) + action.trigger(context); + } + + static void trigger(@NotNull Context context, @Nullable Action[] actions) { if (actions != null) for (Action action : actions) action.trigger(context); diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java index 2f41923a..f98abee3 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java @@ -18,7 +18,6 @@ package net.momirealms.customfishing.api.mechanic.action; public enum ActionTrigger { - SUCCESS, FAILURE, HOOK, diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/bag/BagManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/bag/BagManager.java deleted file mode 100644 index 8e75fe08..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/bag/BagManager.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.bag; - -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 mechanics 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 getBagWhiteListItems(); - - /** - * Get the requirements for automatically collecting loots - * - * @return requirements - */ - Requirement[] getCollectRequirements(); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/bag/FishingBagHolder.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/bag/FishingBagHolder.java deleted file mode 100644 index 17d0644a..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/bag/FishingBagHolder.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.bag; - -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.UUID; - -public class FishingBagHolder implements InventoryHolder { - - private final UUID owner; - private Inventory inventory; - - public FishingBagHolder(UUID owner) { - this.owner = owner; - } - - @Override - public @NotNull Inventory getInventory() { - return inventory; - } - - public void setItems(ItemStack[] itemStacks) { - this.inventory.setContents(itemStacks); - } - - public UUID getOwner() { - return owner; - } - - public void setInventory(Inventory inventory) { - this.inventory = inventory; - } -} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java deleted file mode 100644 index d7da2a56..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -import java.util.List; - -public class BlockConfig implements BlockSettings { - - private String blockID; - private List dataModifierList; - private List stateModifierList; - private boolean persist; - private double horizontalVector; - private double verticalVector; - - @Override - public String getBlockID() { - return blockID; - } - - @Override - public List getDataModifier() { - return dataModifierList; - } - - @Override - public List getStateModifierList() { - return stateModifierList; - } - - @Override - public boolean isPersist() { - return persist; - } - - @Override - public double getHorizontalVector() { - return horizontalVector; - } - - @Override - public double getVerticalVector() { - return verticalVector; - } - - 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 value) { - config.dataModifierList = value; - return this; - } - - public Builder stateModifiers(List value) { - config.stateModifierList = value; - return this; - } - - public BlockConfig build() { - return config; - } - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockDataModifier.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockDataModifier.java deleted file mode 100644 index e2995779..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockDataModifier.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; - -public interface BlockDataModifier { - - void apply(Player player, BlockData blockData); -} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockDataModifierBuilder.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockDataModifierBuilder.java deleted file mode 100644 index da0e2e0b..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockDataModifierBuilder.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -public interface BlockDataModifierBuilder { - - BlockDataModifier build(Object args); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockLibrary.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockLibrary.java deleted file mode 100644 index e530a6b9..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockLibrary.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public interface BlockLibrary { - - String identification(); - - BlockData getBlockData(Player player, String id, List modifiers); - - @Nullable - String getBlockID(Block block); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockManager.java deleted file mode 100644 index ab99950e..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockManager.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -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); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockSettings.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockSettings.java deleted file mode 100644 index 657d6b45..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockSettings.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -import java.util.List; - -public interface BlockSettings { - String getBlockID(); - - List getDataModifier(); - - List getStateModifierList(); - - boolean isPersist(); - - double getHorizontalVector(); - - double getVerticalVector(); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockStateModifier.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockStateModifier.java deleted file mode 100644 index 6cd59654..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockStateModifier.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -import org.bukkit.block.BlockState; -import org.bukkit.entity.Player; - -public interface BlockStateModifier { - - void apply(Player player, BlockState blockState); -} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockStateModifierBuilder.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockStateModifierBuilder.java deleted file mode 100644 index 3503cd3f..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockStateModifierBuilder.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.block; - -public interface BlockStateModifierBuilder { - - BlockStateModifier build(Object args); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/BukkitConfigManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java similarity index 52% rename from api/src/main/java/net/momirealms/customfishing/api/mechanic/config/BukkitConfigManager.java rename to api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java index 68ca2965..58ab82ae 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/BukkitConfigManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java @@ -7,109 +7,101 @@ 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.mechanic.context.Context; -import net.momirealms.customfishing.api.mechanic.context.ContextKeys; -import net.momirealms.customfishing.api.mechanic.misc.function.FormatFunction; -import net.momirealms.customfishing.api.mechanic.misc.function.ItemPropertyFunction; -import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; -import net.momirealms.customfishing.api.mechanic.misc.value.TextValue; -import net.momirealms.customfishing.common.config.ConfigManager; +import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect; +import net.momirealms.customfishing.api.mechanic.loot.Loot; +import net.momirealms.customfishing.api.mechanic.misc.function.*; +import net.momirealms.customfishing.common.config.ConfigLoader; import net.momirealms.customfishing.common.config.node.Node; -import net.momirealms.customfishing.common.helper.AdventureHelper; import net.momirealms.customfishing.common.item.Item; import net.momirealms.customfishing.common.plugin.CustomFishingPlugin; -import net.momirealms.customfishing.common.util.ListUtils; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Function; -public class BukkitConfigManager implements ConfigManager { +public abstract class ConfigManager implements ConfigLoader { private final CustomFishingPlugin plugin; - private final HashMap> formatFunctions = new HashMap<>(); + private final HashMap> formatFunctions = new HashMap<>(); - public BukkitConfigManager(CustomFishingPlugin plugin) { + public ConfigManager(CustomFishingPlugin plugin) { this.plugin = plugin; - this.registerBuiltInItemProperties(); } - private void registerBuiltInItemProperties() { - this.registerItemFunction(arg -> { - MathValue mathValue = MathValue.auto(arg); - return (item, context) -> item.customModelData((int) mathValue.evaluate(context)); - }, 4000, "custom-model-data"); - this.registerItemFunction(arg -> { - TextValue textValue = TextValue.auto((String) arg); - return (item, context) -> { - item.displayName(AdventureHelper.miniMessageToJson(textValue.render(context))); - }; - }, 3000, "display", "name"); - this.registerItemFunction(arg -> { - List list = ListUtils.toList(arg); - List> lore = new ArrayList<>(); - for (String text : list) { - lore.add(TextValue.auto(text)); - } - return (item, context) -> { - item.lore(lore.stream() - .map(it -> AdventureHelper.miniMessageToJson(it.render(context))) - .toList()); - }; - }, 2000, "display", "lore"); - this.registerItemFunction(arg -> { - boolean enable = (boolean) arg; - return (item, context) -> { - if (!enable) return; - item.setTag(context.arg(ContextKeys.ID), "CustomFishing", "id"); - item.setTag(context.arg(ContextKeys.TYPE), "CustomFishing", "type"); - }; - }, 1000, "tag"); + public void registerLootParser(Function> function, String... nodes) { + registerNodeFunction(nodes, new LootParserFunction(function)); } - private void registerItemFunction(Function, Context>> function, int priority, String... nodes) { - registerNodeFunction(nodes, new ItemPropertyFunction(priority, function)); + public void registerBaseEffectParser(Function> function, String... nodes) { + registerNodeFunction(nodes, new BaseEffectParserFunction(function)); } - public void registerNodeFunction(String[] nodes, FormatFunction formatFunction) { - Map> functionMap = formatFunctions; + public void registerItemParser(Function, Context>> function, int priority, String... nodes) { + registerNodeFunction(nodes, new ItemParserFunction(priority, function)); + } + + public void registerEffectModifierParser(Function> function, String... nodes) { + registerNodeFunction(nodes, new EffectModifierParserFunction(function)); + } + + public void unregisterNodeFunction(String... nodes) { + Map> functionMap = formatFunctions; for (int i = 0; i < nodes.length; i++) { if (functionMap.containsKey(nodes[i])) { - Node functionNode = functionMap.get(nodes[i]); + Node 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> functionMap = formatFunctions; + for (int i = 0; i < nodes.length; i++) { + if (functionMap.containsKey(nodes[i])) { + Node 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 newNode = new Node<>(); + Node newNode = new Node<>(); functionMap.put(nodes[i], newNode); functionMap = newNode.getChildTree(); } else { - functionMap.put(nodes[i], new Node<>(formatFunction)); + functionMap.put(nodes[i], new Node<>(configParserFunction)); } } } } protected Path resolveConfig(String filePath) { - if (filePath == null || filePath.equals("")) { + 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 { @@ -117,19 +109,15 @@ public class BukkitConfigManager implements ConfigManager { } 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; } @@ -157,7 +145,27 @@ public class BukkitConfigManager implements ConfigManager { ); } catch (IOException e) { plugin.getPluginLogger().severe("Failed to load config " + filePath, e); - return null; + throw new RuntimeException(e); + } + } + + @Override + public YamlDocument loadData(File file) { + try { + return YamlDocument.create(file); + } 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 { + return YamlDocument.create(file, GeneralSettings.builder().setRouteSeparator(routeSeparator).build()); + } catch (IOException e) { + plugin.getPluginLogger().severe("Failed to load config " + file, e); + throw new RuntimeException(e); } } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ItemConfig.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ItemConfig.java deleted file mode 100644 index 4a7ad3c2..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ItemConfig.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.momirealms.customfishing.api.mechanic.config; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.api.mechanic.context.Context; -import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem; -import net.momirealms.customfishing.api.mechanic.misc.function.FormatFunction; -import net.momirealms.customfishing.api.mechanic.misc.function.ItemPropertyFunction; -import net.momirealms.customfishing.api.mechanic.misc.function.PriorityFunction; -import net.momirealms.customfishing.common.config.node.Node; -import net.momirealms.customfishing.common.item.Item; -import net.momirealms.customfishing.common.util.Key; -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 ItemConfig { - - private final String id; - private final String material; - private final List, Context>>> tagConsumers = new ArrayList<>(); - - public ItemConfig(String id, Section section, Map> functionMap) { - this.id = id; - this.material = section.getString("material"); - analyze(section, functionMap); - } - - private void analyze(Section section, Map> functionMap) { - Map dataMap = section.getStringRouteMappedValues(false); - for (Map.Entry entry : dataMap.entrySet()) { - String key = entry.getKey(); - Node node = functionMap.get(key); - if (node == null) continue; - FormatFunction function = node.nodeValue(); - if (function != null) { - if (function instanceof ItemPropertyFunction propertyFunction) { - BiConsumer, Context> result = propertyFunction.accept(entry.getValue()); - tagConsumers.add(new PriorityFunction<>(, result)); - } - continue; - } - if (entry.getValue() instanceof Section innerSection) { - analyze(innerSection, node.getChildTree()); - } - } - } - - public Key key() { - return Key.of("item", id); - } - - public CustomFishingItem getItem() { - return CustomFishingItem.builder() - .material(material) - .tagConsumers(tagConsumers) - .build(); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ItemLootConfig.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ItemLootConfig.java new file mode 100644 index 00000000..76ccbc7a --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ItemLootConfig.java @@ -0,0 +1,99 @@ +package net.momirealms.customfishing.api.mechanic.config; + +import dev.dejvokep.boostedyaml.block.implementation.Section; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect; +import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem; +import net.momirealms.customfishing.api.mechanic.loot.Loot; +import net.momirealms.customfishing.api.mechanic.misc.function.*; +import net.momirealms.customfishing.common.config.node.Node; +import net.momirealms.customfishing.common.item.Item; +import net.momirealms.customfishing.common.util.Key; +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 ItemLootConfig { + + private final String id; + private final String material; + private final List, Context>>> tagConsumers = new ArrayList<>(); + private final List> effectBuilderConsumers = new ArrayList<>(); + private final List> lootBuilderConsumers = new ArrayList<>(); + + public ItemLootConfig(String id, Section section, Map> functionMap) { + this.id = id; + this.material = section.getString("material"); + analyze(section, functionMap); + } + + private void analyze(Section section, Map> functionMap) { + Map dataMap = section.getStringRouteMappedValues(false); + for (Map.Entry entry : dataMap.entrySet()) { + String key = entry.getKey(); + Node 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, Context> result = propertyFunction.accept(entry.getValue()); + tagConsumers.add(new PriorityFunction<>(propertyFunction.getPriority(), result)); + } + case BASE_EFFECT -> { + BaseEffectParserFunction baseEffectParserFunction = (BaseEffectParserFunction) function; + Consumer consumer = baseEffectParserFunction.accept(entry.getValue()); + effectBuilderConsumers.add(consumer); + } + case LOOT -> { + LootParserFunction lootParserFunction = (LootParserFunction) function; + Consumer consumer = lootParserFunction.accept(entry.getValue()); + lootBuilderConsumers.add(consumer); + } + case EVENT -> { + + } + } + continue; + } + if (entry.getValue() instanceof Section innerSection) { + analyze(innerSection, node.getChildTree()); + } + } + } + + public Key key() { + return Key.of("item", id); + } + + public CustomFishingItem getItem() { + return CustomFishingItem.builder() + .material(material) + .tagConsumers(tagConsumers) + .build(); + } + + private LootBaseEffect getBaseEffect() { + LootBaseEffect.Builder builder = LootBaseEffect.builder(); + for (Consumer consumer : effectBuilderConsumers) { + consumer.accept(builder); + } + return builder.build(); + } + + public Loot getLoot() { + Loot.Builder builder = Loot.builder(); + builder.id(id); + builder.lootBaseEffect(getBaseEffect()); + for (Consumer consumer : lootBuilderConsumers) { + consumer.accept(builder); + } + return builder.build(); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java index 9900e79c..3e5994a4 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java @@ -19,6 +19,7 @@ package net.momirealms.customfishing.api.mechanic.context; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -39,8 +40,26 @@ public interface Context { */ Map, Object> args(); + /** + * Adds or updates an argument in the context. + * This method allows adding a new argument or updating the value of an existing argument. + * + * @param the type of the value being added to the context. + * @param key the ContextKeys key representing the argument to be added or updated. + * @param value the value to be associated with the specified key. + * @return the current context instance, allowing for method chaining. + */ Context arg(ContextKeys key, C value); + /** + * Retrieves the value of a specific argument from the context. + * This method fetches the value associated with the specified ContextKeys key. + * + * @param the type of the value being retrieved. + * @param key the ContextKeys key representing the argument to be retrieved. + * @return the value associated with the specified key, or null if the key does not exist. + */ + @Nullable C arg(ContextKeys key); /** diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java index 182b011a..a588eafd 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java @@ -30,6 +30,8 @@ public class ContextKeys { public static final ContextKeys WORLD = of("world", String.class); public static final ContextKeys ID = of("id", String.class); public static final ContextKeys TYPE = of("type", String.class); + public static final ContextKeys SIZE = of("size", Float.class); + public static final ContextKeys PRICE = of("price", Double.class); private final String key; private final Class type; diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/BaseEffect.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/BaseEffect.java deleted file mode 100644 index caa8796a4..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/BaseEffect.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.momirealms.customfishing.api.mechanic.effect; - -import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class BaseEffect { - - private final MathValue waitTime; - private final MathValue waitTimeMultiplier; - private final MathValue difficulty; - private final MathValue difficultyMultiplier; - private final MathValue gameTime; - private final MathValue gameTimeMultiplier; - - public BaseEffect(MathValue waitTime, MathValue waitTimeMultiplier, MathValue difficulty, MathValue difficultyMultiplier, MathValue gameTime, MathValue gameTimeMultiplier) { - this.waitTime = waitTime; - this.waitTimeMultiplier = waitTimeMultiplier; - this.difficulty = difficulty; - this.difficultyMultiplier = difficultyMultiplier; - this.gameTime = gameTime; - this.gameTimeMultiplier = gameTimeMultiplier; - } - - public Effect build(Player player, Map values) { - return new FishingEffect( - waitTime.get(player, values), - waitTimeMultiplier.get(player, values), - difficulty.get(player, values), - difficultyMultiplier.get(player, values), - gameTime.get(player, values), - gameTimeMultiplier.get(player, values) - ); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java index b7933062..c359b8ef 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/Effect.java @@ -21,41 +21,248 @@ import net.momirealms.customfishing.common.util.Pair; import org.bukkit.entity.Player; import java.util.List; +import java.util.Map; import java.util.function.BiFunction; +/** + * Represents an effect applied in the custom fishing mechanic. + */ public interface Effect { - boolean allowLavaFishing(); + /** + * Retrieves the properties of this effect. + * + * @return a map of effect properties and their values + */ + Map, Object> properties(); + /** + * Sets the specified property to the given value. + * + * @param key the property key + * @param value the property value + * @param the type of the property value + * @return the effect instance with the updated property + */ + EffectImpl arg(EffectProperties key, C value); + + /** + * Retrieves the value of the specified property. + * + * @param key the property key + * @param the type of the property value + * @return the value of the specified property + */ + C arg(EffectProperties key); + + /** + * Gets the chance of multiple loots. + * + * @return the multiple loot chance + */ double multipleLootChance(); + /** + * Sets the chance of multiple loots. + * + * @param multipleLootChance the new multiple loot chance + * @return the effect instance with the updated multiple loot chance + */ + Effect multipleLootChance(double multipleLootChance); + + /** + * Gets the size adder. + * + * @return the size adder + */ double sizeAdder(); + /** + * Sets the size adder. + * + * @param sizeAdder the new size adder + * @return the effect instance with the updated size adder + */ + Effect sizeAdder(double sizeAdder); + + /** + * Gets the size multiplier. + * + * @return the size multiplier + */ double sizeMultiplier(); + /** + * Sets the size multiplier. + * + * @param sizeMultiplier the new size multiplier + * @return the effect instance with the updated size multiplier + */ + Effect sizeMultiplier(double sizeMultiplier); + + /** + * Gets the score adder. + * + * @return the score adder + */ double scoreAdder(); + /** + * Sets the score adder. + * + * @param scoreAdder the new score adder + * @return the effect instance with the updated score adder + */ + Effect scoreAdder(double scoreAdder); + + /** + * Gets the score multiplier. + * + * @return the score multiplier + */ double scoreMultiplier(); + /** + * Sets the score multiplier. + * + * @param scoreMultiplier the new score multiplier + * @return the effect instance with the updated score multiplier + */ + Effect scoreMultiplier(double scoreMultiplier); + + /** + * Gets the wait time adder. + * + * @return the wait time adder + */ double waitTimeAdder(); - double getWaitTimeMultiplier(); + /** + * Sets the wait time adder. + * + * @param waitTimeAdder the new wait time adder + * @return the effect instance with the updated wait time adder + */ + Effect waitTimeAdder(double waitTimeAdder); + /** + * Gets the wait time multiplier. + * + * @return the wait time multiplier + */ + double waitTimeMultiplier(); + + /** + * Sets the wait time multiplier. + * + * @param waitTimeMultiplier the new wait time multiplier + * @return the effect instance with the updated wait time multiplier + */ + Effect waitTimeMultiplier(double waitTimeMultiplier); + + /** + * Gets the game time adder. + * + * @return the game time adder + */ double gameTimeAdder(); + /** + * Sets the game time adder. + * + * @param gameTimeAdder the new game time adder + * @return the effect instance with the updated game time adder + */ + Effect gameTimeAdder(double gameTimeAdder); + + /** + * Gets the game time multiplier. + * + * @return the game time multiplier + */ double gameTimeMultiplier(); + /** + * Sets the game time multiplier. + * + * @param gameTimeMultiplier the new game time multiplier + * @return the effect instance with the updated game time multiplier + */ + Effect gameTimeMultiplier(double gameTimeMultiplier); + + /** + * Gets the difficulty adder. + * + * @return the difficulty adder + */ double difficultyAdder(); + /** + * Sets the difficulty adder. + * + * @param difficultyAdder the new difficulty adder + * @return the effect instance with the updated difficulty adder + */ + Effect difficultyAdder(double difficultyAdder); + + /** + * Gets the difficulty multiplier. + * + * @return the difficulty multiplier + */ double difficultyMultiplier(); - List>> weightModifier(); + /** + * Sets the difficulty multiplier. + * + * @param difficultyMultiplier the new difficulty multiplier + * @return the effect instance with the updated difficulty multiplier + */ + Effect difficultyMultiplier(double difficultyMultiplier); - List>> weightModifierIgnored(); + /** + * Gets the list of weight operations. + * + * @return the list of weight operations + */ + List>> weightOperations(); - void merge(Effect effect); + /** + * Adds the list of weight operations. + * + * @param weightOperations the list of weight operations to add + * @return the effect instance with the updated weight operations + */ + Effect weightOperations(List>> weightOperations); - interface Builder { + /** + * Gets the list of weight operations that are conditions ignored. + * + * @return the list of weight operations that are conditions ignored + */ + List>> weightOperationsIgnored(); + /** + * Adds the list of weight operations that are conditions ignored. + * + * @param weightOperations the list of weight operations that are conditions ignored + * @return the effect instance with the updated ignored weight operations + */ + Effect weightOperationsIgnored(List>> weightOperations); + + /** + * Combines this effect with another effect. + * + * @param effect the effect to combine with + */ + void combine(Effect effect); + + /** + * Creates a new instance of {@link Effect}. + * + * @return a new {@link Effect} instance + */ + static Effect newInstance() { + return new EffectImpl(); } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectCarrier.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectCarrier.java deleted file mode 100644 index cd70ca91..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectCarrier.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.effect; - -import net.kyori.adventure.key.Key; -import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -import net.momirealms.customfishing.api.mechanic.requirement.Requirement; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -public class EffectCarrier { - - private Key key; - private Requirement[] requirements; - private EffectModifier[] effect; - private Map actionMap; - private boolean persist; - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private final EffectCarrier item; - - public Builder() { - this.item = new EffectCarrier(); - } - - public Builder persist(boolean persist) { - item.persist = persist; - return this; - } - - public Builder key(Key key) { - item.key = key; - return this; - } - - public Builder requirements(Requirement[] requirements) { - item.requirements = requirements; - return this; - } - - public Builder effect(EffectModifier[] effect) { - item.effect = effect; - return this; - } - - public Builder actionMap(Map actionMap) { - item.actionMap = actionMap; - return this; - } - - public EffectCarrier build() { - return item; - } - } - - public Key getKey() { - return key; - } - - public Requirement[] getRequirements() { - return requirements; - } - - public EffectModifier[] getEffectModifiers() { - return effect; - } - - public Map getActionMap() { - return actionMap; - } - - @Nullable - public Action[] getActions(ActionTrigger trigger) { - return actionMap.get(trigger); - } - - public boolean isPersist() { - return persist; - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean isConditionMet(PlayerContext playerContext) { - if (requirements == null) return true; - for (Requirement requirement : requirements) { - if (!requirement.check(playerContext)) { - return false; - } - } - return true; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java index 114393ec..901e12e3 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectImpl.java @@ -1,4 +1,207 @@ package net.momirealms.customfishing.api.mechanic.effect; -public class EffectImpl { +import net.momirealms.customfishing.common.util.Pair; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; + +public class EffectImpl implements Effect { + + private final HashMap, Object> properties = new HashMap<>(); + private double multipleLootChance = 0; + private double sizeAdder = 0; + private double sizeMultiplier = 1; + private double scoreAdder = 0; + private double scoreMultiplier = 1; + private double gameTimeAdder = 0; + private double gameTimeMultiplier = 1; + private double waitTimeAdder = 0; + private double waitTimeMultiplier = 1; + private double difficultyAdder = 0; + private double difficultyMultiplier = 1; + private final List>> weightOperations = new ArrayList<>(); + private final List>> weightOperationsIgnored = new ArrayList<>(); + + @Override + public Map, Object> properties() { + return properties; + } + + @Override + public EffectImpl arg(EffectProperties key, C value) { + properties.put(key, value); + return this; + } + + @Override + @SuppressWarnings("unchecked") + public C arg(EffectProperties key) { + return (C) properties.get(key); + } + + @Override + public double multipleLootChance() { + return multipleLootChance; + } + + @Override + public Effect multipleLootChance(double multipleLootChance) { + this.multipleLootChance = multipleLootChance; + return this; + } + + @Override + public double sizeAdder() { + return sizeAdder; + } + + @Override + public Effect sizeAdder(double sizeAdder) { + this.sizeAdder = sizeAdder; + return this; + } + + @Override + public double sizeMultiplier() { + return sizeMultiplier; + } + + @Override + public Effect sizeMultiplier(double sizeMultiplier) { + this.sizeMultiplier = sizeMultiplier; + return this; + } + + @Override + public double scoreAdder() { + return scoreAdder; + } + + @Override + public Effect scoreAdder(double scoreAdder) { + this.scoreAdder = scoreAdder; + return this; + } + + @Override + public double scoreMultiplier() { + return scoreMultiplier; + } + + @Override + public Effect scoreMultiplier(double scoreMultiplier) { + this.scoreMultiplier = scoreMultiplier; + return this; + } + + @Override + public double waitTimeAdder() { + return waitTimeAdder; + } + + @Override + public Effect waitTimeAdder(double waitTimeAdder) { + this.waitTimeAdder = waitTimeAdder; + return this; + } + + @Override + public double waitTimeMultiplier() { + return waitTimeMultiplier; + } + + @Override + public Effect waitTimeMultiplier(double waitTimeMultiplier) { + this.waitTimeMultiplier = waitTimeMultiplier; + return this; + } + + @Override + public double gameTimeAdder() { + return gameTimeAdder; + } + + @Override + public Effect gameTimeAdder(double gameTimeAdder) { + this.gameTimeAdder = gameTimeAdder; + return this; + } + + @Override + public double gameTimeMultiplier() { + return gameTimeMultiplier; + } + + @Override + public Effect gameTimeMultiplier(double gameTimeMultiplier) { + this.gameTimeMultiplier = gameTimeMultiplier; + return this; + } + + @Override + public double difficultyAdder() { + return difficultyAdder; + } + + @Override + public Effect difficultyAdder(double difficultyAdder) { + this.difficultyAdder = difficultyAdder; + return this; + } + + @Override + public double difficultyMultiplier() { + return difficultyMultiplier; + } + + @Override + public Effect difficultyMultiplier(double difficultyMultiplier) { + this.difficultyMultiplier = difficultyMultiplier; + return this; + } + + @Override + public List>> weightOperations() { + return weightOperations; + } + + @Override + public Effect weightOperations(List>> weightOperations) { + this.weightOperations.addAll(weightOperations); + return this; + } + + @Override + public List>> weightOperationsIgnored() { + return weightOperationsIgnored; + } + + @Override + public Effect weightOperationsIgnored(List>> weightOperations) { + this.weightOperationsIgnored.addAll(weightOperations); + return this; + } + + @Override + public void combine(Effect another) { + if (another == null) return; + this.scoreMultiplier += (another.scoreMultiplier() -1); + this.scoreAdder += another.scoreAdder(); + this.sizeMultiplier += (another.sizeMultiplier() -1); + this.sizeAdder += another.sizeAdder(); + this.difficultyMultiplier += (another.difficultyMultiplier() -1); + this.difficultyAdder += another.difficultyAdder(); + this.gameTimeMultiplier += (another.gameTimeMultiplier() - 1); + this.gameTimeAdder += another.gameTimeAdder(); + this.waitTimeAdder += (another.waitTimeAdder() -1); + this.waitTimeMultiplier += (another.waitTimeMultiplier() -1); + this.multipleLootChance += another.multipleLootChance(); + this.weightOperations.addAll(another.weightOperations()); + this.weightOperationsIgnored.addAll(another.weightOperationsIgnored()); + this.properties.putAll(another.properties()); + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectManager.java deleted file mode 100644 index f288b28f..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectManager.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.effect; - -import net.kyori.adventure.key.Key; -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. - *

- * 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. - *

- * 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. - *

- * 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); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java deleted file mode 100644 index 8bbf20ac..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectModifier.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.effect; - -import net.momirealms.customfishing.api.mechanic.context.Context; -import org.bukkit.entity.Player; - -public interface EffectModifier { - - void modify(FishingEffect effect, Context playerContext); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java new file mode 100644 index 00000000..b901b245 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/EffectProperties.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.api.mechanic.effect; + +import java.util.Objects; + +public class EffectProperties { + + public static final EffectProperties LAVA_FISHING = of("lava", Boolean.class); + public static final EffectProperties VOID_FISHING = of("void", Boolean.class); + + private final String key; + private final Class type; + + private EffectProperties(String key, Class type) { + this.key = key; + this.type = type; + } + + public String key() { + return key; + } + + public Class type() { + return type; + } + + public static EffectProperties of(String key, Class type) { + return new EffectProperties(key, type); + } + + @Override + public final boolean equals(final Object other) { + if (this == other) { + return true; + } else if (other != null && this.getClass() == other.getClass()) { + EffectProperties that = (EffectProperties) other; + return Objects.equals(this.key, that.key); + } else { + return false; + } + } + + @Override + public final int hashCode() { + return Objects.hashCode(this.key); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/FishingEffect.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/FishingEffect.java deleted file mode 100644 index 8d294532..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/FishingEffect.java +++ /dev/null @@ -1,372 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.effect; - -import net.momirealms.customfishing.api.common.Pair; - -import java.util.ArrayList; -import java.util.List; - -public class FishingEffect implements Effect { - - private boolean lavaFishing = false; - private double multipleLootChance = 0; - private double waitTime = 0; - private double waitTimeMultiplier = 1; - private double size = 0; - private double sizeMultiplier = 1; - private double score = 0; - private double scoreMultiplier = 1; - private double difficulty = 0; - private double difficultyMultiplier = 1; - private double gameTime = 0; - private double gameTimeMultiplier = 1; - - private final List> weightModifier = new ArrayList<>(); - private final List> weightModifierIgnored = new ArrayList<>(); - - public FishingEffect(double waitTime, double waitTimeMultiplier, double difficulty, double difficultyMultiplier, double gameTime, double gameTimeMultiplier) { - this.waitTime = waitTime; - this.waitTimeMultiplier = waitTimeMultiplier; - this.difficulty = difficulty; - this.difficultyMultiplier = difficultyMultiplier; - this.gameTime = gameTime; - this.gameTimeMultiplier = gameTimeMultiplier; - } - - public FishingEffect() { - } - - /** - * Sets whether lava fishing is enabled. - * - * @param lavaFishing True if lava fishing is enabled, false otherwise. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setLavaFishing(boolean lavaFishing) { - this.lavaFishing = lavaFishing; - return this; - } - - /** - * Sets the multiple loot chance. - * - * @param multipleLootChance The multiple loot chance value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setMultipleLootChance(double multipleLootChance) { - this.multipleLootChance = multipleLootChance; - return this; - } - - /** - * Sets the size multiplier. - * - * @param sizeMultiplier The size multiplier value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setSizeMultiplier(double sizeMultiplier) { - this.sizeMultiplier = sizeMultiplier; - return this; - } - - /** - * Sets the size. - * - * @param size The size value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setSize(double size) { - this.size = size; - return this; - } - - /** - * Sets the score multiplier. - * - * @param scoreMultiplier The score multiplier value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setScoreMultiplier(double scoreMultiplier) { - this.scoreMultiplier = scoreMultiplier; - return this; - } - - /** - * Sets the score - * - * @param score The score value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setScore(double score) { - this.score = score; - return this; - } - - /** - * Sets the wait time multiplier. - * - * @param timeMultiplier The wait time multiplier value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setWaitTimeMultiplier(double timeMultiplier) { - this.waitTimeMultiplier = timeMultiplier; - return this; - } - - /** - * Sets the wait time. - * - * @param waitTime The wait time value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setWaitTime(double waitTime) { - this.waitTime = waitTime; - return this; - } - - /** - * Sets the difficulty. - * - * @param difficulty The difficulty value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setDifficulty(double difficulty) { - this.difficulty = difficulty; - return this; - } - - /** - * Sets the difficulty multiplier. - * - * @param difficultyMultiplier The difficulty multiplier value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setDifficultyMultiplier(double difficultyMultiplier) { - this.difficultyMultiplier = difficultyMultiplier; - return this; - } - - /** - * Sets the game time. - * - * @param gameTime The game time value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setGameTime(double gameTime) { - this.gameTime = gameTime; - return this; - } - - /** - * Sets the game time multiplier. - * - * @param gameTimeMultiplier The game time multiplier value to set. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect setGameTimeMultiplier(double gameTimeMultiplier) { - this.gameTimeMultiplier = gameTimeMultiplier; - return this; - } - - - /** - * Adds weight modifiers to the FishingEffect. - * - * @param weightModifier A list of pairs representing weight modifiers to add. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect addWeightModifier(List> weightModifier) { - this.weightModifier.addAll(weightModifier); - return this; - } - - /** - * Adds ignored weight modifiers to the FishingEffect. - * - * @param weightModifierIgnored A list of pairs representing ignored weight modifiers to add. - * @return The FishingEffect instance for method chaining. - */ - public FishingEffect addWeightModifierIgnored(List> weightModifierIgnored) { - this.weightModifierIgnored.addAll(weightModifierIgnored); - return this; - } - - /** - * Checks if lava fishing is enabled. - * - * @return True if lava fishing is enabled, false otherwise. - */ - @Override - public boolean allowLavaFishing() { - return lavaFishing; - } - - /** - * Retrieves the multiple loot chance. - * - * @return The multiple loot chance value. - */ - @Override - public double multipleLootChance() { - return multipleLootChance; - } - - /** - * Retrieves the size multiplier. - * - * @return The size multiplier value. - */ - @Override - public double sizeMultiplier() { - return sizeMultiplier; - } - - /** - * Retrieves the size. - * - * @return The size value. - */ - @Override - public double sizeAdder() { - return size; - } - - /** - * Retrieves the score multiplier. - * - * @return The score multiplier value. - */ - @Override - public double scoreMultiplier() { - return scoreMultiplier; - } - - /** - * Retrieves the wait time multiplier. - * - * @return The wait time multiplier value. - */ - @Override - public double getWaitTimeMultiplier() { - return waitTimeMultiplier; - } - - /** - * Retrieves the wait time. - * - * @return The wait time . - */ - @Override - public double waitTimeAdder() { - return waitTime; - } - - /** - * Retrieves the game time. - * - * @return The game time value. - */ - @Override - public double gameTimeAdder() { - return gameTime; - } - - /** - * Retrieves the game time multiplier. - * - * @return The game time value multiplier. - */ - @Override - public double gameTimeMultiplier() { - return gameTimeMultiplier; - } - - /** - * Retrieves score modifier. - * - * @return The score value. - */ - @Override - public double scoreAdder() { - return score; - } - - /** - * Retrieves the difficulty. - * - * @return The difficulty value. - */ - @Override - public double difficultyAdder() { - return difficulty; - } - - /** - * Retrieves the difficulty multiplier. - * - * @return The difficulty multiplier value. - */ - @Override - public double difficultyMultiplier() { - return difficultyMultiplier; - } - - /** - * Retrieves the list of weight modifiers. - * - * @return The list of weight modifiers. - */ - @Override - public List> weightModifier() { - return weightModifier; - } - - /** - * Retrieves the list of weight modifiers ignoring conditions. - * - * @return The list of weight modifiers ignoring conditions. - */ - @Override - public List> weightModifierIgnored() { - return weightModifierIgnored; - } - - /** - * Merges another Effect into this FishingEffect, combining their properties. - * - * @param another The Effect to merge into this FishingEffect. - */ - @Override - public void merge(Effect another) { - if (another == null) return; - if (another.allowLavaFishing()) this.lavaFishing = true; - this.scoreMultiplier += (another.scoreMultiplier() -1); - this.score += another.scoreAdder(); - this.sizeMultiplier += (another.sizeMultiplier() -1); - this.size += another.sizeAdder(); - this.difficultyMultiplier += (another.difficultyMultiplier() -1); - this.difficulty += another.difficultyAdder(); - this.gameTimeMultiplier += (another.gameTimeMultiplier() - 1); - this.gameTime += another.gameTimeAdder(); - this.waitTimeMultiplier += (another.getWaitTimeMultiplier() -1); - this.multipleLootChance += another.multipleLootChance(); - this.weightModifierIgnored.addAll(another.weightModifierIgnored()); - this.weightModifier.addAll(another.weightModifier()); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java new file mode 100644 index 00000000..d2c0b2b6 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffect.java @@ -0,0 +1,129 @@ +package net.momirealms.customfishing.api.mechanic.effect; + +import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; +import org.bukkit.entity.Player; + +/** + * Represents the base effect applied to loot in the custom fishing mechanic. + */ +public interface LootBaseEffect { + + MathValue DEFAULT_WAIT_TIME_ADDER = MathValue.plain(0); + MathValue DEFAULT_WAIT_TIME_MULTIPLIER = MathValue.plain(1); + MathValue DEFAULT_DIFFICULTY_ADDER = MathValue.plain(0); + MathValue DEFAULT_DIFFICULTY_MULTIPLIER = MathValue.plain(1); + MathValue DEFAULT_GAME_TIME_ADDER = MathValue.plain(0); + MathValue DEFAULT_GAME_TIME_MULTIPLIER = MathValue.plain(1); + + /** + * Gets the adder value for wait time. + * + * @return the wait time adder value + */ + MathValue waitTimeAdder(); + + /** + * Gets the multiplier value for wait time. + * + * @return the wait time multiplier value + */ + MathValue waitTimeMultiplier(); + + /** + * Gets the adder value for difficulty. + * + * @return the difficulty adder value + */ + MathValue difficultyAdder(); + + /** + * Gets the multiplier value for difficulty. + * + * @return the difficulty multiplier value + */ + MathValue difficultyMultiplier(); + + /** + * Gets the adder value for game time. + * + * @return the game time adder value + */ + MathValue gameTimeAdder(); + + /** + * Gets the multiplier value for game time. + * + * @return the game time multiplier value + */ + MathValue gameTimeMultiplier(); + + /** + * Creates a new {@link Builder} instance for constructing {@link LootBaseEffect} objects. + * + * @return a new {@link Builder} instance + */ + static Builder builder() { + return new LootBaseEffectImpl.BuilderImpl(); + } + + /** + * Builder interface for constructing {@link LootBaseEffect} instances. + */ + interface Builder { + + /** + * Sets the adder value for wait time. + * + * @param waitTimeAdder the wait time adder value + * @return the builder instance + */ + Builder waitTimeAdder(MathValue waitTimeAdder); + + /** + * Sets the multiplier value for wait time. + * + * @param waitTimeMultiplier the wait time multiplier value + * @return the builder instance + */ + Builder waitTimeMultiplier(MathValue waitTimeMultiplier); + + /** + * Sets the adder value for difficulty. + * + * @param difficultyAdder the difficulty adder value + * @return the builder instance + */ + Builder difficultyAdder(MathValue difficultyAdder); + + /** + * Sets the multiplier value for difficulty. + * + * @param difficultyMultiplier the difficulty multiplier value + * @return the builder instance + */ + Builder difficultyMultiplier(MathValue difficultyMultiplier); + + /** + * Sets the adder value for game time. + * + * @param gameTimeAdder the game time adder value + * @return the builder instance + */ + Builder gameTimeAdder(MathValue gameTimeAdder); + + /** + * Sets the multiplier value for game time. + * + * @param gameTimeMultiplier the game time multiplier value + * @return the builder instance + */ + Builder gameTimeMultiplier(MathValue gameTimeMultiplier); + + /** + * Builds and returns the {@link LootBaseEffect} instance. + * + * @return the built {@link LootBaseEffect} instance + */ + LootBaseEffect build(); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java new file mode 100644 index 00000000..1d346c58 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/effect/LootBaseEffectImpl.java @@ -0,0 +1,103 @@ +package net.momirealms.customfishing.api.mechanic.effect; + +import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; +import org.bukkit.entity.Player; + +public class LootBaseEffectImpl implements LootBaseEffect { + + private final MathValue waitTimeAdder; + private final MathValue waitTimeMultiplier; + private final MathValue difficultyAdder; + private final MathValue difficultyMultiplier; + private final MathValue gameTimeAdder; + private final MathValue gameTimeMultiplier; + + public LootBaseEffectImpl( + MathValue waitTimeAdder, + MathValue waitTimeMultiplier, + MathValue difficultyAdder, + MathValue difficultyMultiplier, + MathValue gameTimeAdder, + MathValue gameTimeMultiplier + ) { + this.waitTimeAdder = waitTimeAdder; + this.waitTimeMultiplier = waitTimeMultiplier; + this.difficultyAdder = difficultyAdder; + this.difficultyMultiplier = difficultyMultiplier; + this.gameTimeAdder = gameTimeAdder; + this.gameTimeMultiplier = gameTimeMultiplier; + } + + @Override + public MathValue waitTimeAdder() { + return waitTimeAdder; + } + + @Override + public MathValue waitTimeMultiplier() { + return waitTimeMultiplier; + } + + @Override + public MathValue difficultyAdder() { + return difficultyAdder; + } + + @Override + public MathValue difficultyMultiplier() { + return difficultyMultiplier; + } + + @Override + public MathValue gameTimeAdder() { + return gameTimeAdder; + } + + @Override + public MathValue gameTimeMultiplier() { + return gameTimeMultiplier; + } + + public static class BuilderImpl implements Builder { + private MathValue waitTimeAdder = DEFAULT_WAIT_TIME_ADDER; + private MathValue waitTimeMultiplier = DEFAULT_WAIT_TIME_MULTIPLIER; + private MathValue difficultyAdder = DEFAULT_DIFFICULTY_ADDER; + private MathValue difficultyMultiplier = DEFAULT_DIFFICULTY_MULTIPLIER; + private MathValue gameTimeAdder = DEFAULT_GAME_TIME_ADDER; + private MathValue gameTimeMultiplier = DEFAULT_GAME_TIME_MULTIPLIER; + @Override + public Builder waitTimeAdder(MathValue waitTimeAdder) { + this.waitTimeAdder = waitTimeAdder; + return this; + } + @Override + public Builder waitTimeMultiplier(MathValue waitTimeMultiplier) { + this.waitTimeMultiplier = waitTimeMultiplier; + return this; + } + @Override + public Builder difficultyAdder(MathValue difficultyAdder) { + this.difficultyAdder = difficultyAdder; + return this; + } + @Override + public Builder difficultyMultiplier(MathValue difficultyMultiplier) { + this.difficultyMultiplier = difficultyMultiplier; + return this; + } + @Override + public Builder gameTimeAdder(MathValue gameTimeAdder) { + this.gameTimeAdder = gameTimeAdder; + return this; + } + @Override + public Builder gameTimeMultiplier(MathValue gameTimeMultiplier) { + this.gameTimeMultiplier = gameTimeMultiplier; + return this; + } + @Override + public LootBaseEffect build() { + return new LootBaseEffectImpl(waitTimeAdder, waitTimeMultiplier, difficultyAdder, difficultyMultiplier, gameTimeAdder, gameTimeMultiplier); + } + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/entity/EntityConfig.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/entity/EntityConfig.java index 84e5b4ac..a4aaff28 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/entity/EntityConfig.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/entity/EntityConfig.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.api.mechanic.entity; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.Map; /** diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventCarrier.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventCarrier.java new file mode 100644 index 00000000..953de670 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventCarrier.java @@ -0,0 +1,103 @@ +package net.momirealms.customfishing.api.mechanic.event; + +import net.momirealms.customfishing.api.mechanic.action.Action; +import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.item.ItemType; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.TreeMap; + +/** + * The EventCarrier interface represents an object that carries events in the custom fishing system. + * It defines methods to trigger actions based on specific triggers and contexts. + */ +public interface EventCarrier { + + /** + * Get the type of item + * + * @return type + */ + ItemType type(); + + /** + * Whether to disable global actions + * + * @return disable global actions or not + */ + boolean disableGlobalActions(); + + /** + * Triggers actions based on the given context and trigger. + * + * @param context the context of the event, typically containing information about the player involved. + * @param trigger the trigger that activates the actions. + */ + void trigger(Context context, ActionTrigger trigger); + + /** + * Triggers actions based on the given context, trigger, and action occurrence times. + * + * @param context the context of the event, typically containing information about the player involved. + * @param trigger the trigger that activates the actions. + * @param previousTimes the number of times the action has been triggered before. + * @param afterTimes the number of times the action will be triggered after. + */ + void trigger(Context context, ActionTrigger trigger, int previousTimes, int afterTimes); + + /** + * Creates a new Builder instance for constructing EventCarrier objects. + * + * @return a new Builder instance. + */ + static Builder builder() { + return new EventCarrierImpl.BuilderImpl(); + } + + /** + * The Builder interface provides a fluent API for constructing EventCarrier instances. + */ + interface Builder { + + /** + * Sets the map of actions associated with their triggers. + * + * @param actionMap the map of actions associated with their triggers. + * @return the Builder instance. + */ + Builder actionMap(HashMap[]> actionMap); + + /** + * Sets the map of actions associated with their triggers and occurrence times. + * + * @param actionTimesMap the map of actions associated with their triggers and occurrence times. + * @return the Builder instance. + */ + Builder actionTimesMap(HashMap[]>> actionTimesMap); + + /** + * Set the type of the item + * + * @param type type + * @return the Builder instance. + */ + Builder type(ItemType type); + + /** + * Set whether to disable global events + * + * @param value disable or not + * @return the Builder instance. + */ + Builder disableGlobalActions(boolean value); + + /** + * Builds and returns the EventCarrier instance. + * + * @return the constructed EventCarrier instance. + */ + EventCarrier build(); + } +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventCarrierImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventCarrierImpl.java new file mode 100644 index 00000000..e469fbff --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventCarrierImpl.java @@ -0,0 +1,88 @@ +package net.momirealms.customfishing.api.mechanic.event; + +import net.momirealms.customfishing.api.mechanic.action.Action; +import net.momirealms.customfishing.api.mechanic.action.ActionManager; +import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.item.ItemType; +import org.bukkit.entity.Player; + +import java.util.*; + +import static java.util.Objects.requireNonNull; + +public class EventCarrierImpl implements EventCarrier { + + private final HashMap[]> actionMap; + private final HashMap[]>> actionTimesMap; + private final ItemType type; + private final boolean disableGlobalActions; + + public EventCarrierImpl(ItemType type, boolean disableGlobalActions, HashMap[]> actionMap, HashMap[]>> actionTimesMap) { + this.actionMap = actionMap; + this.actionTimesMap = actionTimesMap; + this.type = type; + this.disableGlobalActions = disableGlobalActions; + } + + @Override + public ItemType type() { + return type; + } + + @Override + public boolean disableGlobalActions() { + return disableGlobalActions; + } + + @Override + public void trigger(Context context, ActionTrigger trigger) { + Optional.ofNullable(actionMap.get(trigger)).ifPresent(actions -> { + ActionManager.trigger(context, actions); + }); + } + + @Override + public void trigger(Context context, ActionTrigger trigger, int previousTimes, int afterTimes) { + Optional.ofNullable(actionTimesMap.get(trigger)).ifPresent(integerTreeMap -> { + for (Map.Entry[]> entry : integerTreeMap.entrySet()) { + if (entry.getKey() <= previousTimes) + continue; + if (entry.getKey() > afterTimes) + return; + ActionManager.trigger(context, entry.getValue()); + } + }); + } + + public static class BuilderImpl implements Builder { + private final HashMap[]> actionMap = new HashMap<>(); + private final HashMap[]>> actionTimesMap = new HashMap<>(); + private ItemType type = null; + private boolean disableGlobalActions = false; + @Override + public Builder actionMap(HashMap[]> actionMap) { + this.actionMap.putAll(actionMap); + return this; + } + @Override + public Builder actionTimesMap(HashMap[]>> actionTimesMap) { + this.actionTimesMap.putAll(actionTimesMap); + return this; + } + @Override + public Builder type(ItemType type) { + this.type = type; + return this; + } + @Override + public Builder disableGlobalActions(boolean value) { + this.disableGlobalActions = value; + return this; + } + @Override + public EventCarrier build() { + return new EventCarrierImpl(requireNonNull(type), disableGlobalActions, actionMap, actionTimesMap); + } + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventManager.java new file mode 100644 index 00000000..cf2a5729 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/event/EventManager.java @@ -0,0 +1,66 @@ +package net.momirealms.customfishing.api.mechanic.event; + +import net.momirealms.customfishing.api.mechanic.action.Action; +import net.momirealms.customfishing.api.mechanic.action.ActionManager; +import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.item.ItemType; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; + +public interface EventManager { + + Map[]>> GLOBAL_ACTIONS = new HashMap<>(); + + Map[]>>> GLOBAL_TIMES_ACTION = new HashMap<>(); + + Optional getEventCarrier(String id); + + boolean registerEventCarrier(String id, EventCarrier carrier); + + default void trigger(Context context, String id, ActionTrigger trigger) { + getEventCarrier(id).ifPresent(carrier -> trigger(context, carrier, trigger)); + } + + default void trigger(Context context, String id, ActionTrigger trigger, int previousTimes, int afterTimes) { + getEventCarrier(id).ifPresent(carrier -> trigger(context, carrier, trigger, previousTimes, afterTimes)); + } + + static void trigger(Context context, EventCarrier carrier, ActionTrigger trigger) { + if (!carrier.disableGlobalActions()) { + triggerGlobalActions(context, carrier.type(), trigger); + } + carrier.trigger(context, trigger); + } + + static void trigger(Context context, EventCarrier carrier, ActionTrigger trigger, int previousTimes, int afterTimes) { + if (!carrier.disableGlobalActions()) { + triggerGlobalActions(context, carrier.type(), trigger, previousTimes, afterTimes); + } + carrier.trigger(context, trigger, previousTimes, afterTimes); + } + + static void triggerGlobalActions(Context context, ItemType type, ActionTrigger trigger) { + Optional.ofNullable(GLOBAL_ACTIONS.get(type)) + .flatMap(actionTriggerMap -> Optional.ofNullable(actionTriggerMap.get(trigger))) + .ifPresent(action -> ActionManager.trigger(context, action)); + } + + static void triggerGlobalActions(Context context, ItemType type, ActionTrigger trigger, int previousTimes, int afterTimes) { + Optional.ofNullable(GLOBAL_TIMES_ACTION.get(type)) + .flatMap(actionTriggerMap -> Optional.ofNullable(actionTriggerMap.get(trigger))) + .ifPresent(integerTreeMap -> { + for (Map.Entry[]> entry : integerTreeMap.entrySet()) { + if (entry.getKey() <= previousTimes) + continue; + if (entry.getKey() > afterTimes) + return; + ActionManager.trigger(context, entry.getValue()); + } + }); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingManager.java index 529b1bd1..65580cbb 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingManager.java @@ -17,7 +17,6 @@ package net.momirealms.customfishing.api.mechanic.fishing; -import net.momirealms.customfishing.api.mechanic.TempFishingState; import net.momirealms.customfishing.api.mechanic.effect.Effect; import net.momirealms.customfishing.api.mechanic.game.GameInstance; import net.momirealms.customfishing.api.mechanic.game.GameSettings; diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java index fcd2abf5..ca8355ba 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java @@ -18,8 +18,8 @@ package net.momirealms.customfishing.api.mechanic.game; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.fishing.FishingManager; import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.fishing.FishingManager; import net.momirealms.customfishing.api.scheduler.CancellableTask; import org.bukkit.Material; import org.bukkit.entity.FishHook; diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItem.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItem.java index ae8995f3..b112f043 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItem.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItem.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.List; -import java.util.TreeSet; import java.util.function.BiConsumer; public interface CustomFishingItem { diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/ItemType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/ItemType.java new file mode 100644 index 00000000..98a9ac6c --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/ItemType.java @@ -0,0 +1,35 @@ +package net.momirealms.customfishing.api.mechanic.item; + +import java.util.Objects; + +public class ItemType { + + public static ItemType LOOT = of("loot"); + + private final String type; + + public ItemType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public static ItemType of(String type) { + return new ItemType(type); + } + + @Override + public boolean equals(Object object) { + if (this == object) return true; + if (object == null || getClass() != object.getClass()) return false; + ItemType itemType = (ItemType) object; + return Objects.equals(type, itemType.type); + } + + @Override + public int hashCode() { + return Objects.hashCode(type); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java index 9baa2517..a305f8ab 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java @@ -17,67 +17,27 @@ package net.momirealms.customfishing.api.mechanic.loot; -import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -import net.momirealms.customfishing.api.mechanic.effect.BaseEffect; +import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect; +import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsKeys; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; public interface Loot { + boolean DEFAULT_INSTANT_GAME = false; + boolean DEFAULT_DISABLE_GAME = false; + boolean DEFAULT_DISABLE_STATS = false; + boolean DEFAULT_SHOW_IN_FINDER = false; + LootType DEFAULT_TYPE = LootType.ITEM; + MathValue DEFAULT_SCORE = MathValue.plain(0); + /** - * Check if this loot has an instance game. + * Check if this loot triggers an instant game. * - * @return True if it's an instance game, false otherwise. + * @return True if it triggers an instant game, false otherwise. */ - boolean instanceGame(); - - /** - * Check if the loot disables global actions - */ - boolean disableGlobalAction(); - - /** - * Get the unique ID of this loot. - * - * @return The unique ID. - */ - String getID(); - - /** - * Get the type of this loot. - * - * @return The loot type. - */ - LootType getType(); - - /** - * Get the nickname of this loot. - * - * @return The nickname. - */ - @NotNull - String getNick(); - - StatisticsKeys getStatisticKey(); - - /** - * Check if this loot should be shown in the finder. - * - * @return True if it should be shown, false otherwise. - */ - boolean showInFinder(); - - /** - * Get the score of this loot. - * - * @return The score. - */ - double getScore(); + boolean instantGame(); /** * Check if games are disabled for this loot. @@ -87,55 +47,176 @@ public interface Loot { boolean disableGame(); /** - * Check if statistics are disabled for this loot. + * Check if statistics recording is disabled for this loot. * * @return True if statistics are disabled, false otherwise. */ boolean disableStats(); /** - * Get the loot group of this loot. + * Check if this loot should be displayed in the finder tool. * - * @return The loot group. + * @return True if it should be shown in the finder, false otherwise. */ - String[] getLootGroup(); + boolean showInFinder(); /** - * Get the actions triggered by a specific action trigger. + * Get the unique identifier for this loot. * - * @param actionTrigger The action trigger. - * @return The actions triggered by the given trigger. + * @return The unique ID of the loot. */ - @Nullable - Action[] getActions(ActionTrigger actionTrigger); + String getID(); /** - * Trigger actions associated with a specific action trigger. + * Get the type of this loot. * - * @param actionTrigger The action trigger. - * @param playerContext The condition under which the actions are triggered. + * @return The type of the loot. */ - void triggerActions(ActionTrigger actionTrigger, PlayerContext playerContext); + LootType getType(); /** - * Get effects that bond to this loot + * Get the display nickname for this loot. * - * @return effects + * @return The nickname of the loot. */ - BaseEffect getBaseEffect(); + @NotNull + String getNick(); /** - * Get the actions triggered by a specific number of successes. + * Get the statistics key associated with this loot. * - * @param times The number of successes. - * @return The actions triggered by the specified number of successes. + * @return The statistics key for this loot. */ - Action[] getRecordActions(int times); + StatisticsKeys getStatisticKey(); /** - * Get a map of actions triggered by different numbers of successes. + * Get the score value for this loot. * - * @return A map of actions triggered by success times. + * @return The score associated with the loot. */ - HashMap[]> getRecordActionMap(); + MathValue getScore(); + + /** + * Get the groups this loot belongs to. + * + * @return An array of group names. + */ + String[] lootGroup(); + + /** + * Get the base effect associated with this loot. + * + * @return The base effect for the loot. + */ + LootBaseEffect baseEffect(); + + /** + * Create a new builder for constructing a Loot instance. + * + * @return A new Loot builder. + */ + static Builder builder() { + return new LootImpl.BuilderImpl(); + } + + /** + * Builder interface for constructing instances of Loot. + */ + interface Builder { + + /** + * Set the type of the loot. + * + * @param type The type of the loot. + * @return The builder instance. + */ + Builder type(LootType type); + + /** + * Specify whether the loot triggers an instant game. + * + * @param instantGame True if it should trigger an instant game. + * @return The builder instance. + */ + Builder instantGame(boolean instantGame); + + /** + * Specify whether games are disabled for this loot. + * + * @param disableGame True if games should be disabled. + * @return The builder instance. + */ + Builder disableGame(boolean disableGame); + + /** + * Specify whether statistics recording is disabled for this loot. + * + * @param disableStatistics True if statistics should be disabled. + * @return The builder instance. + */ + Builder disableStatistics(boolean disableStatistics); + + /** + * Specify whether the loot should be shown in the finder tool. + * + * @param showInFinder True if it should be shown in the finder. + * @return The builder instance. + */ + Builder showInFinder(boolean showInFinder); + + /** + * Set the unique ID for the loot. + * + * @param id The unique identifier. + * @return The builder instance. + */ + Builder id(String id); + + /** + * Set the nickname for the loot. + * + * @param nick The nickname. + * @return The builder instance. + */ + Builder nick(String nick); + + /** + * Set the statistics key for the loot. + * + * @param statisticsKeys The statistics key. + * @return The builder instance. + */ + Builder statisticsKeys(StatisticsKeys statisticsKeys); + + /** + * Set the score for the loot. + * + * @param score The score value. + * @return The builder instance. + */ + Builder score(MathValue score); + + /** + * Set the groups that the loot belongs to. + * + * @param groups An array of group names. + * @return The builder instance. + */ + Builder groups(String[] groups); + + /** + * Set the base effect for the loot. + * + * @param lootBaseEffect The base effect. + * @return The builder instance. + */ + Builder lootBaseEffect(LootBaseEffect lootBaseEffect); + + /** + * Build and return the Loot instance. + * + * @return The constructed Loot instance. + */ + Loot build(); + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java new file mode 100644 index 00000000..125b68df --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java @@ -0,0 +1,183 @@ +package net.momirealms.customfishing.api.mechanic.loot; + +import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect; +import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; +import net.momirealms.customfishing.api.mechanic.statistic.StatisticsKeys; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +import static java.util.Objects.requireNonNull; + +public class LootImpl implements Loot { + + private final LootType type; + private final boolean instantGame; + private final boolean disableGame; + private final boolean disableStatistics; + private final boolean showInFinder; + private final String id; + private final String nick; + private final StatisticsKeys statisticsKeys; + private final MathValue score; + private final String[] groups; + private final LootBaseEffect lootBaseEffect; + + public LootImpl(LootType type, boolean instantGame, boolean disableGame, boolean disableStatistics, boolean showInFinder, String id, String nick, StatisticsKeys statisticsKeys, MathValue score, String[] groups, LootBaseEffect lootBaseEffect) { + this.type = type; + this.instantGame = instantGame; + this.disableGame = disableGame; + this.disableStatistics = disableStatistics; + this.showInFinder = showInFinder; + this.id = id; + this.nick = nick; + this.statisticsKeys = statisticsKeys; + this.score = score; + this.groups = groups; + this.lootBaseEffect = lootBaseEffect; + } + + @Override + public boolean instantGame() { + return instantGame; + } + + @Override + public String getID() { + return id; + } + + @Override + public LootType getType() { + return type; + } + + @NotNull + @Override + public String getNick() { + return nick; + } + + @Override + public StatisticsKeys getStatisticKey() { + return statisticsKeys; + } + + @Override + public boolean showInFinder() { + return showInFinder; + } + + @Override + public MathValue getScore() { + return score; + } + + @Override + public boolean disableGame() { + return disableGame; + } + + @Override + public boolean disableStats() { + return disableStatistics; + } + + @Override + public String[] lootGroup() { + return groups; + } + + @Override + public LootBaseEffect baseEffect() { + return lootBaseEffect; + } + + public static class BuilderImpl implements Builder { + + private LootType type = DEFAULT_TYPE; + private boolean instantGame = DEFAULT_INSTANT_GAME; + private boolean disableGame = DEFAULT_DISABLE_GAME; + private boolean disableStatistics = DEFAULT_DISABLE_STATS; + private boolean showInFinder = DEFAULT_SHOW_IN_FINDER; + private String id = null; + private String nick = null; + private StatisticsKeys statisticsKeys = null; + private MathValue score = DEFAULT_SCORE; + private String[] groups = new String[0]; + private LootBaseEffect lootBaseEffect = null; + + @Override + public Builder type(LootType type) { + this.type = type; + return this; + } + @Override + public Builder instantGame(boolean instantGame) { + this.instantGame = instantGame; + return this; + } + @Override + public Builder disableGame(boolean disableGame) { + this.disableGame = disableGame; + return this; + } + @Override + public Builder disableStatistics(boolean disableStatistics) { + this.disableStatistics = disableStatistics; + return this; + } + @Override + public Builder showInFinder(boolean showInFinder) { + this.showInFinder = showInFinder; + return this; + } + @Override + public Builder id(String id) { + this.id = id; + return this; + } + @Override + public Builder nick(String nick) { + this.nick = nick; + return this; + } + @Override + public Builder statisticsKeys(StatisticsKeys statisticsKeys) { + this.statisticsKeys = statisticsKeys; + return this; + } + @Override + public Builder score(MathValue score) { + this.score = score; + return this; + } + @Override + public Builder groups(String[] groups) { + this.groups = groups; + return this; + } + @Override + public Builder lootBaseEffect(LootBaseEffect lootBaseEffect) { + this.lootBaseEffect = lootBaseEffect; + return this; + } + @Override + public Loot build() { + return new LootImpl( + type, + instantGame, + disableGame, + disableStatistics, + showInFinder, + requireNonNull(id), + Optional.ofNullable(nick).orElse(id), + Optional.ofNullable(statisticsKeys).orElse(new StatisticsKeys(id, id)), + score, + groups, + requireNonNull(lootBaseEffect) + ); + } + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootManager.java index f982e473..2cd7ec52 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootManager.java @@ -17,78 +17,31 @@ package net.momirealms.customfishing.api.mechanic.loot; +import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.effect.Effect; +import org.bukkit.entity.Player; 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; +import java.util.*; 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 getLootGroup(String key); + void registerLoot(@NotNull Loot loot); - /** - * 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); + @NotNull + List getGroupMembers(String key); - /** - * Retrieves a collection of all loot configuration keys. - * - * @return A collection of all loot configuration keys. - */ - Collection getAllLootKeys(); + @NotNull + Optional getLoot(String key); - /** - * Retrieves a collection of all loot configurations. - * - * @return A collection of all loot configurations. - */ - Collection getAllLoots(); + HashMap getLootWithWeight(Context context); - /** - * Retrieves loot configurations with weights based on a given condition. - * - * @param playerContext The condition used to filter loot configurations. - * @return A mapping of loot configuration keys to their associated weights. - */ - HashMap getLootWithWeight(PlayerContext playerContext); + Collection getPossibleLootKeys(Context context); - /** - * Get a collection of possible loot keys based on a given condition. - * - * @param playerContext The condition to determine possible loot. - * @return A collection of loot keys. - */ - Collection getPossibleLootKeys(PlayerContext playerContext); + @NotNull + Map getPossibleLootKeysWithWeight(Effect effect, Context context); - /** - * 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 playerContext The condition to determine possible loot. - * @return A map of loot keys and their weights. - */ - @NotNull Map getPossibleLootKeysWithWeight(Effect initialEffect, PlayerContext playerContext); - - /** - * Get the next loot item based on fishing effect and condition. - * - * @param effect The effect to apply weight modifiers. - * @param playerContext The condition to determine possible loot. - * @return The next loot item, or null if it doesn't exist. - */ - @Nullable Loot getNextLoot(Effect effect, PlayerContext playerContext); + @Nullable + Loot getNextLoot(Effect effect, Context context); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootType.java index 784e6c49..2a12c643 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootType.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootType.java @@ -21,6 +21,5 @@ public enum LootType { ITEM, ENTITY, - BLOCK, - GLOBAL + BLOCK } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/BaseEffectParserFunction.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/BaseEffectParserFunction.java new file mode 100644 index 00000000..b745312c --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/BaseEffectParserFunction.java @@ -0,0 +1,24 @@ +package net.momirealms.customfishing.api.mechanic.misc.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> function; + + public BaseEffectParserFunction(Function> function) { + this.function = function; + } + + public Consumer accept(Object object) { + return function.apply(object); + } + + @Override + public ParserType type() { + return ParserType.BASE_EFFECT; + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/FormatFunction.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ConfigParserFunction.java similarity index 51% rename from api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/FormatFunction.java rename to api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ConfigParserFunction.java index 066b7b39..8ddc4c43 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/FormatFunction.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ConfigParserFunction.java @@ -1,4 +1,6 @@ package net.momirealms.customfishing.api.mechanic.misc.function; -public interface FormatFunction { +public interface ConfigParserFunction { + + ParserType type(); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/EffectModifierParserFunction.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/EffectModifierParserFunction.java new file mode 100644 index 00000000..0410063a --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/EffectModifierParserFunction.java @@ -0,0 +1,24 @@ +package net.momirealms.customfishing.api.mechanic.misc.function; + +import net.momirealms.customfishing.api.mechanic.effect.Effect; + +import java.util.function.Consumer; +import java.util.function.Function; + +public class EffectModifierParserFunction implements ConfigParserFunction { + + private final Function> function; + + public EffectModifierParserFunction(Function> function) { + this.function = function; + } + + public Consumer accept(Object object) { + return function.apply(object); + } + + @Override + public ParserType type() { + return ParserType.EFFECT_MODIFIER; + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ItemPropertyFunction.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ItemParserFunction.java similarity index 57% rename from api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ItemPropertyFunction.java rename to api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ItemParserFunction.java index d92bfa8a..8aad1870 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ItemPropertyFunction.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ItemParserFunction.java @@ -8,13 +8,14 @@ import org.bukkit.inventory.ItemStack; import java.util.function.BiConsumer; import java.util.function.Function; -public class ItemPropertyFunction implements FormatFunction { +public class ItemParserFunction implements ConfigParserFunction { - private Function, Context>> function; - private int priority; + private final Function, Context>> function; + private final int priority; - public ItemPropertyFunction(int priority, Function, Context>> function) { + public ItemParserFunction(int priority, Function, Context>> function) { this.function = function; + this.priority = priority; } public BiConsumer, Context> accept(Object object) { @@ -24,4 +25,9 @@ public class ItemPropertyFunction implements FormatFunction { public int getPriority() { return priority; } + + @Override + public ParserType type() { + return ParserType.ITEM; + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/LootParserFunction.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/LootParserFunction.java new file mode 100644 index 00000000..fedb828c --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/LootParserFunction.java @@ -0,0 +1,24 @@ +package net.momirealms.customfishing.api.mechanic.misc.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> function; + + public LootParserFunction(Function> function) { + this.function = function; + } + + public Consumer accept(Object object) { + return function.apply(object); + } + + @Override + public ParserType type() { + return ParserType.LOOT; + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ParserType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ParserType.java new file mode 100644 index 00000000..9aebe3a2 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/function/ParserType.java @@ -0,0 +1,9 @@ +package net.momirealms.customfishing.api.mechanic.misc.function; + +public enum ParserType { + ITEM, + EFFECT_MODIFIER, + BASE_EFFECT, + LOOT, + EVENT +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/MathValue.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/MathValue.java index a16e448f..58687f4a 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/MathValue.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/MathValue.java @@ -70,7 +70,11 @@ public interface MathValue { */ static MathValue auto(Object o) { if (o instanceof String s) { - return expression(s); + try { + return plain(Double.parseDouble(s)); + } catch (NumberFormatException e) { + return expression(s); + } } else if (o instanceof Number n) { return plain(n.doubleValue()); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java index 3866f2f4..d9b3cf19 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java @@ -97,7 +97,7 @@ public interface RequirementManager { @Nullable RequirementFactory getRequirementFactory(@NotNull String type); - static boolean isSatisfied(Context context, @Nullable Requirement... requirements) { + static boolean isSatisfied(Context context, @Nullable Requirement[] requirements) { if (requirements == null) return true; for (Requirement requirement : requirements) { if (!requirement.isSatisfied(context)) { diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java new file mode 100644 index 00000000..1b0ed1bc --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatistics.java @@ -0,0 +1,133 @@ +package net.momirealms.customfishing.api.mechanic.statistic; + +import net.momirealms.customfishing.common.util.Pair; + +import java.util.Map; + +/** + * The FishingStatistics interface represents statistics related to fishing activities. + * It provides methods to retrieve and manipulate statistics such as the amount of fish caught and the maximum size of fish. + */ +public interface FishingStatistics { + + /** + * Retrieves the total amount of fish caught. + * + * @return the total amount of fish caught. + */ + int amountOfFishCaught(); + + /** + * Sets the total amount of fish caught. + * + * @param amountOfFishCaught the new total amount of fish caught. + */ + void amountOfFishCaught(int amountOfFishCaught); + + /** + * Retrieves the amount of fish caught with the specified ID. + * + * @param id the ID of the fish. + * @return the amount of fish caught with the specified ID. -1 if not exist. + */ + int getAmount(String id); + + /** + * Adds the specified amount to the fish caught with the specified ID and returns the updated amount. + * + * @param id the ID of the fish. + * @param amount the amount to add. + * @return a Pair containing the previous amount and the updated amount. + */ + Pair addAmount(String id, int amount); + + /** + * Sets the amount of fish caught with the specified ID. + * + * @param id the ID of the fish. + * @param amount the new amount to set. + */ + void setAmount(String id, int amount); + + /** + * Retrieves the maximum size of the fish with the specified ID. + * + * @param id the ID of the fish. + * @return the maximum size of the fish with the specified ID. -1f if not exist. + */ + float getMaxSize(String id); + + /** + * Sets the maximum size of the fish with the specified ID. + * + * @param id the ID of the fish. + * @param maxSize the new maximum size to set. + */ + void setMaxSize(String id, float maxSize); + + /** + * Updates the maximum size of the fish with the specified ID and returns true if successful, false otherwise. + * + * @param id the ID of the fish. + * @param newSize the new maximum size. + * @return true if the update is successful, false otherwise. + */ + boolean updateSize(String id, float newSize); + + /** + * Resets the fishing statistics, clearing all recorded data. + */ + void reset(); + + /** + * Retrieves the map containing the amounts of fish caught. + * + * @return the map containing the amounts of fish caught. + */ + Map getAmountMap(); + + /** + * Retrieves the map containing the maximum sizes of fish. + * + * @return the map containing the maximum sizes of fish. + */ + Map getSizeMap(); + + /** + * Creates a new Builder instance for constructing FishingStatistics objects. + * + * @return a new Builder instance. + */ + static Builder builder() { + return new FishingStatisticsImpl.BuilderImpl(); + } + + /** + * The Builder interface provides a fluent API for constructing FishingStatistics instances. + */ + interface Builder { + + /** + * Sets the map containing the amounts of fish caught. + * + * @param amountMap the map containing the amounts of fish caught. + * @return the Builder instance. + */ + Builder amountMap(Map amountMap); + + /** + * Sets the map containing the maximum sizes of fish. + * + * @param sizeMap the map containing the maximum sizes of fish. + * @return the Builder instance. + */ + Builder sizeMap(Map sizeMap); + + /** + * Builds and returns the FishingStatistics instance. + * + * @return the constructed FishingStatistics instance. + */ + FishingStatistics build(); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java new file mode 100644 index 00000000..e7745355 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/FishingStatisticsImpl.java @@ -0,0 +1,109 @@ +package net.momirealms.customfishing.api.mechanic.statistic; + +import net.momirealms.customfishing.common.util.Pair; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class FishingStatisticsImpl implements FishingStatistics { + + private int amountOfFishCaught; + private final Map amountMap; + private final Map sizeMap; + + public FishingStatisticsImpl(HashMap amountMap, HashMap sizeMap) { + this.amountMap = Collections.synchronizedMap(amountMap); + this.sizeMap = Collections.synchronizedMap(sizeMap); + this.amountOfFishCaught = amountMap.values().stream().mapToInt(Integer::intValue).sum(); + } + + @Override + public int amountOfFishCaught() { + return amountOfFishCaught; + } + + @Override + public void amountOfFishCaught(int amountOfFishCaught) { + this.amountOfFishCaught = amountOfFishCaught; + } + + @Override + public int getAmount(String id) { + return amountMap.getOrDefault(id, -1); + } + + @Override + public Pair addAmount(String id, int amount) { + if (amount <= 0) return Pair.of(-1, -1); + int previous = amountMap.getOrDefault(id, 0); + amountMap.put(id, previous + amount); + amountOfFishCaught += amount; + return Pair.of(previous, previous + amount); + } + + @Override + public void setAmount(String id, int amount) { + if (amount < 0) amount = 0; + int previous = amountMap.getOrDefault(id, 0); + int delta = amount - previous; + this.amountOfFishCaught += delta; + amountMap.put(id, amount); + } + + @Override + public float getMaxSize(String id) { + return sizeMap.getOrDefault(id, -1f); + } + + @Override + public void setMaxSize(String id, float maxSize) { + if (maxSize < 0) maxSize = 0; + sizeMap.put(id, maxSize); + } + + @Override + public boolean updateSize(String id, float newSize) { + if (newSize <= 0) return false; + float previous = sizeMap.getOrDefault(id, 0f); + if (previous >= newSize) return false; + sizeMap.put(id, newSize); + return true; + } + + @Override + public void reset() { + this.sizeMap.clear(); + this.amountMap.clear(); + this.amountOfFishCaught = 0; + } + + @Override + public Map getAmountMap() { + return amountMap; + } + + @Override + public Map getSizeMap() { + return sizeMap; + } + + public static class BuilderImpl implements Builder { + private final HashMap amountMap = new HashMap<>(); + private final HashMap sizeMap = new HashMap<>(); + @Override + public Builder amountMap(Map amountMap) { + this.amountMap.putAll(amountMap); + return this; + } + @Override + public Builder sizeMap(Map sizeMap) { + this.sizeMap.putAll(sizeMap); + return this; + } + @Override + public FishingStatistics build() { + return new FishingStatisticsImpl(amountMap, sizeMap); + } + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/Statistics.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/Statistics.java deleted file mode 100644 index 80556acd..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/Statistics.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.statistic; - -import net.momirealms.customfishing.api.data.StatisticData; -import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.context.Context; -import net.momirealms.customfishing.api.mechanic.loot.Loot; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Represents a statistics system for tracking loot and catch amounts. - */ -public class Statistics { - - private final ConcurrentHashMap statisticMap; - private final ConcurrentHashMap sizeMap; - private int total; - - /** - * Creates a new instance of Statistics based on provided statistic data. - * - * @param statisticData The initial statistic data. - */ - public Statistics(StatisticData statisticData) { - this.statisticMap = new ConcurrentHashMap<>(statisticData.amountMap); - this.sizeMap = new ConcurrentHashMap<>(statisticData.sizeMap); - this.total = statisticMap.values().stream().mapToInt(Integer::intValue).sum(); - } - - /** - * Adds an amount of loot to the statistics. - * - * @param loot The loot item. - * @param playerContext The condition associated with the loot. - * @param amount The amount of loot to add. - */ - public synchronized void addLootAmount(Loot loot, Context playerContext, int amount) { - if (amount < 1) { - return; - } - if (amount == 1) { - addSingleLootAmount(loot, playerContext); - return; - } - Integer previous = statisticMap.get(loot.getStatisticKey().amountKey()); - if (previous == null) previous = 0; - int after = previous + amount; - statisticMap.put(loot.getStatisticKey().amountKey(), after); - total += amount; - doSuccessTimesAction(previous, after, playerContext, loot); - } - - /** - * Performs actions associated with the success times of acquiring loot. - * - * @param previous The previous success times. - * @param after The updated success times. - * @param playerContext The condition associated with the loot. - * @param loot The loot item. - */ - private void doSuccessTimesAction(Integer previous, int after, Context playerContext, Loot loot) { - HashMap[]> actionMap = loot.getRecordActionMap(); - if (actionMap != null) { - for (Map.Entry[]> entry : actionMap.entrySet()) { - if (entry.getKey() > previous && entry.getKey() <= after) { - for (Action action : entry.getValue()) { - action.trigger(playerContext); - } - } - } - } - } - - public boolean setSizeIfHigher(String loot, float size) { - float previous = sizeMap.getOrDefault(loot, 0f); - if (previous >= size) return false; - sizeMap.put(loot, size); - return true; - } - - /** - * Adds a single loot amount to the statistics. - * - * @param loot The loot item. - * @param playerContext The condition associated with the loot. - */ - private void addSingleLootAmount(Loot loot, Context playerContext) { - Integer previous = statisticMap.get(loot.getID()); - if (previous == null) previous = 0; - int after = previous + 1; - statisticMap.put(loot.getID(), after); - total += 1; - Action[] actions = loot.getRecordActionMap().get(after); - if (actions != null) - for (Action action : actions) { - action.trigger(playerContext); - } - } - - /** - * Gets the amount of a specific loot item in the statistics. - * - * @param key The key of the loot item. - * @return The amount of the specified loot item. - */ - public int getLootAmount(String key) { - return statisticMap.getOrDefault(key, 0); - } - - public float getSizeRecord(String key) { - return sizeMap.getOrDefault(key, 0f); - } - - /** - * Resets the statistics data. - */ - public void reset() { - statisticMap.clear(); - total = 0; - } - - /** - * Gets the statistic map containing loot item keys and their respective amounts. - * - * @return The statistic map. - */ - public Map getStatisticMap() { - return statisticMap; - } - - public ConcurrentHashMap getSizeMap() { - return sizeMap; - } - - /** - * Sets data for a specific key in the statistics. - * - * @param key The key to set data for. - * @param value The value to set. - */ - public void setData(String key, int value) { - if (value <= 0) { - statisticMap.remove(key); - return; - } - statisticMap.put(key, value); - } - - /** - * Gets the total catch amount across all loot items. - * - * @return The total catch amount. - */ - public int getTotalCatchAmount() { - return total; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/StatisticsManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/StatisticsManager.java index faf0f689..44286c34 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/StatisticsManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/statistic/StatisticsManager.java @@ -20,19 +20,9 @@ package net.momirealms.customfishing.api.mechanic.statistic; 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. * @@ -40,5 +30,5 @@ public interface StatisticsManager { * @return A list of strings associated with the key or null if the key is not found. */ @Nullable - List getCategory(String key); + List getCategoryMembers(String key); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemConfig.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemConfig.java deleted file mode 100644 index a19ef39c..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemConfig.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem; - -import net.momirealms.customfishing.api.mechanic.requirement.Requirement; -import net.momirealms.customfishing.api.mechanic.totem.block.TotemBlock; -import org.bukkit.Location; - -/** - * This class represents the configuration for a totem. - * It defines various settings and properties for the totem. - */ -public class TotemConfig { - - private String key; - private TotemModel[] totemModels; - private TotemParticle[] particleSettings; - private Requirement[] requirements; - private double radius; - private int duration; - - /** - * Get the array of totem models that define the totem's pattern. - * - * @return An array of TotemModel objects. - */ - public TotemModel[] getTotemModels() { - return totemModels; - } - - /** - * Get the array of requirements for totem activation. - * - * @return An array of Requirement objects. - */ - public Requirement[] getRequirements() { - return requirements; - } - - /** - * Get the unique key associated with this totem configuration. - * - * @return The unique key as a string. - */ - public String getKey() { - return key; - } - - /** - * Check if the provided location matches any of the totem model patterns. - * - * @param location The location to check. - * @return True if the location matches a totem model pattern, false otherwise. - */ - public boolean isRightPattern(Location location) { - for (TotemModel totemModel : totemModels) { - if (totemModel.isPatternSatisfied(location)) { - return true; - } - } - return false; - } - - /** - * Get the array of particle settings for the totem's visual effects. - * - * @return An array of TotemParticle objects. - */ - public TotemParticle[] getParticleSettings() { - return particleSettings; - } - - /** - * Get the activation radius of the totem. - * - * @return The activation radius as a double. - */ - public double getRadius() { - return radius; - } - - /** - * Get the duration of the totem's effect when activated. - * - * @return The duration in seconds as an integer. - */ - public int getDuration() { - return duration; - } - - /** - * Get the totem core associated with the first totem model. - * This is used for some internal functionality. - * - * @return An array of TotemBlock objects representing the totem core. - */ - public TotemBlock[] getTotemCore() { - return totemModels[0].getTotemCore(); - } - - public static Builder builder(String key) { - return new Builder(key); - } - - /** - * This class represents a builder for creating instances of TotemConfig. - * It allows for the convenient construction of TotemConfig objects with various settings. - */ - public static class Builder { - - private final TotemConfig config; - - public Builder(String key) { - this.config = new TotemConfig(); - this.config.key = key; - } - - /** - * Sets the totem models for the TotemConfig being built. - * - * @param totemModels An array of TotemModel objects representing different totem models. - * @return The builder instance to allow for method chaining. - */ - public Builder setTotemModels(TotemModel[] totemModels) { - config.totemModels = totemModels; - return this; - } - - /** - * Sets the particle settings for the TotemConfig being built. - * - * @param particleSettings An array of TotemParticle objects representing particle settings. - * @return The builder instance to allow for method chaining. - */ - public Builder setParticleSettings(TotemParticle[] particleSettings) { - config.particleSettings = particleSettings; - return this; - } - - /** - * Sets the requirements for the TotemConfig being built. - * - * @param requirements An array of Requirement objects representing activation requirements. - * @return The builder instance to allow for method chaining. - */ - public Builder setRequirements(Requirement[] requirements) { - config.requirements = requirements; - return this; - } - - /** - * Sets the radius for the TotemConfig being built. - * - * @param radius The activation radius for the totem. - * @return The builder instance to allow for method chaining. - */ - public Builder setRadius(double radius) { - config.radius = radius; - return this; - } - - /** - * Sets the duration for the TotemConfig being built. - * - * @param duration The duration of the totem's effect. - * @return The builder instance to allow for method chaining. - */ - public Builder setDuration(int duration) { - config.duration = duration; - return this; - } - - /** - * Builds and returns the finalized TotemConfig object. - * - * @return The constructed TotemConfig object. - */ - public TotemConfig build() { - return config; - } - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemManager.java deleted file mode 100644 index 737801d6..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemManager.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem; - -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); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemModel.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemModel.java deleted file mode 100644 index c52c6c02..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemModel.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem; - -import net.momirealms.customfishing.api.mechanic.totem.block.TotemBlock; -import org.apache.commons.lang3.SerializationUtils; -import org.bukkit.Axis; -import org.bukkit.Location; - -import java.io.Serializable; -import java.util.StringJoiner; - -/** - * This class represents a totem model used to define the pattern of a totem. - */ -public class TotemModel implements Serializable { - - private int coreX; - private final int coreY; - private int coreZ; - // [Y][Z][X][alternative totem blocks] - private TotemBlock[][][][] model; - - /** - * Constructs a TotemModel with the specified parameters. - * - * @param coreX X-coordinate of the totem's core within the model. - * @param coreY Y-coordinate of the totem's core within the model. - * @param coreZ Z-coordinate of the totem's core within the model. - * @param model 3D array representing the totem model's structure. - */ - public TotemModel(int coreX, int coreY, int coreZ, TotemBlock[][][][] model) { - this.coreX = coreX; - this.coreY = coreY; - this.coreZ = coreZ; - this.model = model; - } - - /** - * Get the totem core as an array of TotemBlock objects. - * - * @return An array of TotemBlock objects representing the totem's core. - */ - public TotemBlock[] getTotemCore() { - return model[coreY][coreZ][coreX]; - } - - /** - * Get the X-coordinate of the totem's core within the model. - * - * @return The X-coordinate as an integer. - */ - public int getCoreX() { - return coreX; - } - - /** - * Get the Y-coordinate of the totem's core within the model. - * - * @return The Y-coordinate as an integer. - */ - public int getCoreY() { - return coreY; - } - - /** - * Get the Z-coordinate of the totem's core within the model. - * - * @return The Z-coordinate as an integer. - */ - public int getCoreZ() { - return coreZ; - } - - /** - * Get the 3D array representing the totem model's structure. - * - * @return The 3D array of TotemBlock objects. - */ - public TotemBlock[][][][] getModel() { - return model; - } - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - for (int h = 0; h < model.length; h++) { - stringBuilder.append("layer: ").append(h + 1).append("\n"); - TotemBlock[][][] totemBlocks1 = model[h]; - for (TotemBlock[][] totemBlocks2 : totemBlocks1) { - for (TotemBlock[] totemBlocks3 : totemBlocks2) { - StringJoiner stringJoiner = new StringJoiner("||"); - for (TotemBlock totemBlock : totemBlocks3) { - stringJoiner.add(totemBlock.toString()); - } - stringBuilder.append(stringJoiner).append("\t"); - } - stringBuilder.append("\n"); - } - } - return stringBuilder.toString(); - } - - public TotemModel deepClone() { - return SerializationUtils.clone(this); - } - - /** - * Rotate the totem model 90 degrees clockwise. - * - * @return The rotated TotemModel. - */ - public TotemModel rotate90() { - int tempX = this.coreX; - this.coreX = this.coreZ; - this.coreZ = this.model[0][0].length - 1 - tempX; - this.model = rotate90(model); - for (TotemBlock[][][] totemBlocks1 : model) { - for (TotemBlock[][] totemBlocks2 : totemBlocks1) { - for (TotemBlock[] totemBlocks3 : totemBlocks2) { - for (TotemBlock totemBlock : totemBlocks3) { - totemBlock.rotate90(); - } - } - } - } - return this; - } - - /** - * Mirror the totem model horizontally. - * - * @return The mirrored TotemModel. - */ - public TotemModel mirrorHorizontally() { - mirrorHorizontally(model); - this.coreZ = model[0].length - this.coreZ - 1; - for (TotemBlock[][][] totemBlocks1 : model) { - for (TotemBlock[][] totemBlocks2 : totemBlocks1) { - for (TotemBlock[] totemBlocks3 : totemBlocks2) { - for (TotemBlock totemBlock : totemBlocks3) { - totemBlock.mirror(Axis.X); - } - } - } - } - return this; - } - - /** - * Mirror the totem model vertically. - * - * @return The mirrored TotemModel. - */ - public TotemModel mirrorVertically() { - mirrorVertically(model); - this.coreX = model[0][0].length - this.coreX - 1; - - for (TotemBlock[][][] totemBlocks1 : model) { - for (TotemBlock[][] totemBlocks2 : totemBlocks1) { - for (TotemBlock[] totemBlocks3 : totemBlocks2) { - for (TotemBlock totemBlock : totemBlocks3) { - totemBlock.mirror(Axis.Z); - } - } - } - } - return this; - } - - /** - * Check if the provided location satisfies the pattern defined by the totem model. - * - * @param location The location to check. - * @return True if the location satisfies the pattern, false otherwise. - */ - public boolean isPatternSatisfied(Location location) { - Location startLoc = location.clone().subtract(0, coreY, 0); - - int height = model.length; - int width = model[0].length; - int length = model[0][0].length; - - for (int y = 0; y < height; y++) { - Location loc = startLoc.clone().add(-coreX, y, -coreZ); - for (int z = 0; z < width; z++) { - outer: - for (int x = 0; x < length; x++) { - for (TotemBlock totemBlock : model[y][z][x]) { - if (totemBlock.isRightBlock(loc.clone().add(x, 0, z).getBlock())) { - continue outer; - } - } - return false; - } - } - } - return true; - } - - /** - * Rotate a 3D totem model 90 degrees clockwise. - * - * @param matrix The 3D totem model to rotate. - * @return The rotated 3D totem model. - */ - private static TotemBlock[][][][] rotate90(TotemBlock[][][][] matrix) { - int height = matrix.length; - int rows = matrix[0].length; - int cols = matrix[0][0].length; - TotemBlock[][][][] rotated = new TotemBlock[height][cols][rows][]; - for (int h = 0; h < height; h++) { - for (int r = 0; r < rows; r++) { - for (int c = 0; c < cols; c++) { - rotated[h][c][rows - 1 - r] = matrix[h][r][c]; - } - } - } - return rotated; - } - - /** - * Mirror a 3D totem model horizontally. - * - * @param matrix The 3D totem model to mirror. - */ - private static void mirrorHorizontally(TotemBlock[][][][] matrix) { - int height = matrix.length; - int rows = matrix[0].length; - int cols = matrix[0][0].length; - - for (int h = 0; h < height; h++) { - for (int i = 0; i < rows / 2; i++) { - for (int j = 0; j < cols; j++) { - TotemBlock[] temp = matrix[h][i][j]; - matrix[h][i][j] = matrix[h][rows - i - 1][j]; - matrix[h][rows - i - 1][j] = temp; - } - } - } - } - - /** - * Mirror a 3D totem model vertically. - * - * @param matrix The 3D totem model to mirror. - */ - private static void mirrorVertically(TotemBlock[][][][] matrix) { - int height = matrix.length; - int rows = matrix[0].length; - int cols = matrix[0][0].length; - for (int h = 0; h < height; h++) { - for (int i = 0; i < rows; i++) { - for (int j = 0; j < cols / 2; j++) { - TotemBlock[] temp = matrix[h][i][j]; - matrix[h][i][j] = matrix[h][i][cols - j - 1]; - matrix[h][i][cols - j - 1] = temp; - } - } - } - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemParticle.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemParticle.java deleted file mode 100644 index f898bfd8..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/TotemParticle.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.momirealms.customfishing.api.mechanic.totem; - -import net.momirealms.customfishing.api.scheduler.CancellableTask; -import org.bukkit.Location; - -public interface TotemParticle { - - /** - * Start the particle task at specified location - * - * @param location location - * @param radius totem radius - * @return cancellable task - */ - CancellableTask start(Location location, double radius); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/TotemBlock.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/TotemBlock.java deleted file mode 100644 index 6d69648c..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/TotemBlock.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block; - -import net.momirealms.customfishing.api.mechanic.totem.block.property.TotemBlockProperty; -import net.momirealms.customfishing.api.mechanic.totem.block.type.TypeCondition; -import org.bukkit.Axis; -import org.bukkit.block.Block; - -import java.io.Serializable; -import java.util.StringJoiner; - -/** - * Represents a TotemBlock that defines conditions and properties for a specific block type in a totem structure. - */ -public class TotemBlock implements Serializable { - - private final TypeCondition typeCondition; - private final TotemBlockProperty[] properties; - - /** - * Initializes a TotemBlock with the specified TypeCondition and properties. - * - * @param typeCondition The TypeCondition that specifies the block type. - * @param properties An array of TotemBlockProperty objects representing additional block properties. - */ - public TotemBlock(TypeCondition typeCondition, TotemBlockProperty[] properties) { - this.typeCondition = typeCondition; - this.properties = properties; - } - - /** - * Gets the TypeCondition associated with this TotemBlock. - * - * @return The TypeCondition defining the block type. - */ - public TypeCondition getTypeCondition() { - return typeCondition; - } - - /** - * Gets an array of properties associated with this TotemBlock. - * - * @return An array of TotemBlockProperty objects representing block properties. - */ - public TotemBlockProperty[] getProperties() { - return properties; - } - - /** - * Checks if a given Block satisfies the TypeCondition and properties of this TotemBlock. - * - * @param block The Block to be checked against the conditions and properties. - * @return `true` if the block satisfies all conditions and properties, otherwise `false`. - */ - public boolean isRightBlock(Block block) { - if (!typeCondition.isMet(block)) { - return false; - } - for (TotemBlockProperty property : properties) { - if (!property.isPropertyMet(block)) { - return false; - } - } - return true; - } - - /** - * Rotates the properties of this TotemBlock by 90 degrees. - * This method should be called when the totem structure is rotated. - */ - public void rotate90() { - for (TotemBlockProperty property : properties) { - property.rotate90(); - } - } - - /** - * Mirrors the properties of this TotemBlock horizontally or vertically. - * This method should be called when the totem structure is mirrored. - * - * @param axis The Axis along which to mirror the properties (X or Z). - */ - public void mirror(Axis axis) { - for (TotemBlockProperty property : properties) { - property.mirror(axis); - } - } - - /** - * Returns the raw text representation of this TotemBlock, including its TypeCondition and properties. - * - * @return The raw text representation of this TotemBlock. - */ - @Override - public String toString() { - StringJoiner stringJoiner = new StringJoiner(";"); - for (TotemBlockProperty property : properties) { - stringJoiner.add(property.getRawText()); - } - return typeCondition.getRawText() + "{" + stringJoiner + "}"; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/AxisImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/AxisImpl.java deleted file mode 100644 index 7fd160e0..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/AxisImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.property; - -import org.bukkit.Axis; -import org.bukkit.block.Block; -import org.bukkit.block.data.Orientable; - -import java.io.Serializable; -import java.util.Locale; - -public class AxisImpl implements TotemBlockProperty, Serializable { - - private Axis axis; - - public AxisImpl(Axis axis) { - this.axis = axis; - } - - @Override - public TotemBlockProperty mirror(Axis axis) { - return this; - } - - /** - * Rotates the block axis 90 degrees. (X -> Z, Z -> X) - * @return The rotated block axis. - */ - @Override - public TotemBlockProperty rotate90() { - if (this.axis == Axis.X) { - axis = Axis.Z; - } else if (this.axis == Axis.Z) { - axis = Axis.X; - } - return this; - } - - /** - * Checks if the block has the property. - * @param block The block to check. - * @return True if the block has the property. - */ - @Override - public boolean isPropertyMet(Block block) { - if (block.getBlockData() instanceof Orientable orientable) { - return orientable.getAxis().equals(this.axis); - } - return false; - } - - @Override - public String getRawText() { - return "axis=" + axis.name().toLowerCase(Locale.ENGLISH); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/FaceImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/FaceImpl.java deleted file mode 100644 index 8519fad3..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/FaceImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.property; - -import org.bukkit.Axis; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Directional; - -import java.io.Serializable; -import java.util.Locale; - -public class FaceImpl implements TotemBlockProperty, Serializable { - - private BlockFace blockFace; - - public FaceImpl(BlockFace blockFace) { - this.blockFace = blockFace; - } - - /** - * Mirrors the block face if the axis is X or Z. - * @param axis The axis to mirror. - * @return The mirrored block face. - */ - @Override - public TotemBlockProperty mirror(Axis axis) { - if (axis == Axis.X) { - if (blockFace == BlockFace.SOUTH || blockFace == BlockFace.NORTH) { - return new FaceImpl(blockFace.getOppositeFace()); - } else { - return this; - } - } else if (axis == Axis.Z) { - if (blockFace == BlockFace.EAST || blockFace == BlockFace.WEST) { - return new FaceImpl(blockFace.getOppositeFace()); - } else { - return this; - } - } - return this; - } - - @Override - public TotemBlockProperty rotate90() { - switch (blockFace) { - case UP, DOWN -> { - return this; - } - case EAST -> blockFace = BlockFace.SOUTH; - case SOUTH -> blockFace = BlockFace.WEST; - case WEST -> blockFace = BlockFace.NORTH; - case NORTH -> blockFace = BlockFace.EAST; - default -> throw new IllegalArgumentException("Unsupported block facing: " + blockFace); - } - return this; - } - - @Override - public boolean isPropertyMet(Block block) { - if (block.getBlockData() instanceof Directional directional) { - return directional.getFacing().equals(this.blockFace); - } - return false; - } - - @Override - public String getRawText() { - return "face=" + blockFace.name().toLowerCase(Locale.ENGLISH); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/HalfImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/HalfImpl.java deleted file mode 100644 index e2a2e2fb..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/HalfImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.property; - -import org.bukkit.Axis; -import org.bukkit.block.Block; -import org.bukkit.block.data.Bisected; - -import java.io.Serializable; -import java.util.Locale; - -public class HalfImpl implements TotemBlockProperty, Serializable { - private final Bisected.Half half; - - public HalfImpl(Bisected.Half half) { - this.half = half; - } - - /** - * half is not affected by mirroring. - * @param axis The axis to mirror. - * @return this - */ - @Override - public TotemBlockProperty mirror(Axis axis) { - return this; - } - - /** - * half is not affected by rotation. - * @return this - */ - @Override - public TotemBlockProperty rotate90() { - return this; - } - - /** - * Checks if the block's half is the same as the half of this property. - * @param block The block to check. - * @return true if the block's half is the same as the half of this property. - */ - @Override - public boolean isPropertyMet(Block block) { - if (block.getBlockData() instanceof Bisected bisected) { - return bisected.getHalf().equals(this.half); - } - return false; - } - - /** - * Returns the raw text of the half property. - * @return The raw text of the half property. - */ - @Override - public String getRawText() { - return "half=" + half.name().toLowerCase(Locale.ENGLISH); - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/TotemBlockProperty.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/TotemBlockProperty.java deleted file mode 100644 index be238682..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/property/TotemBlockProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.property; - -import org.bukkit.Axis; -import org.bukkit.block.Block; - -public interface TotemBlockProperty { - - /** - * Mirrors the block face if the axis is X or Z. - * @param axis The axis to mirror. - * @return The mirrored block face. - */ - TotemBlockProperty mirror(Axis axis); - - /** - * Rotates the block face 90 degrees. - * @return The rotated block face. - */ - TotemBlockProperty rotate90(); - - /** - * Checks if the block has the property. - * @param block The block to check. - * @return True if the block has the property. - */ - boolean isPropertyMet(Block block); - - /** - * Gets the raw text of the property. - * @return The raw text of the property. - */ - String getRawText(); -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/EndWithType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/EndWithType.java deleted file mode 100644 index 1d723c5f..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/EndWithType.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.type; - -import org.bukkit.block.Block; - -import java.io.Serializable; - -/** - * Represents a TypeCondition that checks if a Block's type name ends with a specified string. - */ -public class EndWithType implements TypeCondition, Serializable { - - private final String end; - - public EndWithType(String end) { - this.end = end; - } - - /** - * Checks if the specified Block's type name ends with the configured ending string. - * - * @param type The Block to check. - * @return `true` if the Block's type name ends with the specified string, otherwise `false`. - */ - @Override - public boolean isMet(Block type) { - return type.getType().name().endsWith(end); - } - - /** - * Gets the raw text representation of this TypeCondition. - * The raw text includes the asterisk (*) followed by the configured ending string. - * - * @return The raw text representation of this TypeCondition. - */ - @Override - public String getRawText() { - return "*" + end; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/EqualType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/EqualType.java deleted file mode 100644 index 6ebe37fd..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/EqualType.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.type; - -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import org.bukkit.block.Block; - -import java.io.Serializable; - -/** - * Represents a TypeCondition that checks if a Block's type matches a specified type string. - */ -public class EqualType implements TypeCondition, Serializable { - - private final String type; - - public EqualType(String type) { - this.type = type; - } - - /** - * Checks if the specified Block's type matches the configured type string. - * - * @param type The Block to check. - * @return `true` if the Block's type matches the specified type string, otherwise `false`. - */ - @Override - public boolean isMet(Block type) { - return this.type.equals(BukkitCustomFishingPlugin.get().getBlockManager().getAnyPluginBlockID(type)); - } - - /** - * Gets the raw text representation of this TypeCondition, which is the configured type string. - * - * @return The raw text representation of this TypeCondition. - */ - @Override - public String getRawText() { - return type; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/StartWithType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/StartWithType.java deleted file mode 100644 index 7fab7ba1..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/StartWithType.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.type; - -import org.bukkit.block.Block; - -import java.io.Serializable; - -/** - * Represents a TypeCondition that checks if a Block's type starts with a specified prefix. - */ -public class StartWithType implements TypeCondition, Serializable { - - private final String start; - - public StartWithType(String start) { - this.start = start; - } - - /** - * Checks if the specified Block's type starts with the configured prefix. - * - * @param type The Block to check. - * @return `true` if the Block's type starts with the specified prefix, otherwise `false`. - */ - @Override - public boolean isMet(Block type) { - return type.getType().name().startsWith(start); - } - - /** - * Gets the raw text representation of this TypeCondition, which is the configured prefix followed by '*'. - * - * @return The raw text representation of this TypeCondition. - */ - @Override - public String getRawText() { - return start + "*"; - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/TypeCondition.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/TypeCondition.java deleted file mode 100644 index 4f5422b2..00000000 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/block/type/TypeCondition.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.api.mechanic.totem.block.type; - -import org.bukkit.block.Block; - -/** - * Represents a condition used to check the type of a Block. - */ -public interface TypeCondition { - - /** - * Checks if the specified Block meets the condition. - * - * @param block The Block to check. - * @return `true` if the condition is met, otherwise `false`. - */ - boolean isMet(Block block); - - /** - * Gets the raw text representation of this TypeCondition. - * - * @return The raw text representation of this TypeCondition. - */ - String getRawText(); - - /** - * Gets a TypeCondition based on its raw text representation. - * - * @param raw The raw text representation of the TypeCondition. - * @return A TypeCondition instance corresponding to the raw text. - */ - static TypeCondition getTypeCondition(String raw) { - if (raw.startsWith("*")) { - return new EndWithType(raw.substring(1)); - } else if (raw.endsWith("*")) { - return new StartWithType(raw.substring(0, raw.length() -1)); - } else { - return new EqualType(raw); - } - } -} diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/DataStorageInterface.java b/api/src/main/java/net/momirealms/customfishing/api/storage/DataStorageProvider.java similarity index 88% rename from api/src/main/java/net/momirealms/customfishing/api/data/DataStorageInterface.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/DataStorageProvider.java index 31757898..40282df4 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/data/DataStorageInterface.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/DataStorageProvider.java @@ -15,9 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.data; +package net.momirealms.customfishing.api.storage; -import net.momirealms.customfishing.api.data.user.OfflineUser; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.user.UserData; +import org.bukkit.OfflinePlayer; import java.util.Collection; import java.util.Optional; @@ -25,7 +27,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; -public interface DataStorageInterface { +public interface DataStorageProvider { /** * Initialize the data resource @@ -79,7 +81,7 @@ public interface DataStorageInterface { * @param users A collection of OfflineUser objects representing players. * @param unlock Whether to unlock the player data after updating. */ - void updateManyPlayersData(Collection users, boolean unlock); + void updateManyPlayersData(Collection> users, boolean unlock); /** * Lock or unlock a player's data in the SQL database. @@ -92,8 +94,7 @@ public interface DataStorageInterface { /** * 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 getUniqueUsers(boolean legacy); + Set getUniqueUsers(); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/manager/StorageManager.java b/api/src/main/java/net/momirealms/customfishing/api/storage/StorageManager.java similarity index 75% rename from api/src/main/java/net/momirealms/customfishing/api/manager/StorageManager.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/StorageManager.java index b84b5c1a..36e6b07c 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/manager/StorageManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/StorageManager.java @@ -15,12 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.manager; +package net.momirealms.customfishing.api.storage; -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 net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.user.UserData; +import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,14 +43,15 @@ public interface StorageManager { * @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); + @Nullable + UserData getOnlineUser(UUID uuid); /** * Get all the online users * * @return online users */ - Collection getOnlineUsers(); + Collection> getOnlineUsers(); /** * Asynchronously retrieves an OfflineUser instance for the specified UUID. @@ -62,33 +62,23 @@ public interface StorageManager { * @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> 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); + CompletableFuture>> getOfflineUser(UUID uuid, boolean lock); /** * Asynchronously saves user data for an OfflineUser. * - * @param offlineUser The OfflineUser whose data needs to be saved. + * @param userData 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 saveUserData(OfflineUser offlineUser, boolean unlock); + CompletableFuture saveUserData(UserData userData, boolean unlock); /** * Gets the data source used for data storage. * * @return The data source. */ - DataStorageInterface getDataSource(); + DataStorageProvider getDataSource(); /** * Checks if Redis is enabled. diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/StorageType.java b/api/src/main/java/net/momirealms/customfishing/api/storage/StorageType.java similarity index 94% rename from api/src/main/java/net/momirealms/customfishing/api/data/StorageType.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/StorageType.java index da6a3fe4..8a641db4 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/data/StorageType.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/StorageType.java @@ -15,10 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.data; +package net.momirealms.customfishing.api.storage; public enum StorageType { - JSON, YAML, H2, diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/EarningData.java b/api/src/main/java/net/momirealms/customfishing/api/storage/data/EarningData.java similarity index 63% rename from api/src/main/java/net/momirealms/customfishing/api/data/EarningData.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/data/EarningData.java index 38b4d3d6..c479a9e6 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/data/EarningData.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/data/EarningData.java @@ -15,10 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.data; +package net.momirealms.customfishing.api.storage.data; import com.google.gson.annotations.SerializedName; +/** + * The EarningData class holds data related to the earnings of a player from selling fish. + * It includes the total earnings and the date of the earnings record. + */ public class EarningData { @SerializedName("earnings") @@ -26,11 +30,22 @@ public class EarningData { @SerializedName("date") public int date; + /** + * Constructs a new EarningData instance with specified earnings and date. + * + * @param earnings the total earnings from fishing. + * @param date the date of the earnings record. + */ public EarningData(double earnings, int date) { this.earnings = earnings; this.date = date; } + /** + * Creates an instance of EarningData with default values (zero earnings and date). + * + * @return a new instance of EarningData with default values. + */ public static EarningData empty() { return new EarningData(0d, 0); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/InventoryData.java b/api/src/main/java/net/momirealms/customfishing/api/storage/data/InventoryData.java similarity index 62% rename from api/src/main/java/net/momirealms/customfishing/api/data/InventoryData.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/data/InventoryData.java index ab8a3208..1d2b2118 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/data/InventoryData.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/data/InventoryData.java @@ -15,22 +15,36 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.data; +package net.momirealms.customfishing.api.storage.data; import com.google.gson.annotations.SerializedName; +/** + * The InventoryData class holds data related to a player's fishing bag. + * It includes a serialized representation of the inventory and the size of the inventory. + */ public class InventoryData { @SerializedName("inventory") public String serialized; - @SerializedName("size") public int size; + /** + * Creates an instance of InventoryData with default values (empty inventory and size of 9). + * + * @return a new instance of InventoryData with default values. + */ public static InventoryData empty() { return new InventoryData("", 9); } + /** + * Constructs a new InventoryData instance with specified serialized inventory and size. + * + * @param serialized the serialized representation of the inventory. + * @param size the size of the inventory. + */ public InventoryData(String serialized, int size) { this.serialized = serialized; this.size = size; diff --git a/api/src/main/java/net/momirealms/customfishing/api/storage/data/PlayerData.java b/api/src/main/java/net/momirealms/customfishing/api/storage/data/PlayerData.java new file mode 100644 index 00000000..72fb802e --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/data/PlayerData.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.api.storage.data; + +import com.google.gson.annotations.SerializedName; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The PlayerData class holds data related to a player. + * It includes the player's name, their fishing statistics, inventory data, and earnings data. + */ +public class PlayerData { + + public static final String DEFAULT_NAME = ""; + public static final StatisticData DEFAULT_STATISTICS = StatisticData.empty(); + public static final InventoryData DEFAULT_BAG = InventoryData.empty(); + public static final EarningData DEFAULT_EARNING = EarningData.empty(); + + @SerializedName("name") + protected String name; + @SerializedName("stats") + protected StatisticData statisticsData; + @SerializedName("bag") + protected InventoryData bagData; + @SerializedName("trade") + protected EarningData earningData; + + /** + * Constructs a new PlayerData instance with specified values. + * + * @param name the name of the player. + * @param statisticsData the fishing statistics data. + * @param bagData the inventory data. + * @param earningData the earnings data. + */ + public PlayerData(String name, StatisticData statisticsData, InventoryData bagData, EarningData earningData) { + this.name = name; + this.statisticsData = statisticsData; + this.bagData = bagData; + this.earningData = earningData; + } + + // A static instance representing a locked state of PlayerData. + public static PlayerData LOCKED = empty(); + + /** + * Creates a new Builder instance for constructing PlayerData objects. + * + * @return a new Builder instance. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Creates an instance of PlayerData with empty fields. + * + * @return a new instance of PlayerData with empty fields. + */ + public static PlayerData empty() { + return new Builder() + .bag(InventoryData.empty()) + .earnings(EarningData.empty()) + .stats(StatisticData.empty()) + .build(); + } + + /** + * The Builder class provides a fluent API for constructing PlayerData instances. + */ + public static class Builder { + + private String name = DEFAULT_NAME; + private StatisticData statisticsData = DEFAULT_STATISTICS; + private InventoryData bagData = DEFAULT_BAG; + private EarningData earningData = DEFAULT_EARNING; + + /** + * Sets the name for the PlayerData instance. + * + * @param name the name of the player. + * @return the Builder instance. + */ + @NotNull + public Builder name(@Nullable String name) { + this.name = name; + return this; + } + + /** + * Sets the statistics data for the PlayerData instance. + * + * @param statisticsData the fishing statistics data. + * @return the Builder instance. + */ + @NotNull + public Builder stats(@Nullable StatisticData statisticsData) { + this.statisticsData = statisticsData; + return this; + } + + /** + * Sets the inventory data for the PlayerData instance. + * + * @param inventoryData the inventory data. + * @return the Builder instance. + */ + @NotNull + public Builder bag(@Nullable InventoryData inventoryData) { + this.bagData = inventoryData; + return this; + } + + /** + * Sets the earnings data for the PlayerData instance. + * + * @param earningData the earnings data. + * @return the Builder instance. + */ + @NotNull + public Builder earnings(@Nullable EarningData earningData) { + this.earningData = earningData; + return this; + } + + /** + * Builds and returns the PlayerData instance. + * + * @return the constructed PlayerData instance. + */ + @NotNull + public PlayerData build() { + return new PlayerData(name, statisticsData, bagData, earningData); + } + } + + /** + * Gets the statistics data for the player. + * + * @return the fishing statistics data. + */ + public StatisticData getStatistics() { + return statisticsData; + } + + /** + * Gets the bag data for the player. + * + * @return the bag data. + */ + public InventoryData getBagData() { + return bagData; + } + + /** + * Gets the earnings data for the player. + * + * @return the earnings data. + */ + public EarningData getEarningData() { + return earningData; + } + + /** + * Gets the name of the player. + * + * @return the player's name. + */ + public String getName() { + return name; + } + + /** + * Checks if the PlayerData instance is in a locked state. + * + * @return true if the PlayerData instance is locked, false otherwise. + */ + public boolean isLocked() { + return this == LOCKED; + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/StatisticData.java b/api/src/main/java/net/momirealms/customfishing/api/storage/data/StatisticData.java similarity index 64% rename from api/src/main/java/net/momirealms/customfishing/api/data/StatisticData.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/data/StatisticData.java index 80b4cef4..24ef0a7a 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/data/StatisticData.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/data/StatisticData.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.data; +package net.momirealms.customfishing.api.storage.data; import com.google.gson.annotations.SerializedName; import org.jetbrains.annotations.NotNull; @@ -23,6 +23,10 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; +/** + * The StatisticData class stores fishing statistics including amounts and sizes + * of fish caught, represented as maps. + */ public class StatisticData { @SerializedName(value="amount", alternate={"map"}) @@ -31,16 +35,30 @@ public class StatisticData { @SerializedName("size") public Map sizeMap; - public StatisticData() { + /** + * Default constructor that initializes the sizeMap and amountMap as empty HashMaps. + */ + private StatisticData() { this.sizeMap = new HashMap<>(); this.amountMap = new HashMap<>(); } + /** + * Parameterized constructor that initializes the sizeMap and amountMap with provided values. + * + * @param amount a map containing the amount of each type of fish caught. + * @param size a map containing the size of each type of fish caught. + */ public StatisticData(@NotNull Map amount, @NotNull Map size) { this.amountMap = amount; this.sizeMap = size; } + /** + * Creates an instance of StatisticData with empty maps. + * + * @return a new instance of StatisticData with empty maps. + */ public static StatisticData empty() { return new StatisticData(); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/data/user/OfflineUser.java b/api/src/main/java/net/momirealms/customfishing/api/storage/user/UserData.java similarity index 81% rename from api/src/main/java/net/momirealms/customfishing/api/data/user/OfflineUser.java rename to api/src/main/java/net/momirealms/customfishing/api/storage/user/UserData.java index 2322379c..8a46f319 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/data/user/OfflineUser.java +++ b/api/src/main/java/net/momirealms/customfishing/api/storage/user/UserData.java @@ -15,16 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.api.data.user; +package net.momirealms.customfishing.api.storage.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 net.momirealms.customfishing.api.storage.data.EarningData; +import net.momirealms.customfishing.api.storage.data.PlayerData; import java.util.UUID; -public interface OfflineUser { +public interface UserData { /** * Get the username @@ -74,4 +72,11 @@ public interface OfflineUser { * @return player data */ PlayerData getPlayerData(); + + /** + * Get the user + * + * @return user + */ + O getUser(); } diff --git a/common/src/main/java/net/momirealms/customfishing/common/config/ConfigManager.java b/common/src/main/java/net/momirealms/customfishing/common/config/ConfigLoader.java similarity index 58% rename from common/src/main/java/net/momirealms/customfishing/common/config/ConfigManager.java rename to common/src/main/java/net/momirealms/customfishing/common/config/ConfigLoader.java index 9645cf6f..ef0fec43 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/config/ConfigManager.java +++ b/common/src/main/java/net/momirealms/customfishing/common/config/ConfigLoader.java @@ -2,9 +2,15 @@ package net.momirealms.customfishing.common.config; import dev.dejvokep.boostedyaml.YamlDocument; -public interface ConfigManager { +import java.io.File; + +public interface ConfigLoader { YamlDocument loadConfig(String filePath); YamlDocument loadConfig(String filePath, char routeSeparator); + + YamlDocument loadData(File file); + + YamlDocument loadData(File file, char routeSeparator); } diff --git a/common/src/main/java/net/momirealms/customfishing/common/config/node/Node.java b/common/src/main/java/net/momirealms/customfishing/common/config/node/Node.java index 3b69acc8..e3ef6b94 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/config/node/Node.java +++ b/common/src/main/java/net/momirealms/customfishing/common/config/node/Node.java @@ -32,4 +32,9 @@ public class Node { public Node getChild(String node) { return childTree.get(node); } + + @Nullable + public Node removeChild(String node) { + return childTree.remove(node); + } } diff --git a/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java b/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java index 1f8de79a..2f7832ab 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java +++ b/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java @@ -18,7 +18,7 @@ public class AdventureHelper { private final MiniMessage miniMessage; private final MiniMessage miniMessageStrict; private final GsonComponentSerializer gsonComponentSerializer; - private final Cache miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES) + private final Cache miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); private AdventureHelper() { this.miniMessage = MiniMessage.builder().build(); diff --git a/common/src/main/java/net/momirealms/customfishing/common/item/Item.java b/common/src/main/java/net/momirealms/customfishing/common/item/Item.java index 7cac0779..7ec36416 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/item/Item.java +++ b/common/src/main/java/net/momirealms/customfishing/common/item/Item.java @@ -1,7 +1,6 @@ package net.momirealms.customfishing.common.item; import java.util.List; -import java.util.Objects; import java.util.Optional; public interface Item { diff --git a/common/src/main/java/net/momirealms/customfishing/common/plugin/CustomFishingPlugin.java b/common/src/main/java/net/momirealms/customfishing/common/plugin/CustomFishingPlugin.java index f781c139..4e4f5d9c 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/plugin/CustomFishingPlugin.java +++ b/common/src/main/java/net/momirealms/customfishing/common/plugin/CustomFishingPlugin.java @@ -1,6 +1,6 @@ package net.momirealms.customfishing.common.plugin; -import net.momirealms.customfishing.common.config.ConfigManager; +import net.momirealms.customfishing.common.config.ConfigLoader; import net.momirealms.customfishing.common.dependency.DependencyManager; import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.plugin.classpath.ClassPathAppender; @@ -30,7 +30,7 @@ public interface CustomFishingPlugin { TranslationManager getTranslationManager(); - ConfigManager getConfigManager(); + ConfigLoader getConfigManager(); String getServerVersion(); diff --git a/common/src/main/java/net/momirealms/customfishing/common/util/RandomUtils.java b/common/src/main/java/net/momirealms/customfishing/common/util/RandomUtils.java new file mode 100644 index 00000000..8c878f61 --- /dev/null +++ b/common/src/main/java/net/momirealms/customfishing/common/util/RandomUtils.java @@ -0,0 +1,55 @@ +package net.momirealms.customfishing.common.util; + +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +public class RandomUtils { + + private final Random random; + + private RandomUtils() { + random = ThreadLocalRandom.current(); + } + + private static class SingletonHolder { + private static final RandomUtils INSTANCE = new RandomUtils(); + } + + private static RandomUtils getInstance() { + return SingletonHolder.INSTANCE; + } + + public static int generateRandomInt(int min, int max) { + return getInstance().random.nextInt(max - min + 1) + min; + } + + public static double generateRandomDouble(double min, double max) { + return min + (max - min) * getInstance().random.nextDouble(); + } + + public static boolean generateRandomBoolean() { + return getInstance().random.nextBoolean(); + } + + public static T getRandomElementFromArray(T[] array) { + int index = getInstance().random.nextInt(array.length); + return array[index]; + } + + public static T[] getRandomElementsFromArray(T[] array, int count) { + if (count > array.length) { + throw new IllegalArgumentException("Count cannot be greater than array length"); + } + + @SuppressWarnings("unchecked") + T[] result = (T[]) new Object[count]; + + for (int i = 0; i < count; i++) { + int index = getInstance().random.nextInt(array.length - i); + result[i] = array[index]; + array[index] = array[array.length - i - 1]; + } + + return result; + } +} \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java similarity index 100% rename from core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java rename to compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java diff --git a/core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java b/core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java index 33dff496..c65b3658 100644 --- a/core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java @@ -38,8 +38,6 @@ import net.momirealms.customfishing.mechanic.misc.CoolDownManager; import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; import net.momirealms.customfishing.mechanic.statistic.StatisticsManagerImpl; import net.momirealms.customfishing.mechanic.totem.TotemManagerImpl; -import net.momirealms.customfishing.setting.CFConfig; -import net.momirealms.customfishing.setting.CFLocale; import net.momirealms.customfishing.storage.StorageManagerImpl; import net.momirealms.customfishing.version.VersionManagerImpl; import org.bstats.bukkit.Metrics; diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CFPapi.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CFPapi.java index 5e204bf8..39e54f63 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CFPapi.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CFPapi.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.bukkit.compatibility.papi; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.user.OnlineUser; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -87,7 +86,7 @@ public class CFPapi extends PlaceholderExpansion { } } case "earnings" -> { - OnlineUser user; + OnlineUserData user; if (split.length < 3) { user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); } else { @@ -103,7 +102,7 @@ public class CFPapi extends PlaceholderExpansion { } case "canearn" -> { if (split.length < 3) { - OnlineUser user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); + OnlineUserData user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); if (user == null) return ""; return String.format("%.2f", plugin.getMarketManager().getEarningLimit(player) - user.getEarningData().earnings); @@ -113,7 +112,7 @@ public class CFPapi extends PlaceholderExpansion { return ""; } - OnlineUser user = plugin.getStorageManager().getOnlineUser(another.getUniqueId()); + OnlineUserData user = plugin.getStorageManager().getOnlineUser(another.getUniqueId()); if (user == null) return ""; return String.format("%.2f", plugin.getMarketManager().getEarningLimit(another) - user.getEarningData().earnings); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java index 4a90fd9d..6e21fdb2 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.bukkit.compatibility.papi; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/StatisticsPapi.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/StatisticsPapi.java index a8803583..0cbd1677 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/StatisticsPapi.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/StatisticsPapi.java @@ -19,8 +19,6 @@ package net.momirealms.customfishing.bukkit.compatibility.papi; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.user.OnlineUser; -import net.momirealms.customfishing.api.mechanic.statistic.Statistics; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,7 +63,7 @@ public class StatisticsPapi extends PlaceholderExpansion { @Override public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) { - OnlineUser onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); + OnlineUserData onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); if (onlineUser == null) return "Data not loaded"; Statistics statistics = onlineUser.getStatistics(); String[] split = params.split("_", 2); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BattlePassHook.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BattlePassHook.java index 80a8821f..a24586af 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BattlePassHook.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BattlePassHook.java @@ -65,7 +65,7 @@ public class BattlePassHook implements Listener { .buildAndExecute(); // Group Fish Quest - String[] lootGroup = event.getLoot().getLootGroup(); + String[] lootGroup = event.getLoot().lootGroup(); if (event.getLoot() != null && lootGroup != null) for (String group : lootGroup) { this.executionBuilder("group") diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BetonQuestHook.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BetonQuestHook.java index 8f1f5af5..72e1c9b2 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BetonQuestHook.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/BetonQuestHook.java @@ -148,7 +148,7 @@ public class BetonQuestHook { if (isInvalidLocation(event, onlineProfile)) { return; } - String[] groups = event.getLoot().getLootGroup(); + String[] groups = event.getLoot().lootGroup(); if (groups != null) for (String group : groups) { if (this.loot_groups.contains(group) && this.checkConditions(onlineProfile)) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/ClueScrollsHook.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/ClueScrollsHook.java index a8d97aff..60fa4f2e 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/ClueScrollsHook.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/ClueScrollsHook.java @@ -61,8 +61,8 @@ public class ClueScrollsHook implements Listener { ); } - if (loot != null && loot.getLootGroup() != null) { - for (String group : event.getLoot().getLootGroup()) { + if (loot != null && loot.lootGroup() != null) { + for (String group : event.getLoot().lootGroup()) { groupClue.handle( player, event.getAmount(), diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/NotQuestHook.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/NotQuestHook.java index 14d1734d..5de30970 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/NotQuestHook.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/quest/NotQuestHook.java @@ -55,7 +55,7 @@ public class NotQuestHook implements Listener { for (final ActiveObjective activeObjective : activeQuest.getActiveObjectives()) { if (activeObjective.getObjective() instanceof GroupObjective groupObjective) { if (activeObjective.isUnlocked()) { - final String[] groups = loot.getLootGroup(); + final String[] groups = loot.lootGroup(); if (groups != null) for (String group : groups) { if (group.equals(groupObjective.getGroupToFish())) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigLoader.java b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigLoader.java new file mode 100644 index 00000000..4930000e --- /dev/null +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigLoader.java @@ -0,0 +1,152 @@ +package net.momirealms.customfishing.bukkit.config; + +import dev.dejvokep.boostedyaml.block.implementation.Section; +import net.momirealms.customfishing.api.mechanic.config.ConfigManager; +import net.momirealms.customfishing.api.mechanic.context.ContextKeys; +import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; +import net.momirealms.customfishing.api.mechanic.misc.value.TextValue; +import net.momirealms.customfishing.api.mechanic.statistic.StatisticsKeys; +import net.momirealms.customfishing.common.helper.AdventureHelper; +import net.momirealms.customfishing.common.plugin.CustomFishingPlugin; +import net.momirealms.customfishing.common.util.ListUtils; +import net.momirealms.customfishing.common.util.RandomUtils; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class BukkitConfigLoader extends ConfigManager { + + public BukkitConfigLoader(CustomFishingPlugin plugin) { + super(plugin); + this.registerBuiltInItemProperties(); + this.registerBuiltInBaseEffectParser(); + this.registerBuiltInLootParser(); + } + + private void registerBuiltInItemProperties() { + this.registerItemParser(arg -> { + MathValue mathValue = MathValue.auto(arg); + return (item, context) -> item.customModelData((int) mathValue.evaluate(context)); + }, 5000, "custom-model-data"); + this.registerItemParser(arg -> { + TextValue textValue = TextValue.auto((String) arg); + return (item, context) -> { + item.displayName(AdventureHelper.miniMessageToJson(textValue.render(context))); + }; + }, 4000, "display", "name"); + this.registerItemParser(arg -> { + List list = ListUtils.toList(arg); + List> lore = new ArrayList<>(); + for (String text : list) { + lore.add(TextValue.auto(text)); + } + return (item, context) -> { + item.lore(lore.stream() + .map(it -> AdventureHelper.miniMessageToJson(it.render(context))) + .toList()); + }; + }, 3_000, "display", "lore"); + this.registerItemParser(arg -> { + boolean enable = (boolean) arg; + return (item, context) -> { + if (!enable) return; + item.setTag(context.arg(ContextKeys.ID), "CustomFishing", "id"); + item.setTag(context.arg(ContextKeys.TYPE), "CustomFishing", "type"); + }; + }, 2_000, "tag"); + this.registerItemParser(arg -> { + String sizePair = (String) arg; + String[] split = sizePair.split("~", 2); + MathValue min = MathValue.auto(split[0]); + MathValue max = MathValue.auto(split[1]); + return (item, context) -> { + double minSize = min.evaluate(context); + double maxSize = max.evaluate(context); + float size = (float) RandomUtils.generateRandomDouble(minSize, maxSize); + item.setTag(size, "CustomFishing", "size"); + context.arg(ContextKeys.SIZE, size); + }; + }, 1_000, "size"); + this.registerItemParser(arg -> { + Section section = (Section) arg; + MathValue base = MathValue.auto(section.get("base")); + MathValue bonus = MathValue.auto(section.get("bonus")); + return (item, context) -> { + double basePrice = base.evaluate(context); + double bonusPrice = bonus.evaluate(context); + float size = Optional.ofNullable(context.arg(ContextKeys.SIZE)).orElse(0f); + double price = basePrice + bonusPrice * size; + item.setTag(price, "CustomFishing", "price"); + context.arg(ContextKeys.PRICE, price); + }; + }, 1_500, "price"); + } + + private void registerBuiltInBaseEffectParser() { + this.registerBaseEffectParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.difficultyAdder(mathValue); + }, "base-difficulty-adder"); + this.registerBaseEffectParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.difficultyMultiplier(mathValue); + }, "base-difficulty-multiplier"); + this.registerBaseEffectParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.gameTimeAdder(mathValue); + }, "base-game-time-adder"); + this.registerBaseEffectParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.gameTimeMultiplier(mathValue); + }, "base-game-time-multiplier"); + this.registerBaseEffectParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.waitTimeAdder(mathValue); + }, "base-wait-time-adder"); + this.registerBaseEffectParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.waitTimeMultiplier(mathValue); + }, "base-wait-time-multiplier"); + } + + private void registerBuiltInLootParser() { + this.registerLootParser(object -> { + String string = (String) object; + return builder -> builder.nick(string); + }, "nick"); + this.registerLootParser(object -> { + boolean value = (boolean) object; + return builder -> builder.showInFinder(value); + }, "show-in-fishfinder"); + this.registerLootParser(object -> { + boolean value = (boolean) object; + return builder -> builder.disableStatistics(value); + }, "disable-stat"); + this.registerLootParser(object -> { + boolean value = (boolean) object; + return builder -> builder.disableGame(value); + }, "disable-game"); + this.registerLootParser(object -> { + boolean value = (boolean) object; + return builder -> builder.instantGame(value); + }, "instant-game"); + this.registerLootParser(object -> { + MathValue mathValue = MathValue.auto(object); + return builder -> builder.score(mathValue); + }, "score"); + this.registerLootParser(object -> { + List args = ListUtils.toList(object); + return builder -> builder.groups(args.toArray(new String[0])); + }, "group"); + this.registerLootParser(object -> { + Section section = (Section) object; + StatisticsKeys keys = new StatisticsKeys( + section.getString("amount"), + section.getString("size") + ); + return builder -> builder.statisticsKeys(keys); + }, "statistics"); + } +} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/event/BukkitEventManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/event/BukkitEventManager.java new file mode 100644 index 00000000..53c0de5d --- /dev/null +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/event/BukkitEventManager.java @@ -0,0 +1,32 @@ +package net.momirealms.customfishing.bukkit.event; + +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.mechanic.event.EventCarrier; +import net.momirealms.customfishing.api.mechanic.event.EventManager; + +import java.util.HashMap; +import java.util.Optional; + +public class BukkitEventManager implements EventManager { + + private final HashMap carrierMap = new HashMap<>(); + private BukkitCustomFishingPlugin plugin; + + public BukkitEventManager(BukkitCustomFishingPlugin plugin) { + this.plugin = plugin; + } + + @Override + public Optional getEventCarrier(String id) { + return Optional.ofNullable(carrierMap.get(id)); + } + + @Override + public boolean registerEventCarrier(String id, EventCarrier carrier) { + if (carrierMap.containsKey(id)) { + return false; + } + carrierMap.put(id, carrier); + return true; + } +} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java index 9dbae893..f3f0a5ca 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java @@ -7,11 +7,6 @@ import net.momirealms.customfishing.api.integration.ItemProvider; import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem; import net.momirealms.customfishing.api.mechanic.item.ItemManager; -import net.momirealms.customfishing.api.mechanic.misc.function.FormatFunction; -import net.momirealms.customfishing.api.mechanic.misc.function.ItemPropertyFunction; -import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; -import net.momirealms.customfishing.api.mechanic.misc.value.TextValue; -import net.momirealms.customfishing.common.config.node.Node; import net.momirealms.customfishing.common.item.Item; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -21,10 +16,7 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Locale; -import java.util.Map; -import java.util.Set; import java.util.function.BiConsumer; -import java.util.function.Function; import static java.util.Objects.requireNonNull; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java index 236b579e..6d15c914 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.Icon; import net.momirealms.customfishing.gui.page.file.FileSelector; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java index 4fc69874..484cfeee 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.ParentPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java index 261381bc..7c3b3eb8 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.Icon; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import xyz.xenondevs.invui.gui.PagedGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java index 2923b49a..ca81b9b1 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.Icon; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import xyz.xenondevs.invui.gui.PagedGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java index 31a5388f..5688795c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.Icon; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import xyz.xenondevs.invui.gui.ScrollGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java index e08e120f..31eaf903 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.Icon; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import xyz.xenondevs.invui.gui.ScrollGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java index 858d72fa..b2ab90e6 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.AmountEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java index 5a15f33e..99f5a5d6 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.CustomModelDataEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java index 5f5caa5b..a0426d10 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.DisplayNameEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java index 9795241a..344b4d50 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.DurabilityEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java index e430c351..8ff0a1e5 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.EnchantmentEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java index 12b2036c..b299bcfc 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java @@ -21,7 +21,6 @@ import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java index 6f6e89d6..712730af 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.ItemFlagEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java index db65aa65..7d4b6838 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.LoreEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java index 207d7f7c..3f45729c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.MaterialEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java index af21a788..c1a9d86d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.NBTEditor; -import net.momirealms.customfishing.setting.CFLocale; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java index 83be5005..e89ffec8 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java index ce7d320a..8a22266c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.PriceEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java index c069b995..4ba2dcc9 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java index cb2282f3..cd2490fc 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.SizeEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java index 526ee8aa..7f752e22 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java index 9cfa7bf2..bcf77c38 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.EnchantmentEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java index 5786e165..33494e6b 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java index 1b91a7a3..fa9b664a 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java index 18c0ed19..50e50582 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java index 2be67535..1afd900c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java index e53d108c..d20702e9 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java index cbc7c1fb..0bfd0f5b 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.NickEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java index f47e2282..2b054a5c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.page.property.ScoreEditor; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java index 6f5a1bf3..f224bb4f 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java @@ -19,7 +19,6 @@ package net.momirealms.customfishing.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java b/core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java index 8be1cff4..11d77ce2 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java @@ -23,7 +23,6 @@ import net.momirealms.customfishing.gui.icon.BackToFolderItem; import net.momirealms.customfishing.gui.icon.ScrollDownItem; import net.momirealms.customfishing.gui.icon.ScrollUpItem; import net.momirealms.customfishing.gui.page.item.ItemSelector; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java index e077084a..bb62ff98 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java @@ -24,7 +24,6 @@ import net.momirealms.customfishing.gui.icon.BackGroundItem; import net.momirealms.customfishing.gui.icon.BackToPageItem; import net.momirealms.customfishing.gui.icon.NextPageItem; import net.momirealms.customfishing.gui.icon.PreviousPageItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java b/core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java index f8955e40..6bae1973 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java @@ -25,7 +25,6 @@ import net.momirealms.customfishing.gui.icon.BackGroundItem; import net.momirealms.customfishing.gui.icon.BackToFolderItem; import net.momirealms.customfishing.gui.icon.NextPageItem; import net.momirealms.customfishing.gui.icon.PreviousPageItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java index 91c44c1e..c305f515 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java index 0d1c0694..98baf372 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java @@ -21,7 +21,6 @@ import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWra import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java index dc479679..1633da0d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java index e50abf28..96df812a 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java index 3df4e12c..de46f2b1 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java index b6910cbf..20f27479 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java @@ -21,7 +21,6 @@ import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWra import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java index cfd53b6e..f45e4640 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java index c3969e03..ba1fbaae 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java @@ -22,7 +22,6 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; import net.momirealms.customfishing.mechanic.item.ItemManagerImpl; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java index 7d151268..e1bf1986 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java index 7f6dffc2..4cce6da3 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java index 62c33e35..09ecbbe6 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java index be2030de..a0b72d0a 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java b/core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java index 9ab6ca24..5d6b4199 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; import net.momirealms.customfishing.gui.SectionPage; import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java index e44fa875..ec12db69 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java @@ -23,7 +23,6 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.action.ActionManager; import net.momirealms.customfishing.api.mechanic.loot.LootManager; -import net.momirealms.customfishing.api.mechanic.GlobalSettings; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionExpansion; import net.momirealms.customfishing.api.mechanic.action.ActionFactory; @@ -34,7 +33,6 @@ import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.bukkit.compatibility.VaultHook; import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl; import net.momirealms.customfishing.common.util.ClassUtils; -import net.momirealms.customfishing.setting.CFLocale; import net.momirealms.customfishing.util.*; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java index 17beb876..727d298a 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java @@ -19,15 +19,11 @@ package net.momirealms.customfishing.mechanic.bag; import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.user.OfflineUser; -import net.momirealms.customfishing.api.mechanic.bag.BagManager; -import net.momirealms.customfishing.api.mechanic.effect.EffectManager; +import net.momirealms.customfishing.api.storage.user.UserData; import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.bag.FishingBagHolder; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; import net.momirealms.customfishing.api.util.InventoryUtils; import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl; -import net.momirealms.customfishing.setting.CFConfig; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -48,7 +44,7 @@ import java.util.*; public class BagManagerImpl implements BagManager, Listener { private final BukkitCustomFishingPlugin plugin; - private final HashMap tempEditMap; + private final HashMap tempEditMap; private Action[] collectLootActions; private Action[] bagFullActions; private boolean bagStoreLoots; @@ -145,7 +141,7 @@ public class BagManagerImpl implements BagManager, Listener { * @param userData The OfflineUser data of the player whose bag is being edited. */ @Override - public void editOfflinePlayerBag(Player admin, OfflineUser userData) { + public void editOfflinePlayerBag(Player admin, UserData userData) { this.tempEditMap.put(admin.getUniqueId(), userData); admin.openInventory(userData.getHolder().getInventory()); } @@ -160,10 +156,10 @@ public class BagManagerImpl implements BagManager, Listener { if (!(event.getInventory().getHolder() instanceof FishingBagHolder)) return; final Player viewer = (Player) event.getPlayer(); - OfflineUser offlineUser = tempEditMap.remove(viewer.getUniqueId()); - if (offlineUser == null) + UserData userData = tempEditMap.remove(viewer.getUniqueId()); + if (userData == null) return; - plugin.getStorageManager().saveUserData(offlineUser, true); + plugin.getStorageManager().saveUserData(userData, true); } /** @@ -210,10 +206,10 @@ public class BagManagerImpl implements BagManager, Listener { */ @EventHandler public void onQuit(PlayerQuitEvent event) { - OfflineUser offlineUser = tempEditMap.remove(event.getPlayer().getUniqueId()); - if (offlineUser == null) + UserData userData = tempEditMap.remove(event.getPlayer().getUniqueId()); + if (userData == null) return; - plugin.getStorageManager().saveUserData(offlineUser, true); + plugin.getStorageManager().saveUserData(userData, true); } @Override diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java index 18b4bf4f..8923fae5 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java @@ -25,7 +25,6 @@ import net.momirealms.customfishing.api.mechanic.block.BlockManager; import net.momirealms.customfishing.api.mechanic.block.*; import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.bukkit.compatibility.block.VanillaBlockImpl; -import net.momirealms.customfishing.setting.CFConfig; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.*; import org.bukkit.block.*; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java index 29be675f..c4d03ec2 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java @@ -30,8 +30,6 @@ import net.momirealms.customfishing.mechanic.competition.actionbar.ActionBarMana import net.momirealms.customfishing.mechanic.competition.bossbar.BossBarManager; import net.momirealms.customfishing.mechanic.competition.ranking.LocalRankingImpl; import net.momirealms.customfishing.mechanic.competition.ranking.RedisRankingImpl; -import net.momirealms.customfishing.setting.CFConfig; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/CompetitionManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/CompetitionManagerImpl.java index 3b33fff4..52df26a7 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/CompetitionManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/CompetitionManagerImpl.java @@ -25,7 +25,6 @@ import net.momirealms.customfishing.api.mechanic.competition.*; import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfigImpl; import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfigImpl; import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.setting.CFLocale; import net.momirealms.customfishing.storage.method.database.nosql.RedisManager; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.Bukkit; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/actionbar/ActionBarSender.java b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/actionbar/ActionBarSender.java index ac98f579..57878a56 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/actionbar/ActionBarSender.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/actionbar/ActionBarSender.java @@ -22,7 +22,6 @@ import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfi import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.mechanic.competition.Competition; import net.momirealms.customfishing.mechanic.misc.DynamicText; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.entity.Player; import java.util.HashMap; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/bossbar/BossBarSender.java b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/bossbar/BossBarSender.java index fb733831..34b6ecc0 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/bossbar/BossBarSender.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/bossbar/BossBarSender.java @@ -30,7 +30,6 @@ import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.api.util.ReflectionUtils; import net.momirealms.customfishing.mechanic.competition.Competition; import net.momirealms.customfishing.mechanic.misc.DynamicText; -import net.momirealms.customfishing.setting.CFLocale; import org.bukkit.boss.BarColor; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/ranking/RedisRankingImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/ranking/RedisRankingImpl.java index 9c2a96f7..4b9230bf 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/competition/ranking/RedisRankingImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/competition/ranking/RedisRankingImpl.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.mechanic.competition.ranking; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer; import net.momirealms.customfishing.api.mechanic.competition.Ranking; -import net.momirealms.customfishing.setting.CFConfig; import net.momirealms.customfishing.storage.method.database.nosql.RedisManager; import redis.clients.jedis.Jedis; import redis.clients.jedis.resps.Tuple; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java index e66aa8b7..d5c35ce2 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java @@ -20,12 +20,7 @@ package net.momirealms.customfishing.mechanic.effect; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Key; import net.momirealms.customfishing.api.common.Pair; -import net.momirealms.customfishing.api.mechanic.effect.EffectManager; -import net.momirealms.customfishing.api.mechanic.GlobalSettings; -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 net.momirealms.customfishing.api.mechanic.effect.LootBaseEffectImpl; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; import net.momirealms.customfishing.mechanic.misc.value.PlainMathValue; @@ -208,7 +203,7 @@ public class EffectManagerImpl implements EffectManager { for (String group : modList) { String[] split = group.split(":",2); String key = split[0]; - List members = plugin.getLootManager().getLootGroup(key); + List members = plugin.getLootManager().getGroupMembers(key); if (members == null) { LogUtils.warn("Group " + key + " doesn't contain any loot. The effect would not take effect."); return result; @@ -242,8 +237,8 @@ public class EffectManagerImpl implements EffectManager { } @Override - public BaseEffect getBaseEffect(ConfigurationSection section) { - if (section == null) return new BaseEffect( + public LootBaseEffectImpl getBaseEffect(ConfigurationSection section) { + if (section == null) return new LootBaseEffectImpl( new PlainMathValue(0), new PlainMathValue(1d), new PlainMathValue(0), new PlainMathValue(1d), new PlainMathValue(0), new PlainMathValue(1d) @@ -254,7 +249,7 @@ public class EffectManagerImpl implements EffectManager { MathValue waitTimeMultiplier = section.contains("wait-time-multiplier") ? ConfigUtils.getValue(section.get("wait-time-multiplier")) : new PlainMathValue(1); MathValue difficultyMultiplier = section.contains("difficulty-multiplier") ? ConfigUtils.getValue(section.get("difficulty-multiplier")) : new PlainMathValue(1); MathValue gameTimeMultiplier = section.contains("game-time-multiplier") ? ConfigUtils.getValue(section.get("game-time-multiplier")) : new PlainMathValue(1); - return new BaseEffect( + return new LootBaseEffectImpl( waitTime, waitTimeMultiplier, difficulty, difficultyMultiplier, gameTime, gameTimeMultiplier diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java new file mode 100644 index 00000000..d9ac85d7 --- /dev/null +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java @@ -0,0 +1,4 @@ +package net.momirealms.customfishing.mechanic.fishing; + +public class BukkitFishingManager { +} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java index 62341e8d..99a36643 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java @@ -29,14 +29,9 @@ import net.momirealms.customfishing.api.event.LavaFishingEvent; import net.momirealms.customfishing.api.event.RodCastEvent; import net.momirealms.customfishing.api.mechanic.fishing.FishingManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; -import net.momirealms.customfishing.api.mechanic.GlobalSettings; -import net.momirealms.customfishing.api.mechanic.TempFishingState; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; import net.momirealms.customfishing.api.mechanic.effect.Effect; -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 net.momirealms.customfishing.api.mechanic.game.BasicGameConfig; import net.momirealms.customfishing.api.mechanic.game.GameInstance; import net.momirealms.customfishing.api.mechanic.game.GameSettings; @@ -45,7 +40,6 @@ import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.api.mechanic.loot.LootType; import net.momirealms.customfishing.api.util.WeightUtils; import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.setting.CFConfig; import net.momirealms.customfishing.util.ItemUtils; import org.bukkit.*; import org.bukkit.entity.*; @@ -481,7 +475,7 @@ public class FishingManagerImpl implements Listener, FishingManager { loot.triggerActions(ActionTrigger.BITE, fishingPreparation); fishingPreparation.triggerActions(ActionTrigger.BITE); - if (loot.instanceGame() && !loot.disableGame()) { + if (loot.instantGame() && !loot.disableGame()) { if (!loot.disableGlobalAction()) GlobalSettings.triggerLootActions(ActionTrigger.HOOK, fishingPreparation); loot.triggerActions(ActionTrigger.HOOK, fishingPreparation); diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java index 96c54d19..906c892c 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java @@ -20,12 +20,8 @@ package net.momirealms.customfishing.mechanic.fishing; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.GlobalSettings; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -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.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java index e4cdd1e1..4c73310a 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java @@ -22,13 +22,10 @@ import net.kyori.adventure.sound.Sound; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.event.FishHookLandEvent; import net.momirealms.customfishing.api.event.LavaFishingEvent; -import net.momirealms.customfishing.api.mechanic.TempFishingState; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; import net.momirealms.customfishing.api.mechanic.effect.Effect; -import net.momirealms.customfishing.api.mechanic.effect.FishingEffect; import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.setting.CFConfig; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -146,7 +143,7 @@ public class HookCheckTimerTask implements Runnable { this.setNextLoot(); if (this.loot != null) { - this.tempEffect = this.loot.getBaseEffect().build(fishingPreparation.getPlayer(), fishingPreparation.getArgs()); + this.tempEffect = this.loot.baseEffect().build(fishingPreparation.getPlayer(), fishingPreparation.getArgs()); this.tempEffect.merge(this.initialEffect); this.setTempState(); this.startLavaFishingMechanic(); @@ -191,7 +188,7 @@ public class HookCheckTimerTask implements Runnable { this.manager.removeTempFishingState(fishingPreparation.getPlayer()); BukkitCustomFishingPlugin.get().debug("No loot available for " + fishingPreparation.getPlayer().getName() + " at " + fishingPreparation.getLocation()); } else { - this.tempEffect = this.loot.getBaseEffect().build(fishingPreparation.getPlayer(), fishingPreparation.getArgs()); + this.tempEffect = this.loot.baseEffect().build(fishingPreparation.getPlayer(), fishingPreparation.getArgs()); this.tempEffect.merge(this.initialEffect); this.setWaitTime(); this.setTempState(); @@ -263,14 +260,14 @@ public class HookCheckTimerTask implements Runnable { int random; if (CFConfig.overrideVanilla) { random = ThreadLocalRandom.current().nextInt(CFConfig.lavaMinTime, CFConfig.lavaMaxTime); - random *= tempEffect.getWaitTimeMultiplier(); + random *= tempEffect.waitTimeMultiplier(); random += tempEffect.waitTimeAdder(); random = Math.max(1, random); } else { random = ThreadLocalRandom.current().nextInt(CFConfig.lavaMinTime, CFConfig.lavaMaxTime); random -= lureLevel * 100; random = Math.max(CFConfig.lavaMinTime, random); - random *= tempEffect.getWaitTimeMultiplier(); + random *= tempEffect.waitTimeMultiplier(); random += tempEffect.waitTimeAdder(); random = Math.max(1, random); } @@ -347,10 +344,10 @@ public class HookCheckTimerTask implements Runnable { private void setWaitTime() { if (CFConfig.overrideVanilla) { double initialTime = ThreadLocalRandom.current().nextInt(CFConfig.waterMaxTime - CFConfig.waterMinTime + 1) + CFConfig.waterMinTime; - fishHook.setWaitTime(Math.max(1, (int) (initialTime * tempEffect.getWaitTimeMultiplier() + tempEffect.waitTimeAdder()))); + fishHook.setWaitTime(Math.max(1, (int) (initialTime * tempEffect.waitTimeMultiplier() + tempEffect.waitTimeAdder()))); } else { - fishHook.setMinWaitTime(Math.max(1, (int) (fishHook.getMinWaitTime() * tempEffect.getWaitTimeMultiplier() + tempEffect.waitTimeAdder()))); - fishHook.setMaxWaitTime(Math.max(2, (int) (fishHook.getMaxWaitTime() * tempEffect.getWaitTimeMultiplier() + tempEffect.waitTimeAdder()))); + fishHook.setMinWaitTime(Math.max(1, (int) (fishHook.getMinWaitTime() * tempEffect.waitTimeMultiplier() + tempEffect.waitTimeAdder()))); + fishHook.setMaxWaitTime(Math.max(2, (int) (fishHook.getMaxWaitTime() * tempEffect.waitTimeMultiplier() + tempEffect.waitTimeAdder()))); } } } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java index 9f408f9b..c38e9b40 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java @@ -20,12 +20,10 @@ package net.momirealms.customfishing.mechanic.game; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.game.GameManager; import net.momirealms.customfishing.api.mechanic.game.*; -import net.momirealms.customfishing.api.util.OffsetUtils; +import net.momirealms.customfishing.common.util.Pair; import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.util.ClassUtils; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java index 60753c2f..56caa9da 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java @@ -17,12 +17,9 @@ package net.momirealms.customfishing.mechanic.hook; -import de.tr7zw.changeme.nbtapi.NBTCompound; -import de.tr7zw.changeme.nbtapi.NBTItem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.hook.HookManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; -import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier; import net.momirealms.customfishing.api.mechanic.hook.HookSetting; import net.momirealms.customfishing.mechanic.item.ItemManagerImpl; import net.momirealms.customfishing.util.ItemUtils; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java index 719971b9..40f2c59d 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java @@ -31,17 +31,14 @@ import net.momirealms.customfishing.api.event.FishingLootSpawnEvent; import net.momirealms.customfishing.api.mechanic.action.ActionManager; import net.momirealms.customfishing.api.mechanic.item.ItemManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; -import net.momirealms.customfishing.api.mechanic.GlobalSettings; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier; import net.momirealms.customfishing.api.integration.ItemProvider; import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import net.momirealms.customfishing.bukkit.compatibility.item.CustomFishingItemImpl; import net.momirealms.customfishing.bukkit.compatibility.item.VanillaItemImpl; import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl; -import net.momirealms.customfishing.setting.CFConfig; import net.momirealms.customfishing.util.ConfigUtils; import net.momirealms.customfishing.util.ItemUtils; import net.momirealms.customfishing.util.LocationUtils; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/BukkitLootManager.java b/core/src/main/java/net/momirealms/customfishing/mechanic/loot/BukkitLootManager.java new file mode 100644 index 00000000..303a486d --- /dev/null +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/loot/BukkitLootManager.java @@ -0,0 +1,82 @@ +package net.momirealms.customfishing.mechanic.loot; + +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.loot.Loot; +import net.momirealms.customfishing.api.mechanic.loot.LootManager; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +import static java.util.Objects.requireNonNull; + +public class BukkitLootManager implements LootManager { + + private final BukkitCustomFishingPlugin plugin; + private final HashMap lootMap = new HashMap<>(); + private final HashMap> groupMembersMap = new HashMap<>(); + + public BukkitLootManager(BukkitCustomFishingPlugin plugin) { + this.plugin = plugin; + } + + private void loadConfig() { + + } + + @Override + public void registerLoot(@NotNull final Loot loot) { + requireNonNull(loot, "loot cannot be null"); + this.lootMap.put(loot.getID(), loot); + for (String group : loot.lootGroup()) { + addGroupMember(group, loot.getID()); + } + } + + private void addGroupMember(String group, String member) { + List members = groupMembersMap.get(group); + if (members == null) { + members = new ArrayList<>(List.of(member)); + groupMembersMap.put(group, members); + } else { + members.add(member); + } + } + + @NotNull + @Override + public List getGroupMembers(String key) { + return Optional.ofNullable(groupMembersMap.get(key)).orElse(List.of()); + } + + @NotNull + @Override + public Optional getLoot(String key) { + return Optional.ofNullable(lootMap.get(key)); + } + + @Override + public HashMap getLootWithWeight(Context context) { + return null; + } + + @Override + public Collection getPossibleLootKeys(Context context) { + return List.of(); + } + + @NotNull + @Override + public Map getPossibleLootKeysWithWeight(Effect effect, Context context) { + return Map.of(); + } + + @Nullable + @Override + public Loot getNextLoot(Effect effect, Context context) { + return null; + } +} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java index bc06dcdd..29f03085 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java @@ -26,7 +26,6 @@ import net.momirealms.customfishing.api.mechanic.loot.LootType; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsKeys; import net.momirealms.customfishing.api.util.WeightUtils; import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.setting.CFConfig; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -101,9 +100,9 @@ public class LootManagerImpl implements LootManager { * @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 + @NotNull @Override - public List getLootGroup(String key) { + public List getGroupMembers(String key) { return lootGroupMap.get(key); } @@ -113,7 +112,7 @@ public class LootManagerImpl implements LootManager { * @param key The key of the loot configuration. * @return The Loot object associated with the specified loot key, or null if not found. */ - @Nullable + @NotNull @Override public Loot getLoot(String key) { return lootMap.get(key); @@ -173,12 +172,12 @@ public class LootManagerImpl implements LootManager { public Map getPossibleLootKeysWithWeight(Effect effect, PlayerContext playerContext) { Map lootWithWeight = ((RequirementManagerImpl) plugin.getRequirementManager()).getLootWithWeight(playerContext); Player player = playerContext.getPlayer(); - for (Pair pair : effect.weightModifier()) { + for (Pair pair : effect.weightOperations()) { Double previous = lootWithWeight.get(pair.left()); if (previous != null) lootWithWeight.put(pair.left(), pair.right().modify(player, previous)); } - for (Pair pair : effect.weightModifierIgnored()) { + for (Pair pair : effect.weightOperationsIgnored()) { double previous = lootWithWeight.getOrDefault(pair.left(), 0d); lootWithWeight.put(pair.left(), pair.right().modify(player, previous)); } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java b/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java index 57811287..3c10a707 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.mechanic.market; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.EarningData; +import net.momirealms.customfishing.api.storage.data.EarningData; import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder; import net.momirealms.customfishing.api.util.InventoryUtils; import net.momirealms.customfishing.util.ItemUtils; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java index c5c417e3..3456452a 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java @@ -19,8 +19,7 @@ package net.momirealms.customfishing.mechanic.market; import de.tr7zw.changeme.nbtapi.NBTItem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.EarningData; -import net.momirealms.customfishing.api.data.user.OnlineUser; +import net.momirealms.customfishing.api.storage.data.EarningData; import net.momirealms.customfishing.api.mechanic.market.MarketManager; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder; @@ -96,7 +95,7 @@ public class MarketManagerImpl implements MarketManager, Listener { int now = getRealTimeDate(); if (this.date != now) { this.date = now; - for (OnlineUser onlineUser : plugin.getStorageManager().getOnlineUsers()) { + for (OnlineUserData onlineUser : plugin.getStorageManager().getOnlineUsers()) { onlineUser.getEarningData().date = now; onlineUser.getEarningData().earnings = 0d; } @@ -193,7 +192,7 @@ public class MarketManagerImpl implements MarketManager, Listener { @Override public void openMarketGUI(Player player) { if (!isEnable()) return; - OnlineUser user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); + OnlineUserData user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); if (user == null) { LogUtils.warn("Player " + player.getName() + "'s market data is not loaded yet."); return; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/value/ExpressionMathValue.java b/core/src/main/java/net/momirealms/customfishing/mechanic/misc/value/ExpressionMathValue.java deleted file mode 100644 index 0a330a91..00000000 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/value/ExpressionMathValue.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.mechanic.misc.value; - -import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; -import net.momirealms.customfishing.util.ConfigUtils; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class ExpressionMathValue implements MathValue { - - private final String expression; - - public ExpressionMathValue(String expression) { - this.expression = expression; - } - - @Override - public double get(Player player, Map values) { - return ConfigUtils.getExpressionValue(player, expression, values); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/value/PlainMathValue.java b/core/src/main/java/net/momirealms/customfishing/mechanic/misc/value/PlainMathValue.java deleted file mode 100644 index 586e2b7c..00000000 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/value/PlainMathValue.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.mechanic.misc.value; - -import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; -import org.bukkit.entity.Player; - -import java.util.Map; - -public class PlainMathValue implements MathValue { - - private final double value; - - public PlainMathValue(double value) { - this.value = value; - } - - @Override - public double get(Player player, Map values) { - return value; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java b/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java new file mode 100644 index 00000000..44c928fd --- /dev/null +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java @@ -0,0 +1,4 @@ +package net.momirealms.customfishing.mechanic.requirement; + +public class BukkitRequirementManager { +} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java index f23c8ade..b62ede36 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java @@ -372,7 +372,7 @@ public class RequirementManagerImpl implements RequirementManager { return condition -> { String lootID = condition.getArg("{loot}"); Loot loot = plugin.getLootManager().getLoot(lootID); - String[] groups = loot.getLootGroup(); + String[] groups = loot.lootGroup(); if (groups != null) { for (String g : groups) { if (arg.contains(g)) { @@ -389,7 +389,7 @@ public class RequirementManagerImpl implements RequirementManager { return condition -> { String lootID = condition.getArg("{loot}"); Loot loot = plugin.getLootManager().getLoot(lootID); - String[] groups = loot.getLootGroup(); + String[] groups = loot.lootGroup(); if (groups == null) { return true; } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java index 7258ede5..4cd1ae72 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java @@ -18,9 +18,7 @@ package net.momirealms.customfishing.mechanic.statistic; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.user.OnlineUser; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager; -import net.momirealms.customfishing.api.mechanic.statistic.Statistics; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.Nullable; @@ -58,7 +56,7 @@ public class StatisticsManagerImpl implements StatisticsManager { @Override @Nullable public Statistics getStatistics(UUID uuid) { - OnlineUser onlineUser = plugin.getStorageManager().getOnlineUser(uuid); + OnlineUserData onlineUser = plugin.getStorageManager().getOnlineUser(uuid); if (onlineUser == null) return null; return onlineUser.getStatistics(); } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java b/core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java index c3e3354c..b6282db1 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java @@ -20,7 +20,6 @@ package net.momirealms.customfishing.mechanic.totem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier; import net.momirealms.customfishing.api.mechanic.totem.TotemConfig; import net.momirealms.customfishing.api.mechanic.totem.TotemParticle; import net.momirealms.customfishing.api.scheduler.CancellableTask; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java index bf26393c..0c2e2b65 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java @@ -24,7 +24,6 @@ import net.momirealms.customfishing.api.event.TotemActivateEvent; import net.momirealms.customfishing.api.mechanic.totem.TotemManager; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; -import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier; import net.momirealms.customfishing.api.mechanic.totem.TotemConfig; import net.momirealms.customfishing.api.mechanic.totem.TotemModel; import net.momirealms.customfishing.api.mechanic.totem.block.TotemBlock; diff --git a/core/src/main/java/net/momirealms/customfishing/setting/CFConfig.java b/core/src/main/java/net/momirealms/customfishing/setting/CFConfig.java deleted file mode 100644 index db82e9d2..00000000 --- a/core/src/main/java/net/momirealms/customfishing/setting/CFConfig.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.setting; - -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.util.OffsetUtils; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.event.EventPriority; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Objects; - -public class CFConfig { - - // config version - public static String configVersion = "32"; - // Debug mode - public static boolean debug; - // language - public static String language; - - // update checker - public static boolean updateChecker; - - // BStats - public static boolean metrics; - - // fishing event priority - public static EventPriority eventPriority; - - // thread pool settings - public static int corePoolSize; - public static int maximumPoolSize; - public static int keepAliveTime; - - // detection order for item id - public static List itemDetectOrder = new ArrayList<>(); - public static List blockDetectOrder = new ArrayList<>(); - - // fishing bag - public static boolean enableFishingBag; - - // Fishing wait time - public static boolean overrideVanilla; - public static int waterMinTime; - public static int waterMaxTime; - // Lava fishing - public static int lavaMinTime; - public static int lavaMaxTime; - - // Competition - public static boolean redisRanking; - public static String serverGroup; - public static int placeholderLimit; - - // Data save interval - public static int dataSaveInterval; - // Lock data on join - public static boolean lockData; - public static boolean logDataSaving; - - public static boolean restrictedSizeRange; - - // Legacy color code support - public static boolean legacyColorSupport; - // Durability lore - public static List durabilityLore; - - public static boolean globalShowInFinder; - public static boolean globalDisableStats; - public static boolean globalDisableGame; - public static boolean globalInstantGame; - - public static int multipleLootSpawnDelay; - - public static void load() { - try { - YamlDocument.create( - new File(BukkitCustomFishingPlugin.getInstance().getDataFolder(), "config.yml"), - Objects.requireNonNull(BukkitCustomFishingPlugin.getInstance().getResource("config.yml")), - GeneralSettings.DEFAULT, - LoaderSettings - .builder() - .setAutoUpdate(true) - .build(), - DumperSettings.DEFAULT, - UpdaterSettings - .builder() - .setVersioning(new BasicVersioning("config-version")) - .addIgnoredRoute(configVersion, "mechanics.mechanic-requirements", '.') - .addIgnoredRoute(configVersion, "mechanics.global-events", '.') - .addIgnoredRoute(configVersion, "mechanics.global-effects", '.') - .addIgnoredRoute(configVersion, "mechanics.fishing-bag.collect-actions", '.') - .addIgnoredRoute(configVersion, "mechanics.fishing-bag.full-actions", '.') - .addIgnoredRoute(configVersion, "other-settings.placeholder-register", '.') - .build() - ); - loadSettings(BukkitCustomFishingPlugin.getInstance().getConfig("config.yml")); - } catch (IOException e) { - LogUtils.warn(e.getMessage()); - } - } - - private static void loadSettings(YamlConfiguration config) { - debug = config.getBoolean("debug", false); - - language = config.getString("lang", "english"); - updateChecker = config.getBoolean("update-checker"); - metrics = config.getBoolean("metrics"); - eventPriority = EventPriority.valueOf(config.getString("other-settings.event-priority", "NORMAL").toUpperCase(Locale.ENGLISH)); - - corePoolSize = config.getInt("other-settings.thread-pool-settings.corePoolSize", 1); - maximumPoolSize = config.getInt("other-settings.thread-pool-settings.maximumPoolSize", 1); - keepAliveTime = config.getInt("other-settings.thread-pool-settings.keepAliveTime", 30); - - itemDetectOrder = config.getStringList("other-settings.item-detection-order"); - blockDetectOrder = config.getStringList("other-settings.block-detection-order"); - - enableFishingBag = config.getBoolean("mechanics.fishing-bag.enable", true); - - overrideVanilla = config.getBoolean("mechanics.fishing-wait-time.override-vanilla", false); - waterMinTime = config.getInt("mechanics.fishing-wait-time.min-wait-time", 100); - waterMaxTime = config.getInt("mechanics.fishing-wait-time.min-wait-time", 600); - - lavaMinTime = config.getInt("mechanics.lava-fishing.min-wait-time", 100); - lavaMaxTime = config.getInt("mechanics.lava-fishing.max-wait-time", 600); - - restrictedSizeRange = config.getBoolean("mechanics.size.restricted-size-range", true); - - globalShowInFinder = config.getBoolean("mechanics.global-loot-property.show-in-fishfinder", true); - globalDisableStats = config.getBoolean("mechanics.global-loot-property.disable-stat", false); - globalDisableGame = config.getBoolean("mechanics.global-loot-property.disable-game", false); - globalInstantGame = config.getBoolean("mechanics.global-loot-property.instant-game", false); - - redisRanking = config.getBoolean("mechanics.competition.redis-ranking", false); - placeholderLimit = config.getInt("mechanics.competition.placeholder-limit", 3); - serverGroup = config.getString("mechanics.competition.server-group","default"); - - multipleLootSpawnDelay = config.getInt("mechanics.multiple-loot-spawn-delay", 0); - - dataSaveInterval = config.getInt("other-settings.data-saving-interval", 600); - logDataSaving = config.getBoolean("other-settings.log-data-saving", true); - lockData = config.getBoolean("other-settings.lock-data", true); - legacyColorSupport = config.getBoolean("other-settings.legacy-color-code-support", false); - - durabilityLore = config.getStringList("other-settings.custom-durability-format").stream().map(it -> "" + it).toList(); - - OffsetUtils.loadConfig(config.getConfigurationSection("other-settings.offset-characters")); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/setting/CFLocale.java b/core/src/main/java/net/momirealms/customfishing/setting/CFLocale.java deleted file mode 100644 index 20bbb5cd..00000000 --- a/core/src/main/java/net/momirealms/customfishing/setting/CFLocale.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.setting; - -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 org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -public class CFLocale { - public static String MSG_Total_Size; - public static String MSG_Catch_Amount; - public static String MSG_Total_Score; - public static String MSG_Max_Size; - public static String MSG_No_Player; - public static String MSG_No_Score; - public static String MSG_Prefix; - public static String MSG_Reload; - public static String MSG_Competition_Not_Exist; - public static String MSG_No_Competition_Ongoing; - public static String MSG_End_Competition; - public static String MSG_Stop_Competition; - public static String MSG_No_Rank; - public static String MSG_Item_Not_Exists; - public static String MSG_Get_Item; - public static String MSG_Give_Item; - public static String MSG_Never_Played; - public static String MSG_Unsafe_Modification; - public static String MSG_Data_Not_Loaded; - public static String MSG_Market_GUI_Open; - public static String MSG_Fishing_Bag_Open; - public static String MSG_Split_Char; - public static String MSG_Possible_Loots; - public static String FORMAT_Day; - public static String FORMAT_Hour; - public static String FORMAT_Minute; - public static String FORMAT_Second; - public static String GUI_SCROLL_DOWN; - public static String GUI_SCROLL_UP; - public static String GUI_CANNOT_SCROLL_UP; - public static String GUI_CANNOT_SCROLL_DOWN; - public static String GUI_NEXT_PAGE; - public static String GUI_GOTO_NEXT_PAGE; - public static String GUI_CANNOT_GOTO_NEXT_PAGE; - public static String GUI_PREVIOUS_PAGE; - public static String GUI_GOTO_PREVIOUS_PAGE; - public static String GUI_CANNOT_GOTO_PREVIOUS_PAGE; - public static String GUI_BACK_TO_PARENT_PAGE; - public static String GUI_BACK_TO_PARENT_FOLDER; - public static String GUI_CURRENT_VALUE; - public static String GUI_CLICK_TO_TOGGLE; - public static String GUI_LEFT_CLICK_EDIT; - public static String GUI_RIGHT_CLICK_RESET; - public static String GUI_RIGHT_CLICK_DELETE; - public static String GUI_LOOT_SHOW_IN_FINDER; - public static String GUI_LOOT_SCORE; - public static String GUI_LOOT_NICK; - public static String GUI_LOOT_INSTANT_GAME; - public static String GUI_LOOT_DISABLE_STATS; - public static String GUI_LOOT_DISABLE_GAME; - public static String GUI_ITEM_AMOUNT; - public static String GUI_ITEM_MODEL_DATA; - public static String GUI_ITEM_DISPLAY_NAME; - public static String GUI_ITEM_DURABILITY; - public static String GUI_ITEM_ENCHANTMENT; - public static String GUI_ITEM_HEAD64; - public static String GUI_ITEM_FLAG; - public static String GUI_ITEM_LORE; - public static String GUI_ITEM_MATERIAL; - public static String GUI_ITEM_NBT; - public static String GUI_ITEM_PREVENT_GRAB; - public static String GUI_ITEM_PRICE; - public static String GUI_ITEM_PRICE_BASE; - public static String GUI_ITEM_PRICE_BONUS; - public static String GUI_ITEM_RANDOM_DURABILITY; - public static String GUI_ITEM_SIZE; - public static String GUI_ITEM_STACKABLE; - public static String GUI_ITEM_STORED_ENCHANTMENT; - public static String GUI_ITEM_TAG; - public static String GUI_ITEM_UNBREAKABLE; - public static String GUI_DELETE_PROPERTY; - public static String GUI_NEW_VALUE; - public static String GUI_CLICK_CONFIRM; - public static String GUI_INVALID_NUMBER; - public static String GUI_ILLEGAL_FORMAT; - public static String GUI_TITLE_AMOUNT; - public static String GUI_TITLE_MODEL_DATA; - public static String GUI_TITLE_DISPLAY_NAME; - public static String GUI_NEW_DISPLAY_NAME; - public static String GUI_TITLE_CUSTOM_DURABILITY; - public static String GUI_TITLE_ENCHANTMENT; - public static String GUI_TITLE_STORED_ENCHANTMENT; - public static String GUI_SELECT_ONE_ENCHANTMENT; - public static String GUI_ADD_NEW_ENCHANTMENT; - public static String GUI_TITLE_ITEM_FLAG; - public static String GUI_TITLE_LORE; - public static String GUI_ADD_NEW_LORE; - public static String GUI_SELECT_ONE_LORE; - public static String GUI_TITLE_MATERIAL; - public static String GUI_TITLE_NBT_COMPOUND; - public static String GUI_TITLE_NBT_LIST; - public static String GUI_TITLE_NBT_KEY; - public static String GUI_NBT_INVALID_KEY; - public static String GUI_RIGHT_CLICK_CANCEL; - public static String GUI_NBT_ADD_COMPOUND; - public static String GUI_NBT_ADD_LIST; - public static String GUI_NBT_ADD_VALUE; - public static String GUI_NBT_PREVIEW; - public static String GUI_NBT_BACK_TO_COMPOUND; - public static String GUI_NBT_SET_VALUE_TITLE; - public static String GUI_NBT_EDIT_TITLE; - public static String GUI_NICK_TITLE; - public static String GUI_NICK_NEW; - public static String GUI_PRICE_TITLE; - public static String GUI_PRICE_BASE; - public static String GUI_PRICE_BONUS; - public static String GUI_SCORE_TITLE; - public static String GUI_SIZE_TITLE; - public static String GUI_SIZE_MIN; - public static String GUI_SIZE_MAX; - public static String GUI_SIZE_MAX_NO_LESS; - public static String GUI_SELECT_FILE; - public static String GUI_SELECT_ITEM; - public static String GUI_ADD_NEW_KEY; - public static String GUI_DUPE_INVALID_KEY; - public static String GUI_SEARCH; - public static String GUI_TEMP_NEW_KEY; - public static String GUI_SET_NEW_KEY; - public static String GUI_EDIT_KEY; - - public static void load() { - InputStream inputStream = BukkitCustomFishingPlugin.getInstance().getResource("messages/" + CFConfig.language + ".yml"); - if (inputStream != null) { - try { - YamlDocument.create( - new File(BukkitCustomFishingPlugin.getInstance().getDataFolder(), "messages/" + CFConfig.language + ".yml"), - inputStream, - GeneralSettings.DEFAULT, - LoaderSettings - .builder() - .setAutoUpdate(true) - .build(), - DumperSettings.DEFAULT, - UpdaterSettings - .builder() - .setVersioning(new BasicVersioning("config-version")) - .build() - ); - inputStream.close(); - } catch (IOException e) { - LogUtils.warn(e.getMessage()); - } - } - loadSettings(BukkitCustomFishingPlugin.get().getConfig("messages/" + CFConfig.language + ".yml")); - } - - private static void loadSettings(YamlConfiguration locale) { - ConfigurationSection msgSection = locale.getConfigurationSection("messages"); - if (msgSection != null) { - MSG_Prefix = msgSection.getString("prefix"); - MSG_Reload = msgSection.getString("reload"); - MSG_Competition_Not_Exist = msgSection.getString("competition-not-exist"); - MSG_No_Competition_Ongoing = msgSection.getString("no-competition-ongoing"); - MSG_Stop_Competition = msgSection.getString("stop-competition"); - MSG_End_Competition = msgSection.getString("end-competition"); - MSG_No_Player = msgSection.getString("no-player"); - MSG_No_Score = msgSection.getString("no-score"); - MSG_No_Rank = msgSection.getString("no-rank"); - MSG_Catch_Amount = msgSection.getString("goal-catch-amount"); - MSG_Max_Size = msgSection.getString("goal-max-size"); - MSG_Total_Score = msgSection.getString("goal-total-score"); - MSG_Total_Size = msgSection.getString("goal-total-size"); - MSG_Item_Not_Exists = msgSection.getString("item-not-exist"); - MSG_Get_Item = msgSection.getString("get-item"); - MSG_Give_Item = msgSection.getString("give-item"); - MSG_Never_Played = msgSection.getString("never-played"); - MSG_Unsafe_Modification = msgSection.getString("unsafe-modification"); - MSG_Data_Not_Loaded = msgSection.getString("data-not-loaded"); - MSG_Market_GUI_Open = msgSection.getString("open-market-gui"); - MSG_Fishing_Bag_Open = msgSection.getString("open-fishing-bag"); - MSG_Split_Char = msgSection.getString("split-char"); - MSG_Possible_Loots = msgSection.getString("possible-loots"); - FORMAT_Day = msgSection.getString("format-day"); - FORMAT_Hour = msgSection.getString("format-hour"); - FORMAT_Minute = msgSection.getString("format-minute"); - FORMAT_Second = msgSection.getString("format-second"); - } - ConfigurationSection guiSection = locale.getConfigurationSection("gui"); - if (guiSection != null) { - GUI_SEARCH = guiSection.getString("search"); - GUI_EDIT_KEY = guiSection.getString("edit-key"); - GUI_DELETE_PROPERTY = guiSection.getString("delete-property"); - GUI_DUPE_INVALID_KEY = guiSection.getString("dupe-invalid-key"); - GUI_SELECT_ITEM = guiSection.getString("select-item"); - GUI_SELECT_FILE = guiSection.getString("select-file"); - GUI_TEMP_NEW_KEY = guiSection.getString("temp-new-key"); - GUI_SET_NEW_KEY = guiSection.getString("set-new-key"); - GUI_ADD_NEW_KEY = guiSection.getString("page-add-new-key"); - GUI_SCROLL_UP = guiSection.getString("scroll-up"); - GUI_SCROLL_DOWN = guiSection.getString("scroll-down"); - GUI_CANNOT_SCROLL_UP = guiSection.getString("cannot-scroll-up"); - GUI_CANNOT_SCROLL_DOWN = guiSection.getString("cannot-scroll-down"); - GUI_NEXT_PAGE = guiSection.getString("next-page"); - GUI_GOTO_NEXT_PAGE = guiSection.getString("goto-next-page"); - GUI_CANNOT_GOTO_NEXT_PAGE = guiSection.getString("cannot-goto-next-page"); - GUI_PREVIOUS_PAGE = guiSection.getString("previous-page"); - GUI_GOTO_PREVIOUS_PAGE = guiSection.getString("goto-previous-page"); - GUI_CANNOT_GOTO_PREVIOUS_PAGE = guiSection.getString("cannot-goto-previous-page"); - GUI_BACK_TO_PARENT_PAGE = guiSection.getString("back-to-parent-page"); - GUI_BACK_TO_PARENT_FOLDER = guiSection.getString("back-to-parent-folder"); - GUI_CURRENT_VALUE = guiSection.getString("current-value"); - GUI_CLICK_TO_TOGGLE = guiSection.getString("click-to-toggle"); - GUI_LEFT_CLICK_EDIT = guiSection.getString("left-click-edit"); - GUI_RIGHT_CLICK_RESET = guiSection.getString("right-click-reset"); - GUI_RIGHT_CLICK_DELETE = guiSection.getString("right-click-delete"); - GUI_RIGHT_CLICK_CANCEL = guiSection.getString("right-click-cancel"); - GUI_LOOT_SHOW_IN_FINDER = guiSection.getString("loot-show-in-finder"); - GUI_LOOT_SCORE = guiSection.getString("loot-score"); - GUI_LOOT_NICK = guiSection.getString("loot-nick"); - GUI_LOOT_INSTANT_GAME = guiSection.getString("loot-instant-game"); - GUI_LOOT_DISABLE_STATS = guiSection.getString("loot-disable-statistics"); - GUI_LOOT_DISABLE_GAME = guiSection.getString("loot-disable-game"); - GUI_ITEM_AMOUNT = guiSection.getString("item-amount"); - GUI_ITEM_MODEL_DATA = guiSection.getString("item-custom-model-data"); - GUI_ITEM_DISPLAY_NAME = guiSection.getString("item-display-name"); - GUI_ITEM_DURABILITY = guiSection.getString("item-custom-durability"); - GUI_ITEM_ENCHANTMENT = guiSection.getString("item-enchantment"); - GUI_ITEM_HEAD64 = guiSection.getString("item-head64"); - GUI_ITEM_FLAG = guiSection.getString("item-item-flag"); - GUI_ITEM_LORE = guiSection.getString("item-lore"); - GUI_ITEM_MATERIAL = guiSection.getString("item-material"); - GUI_ITEM_NBT = guiSection.getString("item-nbt"); - GUI_ITEM_PREVENT_GRAB = guiSection.getString("item-prevent-grab"); - GUI_ITEM_PRICE = guiSection.getString("item-price"); - GUI_ITEM_PRICE_BASE = guiSection.getString("item-price-base"); - GUI_ITEM_PRICE_BONUS = guiSection.getString("item-price-bonus"); - GUI_ITEM_RANDOM_DURABILITY = guiSection.getString("item-random-durability"); - GUI_ITEM_SIZE = guiSection.getString("item-size"); - GUI_ITEM_STACKABLE = guiSection.getString("item-stackable"); - GUI_ITEM_STORED_ENCHANTMENT = guiSection.getString("item-stored-enchantment"); - GUI_ITEM_TAG = guiSection.getString("item-tag"); - GUI_ITEM_UNBREAKABLE = guiSection.getString("item-unbreakable"); - GUI_NEW_VALUE = guiSection.getString("new-value"); - GUI_CLICK_CONFIRM = guiSection.getString("click-confirm"); - GUI_INVALID_NUMBER = guiSection.getString("invalid-number"); - GUI_ILLEGAL_FORMAT = guiSection.getString("illegal-format"); - GUI_TITLE_AMOUNT = guiSection.getString("page-amount-title"); - GUI_TITLE_MODEL_DATA = guiSection.getString("page-model-data-title"); - GUI_TITLE_DISPLAY_NAME = guiSection.getString("page-display-name-title"); - GUI_NEW_DISPLAY_NAME = guiSection.getString("page-new-display-name"); - GUI_TITLE_CUSTOM_DURABILITY = guiSection.getString("page-custom-durability-title"); - GUI_TITLE_ENCHANTMENT = guiSection.getString("page-enchantment-title"); - GUI_TITLE_STORED_ENCHANTMENT = guiSection.getString("page-stored-enchantment-title"); - GUI_SELECT_ONE_ENCHANTMENT = guiSection.getString("page-select-one-enchantment"); - GUI_ADD_NEW_ENCHANTMENT = guiSection.getString("page-add-new-enchantment"); - GUI_TITLE_ITEM_FLAG = guiSection.getString("page-item-flag-title"); - GUI_TITLE_LORE = guiSection.getString("page-lore-title"); - GUI_ADD_NEW_LORE = guiSection.getString("page-add-new-lore"); - GUI_SELECT_ONE_LORE = guiSection.getString("page-select-one-lore"); - GUI_TITLE_MATERIAL = guiSection.getString("page-material-title"); - GUI_TITLE_NBT_COMPOUND = guiSection.getString("page-nbt-compound-key-title"); - GUI_TITLE_NBT_LIST = guiSection.getString("page-nbt-list-key-title"); - GUI_TITLE_NBT_KEY = guiSection.getString("page-nbt-key-title"); - GUI_NBT_INVALID_KEY = guiSection.getString("page-nbt-invalid-key"); - GUI_NBT_ADD_COMPOUND = guiSection.getString("page-nbt-add-new-compound"); - GUI_NBT_ADD_LIST = guiSection.getString("page-nbt-add-new-list"); - GUI_NBT_ADD_VALUE = guiSection.getString("page-nbt-add-new-value"); - GUI_NBT_PREVIEW = guiSection.getString("page-nbt-preview"); - GUI_NBT_BACK_TO_COMPOUND = guiSection.getString("page-nbt-back-to-compound"); - GUI_NBT_SET_VALUE_TITLE = guiSection.getString("page-nbt-set-value-title"); - GUI_NBT_EDIT_TITLE = guiSection.getString("page-nbt-edit-title"); - GUI_NICK_TITLE = guiSection.getString("page-nick-title"); - GUI_NICK_NEW = guiSection.getString("page-new-nick"); - GUI_PRICE_TITLE = guiSection.getString("page-price-title"); - GUI_PRICE_BASE = guiSection.getString("page-base-price"); - GUI_PRICE_BONUS = guiSection.getString("page-base-bonus"); - GUI_SCORE_TITLE = guiSection.getString("page-score-title"); - GUI_SIZE_TITLE = guiSection.getString("page-size-title"); - GUI_SIZE_MIN = guiSection.getString("page-size-min"); - GUI_SIZE_MAX = guiSection.getString("page-size-max"); - GUI_SIZE_MAX_NO_LESS = guiSection.getString("page-size-max-no-less-min"); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java index 85b79fd1..ff7dcaad 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java @@ -22,14 +22,12 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.DataStorageInterface; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.StorageType; -import net.momirealms.customfishing.api.data.user.OfflineUser; -import net.momirealms.customfishing.api.data.user.OnlineUser; -import net.momirealms.customfishing.api.manager.StorageManager; +import net.momirealms.customfishing.api.storage.DataStorageProvider; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.StorageType; +import net.momirealms.customfishing.api.storage.user.UserData; +import net.momirealms.customfishing.api.storage.StorageManager; import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.setting.CFConfig; import net.momirealms.customfishing.storage.method.database.nosql.MongoDBImpl; import net.momirealms.customfishing.storage.method.database.nosql.RedisManager; import net.momirealms.customfishing.storage.method.database.sql.H2Impl; @@ -38,8 +36,7 @@ import net.momirealms.customfishing.storage.method.database.sql.MySQLImpl; import net.momirealms.customfishing.storage.method.database.sql.SQLiteImpl; import net.momirealms.customfishing.storage.method.file.JsonImpl; import net.momirealms.customfishing.storage.method.file.YAMLImpl; -import net.momirealms.customfishing.storage.user.OfflineUserImpl; -import net.momirealms.customfishing.storage.user.OnlineUserImpl; +import net.momirealms.customfishing.storage.user.OfflineUser; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -67,9 +64,9 @@ import java.util.concurrent.TimeUnit; public class StorageManagerImpl implements StorageManager, Listener { private final BukkitCustomFishingPlugin plugin; - private DataStorageInterface dataSource; + private DataStorageProvider dataSource; private StorageType previousType; - private final ConcurrentHashMap onlineUserMap; + private final ConcurrentHashMap onlineUserMap; private final HashSet locked; private boolean hasRedis; private RedisManager redisManager; @@ -174,12 +171,12 @@ public class StorageManagerImpl implements StorageManager, Listener { * @return An OnlineUser instance if the player is online, or null if not. */ @Override - public OnlineUser getOnlineUser(UUID uuid) { + public OnlineUserData getOnlineUser(UUID uuid) { return onlineUserMap.get(uuid); } @Override - public Collection getOnlineUsers() { + public Collection getOnlineUsers() { return onlineUserMap.values(); } @@ -191,7 +188,7 @@ public class StorageManagerImpl implements StorageManager, Listener { * @return A CompletableFuture that resolves to an Optional containing the OfflineUser instance if found, or empty if not found or locked. */ @Override - public CompletableFuture> getOfflineUser(UUID uuid, boolean lock) { + public CompletableFuture> getOfflineUser(UUID uuid, boolean lock) { var optionalDataFuture = dataSource.getPlayerData(uuid, lock); return optionalDataFuture.thenCompose(optionalUser -> { if (optionalUser.isEmpty()) { @@ -200,29 +197,29 @@ public class StorageManagerImpl implements StorageManager, Listener { } PlayerData data = optionalUser.get(); if (data.isLocked()) { - return CompletableFuture.completedFuture(Optional.of(OfflineUserImpl.LOCKED_USER)); + return CompletableFuture.completedFuture(Optional.of(OfflineUser.LOCKED_USER)); } else { - OfflineUser offlineUser = new OfflineUserImpl(uuid, data.getName(), data); - return CompletableFuture.completedFuture(Optional.of(offlineUser)); + UserData userData = new OfflineUser(uuid, data.getName(), data); + return CompletableFuture.completedFuture(Optional.of(userData)); } }); } @Override - public boolean isLockedData(OfflineUser offlineUser) { - return OfflineUserImpl.LOCKED_USER == offlineUser; + public boolean isLockedData(UserData userData) { + return OfflineUser.LOCKED_USER == userData; } /** * Asynchronously saves user data for an OfflineUser. * - * @param offlineUser The OfflineUser whose data needs to be saved. + * @param userData 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. */ @Override - public CompletableFuture saveUserData(OfflineUser offlineUser, boolean unlock) { - return dataSource.updatePlayerData(offlineUser.getUUID(), offlineUser.getPlayerData(), unlock); + public CompletableFuture saveUserData(UserData userData, boolean unlock) { + return dataSource.updatePlayerData(userData.getUUID(), userData.getPlayerData(), unlock); } /** @@ -231,7 +228,7 @@ public class StorageManagerImpl implements StorageManager, Listener { * @return The data source. */ @Override - public DataStorageInterface getDataSource() { + public DataStorageProvider getDataSource() { return dataSource; } @@ -270,7 +267,7 @@ public class StorageManagerImpl implements StorageManager, Listener { if (locked.contains(uuid)) return; - OnlineUser onlineUser = onlineUserMap.remove(uuid); + OnlineUserData onlineUser = onlineUserMap.remove(uuid); if (onlineUser == null) return; PlayerData data = onlineUser.getPlayerData(); @@ -370,7 +367,7 @@ public class StorageManagerImpl implements StorageManager, Listener { */ public void putDataInCache(Player player, PlayerData playerData) { locked.remove(player.getUniqueId()); - OnlineUserImpl bukkitUser = new OnlineUserImpl(player, playerData); + OnlineUserDataImpl bukkitUser = new OnlineUserDataImpl(player, playerData); onlineUserMap.put(player.getUniqueId(), bukkitUser); } diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java b/core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java index 44c6ac8a..248be24b 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java @@ -18,9 +18,9 @@ package net.momirealms.customfishing.storage.method; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -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.storage.DataStorageProvider; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.user.UserData; import java.time.Instant; import java.util.Collection; @@ -30,7 +30,7 @@ import java.util.concurrent.CompletableFuture; /** * An abstract class that implements the DataStorageInterface and provides common functionality for data storage. */ -public abstract class AbstractStorage implements DataStorageInterface { +public abstract class AbstractStorage implements DataStorageProvider { protected BukkitCustomFishingPlugin plugin; @@ -58,9 +58,9 @@ public abstract class AbstractStorage implements DataStorageInterface { } @Override - public void updateManyPlayersData(Collection users, boolean unlock) { + public void updateManyPlayersData(Collection users, boolean unlock) { // Update data for multiple players by iterating through the collection of OfflineUser objects. - for (OfflineUser user : users) { + for (UserData user : users) { this.updatePlayerData(user.getUUID(), user.getPlayerData(), unlock); } } diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java index 7a9c04c9..59122239 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java @@ -22,10 +22,9 @@ import com.mongodb.client.*; import com.mongodb.client.model.*; import com.mongodb.client.result.UpdateResult; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.StorageType; -import net.momirealms.customfishing.api.data.user.OfflineUser; -import net.momirealms.customfishing.setting.CFConfig; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.StorageType; +import net.momirealms.customfishing.api.storage.user.UserData; import net.momirealms.customfishing.storage.method.AbstractStorage; import org.bson.Document; import org.bson.UuidRepresentation; @@ -190,7 +189,7 @@ public class MongoDBImpl extends AbstractStorage { * @param unlock Flag indicating whether to unlock the data. */ @Override - public void updateManyPlayersData(Collection users, boolean unlock) { + public void updateManyPlayersData(Collection users, boolean unlock) { MongoCollection collection = database.getCollection(getCollectionName("data")); try { int lock = unlock ? 0 : getCurrentSeconds(); diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java index 3a48e2eb..995614d7 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java @@ -18,9 +18,8 @@ package net.momirealms.customfishing.storage.method.database.nosql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.StorageType; -import net.momirealms.customfishing.setting.CFConfig; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.storage.method.AbstractStorage; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java index bb29fdc5..22ee2304 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java @@ -20,7 +20,11 @@ package net.momirealms.customfishing.storage.method.database.sql; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.*; +import net.momirealms.customfishing.api.storage.*; +import net.momirealms.customfishing.api.storage.data.EarningData; +import net.momirealms.customfishing.api.storage.data.InventoryData; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.data.StatisticData; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -150,16 +154,16 @@ public abstract class AbstractHikariDatabase extends AbstractSQLDatabase impleme try ( Connection connection = getConnection() ) { - var builder = new PlayerData.Builder().setName(""); + var builder = new PlayerData.Builder().name(""); PreparedStatement statementOne = connection.prepareStatement(String.format(SqlConstants.SQL_SELECT_BY_UUID, getTableName("fishingbag"))); statementOne.setString(1, uuid.toString()); ResultSet rsOne = statementOne.executeQuery(); if (rsOne.next()) { int size = rsOne.getInt("size"); String contents = rsOne.getString("contents"); - builder.setBagData(new InventoryData(contents, size)); + builder.bag(new InventoryData(contents, size)); } else { - builder.setBagData(InventoryData.empty()); + builder.bag(InventoryData.empty()); } PreparedStatement statementTwo = connection.prepareStatement(String.format(SqlConstants.SQL_SELECT_BY_UUID, getTableName("selldata"))); @@ -168,9 +172,9 @@ public abstract class AbstractHikariDatabase extends AbstractSQLDatabase impleme if (rsTwo.next()) { int date = rsTwo.getInt("date"); double money = rsTwo.getInt("money"); - builder.setEarningData(new EarningData(money, date)); + builder.earnings(new EarningData(money, date)); } else { - builder.setEarningData(EarningData.empty()); + builder.earnings(EarningData.empty()); } PreparedStatement statementThree = connection.prepareStatement(String.format(SqlConstants.SQL_SELECT_BY_UUID, getTableName("statistics"))); @@ -182,9 +186,9 @@ public abstract class AbstractHikariDatabase extends AbstractSQLDatabase impleme .map(element -> element.split(":")) .filter(pair -> pair.length == 2) .collect(Collectors.toMap(pair -> pair[0], pair -> Integer.parseInt(pair[1]))); - builder.setStats(new StatisticData(amountMap, new HashMap<>())); + builder.stats(new StatisticData(amountMap, new HashMap<>())); } else { - builder.setStats(StatisticData.empty()); + builder.stats(StatisticData.empty()); } future.complete(Optional.of(builder.build())); } catch (SQLException e) { diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java index 2100cb59..cb2417b1 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java @@ -18,9 +18,8 @@ package net.momirealms.customfishing.storage.method.database.sql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.user.OfflineUser; -import net.momirealms.customfishing.setting.CFConfig; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.user.UserData; import net.momirealms.customfishing.storage.method.AbstractStorage; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; @@ -197,12 +196,12 @@ public abstract class AbstractSQLDatabase extends AbstractStorage { * @param unlock Whether to unlock the player data after updating. */ @Override - public void updateManyPlayersData(Collection users, boolean unlock) { + public void updateManyPlayersData(Collection users, boolean unlock) { String sql = String.format(SqlConstants.SQL_UPDATE_BY_UUID, getTableName("data")); try (Connection connection = getConnection()) { connection.setAutoCommit(false); try (PreparedStatement statement = connection.prepareStatement(sql)) { - for (OfflineUser user : users) { + for (UserData user : users) { statement.setInt(1, unlock ? 0 : getCurrentSeconds()); statement.setBlob(2, new ByteArrayInputStream(plugin.getStorageManager().toBytes(user.getPlayerData()))); statement.setString(3, user.getUUID().toString()); diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java index 9884ce2e..d8b6e7f0 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.storage.method.database.sql; import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.StorageType; +import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.libraries.dependencies.Dependency; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java index 354673c7..be3d7cc8 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.storage.method.database.sql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.StorageType; +import net.momirealms.customfishing.api.storage.StorageType; public class MariaDBImpl extends AbstractHikariDatabase { diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java index 2c529fa1..43c1fd3e 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.storage.method.database.sql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.StorageType; +import net.momirealms.customfishing.api.storage.StorageType; public class MySQLImpl extends AbstractHikariDatabase { diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java index bed18e02..7b57773a 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java @@ -19,11 +19,10 @@ package net.momirealms.customfishing.storage.method.database.sql; import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.StorageType; -import net.momirealms.customfishing.api.data.user.OfflineUser; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.StorageType; +import net.momirealms.customfishing.api.storage.user.UserData; import net.momirealms.customfishing.libraries.dependencies.Dependency; -import net.momirealms.customfishing.setting.CFConfig; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; @@ -191,12 +190,12 @@ public class SQLiteImpl extends AbstractSQLDatabase { * @param unlock Flag indicating whether to unlock the data. */ @Override - public void updateManyPlayersData(Collection users, boolean unlock) { + public void updateManyPlayersData(Collection users, boolean unlock) { String sql = String.format(SqlConstants.SQL_UPDATE_BY_UUID, getTableName("data")); try (Connection connection = getConnection()) { connection.setAutoCommit(false); try (PreparedStatement statement = connection.prepareStatement(sql)) { - for (OfflineUser user : users) { + for (UserData user : users) { statement.setInt(1, unlock ? 0 : getCurrentSeconds()); statement.setBytes(2, plugin.getStorageManager().toBytes(user.getPlayerData())); statement.setString(3, user.getUUID().toString()); diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java index 4a54cb74..ba64e6df 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java @@ -19,8 +19,8 @@ package net.momirealms.customfishing.storage.method.file; import com.google.gson.Gson; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.StorageType; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.storage.method.AbstractStorage; import org.bukkit.Bukkit; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java index 8df635c5..e82ca7b0 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java @@ -18,7 +18,11 @@ package net.momirealms.customfishing.storage.method.file; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.*; +import net.momirealms.customfishing.api.storage.*; +import net.momirealms.customfishing.api.storage.data.EarningData; +import net.momirealms.customfishing.api.storage.data.InventoryData; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.data.StatisticData; import net.momirealms.customfishing.storage.method.AbstractStorage; import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.Bukkit; @@ -70,10 +74,10 @@ public class YAMLImpl extends AbstractStorage implements LegacyDataStorageInterf YamlConfiguration data = ConfigUtils.readData(dataFile); PlayerData playerData = new PlayerData.Builder() - .setBagData(new InventoryData(data.getString("bag", ""), data.getInt("size", 9))) - .setEarningData(new EarningData(data.getDouble("earnings"), data.getInt("date"))) - .setStats(getStatistics(data.getConfigurationSection("stats"))) - .setName(data.getString("name")) + .bag(new InventoryData(data.getString("bag", ""), data.getInt("size", 9))) + .earnings(new EarningData(data.getDouble("earnings"), data.getInt("date"))) + .stats(getStatistics(data.getConfigurationSection("stats"))) + .name(data.getString("name")) .build(); return CompletableFuture.completedFuture(Optional.of(playerData)); } @@ -153,15 +157,15 @@ public class YAMLImpl extends AbstractStorage implements LegacyDataStorageInterf @Override public CompletableFuture> getLegacyPlayerData(UUID uuid) { // Retrieve legacy player data (YAML format) for a given UUID. - var builder = new PlayerData.Builder().setName(""); + var builder = new PlayerData.Builder().name(""); File bagFile = new File(plugin.getDataFolder(), "data/fishingbag/" + uuid + ".yml"); if (bagFile.exists()) { YamlConfiguration yaml = YamlConfiguration.loadConfiguration(bagFile); String contents = yaml.getString("contents", ""); int size = yaml.getInt("size", 9); - builder.setBagData(new InventoryData(contents, size)); + builder.bag(new InventoryData(contents, size)); } else { - builder.setBagData(InventoryData.empty()); + builder.bag(InventoryData.empty()); } File statFile = new File(plugin.getDataFolder(), "data/statistics/" + uuid + ".yml"); @@ -173,17 +177,17 @@ public class YAMLImpl extends AbstractStorage implements LegacyDataStorageInterf map.put(entry.getKey(), integer); } } - builder.setStats(new StatisticData(map, new HashMap<>())); + builder.stats(new StatisticData(map, new HashMap<>())); } else { - builder.setStats(StatisticData.empty()); + builder.stats(StatisticData.empty()); } File sellFile = new File(plugin.getDataFolder(), "data/sell/" + uuid + ".yml"); if (sellFile.exists()) { YamlConfiguration yaml = YamlConfiguration.loadConfiguration(sellFile); - builder.setEarningData(new EarningData(yaml.getDouble("earnings"), yaml.getInt("date"))); + builder.earnings(new EarningData(yaml.getDouble("earnings"), yaml.getInt("date"))); } else { - builder.setEarningData(EarningData.empty()); + builder.earnings(EarningData.empty()); } return CompletableFuture.completedFuture(Optional.of(builder.build())); diff --git a/core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUserImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUser.java similarity index 76% rename from core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUserImpl.java rename to core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUser.java index 5ff08f57..845b95f4 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUserImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUser.java @@ -18,14 +18,11 @@ package net.momirealms.customfishing.storage.user; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.data.EarningData; -import net.momirealms.customfishing.api.data.InventoryData; -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.StatisticData; -import net.momirealms.customfishing.api.data.user.OfflineUser; -import net.momirealms.customfishing.api.mechanic.bag.FishingBagHolder; -import net.momirealms.customfishing.api.mechanic.statistic.Statistics; -import net.momirealms.customfishing.api.util.InventoryUtils; +import net.momirealms.customfishing.api.storage.data.EarningData; +import net.momirealms.customfishing.api.storage.data.InventoryData; +import net.momirealms.customfishing.api.storage.data.PlayerData; +import net.momirealms.customfishing.api.storage.data.StatisticData; +import net.momirealms.customfishing.api.storage.user.UserData; import net.momirealms.customfishing.bukkit.compatibility.papi.PlaceholderManagerImpl; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -38,14 +35,14 @@ import java.util.UUID; /** * Implementation of the OfflineUser interface for representing offline player data. */ -public class OfflineUserImpl implements OfflineUser { +public class OfflineUser implements UserData { private final UUID uuid; private final String name; private final FishingBagHolder holder; private final EarningData earningData; private final Statistics statistics; - public static OfflineUserImpl LOCKED_USER = new OfflineUserImpl(UUID.randomUUID(), "-locked-", PlayerData.empty()); + private boolean isDirty; /** * Constructor to create an OfflineUserImpl instance. @@ -54,7 +51,7 @@ public class OfflineUserImpl implements OfflineUser { * @param name The name of the player. * @param playerData The player's data, including bag contents, earnings, and statistics. */ - public OfflineUserImpl(UUID uuid, String name, PlayerData playerData) { + public OfflineUser(UUID uuid, String name, PlayerData playerData) { this.name = name; this.uuid = uuid; this.holder = new FishingBagHolder(uuid); @@ -113,10 +110,15 @@ public class OfflineUserImpl implements OfflineUser { public PlayerData getPlayerData() { // Create a new PlayerData instance based on the stored information return new PlayerData.Builder() - .setBagData(new InventoryData(InventoryUtils.stacksToBase64(holder.getInventory().getStorageContents()), holder.getInventory().getSize())) - .setEarningData(earningData) - .setStats(new StatisticData(statistics.getStatisticMap(), statistics.getSizeMap())) - .setName(name) + .bag(new InventoryData(InventoryUtils.stacksToBase64(holder.getInventory().getStorageContents()), holder.getInventory().getSize())) + .earnings(earningData) + .stats(new StatisticData(statistics.getStatisticMap(), statistics.getSizeMap())) + .name(name) .build(); } + + @Override + public OfflinePlayer getUser() { + return null; + } } diff --git a/core/src/main/java/net/momirealms/customfishing/storage/user/OnlineUserImpl.java b/core/src/main/java/net/momirealms/customfishing/storage/user/OnlineUserImpl.java deleted file mode 100644 index ea8f63d1..00000000 --- a/core/src/main/java/net/momirealms/customfishing/storage/user/OnlineUserImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.storage.user; - -import net.momirealms.customfishing.api.data.PlayerData; -import net.momirealms.customfishing.api.data.user.OnlineUser; -import org.bukkit.entity.Player; - -/** - * Implementation of the OnlineUser interface, extending OfflineUserImpl to represent online player data. - */ -public class OnlineUserImpl extends OfflineUserImpl implements OnlineUser { - - private final Player player; - - /** - * Constructor to create an OnlineUserImpl instance. - * - * @param player The online player associated with this user. - * @param playerData The player's data, including bag contents, earnings, and statistics. - */ - public OnlineUserImpl(Player player, PlayerData playerData) { - super(player.getUniqueId(), player.getName(), playerData); - this.player = player; - } - - @Override - public Player getPlayer() { - return player; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java b/core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java index da8f3dd2..f98d1fd8 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java @@ -26,7 +26,6 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.hook.HookSetting; -import net.momirealms.customfishing.setting.CFConfig; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; diff --git a/core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java index 5a938992..95b2859f 100644 --- a/core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java @@ -18,7 +18,6 @@ package net.momirealms.customfishing.version; import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; -import net.momirealms.customfishing.api.manager.VersionManager; import org.bukkit.Bukkit; import java.io.BufferedReader;