diff --git a/obf.dict b/obf.dict deleted file mode 100644 index 9ea3b95..0000000 --- a/obf.dict +++ /dev/null @@ -1,105 +0,0 @@ -™ -▄ -▒ -░ -▓ -™™ -▄™ -▒™ -░™ -▓™ -™▄ -▄▄ -▒▄ -░▄ -▓▄ -™▒ -▄▒ -▒▒ -░▒ -▓▒ -™░ -▄░ -▒░ -░░ -▓░ -™▓ -▄▓ -▒▓ -░▓ -▓▓ - ™ -™▄ -™▒ -™░ -™▓ -▄™ -▄▄ -▄▒ -▄░ -▄▓ -▒™ -▒▄ - ▒ -▒░ -▒▓ -░™ -░▄ -░▒ - ░ -░▓ -▓™ -▓▄ -▓▒ -▓░ - ▓ -™™™ -▄™▄ -▒™▒ -░™░ -▓™▓ -™▄™ -▄▄▄ -▒▄▒ -░▄░ -▓▄▓ -™▒™ -▄▒▄ -▒▒▒ -░▒░ -▓▒▓ -™░™ -▄░▄ -▒░▒ -░░░ -▓░▓ -™▓™ -▄▓▄ -▒▓▒ -░▓░ -▓▓▓ -™ ™ -™▄™ -™▒™ -™░™ -™▓™ -▄™▄ -▄ ▄ -▄▒▄ -▄░▄ -▄▓▄ -▒™▒ -▒▄▒ -▒ ▒ -▒░▒ -▒▓▒ -░™░ -░▄░ -░▒░ -░ ░ -░▓░ -▓™▓ -▓▄▓ -▓▒▓ -▓░▓ -▓ ▓ \ No newline at end of file diff --git a/pom.xml b/pom.xml index e459bed..a211852 100644 --- a/pom.xml +++ b/pom.xml @@ -23,59 +23,6 @@ true - - - org.apache.maven.plugins - maven-shade-plugin - 2.4.3 - - - package - - shade - - - false - true - - - pw.yumc:YumCore - - - - - pw.yumc.YumCore - ${project.groupId}.${project.artifactId} - - - - - - - - com.github.wvengen - proguard-maven-plugin - 2.0.13 - - - package - - proguard - - - - - - - - - ${java.home}/lib/rt.jar - - - - - - Jenkins @@ -181,21 +128,19 @@ - pw.yumc - YumCore - jar - 1.8.8 - - - org.bukkit - craftbukkit - - + org.projectlombok + lombok + 1.18.6 + + + org.spigotmc + spigot-api + 1.13.2-R0.1-SNAPSHOT org.spongepowered spongeapi - 6.0.0 + 7.1.0 \ No newline at end of file diff --git a/proguard.conf b/proguard.conf deleted file mode 100644 index 85d7127..0000000 --- a/proguard.conf +++ /dev/null @@ -1,61 +0,0 @@ -# -----不优化----- --dontoptimize - -# -----忽略所有警告----- --dontwarn --dontnote - -# -----混淆时应用侵入式重载----- --overloadaggressively - -# -----启用混淆字典----- --obfuscationdictionary obf.dict --classobfuscationdictionary obf.dict --packageobfuscationdictionary obf.dict - -# -----保留所有属性 --keepattributes ** - -# -----保护所有实体中的字段名称----- --keepclassmembers class * implements java.io.Serializable { ; } - -# -----保护监听方法不被清理----- --keepclassmembers class * implements org.bukkit.event.Listener { - @org.bukkit.event.EventHandler ; -} --keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener { - @net.md_5.bungee.event.EventHandler ; -} --keepclassmembers class * { - @org.spongepowered.api.event.Listener ; -} - -# -----保护继承事件不被清理----- --keep class ** extends org.bukkit.event.Event {*;} - -# -----保护枚举方法的完整性----- --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - -# -----保护配置注入不被清理----- --keepclassmembers class * extends **.config.inject.Inject** { - ; - public (org.bukkit.configuration.ConfigurationSection); -} - -# -----保护注解命令方法不被清理----- --keepclassmembers class **.commands.annotation.** {;} --keepclassmembers class * implements **.commands.interfaces.Executor {;} - -# -----保护注解命令方法不被清理----- --keep @org.spongepowered.api.plugin.Plugin class * {*;} - -# -----保护注解NotProguard标记----- --keep class **.NotProguard --keep @**.NotProguard class * {*;} --keepclassmembers class * { - @**.NotProguard ; - @**.NotProguard ; -} \ 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 2b4d154..c7029af 100644 --- a/src/main/java/pw/yumc/MiaoScript/Base.java +++ b/src/main/java/pw/yumc/MiaoScript/Base.java @@ -7,8 +7,6 @@ import java.nio.file.Path; import java.util.stream.Collectors; import lombok.val; -import pw.yumc.YumCore.annotation.NotProguard; -import pw.yumc.YumCore.mc.MinecraftTools; /** * Created with IntelliJ IDEA @@ -16,7 +14,6 @@ import pw.yumc.YumCore.mc.MinecraftTools; * @author 喵♂呜 * Created on 2017/10/9 12:40. */ -@NotProguard public class Base { public Class getClass(String name) throws ClassNotFoundException { return Class.forName(name); @@ -46,8 +43,4 @@ public class Base { } Files.delete(path); } - - public Class getTools() { - return MinecraftTools.class; - } } diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java new file mode 100644 index 0000000..a0fc88d --- /dev/null +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptEngine.java @@ -0,0 +1,182 @@ +package pw.yumc.MiaoScript; + +import java.io.File; +import java.io.Reader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashMap; + +import javax.script.Bindings; +import javax.script.Invocable; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; +import javax.script.SimpleBindings; + +import lombok.val; + +/** + * 喵式脚本引擎 + * + * @author 喵♂呜 + * @since 2016年8月29日 上午7:51:43 + */ +public class MiaoScriptEngine implements ScriptEngine, Invocable { + private static MiaoScriptEngine DEFAULT; + private static ScriptEngineManager manager; + private ScriptEngine engine; + + static { + manager = new ScriptEngineManager(ClassLoader.getSystemClassLoader()); + } + + public static void setBindings(Bindings bindings) { + manager.setBindings(bindings); + } + + public static Bindings getBindings() { + return manager.getBindings(); + } + + public MiaoScriptEngine() { + this("js"); + } + + public MiaoScriptEngine(final String engineType) { + this(manager, engineType); + } + + public MiaoScriptEngine(ScriptEngineManager engineManager) { + this(engineManager, "js"); + } + + public MiaoScriptEngine(ScriptEngineManager engineManager, final String engineType) { + try { + engine = engineManager.getEngineByName(engineType); + } catch (final NullPointerException ignored) { + } + if (engine == null) { + val dirs = System.getProperty("java.ext.dirs").split(File.pathSeparator); + for (String dir : dirs) { + File nashorn = new File(dir, "nashorn.jar"); + if (nashorn.exists()) { + try { + Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + // 设置方法的访问权限 + method.setAccessible(true); + // 获取系统类加载器 + URL url = nashorn.toURI().toURL(); + method.invoke(Thread.currentThread().getContextClassLoader(), url); + engineManager = new ScriptEngineManager(); + engine = engineManager.getEngineByName(engineType); + } catch (NoSuchMethodException | MalformedURLException | IllegalAccessException | InvocationTargetException | NullPointerException ignored) { + } + return; + } + } + throw new UnsupportedOperationException("当前环境不支持 " + engineType + " 脚本类型!"); + } + } + + public static MiaoScriptEngine getDefault() { + if (DEFAULT == null) { + DEFAULT = new MiaoScriptEngine(); + } + return DEFAULT; + } + + @Override + public Bindings createBindings() { + return new SimpleBindings(new HashMap<>(engine.getBindings(ScriptContext.GLOBAL_SCOPE))); + } + + @Override + public Object eval(final Reader reader) throws ScriptException { + return engine.eval(reader); + } + + @Override + public Object eval(final Reader reader, final Bindings n) throws ScriptException { + return engine.eval(reader, n); + } + + @Override + public Object eval(final Reader reader, final ScriptContext context) throws ScriptException { + return engine.eval(reader, context); + } + + @Override + public Object eval(final String script) throws ScriptException { + return engine.eval(script); + } + + @Override + public Object eval(final String script, final Bindings n) throws ScriptException { + return engine.eval(script, n); + } + + @Override + public Object eval(final String script, final ScriptContext context) throws ScriptException { + return engine.eval(script, context); + } + + @Override + public Object get(final String key) { + return engine.get(key); + } + + @Override + public Bindings getBindings(final int scope) { + return engine.getBindings(scope); + } + + @Override + public ScriptContext getContext() { + return engine.getContext(); + } + + @Override + public ScriptEngineFactory getFactory() { + return engine.getFactory(); + } + + @Override + public T getInterface(final Class clasz) { + return ((Invocable) engine).getInterface(clasz); + } + + @Override + public T getInterface(final Object thiz, final Class clasz) { + return ((Invocable) engine).getInterface(thiz, clasz); + } + + @Override + public Object invokeFunction(final String name, final Object... args) throws ScriptException, NoSuchMethodException { + return ((Invocable) engine).invokeFunction(name, args); + } + + @Override + public Object invokeMethod(final Object thiz, final String name, final Object... args) throws ScriptException, NoSuchMethodException { + return ((Invocable) engine).invokeMethod(thiz, name, args); + } + + @Override + public void put(final String key, final Object value) { + engine.put(key, value); + } + + @Override + public void setBindings(final Bindings bindings, final int scope) { + engine.setBindings(bindings, scope); + } + + @Override + public void setContext(final ScriptContext context) { + engine.setContext(context); + } +} diff --git a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java index 3f6f4df..6730c93 100644 --- a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java @@ -8,15 +8,12 @@ import java.nio.file.Paths; import javax.script.ScriptEngineManager; import lombok.SneakyThrows; -import pw.yumc.YumCore.annotation.NotProguard; -import pw.yumc.YumCore.engine.MiaoScriptEngine; /** * Created with IntelliJ IDEA * * @author 喵♂呜 * Created on 2017/10/25 21:01. */ -@NotProguard public class ScriptEngine { private String root; private Object logger;