Skip to content

Commit

Permalink
Update Checker fix, /holo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
d0by1 committed Nov 27, 2021
1 parent af0b740 commit 7ce09dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import eu.decentsoftware.holograms.api.nms.PacketListener;
import eu.decentsoftware.holograms.api.player.PlayerListener;
import eu.decentsoftware.holograms.api.utils.BungeeUtils;
import eu.decentsoftware.holograms.api.utils.Common;
import eu.decentsoftware.holograms.api.utils.DExecutor;
import eu.decentsoftware.holograms.api.utils.UpdateChecker;
import eu.decentsoftware.holograms.api.utils.tick.Ticker;
Expand Down Expand Up @@ -72,7 +73,7 @@ protected void enable() {
if (Settings.CHECK_UPDATES.getValue()) {
UpdateChecker updateChecker = new UpdateChecker(getPlugin(), 96927);
updateChecker.getVersion((ver) -> {
if (!ver.equals(Settings.getAPIVersion())) {
if (Common.isVersionHigher(ver)) {
Lang.sendUpdateMessage(Bukkit.getConsoleSender());
updateAvailable = true;
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/eu/decentsoftware/holograms/api/utils/Common.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.decentsoftware.holograms.api.utils;

import eu.decentsoftware.holograms.api.Settings;
import eu.decentsoftware.holograms.api.utils.color.IridiumColorAPI;
import eu.decentsoftware.holograms.api.utils.reflect.ReflectionUtil;
import eu.decentsoftware.holograms.api.utils.reflect.Version;
Expand Down Expand Up @@ -134,4 +135,45 @@ public static String removeSpacingChars(String string) {
return SPACING_CHARS_REGEX.matcher(string).replaceAll("");
}

/**
* Check whether the given version is higher than the current version.
*
* @param version The version.
* @return Boolean.
*/
public static boolean isVersionHigher(String version) {
if (!version.matches("(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?")) {
return false;
}
String current = Settings.getAPIVersion();
int[] i1 = splitVersion(version);
int[] i2 = splitVersion(current);
if (i1 == null || i2 == null) {
return false;
}
return i1[0] > i2[0] // Major version is higher.
|| (i1[0] == i2[0] && i1[1] > i2[1]) // Minor version is higher and major is the same.
|| (i1[0] == i2[0] && i1[1] == i2[1] && i1[2] > i2[2]); // Major and minor versions are the same and patch is higher.
}

private static int[] splitVersion(String version) {
String[] spl = version == null ? null : version.split("\\.");
if (spl == null || spl.length < 3) {
return new int[0];
}
int[] arr = new int[spl.length];
for (int i = 0; i < spl.length; i++) {
arr[i] = parseInt(spl[i]);
}
return arr;
}

private static int parseInt(String string) {
try {
return Integer.parseInt(string);
} catch (NumberFormatException e) {
return -1;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.stream.Collectors;

@CommandInfo(
aliases = {"holograms", "hologram", "dh"},
aliases = {"holograms", "hologram", "dh", "holo"},
permission = "",
usage = "/dh <args>",
description = "The main DecentHolograms Command."
Expand Down

0 comments on commit 7ce09dc

Please sign in to comment.