From 91a87ab20eae6810847733201dad16c98cd7374d Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Wed, 16 Feb 2022 14:36:22 +0800 Subject: [PATCH] feat: release 0.18.0 version 1. optimize load logic 2. add root change detach 3. add common softdepends Signed-off-by: MiaoWoo --- pom.xml | 20 +++++++++---------- src/main/java/pw/yumc/MiaoScript/Base.java | 13 ++++++++---- ...{MiaoScript.java => MiaoScriptBukkit.java} | 10 +++++++--- .../pw/yumc/MiaoScript/MiaoScriptBungee.java | 7 +++++-- .../pw/yumc/MiaoScript/MiaoScriptEngine.java | 12 +++++------ .../pw/yumc/MiaoScript/MiaoScriptNukkit.java | 11 ++++++---- .../pw/yumc/MiaoScript/MiaoScriptSponge.java | 10 +++++----- src/main/resources/bios.js | 2 +- src/main/resources/core/require.js | 15 +++++++++++--- src/main/resources/plugin.yml | 20 ++++++++++++++----- 10 files changed, 77 insertions(+), 43 deletions(-) rename src/main/java/pw/yumc/MiaoScript/{MiaoScript.java => MiaoScriptBukkit.java} (87%) diff --git a/pom.xml b/pom.xml index 3cca136..eaef3b3 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 pw.yumc MiaoScript - 0.17.0 + 0.18.0 502647092 @@ -53,6 +53,10 @@ DEV + §622-02-16 §afeat: 优化 初始化逻辑 加快引擎加载速度; +       §afeat: 新增 root 目录变更检测 变更后重新生成缓存; +       §afeat: 添加常用库的软依赖; + §622-01-01 §afeat: 兼容JDK17 更新Nashorn; §621-11-04 §afeat: 优化系统模块升级逻辑; §621-07-10 §afeat: 优化网络相关功能; §621-06-25 §afeat: 调整启动逻辑 兼容 Arclight; @@ -168,10 +172,6 @@ yumc-repo ${repo.url}/repository/maven-public/ - - sponge - https://repo.spongepowered.org/maven/ - @@ -190,7 +190,7 @@ org.projectlombok lombok - 1.18.18 + 1.18.22 org.kamranzafar @@ -212,18 +212,18 @@ net.md-5 bungeecord-api - 1.16-R0.4-SNAPSHOT + 1.16-R0.4 cn.nukkit nukkit - 2.0.0-SNAPSHOT + 1.0-SNAPSHOT compile org.springframework spring-websocket - 5.2.6.RELEASE + 5.3.13 compile @@ -233,4 +233,4 @@ compile - + \ No newline at end of file diff --git a/src/main/java/pw/yumc/MiaoScript/Base.java b/src/main/java/pw/yumc/MiaoScript/Base.java index 80e0765..4eb8f70 100644 --- a/src/main/java/pw/yumc/MiaoScript/Base.java +++ b/src/main/java/pw/yumc/MiaoScript/Base.java @@ -13,12 +13,17 @@ import java.nio.file.Path; * Created on 2017/10/9 12:40. */ public class Base { + public static final String VERSION = "0.18.0"; private Object instance; public Base(Object instance) { this.instance = instance; } + public String getVersion() { + return Base.VERSION; + } + public Class getClass(String name) throws ClassNotFoundException { return Class.forName(name); } @@ -39,10 +44,10 @@ public class Base { return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8); } - public void save(String path, String content) throws IOException { + public Path save(String path, String content) throws IOException { File file = new File(path); file.getParentFile().mkdirs(); - Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8)); + return Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8)); } public boolean move(String source, String target) { @@ -54,8 +59,8 @@ public class Base { return delete(new File(path)); } - public void delete(Path path) throws IOException { - delete(path.toFile()); + public boolean delete(Path path) throws IOException { + return delete(path.toFile()); } public boolean delete(File file) throws IOException { diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptBukkit.java similarity index 87% rename from src/main/java/pw/yumc/MiaoScript/MiaoScript.java rename to src/main/java/pw/yumc/MiaoScript/MiaoScriptBukkit.java index 9ecf16e..b43a70b 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptBukkit.java @@ -9,12 +9,11 @@ import org.bukkit.plugin.java.JavaPlugin; * @author 喵♂呜 * @since 2016年8月29日 上午7:50:39 */ -public class MiaoScript extends JavaPlugin { +public class MiaoScriptBukkit extends JavaPlugin { private ScriptEngine engine; - @Override @SneakyThrows - public void onLoad() { + public MiaoScriptBukkit() { ClassLoader origin = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger(), this); @@ -22,6 +21,10 @@ public class MiaoScript extends JavaPlugin { engine.loadEngine(); } + @Override + public void onLoad() { + } + @Override public void onEnable() { engine.enableEngine(); @@ -30,5 +33,6 @@ public class MiaoScript extends JavaPlugin { @Override public void onDisable() { engine.disableEngine(); + engine = null; } } diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScriptBungee.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptBungee.java index d565a64..ffa5620 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScriptBungee.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptBungee.java @@ -12,14 +12,17 @@ import net.md_5.bungee.api.plugin.Plugin; public class MiaoScriptBungee extends Plugin { private ScriptEngine engine; - @Override @SneakyThrows - public void onLoad() { + public MiaoScriptBungee() { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger(), this); engine.loadEngine(); } + @Override + public void onLoad() { + } + @Override public void onEnable() { engine.enableEngine(); diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java index 0a4613f..18e0e5c 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java @@ -112,11 +112,11 @@ public class MiaoScriptEngine implements ScriptEngine, Invocable { File libRootFile = new File(engineRoot, "lib"); libRootFile.mkdirs(); String libRoot = libRootFile.getCanonicalPath(); - downloadJar(libRoot, "org.openjdk.nashorn", "nashorn-core", "15.2"); - downloadJar(libRoot, "org.ow2.asm", "asm", "9.1"); - downloadJar(libRoot, "org.ow2.asm", "asm-commons", "9.1"); - downloadJar(libRoot, "org.ow2.asm", "asm-tree", "9.1"); - downloadJar(libRoot, "org.ow2.asm", "asm-util", "9.1"); + downloadJar(libRoot, "org.openjdk.nashorn", "nashorn-core", "15.3"); + downloadJar(libRoot, "org.ow2.asm", "asm", "9.2"); + downloadJar(libRoot, "org.ow2.asm", "asm-commons", "9.2"); + downloadJar(libRoot, "org.ow2.asm", "asm-tree", "9.2"); + downloadJar(libRoot, "org.ow2.asm", "asm-util", "9.2"); this.createEngineByName("nashorn"); } @@ -127,7 +127,7 @@ public class MiaoScriptEngine implements ScriptEngine, Invocable { @SneakyThrows private void downloadJar(String engineRoot, String groupId, String artifactId, String version) { - File lib = new File(engineRoot, artifactId + ".jar"); + File lib = new File(engineRoot, String.format("%s-%s.jar", artifactId, version)); if (!lib.exists()) { Files.copy(new URL(MavenRepo + String.format("/%1$s/%2$s/%3$s/%2$s-%3$s.jar", diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java index 2b52666..6aa1415 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java @@ -9,12 +9,15 @@ import lombok.SneakyThrows; public class MiaoScriptNukkit extends PluginBase { private ScriptEngine engine; - @Override @SneakyThrows - public void onLoad() { + public MiaoScriptNukkit() { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger(), this); - engine.enableEngine(); + engine = new ScriptEngine(getDataFolder().getCanonicalPath(), super.getLogger(), this); + engine.loadEngine(); + } + + @Override + public void onLoad() { } @Override diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScriptSponge.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptSponge.java index 51710a0..fe96798 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScriptSponge.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptSponge.java @@ -1,7 +1,7 @@ package pw.yumc.MiaoScript; -import java.io.File; - +import com.google.inject.Inject; +import lombok.SneakyThrows; import org.slf4j.Logger; import org.spongepowered.api.config.ConfigDir; import org.spongepowered.api.event.Listener; @@ -11,8 +11,7 @@ import org.spongepowered.api.event.game.state.GameStartingServerEvent; import org.spongepowered.api.event.game.state.GameStoppingServerEvent; import org.spongepowered.api.plugin.Plugin; -import com.google.inject.Inject; -import lombok.SneakyThrows; +import java.io.File; /** * Created with IntelliJ IDEA @@ -20,7 +19,7 @@ import lombok.SneakyThrows; * @author 喵♂呜 * Created on 2017/10/25 20:35. */ -@Plugin(id = "miaoscript", name = "MiaoScript", version = "1.0", authors = "MiaoWoo") +@Plugin(id = "miaoscript", name = "MiaoScript", version = Base.VERSION, authors = "MiaoWoo") public class MiaoScriptSponge { private ScriptEngine engine; @Inject @@ -55,6 +54,7 @@ public class MiaoScriptSponge { public void reload(GameReloadEvent event) { engine.disableEngine(); engine = new ScriptEngine(pluginConfigDir.getCanonicalPath(), logger, this); + engine.loadEngine(); engine.enableEngine(); } } diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index ea2ae8a..04fe00e 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -3,7 +3,7 @@ var global = this; /** * Init MiaoScriptEngine Runtime */ -/*global base */ +/*global base ScriptEngineContextHolder*/ (function () { var Files = Java.type('java.nio.file.Files') var Paths = Java.type('java.nio.file.Paths') diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index 75cfe32..d86ab39 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -526,7 +526,12 @@ require.clear = __DynamicClear__ require.disable = __DynamicDisable__ require.setUpgradeMode = __setUpgradeMode__ - require.core_modules = CoreModules + require.internal = { + coreModules: CoreModules, + cacheModules: cacheModules, + cacheModuleIds: cacheModuleIds, + notFoundModules: notFoundModules, + } return require } @@ -540,7 +545,7 @@ var cacheModuleIdsFile = _canonical(new File(NODE_PATH, 'cacheModuleIds.json')) var localVersionLockFile = _canonical(new File(NODE_PATH, 'moduleVersionLock.json')) /** - * @type {{[key:string]:{[key:string]:string}}} cacheModuleIds + * @type {{[key:string]:{[key:string]:string}|string}} cacheModuleIds */ var cacheModuleIds = {} /** @@ -559,10 +564,14 @@ try { // @ts-ignore cacheModuleIds = JSON.parse(base.read(cacheModuleIdsFile)) + if (cacheModuleIds['@ccms-cache-module-root'] != NODE_PATH) { + throw new Error('canonicalRoot Change ' + cacheModuleIds['@ccms-cache-module-root'] + ' to ' + NODE_PATH + ' Clear Cache!') + } console.log('Read cacheModuleIds from file ' + cacheModuleIdsFile) } catch (error) { cacheModuleIds = {} - console.log('Initialization new cacheModuleIds') + cacheModuleIds['@ccms-cache-module-root'] = NODE_PATH + console.log('Initialization new cacheModuleIds: ' + error) } try { ModulesVersionLock = JSON.parse(fetchContent('http://ms.yumc.pw/api/plugin/download/name/version_lock')) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fa163a2..3f3aee1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,12 +1,22 @@ name: ${project.artifactId} description: ${project.description} -main: ${project.groupId}.${project.artifactId}.${project.artifactId} +main: ${project.groupId}.${project.artifactId}.${project.artifactId}Bukkit version: ${project.version} api-version: 1.13 author: MiaoWoo website: ${ciManagement.url} -load: STARTUP softdepend: -- PlaceholderAPI -- ProtocolLib -- Vault + - PlaceholderAPI + - AttributePlus + - PlayerPoints + - CrazyCrates + - ProtocolLib + - DragonCore + - MythicMobs + - WorldGuard + - Adyeshach + - WorldEdit + - SkillAPI + - TradeMe + - Chemdah + - Vault