Skip to content

Commit 95c4e0d

Browse files
committed
Update
1 parent 3298b5d commit 95c4e0d

7 files changed

Lines changed: 67 additions & 39 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build Release
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Cache
13+
uses: actions/cache@v2
14+
with:
15+
path: |
16+
~/.gradle/caches
17+
~/.gradle/wrapper
18+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
19+
restore-keys: |
20+
${{ runner.os }}-gradle-
21+
- uses: actions/checkout@v2
22+
- name: Set up JDK 8
23+
uses: actions/setup-java@v2
24+
with:
25+
java-version: '8'
26+
distribution: 'adopt'
27+
- name: Set version env
28+
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
29+
- name: Grant execute permission for gradlew
30+
run: chmod +x gradlew
31+
- name: Build with Gradle
32+
run: ./gradlew build
33+
- name: Upload binaries to release
34+
uses: Shopify/upload-to-release@v1.0.1
35+
with:
36+
name: PaperShelled=-${{ env.RELEASE_VERSION }}.jar
37+
path: build/libs/PaperShelled-${{ env.RELEASE_VERSION }}.jar
38+
repo-token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PaperShelled
1+
# 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)
22

33
A Paper plugin mixin development framework.
44

build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.text.SimpleDateFormat
2+
13
//file:noinspection GroovyUnusedAssignment
24
//file:noinspection GrUnresolvedAccess
35

@@ -10,7 +12,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8
1012
targetCompatibility = JavaVersion.VERSION_1_8
1113

1214
group 'cn.apisium.papershelled'
13-
version '1.0-SNAPSHOT'
15+
def psVersion = version = System.getenv('RELEASE_VERSION') ?: '0.0.0-DEV'
1416

