init: Create MiaoNashorn Project...
This commit is contained in:
commit
8467e4a85e
55
.gitignore
vendored
Normal file
55
.gitignore
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Eclipse stuff
|
||||||
|
/.settings
|
||||||
|
|
||||||
|
# netbeans
|
||||||
|
/nbproject
|
||||||
|
|
||||||
|
# we use maven!
|
||||||
|
/build.xml
|
||||||
|
|
||||||
|
# maven
|
||||||
|
/target
|
||||||
|
/repo
|
||||||
|
|
||||||
|
# vim
|
||||||
|
.*.sw[a-p]
|
||||||
|
|
||||||
|
# various other potential build files
|
||||||
|
/build
|
||||||
|
/bin
|
||||||
|
/dist
|
||||||
|
/manifest.mf
|
||||||
|
|
||||||
|
# Mac filesystem dust
|
||||||
|
*.DS_Store
|
||||||
|
|
||||||
|
# intellij
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Project Stuff
|
||||||
|
/src/main/resources/Soulbound
|
||||||
|
|
||||||
|
# Atlassian Stuff
|
||||||
|
/atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.settings
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# NodeJs PHP LOCK File
|
||||||
|
*.lock
|
||||||
|
|
||||||
|
# PHP Vendor
|
||||||
|
vendor/
|
||||||
|
|
||||||
|
# Minecraft Data
|
||||||
|
/world
|
||||||
|
**/node_modules/
|
95
pom.xml
Normal file
95
pom.xml
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>pw.yumc</groupId>
|
||||||
|
<artifactId>MiaoNashorn</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>502647092</id>
|
||||||
|
<name>MiaoWoo</name>
|
||||||
|
<email>admin@yumc.pw</email>
|
||||||
|
<url>http://www.yumc.pw</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<build>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>dev-plugins/**</exclude>
|
||||||
|
</excludes>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
<ciManagement>
|
||||||
|
<system>Jenkins</system>
|
||||||
|
<url>https://ci.yumc.pw/job/Minecraft/job/${project.artifactId}/</url>
|
||||||
|
</ciManagement>
|
||||||
|
<properties>
|
||||||
|
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
|
||||||
|
<update.changes>
|
||||||
|
</update.changes>
|
||||||
|
<update.changelog>
|
||||||
|
</update.changelog>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<repo.url>https://repo.yumc.pw</repo.url>
|
||||||
|
</properties>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>yumc-repo</id>
|
||||||
|
<url>${repo.url}/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sponge</id>
|
||||||
|
<url>https://repo.spongepowered.org/maven/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>yumc-repo</id>
|
||||||
|
<url>${repo.url}/repository/maven-public/</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>jtb</id>
|
||||||
|
<name>YUMC</name>
|
||||||
|
<url>${repo.url}/repository/yumcenter/</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.18</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.16.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spongepowered</groupId>
|
||||||
|
<artifactId>spongeapi</artifactId>
|
||||||
|
<version>7.2.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-api</artifactId>
|
||||||
|
<version>1.16-R0.4-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.nukkit</groupId>
|
||||||
|
<artifactId>nukkit</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
103
src/main/java/pw/yumc/MiaoNashorn/MiaoNashorn.java
Normal file
103
src/main/java/pw/yumc/MiaoNashorn/MiaoNashorn.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package pw.yumc.MiaoNashorn;
|
||||||
|
|
||||||
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喵式脚本
|
||||||
|
*
|
||||||
|
* @author 喵♂呜
|
||||||
|
* @since 2016年8月29日 上午7:50:39
|
||||||
|
*/
|
||||||
|
public class MiaoNashorn {
|
||||||
|
private static String MavenRepo = "https://maven.aliyun.com/repository/public";
|
||||||
|
private static final Object ucp;
|
||||||
|
private static final MethodHandle addURLMethodHandle;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
Field theUnsafe = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||||
|
theUnsafe.setAccessible(true);
|
||||||
|
Unsafe unsafe = (Unsafe) theUnsafe.get(null);
|
||||||
|
Field field = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
|
||||||
|
MethodHandles.Lookup lookup = (MethodHandles.Lookup) unsafe.getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
|
||||||
|
Field ucpField;
|
||||||
|
try {
|
||||||
|
ucpField = loader.getClass().getDeclaredField("ucp");
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
ucpField = loader.getClass().getSuperclass().getDeclaredField("ucp");
|
||||||
|
}
|
||||||
|
long offset = unsafe.objectFieldOffset(ucpField);
|
||||||
|
ucp = unsafe.getObject(loader, offset);
|
||||||
|
Method method = ucp.getClass().getDeclaredMethod("addURL", URL.class);
|
||||||
|
addURLMethodHandle = lookup.unreflect(method);
|
||||||
|
createEngine();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(String format, Object... args) {
|
||||||
|
System.out.println("[MiaoNashorn] " + String.format(format, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createEngine() throws Throwable {
|
||||||
|
String extDirs = System.getProperty("java.ext.dirs");
|
||||||
|
if (extDirs != null) {
|
||||||
|
String[] dirs = extDirs.split(File.pathSeparator);
|
||||||
|
for (String dir : dirs) {
|
||||||
|
File nashorn = new File(dir, "nashorn.jar");
|
||||||
|
if (nashorn.exists()) {
|
||||||
|
loadJar(nashorn);
|
||||||
|
System.out.println("扩展目录发现 Nashorn 已加载完成!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loadLocalNashorn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadLocalNashorn() throws Throwable {
|
||||||
|
File libRootFile = new File("plugins/MiaoNashorn", "libs");
|
||||||
|
libRootFile.mkdirs();
|
||||||
|
log("从云端加载 Nashorn 请稍候...");
|
||||||
|
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");
|
||||||
|
log("云端 Nashorn 已加载完成!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadJar(File file) throws Throwable {
|
||||||
|
addURLMethodHandle.invoke(ucp, file.toURI().toURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void downloadJar(String engineRoot, String groupId, String artifactId, String version) throws Throwable {
|
||||||
|
File lib = new File(engineRoot, artifactId + ".jar");
|
||||||
|
if (!lib.exists()) {
|
||||||
|
log("正在下载类库 %s 版本 %s 请稍候...", artifactId, version);
|
||||||
|
Files.copy(new URL(MavenRepo +
|
||||||
|
String.format("/%1$s/%2$s/%3$s/%2$s-%3$s.jar",
|
||||||
|
groupId.replace(".", "/"),
|
||||||
|
artifactId,
|
||||||
|
version)
|
||||||
|
).openStream(),
|
||||||
|
lib.toPath(),
|
||||||
|
StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
loadJar(lib);
|
||||||
|
}
|
||||||
|
}
|
15
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornBukkit.java
Normal file
15
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornBukkit.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package pw.yumc.MiaoNashorn;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喵式脚本
|
||||||
|
*
|
||||||
|
* @author 喵♂呜
|
||||||
|
* @since 2016年8月29日 上午7:50:39
|
||||||
|
*/
|
||||||
|
public class MiaoNashornBukkit extends JavaPlugin {
|
||||||
|
public MiaoNashornBukkit() {
|
||||||
|
new MiaoNashorn();
|
||||||
|
}
|
||||||
|
}
|
15
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornBungee.java
Normal file
15
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornBungee.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package pw.yumc.MiaoNashorn;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA
|
||||||
|
*
|
||||||
|
* @author MiaoWoo
|
||||||
|
* Created on 2020/1/14 16:02.
|
||||||
|
*/
|
||||||
|
public class MiaoNashornBungee extends Plugin {
|
||||||
|
public MiaoNashornBungee() {
|
||||||
|
new MiaoNashorn();
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornNukkit.java
Normal file
12
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornNukkit.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package pw.yumc.MiaoNashorn;
|
||||||
|
|
||||||
|
import cn.nukkit.plugin.PluginBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author MiaoWoo
|
||||||
|
*/
|
||||||
|
public class MiaoNashornNukkit extends PluginBase {
|
||||||
|
public MiaoNashornNukkit() {
|
||||||
|
new MiaoNashorn();
|
||||||
|
}
|
||||||
|
}
|
16
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornSponge.java
Normal file
16
src/main/java/pw/yumc/MiaoNashorn/MiaoNashornSponge.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package pw.yumc.MiaoNashorn;
|
||||||
|
|
||||||
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA
|
||||||
|
*
|
||||||
|
* @author 喵♂呜
|
||||||
|
* Created on 2017/10/25 20:35.
|
||||||
|
*/
|
||||||
|
@Plugin(id = "miaonashorn", name = "MiaoNashorn", version = "1.0", authors = "MiaoWoo")
|
||||||
|
public class MiaoNashornSponge {
|
||||||
|
public MiaoNashornSponge() {
|
||||||
|
new MiaoNashorn();
|
||||||
|
}
|
||||||
|
}
|
5
src/main/resources/bungee.yml
Normal file
5
src/main/resources/bungee.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: ${project.artifactId}
|
||||||
|
description: ${project.description}
|
||||||
|
main: ${project.groupId}.${project.artifactId}.${project.artifactId}Bungee
|
||||||
|
version: ${project.version}
|
||||||
|
author: MiaoWoo
|
6
src/main/resources/nukkit.yml
Normal file
6
src/main/resources/nukkit.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
name: ${project.artifactId}
|
||||||
|
description: ${project.description}
|
||||||
|
main: ${project.groupId}.${project.artifactId}.${project.artifactId}Nukkit
|
||||||
|
version: ${project.version}
|
||||||
|
api: "1.0.0"
|
||||||
|
author: MiaoWoo
|
8
src/main/resources/plugin.yml
Normal file
8
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
name: ${project.artifactId}
|
||||||
|
description: ${project.description}
|
||||||
|
main: ${project.groupId}.${project.artifactId}.${project.artifactId}Bukkit
|
||||||
|
version: ${project.version}
|
||||||
|
api-version: 1.13
|
||||||
|
author: MiaoWoo
|
||||||
|
website: ${ciManagement.url}
|
||||||
|
load: STARTUP
|
Loading…
Reference in New Issue
Block a user