mirror of
https://github.com/Verdurae/PlaceholderPlus.git
synced 2026-11-25 06:14:31 +08:00
1.2.2优化更新
重构util类名 添加指令补全 增加注释
This commit is contained in:
1 parent
4d2919cfb3
commit
44e553ea2a
14 files changed
+347
-118
No files matched your search
+2
-1
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'org.verdurae'
|
||||
version = '1.1.2-SNAPSHOT'
|
||||
version = '1.2.2-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -21,6 +21,7 @@ repositories {
|
||||
dependencies {
|
||||
compileOnly "org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT"
|
||||
implementation 'me.clip:placeholderapi:2.+'
|
||||
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
def targetJavaVersion = 8
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.5-bin.zip
|
||||
@@ -2,8 +2,6 @@ package org.verdurae.placeholderplus.API.Abstract;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
|
||||
import javax.script.Invocable;
|
||||
@@ -11,10 +9,10 @@ import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
public abstract class SubJsPlaceholder extends PlaceholderExpansion {
|
||||
public abstract @NotNull ScriptEngine getEngine();
|
||||
public abstract ScriptEngine getEngine();
|
||||
|
||||
@Override
|
||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
Invocable inv = (Invocable) getEngine();
|
||||
try {
|
||||
return inv.invokeFunction("onRequest", player, params).toString();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.verdurae.placeholderplus.API;
|
||||
|
||||
import org.verdurae.placeholderplus.Util.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||
|
||||
/**
|
||||
* @author Kaminy
|
||||
@@ -17,7 +18,10 @@ public class PlaceholderPlusApi {
|
||||
*/
|
||||
public static String getPlaceholder(String player, String placeholder) {
|
||||
String[] perms = placeholder.split("_");
|
||||
return PlayerAPI.getPlayerData(player).getString(perms[0] + "." + perms[1]);
|
||||
if (perms.length == 1) perms = new String[]{"normal", perms[0]};
|
||||
return PlayerUtil.getPlayerData(player).getString(perms[0] + "." + perms[1]) == null ?
|
||||
PlaceholderPlus.config.getString("Placeholders." + perms[0] + "." + perms[1]) :
|
||||
PlayerUtil.getPlayerData(player).getString(perms[0] + "." + perms[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +33,6 @@ public class PlaceholderPlusApi {
|
||||
*/
|
||||
public static void setPlaceholder(String player, String placeholder, String value) {
|
||||
String[] perms = placeholder.split("_");
|
||||
PlayerAPI.getPlayerData(player).set(perms[0] + "." + perms[1], value);
|
||||
PlayerUtil.getPlayerData(player).set(perms[0] + "." + perms[1], value);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,23 @@
|
||||
package org.verdurae.placeholderplus.Command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.verdurae.placeholderplus.Util.MathAPI;
|
||||
import org.verdurae.placeholderplus.Util.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.Util.PluginAPI;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
import org.verdurae.placeholderplus.ThisPlaceholder;
|
||||
import org.verdurae.placeholderplus.Util.MathUtil;
|
||||
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||
import org.verdurae.placeholderplus.Util.PluginUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlaceholderPlusCommand implements CommandExecutor {
|
||||
public class PlaceholderPlusCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
@@ -18,43 +25,149 @@ public class PlaceholderPlusCommand implements CommandExecutor {
|
||||
if (args.length == 1 && args[0].equals("reload")) {
|
||||
PlaceholderPlus.instance.reloadConfig();
|
||||
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
||||
PluginAPI.saveAllPlayerData();
|
||||
PlayerAPI.playerData = new ConcurrentHashMap<>();
|
||||
PluginAPI.loadOnlinePlayerData();
|
||||
PluginUtil.saveAllPlayerData();
|
||||
PluginUtil.saveServerData();
|
||||
PlayerUtil.playerData = new ConcurrentHashMap<>();
|
||||
PluginUtil.serverData = new YamlConfiguration();
|
||||
PluginUtil.loadAllPlayerData();
|
||||
PluginUtil.loadServerData();
|
||||
PlaceholderPlus.timer.cancel();
|
||||
PlaceholderPlus.newTimer();
|
||||
sender.sendMessage("已重载");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("PlaceholderPlus:");
|
||||
sender.sendMessage("/pp 玩家名 set 变量名 数值");
|
||||
sender.sendMessage("/pp 玩家名 add 变量名 数值");
|
||||
sender.sendMessage("/pp 玩家名 remove 变量名");
|
||||
sender.sendMessage("PlaceholderPlus:<>是必填 []是选填");
|
||||
sender.sendMessage("/pp 玩家名 set <变量名> <数值> [参数...]");
|
||||
sender.sendMessage("/pp 玩家名 add <变量名> <数值> [参数...]");
|
||||
sender.sendMessage("/pp 玩家名 remove <变量名> [参数...]");
|
||||
sender.sendMessage("/pp reload");
|
||||
return true;
|
||||
} else {
|
||||
String holdername = args[2];
|
||||
String[] perms = holdername.split("_");
|
||||
if (perms.length < 1) {
|
||||
sender.sendMessage("请输入正确的变量名");
|
||||
return false;
|
||||
try {
|
||||
|
||||
String holdername = args[2];
|
||||
String[] perms = holdername.split("_");
|
||||
if (perms.length < 1) {
|
||||
sender.sendMessage("请输入正确的变量名");
|
||||
return false;
|
||||
}
|
||||
if (!ThisPlaceholder.placeholderTypes.contains(perms[0])) {
|
||||
perms = new String[]{"normal", perms[0]};
|
||||
}
|
||||
boolean message = PlaceholderPlus.config.getBoolean("Setting.message", true);
|
||||
for (String arg : args) {
|
||||
if (arg.startsWith("m:")) {
|
||||
message = Boolean.parseBoolean(arg.substring(2));
|
||||
}
|
||||
}
|
||||
if (perms[0].equals("server")) {
|
||||
switch (args[1]) {
|
||||
case "set":
|
||||
PluginUtil.serverData.set(perms[1], args[3]);
|
||||
if (message) {
|
||||
sender.sendMessage("将服务器的" + holdername + "变量设置为" + args[3]);
|
||||
}
|
||||
break;
|
||||
case "add":
|
||||
Number number = MathUtil.calculate(PlayerUtil.getPlayerData(args[0]).getDouble(perms[0] + "." + perms[1]), args[3]);
|
||||
PluginUtil.serverData.set(perms[1], number);
|
||||
if (message) {
|
||||
sender.sendMessage("将服务器的" + holdername + "变量设置为" + number);
|
||||
}
|
||||
break;
|
||||
case "remove":
|
||||
PluginUtil.serverData.set(perms[1], null);
|
||||
if (message) {
|
||||
sender.sendMessage("将服务器的" + holdername + "变量移除(解析将会获得默认值)");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
switch (args[1]) {
|
||||
case "set":
|
||||
PlayerUtil.getPlayerData(args[0]).set(perms[0] + "." + perms[1], args[3]);
|
||||
if (message) {
|
||||
sender.sendMessage("将" + args[0] + "的" + holdername + "变量设置为" + args[3]);
|
||||
}
|
||||
break;
|
||||
case "add":
|
||||
Number number = MathUtil.calculate(PlayerUtil.getPlayerData(args[0]).getDouble(perms[0] + "." + perms[1]), args[3]);
|
||||
PlayerUtil.getPlayerData(args[0]).set(perms[0] + "." + perms[1], number);
|
||||
if (message) {
|
||||
sender.sendMessage("将" + args[0] + "的" + holdername + "变量设置为" + number);
|
||||
}
|
||||
break;
|
||||
case "remove":
|
||||
PlayerUtil.getPlayerData(args[0]).set(perms[0] + "." + perms[1], null);
|
||||
if (message) {
|
||||
sender.sendMessage("将" + args[0] + "的" + holdername + "变量记录移除(解析将会获得默认值)");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
|
||||
sender.sendMessage("参数不足");
|
||||
}
|
||||
if (perms.length < 2) {
|
||||
perms = new String[]{"normal", perms[0]};
|
||||
}
|
||||
switch (args[1]) {
|
||||
case "set":
|
||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], args[3]);
|
||||
break;
|
||||
case "add":
|
||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], MathAPI.calculate(PlayerAPI.getPlayerData(args[0]).getDouble(perms[0] + "." + perms[1]), args[3]));
|
||||
break;
|
||||
case "remove":
|
||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], null);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
List<String> list1 = new ArrayList<>();
|
||||
|
||||
if (args.length == 1) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> list1.add(player.getName()));
|
||||
} else if (args.length == 2) {
|
||||
list1.add("set");
|
||||
list1.add("add");
|
||||
list1.add("remove");
|
||||
|
||||
} else if (args.length == 3) {
|
||||
String arg = args[2];
|
||||
if (arg.startsWith("normal_")) {
|
||||
FileConfiguration playerData = PlayerUtil.getPlayerData(args[0]);
|
||||
if (playerData.getConfigurationSection("normal") != null) {
|
||||
for (String key : playerData.getConfigurationSection("normal").getKeys(false)) {
|
||||
list1.add("normal_" + key);
|
||||
}
|
||||
} else {
|
||||
list1.add("变量名");
|
||||
}
|
||||
} else if (arg.startsWith("update_")) {
|
||||
FileConfiguration playerData = PlayerUtil.getPlayerData(args[0]);
|
||||
if (playerData.getConfigurationSection("update") != null) {
|
||||
for (String key : playerData.getConfigurationSection("update").getKeys(false)) {
|
||||
list1.add("update_" + key);
|
||||
}
|
||||
} else {
|
||||
list1.add("变量名");
|
||||
}
|
||||
} else if (arg.startsWith("server_")) {
|
||||
FileConfiguration serverData = PluginUtil.serverData;
|
||||
if (serverData.getKeys(false).isEmpty()) {
|
||||
list1.add("变量名");
|
||||
} else {
|
||||
for (String key : serverData.getKeys(false)) {
|
||||
list1.add("server_" + key);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list1.add("normal_");
|
||||
list1.add("update_");
|
||||
list1.add("server_");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
for (String param : list1) {
|
||||
if (param.startsWith(args[args.length - 1])) {
|
||||
list.add(param);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.verdurae.placeholderplus;
|
||||
|
||||
/**
|
||||
* @author Kaminy
|
||||
* @date 2025/6/10 17:03
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(60%1);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package org.verdurae.placeholderplus.Object;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.verdurae.placeholderplus.Util.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -18,7 +18,7 @@ public class PlayerData {
|
||||
if (data == null) data = new YamlConfiguration();
|
||||
this.data = defaultData(data);
|
||||
save();
|
||||
PlayerAPI.playerData.put(name, this);
|
||||
PlayerUtil.playerData.put(name, this);
|
||||
}
|
||||
|
||||
public FileConfiguration defaultData(FileConfiguration data) {
|
||||
@@ -37,7 +37,7 @@ public class PlayerData {
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
data.save(PlaceholderPlus.dataFolder + "/" + name + ".yml");
|
||||
data.save(PlaceholderPlus.playerDataFolder + "/" + name + ".yml");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package org.verdurae.placeholderplus;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.verdurae.placeholderplus.Util.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.Util.PluginAPI;
|
||||
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
||||
import org.verdurae.placeholderplus.Object.PlayerData;
|
||||
import org.verdurae.placeholderplus.Util.MathUtil;
|
||||
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||
import org.verdurae.placeholderplus.Util.PluginUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -29,6 +31,8 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
public static boolean jsSupport = false;
|
||||
public static ArrayList<PlaceholderExpansion> expansions = new ArrayList<>();
|
||||
public static File dataFolder;
|
||||
public static File serverDataFolder;
|
||||
public static File playerDataFolder;
|
||||
public static boolean autosave;
|
||||
public static BukkitTask timer;
|
||||
public static int timeCount = 0;
|
||||
@@ -61,19 +65,25 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
logger.info("开始加载");
|
||||
dataFolder = new File(getDataFolder(), "PlayerData");
|
||||
dataFolder.mkdirs();
|
||||
PluginAPI.loadAllHolder();
|
||||
PluginAPI.loadAllPlayerData();
|
||||
dataFolder = getDataFolder();
|
||||
serverDataFolder = new File(dataFolder, "ServerData");
|
||||
playerDataFolder = new File(dataFolder, "PlayerData");
|
||||
serverDataFolder.mkdirs();
|
||||
playerDataFolder.mkdirs();
|
||||
PluginUtil.loadAllHolder();
|
||||
PluginUtil.loadAllPlayerData();
|
||||
PluginUtil.loadServerData();
|
||||
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
||||
getCommand("pp").setTabCompleter(new PlaceholderPlusCommand());
|
||||
newTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
logger.info("插件卸载");
|
||||
PluginAPI.saveAllPlayerData();
|
||||
PluginAPI.unloadAllHolder();
|
||||
PluginUtil.saveAllPlayerData();
|
||||
PluginUtil.saveServerData();
|
||||
PluginUtil.unloadAllHolder();
|
||||
}
|
||||
|
||||
public static void newTimer() {
|
||||
@@ -81,17 +91,27 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
timeCount++;
|
||||
if (PlaceholderPlus.config.getBoolean("Task.SaveTask.enable") && timeCount % PlaceholderPlus.config.getInt("Task.SaveTask.period") == 0) {
|
||||
logger.info("正在自动保存数据");
|
||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||
for (PlayerData playerData : PlayerUtil.playerData.values()) {
|
||||
playerData.save();
|
||||
}
|
||||
}
|
||||
ConfigurationSection updates = PlaceholderPlus.config.getConfigurationSection("Placeholders.update");
|
||||
for (String update : updates.getKeys(false)) {
|
||||
if (timeCount % PlaceholderPlus.config.getInt("Placeholders.update." + update + ".period") == 0) {
|
||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||
if (playerData.data.getInt("update." + update) < PlaceholderPlus.config.getInt("Placeholders.update." + update + ".max")) {
|
||||
for (PlayerData playerData : PlayerUtil.playerData.values()) {
|
||||
double max = 0;
|
||||
if (config.isDouble("Placeholders.update." + update + ".max")) {
|
||||
max = config.getDouble("Placeholders.update." + update + ".max");
|
||||
} else {
|
||||
try {
|
||||
max = Double.parseDouble(PlaceholderAPI.setPlaceholders(Bukkit.getOfflinePlayer(playerData.name), config.getString("Placeholders.update." + update + ".max")));
|
||||
} catch (NumberFormatException e) {
|
||||
max = MathUtil.calculate(PlaceholderAPI.setPlaceholders(Bukkit.getOfflinePlayer(playerData.name), config.getString("Placeholders.update." + update + ".max"))).doubleValue();
|
||||
}
|
||||
}
|
||||
if (playerData.data.getInt("update." + update) < max) {
|
||||
FileConfiguration data = playerData.data;
|
||||
data.set("update." + update, data.getInt("update." + update) + PlaceholderPlus.config.getInt("Placeholders.update." + update + ".amount"));
|
||||
data.set("update." + update, data.getDouble("update." + update) + PlaceholderPlus.config.getDouble("Placeholders.update." + update + ".amount"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,39 +2,74 @@ package org.verdurae.placeholderplus;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.verdurae.placeholderplus.Util.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||
import org.verdurae.placeholderplus.Util.PluginUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ThisPlaceholder extends PlaceholderExpansion {
|
||||
public final static List<String> placeholderTypes = Arrays.asList("normal", "update", "server");
|
||||
|
||||
@Override
|
||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String param) {
|
||||
public String onRequest(OfflinePlayer player, String param) {
|
||||
String[] params = param.split("_");
|
||||
if (params.length < 2) {
|
||||
String defaultValue = "未定义的变量";
|
||||
for (String arg : params) {
|
||||
if (arg.startsWith("d:")) {
|
||||
defaultValue = arg.replaceFirst("d:", "");
|
||||
}
|
||||
}
|
||||
if (!placeholderTypes.contains(params[0])) {
|
||||
params = new String[]{"normal", params[0]};
|
||||
}
|
||||
if (params[0].equals("normal")) {
|
||||
String a = PlayerAPI.getPlayerData(player.getName()).getString("normal." + params[1]);
|
||||
return (a == null) ? PlaceholderPlus.config.getString("Placeholders.normal." + params[1]) : a;
|
||||
} else if (params[0].equals("update")) {
|
||||
String a = PlayerAPI.getPlayerData(player.getName()).getString("update." + params[1]);
|
||||
return (a == null) ? PlaceholderPlus.config.getString("Placeholders.update." + params[1] + ".max") : a;
|
||||
switch (params[0]) {
|
||||
case "normal": {
|
||||
String a = PlayerUtil.getPlayerData(player.getName()).getString("normal." + params[1]);
|
||||
if (a == null) {
|
||||
a = PlaceholderPlus.config.getString("Placeholders.normal." + params[1]);
|
||||
if (a == null) {
|
||||
a = defaultValue;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
case "update": {
|
||||
String a = PlayerUtil.getPlayerData(player.getName()).getString("update." + params[1]);
|
||||
if (a == null) {
|
||||
a = PlaceholderPlus.config.getString("Placeholders.update." + params[1] + ".max");
|
||||
if (a == null) {
|
||||
a = defaultValue;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
case "server": {
|
||||
String a = PluginUtil.serverData.getString(params[1]);
|
||||
if (a == null) {
|
||||
a = PlaceholderPlus.config.getString("Placeholders.server." + params[1]);
|
||||
if (a == null) {
|
||||
a = defaultValue;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
public String getIdentifier() {
|
||||
return "pp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
public String getAuthor() {
|
||||
return "Kaminy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
public String getVersion() {
|
||||
return PlaceholderPlus.instance.getDescription().getVersion();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.verdurae.placeholderplus.Util;
|
||||
|
||||
public class MathAPI {
|
||||
public static <T extends Number> Number calculate(T number, String formula) {
|
||||
double v = number.doubleValue();
|
||||
if (formula.startsWith("+")) {
|
||||
return v + Double.parseDouble(formula.substring(1));
|
||||
} else if (formula.startsWith("-")) {
|
||||
return v - Double.parseDouble(formula.substring(1));
|
||||
} else if (formula.startsWith("*")) {
|
||||
return v * Double.parseDouble(formula.substring(1));
|
||||
} else if (formula.startsWith("/")) {
|
||||
return v / Double.parseDouble(formula.substring(1));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.verdurae.placeholderplus.Util;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
public class MathUtil {
|
||||
public static <T extends Number> Number calculate(String formula) {
|
||||
if (formula == null || formula.isEmpty()) {
|
||||
throw new IllegalArgumentException("空算式");
|
||||
}
|
||||
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
ScriptEngine engine = manager.getEngineByName("JavaScript");
|
||||
|
||||
try {
|
||||
formula = formula.replaceAll("\\s+", "");
|
||||
Object result = engine.eval(formula);
|
||||
if (result instanceof Number) {
|
||||
return (Number) result;
|
||||
} else {
|
||||
throw new IllegalArgumentException("算式结果不合法 反馈报错: " + result);
|
||||
}
|
||||
} catch (ScriptException e) {
|
||||
throw new IllegalArgumentException("无效算式 反馈报错: " + formula, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T extends Number> Number calculate(T number, String formula) {
|
||||
double v = number.doubleValue();
|
||||
if (formula.startsWith("+")) {
|
||||
return v + Double.parseDouble(formula.substring(1));
|
||||
} else if (formula.startsWith("-")) {
|
||||
return v - Double.parseDouble(formula.substring(1));
|
||||
} else if (formula.startsWith("*")) {
|
||||
return v * Double.parseDouble(formula.substring(1));
|
||||
} else if (formula.startsWith("/")) {
|
||||
return v / Double.parseDouble(formula.substring(1));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -9,12 +9,12 @@ import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerAPI {
|
||||
public class PlayerUtil {
|
||||
public static ConcurrentHashMap<String, PlayerData> playerData = new ConcurrentHashMap<>();
|
||||
|
||||
public static FileConfiguration getPlayerData(String playername) {
|
||||
if (playerData.containsKey(playername)) return playerData.get(playername).data;
|
||||
YamlConfiguration data = YamlConfiguration.loadConfiguration(new File(PlaceholderPlus.dataFolder, playername + ".yml"));
|
||||
YamlConfiguration data = YamlConfiguration.loadConfiguration(new File(PlaceholderPlus.playerDataFolder, playername + ".yml"));
|
||||
new PlayerData(playername, data);
|
||||
return data;
|
||||
}
|
||||
+33
-10
@@ -3,9 +3,9 @@ package org.verdurae.placeholderplus.Util;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.verdurae.placeholderplus.API.Abstract.SubJsPlaceholder;
|
||||
import org.verdurae.placeholderplus.Object.PlayerData;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
@@ -21,22 +21,44 @@ import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PluginAPI {
|
||||
public class PluginUtil {
|
||||
public static FileConfiguration serverData = new YamlConfiguration();
|
||||
|
||||
public static void saveServerData() {
|
||||
try {
|
||||
serverData.save(new File(PlaceholderPlus.serverDataFolder, "serverholder.yml"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadServerData() {
|
||||
File file = new File(PlaceholderPlus.serverDataFolder, "serverholder.yml");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
serverData.save(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
serverData = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static void saveAllPlayerData() {
|
||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||
for (PlayerData playerData : PlayerUtil.playerData.values()) {
|
||||
playerData.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadOnlinePlayerData() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
PlayerAPI.getPlayerData(player);
|
||||
PlayerUtil.getPlayerData(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadAllHolder() {
|
||||
PlaceholderPlus.expansions.add(new ThisPlaceholder());
|
||||
File JsFolder = new File(PlaceholderPlus.instance.getDataFolder(), "Js");
|
||||
File JsFolder = new File(PlaceholderPlus.dataFolder, "Js");
|
||||
JsFolder.mkdirs();
|
||||
for (File file : Objects.requireNonNull(JsFolder.listFiles())) {
|
||||
if (file.getName().endsWith(".js")) {
|
||||
@@ -63,22 +85,22 @@ public class PluginAPI {
|
||||
String version = (String) engine.get("version");
|
||||
PlaceholderPlus.expansions.add(new SubJsPlaceholder() {
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ScriptEngine getEngine() {
|
||||
public ScriptEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
});
|
||||
@@ -99,8 +121,9 @@ public class PluginAPI {
|
||||
expansion.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadAllPlayerData() {
|
||||
File[] files = PlaceholderPlus.dataFolder.listFiles();
|
||||
File[] files = PlaceholderPlus.playerDataFolder.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
if (!file.getName().endsWith(".yml")) continue;
|
||||
@@ -1,22 +1,43 @@
|
||||
Setting:
|
||||
# 指令是否发送反馈消息
|
||||
# 也可以在指令里添加参数m=false或m=true,指令参数优先级高于全服设置
|
||||
message: true
|
||||
|
||||
# 要给js变量导的包,新手不建议使用
|
||||
JsImportPacket:
|
||||
"Bukkit": "org.bukkit.Bukkit"
|
||||
"Arrays": "java.util.Arrays"
|
||||
"PAPI": "me.clip.placeholderapi.PlaceholderAPI"
|
||||
|
||||
# 自定义变量
|
||||
# 最终解析的变量是%pp_变量类型_变量名%
|
||||
Placeholders:
|
||||
# 常规变量
|
||||
# 不具备对应变量玩家解析常规变量时会获得默认值(就是配置中写的值)
|
||||
# 当通过指令或其他方式设置之后就会获得玩家自己的储存值
|
||||
normal:
|
||||
"test": "这是一个变量"
|
||||
"test": "这是一个变量" # 比如你想返回这个,就是%pp_normal_test% 或者 %pp_test% normal类型解析变量时可以省略normal
|
||||
"test1": "这是另一个变量"
|
||||
"test2": "最好不要留空"
|
||||
"test3": "1"
|
||||
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
||||
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有负号和小数点"
|
||||
# 脉冲变量
|
||||
# 脉冲变量会自动变化 可以增加也可以减少 不会超过变量上限(无下限限制)
|
||||
# 可以用来做体力之类的功能
|
||||
update:
|
||||
update:
|
||||
max: 160
|
||||
period: 1
|
||||
amount: 1
|
||||
update: # %pp_update_update%
|
||||
max: 160 # 自增上限,可以解析papi变量以将其他papi变量作为仅对该玩家该脉冲变量生效的上限,如%player_health%,也支持四则运算,比如10+%player_health%
|
||||
period: 1 # 变化周期,秒
|
||||
amount: 1 # 变化量
|
||||
# 全服变量
|
||||
# 不会储存到玩家而是储存到服务器缓存,关服时会保存到文件,缓存里没有对应变量值的时候会获得默认值
|
||||
# 所有玩家解析全服变量的结果都是相同的
|
||||
# 可用于设置全服的某种功能门槛,如击败某个全服boss后解锁新的玩法之类
|
||||
server:
|
||||
server1: "false"
|
||||
|
||||
Task:
|
||||
# 自动保存
|
||||
SaveTask:
|
||||
enable: true
|
||||
period: 600
|
||||
Reference in new issue
Block a user