Skip to content

Commit df3137f

Browse files
committed
1.0.3 release: ability to disable PNG recompression
1 parent 693a816 commit df3137f

File tree

6 files changed

+120
-36
lines changed

6 files changed

+120
-36
lines changed

.github/workflows/build.yml

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,67 @@
11
name: Java CI with Gradle
22

3-
on: [ push, pull_request ]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
build:
713
runs-on: ubuntu-latest
8-
strategy:
9-
matrix:
10-
java: [ 11, 17 ]
11-
fail-fast: true
1214
steps:
1315
- name: Checkout
14-
uses: actions/checkout@v3.0.1
15-
- name: Set up JDK ${{ matrix.java }}
16-
uses: actions/setup-java@v3.1.1
16+
uses: actions/checkout@v3.0.0
17+
- name: Set up JDK
18+
uses: actions/setup-java@v3.0.0
1719
with:
1820
distribution: adopt
19-
java-version: ${{ matrix.java }}
21+
java-version: 11
2022
- name: Build FastMOTD
2123
run: ./gradlew build
2224
- name: Upload FastMOTD
2325
uses: actions/upload-artifact@v3.0.0
2426
with:
25-
name: FastMOTD Built On ${{ matrix.java }} JDK
27+
name: FastMOTD
2628
path: "build/libs/FastMOTD*.jar"
2729
- uses: dev-drprasad/delete-tag-and-release@v0.2.0
30+
if: ${{ github.event_name == 'push' }}
2831
with:
2932
delete_release: true
30-
tag_name: dev-build-jdk-${{ matrix.java }}
33+
tag_name: dev-build
3134
env:
3235
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
- name: Find git version
37+
id: git-version
38+
run: echo "id=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
39+
- name: Find correct JAR
40+
if: ${{ github.event_name == 'push' }}
41+
id: find-jar
42+
run: |
43+
output="$(find build/libs/ ! -name "*-javadoc.jar" ! -name "*-sources.jar" -type f -printf "%f\n")"
44+
echo "::set-output name=jarname::$output"
3345
- name: Release the build
34-
uses: ncipollo/release-action@v1.10.0
46+
if: ${{ github.event_name == 'push' }}
47+
uses: ncipollo/release-action@v1
3548
with:
36-
artifacts: "build/libs/FastMOTD*.jar"
49+
artifacts: build/libs/${{ steps.find-jar.outputs.jarname }}
3750
body: ${{ join(github.event.commits.*.message, '\n') }}
3851
prerelease: true
39-
name: JDK ${{ matrix.java }} Dev-build
40-
tag: dev-build-jdk-${{ matrix.java }}
52+
name: Dev-build ${{ steps.git-version.outputs.id }}
53+
tag: dev-build
54+
- name: Upload to Modrinth
55+
if: ${{ github.event_name == 'push' }}
56+
uses: RubixDev/modrinth-upload@v1.0.0
57+
with:
58+
token: ${{ secrets.MODRINTH_TOKEN }}
59+
file_path: build/libs/${{ steps.find-jar.outputs.jarname }}
60+
name: Dev-build ${{ steps.git-version.outputs.id }}
61+
version: ${{ steps.git-version.outputs.id }}
62+
changelog: ${{ join(github.event.commits.*.message, '\n') }}
63+
game_versions: 1.7.2
64+
release_type: beta
65+
loaders: velocity
66+
featured: false
67+
project_id: OfMfkdiO

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Java CI with Gradle
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3.0.0
13+
- name: Set up JDK
14+
uses: actions/setup-java@v3.0.0
15+
with:
16+
distribution: adopt
17+
java-version: 11
18+
- name: Build FastMOTD
19+
run: ./gradlew build
20+
- name: Upload FastMOTD
21+
uses: actions/upload-artifact@v3.0.0
22+
with:
23+
name: FastMOTD
24+
path: "build/libs/FastMOTD*.jar"
25+
- name: Find correct JAR
26+
id: find-jar
27+
run: |
28+
output="$(find build/libs/ ! -name "*-javadoc.jar" ! -name "*-sources.jar" -type f -printf "%f\n")"
29+
echo "::set-output name=jarname::$output"
30+
- name: Upload to the GitHub release
31+
uses: actions/upload-release-asset@v1
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
with:
35+
upload_url: ${{ github.event.release.upload_url }}
36+
asset_path: build/libs/${{ steps.find-jar.outputs.jarname }}
37+
asset_name: ${{ steps.find-jar.outputs.jarname }}
38+
asset_content_type: application/java-archive
39+
- name: Upload to Modrinth
40+
uses: RubixDev/modrinth-upload@v1.0.0
41+
with:
42+
token: ${{ secrets.MODRINTH_TOKEN }}
43+
file_path: build/libs/${{ steps.find-jar.outputs.jarname }}
44+
name: Release ${{ github.event.release.tag_name }}
45+
version: ${{ github.event.release.tag_name }}
46+
changelog: ${{ github.event.release.body }}
47+
game_versions: 1.7.2
48+
release_type: release
49+
loaders: velocity
50+
featured: false
51+
project_id: OfMfkdiO

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.2
1+
1.0.3

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
setGroup("net.elytrium")
12-
setVersion("1.0.2")
12+
setVersion("1.0.3")
1313

