Skip to content

Commit 7ce09dc

Browse files
committed
Update Checker fix, /holo fix
1 parent af0b740 commit 7ce09dc

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/main/java/eu/decentsoftware/holograms/api/DecentHolograms.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import eu.decentsoftware.holograms.api.nms.PacketListener;
1010
import eu.decentsoftware.holograms.api.player.PlayerListener;
1111
import eu.decentsoftware.holograms.api.utils.BungeeUtils;
12+
import eu.decentsoftware.holograms.api.utils.Common;
1213
import eu.decentsoftware.holograms.api.utils.DExecutor;
1314
import eu.decentsoftware.holograms.api.utils.UpdateChecker;
1415
import eu.decentsoftware.holograms.api.utils.tick.Ticker;
@@ -72,7 +73,7 @@ protected void enable() {
7273
if (Settings.CHECK_UPDATES.getValue()) {
7374
UpdateChecker updateChecker = new UpdateChecker(getPlugin(), 96927);
7475
updateChecker.getVersion((ver) -> {
75-
if (!ver.equals(Settings.getAPIVersion())) {
76+
if (Common.isVersionHigher(ver)) {
7677
Lang.sendUpdateMessage(Bukkit.getConsoleSender());
7778
updateAvailable = true;
7879
}

src/main/java/eu/decentsoftware/holograms/api/utils/Common.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eu.decentsoftware.holograms.api.utils;
22

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

138+
/**
139+
* Check whether the given version is higher than the current version.
140+
*
141+
* @param version The version.
142+
* @return Boolean.
143+
*/
144+
public static boolean isVersionHigher(String version) {
145+
if (!version.matches("(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?")) {
146+
return false;
147+
}
148+
String current = Settings.getAPIVersion();
149+
int[] i1 = splitVersion(version);
150+
int[] i2 = splitVersion(current);
151+
if (i1 == null || i2 == null) {
152+
return false;
153+
}
154+
return i1[0] > i2[0] // Major version is higher.
155+
|| (i1[0] == i2[0] && i1[1] > i2[1]) // Minor version is higher and major is the same.
156+
|| (i1[0] == i2[0] && i1[1] == i2[1] && i1[2] > i2[2]); // Major and minor versions are the same and patch is higher.
157+
}
158+
159+
private static int[] splitVersion(String version) {
160+
String[] spl = version == null ? null : version.split("\\.");
161+
if (spl == null || spl.length < 3) {
162+
return new int[0];
163+
}
164+
int[] arr = new int[spl.length];
165+
for (int i = 0; i < spl.length; i++) {
166+
arr[i] = parseInt(spl[i]);
167+
}
168+
return arr;
169+
}
170+
171+
private static int parseInt(String string) {
172+
try {
173+
return Integer.parseInt(string);
174+
} catch (NumberFormatException e) {
175+
return -1;
176+
}
177+
}
178+
137179
}

src/main/java/eu/decentsoftware/holograms/plugin/commands/HologramsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.stream.Collectors;
2222

2323
@CommandInfo(
24-
aliases = {"holograms", "hologram", "dh"},
24+
aliases = {"holograms", "hologram", "dh", "holo"},
2525
permission = "",
2626
usage = "/dh <args>",
2727
description = "The main DecentHolograms Command."

0 commit comments

Comments
 (0)