mirror of
https://github.com/Verdurae/PlaceholderPlus.git
synced 2026-02-24 14:45:06 +08:00
更多配置
新增update类变量,原变量类型为normal类
This commit is contained in:
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'org.verdurae'
|
||||
version = '1.0-SNAPSHOT'
|
||||
version = '1.1-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -12,6 +12,6 @@ public class MathAPI {
|
||||
} else if (formula.startsWith("/")) {
|
||||
return v / Double.parseDouble(formula.substring(1));
|
||||
}
|
||||
return null;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import org.verdurae.placeholderplus.Object.PlayerData;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerAPI {
|
||||
public static HashMap<String, PlayerData> playerData = new HashMap<>();
|
||||
public static ConcurrentHashMap<String, PlayerData> playerData = new ConcurrentHashMap<>();
|
||||
|
||||
public static FileConfiguration getPlayerData(String playername) {
|
||||
if (playerData.containsKey(playername)) return playerData.get(playername).data;
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.verdurae.placeholderplus.API;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.verdurae.placeholderplus.API.Abstract.SubJsPlaceholder;
|
||||
@@ -98,4 +99,14 @@ public class PluginAPI {
|
||||
expansion.unregister();
|
||||
}
|
||||
}
|
||||
public static void loadAllPlayerData() {
|
||||
File[] files = PlaceholderPlus.dataFolder.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
if (!file.getName().endsWith(".yml")) continue;
|
||||
String name = file.getName().replace(".yml", "");
|
||||
YamlConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
new PlayerData(name, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,34 +8,43 @@ import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.API.PluginAPI;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlaceholderPlusCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (args.length < 1) {
|
||||
if (args.length < 2) {
|
||||
if (args.length == 1 && args[0].equals("reload")) {
|
||||
PlaceholderPlus.instance.reloadConfig();
|
||||
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
||||
PluginAPI.saveAllPlayerData();
|
||||
PlayerAPI.playerData = new ConcurrentHashMap<>();
|
||||
PluginAPI.loadOnlinePlayerData();
|
||||
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("/pp reload");
|
||||
} else {
|
||||
String holdername = args[2];
|
||||
String[] perms = holdername.split("_");
|
||||
switch (args[1]) {
|
||||
case "set":
|
||||
PlayerAPI.getPlayerData(args[0]).set(args[2], args[3]);
|
||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], args[3]);
|
||||
break;
|
||||
case "add":
|
||||
PlayerAPI.getPlayerData(args[0]).set(args[2], MathAPI.calculate(PlayerAPI.getPlayerData(args[0]).getDouble(args[2]), args[3]));
|
||||
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(args[2], null);
|
||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], null);
|
||||
break;
|
||||
case "reload":
|
||||
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
||||
PluginAPI.saveAllPlayerData();
|
||||
PlayerAPI.playerData = new HashMap<>();
|
||||
PluginAPI.loadOnlinePlayerData();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
12
src/main/java/org/verdurae/placeholderplus/Main.java
Normal file
12
src/main/java/org/verdurae/placeholderplus/Main.java
Normal file
@@ -0,0 +1,12 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.verdurae.placeholderplus.PlaceholderPlus.config;
|
||||
|
||||
public class PlayerData {
|
||||
public String name;
|
||||
@@ -21,10 +22,14 @@ public class PlayerData {
|
||||
}
|
||||
|
||||
public FileConfiguration defaultData(FileConfiguration data) {
|
||||
Map<String, Object> value = PlaceholderPlus.config.getValues(true);
|
||||
for (String key : value.keySet()) {
|
||||
if (key.startsWith("Placeholders.")) {
|
||||
if (!data.contains(key.replace("Placeholders.", ""))) data.set(key.replace("Placeholders.", ""), value.get(key));
|
||||
for (String key : config.getStringList("Placeholders.normal")) {
|
||||
if (!data.contains("normal." + key)) {
|
||||
data.set("normal." + key, config.get("Placeholders.normal." + key));
|
||||
}
|
||||
}
|
||||
for (String key : config.getStringList("Placeholders.update")) {
|
||||
if (!data.contains("update." + key)) {
|
||||
data.set("update." + key, config.get("Placeholders.update." + key + ".max"));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
||||
@@ -2,8 +2,10 @@ package org.verdurae.placeholderplus;
|
||||
|
||||
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.API.PlayerAPI;
|
||||
import org.verdurae.placeholderplus.API.PluginAPI;
|
||||
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
||||
@@ -20,7 +22,9 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
public static boolean jsSupport = false;
|
||||
public static ArrayList<PlaceholderExpansion> expansions = new ArrayList<>();
|
||||
public static File dataFolder;
|
||||
public static boolean autosave = true;
|
||||
public static boolean autosave;
|
||||
public static BukkitTask timer;
|
||||
public static int timeCount = 0;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@@ -39,6 +43,7 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
}
|
||||
saveDefaultConfig();
|
||||
config = getConfig();
|
||||
autosave = config.getBoolean("Task.SaveTask.enable");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,22 +52,9 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
dataFolder = new File(getDataFolder(), "PlayerData");
|
||||
dataFolder.mkdirs();
|
||||
PluginAPI.loadAllHolder();
|
||||
PluginAPI.loadOnlinePlayerData();
|
||||
PluginAPI.loadAllPlayerData();
|
||||
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
while (isEnabled() && autosave) {
|
||||
try {
|
||||
Thread.sleep(300000);
|
||||
logger.info("正在自动保存数据");
|
||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||
playerData.save();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
autosave = true;
|
||||
});
|
||||
newTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,4 +63,30 @@ public final class PlaceholderPlus extends JavaPlugin {
|
||||
PluginAPI.saveAllPlayerData();
|
||||
PluginAPI.unloadAllHolder();
|
||||
}
|
||||
|
||||
public static void newTimer() {
|
||||
timer = Bukkit.getScheduler().runTaskTimerAsynchronously(PlaceholderPlus.instance, () -> {
|
||||
timeCount++;
|
||||
System.out.println(timeCount);
|
||||
if (PlaceholderPlus.config.getBoolean("Task.SaveTask.enable") && timeCount % PlaceholderPlus.config.getInt("Task.SaveTask.period") == 0) {
|
||||
logger.info("正在自动保存数据");
|
||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||
playerData.save();
|
||||
}
|
||||
}
|
||||
ConfigurationSection updates = PlaceholderPlus.config.getConfigurationSection("Placeholders.update");
|
||||
for (String update : updates.getKeys(false)) {
|
||||
System.out.println(update);
|
||||
System.out.println(PlaceholderPlus.config.getInt("Placeholders.update." + update + ".period"));
|
||||
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")) {
|
||||
FileConfiguration data = playerData.data;
|
||||
data.set("update." + update, data.getInt("update." + update) + PlaceholderPlus.config.getInt("Placeholders.update." + update + ".amount"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,16 @@ import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||
|
||||
public class ThisPlaceholder extends PlaceholderExpansion {
|
||||
@Override
|
||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
String a = PlayerAPI.getPlayerData(player.getName()).getString(params);
|
||||
return (a == null) ? PlaceholderPlus.config.getString("Placeholders." + params) : a;
|
||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String param) {
|
||||
String[] params = param.split("_");
|
||||
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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,8 +4,19 @@ JsImportPacket:
|
||||
"PAPI": "me.clip.placeholderapi.PlaceholderAPI"
|
||||
|
||||
Placeholders:
|
||||
"test": "这是一个变量"
|
||||
"test1": "这是另一个变量"
|
||||
"test2": "最好不要留空"
|
||||
"test3": "1"
|
||||
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
||||
normal:
|
||||
"test": "这是一个变量"
|
||||
"test1": "这是另一个变量"
|
||||
"test2": "最好不要留空"
|
||||
"test3": "1"
|
||||
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
||||
update:
|
||||
update:
|
||||
max: 160
|
||||
period: 1
|
||||
amount: 1
|
||||
|
||||
Task:
|
||||
SaveTask:
|
||||
enable: true
|
||||
period: 600
|
||||
Reference in New Issue
Block a user