Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6145c87
Merge pull request #1 from WirelessRedstoneGroup/master
Clarkcj12 Sep 9, 2019
6cd70ed
Merge branch 'WirelessRedstoneGroup:master' into master
Clarkcj12 Sep 17, 2021
106f2ed
Bump commons-io from 2.5 to 2.7 in /core
dependabot[bot] Sep 17, 2021
c36a4cc
Merge pull request #2 from Clarkcj12/dependabot/maven/core/commons-io…
Clarkcj12 Sep 17, 2021
1227065
Create dependabot.yml
Clarkcj12 Mar 30, 2022
b108a64
Bump maven-compiler-plugin from 3.8.1 to 3.10.1
dependabot[bot] Mar 30, 2022
3bae0b8
Bump slf4j-simple from 1.7.25 to 1.7.36
dependabot[bot] Mar 30, 2022
f481a7c
Bump worldedit-core from 6.1 to 7.2.8
dependabot[bot] Mar 30, 2022
384d9ec
Bump worldedit-bukkit from 6.1 to 7.2.8
dependabot[bot] Mar 30, 2022
1a21f88
Bump annotations from 13.0 to 23.0.0
dependabot[bot] Mar 30, 2022
80b409c
Merge pull request #3 from Clarkcj12/dependabot/maven/org.apache.mave…
Clarkcj12 Mar 30, 2022
27ff076
Merge pull request #4 from Clarkcj12/dependabot/maven/org.slf4j-slf4j…
Clarkcj12 Mar 30, 2022
fa53358
Merge pull request #5 from Clarkcj12/dependabot/maven/com.sk89q.world…
Clarkcj12 Mar 30, 2022
cd77ce8
Merge pull request #6 from Clarkcj12/dependabot/maven/com.sk89q.world…
Clarkcj12 Mar 30, 2022
94f8274
Merge pull request #7 from Clarkcj12/dependabot/maven/org.jetbrains-a…
Clarkcj12 Mar 30, 2022
29f38c4
Bump commons-io from 2.7 to 2.11.0
dependabot[bot] Mar 31, 2022
962da00
Bump gson from 2.8.5 to 2.9.0
dependabot[bot] Mar 31, 2022
557df47
Bump maven-shade-plugin from 3.2.1 to 3.3.0
dependabot[bot] Mar 31, 2022
77547e1
Merge pull request #10 from Clarkcj12/dependabot/maven/org.apache.mav…
Clarkcj12 Apr 3, 2022
abe5599
Merge pull request #9 from Clarkcj12/dependabot/maven/com.google.code…
Clarkcj12 Apr 3, 2022
aa12643
Merge pull request #8 from Clarkcj12/dependabot/maven/commons-io-comm…
Clarkcj12 Apr 3, 2022
31f385a
Bump gson from 2.9.0 to 2.9.1
dependabot[bot] Aug 1, 2022
dbba966
Bump slf4j-simple from 1.7.36 to 2.0.0
dependabot[bot] Aug 22, 2022
667600f
Merge pull request #11 from Clarkcj12/dependabot/maven/com.google.cod…
Clarkcj12 Sep 6, 2022
b7c69e3
Merge pull request #12 from Clarkcj12/dependabot/maven/org.slf4j-slf4…
Clarkcj12 Sep 6, 2022
fb54c00
Bump maven-shade-plugin from 3.3.0 to 3.4.0
dependabot[bot] Sep 15, 2022
2676d4b
Bump slf4j-simple from 2.0.0 to 2.0.1
dependabot[bot] Sep 15, 2022
3147783
Merge pull request #13 from Clarkcj12/dependabot/maven/org.apache.mav…
Clarkcj12 Sep 20, 2022
fe5bc4e
Merge pull request #14 from Clarkcj12/dependabot/maven/org.slf4j-slf4…
Clarkcj12 Sep 20, 2022
7083550
Bump slf4j-simple from 2.0.1 to 2.0.3
dependabot[bot] Sep 29, 2022
cea927e
Merge pull request #16 from Clarkcj12/dependabot/maven/org.slf4j-slf4…
Clarkcj12 Oct 20, 2022
1c3b61d
Bump maven-shade-plugin from 3.4.0 to 3.4.1
dependabot[bot] Oct 28, 2022
275f167
Bump slf4j-simple from 2.0.3 to 2.0.5
dependabot[bot] Nov 28, 2022
d62c57a
Merge pull request #17 from Clarkcj12/dependabot/maven/org.apache.mav…
Clarkcj12 Nov 28, 2022
e79ca9f
Merge pull request #19 from Clarkcj12/dependabot/maven/org.slf4j-slf4…
Clarkcj12 Nov 28, 2022
89e01b8
Bump slf4j-simple from 2.0.5 to 2.0.6
dependabot[bot] Dec 13, 2022
c6707bf
Bump annotations from 23.0.0 to 24.0.0
dependabot[bot] Jan 12, 2023
68bd6f2
Merge pull request #21 from Clarkcj12/dependabot/maven/org.slf4j-slf4…
Clarkcj12 Jan 17, 2023
a3f97e8
Merge pull request #22 from Clarkcj12/dependabot/maven/org.jetbrains-…
Clarkcj12 Jan 17, 2023
18a69eb
Update Java version, Minecraft version, and dependency
Clarkcj12 Mar 9, 2025
5478071
Upgrade dependencies and update Maven configurations
Clarkcj12 Mar 9, 2025
659ea75
Update Maven compiler plugin version and Java target/source
Clarkcj12 Mar 9, 2025
35637b3
Update dependencies and plugin versions in pom files
Clarkcj12 Mar 9, 2025
1711917
Update API version to 1.20.6 in plugin.yml
Clarkcj12 Mar 9, 2025
0d414b2
Switch to Paper API and update dependencies
Clarkcj12 Mar 9, 2025
094e605
Refactor onDisable to improve cleanup and logging.
Clarkcj12 Mar 9, 2025
92fa3de
Handle missing or unreadable plugin.yml gracefully
Clarkcj12 Mar 9, 2025
b075de3
Improve incompatibility logging for better debugging
Clarkcj12 Mar 9, 2025
37d02b7
Refactor main plugin structure and improve initialization
Clarkcj12 Mar 9, 2025
eb03324
Ensure null safety in command registration logic
Clarkcj12 Mar 9, 2025
2f554ff
Refactor WRLogger to use Optional for console field.
Clarkcj12 Mar 9, 2025
7efbff1
Refactor WRLogger for safer console handling with Optional
Clarkcj12 Mar 9, 2025
ea5cf2c
Refactor WRLogger to use Kyori Adventure API.
Clarkcj12 Mar 9, 2025
9a3b628
Refactor logging and code structure for clarity
Clarkcj12 Mar 9, 2025
f2d60ba
Refactor to integrate Adventure API for logging and messaging
Clarkcj12 Mar 9, 2025
63d2936
Enhance plugin initialization and lifecycle management
Clarkcj12 Mar 9, 2025
c3d260c
Refactor Utils method calls to support additional parameters
Clarkcj12 Mar 9, 2025
dccf9f8
Refactor `Utils` for improved code clarity and efficiency.
Clarkcj12 Mar 9, 2025
bed5af7
Refactor UpdateChecker to use modern HttpClient API
Clarkcj12 Mar 9, 2025
4eb77f1
Refactor logging and add `getStrings` method.
Clarkcj12 Mar 9, 2025
93b9970
Refactor utility methods and improve documentation.
Clarkcj12 Mar 9, 2025
d661fc9
Simplify imports in UpdateChecker.java
Clarkcj12 Mar 9, 2025
ab7b91d
Add StorageConfiguration initialization and accessor method
Clarkcj12 Mar 9, 2025
dfde863
Fix logical flow in hasAccessToChannel method
Clarkcj12 Mar 9, 2025
33cb334
Add stub for sendFeedback method in Utils
Clarkcj12 Mar 9, 2025
fd6acb6
Refactor AdminAddOwner command with enhanced validations.
Clarkcj12 Mar 9, 2025
16f79c5
Add Javadoc comments for AdminAddOwner command method
Clarkcj12 Mar 9, 2025
11c7402
Bump io.sentry:sentry from 1.7.23 to 8.3.0
dependabot[bot] Mar 10, 2025
e775d1d
Merge pull request #34 from Clarkcj12/dependabot/maven/io.sentry-sent…
Clarkcj12 Mar 10, 2025
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
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
27 changes: 19 additions & 8 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<dependencies>
<!-- Spigot API includes the Bukkit API and is what plugins generally use -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${project.cbversion}</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -53,13 +53,13 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<version>2.12.1</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>2.18.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.sentry/sentry -->
Expand All @@ -81,15 +81,26 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<version>2.0.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.19.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.4</version>
</dependency>
</dependencies>

