9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
XiaoMoMi
2024-03-21 18:28:21 +08:00
parent cf0ced5eca
commit 716d73033e
17 changed files with 414 additions and 156 deletions

View File

@@ -18,6 +18,7 @@
package net.momirealms.customfishing.api.manager; package net.momirealms.customfishing.api.manager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Map; import java.util.Map;
@@ -75,11 +76,18 @@ public interface MarketManager {
char getItemSlot(); char getItemSlot();
/** /**
* Gets the character representing the function slot in the MarketGUI. * Gets the character representing the sell slot in the MarketGUI.
* *
* @return The function slot character. * @return The sell slot character.
*/ */
char getFunctionSlot(); char getSellSlot();
/**
* Gets the character representing the sell-all slot in the MarketGUI.
*
* @return The sell-all slot character.
*/
char getSellAllSlot();
/** /**
* Gets the layout of the MarketGUI as an array of strings. * Gets the layout of the MarketGUI as an array of strings.
@@ -108,4 +116,21 @@ public interface MarketManager {
* @return enable or not * @return enable or not
*/ */
boolean isEnable(); boolean isEnable();
/**
* Should fish in bag also be sold
*
* @return sell or not
*/
boolean sellFishingBag();
/**
* Get the total worth of the items in inventory
*
* @param inventory inventory
* @return total worth
*/
double getInventoryTotalWorth(Inventory inventory);
int getInventorySellAmount(Inventory inventory);
} }

View File

