feat: 添加命令别名
This commit is contained in:
@@ -6,7 +6,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "cn.hamster3.mc.plugin"
|
group = "cn.hamster3.mc.plugin"
|
||||||
version = "1.0.4"
|
version = "1.0.5"
|
||||||
description = "为Minecraft服务器导入 OpenJDK Nashorn 引擎来执行 JavaScript 脚本"
|
description = "为Minecraft服务器导入 OpenJDK Nashorn 引擎来执行 JavaScript 脚本"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@@ -9,7 +9,10 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.script.*;
|
import javax.script.Bindings;
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -64,16 +67,15 @@ public class HamsterScriptPlugin extends JavaPlugin {
|
|||||||
Class<?> clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
engine.put(simpleName, clazz);
|
engine.put(simpleName, clazz);
|
||||||
engine.eval(String.format("%s = %s.static;", simpleName, simpleName));
|
engine.eval(String.format("%s = %s.static;", simpleName, simpleName));
|
||||||
getLogger().info("将 " + className + " 导入为 " + simpleName);
|
getLogger().info("已导入 " + className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
getLogger().warning("将 " + className + " 导入为 " + simpleName + " 失败:未找到这个类");
|
getLogger().warning("导入 " + className + " 失败:未找到这个类");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getLogger().warning("将 " + className + " 导入为 " + simpleName + " 失败");
|
getLogger().warning("导入 " + className + " 失败");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -3,9 +3,10 @@ enable-eval-command: false
|
|||||||
|
|
||||||
# 导入的 Java 代码
|
# 导入的 Java 代码
|
||||||
import:
|
import:
|
||||||
|
Math: java.lang.Math
|
||||||
|
String: java.lang.String
|
||||||
|
UUID: java.util.UUID
|
||||||
|
Base64: java.util.Base64
|
||||||
Bukkit: org.bukkit.Bukkit
|
Bukkit: org.bukkit.Bukkit
|
||||||
Material: org.bukkit.Material
|
Material: org.bukkit.Material
|
||||||
ItemStack: org.bukkit.inventory.ItemStack
|
ItemStack: org.bukkit.inventory.ItemStack
|
||||||
UUID: java.util.UUID
|
|
||||||
Math: java.lang.Math
|
|
||||||
String: java.lang.String
|
|
||||||
|
@@ -9,8 +9,8 @@ Plugin:
|
|||||||
join-classpath: true
|
join-classpath: true
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
scripts:
|
hamster-script:
|
||||||
aliases: script
|
aliases: [ scripts,script ]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
hamster.script.admin:
|
hamster.script.admin:
|
||||||
|
Reference in New Issue
Block a user