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:
@@ -1,7 +1,7 @@
|
|||||||
dependencies {
|
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")
|
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 {
|
tasks {
|
||||||
|
|||||||
@@ -81,4 +81,20 @@ public interface PlaceholderManager {
|
|||||||
* @return The list of text strings with placeholders replaced by their values.
|
* @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);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
|
||||||
version = "2.0.5"
|
version = "2.0.6"
|
||||||
|
|
||||||
apply<JavaPlugin>()
|
apply<JavaPlugin>()
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package net.momirealms.customfishing.compatibility.papi;
|
|||||||
|
|
||||||
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
||||||
import net.momirealms.customfishing.api.manager.PlaceholderManager;
|
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.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@@ -196,4 +198,14 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
public boolean hasPapi() {
|
public boolean hasPapi() {
|
||||||
return 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) -> {
|
registerAction("delay", (args, chance) -> {
|
||||||
List<Action> actions = new ArrayList<>();
|
List<Action> actions = new ArrayList<>();
|
||||||
int delay;
|
int delay;
|
||||||
|
boolean async;
|
||||||
if (args instanceof ConfigurationSection section) {
|
if (args instanceof ConfigurationSection section) {
|
||||||
delay = section.getInt("delay", 1);
|
delay = section.getInt("delay", 1);
|
||||||
|
async = section.getBoolean("async", false);
|
||||||
ConfigurationSection actionSection = section.getConfigurationSection("actions");
|
ConfigurationSection actionSection = section.getConfigurationSection("actions");
|
||||||
if (actionSection != null) {
|
if (actionSection != null) {
|
||||||
for (Map.Entry<String, Object> entry : actionSection.getValues(false).entrySet()) {
|
for (Map.Entry<String, Object> entry : actionSection.getValues(false).entrySet()) {
|
||||||
@@ -715,14 +717,23 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delay = 1;
|
delay = 1;
|
||||||
|
async = false;
|
||||||
}
|
}
|
||||||
return condition -> {
|
return condition -> {
|
||||||
if (Math.random() > chance) return;
|
if (Math.random() > chance) return;
|
||||||
|
if (async) {
|
||||||
plugin.getScheduler().runTaskSyncLater(() -> {
|
plugin.getScheduler().runTaskSyncLater(() -> {
|
||||||
for (Action action : actions) {
|
for (Action action : actions) {
|
||||||
action.trigger(condition);
|
action.trigger(condition);
|
||||||
}
|
}
|
||||||
}, condition.getLocation(), delay * 50L, TimeUnit.MILLISECONDS);
|
}, 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) -> {
|
editors.put("price", (player, nbtItem, placeholders) -> {
|
||||||
if (base != 0) {
|
if (base != 0) {
|
||||||
placeholders.put("{base}", String.format("%.2f", base));
|
placeholders.put("{base}", String.format("%.2f", base));
|
||||||
|
placeholders.put("{BASE}", String.valueOf(base));
|
||||||
}
|
}
|
||||||
if (bonus != 0) {
|
if (bonus != 0) {
|
||||||
placeholders.put("{bonus}", String.format("%.2f", bonus));
|
placeholders.put("{bonus}", String.format("%.2f", bonus));
|
||||||
|
placeholders.put("{BONUS}", String.valueOf(bonus));
|
||||||
}
|
}
|
||||||
float size = Float.parseFloat(placeholders.getOrDefault("{SIZE}", "0"));
|
float size = Float.parseFloat(placeholders.getOrDefault("{SIZE}", "0"));
|
||||||
double price = CustomFishingPlugin.get().getMarketManager().getFishPrice(
|
double price = CustomFishingPlugin.get().getMarketManager().getFishPrice(
|
||||||
|
|||||||
@@ -144,8 +144,7 @@ public class NBTUtils {
|
|||||||
switch (data.substring(0,3)) {
|
switch (data.substring(0,3)) {
|
||||||
case "-P:" -> data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
|
case "-P:" -> data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
|
||||||
case "-E:" -> {
|
case "-E:" -> {
|
||||||
data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
|
double value = ConfigUtils.getExpressionValue(player, data.substring(3), placeholders);
|
||||||
double value = ConfigUtils.getExpressionValue(player, data, new HashMap<>());
|
|
||||||
if (value % 1 == 0) {
|
if (value % 1 == 0) {
|
||||||
data = Long.toString((long) value);
|
data = Long.toString((long) value);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user