Skip to content

Commit 3495224

Browse files
author
Im-Fran
committed
+ Added VersioningUtil
* Updated API version in SuperPlugin
1 parent c60dec0 commit 3495224

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

src/main/java/xyz/theprogramsrc/supercoreapi/Base.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import xyz.theprogramsrc.supercoreapi.global.updater.SongodaUpdateChecker;
5+
import xyz.theprogramsrc.supercoreapi.global.utils.VersioningUtil;
56

67
/**
78
* This is a set of utils that need to be loaded before everything
@@ -24,24 +25,11 @@ public void onFailCheck() {
2425

2526
@Override
2627
public void onSuccessCheck(String lastVersion) {
27-
StringBuilder latest = new StringBuilder(lastVersion.split(" ")[0].replaceAll("\\.", "").replaceAll("[a-zA-Z]", "")),
28-
current = new StringBuilder(Base.this.plugin.SUPER_CORE_API_VERSION.split(" ")[0].replaceAll("\\.", "").replaceAll("[a-zA-Z]", ""));
29-
if(latest.length() > current.length()){
30-
int amount = latest.length() - current.length();
31-
for(int i = 0; i < amount; ++i){
32-
current.append("0");
33-
}
34-
}else if(current.length() > latest.length()){
35-
int amount = current.length() - latest.length();
36-
for(int i = 0; i < amount; ++i){
37-
latest.append("0");
38-
}
39-
}
40-
int l = Integer.parseInt(latest.toString()), c = Integer.parseInt(current.toString());
41-
if(l > c){
28+
int check = VersioningUtil.checkVersions(Base.this.plugin.SUPER_CORE_API_VERSION, lastVersion);
29+
if(check == 1){
4230
Base.this.plugin.log("&cNew update available for &3SuperCoreAPI &7("+lastVersion+")");
4331
Base.this.plugin.log("&cIf you're the developer of the plugin update the API, if you're a customer of a plugin using &3SuperCoreAPI&c please notify to the Developer.");
44-
}else if(l < c){
32+
}else if(check == 2){
4533
Base.this.plugin.log("&cIt seems like you're running a non-release version of &3SuperCoreAPI");
4634
Base.this.plugin.log("&cUnless you're the developer, you must use the version &7" + lastVersion);
4735
}

src/main/java/xyz/theprogramsrc/supercoreapi/SuperPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface SuperPlugin<PLUGIN> {
1818
/*
1919
* This need to be updated on every new release
2020
*/
21-
String SUPER_CORE_API_VERSION = "4.3.0";
21+
String SUPER_CORE_API_VERSION = "4.4.0";
2222

2323
/**
2424
* Gets if this plugin is paid, By default is set to true, but is recommended to change it if your plugin is free.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package xyz.theprogramsrc.supercoreapi.global.utils;
2+
3+
public class VersioningUtil {
4+
5+
/**
6+
* Check any type of version into numbers to check the version.
7+
*
8+
* @param currentVersion the current version (usually stored in the plugin.yml or bungee.yml)
9+
* @param latestVersion the latest version stored in the database, or the platform with the latest update
10+
* @return 1 if there latest version is higher than the current one; 2 if the current version is higher than the latest version; 0 if booth versions are the same
11+
*/
12+
public static int checkVersions(String currentVersion, String latestVersion){
13+
StringBuilder latest = new StringBuilder(latestVersion.split(" ")[0].replaceAll("\\.", "").replaceAll("[a-zA-Z]", "")),
14+
current = new StringBuilder(currentVersion.split(" ")[0].replaceAll("[^\\d.]", "").replaceAll("\\.", "").replaceAll("[a-zA-Z]", ""));
15+
if(latest.length() > current.length()){
16+
int amount = latest.length() - current.length();
17+
for(int i = 0; i < amount; ++i){
18+
current.append("0");
19+
}
20+
}else if(current.length() > latest.length()){
21+
int amount = current.length() - latest.length();
22+
for(int i = 0; i < amount; ++i){
23+
latest.append("0");
24+
}
25+
}
26+
int l = Integer.parseInt(latest.toString()), c = Integer.parseInt(current.toString());
27+
if(l > c){
28+
return 1;
29+
}else if(l < c){
30+
return 2;
31+
}else {
32+
return 0;
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)