Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Sep 15, 2021
1 parent 3298b5d commit 95c4e0d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 39 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
name: PaperShelled=-${{ env.RELEASE_VERSION }}.jar
path: build/libs/PaperShelled-${{ env.RELEASE_VERSION }}.jar
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.text.SimpleDateFormat

//file:noinspection GroovyUnusedAssignment
//file:noinspection GrUnresolvedAccess

Expand All @@ -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()
Expand All @@ -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'
Expand All @@ -40,7 +47,6 @@ jar {
}

shadowJar {
relocate 'joptsimple', 'cn.apisium.papershelled.jopt'
relocate 'com.google.common', 'cn.apisium.papershelled.guava'
archiveClassifier.set('')
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/cn/apisium/papershelled/PaperShelled.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cn/apisium/papershelled/PaperShelledAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down Expand Up @@ -71,7 +72,7 @@ public final File getDataFolder() {
*/
@NotNull
@Override
public final PluginLoader getPluginLoader() {
public final PaperShelledPluginLoader getPluginLoader() {
return loader;
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 95c4e0d

Please sign in to comment.