mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-26 18:39:11 +00:00
improve api
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user