@@ -18,6 +18,8 @@
package net.momirealms.customfishing.api.mechanic.competition; package net.momirealms.customfishing.api.mechanic.competition;
import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
@@ -33,6 +35,7 @@ public class CompetitionConfig {
private Action[] startActions; private Action[] startActions;
private Action[] endActions; private Action[] endActions;
private Action[] joinActions; private Action[] joinActions;
private Requirement[] requirements;
private CompetitionGoal goal; private CompetitionGoal goal;
private HashMap<String, Action[]> rewards; private HashMap<String, Action[]> rewards;
@@ -52,10 +55,12 @@ public class CompetitionConfig {
return minPlayers; return minPlayers;
} }
@Nullable
public Action[] getStartActions() { public Action[] getStartActions() {
return startActions; return startActions;
} }
@Nullable
public Action[] getEndActions() { public Action[] getEndActions() {
return endActions; return endActions;
} }
@@ -65,6 +70,7 @@ public class CompetitionConfig {
* *
* @return actions * @return actions
*/ */
@Nullable
public Action[] getJoinActions() { public Action[] getJoinActions() {
return joinActions; return joinActions;
} }
@@ -74,10 +80,22 @@ public class CompetitionConfig {
* *
* @return actions * @return actions
*/ */
@Nullable
public Action[] getSkipActions() { public Action[] getSkipActions() {
return skipActions; return skipActions;
} }
/**
* Get the requirements for participating the competition
*
* @return requirements
*/
@Nullable
public Requirement[] getRequirements() {
return requirements;
}
@NotNull
public CompetitionGoal getGoal() { public CompetitionGoal getGoal() {
return goal; return goal;
} }
@@ -155,6 +173,11 @@ public class CompetitionConfig {
return this; return this;
} }
public Builder requirements(Requirement[] requirements) {
config.requirements = requirements;
return this;
}
public Builder goal(CompetitionGoal goal) { public Builder goal(CompetitionGoal goal) {
config.goal = goal; config.goal = goal;
return this; return this;

View File

@@ -34,6 +34,10 @@ public class EffectCarrier {
private Map<ActionTrigger, Action[]> actionMap; private Map<ActionTrigger, Action[]> actionMap;
private boolean persist; private boolean persist;
public static Builder builder() {
return new Builder();
}
public static class Builder { public static class Builder {
private final EffectCarrier item; private final EffectCarrier item;

View File

@@ -7,7 +7,7 @@ plugins {
allprojects { allprojects {
version = "2.1.0.3.2" version = "2.1.1"
apply<JavaPlugin>() apply<JavaPlugin>()
apply(plugin = "java") apply(plugin = "java")

View File

@@ -53,7 +53,7 @@ dependencies {
compileOnly("org.betonquest:betonquest:2.0.0") compileOnly("org.betonquest:betonquest:2.0.0")
compileOnly("xyz.xenondevs.invui:invui:1.26") compileOnly("xyz.xenondevs.invui:invui:1.26")
compileOnly("com.github.Xiao-MoMi:Custom-Crops:3.4-BETA-1") compileOnly("com.github.Xiao-MoMi:Custom-Crops:3.4-BETA-1")
compileOnly("com.github.Xiao-MoMi:BiomeAPI:0.2") implementation("com.github.Xiao-MoMi:BiomeAPI:0.3")
// local jars // local jars
compileOnly(files("libs/AdvancedEnchantments-api.jar")) compileOnly(files("libs/AdvancedEnchantments-api.jar"))

View File

@@ -109,8 +109,7 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
Dependency.BSTATS_BUKKIT, Dependency.BSTATS_BUKKIT,
Dependency.INV_UI, Dependency.INV_UI,
Dependency.INV_UI_ACCESS, Dependency.INV_UI_ACCESS,
Dependency.INV_UI_NMS, Dependency.INV_UI_NMS
Dependency.BIOME_API
) )
)); ));
} }

View File

@@ -325,7 +325,7 @@ public enum Dependency {
BIOME_API( BIOME_API(
"com{}github{}Xiao-MoMi", "com{}github{}Xiao-MoMi",
"BiomeAPI", "BiomeAPI",
"0.2", "0.3",
"jitpack", "jitpack",
"biome-api", "biome-api",
Relocation.of("biomeapi", "net{}momirealms{}biomeapi") Relocation.of("biomeapi", "net{}momirealms{}biomeapi")

View File

@@ -61,12 +61,12 @@ import java.util.concurrent.TimeUnit;
public class ActionManagerImpl implements ActionManager { public class ActionManagerImpl implements ActionManager {
private final CustomFishingPlugin plugin; private final CustomFishingPlugin plugin;
private final HashMap<String, ActionFactory> actionBuilderMap; private final HashMap<String, ActionFactory> actionFactoryMap;
private final String EXPANSION_FOLDER = "expansions/action"; private final String EXPANSION_FOLDER = "expansions/action";
public ActionManagerImpl(CustomFishingPlugin plugin) { public ActionManagerImpl(CustomFishingPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.actionBuilderMap = new HashMap<>(); this.actionFactoryMap = new HashMap<>();
this.registerInbuiltActions(); this.registerInbuiltActions();
} }
@@ -110,7 +110,7 @@ public class ActionManagerImpl implements ActionManager {
public void disable() { public void disable() {
unload(); unload();
this.actionBuilderMap.clear(); this.actionFactoryMap.clear();
} }
// Method to load global event actions from the plugin's configuration file. // Method to load global event actions from the plugin's configuration file.
@@ -129,8 +129,8 @@ public class ActionManagerImpl implements ActionManager {
*/ */
@Override @Override
public boolean registerAction(String type, ActionFactory actionFactory) { public boolean registerAction(String type, ActionFactory actionFactory) {
if (this.actionBuilderMap.containsKey(type)) return false; if (this.actionFactoryMap.containsKey(type)) return false;
this.actionBuilderMap.put(type, actionFactory); this.actionFactoryMap.put(type, actionFactory);
return true; return true;
} }
@@ -143,7 +143,7 @@ public class ActionManagerImpl implements ActionManager {
*/ */
@Override @Override
public boolean unregisterAction(String type) { public boolean unregisterAction(String type) {
return this.actionBuilderMap.remove(type) != null; return this.actionFactoryMap.remove(type) != null;
} }
/** /**
@@ -238,7 +238,7 @@ public class ActionManagerImpl implements ActionManager {
@Nullable @Nullable
@Override @Override
public ActionFactory getActionFactory(String type) { public ActionFactory getActionFactory(String type) {
return actionBuilderMap.get(type); return actionFactoryMap.get(type);
} }
/** /**

View File

@@ -130,6 +130,8 @@ public class CompetitionManagerImpl implements CompetitionManager {
.minPlayers(section.getInt("min-players", 0)) .minPlayers(section.getInt("min-players", 0))
.duration(section.getInt("duration", 300)) .duration(section.getInt("duration", 300))
.rewards(getPrizeActions(section.getConfigurationSection("rewards"))) .rewards(getPrizeActions(section.getConfigurationSection("rewards")))
.requirements(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("participate-requirements"), false))
.joinActions(plugin.getActionManager().getActions(section.getConfigurationSection("participate-actions")))
.startActions(plugin.getActionManager().getActions(section.getConfigurationSection("start-actions"))) .startActions(plugin.getActionManager().getActions(section.getConfigurationSection("start-actions")))
.endActions(plugin.getActionManager().getActions(section.getConfigurationSection("end-actions"))) .endActions(plugin.getActionManager().getActions(section.getConfigurationSection("end-actions")))
.skipActions(plugin.getActionManager().getActions(section.getConfigurationSection("skip-actions"))); .skipActions(plugin.getActionManager().getActions(section.getConfigurationSection("skip-actions")));

View File

@@ -59,6 +59,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
@@ -718,7 +719,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
*/ */
private void doSuccessActions(Loot loot, Effect effect, FishingPreparation fishingPreparation, Player player) { private void doSuccessActions(Loot loot, Effect effect, FishingPreparation fishingPreparation, Player player) {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition(); FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition != null) { if (competition != null && RequirementManager.isRequirementMet(fishingPreparation, competition.getConfig().getRequirements())) {
String scoreStr = fishingPreparation.getArg("{CUSTOM_SCORE}"); String scoreStr = fishingPreparation.getArg("{CUSTOM_SCORE}");
if (scoreStr != null) { if (scoreStr != null) {
competition.refreshData(player, Double.parseDouble(scoreStr)); competition.refreshData(player, Double.parseDouble(scoreStr));

View File

@@ -188,7 +188,8 @@ public class HookCheckTimerTask implements Runnable {
private void setTempState() { private void setTempState() {
Loot nextLoot = CustomFishingPlugin.get().getLootManager().getNextLoot(initialEffect, fishingPreparation); Loot nextLoot = CustomFishingPlugin.get().getLootManager().getNextLoot(initialEffect, fishingPreparation);
if (nextLoot == null) { if (nextLoot == null) {
CustomFishingPlugin.get().debug("No loot available, using vanilla "); fishHook.setWaitTime(Integer.MAX_VALUE);
CustomFishingPlugin.get().debug("No loot available at " + fishingPreparation.getLocation());
return; return;
} }

View File

@@ -201,7 +201,6 @@ public class LootManagerImpl implements LootManager {
public Loot getNextLoot(Effect initialEffect, Condition condition) { public Loot getNextLoot(Effect initialEffect, Condition condition) {
String key = WeightUtils.getRandom(getPossibleLootKeysWithWeight(initialEffect, condition)); String key = WeightUtils.getRandom(getPossibleLootKeysWithWeight(initialEffect, condition));
if (key == null) { if (key == null) {
LogUtils.warn("No loot available at " + condition.getLocation() + " for player: " + condition.getPlayer().getName());
return null; return null;
} }
Loot loot = getLoot(key); Loot loot = getLoot(key);

View File

@@ -18,6 +18,7 @@
package net.momirealms.customfishing.mechanic.market; package net.momirealms.customfishing.mechanic.market;
import net.momirealms.customfishing.adventure.AdventureManagerImpl; import net.momirealms.customfishing.adventure.AdventureManagerImpl;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.data.EarningData; import net.momirealms.customfishing.api.data.EarningData;
import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder; import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder;
import net.momirealms.customfishing.api.util.InventoryUtils; import net.momirealms.customfishing.api.util.InventoryUtils;
@@ -146,37 +147,87 @@ public class MarketGUI {
* @return The MarketGUI instance. * @return The MarketGUI instance.
*/ */
public MarketGUI refresh() { public MarketGUI refresh() {
double totalWorth = getTotalWorth();
MarketDynamicGUIElement functionElement = (MarketDynamicGUIElement) getElement(manager.getFunctionSlot());
if (functionElement == null) {
return this;
}
double earningLimit = manager.getEarningLimit(owner); double earningLimit = manager.getEarningLimit(owner);
MarketDynamicGUIElement sellElement = (MarketDynamicGUIElement) getElement(manager.getSellSlot());
if (sellElement != null && sellElement.getSlots().size() > 0) {
double totalWorth = getTotalWorthInMarketGUI();
int soldAmount = getSoldAmount();
if (totalWorth <= 0) { if (totalWorth <= 0) {
functionElement.setItemStack( sellElement.setItemStack(
manager.getFunctionIconDenyBuilder().build(owner, manager.getSellIconDenyBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth) Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName() ,"{player}", owner.getName()
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)) ,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
,"{sold-item-amount}", String.valueOf(soldAmount)
)
) )
); );
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) { } else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
functionElement.setItemStack( sellElement.setItemStack(
manager.getFunctionIconLimitBuilder().build(owner, manager.getSellIconLimitBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth) Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName() ,"{player}", owner.getName()
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)) ,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
,"{sold-item-amount}", String.valueOf(soldAmount)
)
) )
); );
} else { } else {
functionElement.setItemStack( sellElement.setItemStack(
manager.getFunctionIconAllowBuilder().build(owner, manager.getSellIconAllowBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth) Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName() ,"{player}", owner.getName()
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)) ,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
,"{sold-item-amount}", String.valueOf(soldAmount)
)
) )
); );
} }
}
MarketDynamicGUIElement sellAllElement = (MarketDynamicGUIElement) getElement(manager.getSellAllSlot());
if (sellAllElement != null && sellAllElement.getSlots().size() > 0) {
double totalWorth = manager.getInventoryTotalWorth(owner.getInventory());
int sellAmount = manager.getInventorySellAmount(owner.getInventory());
if (manager.sellFishingBag() && CustomFishingPlugin.get().getBagManager().isEnabled()) {
Inventory bag = CustomFishingPlugin.get().getBagManager().getOnlineBagInventory(owner.getUniqueId());
if (bag != null) {
totalWorth += manager.getInventoryTotalWorth(bag);
sellAmount += manager.getInventorySellAmount(bag);
}
}
if (totalWorth <= 0) {
sellAllElement.setItemStack(
manager.getSellAllIconDenyBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName()
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
,"{sold-item-amount}", String.valueOf(sellAmount)
)
)
);
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
sellAllElement.setItemStack(
manager.getSellAllIconLimitBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName()
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
,"{sold-item-amount}", String.valueOf(sellAmount)
)
)
);
} else {
sellAllElement.setItemStack(
manager.getSellAllIconAllowBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName()
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings)
,"{sold-item-amount}", String.valueOf(sellAmount)
)
)
);
}
}
for (Map.Entry<Integer, MarketGUIElement> entry : itemsSlotMap.entrySet()) { for (Map.Entry<Integer, MarketGUIElement> entry : itemsSlotMap.entrySet()) {
if (entry.getValue() instanceof MarketDynamicGUIElement dynamicGUIElement) { if (entry.getValue() instanceof MarketDynamicGUIElement dynamicGUIElement) {
this.inventory.setItem(entry.getKey(), dynamicGUIElement.getItemStack().clone()); this.inventory.setItem(entry.getKey(), dynamicGUIElement.getItemStack().clone());
@@ -189,7 +240,7 @@ public class MarketGUI {
* Calculate and return the total worth of items in the inventory. * Calculate and return the total worth of items in the inventory.
* @return The total worth of items. * @return The total worth of items.
*/ */
public double getTotalWorth() { public double getTotalWorthInMarketGUI() {
double money = 0d; double money = 0d;
MarketGUIElement itemElement = getElement(manager.getItemSlot()); MarketGUIElement itemElement = getElement(manager.getItemSlot());
if (itemElement == null) { if (itemElement == null) {

View File

@@ -60,15 +60,23 @@ public class MarketManagerImpl implements MarketManager, Listener {
private String formula; private String formula;
private final HashMap<Character, BuildableItem> decorativeIcons; private final HashMap<Character, BuildableItem> decorativeIcons;
private char itemSlot; private char itemSlot;
private char functionSlot; private char sellSlot;
private BuildableItem functionIconAllowBuilder; private char sellAllSlot;
private BuildableItem functionIconDenyBuilder; private BuildableItem sellIconAllowBuilder;
private BuildableItem functionIconLimitBuilder; private BuildableItem sellIconDenyBuilder;
private Action[] denyActions; private BuildableItem sellIconLimitBuilder;
private Action[] allowActions; private BuildableItem sellAllIconAllowBuilder;
private Action[] limitActions; private BuildableItem sellAllIconDenyBuilder;
private BuildableItem sellAllIconLimitBuilder;
private Action[] sellDenyActions;
private Action[] sellAllowActions;
private Action[] sellLimitActions;
private Action[] sellAllDenyActions;
private Action[] sellAllAllowActions;
private Action[] sellAllLimitActions;
private String earningLimitExpression; private String earningLimitExpression;
private boolean allowItemWithNoPrice; private boolean allowItemWithNoPrice;
private boolean sellFishingBag;
private final ConcurrentHashMap<UUID, MarketGUI> marketGUIMap; private final ConcurrentHashMap<UUID, MarketGUI> marketGUIMap;
private boolean enable; private boolean enable;
private CancellableTask resetEarningsTask; private CancellableTask resetEarningsTask;
@@ -123,16 +131,41 @@ public class MarketManagerImpl implements MarketManager, Listener {
this.layout = config.getStringList("layout").toArray(new String[0]); this.layout = config.getStringList("layout").toArray(new String[0]);
this.title = config.getString("title", "market.title"); this.title = config.getString("title", "market.title");
this.itemSlot = config.getString("item-slot.symbol", "I").charAt(0); this.itemSlot = config.getString("item-slot.symbol", "I").charAt(0);
this.functionSlot = config.getString("functional-icons.symbol", "B").charAt(0);
this.functionIconAllowBuilder = plugin.getItemManager().getItemBuilder(config.getConfigurationSection("functional-icons.allow-icon"), "gui", "allow");
this.functionIconDenyBuilder = plugin.getItemManager().getItemBuilder(config.getConfigurationSection("functional-icons.deny-icon"), "gui", "deny");
this.functionIconLimitBuilder = plugin.getItemManager().getItemBuilder(config.getConfigurationSection("functional-icons.limit-icon"), "gui", "limit");
this.allowActions = plugin.getActionManager().getActions(config.getConfigurationSection("functional-icons.allow-icon.action"));
this.denyActions = plugin.getActionManager().getActions(config.getConfigurationSection("functional-icons.deny-icon.action"));
this.limitActions = plugin.getActionManager().getActions(config.getConfigurationSection("functional-icons.limit-icon.action"));
this.earningLimitExpression = config.getBoolean("limitation.enable", true) ? config.getString("limitation.earnings", "10000") : "-1";
this.allowItemWithNoPrice = config.getBoolean("item-slot.allow-items-with-no-price", true); this.allowItemWithNoPrice = config.getBoolean("item-slot.allow-items-with-no-price", true);
ConfigurationSection sellAllSection = config.getConfigurationSection("sell-all-icons");
if (sellAllSection != null) {
this.sellAllSlot = sellAllSection.getString("symbol", "S").charAt(0);
this.sellFishingBag = sellAllSection.getBoolean("fishingbag", true);
this.sellAllIconAllowBuilder = plugin.getItemManager().getItemBuilder(sellAllSection.getConfigurationSection("allow-icon"), "gui", "sell-all");
this.sellAllIconDenyBuilder = plugin.getItemManager().getItemBuilder(sellAllSection.getConfigurationSection("deny-icon"), "gui", "sell-all");
this.sellAllIconLimitBuilder = plugin.getItemManager().getItemBuilder(sellAllSection.getConfigurationSection("limit-icon"), "gui", "sell-all");
this.sellAllAllowActions = plugin.getActionManager().getActions(sellAllSection.getConfigurationSection("allow-icon.action"));
this.sellAllDenyActions = plugin.getActionManager().getActions(sellAllSection.getConfigurationSection("deny-icon.action"));
this.sellAllLimitActions = plugin.getActionManager().getActions(sellAllSection.getConfigurationSection("limit-icon.action"));
}
ConfigurationSection sellSection = config.getConfigurationSection("sell-icons");
if (sellSection == null) {
// for old config compatibility
sellSection = config.getConfigurationSection("functional-icons");
}
if (sellSection != null) {
this.sellSlot = sellSection.getString("symbol", "B").charAt(0);
this.sellIconAllowBuilder = plugin.getItemManager().getItemBuilder(sellSection.getConfigurationSection("allow-icon"), "gui", "allow");
this.sellIconDenyBuilder = plugin.getItemManager().getItemBuilder(sellSection.getConfigurationSection("deny-icon"), "gui", "deny");
this.sellIconLimitBuilder = plugin.getItemManager().getItemBuilder(sellSection.getConfigurationSection("limit-icon"), "gui", "limit");
this.sellAllowActions = plugin.getActionManager().getActions(sellSection.getConfigurationSection("allow-icon.action"));
this.sellDenyActions = plugin.getActionManager().getActions(sellSection.getConfigurationSection("deny-icon.action"));
this.sellLimitActions = plugin.getActionManager().getActions(sellSection.getConfigurationSection("limit-icon.action"));
}
this.earningLimitExpression = config.getBoolean("limitation.enable", true) ? config.getString("limitation.earnings", "10000") : "-1";
// Load item prices from the configuration // Load item prices from the configuration
ConfigurationSection priceSection = config.getConfigurationSection("item-price"); ConfigurationSection priceSection = config.getConfigurationSection("item-price");
if (priceSection != null) { if (priceSection != null) {
@@ -170,7 +203,8 @@ public class MarketManagerImpl implements MarketManager, Listener {
MarketGUI gui = new MarketGUI(this, player, user.getEarningData()); MarketGUI gui = new MarketGUI(this, player, user.getEarningData());
gui.addElement(new MarketGUIElement(getItemSlot(), new ItemStack(Material.AIR))); gui.addElement(new MarketGUIElement(getItemSlot(), new ItemStack(Material.AIR)));
gui.addElement(new MarketDynamicGUIElement(getFunctionSlot(), new ItemStack(Material.AIR))); gui.addElement(new MarketDynamicGUIElement(getSellSlot(), new ItemStack(Material.AIR)));
gui.addElement(new MarketDynamicGUIElement(getSellAllSlot(), new ItemStack(Material.AIR)));
for (Map.Entry<Character, BuildableItem> entry : decorativeIcons.entrySet()) { for (Map.Entry<Character, BuildableItem> entry : decorativeIcons.entrySet()) {
gui.addElement(new MarketGUIElement(entry.getKey(), entry.getValue().build(player))); gui.addElement(new MarketGUIElement(entry.getKey(), entry.getValue().build(player)));
} }
@@ -288,8 +322,8 @@ public class MarketManagerImpl implements MarketManager, Listener {
event.setCancelled(true); event.setCancelled(true);
} }
if (element.getSymbol() == functionSlot) { if (element.getSymbol() == sellSlot) {
double worth = gui.getTotalWorth(); double worth = gui.getTotalWorthInMarketGUI();
int amount = gui.getSoldAmount(); int amount = gui.getSoldAmount();
double earningLimit = getEarningLimit(player); double earningLimit = getEarningLimit(player);
Condition condition = new Condition(player, new HashMap<>(Map.of( Condition condition = new Condition(player, new HashMap<>(Map.of(
@@ -300,8 +334,8 @@ public class MarketManagerImpl implements MarketManager, Listener {
if (worth > 0) { if (worth > 0) {
if (earningLimit != -1 && (earningLimit - data.earnings) < worth) { if (earningLimit != -1 && (earningLimit - data.earnings) < worth) {
// Can't earn more money // Can't earn more money
if (limitActions != null) { if (getSellLimitActions() != null) {
for (Action action : limitActions) { for (Action action : getSellLimitActions()) {
action.trigger(condition); action.trigger(condition);
} }
} }
@@ -310,16 +344,65 @@ public class MarketManagerImpl implements MarketManager, Listener {
gui.clearWorthyItems(); gui.clearWorthyItems();
data.earnings += worth; data.earnings += worth;
condition.insertArg("{rest}", String.format("%.2f", (earningLimit - data.earnings))); condition.insertArg("{rest}", String.format("%.2f", (earningLimit - data.earnings)));
if (allowActions != null) { if (getSellAllowActions() != null) {
for (Action action : allowActions) { for (Action action : getSellAllowActions()) {
action.trigger(condition); action.trigger(condition);
} }
} }
} }
} else { } else {
// Nothing to sell // Nothing to sell
if (denyActions != null) { if (getSellDenyActions() != null) {
for (Action action : denyActions) { for (Action action : getSellDenyActions()) {
action.trigger(condition);
}
}
}
} else if (element.getSymbol() == sellAllSlot) {
double worth = getInventoryTotalWorth(player.getInventory());
int amount = getInventorySellAmount(player.getInventory());
double earningLimit = getEarningLimit(player);
if (sellFishingBag() && CustomFishingPlugin.get().getBagManager().isEnabled()) {
Inventory bag = CustomFishingPlugin.get().getBagManager().getOnlineBagInventory(player.getUniqueId());
if (bag != null) {
worth += getInventoryTotalWorth(bag);
amount += getInventorySellAmount(bag);
}
}
Condition condition = new Condition(player, new HashMap<>(Map.of(
"{money}", String.format("%.2f", worth)
,"{rest}", String.format("%.2f", (earningLimit - data.earnings))
,"{sold-item-amount}", String.valueOf(amount)
)));
if (worth > 0) {
if (earningLimit != -1 && (earningLimit - data.earnings) < worth) {
// Can't earn more money
if (getSellAllLimitActions() != null) {
for (Action action : getSellAllLimitActions()) {
action.trigger(condition);
}
}
} else {
// Clear items and update earnings
clearWorthyItems(player.getInventory());
if (sellFishingBag() && CustomFishingPlugin.get().getBagManager().isEnabled()) {
Inventory bag = CustomFishingPlugin.get().getBagManager().getOnlineBagInventory(player.getUniqueId());
if (bag != null) {
clearWorthyItems(bag);
}
}
data.earnings += worth;
condition.insertArg("{rest}", String.format("%.2f", (earningLimit - data.earnings)));
if (getSellAllAllowActions() != null) {
for (Action action : getSellAllAllowActions()) {
action.trigger(condition);
}
}
}
} else {
// Nothing to sell
if (getSellAllDenyActions() != null) {
for (Action action : getSellAllDenyActions()) {
action.trigger(condition); action.trigger(condition);
} }
} }
@@ -371,11 +454,6 @@ public class MarketManagerImpl implements MarketManager, Listener {
plugin.getScheduler().runTaskSyncLater(gui::refresh, player.getLocation(), 50, TimeUnit.MILLISECONDS); plugin.getScheduler().runTaskSyncLater(gui::refresh, player.getLocation(), 50, TimeUnit.MILLISECONDS);
} }
/**
* Retrieves the current date as an integer in the format MMDD (e.g., September 21 as 0921).
*
* @return An integer representing the current date.
*/
@Override @Override
public int getCachedDate() { public int getCachedDate() {
return date; return date;
@@ -387,12 +465,6 @@ public class MarketManagerImpl implements MarketManager, Listener {
return (calendar.get(Calendar.MONTH) +1) * 100 + calendar.get(Calendar.DATE); return (calendar.get(Calendar.MONTH) +1) * 100 + calendar.get(Calendar.DATE);
} }
/**
* Calculates the price of an ItemStack based on custom data or a predefined price map.
*
* @param itemStack The ItemStack for which the price is calculated.
* @return The calculated price of the ItemStack.
*/
@Override @Override
public double getItemPrice(ItemStack itemStack) { public double getItemPrice(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) if (itemStack == null || itemStack.getType() == Material.AIR)
@@ -415,21 +487,11 @@ public class MarketManagerImpl implements MarketManager, Listener {
return priceMap.getOrDefault(itemID, 0d) * itemStack.getAmount(); return priceMap.getOrDefault(itemID, 0d) * itemStack.getAmount();
} }
/**
* Retrieves the formula used for calculating prices.
*
* @return The pricing formula as a string.
*/
@Override @Override
public String getFormula() { public String getFormula() {
return formula; return formula;
} }
/**
* Calculates the price based on a formula with provided variables.
*
* @return The calculated price based on the formula and provided variables.
*/
@Override @Override
public double getFishPrice(Player player, Map<String, String> vars) { public double getFishPrice(Player player, Map<String, String> vars) {
String temp = PlaceholderManagerImpl.getInstance().parse(player, formula, vars); String temp = PlaceholderManagerImpl.getInstance().parse(player, formula, vars);
@@ -440,51 +502,31 @@ public class MarketManagerImpl implements MarketManager, Listener {
return new ExpressionBuilder(temp).build().evaluate(); return new ExpressionBuilder(temp).build().evaluate();
} }
/**
* Gets the character representing the item slot in the MarketGUI.
*
* @return The item slot character.
*/
@Override @Override
public char getItemSlot() { public char getItemSlot() {
return itemSlot; return itemSlot;
} }
/**
* Gets the character representing the function slot in the MarketGUI.
*
* @return The function slot character.
*/
@Override @Override
public char getFunctionSlot() { public char getSellSlot() {
return functionSlot; return sellSlot;
}
@Override
public char getSellAllSlot() {
return sellAllSlot;
} }
/**
* Gets the layout of the MarketGUI as an array of strings.
*
* @return The layout of the MarketGUI.
*/
@Override @Override
public String[] getLayout() { public String[] getLayout() {
return layout; return layout;
} }
/**
* Gets the title of the MarketGUI.
*
* @return The title of the MarketGUI.
*/
@Override @Override
public String getTitle() { public String getTitle() {
return title; return title;
} }
/**
* Gets the earning limit
*
* @return The earning limit
*/
@Override @Override
public double getEarningLimit(Player player) { public double getEarningLimit(Player player) {
return new ExpressionBuilder( return new ExpressionBuilder(
@@ -497,40 +539,92 @@ public class MarketManagerImpl implements MarketManager, Listener {
.evaluate(); .evaluate();
} }
/** public BuildableItem getSellIconLimitBuilder() {
* Gets the builder for the function icon representing the limit in the MarketGUI. return sellIconLimitBuilder;
*
* @return The function icon builder for the limit.
*/
public BuildableItem getFunctionIconLimitBuilder() {
return functionIconLimitBuilder;
} }
/** public BuildableItem getSellIconAllowBuilder() {
* Gets the builder for the function icon representing allow actions in the MarketGUI. return sellIconAllowBuilder;
*
* @return The function icon builder for allow actions.
*/
public BuildableItem getFunctionIconAllowBuilder() {
return functionIconAllowBuilder;
} }
/** public BuildableItem getSellIconDenyBuilder() {
* Gets the builder for the function icon representing deny actions in the MarketGUI. return sellIconDenyBuilder;
* }
* @return The function icon builder for deny actions.
*/ public BuildableItem getSellAllIconAllowBuilder() {
public BuildableItem getFunctionIconDenyBuilder() { return sellAllIconAllowBuilder;
return functionIconDenyBuilder; }
public BuildableItem getSellAllIconDenyBuilder() {
return sellAllIconDenyBuilder;
}
public BuildableItem getSellAllIconLimitBuilder() {
return sellAllIconLimitBuilder;
}
public Action[] getSellDenyActions() {
return sellDenyActions;
}
public Action[] getSellAllowActions() {
return sellAllowActions;
}
public Action[] getSellLimitActions() {
return sellLimitActions;
}
public Action[] getSellAllDenyActions() {
return sellAllDenyActions;
}
public Action[] getSellAllAllowActions() {
return sellAllAllowActions;
}
public Action[] getSellAllLimitActions() {
return sellAllLimitActions;
} }
/**
* Is market enabled
*
* @return enable or not
*/
@Override @Override
public boolean isEnable() { public boolean isEnable() {
return enable; return enable;
} }
@Override
public boolean sellFishingBag() {
return sellFishingBag;
}
@Override
public double getInventoryTotalWorth(Inventory inventory) {
double total = 0d;
for (ItemStack itemStack : inventory.getStorageContents()) {
double price = getItemPrice(itemStack);
total += price;
}
return total;
}
@Override
public int getInventorySellAmount(Inventory inventory) {
int amount = 0;
for (ItemStack itemStack : inventory.getStorageContents()) {
double price = getItemPrice(itemStack);
if (price > 0 && itemStack != null) {
amount += itemStack.getAmount();
}
}
return amount;
}
public void clearWorthyItems(Inventory inventory) {
for (ItemStack itemStack : inventory.getStorageContents()) {
double price = getItemPrice(itemStack);
if (price > 0 && itemStack != null) {
itemStack.setAmount(0);
}
}
}
} }

View File

@@ -59,14 +59,14 @@ public class RequirementManagerImpl implements RequirementManager {
public static Requirement[] mechanicRequirements; public static Requirement[] mechanicRequirements;
private final CustomFishingPluginImpl plugin; private final CustomFishingPluginImpl plugin;
private final HashMap<String, RequirementFactory> requirementBuilderMap; private final HashMap<String, RequirementFactory> requirementFactoryMap;
private final LinkedHashMap<String, ConditionalElement> conditionalLootsMap; private final LinkedHashMap<String, ConditionalElement> conditionalLootsMap;
private final LinkedHashMap<String, ConditionalElement> conditionalGamesMap; private final LinkedHashMap<String, ConditionalElement> conditionalGamesMap;
private final String EXPANSION_FOLDER = "expansions/requirement"; private final String EXPANSION_FOLDER = "expansions/requirement";
public RequirementManagerImpl(CustomFishingPluginImpl plugin) { public RequirementManagerImpl(CustomFishingPluginImpl plugin) {
this.plugin = plugin; this.plugin = plugin;
this.requirementBuilderMap = new HashMap<>(); this.requirementFactoryMap = new HashMap<>();
this.conditionalLootsMap = new LinkedHashMap<>(); this.conditionalLootsMap = new LinkedHashMap<>();
this.conditionalGamesMap = new LinkedHashMap<>(); this.conditionalGamesMap = new LinkedHashMap<>();
this.registerInbuiltRequirements(); this.registerInbuiltRequirements();
@@ -82,7 +82,7 @@ public class RequirementManagerImpl implements RequirementManager {
} }
public void disable() { public void disable() {
this.requirementBuilderMap.clear(); this.requirementFactoryMap.clear();
this.conditionalLootsMap.clear(); this.conditionalLootsMap.clear();
} }
@@ -130,8 +130,8 @@ public class RequirementManagerImpl implements RequirementManager {
*/ */
@Override @Override
public boolean registerRequirement(String type, RequirementFactory requirementFactory) { public boolean registerRequirement(String type, RequirementFactory requirementFactory) {
if (this.requirementBuilderMap.containsKey(type)) return false; if (this.requirementFactoryMap.containsKey(type)) return false;
this.requirementBuilderMap.put(type, requirementFactory); this.requirementFactoryMap.put(type, requirementFactory);
return true; return true;
} }
@@ -143,7 +143,7 @@ public class RequirementManagerImpl implements RequirementManager {
*/ */
@Override @Override
public boolean unregisterRequirement(String type) { public boolean unregisterRequirement(String type) {
return this.requirementBuilderMap.remove(type) != null; return this.requirementFactoryMap.remove(type) != null;
} }
/** /**
@@ -282,7 +282,7 @@ public class RequirementManagerImpl implements RequirementManager {
@Override @Override
public boolean hasRequirement(String type) { public boolean hasRequirement(String type) {
return requirementBuilderMap.containsKey(type); return requirementFactoryMap.containsKey(type);
} }
/** /**
@@ -350,7 +350,7 @@ public class RequirementManagerImpl implements RequirementManager {
@Override @Override
@Nullable @Nullable
public RequirementFactory getRequirementFactory(String type) { public RequirementFactory getRequirementFactory(String type) {
return requirementBuilderMap.get(type); return requirementFactoryMap.get(type);
} }
private void registerTimeRequirement() { private void registerTimeRequirement() {

View File

@@ -90,6 +90,10 @@ weekend_competition:
value: value:
- 'You have joined the competition. Good luck!' - 'You have joined the competition. Good luck!'
# Requirements for participating the competition
participate-requirements: {}
# Rewards
rewards: rewards:
1: 1:
command_action: command_action:

View File

@@ -34,8 +34,63 @@ item-slot:
symbol: 'I' symbol: 'I'
allow-items-with-no-price: true allow-items-with-no-price: true
# Functional icon # This is an icon that allows players to sell all the fish from their inventory and fishingbag
functional-icons: # You can enable it by putting the symbol into layout
sell-all-icons:
symbol: 'S'
# Should the fish in fishing bag be sold
fishingbag: true
allow-icon:
material: IRON_BLOCK
display:
name: '<#00CED1><b>● <!b>Ship the fish'
lore:
- '<font:uniform><gradient:#E6E6FA:#48D1CC:#E6E6FA>You will get <green>{money}$</green> by selling the fish from inventory and bag</gradient></font>'
action:
sound_action:
type: sound
value:
key: 'minecraft:block.amethyst_block.place'
source: 'player'
volume: 1
pitch: 1
message_action:
type: message
value: 'You earned {money}$ by selling the fish! You can still get {rest}$ from market today'
command_action:
type: command
value: 'money give {player} {money}'
deny-icon:
material: REDSTONE_BLOCK
display:
name: '<red><b>● <!b>Denied trade'
lore:
- '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>Nothing to sell!</gradient></font>'
action:
sound_action:
type: sound
value:
key: 'minecraft:entity.villager.no'
source: 'player'
volume: 1
pitch: 1
limit-icon:
material: REDSTONE_BLOCK
display:
name: '<red><b>● <!b>Denied trade'
lore:
- '<font:uniform><gradient:#E6E6FA:red:#E6E6FA>The worth of items exceeds the money that can be earned for the rest of today!</gradient></font>'
action:
sound_action:
type: sound
value:
key: 'minecraft:block.anvil.land'
source: 'player'
volume: 1
pitch: 1
# Sell icon
sell-icons:
symbol: 'B' symbol: 'B'
allow-icon: allow-icon:
material: IRON_BLOCK material: IRON_BLOCK