File tree Expand file tree Collapse file tree
src/main/java/fr/snipertvmc/essentialsxgui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,43 @@ public Essentials getEssentials() {
4444 // -------------------------------------------------- //
4545
4646
47+ private final String minimumVersionRequired = "2.21.2" ;
48+
49+
50+ public String getMinimumVersionRequired () {
51+ return minimumVersionRequired ;
52+ }
53+
54+
55+ public boolean isEssentialsVersionSupported () {
56+
57+ String version = essentials .getDescription ().getVersion ();
58+ String cleanVersion = version .split ("-" )[0 ];
59+
60+ return isVersionGreaterOrEqual (cleanVersion , minimumVersionRequired );
61+ }
62+
63+
64+ private boolean isVersionGreaterOrEqual (String current , String minimum ) {
65+ String [] currentParts = current .split ("\\ ." );
66+ String [] minimumParts = minimum .split ("\\ ." );
67+
68+ int length = Math .max (currentParts .length , minimumParts .length );
69+
70+ for (int i = 0 ; i < length ; i ++) {
71+ int cur = (i < currentParts .length ) ? Integer .parseInt (currentParts [i ]) : 0 ;
72+ int min = (i < minimumParts .length ) ? Integer .parseInt (minimumParts [i ]) : 0 ;
73+
74+ if (cur > min ) return true ;
75+ if (cur < min ) return false ;
76+ }
77+ return true ;
78+ }
79+
80+
81+ // -------------------------------------------------- //
82+
83+
4784 public boolean canCreateHome (Player player ) {
4885 int homeLimit = essentials .getSettings ().getHomeLimit (essentials .getUser (player ));
4986 EXGPlayer exgPlayer = Main .getInstance ().getPlayerManager ().getPlayer (player .getUniqueId ().toString ());
Original file line number Diff line number Diff line change @@ -91,25 +91,25 @@ public void unloadPlugin(boolean detailedLoading) {
9191 // -------------------------------------------------- //
9292
9393
94- private final String essentialsVersionRequired = "2.21.2" ;
95-
96-
9794 public boolean isServerReady () {
9895
96+ String essentialsVersionRequired = Main .getInstance ().getHookManager ().getEssentialsHook ().getMinimumVersionRequired ();
97+
9998 if (Main .getInstance ().getEssentials () == null ) {
10099
101100 ConsoleLogger .console ("\t §6EssentialsX-GUI: §cEssentialsX is not installed on the server." );
102101 ConsoleLogger .console ("\t §6EssentialsX-GUI: §cPlease install EssentialsX (" + essentialsVersionRequired + ") to use this plugin." );
103102 return false ;
104103 }
105104
105+ boolean essentialsVersionSupported = Main .getInstance ().getHookManager ().getEssentialsHook ().isEssentialsVersionSupported ();
106106 String version = Main .getInstance ().getEssentials ().getDescription ().getVersion ();
107- String essentialsVersionColor = version . equals ( essentialsVersionRequired ) ? "§a" : "§c" ;
107+ String essentialsVersionColor = essentialsVersionSupported ? "§a" : "§c" ;
108108
109109 ConsoleLogger .console ("\t §6EssentialsX-GUI: §7EssentialsX version found: " + essentialsVersionColor + version );
110110
111- if (!version . equals ( essentialsVersionRequired ) ) {
112- ConsoleLogger .console ("\t §6EssentialsX-GUI: §cCurrent version is not supported. §4(Required version: §4" + essentialsVersionRequired + ")" );
111+ if (!essentialsVersionSupported ) {
112+ ConsoleLogger .console ("\t §6EssentialsX-GUI: §cCurrent version is not supported. §4(Minimum version required : §4" + essentialsVersionRequired + ")" );
113113 return false ;
114114 }
115115
You can’t perform that action at this time.
0 commit comments