Skip to content

Commit

Permalink
Merge remote-tracking branch 'Slimefun/master'
Browse files Browse the repository at this point in the history
Build 1144
  • Loading branch information
xMikux committed Apr 1, 2024
2 parents 24c58b8 + f4581e4 commit 3a5dcac
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 119 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish build

on:
push:
branches:
- master
- stable

jobs:
publish:
name: Upload build
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, '[ci skip]') == false

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/[email protected]
with:
distribution: 'adopt'
java-version: '17'
java-package: jdk
architecture: x64

- name: Build with Maven
run: mvn clean package

- name: Upload to Blob Builds
uses: WalshyDev/blob-builds/gh-action@f3da5ce7b7e2b70eb963e0c0014677b3d78c10fa
with:
project: Slimefun4
releaseChannel: ${{ github.ref == 'refs/heads/master' && 'Dev' || 'RC' }}
apiToken: ${{ secrets.BLOB_BUILDS_API_TOKEN }}
file: './target/Slimefun v4.9-UNOFFICIAL.jar'
releaseNotes: ${{ github.event.head_commit.message }}
2 changes: 1 addition & 1 deletion .github/workflows/release-candidates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
Slimefun4的穩定版本可以在這裡下載:
**官方英文版**
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/Slimefun4-${{ github.event.inputs.number }}.jar
https://blob.build/project/Slimefun4/RC
**非官方繁體中文版**
尚未支持 如果有需要可在非官方Discord內進行建議!
Expand Down
31 changes: 29 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of contents
- [Release Candidate 37 (TBD)](#release-candidate-37-tbd)
- [Release Candidate 38 (TBD)](#release-candidate-38-tbd)
- [Release Candidate 37 (25 Feb 2024)](#release-candidate-37-25-feb-2024)
- [Release Candidate 36 (20 Dec 2023)](#release-candidate-36-20-dec-2023)
- [Release Candidate 35 (07 Jul 2023)](#release-candidate-35-07-jul-2023)
- [Release Candidate 34 (20 Jun 2023)](#release-candidate-34-20-jun-2023)
Expand Down Expand Up @@ -37,7 +38,33 @@
- [Release Candidate 2 (29 Sep 2019)](#release-candidate-2-29-sep-2019)
- [Release Candidate 1 (26 Sep 2019)](#release-candidate-1-26-sep-2019)

## Release Candidate 37 (TBD)
## Release Candidate 38 (TBD)

## Release Candidate 37 (25 Feb 2024)

#### Additions
* (API) Introduce SlimefunItemRegistryFinalizedEvent (#4099)
* Add update warning to /sf versions (#4096)
* Add new analytics service (#4067)

#### Changes
* Allow blocks to be dropped while in creative mode (#3934)
* Storage rewrite - Phase 1 (#4065)
* Temporarily disable senstive blocks check (#4077)
* Update MockBukkit to 1.20.4 along with existing tests (#4086)
* Move PlayerProfile saving off the main thread (#4119)

#### Fixes
* Fix contributor head being pullable (#4072)
* Fix backpack IDs not incrementing (#4081)
* Fix inventory being used when Slimefun block is broken (#4088)
* Fix items not being able to be placed on ancient altar (#4094)
* Update dough to fix item stacking issue (#4100)
* Fix slimefun block turning into a vanilla block if there are viewers (#4101)
* Fixes #4123 - Coal Generator will no longer be locked after researching (#4124)
* Fixes exhaustion when loading large profiles (#4127)
* Fixes guide search when using colored chat (#4125)
* Fix dupe glitch with backpacks (#4134)

## Release Candidate 36 (20 Dec 2023)

Expand Down
22 changes: 2 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
<!-- Dependency shading -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<version>3.5.1</version>

<configuration>
<!-- Relocate these to avoid clashes and conflicts -->
Expand All @@ -204,10 +204,6 @@
<pattern>io.papermc.lib</pattern>
<shadedPattern>io.github.thebusybiscuit.slimefun4.libraries.paperlib</shadedPattern>
</relocation>
<relocation>
<pattern>kong.unirest</pattern>
<shadedPattern>io.github.thebusybiscuit.slimefun4.libraries.unirest</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.lang</pattern>
<shadedPattern>io.github.thebusybiscuit.slimefun4.libraries.commons.lang</shadedPattern>
Expand Down Expand Up @@ -348,7 +344,7 @@
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-api</artifactId>
<version>0130f8d9ce</version>
<version>baf2d79f62</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -357,20 +353,6 @@
<version>1.0.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.14.5</version>
<scope>compile</scope>

<exclusions>
<exclusion>
<!-- No need to shade Gson, Spigot does that already -->
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Testing dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) {
.append(")").color(ChatColor.GRAY);
}

builder.append("\n");
builder.append("\n").event((HoverEvent) null);
// @formatter:on

if (Slimefun.getMetricsService().getVersion() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
import java.net.http.HttpResponse.BodySubscriber;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.atomic.AtomicInteger;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow.Subscription;
import java.util.logging.Level;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.bukkit.plugin.Plugin;

import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;

import io.github.bakedlibs.dough.common.CommonPatterns;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

import kong.unirest.GetRequest;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;

/**
* This Class represents a Metrics Service that sends data to https://bstats.org/
* This data is used to analyse the usage of this {@link Plugin}.
Expand Down Expand Up @@ -66,22 +75,12 @@ public class MetricsService {
private final Slimefun plugin;
private final File parentFolder;
private final File metricsModuleFile;
private final HttpClient client = HttpClient.newHttpClient();

private URLClassLoader moduleClassLoader;
private String metricVersion = null;
private boolean hasDownloadedUpdate = false;

static {
// @formatter:off (We want this to stay this nicely aligned :D )
Unirest.config()
.concurrency(2, 1)
.setDefaultHeader("User-Agent", "MetricsModule Auto-Updater")
.setDefaultHeader("Accept", "application/vnd.github.v3+json")
.enableCookieManagement(false)
.cookieSpec("ignoreCookies");
// @formatter:on
}

/**
* This constructs a new instance of our {@link MetricsService}.
*
Expand Down Expand Up @@ -199,20 +198,16 @@ public boolean checkForUpdate(@Nullable String currentVersion) {
*/
private int getLatestVersion() {
try {
HttpResponse<JsonNode> response = Unirest.get(RELEASES_URL).asJson();
HttpResponse<String> response = client.send(buildBaseRequest(URI.create(RELEASES_URL)), HttpResponse.BodyHandlers.ofString());

if (!response.isSuccess()) {
if (response.statusCode() < 200 || response.statusCode() >= 300) {
return -1;
}

JsonNode node = response.getBody();
JsonElement element = JsonParser.parseString(response.body());

if (node == null) {
return -1;
}

return node.getObject().getInt("tag_name");
} catch (UnirestException e) {
return element.getAsJsonObject().get("tag_name").getAsInt();
} catch (IOException | InterruptedException | JsonParseException e) {
plugin.getLogger().log(Level.WARNING, "無法獲取指標模組的最新建構:{0}", e.getMessage());
return -1;
}
Expand All @@ -235,19 +230,13 @@ private boolean download(int version) {
Files.delete(file.toPath());
}

AtomicInteger lastPercentPosted = new AtomicInteger();
GetRequest request = Unirest.get(DOWNLOAD_URL + "/" + version + "/" + JAR_NAME + ".jar");

HttpResponse<File> response = request.downloadMonitor((b, fileName, bytesWritten, totalBytes) -> {
int percent = (int) (20 * (Math.round((((double) bytesWritten / totalBytes) * 100) / 20)));
HttpResponse<Path> response = client.send(
buildBaseRequest(URI.create(DOWNLOAD_URL + "/" + version + "/" + JAR_NAME + ".jar")),
downloadMonitor(HttpResponse.BodyHandlers.ofFile(file.toPath()))
);

if (percent != 0 && percent != lastPercentPosted.get()) {
plugin.getLogger().info("# 下載中... " + percent + "% " + "(" + bytesWritten + "/" + totalBytes + " bytes)");
lastPercentPosted.set(percent);
}
}).asFile(file.getPath());

if (response.isSuccess()) {
if (response.statusCode() >= 200 && response.statusCode() < 300) {
plugin.getLogger().log(Level.INFO, "成功下載 {0} 建構:#{1}", new Object[] { JAR_NAME, version });

// Replace the metric file with the new one
Expand All @@ -258,8 +247,8 @@ private boolean download(int version) {
hasDownloadedUpdate = true;
return true;
}
} catch (UnirestException e) {
plugin.getLogger().log(Level.WARNING, "無法從建構頁面獲取最新的 Jar 檔案。也許 GitHub 服務中斷?回應:{0}", e.getMessage());
} catch (InterruptedException | JsonParseException e) {
plugin.getLogger().log(Level.WARNING, "無法從建構頁面上獲取最新 Jar 檔案。可能 GitHub 服務中斷?回應:{0}", e.getMessage());
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, "無法將舊的指標模組檔案替換為新的。請手動執行此操作!錯誤:{0}", e.getMessage());
}
Expand Down Expand Up @@ -287,4 +276,58 @@ public String getVersion() {
public boolean hasAutoUpdates() {
return Slimefun.instance().getConfig().getBoolean("metrics.auto-update");
}

private HttpRequest buildBaseRequest(@Nonnull URI uri) {
return HttpRequest.newBuilder()
.uri(uri)
.timeout(Duration.ofSeconds(5))
.header("User-Agent", "MetricsModule Auto-Updater")
.header("Accept", "application/vnd.github.v3+json")
.build();
}

private <T> BodyHandler<T> downloadMonitor(BodyHandler<T> h) {
return info -> new BodySubscriber<T>() {

private BodySubscriber<T> delegateSubscriber = h.apply(info);
private int lastPercentPosted = 0;
private long bytesWritten = 0;

@Override
public void onSubscribe(Subscription subscription) {
delegateSubscriber.onSubscribe(subscription);
}

@Override
public void onNext(List<ByteBuffer> item) {
bytesWritten += item.stream().mapToLong(ByteBuffer::capacity).sum();
long totalBytes = info.headers().firstValue("Content-Length").map(Long::parseLong).orElse(-1L);

int percent = (int) (20 * (Math.round((((double) bytesWritten / totalBytes) * 100) / 20)));

if (percent != 0 && percent != lastPercentPosted) {
plugin.getLogger().info("# 下載中... " + percent + "% " + "(" + bytesWritten + "/" + totalBytes + " bytes)");
lastPercentPosted = percent;
}

delegateSubscriber.onNext(item);
}

@Override
public void onError(Throwable throwable) {
delegateSubscriber.onError(throwable);

}

@Override
public void onComplete() {
delegateSubscriber.onComplete();
}

@Override
public CompletionStage<T> getBody() {
return delegateSubscriber.getBody();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import kong.unirest.JsonNode;
import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

class ContributionsConnector extends GitHubConnector {

Expand Down Expand Up @@ -90,11 +90,11 @@ public boolean hasFinished() {
}

@Override
public void onSuccess(@Nonnull JsonNode response) {
public void onSuccess(@Nonnull JsonElement response) {
finished = true;

if (response.isArray()) {
computeContributors(response.getArray());
if (response.isJsonArray()) {
computeContributors(response.getAsJsonArray());
} else {
Slimefun.logger().log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", response);
}
Expand Down Expand Up @@ -123,13 +123,13 @@ public Map<String, Object> getParameters() {
return parameters;
}

private void computeContributors(@Nonnull JSONArray array) {
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
private void computeContributors(@Nonnull JsonArray array) {
for (JsonElement element : array) {
JsonObject object = element.getAsJsonObject();

String name = object.getString("login");
int commits = object.getInt("contributions");
String profile = object.getString("html_url");
String name = object.get("login").getAsString();
int commits = object.get("contributions").getAsInt();
String profile = object.get("html_url").getAsString();

if (!ignoredAccounts.contains(name)) {
String username = aliases.getOrDefault(name, name);
Expand Down
Loading

0 comments on commit 3a5dcac

Please sign in to comment.