<repositories>
<!-- Repo for access to CraftBukkit -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public boolean isWirelessRedstoneSign(Block block) {

Sign sign = (Sign) block.getState();

if (Utils.getSignType(sign.getLine(0)) == null || sign.getLine(1).equalsIgnoreCase("")) {
if (Utils.getType(sign.getLine(0), sign.getLine(2)) == null || sign.getLine(1).equalsIgnoreCase("")) {
return false;
}

Expand Down
217 changes: 131 additions & 86 deletions core/src/main/java/net/licks92/wirelessredstone/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -1,151 +1,196 @@
package net.licks92.wirelessredstone;

import com.github.zafarkhaja.semver.Version;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class UpdateChecker {

private static final String USER_AGENT = "WirelessRedstone-update-checker";
private static final String UPDATE_URL = "https://wirelessredstonegroup.github.io/WirelessRedstoneUpdate/update2.json";

private static UpdateChecker instance;

private UpdateResult lastResult = null;

private static volatile UpdateChecker instance; // Ensures thread-safety for singleton
private final JavaPlugin plugin;
private volatile UpdateResult lastResult; // Thread-safe storage
private final HttpClient httpClient; // Modern HTTP client for async requests

// Constructor
private UpdateChecker(JavaPlugin plugin) {
this.plugin = plugin;
this.httpClient = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NORMAL)
.build();
}

/**
* Initializes the UpdateChecker for the given plugin.
*/
public static UpdateChecker init(JavaPlugin plugin) {
Objects.requireNonNull(plugin, "Plugin object cannot be NULL");
if (instance == null) { // Double-checked locking for thread safety
synchronized (UpdateChecker.class) {
if (instance == null) {
instance = new UpdateChecker(plugin);
}
}
}
return instance;
}

return instance != null ? instance : (instance = new UpdateChecker(plugin));
/**
* Returns the current instance of UpdateChecker.
*
* @throws IllegalStateException if not initialized
*/
public static UpdateChecker getInstance() {
if (instance == null) {
throw new IllegalStateException("UpdateChecker is not initialized!");
}
return instance;
}

/**
* Performs an asynchronous update check.
*
* @return a CompletableFuture that completes with the update result.
*/
public CompletableFuture<UpdateResult> requestUpdateCheck() {
return CompletableFuture.supplyAsync(() -> {
try {
URL url = new URL(UPDATE_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
connection.addRequestProperty("User-Agent", USER_AGENT);
// Create HTTP request
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(UPDATE_URL))
.header("User-Agent", USER_AGENT)
.build();

// Send request and get response
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
plugin.getLogger().warning("Failed to fetch update info. HTTP Status: " + response.statusCode());
return new UpdateResult(UpdateReason.COULD_NOT_CONNECT, null, null, null);
}

InputStreamReader reader = new InputStreamReader(connection.getInputStream());
// Parse the response body
return parseResponse(response.body());
} catch (IOException | InterruptedException e) {
plugin.getLogger().severe("Failed to check for updates: " + e.getMessage());
return new UpdateResult(UpdateReason.COULD_NOT_CONNECT, null, null, null);
} catch (JsonSyntaxException e) {
plugin.getLogger().warning("Invalid JSON received from update server.");
return new UpdateResult(UpdateReason.INVALID_JSON, null, null, null);
}
});
}

JsonElement element = new JsonParser().parse(reader);
if (!element.isJsonObject()) {
return new UpdateResult(UpdateReason.INVALID_JSON);
}
/**
* Parses the JSON response to determine update results.
*/
private UpdateResult parseResponse(String responseBody) {
JsonElement rootElement = JsonParser.parseString(responseBody);
if (!rootElement.isJsonObject()) {
return new UpdateResult(UpdateReason.INVALID_JSON, null, null, null);
}

reader.close();
JsonObject root = rootElement.getAsJsonObject();
JsonObject latest = root.getAsJsonObject("latest");
JsonObject versions = root.getAsJsonObject("versions");

JsonObject versionObject = element.getAsJsonObject().getAsJsonObject("latest");
JsonObject versionsObject = element.getAsJsonObject().getAsJsonObject("versions");
String spigotVersion = latest.get("spigotversion").getAsString();
String currentVersion = plugin.getDescription().getVersion();

if (!versionsObject.has(versionObject.get("spigotversion").getAsString())) {
return new UpdateResult(UpdateReason.INVALID_JSON);
}
if (!versions.has(spigotVersion)) {
return new UpdateResult(UpdateReason.INVALID_JSON, null, null, null);
}

JsonObject updateObject = versionsObject.getAsJsonObject(versionObject.get("spigotversion").getAsString());
JsonObject updateData = versions.getAsJsonObject(spigotVersion);

Version current = Version.valueOf(plugin.getDescription().getVersion());
Version newest = Version.valueOf(versionObject.get("spigotversion").getAsString());
boolean isUpdateAvailable = versionGreaterThan(spigotVersion, currentVersion);
if (isUpdateAvailable) {
String downloadUrl = updateData.get("downloadUrl").getAsString();
List<String> changelog = IntStream.range(0, updateData.getAsJsonArray("changelog").size())
.mapToObj(i -> updateData.getAsJsonArray("changelog").get(i).getAsString())
.toList();

String updateUrl = updateObject.getAsJsonObject("spigot")
.get("downloadUrl").getAsString();
return new UpdateResult(UpdateReason.NEW_UPDATE, spigotVersion, downloadUrl, changelog);
}

List<String> changelog = IntStream
.range(0, updateObject.getAsJsonArray("changelog").size())
.mapToObj(i -> updateObject.getAsJsonArray("changelog").get(i).getAsString())
.collect(Collectors.toList());
return new UpdateResult(UpdateReason.UP_TO_DATE, currentVersion, null, null);
}

return newest.greaterThan(current) ? new UpdateResult(UpdateReason.NEW_UPDATE, newest.toString(), updateUrl, changelog) :
new UpdateResult(UpdateReason.UP_TO_DATE);
} catch (IOException e) {
e.printStackTrace();
return new UpdateResult(UpdateReason.COULD_NOT_CONNECT);
} catch (JsonSyntaxException e) {
return new UpdateResult(UpdateReason.INVALID_JSON);
}
});
/**
* Compares two version strings and determines if the first version is greater than the second.
* The versions are expected to be in a semantic versioning format.
*
* @param newVersion the new version string to compare, must not be null
* @param currentVersion the current version string to compare against, must not be null
* @return true if the new version is greater than the current version; false if not, or if an exception occurs
*/
private boolean versionGreaterThan(@NotNull String newVersion, @NotNull String currentVersion) {
try {
var newVer = com.github.zafarkhaja.semver.Version.valueOf(newVersion);
var currentVer = com.github.zafarkhaja.semver.Version.valueOf(currentVersion);

return newVer.greaterThan(currentVer);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("Invalid version string provided: " + e.getMessage());
}
return false;
}

