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

improve api

This commit is contained in:
XiaoMoMi
2023-12-26 16:35:43 +08:00
parent db722484af
commit 4c1eeda61f
7 changed files with 50 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
implementation("de.tr7zw:item-nbt-api:2.12.1")
implementation("de.tr7zw:item-nbt-api:2.12.2")
}
tasks {

View File

@@ -81,4 +81,20 @@ public interface PlaceholderManager {
* @return The list of text strings with placeholders replaced by their values.
*/
List<String> parse(@Nullable OfflinePlayer player, List<String> list, Map<String, String> replacements);
/**
* Get an expression's value
* @param player player
* @param formula formula
* @param vars vars
* @return result
*/
double getExpressionValue(Player player, String formula, Map<String, String> vars);
/**
* Get an expression's value
* @param formula formula
* @return result
*/
double getExpressionValue(String formula);
}

View File

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

View File

@@ -19,6 +19,8 @@ package net.momirealms.customfishing.compatibility.papi;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.manager.PlaceholderManager;
import net.momirealms.customfishing.util.ConfigUtils;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
@@ -196,4 +198,14 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
public boolean hasPapi() {
return hasPapi;
}
@Override
public double getExpressionValue(Player player, String formula, Map<String, String> vars) {
return ConfigUtils.getExpressionValue(player, formula, vars);
}
@Override
public double getExpressionValue(String formula) {
return new ExpressionBuilder(formula).build().evaluate();
}
}

View File

@@ -703,8 +703,10 @@ public class ActionManagerImpl implements ActionManager {
registerAction("delay", (args, chance) -> {
List<Action> actions = new ArrayList<>();
int delay;
boolean async;
if (args instanceof ConfigurationSection section) {
delay = section.getInt("delay", 1);
async = section.getBoolean("async", false);
ConfigurationSection actionSection = section.getConfigurationSection("actions");
if (actionSection != null) {
for (Map.Entry<String, Object> entry : actionSection.getValues(false).entrySet()) {
@@ -715,14 +717,23 @@ public class ActionManagerImpl implements ActionManager {
}
} else {
delay = 1;
async = false;
}
return condition -> {
if (Math.random() > chance) return;
plugin.getScheduler().runTaskSyncLater(() -> {
for (Action action : actions) {
action.trigger(condition);
}
}, condition.getLocation(), delay * 50L, TimeUnit.MILLISECONDS);
if (async) {
plugin.getScheduler().runTaskSyncLater(() -> {
for (Action action : actions) {
action.trigger(condition);
}
}, condition.getLocation(), delay * 50L, TimeUnit.MILLISECONDS);
} else {
plugin.getScheduler().runTaskSyncLater(() -> {
for (Action action : actions) {
action.trigger(condition);
}
}, condition.getLocation(), delay * 50L, TimeUnit.MILLISECONDS);
}
};
});
}

View File

@@ -706,9 +706,11 @@ public class ItemManagerImpl implements ItemManager, Listener {
editors.put("price", (player, nbtItem, placeholders) -> {
if (base != 0) {
placeholders.put("{base}", String.format("%.2f", base));
placeholders.put("{BASE}", String.valueOf(base));
}
if (bonus != 0) {
placeholders.put("{bonus}", String.format("%.2f", bonus));
placeholders.put("{BONUS}", String.valueOf(bonus));
}
float size = Float.parseFloat(placeholders.getOrDefault("{SIZE}", "0"));
double price = CustomFishingPlugin.get().getMarketManager().getFishPrice(

View File

@@ -144,8 +144,7 @@ public class NBTUtils {
switch (data.substring(0,3)) {
case "-P:" -> data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
case "-E:" -> {
data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
double value = ConfigUtils.getExpressionValue(player, data, new HashMap<>());
double value = ConfigUtils.getExpressionValue(player, data.substring(3), placeholders);
if (value % 1 == 0) {
data = Long.toString((long) value);
} else {