Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orebfuscator-nms/orebfuscator-nms-v1_16_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
2 changes: 1 addition & 1 deletion orebfuscator-nms/orebfuscator-nms-v1_16_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
2 changes: 1 addition & 1 deletion orebfuscator-nms/orebfuscator-nms-v1_16_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
2 changes: 1 addition & 1 deletion orebfuscator-nms/orebfuscator-nms-v1_17_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
2 changes: 1 addition & 1 deletion orebfuscator-nms/orebfuscator-nms-v1_18_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
2 changes: 1 addition & 1 deletion orebfuscator-nms/orebfuscator-nms-v1_18_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
2 changes: 1 addition & 1 deletion orebfuscator-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>${dependency.protocollib.version}</version>
<scope>provided</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@ private CompletableFuture<Optional<ModrinthVersion>> requestLatestVersion() {
}

var uri = String.format(API_URI, "bukkit", MinecraftVersion.current());
return HTTP.sendAsync(request(uri).build(), json(ModrinthVersion[].class)).thenApply(request -> {
var version = Version.parse(installedVersion);
var latestVersion = Arrays.stream(request.body())
.filter(e -> Objects.equals(e.versionType, "release"))
.filter(e -> Objects.equals(e.status, "listed"))
.sorted(Comparator.reverseOrder())
.findFirst();

latestVersion.ifPresentOrElse(
v -> OFCLogger.debug("UpdateSystem - Fetched latest version " + v.version),
() -> OFCLogger.debug("UpdateSystem - Couldn't fetch latest version"));

return latestVersion.map(v -> version.isBelow(v.version) ? v : null);
}).exceptionally(throwable -> {
return HTTP.sendAsync(request(uri).build(), optionalJson(ModrinthVersion[].class)).thenApply(response ->
response.body().flatMap(body -> {
var version = Version.parse(installedVersion);
var latestVersion = Arrays.stream(body)
.filter(e -> Objects.equals(e.versionType, "release"))
.filter(e -> Objects.equals(e.status, "listed"))
.sorted(Comparator.reverseOrder())
.findFirst();

latestVersion.ifPresentOrElse(
v -> OFCLogger.debug("UpdateSystem - Fetched latest version " + v.version),
() -> OFCLogger.debug("UpdateSystem - Couldn't fetch latest version"));

return latestVersion.map(v -> version.isBelow(v.version) ? v : null);
})
).exceptionally(throwable -> {
OFCLogger.log(Level.WARNING, "UpdateSystem - Unable to fetch latest version", throwable);
return Optional.empty();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ public void deserialize(ConfigurationSection section, ConfigParsingContext conte
}

// try create diskCache.directory
OFCLogger.debug("Using '" + this.baseDirectory.toAbsolutePath() + "' as chunk cache path");
try {
if (Files.notExists(this.baseDirectory)) {
Files.createDirectories(this.baseDirectory);
if (this.enableDiskCacheValue) {
OFCLogger.debug("Using '" + this.baseDirectory.toAbsolutePath() + "' as chunk cache path");
try {
if (Files.notExists(this.baseDirectory)) {
Files.createDirectories(this.baseDirectory);
}
} catch (IOException e) {
diskContext.error(String.format("can't create cache directory {%s}", e));
e.printStackTrace();
}
} catch (IOException e) {
diskContext.error(String.format("can't create cache directory {%s}", e));
e.printStackTrace();
}

// disable features if their config sections contain errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandler;
import java.net.http.HttpResponse.BodySubscribers;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import org.bukkit.plugin.PluginDescriptionFile;

Expand All @@ -27,7 +30,7 @@ public abstract class AbstractHttpService {

public AbstractHttpService(Orebfuscator orebfuscator) {
PluginDescriptionFile plugin = orebfuscator.getDescription();
this.userAgent = String.format("%s/%s", plugin.getName(), plugin.getVersion());
this.userAgent = String.format("Imprex-Development/%s/%s", plugin.getName(), plugin.getVersion());
}

protected HttpRequest.Builder request(String url) {
Expand All @@ -36,16 +39,15 @@ protected HttpRequest.Builder request(String url) {
.header("Accept", "application/json");
}

protected static <T> BodyHandler<T> json(Class<T> target) {
protected static <T> BodyHandler<Optional<T>> optionalJson(Class<T> target) {
return (responseInfo) -> responseInfo.statusCode() == 200
? BodySubscribers.mapping(BodySubscribers.ofInputStream(), inputStream -> {
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
return GSON.fromJson(new InputStreamReader(inputStream), target);
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
return Optional.ofNullable(GSON.fromJson(reader, target));
} catch (IOException e) {
e.printStackTrace();
return null;
throw new UncheckedIOException("I/O while reading JSON", e);
}
})
: BodySubscribers.replacing(null);
: BodySubscribers.replacing(Optional.empty());
}
}
18 changes: 8 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.imprex</groupId>
Expand All @@ -25,7 +27,7 @@
<dependency.bstats.version>3.1.0</dependency.bstats.version>
<dependency.junit.version>5.11.2</dependency.junit.version>
<dependency.netty.version>4.1.90.Final</dependency.netty.version>
<dependency.protocollib.version>5.0.0</dependency.protocollib.version>
<dependency.protocollib.version>5.3.0</dependency.protocollib.version>
<dependency.joml.version>1.10.8</dependency.joml.version>
<dependency.lz4.version>1.8.0</dependency.lz4.version>

Expand All @@ -43,10 +45,6 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
Expand Down Expand Up @@ -122,9 +120,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${plugin.sunfire.version}</version>
<configuration>
<junitArtifactName>org.junit.jupiter:junit-jupiter</junitArtifactName>
<trimStackTrace>false</trimStackTrace>
</configuration>
<junitArtifactName>org.junit.jupiter:junit-jupiter</junitArtifactName>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -161,7 +159,7 @@
</plugin>
</plugins>
</build>

<dependencies>
<!-- Test -->
<dependency>
Expand Down