1517
repositories {
1618
mavenCentral()
@@ -32,6 +34,11 @@ dependencies {
3234

3335
jar {
3436
manifest {
37+
def sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z")
38+
sdf.setTimeZone(TimeZone.getTimeZone("GMT"))
39+
attributes 'Implementation-Title': 'PaperShelled'
40+
attributes 'Implementation-Version': psVersion
41+
attributes 'Implementation-Vendor': sdf.format(new Date())
3542
attributes 'Can-Redefine-Classes': 'true'
3643
attributes 'Can-Retransform-Classes': 'true'
3744
attributes 'Agent-Class': 'cn.apisium.papershelled.PaperShelledAgent'
@@ -40,7 +47,6 @@ jar {
4047
}
4148

4249
shadowJar {
43-
relocate 'joptsimple', 'cn.apisium.papershelled.jopt'
4450
relocate 'com.google.common', 'cn.apisium.papershelled.guava'
4551
archiveClassifier.set('')
4652
}

src/main/java/cn/apisium/papershelled/PaperShelled.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ protected static void init(Instrumentation instrumentation) throws Throwable {
2828
Files.createDirectories(pluginsPath);
2929
loader = new PaperShelledPluginLoader(instrumentation);
3030

31-
// new PaperShelledReferenceMapper("META-INF/mappings/reobf.tiny");
32-
3331
loadPlugins(pluginsPath).forEach(it -> {
3432
try {
3533
PaperShelledAgent.LOGGER.info("Loading " + it.getDescription().getFullName());

src/main/java/cn/apisium/papershelled/PaperShelledAgent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public void visitCode() {
6969
}
7070

7171
private static void initPaperShelled(Instrumentation instrumentation) {
72+
Package pkg = PaperShelledAgent.class.getPackage();
73+
LOGGER.info(pkg.getImplementationTitle() + " version: " + pkg.getImplementationVersion() +
74+
"(" + pkg.getImplementationVendor() + ")");
75+
LOGGER.info("You can get the latest updates from: https://github.com/Apisium/PaperShelled");
7276
System.setProperty("mixin.env.remapRefMap", "true");
7377
PaperShelledAgent.instrumentation = instrumentation;
7478
instrumentation.addTransformer(new Transformer());

src/main/java/cn/apisium/papershelled/plugin/PaperShelledPlugin.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
import org.bukkit.generator.ChunkGenerator;
1212
import org.bukkit.plugin.PluginBase;
1313
import org.bukkit.plugin.PluginDescriptionFile;
14-
import org.bukkit.plugin.PluginLoader;
1514
import org.jetbrains.annotations.NotNull;
1615
import org.jetbrains.annotations.Nullable;
1716

1817
import java.io.*;
19-
import java.net.URL;
20-
import java.net.URLConnection;
18+
import java.nio.file.Files;
19+
import java.nio.file.Path;
2120
import java.util.List;
2221
import java.util.Objects;
22+
import java.util.jar.JarEntry;
23+
import java.util.jar.JarFile;
2324
import java.util.logging.Level;
2425
import java.util.logging.Logger;
2526

@@ -42,7 +43,7 @@ public PaperShelledPlugin(@NotNull PaperShelledPluginLoader loader,
4243
this.paperShelledDescription = paperShelledDescription;
4344
this.description = description;
4445
this.file = file;
45-
dataFolder = file.getParentFile();
46+
dataFolder = new File(file.getParentFile(), description.getName());
4647
configFile = new File(dataFolder, "config.yml");
4748
logger = PaperShelledLogger.getLogger(description.getPrefix() == null ?
4849
description.getName() : description.getPrefix());
@@ -71,7 +72,7 @@ public final File getDataFolder() {
7172
*/
7273
@NotNull
7374
@Override
74-
public final PluginLoader getPluginLoader() {
75+
public final PaperShelledPluginLoader getPluginLoader() {
7576
return loader;
7677
}
7778

@@ -199,30 +200,17 @@ public void saveResource(@NotNull String resourcePath, boolean replace) {
199200
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + file);
200201
}
201202

202-
File outFile = new File(dataFolder, resourcePath);
203-
int lastIndex = resourcePath.lastIndexOf('/');
204-
File outDir = new File(dataFolder, resourcePath.substring(0, Math.max(lastIndex, 0)));
205-
206-
if (!outDir.exists()) {
207-
// noinspection ResultOfMethodCallIgnored
208-
outDir.mkdirs();
209-
}
203+
Path outFile = new File(dataFolder, resourcePath).toPath();
210204

211205
try {
212-
if (!outFile.exists() || replace) {
213-
OutputStream out = new FileOutputStream(outFile);
214-
byte[] buf = new byte[1024];
215-
int len;
216-
while ((len = in.read(buf)) > 0) {
217-
out.write(buf, 0, len);
218-
}
219-
out.close();
220-
in.close();
206+
if (outFile.getParent() != null) Files.createDirectories(outFile.getParent());
207+
if (!Files.exists(outFile) || replace) {
208+
Files.copy(in, outFile);
221209
} else {
222-
logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
210+
logger.log(Level.WARNING, "Could not save " + outFile + " because it already exists.");
223211
}
224212
} catch (IOException ex) {
225-
logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex);
213+
logger.log(Level.SEVERE, "Could not save " + outFile, ex);
226214
}
227215
}
228216

@@ -235,15 +223,10 @@ public InputStream getResource(@NotNull String filename) {
235223
}
236224

237225
try {
238-
URL url = getClass().getResource(filename);
239-
240-
if (url == null) {
241-
return null;
242-
}
243-
244-
URLConnection connection = url.openConnection();
245-
connection.setUseCaches(false);
246-
return connection.getInputStream();
226+
JarFile jar = loader.getPluginJar(description.getName());
227+
JarEntry entry = jar.getJarEntry(filename);
228+
if (entry == null) return null;
229+
return jar.getInputStream(entry);
247230
} catch (IOException ex) {
248231
return null;
249232
}

src/main/java/cn/apisium/papershelled/services/MixinService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public IContainerHandle getPrimaryContainer() {
8383

8484
@Override
8585
public InputStream getResourceAsStream(String name) {
86-
System.out.println(name);
8786
if (name.equals("mixin.refmap.json")) return refMap;
8887
try {
8988
String[] names = name.split("\\|", 2);

0 commit comments

Comments
 (0)