9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-26 18:39:11 +00:00
This commit is contained in:
XiaoMoMi
2023-09-28 23:22:54 +08:00
parent e224a4de5e
commit a354578958
10 changed files with 62 additions and 25 deletions

View File

@@ -46,6 +46,6 @@ public class MMOItemsItemImpl implements ItemLibrary {
public String getItemID(ItemStack itemStack) {
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.hasTag("MMOITEMS_ITEM_ID")) return null;
return nbtItem.getString("MMOITEMS_ITEM_ID").toLowerCase(Locale.ENGLISH);
return nbtItem.getString("MMOITEMS_ITEM_ID");
}
}

View File

@@ -30,6 +30,7 @@ import net.momirealms.customfishing.api.mechanic.action.ActionExpansion;
import net.momirealms.customfishing.api.mechanic.action.ActionFactory;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.effect.FishingEffect;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import net.momirealms.customfishing.api.util.LogUtils;

View File

@@ -29,6 +29,7 @@ import net.momirealms.customfishing.api.mechanic.loot.WeightModifier;
import net.momirealms.customfishing.api.util.LogUtils;
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;
@@ -256,10 +257,10 @@ public class LootManagerImpl implements LootManager {
private CFLoot getSingleSectionItem(String filePath, ConfigurationSection section, String namespace, String key) {
return new CFLoot.Builder(key, LootType.valueOf(namespace.toUpperCase(Locale.ENGLISH)))
.filePath(filePath)
.disableStats(section.getBoolean("disable-stat", false))
.disableGames(section.getBoolean("disable-game", false))
.instantGame(section.getBoolean("instant-game", false))
.showInFinder(section.getBoolean("show-in-fishfinder", true))
.disableStats(section.getBoolean("disable-stat", CFConfig.globalDisableStats))
.disableGames(section.getBoolean("disable-game", CFConfig.globalDisableGame))
.instantGame(section.getBoolean("instant-game", CFConfig.globalInstantGame))
.showInFinder(section.getBoolean("show-in-fishfinder", CFConfig.globalShowInFinder))
.score(section.getDouble("score"))
.lootGroup(ConfigUtils.stringListArgs(section.get("group")).toArray(new String[0]))
.nick(section.getString("nick", section.getString("display.name", key)))

View File

@@ -151,20 +151,21 @@ public class MarketGUI {
if (functionElement == null) {
return this;
}
double earningLimit = manager.getEarningLimit(owner);
if (totalWorth <= 0) {
functionElement.setItemStack(
manager.getFunctionIconDenyBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName()
,"{rest}", String.format("%.2f", manager.getEarningLimit() - earningData.earnings))
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings))
)
);
} else if (manager.getEarningLimit() != -1 && (manager.getEarningLimit() - earningData.earnings < totalWorth)) {
} else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) {
functionElement.setItemStack(
manager.getFunctionIconLimitBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName()
,"{rest}", String.format("%.2f", manager.getEarningLimit() - earningData.earnings))
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings))
)
);
} else {
@@ -172,7 +173,7 @@ public class MarketGUI {
manager.getFunctionIconAllowBuilder().build(owner,
Map.of("{money}", String.format("%.2f", totalWorth)
,"{player}", owner.getName()
,"{rest}", String.format("%.2f", manager.getEarningLimit() - earningData.earnings))
,"{rest}", String.format("%.2f", earningLimit - earningData.earnings))
)
);
}

View File

