diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0b60f80 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: Build Release + +on: + release: + types: + - created + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + - name: Set version env + run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: Upload binaries to release + uses: Shopify/upload-to-release@v1.0.1 + with: + name: PaperShelled=-${{ env.RELEASE_VERSION }}.jar + path: build/libs/PaperShelled-${{ env.RELEASE_VERSION }}.jar + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 7cedd68..4430f68 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PaperShelled +# PaperShelled [![](https://www.jitpack.io/v/Apisium/PaperShelled.svg)](https://www.jitpack.io/#Apisium/PaperShelled) [![Release](https://github.com/Apisium/PaperShelled/actions/workflows/release.yml/badge.svg)](https://github.com/Apisium/PaperShelled/actions/workflows/release.yml) A Paper plugin mixin development framework. diff --git a/build.gradle b/build.gradle index 732e055..25dd46e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import java.text.SimpleDateFormat + //file:noinspection GroovyUnusedAssignment //file:noinspection GrUnresolvedAccess @@ -10,7 +12,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 group 'cn.apisium.papershelled' -version '1.0-SNAPSHOT' +def psVersion = version = System.getenv('RELEASE_VERSION') ?: '0.0.0-DEV' repositories { mavenCentral() @@ -32,6 +34,11 @@ dependencies { jar { manifest { + def sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z") + sdf.setTimeZone(TimeZone.getTimeZone("GMT")) + attributes 'Implementation-Title': 'PaperShelled' + attributes 'Implementation-Version': psVersion + attributes 'Implementation-Vendor': sdf.format(new Date()) attributes 'Can-Redefine-Classes': 'true' attributes 'Can-Retransform-Classes': 'true' attributes 'Agent-Class': 'cn.apisium.papershelled.PaperShelledAgent' @@ -40,7 +47,6 @@ jar { } shadowJar { - relocate 'joptsimple', 'cn.apisium.papershelled.jopt' relocate 'com.google.common', 'cn.apisium.papershelled.guava' archiveClassifier.set('') } diff --git a/src/main/java/cn/apisium/papershelled/PaperShelled.java b/src/main/java/cn/apisium/papershelled/PaperShelled.java index 921db0d..598eded 100644 --- a/src/main/java/cn/apisium/papershelled/PaperShelled.java +++ b/src/main/java/cn/apisium/papershelled/PaperShelled.java @@ -28,8 +28,6 @@ protected static void init(Instrumentation instrumentation) throws Throwable { Files.createDirectories(pluginsPath); loader = new PaperShelledPluginLoader(instrumentation); -// new PaperShelledReferenceMapper("META-INF/mappings/reobf.tiny"); - loadPlugins(pluginsPath).forEach(it -> { try { PaperShelledAgent.LOGGER.info("Loading " + it.getDescription().getFullName()); diff --git a/src/main/java/cn/apisium/papershelled/PaperShelledAgent.java b/src/main/java/cn/apisium/papershelled/PaperShelledAgent.java index 2e8dbe7..d3ce200 100644 --- a/src/main/java/cn/apisium/papershelled/PaperShelledAgent.java +++ b/src/main/java/cn/apisium/papershelled/PaperShelledAgent.java @@ -69,6 +69,10 @@ public void visitCode() { } private static void initPaperShelled(Instrumentation instrumentation) { + Package pkg = PaperShelledAgent.class.getPackage(); + LOGGER.info(pkg.getImplementationTitle() + " version: " + pkg.getImplementationVersion() + + "(" + pkg.getImplementationVendor() + ")"); + LOGGER.info("You can get the latest updates from: https://github.com/Apisium/PaperShelled"); System.setProperty("mixin.env.remapRefMap", "true"); PaperShelledAgent.instrumentation = instrumentation; instrumentation.addTransformer(new Transformer()); diff --git a/src/main/java/cn/apisium/papershelled/plugin/PaperShelledPlugin.java b/src/main/java/cn/apisium/papershelled/plugin/PaperShelledPlugin.java index b2f1bfb..4398a73 100644 --- a/src/main/java/cn/apisium/papershelled/plugin/PaperShelledPlugin.java +++ b/src/main/java/cn/apisium/papershelled/plugin/PaperShelledPlugin.java @@ -11,15 +11,16 @@ import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.PluginBase; import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginLoader; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.*; -import java.net.URL; -import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.Objects; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; @@ -42,7 +43,7 @@ public PaperShelledPlugin(@NotNull PaperShelledPluginLoader loader, this.paperShelledDescription = paperShelledDescription; this.description = description; this.file = file; - dataFolder = file.getParentFile(); + dataFolder = new File(file.getParentFile(), description.getName()); configFile = new File(dataFolder, "config.yml"); logger = PaperShelledLogger.getLogger(description.getPrefix() == null ? description.getName() : description.getPrefix()); @@ -71,7 +72,7 @@ public final File getDataFolder() { */ @NotNull @Override - public final PluginLoader getPluginLoader() { + public final PaperShelledPluginLoader getPluginLoader() { return loader; } @@ -199,30 +200,17 @@ public void saveResource(@NotNull String resourcePath, boolean replace) { throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + file); } - File outFile = new File(dataFolder, resourcePath); - int lastIndex = resourcePath.lastIndexOf('/'); - File outDir = new File(dataFolder, resourcePath.substring(0, Math.max(lastIndex, 0))); - - if (!outDir.exists()) { - // noinspection ResultOfMethodCallIgnored - outDir.mkdirs(); - } + Path outFile = new File(dataFolder, resourcePath).toPath(); try { - if (!outFile.exists() || replace) { - OutputStream out = new FileOutputStream(outFile); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.close(); - in.close(); + if (outFile.getParent() != null) Files.createDirectories(outFile.getParent()); + if (!Files.exists(outFile) || replace) { + Files.copy(in, outFile); } else { - logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists."); + logger.log(Level.WARNING, "Could not save " + outFile + " because it already exists."); } } catch (IOException ex) { - logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex); + logger.log(Level.SEVERE, "Could not save " + outFile, ex); } } @@ -235,15 +223,10 @@ public InputStream getResource(@NotNull String filename) { } try { - URL url = getClass().getResource(filename); - - if (url == null) { - return null; - } - - URLConnection connection = url.openConnection(); - connection.setUseCaches(false); - return connection.getInputStream(); + JarFile jar = loader.getPluginJar(description.getName()); + JarEntry entry = jar.getJarEntry(filename); + if (entry == null) return null; + return jar.getInputStream(entry); } catch (IOException ex) { return null; } diff --git a/src/main/java/cn/apisium/papershelled/services/MixinService.java b/src/main/java/cn/apisium/papershelled/services/MixinService.java index 560436f..981e682 100644 --- a/src/main/java/cn/apisium/papershelled/services/MixinService.java +++ b/src/main/java/cn/apisium/papershelled/services/MixinService.java @@ -83,7 +83,6 @@ public IContainerHandle getPrimaryContainer() { @Override public InputStream getResourceAsStream(String name) { - System.out.println(name); if (name.equals("mixin.refmap.json")) return refMap; try { String[] names = name.split("\\|", 2);