diff --git a/Plugin/pom.xml b/Plugin/pom.xml
index a05ba777..0be84e79 100644
--- a/Plugin/pom.xml
+++ b/Plugin/pom.xml
@@ -14,7 +14,6 @@
21
UTF-8
-
1.21.11
diff --git a/Plugin/src/main/java/dev/lrxh/neptune/Neptune.java b/Plugin/src/main/java/dev/lrxh/neptune/Neptune.java
index a553d2d7..867cb52d 100644
--- a/Plugin/src/main/java/dev/lrxh/neptune/Neptune.java
+++ b/Plugin/src/main/java/dev/lrxh/neptune/Neptune.java
@@ -72,9 +72,7 @@
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
-import java.util.Arrays;
-import java.util.Optional;
-import java.util.UUID;
+import java.util.*;
import java.util.function.Consumer;
@Getter
diff --git a/Plugin/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java b/Plugin/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java
index 3241e908..2c0cbfdd 100644
--- a/Plugin/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java
+++ b/Plugin/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java
@@ -13,6 +13,7 @@
@Getter
public enum SettingsLocale implements IDataAccessor {
+ CHECK_FOR_UPDATES("CHECK_FOR_UPDATES", DataType.BOOLEAN, "true"),
FRIENDLY_FIRE("FRIENDLY_FIRE", DataType.BOOLEAN, "false"),
COMMANDS_AFTER_MATCH_WINNER("COMMAND_AFTER_MATCH.WINNER", DataType.STRING_LIST, "NONE"),
COMMANDS_AFTER_MATCH_LOSER("COMMAND_AFTER_MATCH.LOSER", DataType.STRING_LIST, "NONE"),
diff --git a/Plugin/src/main/java/dev/lrxh/neptune/providers/listeners/GlobalListener.java b/Plugin/src/main/java/dev/lrxh/neptune/providers/listeners/GlobalListener.java
index 2faad47c..46605858 100644
--- a/Plugin/src/main/java/dev/lrxh/neptune/providers/listeners/GlobalListener.java
+++ b/Plugin/src/main/java/dev/lrxh/neptune/providers/listeners/GlobalListener.java
@@ -7,6 +7,7 @@
import dev.lrxh.neptune.feature.party.Party;
import dev.lrxh.neptune.profile.data.ProfileState;
import dev.lrxh.neptune.profile.impl.Profile;
+import dev.lrxh.neptune.utils.UpdateChecker;
import dev.lrxh.neptune.utils.tasks.NeptuneRunnable;
import dev.lrxh.neptune.utils.tasks.TaskScheduler;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@@ -24,6 +25,7 @@
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
+import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.metadata.FixedMetadataValue;
@@ -32,13 +34,17 @@
import java.util.Objects;
public class GlobalListener implements Listener {
-
private boolean isPlayerNotInMatch(Profile profile) {
if (profile == null) return true;
ProfileState state = profile.getState();
return !state.equals(ProfileState.IN_GAME) && !state.equals(ProfileState.IN_SPECTATOR) || profile.getMatch() == null;
}
+ @EventHandler
+ public void updateCheck(ServerLoadEvent e) {
+ UpdateChecker.run();
+ }
+
@EventHandler
public void onCreatureSpawnEvent(CreatureSpawnEvent event) {
if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.BUCKET)) {
diff --git a/Plugin/src/main/java/dev/lrxh/neptune/utils/UpdateChecker.java b/Plugin/src/main/java/dev/lrxh/neptune/utils/UpdateChecker.java
new file mode 100644
index 00000000..98cd1be9
--- /dev/null
+++ b/Plugin/src/main/java/dev/lrxh/neptune/utils/UpdateChecker.java
@@ -0,0 +1,45 @@
+package dev.lrxh.neptune.utils;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import dev.lrxh.neptune.Neptune;
+import dev.lrxh.neptune.configs.impl.SettingsLocale;
+import lombok.experimental.UtilityClass;
+import org.bukkit.Bukkit;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.Objects;
+
+@UtilityClass
+public class UpdateChecker {
+ int behindBy = 0;
+ private void checkForUpdates() throws IOException, InterruptedException {
+ if (!SettingsLocale.CHECK_FOR_UPDATES.getBoolean()) return;
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("https://api.github.com/repos/Solara-Development/Neptune/compare/master..." + GithubUtils.getCommitId()))
+ .header("Accept", "application/vnd.github+json")
+ .build();
+ HttpClient client = HttpClient.newHttpClient();
+ HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ JsonObject json = JsonParser.parseString(response.body()).getAsJsonObject();
+ String status = json.get("status").getAsString();
+ if (Objects.equals(status, "behind")) {
+ behindBy = json.get("behind_by").getAsInt();
+ Neptune.get().getLogger().info("Your Neptune version is behind by " + behindBy + (behindBy == 1 ? " version" : " versions") + "!");
+ Neptune.get().getLogger().info("It is recommended to update to the latest version available here: https://github.com/Solara-Development/Neptune#-installation");
+ }
+ }
+ public void run() {
+ Bukkit.getScheduler().runTaskAsynchronously(Neptune.get(), () -> {
+ try {
+ checkForUpdates();
+ } catch (Exception e) {
+ Neptune.get().getLogger().warning("Failed to check for updates! " + e.getMessage());
+ }
+ });
+ }
+}