@@ -27,6 +27,7 @@ import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.item.BuildableItem;
import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder;
import net.momirealms.customfishing.api.util.LogUtils;
import net.momirealms.customfishing.compatibility.papi.PlaceholderManagerImpl;
import net.momirealms.customfishing.util.ConfigUtils;
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
@@ -66,7 +67,7 @@ public class MarketManagerImpl implements MarketManager, Listener {
private Action[] denyActions;
private Action[] allowActions;
private Action[] limitActions;
private double earningLimit;
private String earningLimitExpression;
private boolean allowItemWithNoPrice;
private final ConcurrentHashMap<UUID, MarketGUI> marketGUIMap;
private boolean enable;
@@ -111,7 +112,7 @@ public class MarketManagerImpl implements MarketManager, Listener {
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.earningLimit = config.getBoolean("limitation.enable", true) ? config.getDouble("limitation.earnings", 100) : -1;
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);
// Load item prices from the configuration
@@ -271,6 +272,7 @@ public class MarketManagerImpl implements MarketManager, Listener {
if (element.getSymbol() == functionSlot) {
double worth = gui.getTotalWorth();
double earningLimit = getEarningLimit(player);
Condition condition = new Condition(player, new HashMap<>(Map.of(
"{money}", String.format("%.2f", worth)
,"{rest}", String.format("%.2f", (earningLimit - data.earnings))
@@ -463,8 +465,15 @@ public class MarketManagerImpl implements MarketManager, Listener {
* @return The earning limit
*/
@Override
public double getEarningLimit() {
return earningLimit;
public double getEarningLimit(Player player) {
return new ExpressionBuilder(
PlaceholderManagerImpl.getInstance().parse(
player,
earningLimitExpression,
new HashMap<>()
))
.build()
.evaluate();
}
/**

View File

@@ -40,7 +40,7 @@ import java.util.Objects;
public class CFConfig {
// config version
public static String configVersion = "27";
public static String configVersion = "28";
// Debug mode
public static boolean debug;
// language
@@ -88,6 +88,11 @@ public class CFConfig {
// Durability lore
public static List<String> durabilityLore;
public static boolean globalShowInFinder;
public static boolean globalDisableStats;
public static boolean globalDisableGame;
public static boolean globalInstantGame;
public static void load() {
try {
YamlDocument.create(
@@ -135,6 +140,11 @@ public class CFConfig {
lavaMinTime = config.getInt("mechanics.lava-fishing.min-wait-time", 100);
lavaMaxTime = config.getInt("mechanics.lava-fishing.max-wait-time", 600);
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);
@@ -144,6 +154,7 @@ public class CFConfig {
durabilityLore = config.getStringList("other-settings.custom-durability-format").stream().map(it -> "<!i>" + it).toList();
OffsetUtils.loadConfig(config.getConfigurationSection("other-settings.offset-characters"));
}
}

View File

@@ -1,6 +1,6 @@
# Developer: @Xiao-MoMi
# Wiki: https://mo-mi.gitbook.io/xiaomomi-plugins/
config-version: '27'
config-version: '28'
# Debug
debug: false
@@ -26,8 +26,10 @@ mechanics:
value:
- blacklist_world
# Configures how events related to bait, loot, and rods behave
# Configures global events for hook/bait/rod/loot
# which would help you reduce duplicated lines
global-events:
hook: {}
bait: {}
loot:
success:
@@ -92,7 +94,15 @@ mechanics:
y: 0
x: 0
z: 0
# Fishing bag is where players can store their baits, utils and rods (Fish optional)
# Global properties which would help you reduce duplicated lines
global-loot-property:
show-in-fishfinder: true
disable-stat: false
disable-game: false
instant-game: false
# Fishing bag is where players can store their baits, utils, hooks and rods (Loot optional)
fishing-bag:
# Enable
enable: true
@@ -105,6 +115,7 @@ mechanics:
- fishing_rod
# Lava fishing settings
# To modify vanilla fishing time, you should edit paper-world-defaults.yml where there's a section called fishing-time-range
lava-fishing:
# ticks
min-wait-time: 100
@@ -136,23 +147,23 @@ other-settings:
event-priority: NORMAL
# Save the data from cache to file periodically to minimize the data loss if server crashes
# set to -1 to disable
# -1 to disable
data-saving-interval: 600
# Lock player's data if a player is playing on a server that connected to database
# If you can ensure low database link latency and fast processing, you can consider disabling this option to save some performance
# If you can ensure low database link latency and fast processing, you can consider disabling this option to improve performance
lock-data: true
# Requires PlaceholderAPI to work
placeholder-register:
'{date}': '%server_time_yyyy-MM-dd-HH:mm:ss%'
# CustomFishing supports using items from other plugins
# CustomFishing supports using items/blocks from other plugins
# If items share the same id, they would inherit the effects
# Check the wiki for examples
item-detection-order:
- CustomFishing
- vanilla
block-detection-order:
- vanilla

View File

@@ -5,7 +5,8 @@ enable: true
limitation:
enable: true
earnings: 10000
# Support expression and placeholders
earnings: '10000'
# Market menu layout
layout: