mirror of
https://github.com/Verdurae/PlaceholderPlus.git
synced 2026-11-25 14:24:32 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88f6259b1a | ||
|
|
4f5775e63a | ||
|
|
b44410f40c | ||
|
|
d4e53ea858 | ||
|
|
7e6f4eb53d | ||
|
|
85b28f0a07 | ||
|
|
44e553ea2a | ||
|
|
4d2919cfb3 | ||
|
|
11289fa6c6 |
No files matched your search
@@ -1,74 +0,0 @@
|
|||||||
# This workflow uses actions that are not certified by GitHub.
|
|
||||||
# They are provided by a third-party and are governed by
|
|
||||||
# separate terms of service, privacy policy, and support
|
|
||||||
# documentation.
|
|
||||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
|
||||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
|
|
||||||
|
|
||||||
name: Java CI with Gradle
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "master" ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up JDK 8
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: '8'
|
|
||||||
distribution: 'temurin'
|
|
||||||
- name: Download and install Gradle
|
|
||||||
uses: gradle/gradle-build-action@v2
|
|
||||||
with:
|
|
||||||
gradle-version: '8.7'
|
|
||||||
- name: Refresh dependencies cache
|
|
||||||
run: gradle clean --refresh-dependencies
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: gradle build
|
|
||||||
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
|
|
||||||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
|
|
||||||
- name: Setup Gradle
|
|
||||||
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
|
||||||
|
|
||||||
# - name: Build with Gradle Wrapper
|
|
||||||
# run: ./gradlew build
|
|
||||||
|
|
||||||
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
|
|
||||||
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
|
|
||||||
#
|
|
||||||
# - name: Setup Gradle
|
|
||||||
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
|
||||||
# with:
|
|
||||||
# gradle-version: '8.7'
|
|
||||||
|
|
||||||
# - name: Build with Gradle 8.7
|
|
||||||
# run: gradle build
|
|
||||||
|
|
||||||
dependency-submission:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up JDK 8
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: '8'
|
|
||||||
distribution: 'temurin'
|
|
||||||
|
|
||||||
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
|
|
||||||
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
|
|
||||||
- name: Generate and submit dependency graph
|
|
||||||
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
|
||||||
+3
-2
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'org.verdurae'
|
group = 'org.verdurae'
|
||||||
version = '1.1-SNAPSHOT'
|
version = '1.1.6-SNAPSHOT'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -19,8 +19,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"
|
compileOnly "org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT"
|
||||||
implementation 'me.clip:placeholderapi:2.+'
|
implementation 'me.clip:placeholderapi:2.+'
|
||||||
|
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 8
|
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 me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
import javax.script.Invocable;
|
import javax.script.Invocable;
|
||||||
@@ -11,10 +9,10 @@ import javax.script.ScriptEngine;
|
|||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
|
|
||||||
public abstract class SubJsPlaceholder extends PlaceholderExpansion {
|
public abstract class SubJsPlaceholder extends PlaceholderExpansion {
|
||||||
public abstract @NotNull ScriptEngine getEngine();
|
public abstract ScriptEngine getEngine();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String params) {
|
public String onRequest(OfflinePlayer player, String params) {
|
||||||
Invocable inv = (Invocable) getEngine();
|
Invocable inv = (Invocable) getEngine();
|
||||||
try {
|
try {
|
||||||
return inv.invokeFunction("onRequest", player, params).toString();
|
return inv.invokeFunction("onRequest", player, params).toString();
|
||||||
@@ -30,6 +28,8 @@ public abstract class SubJsPlaceholder extends PlaceholderExpansion {
|
|||||||
if (PlaceholderPlus.jsSupport) {
|
if (PlaceholderPlus.jsSupport) {
|
||||||
PlaceholderPlus.expansions.add(this);
|
PlaceholderPlus.expansions.add(this);
|
||||||
return super.register();
|
return super.register();
|
||||||
|
} else {
|
||||||
|
PlaceholderPlus.expansions.remove(this);
|
||||||
}
|
}
|
||||||
PlaceholderPlus.logger.warning("你的运行Java中没有JS引擎," + getIdentifier() + "变量终止注册");
|
PlaceholderPlus.logger.warning("你的运行Java中没有JS引擎," + getIdentifier() + "变量终止注册");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package org.verdurae.placeholderplus.API;
|
|
||||||
|
|
||||||
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,38 @@
|
|||||||
|
package org.verdurae.placeholderplus.API;
|
||||||
|
|
||||||
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kaminy
|
||||||
|
* @date 2025/11/12 22:39
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public class PlaceholderPlusApi {
|
||||||
|
/**
|
||||||
|
* 获取玩家占位符对应的数据值
|
||||||
|
*
|
||||||
|
* @param player 玩家名
|
||||||
|
* @param placeholder 占位符名称,格式为"xxx_yyy",不需要带%
|
||||||
|
* @return 对应的玩家插件变量值
|
||||||
|
*/
|
||||||
|
public static String getPlaceholder(String player, String placeholder) {
|
||||||
|
String[] perms = placeholder.split("_");
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置玩家数据中的占位符
|
||||||
|
*
|
||||||
|
* @param player 玩家名
|
||||||
|
* @param placeholder 占位符名称,格式为"xxx_yyy",不需要带%
|
||||||
|
* @param value 要设置的值
|
||||||
|
*/
|
||||||
|
public static void setPlaceholder(String player, String placeholder, String value) {
|
||||||
|
String[] perms = placeholder.split("_");
|
||||||
|
PlayerUtil.getPlayerData(player).set(perms[0] + "." + perms[1], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,23 @@
|
|||||||
package org.verdurae.placeholderplus.Command;
|
package org.verdurae.placeholderplus.Command;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.verdurae.placeholderplus.API.MathAPI;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.verdurae.placeholderplus.API.PlayerAPI;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.verdurae.placeholderplus.API.PluginAPI;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
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;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PlaceholderPlusCommand implements CommandExecutor {
|
public class PlaceholderPlusCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||||
@@ -18,36 +25,150 @@ public class PlaceholderPlusCommand implements CommandExecutor {
|
|||||||
if (args.length == 1 && args[0].equals("reload")) {
|
if (args.length == 1 && args[0].equals("reload")) {
|
||||||
PlaceholderPlus.instance.reloadConfig();
|
PlaceholderPlus.instance.reloadConfig();
|
||||||
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
||||||
PluginAPI.saveAllPlayerData();
|
PluginUtil.saveAllPlayerData();
|
||||||
PlayerAPI.playerData = new ConcurrentHashMap<>();
|
PluginUtil.saveServerData();
|
||||||
PluginAPI.loadOnlinePlayerData();
|
PlayerUtil.playerData = new ConcurrentHashMap<>();
|
||||||
|
PluginUtil.serverData = new YamlConfiguration();
|
||||||
|
PluginUtil.loadAllPlayerData();
|
||||||
|
PluginUtil.loadServerData();
|
||||||
|
PluginUtil.loadAllHolder();
|
||||||
PlaceholderPlus.timer.cancel();
|
PlaceholderPlus.timer.cancel();
|
||||||
PlaceholderPlus.newTimer();
|
PlaceholderPlus.newTimer();
|
||||||
sender.sendMessage("已重载");
|
sender.sendMessage("已重载");
|
||||||
return true;
|
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");
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
String holdername = args[2];
|
try {
|
||||||
String[] perms = holdername.split("_");
|
|
||||||
switch (args[1]) {
|
String holdername = args[2];
|
||||||
case "set":
|
String[] perms = holdername.split("_");
|
||||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], args[3]);
|
if (perms.length < 1) {
|
||||||
break;
|
sender.sendMessage("请输入正确的变量名");
|
||||||
case "add":
|
return false;
|
||||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], MathAPI.calculate(PlayerAPI.getPlayerData(args[0]).getDouble(perms[0] + "." + perms[1]), args[3]));
|
}
|
||||||
break;
|
if (!ThisPlaceholder.placeholderTypes.contains(perms[0])) {
|
||||||
case "remove":
|
perms = new String[]{"normal", perms[0]};
|
||||||
PlayerAPI.getPlayerData(args[0]).set(perms[0] + "." + perms[1], null);
|
}
|
||||||
break;
|
boolean message = PlaceholderPlus.config.getBoolean("Setting.message", true);
|
||||||
default:
|
for (String arg : args) {
|
||||||
break;
|
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("参数不足");
|
||||||
|
}
|
||||||
|
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.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.verdurae.placeholderplus.API.PlayerAPI;
|
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -18,7 +18,7 @@ public class PlayerData {
|
|||||||
if (data == null) data = new YamlConfiguration();
|
if (data == null) data = new YamlConfiguration();
|
||||||
this.data = defaultData(data);
|
this.data = defaultData(data);
|
||||||
save();
|
save();
|
||||||
PlayerAPI.playerData.put(name, this);
|
PlayerUtil.playerData.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration defaultData(FileConfiguration data) {
|
public FileConfiguration defaultData(FileConfiguration data) {
|
||||||
@@ -37,7 +37,7 @@ public class PlayerData {
|
|||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try {
|
try {
|
||||||
data.save(PlaceholderPlus.dataFolder + "/" + name + ".yml");
|
data.save(PlaceholderPlus.playerDataFolder + "/" + name + ".yml");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
package org.verdurae.placeholderplus;
|
package org.verdurae.placeholderplus;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
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.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.verdurae.placeholderplus.API.PlayerAPI;
|
|
||||||
import org.verdurae.placeholderplus.API.PluginAPI;
|
|
||||||
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
||||||
import org.verdurae.placeholderplus.Object.PlayerData;
|
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.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -20,11 +29,16 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
public static Logger logger;
|
public static Logger logger;
|
||||||
public static FileConfiguration config;
|
public static FileConfiguration config;
|
||||||
public static boolean jsSupport = false;
|
public static boolean jsSupport = false;
|
||||||
public static ArrayList<PlaceholderExpansion> expansions = new ArrayList<>();
|
public static ArrayList<PlaceholderExpansion> expansions;
|
||||||
public static File dataFolder;
|
public static File dataFolder;
|
||||||
|
public static File serverDataFolder;
|
||||||
|
public static File playerDataFolder;
|
||||||
public static boolean autosave;
|
public static boolean autosave;
|
||||||
public static BukkitTask timer;
|
public static BukkitTask timer;
|
||||||
public static int timeCount = 0;
|
public static int timeCount = 0;
|
||||||
|
private static final String DEPENDENCY_URL = "https://repo1.maven.org/maven2/org/openjdk/nashorn/nashorn-core/15.2/nashorn-core-15.2.jar";
|
||||||
|
private static final File LOCAL_JAR = new File("plugins/PlaceholderPlus/lib/nashorn-core.jar");
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
@@ -40,6 +54,8 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
logger.warning("你的运行Java中没有JS引擎,无法使用JS变量功能噢");
|
logger.warning("你的运行Java中没有JS引擎,无法使用JS变量功能噢");
|
||||||
logger.warning("解决办法:安装一个带有nashornJs引擎的插件或模组/使用Java15-的版本/催更我内置一个JS引擎");
|
logger.warning("解决办法:安装一个带有nashornJs引擎的插件或模组/使用Java15-的版本/催更我内置一个JS引擎");
|
||||||
logger.warning("状态决定类:jdk.nashorn.api.scripting.NashornScriptEngine");
|
logger.warning("状态决定类:jdk.nashorn.api.scripting.NashornScriptEngine");
|
||||||
|
logger.warning("准备开始自动下载nashorn....");
|
||||||
|
loadDependencyIfMissing();
|
||||||
}
|
}
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
config = getConfig();
|
config = getConfig();
|
||||||
@@ -49,44 +65,89 @@ public final class PlaceholderPlus extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
logger.info("开始加载");
|
logger.info("开始加载");
|
||||||
dataFolder = new File(getDataFolder(), "PlayerData");
|
dataFolder = getDataFolder();
|
||||||
dataFolder.mkdirs();
|
serverDataFolder = new File(dataFolder, "ServerData");
|
||||||
PluginAPI.loadAllHolder();
|
playerDataFolder = new File(dataFolder, "PlayerData");
|
||||||
PluginAPI.loadAllPlayerData();
|
serverDataFolder.mkdirs();
|
||||||
|
playerDataFolder.mkdirs();
|
||||||
|
PluginUtil.loadAllHolder();
|
||||||
|
PluginUtil.loadAllPlayerData();
|
||||||
|
PluginUtil.loadServerData();
|
||||||
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
||||||
|
getCommand("pp").setTabCompleter(new PlaceholderPlusCommand());
|
||||||
newTimer();
|
newTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
logger.info("插件卸载");
|
logger.info("插件卸载");
|
||||||
PluginAPI.saveAllPlayerData();
|
PluginUtil.saveAllPlayerData();
|
||||||
PluginAPI.unloadAllHolder();
|
PluginUtil.saveServerData();
|
||||||
|
PluginUtil.unloadAllHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void newTimer() {
|
public static void newTimer() {
|
||||||
timer = Bukkit.getScheduler().runTaskTimerAsynchronously(PlaceholderPlus.instance, () -> {
|
timer = Bukkit.getScheduler().runTaskTimerAsynchronously(PlaceholderPlus.instance, () -> {
|
||||||
timeCount++;
|
timeCount++;
|
||||||
System.out.println(timeCount);
|
|
||||||
if (PlaceholderPlus.config.getBoolean("Task.SaveTask.enable") && timeCount % PlaceholderPlus.config.getInt("Task.SaveTask.period") == 0) {
|
if (PlaceholderPlus.config.getBoolean("Task.SaveTask.enable") && timeCount % PlaceholderPlus.config.getInt("Task.SaveTask.period") == 0) {
|
||||||
logger.info("正在自动保存数据");
|
logger.info("正在自动保存数据");
|
||||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
for (PlayerData playerData : PlayerUtil.playerData.values()) {
|
||||||
playerData.save();
|
playerData.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConfigurationSection updates = PlaceholderPlus.config.getConfigurationSection("Placeholders.update");
|
ConfigurationSection updates = PlaceholderPlus.config.getConfigurationSection("Placeholders.update");
|
||||||
for (String update : updates.getKeys(false)) {
|
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) {
|
if (timeCount % PlaceholderPlus.config.getInt("Placeholders.update." + update + ".period") == 0) {
|
||||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
for (PlayerData playerData : PlayerUtil.playerData.values()) {
|
||||||
if (playerData.data.getInt("update." + update) < PlaceholderPlus.config.getInt("Placeholders.update." + update + ".max")) {
|
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;
|
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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1, 20);
|
}, 1, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void loadDependencyIfMissing() {
|
||||||
|
if (!LOCAL_JAR.exists()) {
|
||||||
|
LOCAL_JAR.getParentFile().mkdirs();
|
||||||
|
downloadFile(DEPENDENCY_URL, LOCAL_JAR);
|
||||||
|
}
|
||||||
|
addJarToClasspath(LOCAL_JAR.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void downloadFile(String urlStr, File destination) {
|
||||||
|
try (InputStream in = new URL(urlStr).openStream()) {
|
||||||
|
ReadableByteChannel rbc = Channels.newChannel(in);
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(destination)) {
|
||||||
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addJarToClasspath(String jarPath) {
|
||||||
|
try {
|
||||||
|
URL url = new File(jarPath).toURI().toURL();
|
||||||
|
URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||||
|
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(loader, url);
|
||||||
|
System.out.println("成功将依赖添加到类路径: " + jarPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,36 +2,74 @@ package org.verdurae.placeholderplus;
|
|||||||
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.verdurae.placeholderplus.Util.PlayerUtil;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.verdurae.placeholderplus.Util.PluginUtil;
|
||||||
import org.verdurae.placeholderplus.API.PlayerAPI;
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ThisPlaceholder extends PlaceholderExpansion {
|
public class ThisPlaceholder extends PlaceholderExpansion {
|
||||||
|
public final static List<String> placeholderTypes = Arrays.asList("normal", "update", "server");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String param) {
|
public String onRequest(OfflinePlayer player, String param) {
|
||||||
String[] params = param.split("_");
|
String[] params = param.split("_");
|
||||||
if (params[0].equals("normal")) {
|
String defaultValue = "未定义的变量";
|
||||||
String a = PlayerAPI.getPlayerData(player.getName()).getString("normal." + params[1]);
|
for (String arg : params) {
|
||||||
return (a == null) ? PlaceholderPlus.config.getString("Placeholders.normal." + params[1]) : a;
|
if (arg.startsWith("d:")) {
|
||||||
} else if (params[0].equals("update")) {
|
defaultValue = arg.replaceFirst("d:", "");
|
||||||
String a = PlayerAPI.getPlayerData(player.getName()).getString("update." + params[1]);
|
}
|
||||||
return (a == null) ? PlaceholderPlus.config.getString("Placeholders.update." + params[1] + ".max") : a;
|
}
|
||||||
|
if (!placeholderTypes.contains(params[0])) {
|
||||||
|
params = new String[]{"normal", params[0]};
|
||||||
|
}
|
||||||
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return "pp";
|
return "pp";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getAuthor() {
|
public String getAuthor() {
|
||||||
return "Kaminy";
|
return "Kaminy";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getVersion() {
|
public String getVersion() {
|
||||||
return PlaceholderPlus.instance.getDescription().getVersion();
|
return PlaceholderPlus.instance.getDescription().getVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package org.verdurae.placeholderplus.API;
|
package org.verdurae.placeholderplus.Util;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -9,12 +9,12 @@ import org.verdurae.placeholderplus.PlaceholderPlus;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PlayerAPI {
|
public class PlayerUtil {
|
||||||
public static ConcurrentHashMap<String, PlayerData> playerData = new ConcurrentHashMap<>();
|
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;
|
||||||
YamlConfiguration data = YamlConfiguration.loadConfiguration(new File(PlaceholderPlus.dataFolder, playername + ".yml"));
|
YamlConfiguration data = YamlConfiguration.loadConfiguration(new File(PlaceholderPlus.playerDataFolder, playername + ".yml"));
|
||||||
new PlayerData(playername, data);
|
new PlayerData(playername, data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
+57
-25
@@ -1,11 +1,12 @@
|
|||||||
package org.verdurae.placeholderplus.API;
|
package org.verdurae.placeholderplus.Util;
|
||||||
|
|
||||||
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.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.verdurae.placeholderplus.API.Abstract.SubJsPlaceholder;
|
import org.verdurae.placeholderplus.API.Abstract.SubJsPlaceholder;
|
||||||
import org.verdurae.placeholderplus.Object.PlayerData;
|
import org.verdurae.placeholderplus.Object.PlayerData;
|
||||||
import org.verdurae.placeholderplus.PlaceholderPlus;
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
@@ -18,36 +19,60 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Map;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
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() {
|
public static void saveAllPlayerData() {
|
||||||
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
for (PlayerData playerData : PlayerUtil.playerData.values()) {
|
||||||
playerData.save();
|
playerData.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadOnlinePlayerData() {
|
public static void loadOnlinePlayerData() {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
PlayerAPI.getPlayerData(player);
|
PlayerUtil.getPlayerData(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadAllHolder() {
|
public static void loadAllHolder() {
|
||||||
|
PlaceholderPlus.expansions = new ArrayList<>();
|
||||||
PlaceholderPlus.expansions.add(new ThisPlaceholder());
|
PlaceholderPlus.expansions.add(new ThisPlaceholder());
|
||||||
File JsFolder = new File(PlaceholderPlus.instance.getDataFolder(), "Js");
|
File JsFolder = new File(PlaceholderPlus.dataFolder, "Js");
|
||||||
JsFolder.mkdirs();
|
if (!JsFolder.exists()) {
|
||||||
|
PlaceholderPlus.logger.info("生成示例JS文件");
|
||||||
|
PlaceholderPlus.instance.saveResource("Js/exampleJS.js", false);
|
||||||
|
}
|
||||||
for (File file : Objects.requireNonNull(JsFolder.listFiles())) {
|
for (File file : Objects.requireNonNull(JsFolder.listFiles())) {
|
||||||
if (file.getName().endsWith(".js")) {
|
if (file.getName().endsWith(".js")) {
|
||||||
try {
|
try {
|
||||||
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
||||||
ScriptEngine engine = factory.getScriptEngine();
|
ScriptEngine engine = factory.getScriptEngine(PlaceholderPlus.class.getClassLoader());
|
||||||
Map<String, Object> value = PlaceholderPlus.config.getValues(true);
|
ConfigurationSection value = PlaceholderPlus.config.getConfigurationSection("JsImportPacket");
|
||||||
for (String key : value.keySet()) {
|
for (String key : value.getKeys(false)) {
|
||||||
if (key.startsWith("JsImportPacket.")) {
|
engine.put(key, Class.forName(value.getString(key)));
|
||||||
engine.put(key.replace("JsImportPacket.", ""), Class.forName(key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
|
InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
|
||||||
char[] buffer = new char[1024];
|
char[] buffer = new char[1024];
|
||||||
@@ -59,26 +84,32 @@ public class PluginAPI {
|
|||||||
String scriptContent = builder.toString();
|
String scriptContent = builder.toString();
|
||||||
engine.eval(scriptContent);
|
engine.eval(scriptContent);
|
||||||
String identifier = (String) engine.get("identifier");
|
String identifier = (String) engine.get("identifier");
|
||||||
|
identifier = identifier == null ? file.getName().substring(".js".length()) : identifier;
|
||||||
String author = (String) engine.get("author");
|
String author = (String) engine.get("author");
|
||||||
|
author = author == null ? "Unknown" : author;
|
||||||
String version = (String) engine.get("version");
|
String version = (String) engine.get("version");
|
||||||
|
version = version == null ? "Unknown" : version;
|
||||||
|
String finalIdentifier = identifier;
|
||||||
|
String finalAuthor = author;
|
||||||
|
String finalVersion = version;
|
||||||
PlaceholderPlus.expansions.add(new SubJsPlaceholder() {
|
PlaceholderPlus.expansions.add(new SubJsPlaceholder() {
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return identifier;
|
return finalIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return finalAuthor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return finalVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ScriptEngine getEngine() {
|
public ScriptEngine getEngine() {
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -89,18 +120,19 @@ public class PluginAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (PlaceholderExpansion expansion : PlaceholderPlus.expansions) {
|
for (PlaceholderExpansion expansion : new ArrayList<>(PlaceholderPlus.expansions)) {
|
||||||
if (expansion.canRegister()) expansion.register();
|
if (expansion.canRegister()) expansion.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unloadAllHolder() {
|
public static void unloadAllHolder() {
|
||||||
for (PlaceholderExpansion expansion : PlaceholderPlus.expansions) {
|
for (PlaceholderExpansion expansion : new ArrayList<>(PlaceholderPlus.expansions)) {
|
||||||
expansion.unregister();
|
expansion.unregister();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadAllPlayerData() {
|
public static void loadAllPlayerData() {
|
||||||
File[] files = PlaceholderPlus.dataFolder.listFiles();
|
File[] files = PlaceholderPlus.playerDataFolder.listFiles();
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (!file.getName().endsWith(".yml")) continue;
|
if (!file.getName().endsWith(".yml")) continue;
|
||||||
@@ -109,4 +141,4 @@ public class PluginAPI {
|
|||||||
new PlayerData(name, data);
|
new PlayerData(name, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
identifier = "exampleJS"
|
||||||
|
author = "Kaminy"
|
||||||
|
version = "1.1.5"
|
||||||
|
|
||||||
|
function onRequest(player, params) {
|
||||||
|
// 示例处理 如果这个玩家是作者的话返回"这个玩家是作者"
|
||||||
|
// 你可以写任意多的判断在这里
|
||||||
|
// params是这个调用的js的参数,形如%exampleJS_参数1_参数2_参数3%,该方法获得的params就是一整段"参数1_参数2_参数3"作为一个参数,需要手动使用_切割
|
||||||
|
if (player.getName() === author) {
|
||||||
|
return "这个玩家是作者";
|
||||||
|
} else {
|
||||||
|
return "这个玩家不是作者";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,43 @@
|
|||||||
JsImportPacket:
|
Setting:
|
||||||
"Bukkit": "org.bukkit.Bukkit"
|
# 指令是否发送反馈消息
|
||||||
"Arrays": "java.util.Arrays"
|
# 也可以在指令里添加参数m=false或m=true,指令参数优先级高于全服设置
|
||||||
"PAPI": "me.clip.placeholderapi.PlaceholderAPI"
|
message: true
|
||||||
|
|
||||||
|
# 要给js变量导的包,新手不建议使用
|
||||||
|
JsImportPacket:
|
||||||
|
Bukkit: "org.bukkit.Bukkit"
|
||||||
|
Arrays: "java.util.Arrays"
|
||||||
|
PAPI: "me.clip.placeholderapi.PlaceholderAPI"
|
||||||
|
|
||||||
|
# 自定义变量
|
||||||
|
# 最终解析的变量是%pp_变量类型_变量名%
|
||||||
Placeholders:
|
Placeholders:
|
||||||
|
# 常规变量
|
||||||
|
# 不具备对应变量玩家解析常规变量时会获得默认值(就是配置中写的值)
|
||||||
|
# 当通过指令或其他方式设置之后就会获得玩家自己的储存值
|
||||||
normal:
|
normal:
|
||||||
"test": "这是一个变量"
|
"test": "这是一个变量" # 比如你想返回这个,就是%pp_normal_test% 或者 %pp_test% normal类型解析变量时可以省略normal
|
||||||
"test1": "这是另一个变量"
|
"test1": "这是另一个变量"
|
||||||
"test2": "最好不要留空"
|
"test2": "最好不要留空"
|
||||||
"test3": "1"
|
"test3": "1"
|
||||||
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有负号和小数点"
|
||||||
|
# 脉冲变量
|
||||||
|
# 脉冲变量会自动变化 可以增加也可以减少 不会超过变量上限(无下限限制)
|
||||||
|
# 可以用来做体力之类的功能
|
||||||
update:
|
update:
|
||||||
update:
|
update: # %pp_update_update%
|
||||||
max: 160
|
max: 160 # 自增上限,可以解析papi变量以将其他papi变量作为仅对该玩家该脉冲变量生效的上限,如%player_health%,也支持四则运算,比如10+%player_health%
|
||||||
period: 1
|
period: 1 # 变化周期,秒
|
||||||
amount: 1
|
amount: 1 # 变化量
|
||||||
|
# 全服变量
|
||||||
|
# 不会储存到玩家而是储存到服务器缓存,关服时会保存到文件,缓存里没有对应变量值的时候会获得默认值
|
||||||
|
# 所有玩家解析全服变量的结果都是相同的
|
||||||
|
# 可用于设置全服的某种功能门槛,如击败某个全服boss后解锁新的玩法之类
|
||||||
|
server:
|
||||||
|
server1: "false"
|
||||||
|
|
||||||
Task:
|
Task:
|
||||||
|
# 自动保存
|
||||||
SaveTask:
|
SaveTask:
|
||||||
enable: true
|
enable: true
|
||||||
period: 600
|
period: 600
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
name: PlaceholderPlus
|
name: PlaceholderPlus
|
||||||
version: '${version}'
|
version: '${version}'
|
||||||
|
api-version: 1.13
|
||||||
main: org.verdurae.placeholderplus.PlaceholderPlus
|
main: org.verdurae.placeholderplus.PlaceholderPlus
|
||||||
author: Kaminy
|
author: Kaminy
|
||||||
depend:
|
depend:
|
||||||
|
|||||||
Reference in new issue
Block a user