1414
java {
1515
setSourceCompatibility(JavaVersion.VERSION_11)

src/main/java/net/elytrium/fastmotd/Settings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public static class MAIN {
6161
public int FAKE_ONLINE_ADD_PERCENT = 20;
6262
@Comment({
6363
"Accepted values: from 0.0 to 1.0.",
64-
"Keep this value as low as possible"
64+
"Keep this value as low as possible",
65+
"Set -1 to disable PNG recompression"
6566
})
6667
public double PNG_QUALITY = 0.0;
6768
public boolean LOG_PINGS = false;

src/main/java/net/elytrium/fastmotd/utils/MOTDGenerator.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,33 @@ private void generate(int i, String favicon) {
9191
}
9292

9393
private String getFavicon(Path faviconLocation) throws IOException {
94-
BufferedImage image = ImageIO.read(Files.newInputStream(faviconLocation));
95-
96-
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
97-
try (ImageOutputStream out = ImageIO.createImageOutputStream(outBytes)) {
98-
ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(image);
99-
ImageWriter writer = ImageIO.getImageWriters(type, "png").next();
100-
101-
ImageWriteParam param = writer.getDefaultWriteParam();
102-
if (param.canWriteCompressed()) {
103-
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
104-
param.setCompressionQuality((float) Settings.IMP.MAIN.PNG_QUALITY);
94+
byte[] imageBytes;
95+
96+
if (Settings.IMP.MAIN.PNG_QUALITY < 0) {
97+
imageBytes = Files.readAllBytes(faviconLocation);
98+
} else {
99+
BufferedImage image = ImageIO.read(Files.newInputStream(faviconLocation));
100+
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
101+
try (ImageOutputStream out = ImageIO.createImageOutputStream(outBytes)) {
102+
ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(image);
103+
ImageWriter writer = ImageIO.getImageWriters(type, "png").next();
104+
105+
ImageWriteParam param = writer.getDefaultWriteParam();
106+
if (param.canWriteCompressed()) {
107+
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
108+
param.setCompressionQuality((float) Settings.IMP.MAIN.PNG_QUALITY);
109+
}
110+
111+
writer.setOutput(out);
112+
writer.write(null, new IIOImage(image, null, null), param);
113+
writer.dispose();
105114
}
106115

107-
writer.setOutput(out);
108-
writer.write(null, new IIOImage(image, null, null), param);
109-
writer.dispose();
116+
imageBytes = outBytes.toByteArray();
117+
outBytes.close();
110118
}
111119

112-
String favicon = "data:image/png;base64," + Base64.getEncoder().encodeToString(outBytes.toByteArray());
113-
outBytes.close();
114-
115-
return favicon;
120+
return "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes);
116121
}
117122

118123
public void update(int max, int online) {

0 commit comments

Comments
 (0)