mirror of
https://github.com/Verdurae/PlaceholderPlus.git
synced 2026-11-25 14:24:32 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2dd1f8245 | ||
|
|
e5e24faf9b |
No files matched your search
+2
-2
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'org.verdurae'
|
group = 'org.verdurae'
|
||||||
version = '1.0-SNAPSHOT'
|
version = '1.1-SNAPSHOT'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -20,7 +20,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"
|
compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"
|
||||||
implementation 'me.clip:placeholderapi:2.11.6'
|
implementation 'me.clip:placeholderapi:2.+'
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 8
|
def targetJavaVersion = 8
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ public class MathAPI {
|
|||||||
} else if (formula.startsWith("/")) {
|
} else if (formula.startsWith("/")) {
|
||||||
return v / Double.parseDouble(formula.substring(1));
|
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 org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PlayerAPI {
|
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) {
|
public static FileConfiguration getPlayerData(String playername) {
|
||||||
if (playerData.containsKey(playername)) return playerData.get(playername).data;
|
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 jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.verdurae.placeholderplus.API.Abstract.SubJsPlaceholder;
|
import org.verdurae.placeholderplus.API.Abstract.SubJsPlaceholder;
|
||||||
@@ -98,4 +99,14 @@ public class PluginAPI {
|
|||||||
expansion.unregister();
|
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.API.PluginAPI;
|
||||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PlaceholderPlusCommand implements CommandExecutor {
|
public class PlaceholderPlusCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
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("PlaceholderPlus:");
|
||||||
sender.sendMessage("/pp 玩家名 set 变量名 数值");
|
sender.sendMessage("/pp 玩家名 set 变量名 数值");
|
||||||
sender.sendMessage("/pp 玩家名 add 变量名 数值");
|
sender.sendMessage("/pp 玩家名 add 变量名 数值");
|
||||||
sender.sendMessage("/pp 玩家名 remove 变量名");
|
sender.sendMessage("/pp 玩家名 remove 变量名");
|
||||||
sender.sendMessage("/pp reload");
|
sender.sendMessage("/pp reload");
|
||||||
} else {
|
} else {
|
||||||
|
String holdername = args[2];
|
||||||
|
String[] perms = holdername.split("_");
|
||||||
switch (args[1]) {
|
switch (args[1]) {
|
||||||
case "set":
|
case "set":
|
||||||
PlayerAPI.getPlayerData(args[0]).set(args[2], args[3]);
|
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], args[3]);
|
||||||
break;
|
break;
|
||||||
case "add":
|
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;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
PlayerAPI.getPlayerData(args[0]).set(args[2], null);
|
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], null);
|
||||||
break;
|
break;
|
||||||
case "reload":
|
default:
|
||||||
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
|
||||||
PluginAPI.saveAllPlayerData();
|
|
||||||
PlayerAPI.playerData = new HashMap<>();
|
|
||||||
PluginAPI.loadOnlinePlayerData();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
|
||||||
|
import static org.verdurae.placeholderplus.PlaceholderPlus.config;
|
||||||
|
|
||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
public String name;
|
public String name;
|
||||||
@@ -21,10 +22,14 @@ public class PlayerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration defaultData(FileConfiguration data) {
|
public FileConfiguration defaultData(FileConfiguration data) {
|
||||||
Map<String, Object> value = PlaceholderPlus.config.getValues(true);
|
for (String key : config.getStringList("Placeholders.normal")) {
|
||||||
for (String key : value.keySet()) {
|
if (!data.contains("normal." + key)) {
|
||||||
if (key.startsWith("Placeholders.")) {
|
data.set("normal." + key, config.get("Placeholders.normal." + key));
|
||||||
if (!data.contains(key.replace("Placeholders.", ""))) data.set(key.replace("Placeholders.", ""), value.get(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;
|
return data;
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package org.verdurae.placeholderplus;
|
|||||||
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.verdurae.placeholderplus.API.PlayerAPI;
|
import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||||
import org.verdurae.placeholderplus.API.PluginAPI;
|
import org.verdurae.placeholderplus.API.PluginAPI;
|
||||||
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
||||||
@@ -21,7 +22,9 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
public static boolean jsSupport = false;
|
public static boolean jsSupport = false;
|
||||||
public static ArrayList<PlaceholderExpansion> expansions = new ArrayList<>();
|
public static ArrayList<PlaceholderExpansion> expansions = new ArrayList<>();
|
||||||
public static File dataFolder;
|
public static File dataFolder;
|
||||||
public static boolean autosave = true;
|
public static boolean autosave;
|
||||||
|
public static BukkitTask timer;
|
||||||
|
public static int timeCount = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
@@ -40,6 +43,7 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
config = getConfig();
|
config = getConfig();
|
||||||
|
autosave = config.getBoolean("Task.SaveTask.enable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,22 +52,9 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
dataFolder = new File(getDataFolder(), "PlayerData");
|
dataFolder = new File(getDataFolder(), "PlayerData");
|
||||||
dataFolder.mkdirs();
|
dataFolder.mkdirs();
|
||||||
PluginAPI.loadAllHolder();
|
PluginAPI.loadAllHolder();
|
||||||
PluginAPI.loadOnlinePlayerData();
|
PluginAPI.loadAllPlayerData();
|
||||||
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
newTimer();
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,4 +63,30 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
PluginAPI.saveAllPlayerData();
|
PluginAPI.saveAllPlayerData();
|
||||||
PluginAPI.unloadAllHolder();
|
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 {
|
public class ThisPlaceholder extends PlaceholderExpansion {
|
||||||
@Override
|
@Override
|
||||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String params) {
|
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String param) {
|
||||||
String a = PlayerAPI.getPlayerData(player.getName()).getString(params);
|
String[] params = param.split("_");
|
||||||
return (a == null) ? PlaceholderPlus.config.getString("Placeholders." + params) : a;
|
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
|
@Override
|
||||||
|
|||||||
@@ -4,8 +4,19 @@ JsImportPacket:
|
|||||||
"PAPI": "me.clip.placeholderapi.PlaceholderAPI"
|
"PAPI": "me.clip.placeholderapi.PlaceholderAPI"
|
||||||
|
|
||||||
Placeholders:
|
Placeholders:
|
||||||
"test": "这是一个变量"
|
normal:
|
||||||
"test1": "这是另一个变量"
|
"test": "这是一个变量"
|
||||||
"test2": "最好不要留空"
|
"test1": "这是另一个变量"
|
||||||
"test3": "1"
|
"test2": "最好不要留空"
|
||||||
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
"test3": "1"
|
||||||
|
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
||||||
|
update:
|
||||||
|
update:
|
||||||
|
max: 160
|
||||||
|
period: 1
|
||||||
|
amount: 1
|
||||||
|
|
||||||
|
Task:
|
||||||
|
SaveTask:
|
||||||
|
enable: true
|
||||||
|
period: 600
|
||||||
@@ -5,5 +5,6 @@ author: Kaminy
|
|||||||
depend:
|
depend:
|
||||||
- PlaceholderAPI
|
- PlaceholderAPI
|
||||||
website: https://github.com/Verdurae/PlaceholderPlus
|
website: https://github.com/Verdurae/PlaceholderPlus
|
||||||
|
folia-supported: true
|
||||||
commands:
|
commands:
|
||||||
pp:
|
pp:
|
||||||
Reference in new issue
Block a user