/**
* Returns the result of the last update check performed by the UpdateChecker.
*
* @return the {@link UpdateResult} object containing information about the update
* check, such as the update reason, newest version, download URL, and changelog.
*/
public UpdateResult getLastResult() {
return lastResult;
}

// Enum for update reason explanations
public enum UpdateReason {
NEW_UPDATE, UP_TO_DATE, COULD_NOT_CONNECT, INVALID_JSON;
NEW_UPDATE, UP_TO_DATE, COULD_NOT_CONNECT, INVALID_JSON
}

public final class UpdateResult {
private final UpdateReason reason;
private final String newestVersion, url;
private List<String> changelog;

{
UpdateChecker.this.lastResult = this;
}

private UpdateResult(UpdateReason reason, String newestVersion, String url, List<String> changelog) {
this.reason = reason;
this.newestVersion = newestVersion;
this.url = url;
this.changelog = changelog;
}

private UpdateResult(UpdateReason reason) {
if (reason == UpdateReason.NEW_UPDATE) {
throw new IllegalArgumentException("Reasons that require updates must also provide the latest version, URL and changelog");
}

this.reason = reason;
this.newestVersion = plugin.getDescription().getVersion();
this.url = null;
this.changelog = null;
}
/**
* Record to represent the result of an update check.
*/
public record UpdateResult(UpdateReason reason, String newestVersion,
String downloadUrl, List<String> changelog) {

public boolean updateAvailable() {
return this.reason == UpdateReason.NEW_UPDATE;
}

public String getNewestVersion() {
return newestVersion;
}

public String getUrl() {
return url;
}

public List<String> getChangelog() {
return changelog;
return reason == UpdateChecker.UpdateReason.NEW_UPDATE;
}

@Override
public String toString() {
return "UpdateResult{" +
"reason=" + reason +
", newestVersion='" + newestVersion + '\'' +
", url='" + url + '\'' +
", downloadUrl='" + downloadUrl + '\'' +
", changelog=" + changelog +
'}';
}

public String getNewestVersion() {
return newestVersion;
}

public String getUrl() {
return downloadUrl;
}
}
}
}
Loading