mirror of
https://github.com/Verdurae/PlaceholderPlus.git
synced 2026-11-25 22:25:21 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b44410f40c |
No files matched your search
+1
-1
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'org.verdurae'
|
group = 'org.verdurae'
|
||||||
version = '1.1.4-SNAPSHOT'
|
version = '1.1.5-SNAPSHOT'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -28,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;
|
||||||
|
|||||||
@@ -61,12 +61,15 @@ public class PluginUtil {
|
|||||||
PlaceholderPlus.expansions = new ArrayList<>();
|
PlaceholderPlus.expansions = new ArrayList<>();
|
||||||
PlaceholderPlus.expansions.add(new ThisPlaceholder());
|
PlaceholderPlus.expansions.add(new ThisPlaceholder());
|
||||||
File JsFolder = new File(PlaceholderPlus.dataFolder, "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());
|
||||||
ConfigurationSection value = PlaceholderPlus.config.getConfigurationSection("JsImportPacket");
|
ConfigurationSection value = PlaceholderPlus.config.getConfigurationSection("JsImportPacket");
|
||||||
for (String key : value.getKeys(false)) {
|
for (String key : value.getKeys(false)) {
|
||||||
engine.put(key, Class.forName(value.getString(key)));
|
engine.put(key, Class.forName(value.getString(key)));
|
||||||
@@ -81,22 +84,28 @@ public class PluginUtil {
|
|||||||
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 String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return identifier;
|
return finalIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return finalAuthor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return finalVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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.player.getName() === author) {
|
||||||
|
return "这个玩家是作者";
|
||||||
|
} else {
|
||||||
|
return "这个玩家不是作者";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user