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

Added earnings multiplier

This commit is contained in:
XiaoMoMi
2024-11-28 15:39:21 +08:00
parent 484ca14c4e
commit 9bdfbf7cf1
6 changed files with 24 additions and 16 deletions

View File

@@ -58,4 +58,6 @@ public interface MarketManager extends Reloadable {
* @return the earning limit as a double * @return the earning limit as a double
*/ */
double earningLimit(Context<Player> context); double earningLimit(Context<Player> context);
double earningsMultiplier(Context<Player> context);
} }

View File

@@ -638,7 +638,7 @@ public class BukkitConfigManager extends ConfigManager {
} }
})); }));
} }
case "group-mod" -> { case "group-mod", "group_mod" -> {
var op = parseGroupWeightOperation(section.getStringList("value")); var op = parseGroupWeightOperation(section.getStringList("value"));
return (((effect, context, phase) -> { return (((effect, context, phase) -> {
if (phase == 1) { if (phase == 1) {
@@ -647,7 +647,7 @@ public class BukkitConfigManager extends ConfigManager {
} }
})); }));
} }
case "group-mod-ignore-conditions" -> { case "group-mod-ignore-conditions", "group_mod_ignore_conditions" -> {
var op = parseGroupWeightOperation(section.getStringList("value")); var op = parseGroupWeightOperation(section.getStringList("value"));
return (((effect, context, phase) -> { return (((effect, context, phase) -> {
if (phase == 1) { if (phase == 1) {
@@ -656,7 +656,7 @@ public class BukkitConfigManager extends ConfigManager {
} }
})); }));
} }
case "wait-time" -> { case "wait-time", "wait_time" -> {
MathValue<Player> value = MathValue.auto(section.get("value")); MathValue<Player> value = MathValue.auto(section.get("value"));
return (((effect, context, phase) -> { return (((effect, context, phase) -> {
if (phase == 2) { if (phase == 2) {
@@ -665,7 +665,7 @@ public class BukkitConfigManager extends ConfigManager {
} }
})); }));
} }
case "hook-time", "wait-time-multiplier" -> { case "hook-time", "hook_time", "wait-time-multiplier", "wait_time_multiplier" -> {
MathValue<Player> value = MathValue.auto(section.get("value")); MathValue<Player> value = MathValue.auto(section.get("value"));
return (((effect, context, phase) -> { return (((effect, context, phase) -> {
if (phase == 2) { if (phase == 2) {
@@ -683,7 +683,7 @@ public class BukkitConfigManager extends ConfigManager {
} }
})); }));
} }
case "difficulty-multiplier", "difficulty-bonus" -> { case "difficulty-multiplier", "difficulty_multiplier", "difficulty-bonus" -> {
MathValue<Player> value = MathValue.auto(section.get("value")); MathValue<Player> value = MathValue.auto(section.get("value"));
return (((effect, context, phase) -> { return (((effect, context, phase) -> {
if (phase == 2) { if (phase == 2) {

View File

@@ -62,6 +62,7 @@ public class BukkitMarketManager implements MarketManager, Listener {
private final HashMap<String, MathValue<Player>> priceMap; private final HashMap<String, MathValue<Player>> priceMap;
private String formula; private String formula;
private MathValue<Player> earningsLimit; private MathValue<Player> earningsLimit;
private MathValue<Player> earningsMultiplier;
private boolean allowItemWithNoPrice; private boolean allowItemWithNoPrice;
protected boolean sellFishingBag; protected boolean sellFishingBag;
@@ -173,6 +174,7 @@ public class BukkitMarketManager implements MarketManager, Listener {
} }
this.earningsLimit = config.getBoolean("limitation.enable", true) ? MathValue.auto(config.getString("limitation.earnings", "10000")) : MathValue.plain(-1); this.earningsLimit = config.getBoolean("limitation.enable", true) ? MathValue.auto(config.getString("limitation.earnings", "10000")) : MathValue.plain(-1);
this.earningsMultiplier = MathValue.auto(config.get("earnings-multiplier", 1d));
// Load item prices from the configuration // Load item prices from the configuration
Section priceSection = config.getSection("item-price"); Section priceSection = config.getSection("item-price");
@@ -337,7 +339,7 @@ public class BukkitMarketManager implements MarketManager, Listener {
if (element.getSymbol() == sellSlot) { if (element.getSymbol() == sellSlot) {
Pair<Integer, Double> pair = getItemsToSell(gui.context, gui.getItemsInGUI()); Pair<Integer, Double> pair = getItemsToSell(gui.context, gui.getItemsInGUI());
double totalWorth = pair.right(); double totalWorth = pair.right() * earningsMultiplier(gui.context);
gui.context.arg(ContextKeys.MONEY, money(totalWorth)) gui.context.arg(ContextKeys.MONEY, money(totalWorth))
.arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth)) .arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth))
.arg(ContextKeys.REST, money(earningLimit - earningData.earnings)) .arg(ContextKeys.REST, money(earningLimit - earningData.earnings))
@@ -367,7 +369,7 @@ public class BukkitMarketManager implements MarketManager, Listener {
optionalUserData.ifPresent(userData -> itemStacksToSell.addAll(storageContentsToList(userData.holder().getInventory().getStorageContents()))); optionalUserData.ifPresent(userData -> itemStacksToSell.addAll(storageContentsToList(userData.holder().getInventory().getStorageContents())));
} }
Pair<Integer, Double> pair = getItemsToSell(gui.context, itemStacksToSell); Pair<Integer, Double> pair = getItemsToSell(gui.context, itemStacksToSell);
double totalWorth = pair.right(); double totalWorth = pair.right() * earningsMultiplier(gui.context);
gui.context.arg(ContextKeys.MONEY, money(totalWorth)) gui.context.arg(ContextKeys.MONEY, money(totalWorth))
.arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth)) .arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth))
.arg(ContextKeys.REST, money(earningLimit - earningData.earnings)) .arg(ContextKeys.REST, money(earningLimit - earningData.earnings))
@@ -485,6 +487,11 @@ public class BukkitMarketManager implements MarketManager, Listener {
return earningsLimit.evaluate(context); return earningsLimit.evaluate(context);
} }
@Override
public double earningsMultiplier(Context<Player> context) {
return earningsMultiplier.evaluate(context);
}
public Pair<Integer, Double> getItemsToSell(Context<Player> context, List<ItemStack> itemStacks) { public Pair<Integer, Double> getItemsToSell(Context<Player> context, List<ItemStack> itemStacks) {
int amount = 0; int amount = 0;
double worth = 0d; double worth = 0d;
@@ -506,9 +513,7 @@ public class BukkitMarketManager implements MarketManager, Listener {
if (allowBundle && itemStack.getItemMeta() instanceof BundleMeta bundleMeta) { if (allowBundle && itemStack.getItemMeta() instanceof BundleMeta bundleMeta) {
clearWorthyItems(context, bundleMeta.getItems()); clearWorthyItems(context, bundleMeta.getItems());
List<ItemStack> newItems = new ArrayList<>(bundleMeta.getItems()); List<ItemStack> newItems = new ArrayList<>(bundleMeta.getItems());
newItems.removeIf(item -> { newItems.removeIf(item -> item.getAmount() == 0 || item.getType() == Material.AIR);
return item.getAmount() == 0 || item.getType() == Material.AIR;
});
bundleMeta.setItems(newItems); bundleMeta.setItems(newItems);
itemStack.setItemMeta(bundleMeta); itemStack.setItemMeta(bundleMeta);
continue; continue;
@@ -527,8 +532,7 @@ public class BukkitMarketManager implements MarketManager, Listener {
} }
protected String money(double money) { protected String money(double money) {
String str = String.format("%.2f", money); return String.format(Locale.US, "%.2f", money);
return str.replace(",", ".");
} }
protected List<ItemStack> storageContentsToList(ItemStack[] itemStacks) { protected List<ItemStack> storageContentsToList(ItemStack[] itemStacks) {

View File

@@ -114,7 +114,7 @@ public class MarketGUI {
MarketDynamicGUIElement sellElement = (MarketDynamicGUIElement) getElement(manager.sellSlot); MarketDynamicGUIElement sellElement = (MarketDynamicGUIElement) getElement(manager.sellSlot);
if (sellElement != null && !sellElement.getSlots().isEmpty()) { if (sellElement != null && !sellElement.getSlots().isEmpty()) {
Pair<Integer, Double> pair = manager.getItemsToSell(context, getItemsInGUI()); Pair<Integer, Double> pair = manager.getItemsToSell(context, getItemsInGUI());
double totalWorth = pair.right(); double totalWorth = pair.right() * manager.earningsMultiplier(context);
int soldAmount = pair.left(); int soldAmount = pair.left();
context.arg(ContextKeys.MONEY, manager.money(totalWorth)) context.arg(ContextKeys.MONEY, manager.money(totalWorth))
.arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth)) .arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth))
@@ -138,7 +138,7 @@ public class MarketGUI {
optionalUserData.ifPresent(userData -> itemStacksToSell.addAll(manager.storageContentsToList(userData.holder().getInventory().getStorageContents()))); optionalUserData.ifPresent(userData -> itemStacksToSell.addAll(manager.storageContentsToList(userData.holder().getInventory().getStorageContents())));
} }
Pair<Integer, Double> pair = manager.getItemsToSell(context, itemStacksToSell); Pair<Integer, Double> pair = manager.getItemsToSell(context, itemStacksToSell);
double totalWorth = pair.right(); double totalWorth = pair.right() * manager.earningsMultiplier(context);
int soldAmount = pair.left(); int soldAmount = pair.left();
context.arg(ContextKeys.MONEY, manager.money(totalWorth)) context.arg(ContextKeys.MONEY, manager.money(totalWorth))
.arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth)) .arg(ContextKeys.MONEY_FORMATTED, String.format("%.2f", totalWorth))

View File

@@ -202,6 +202,8 @@ mechanics:
limitation: limitation:
enable: true enable: true
earnings: '10000' # Expressions can be used here earnings: '10000' # Expressions can be used here
# You can use expressions here if you want some players to earn more from selling fish
earnings-multiplier: 1
# Layout for the market menu # Layout for the market menu
layout: layout:
- 'AAAAAAAAA' - 'AAAAAAAAA'

View File

@@ -1,7 +1,7 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=2.2.33 project_version=2.2.34
config_version=36 config_version=37
project_group=net.momirealms project_group=net.momirealms
# Supported languages # Supported languages