|
13 | 13 | import de.nightevolution.realisticplantgrowth.utils.rest.ModrinthVersion; |
14 | 14 | import org.bstats.bukkit.Metrics; |
15 | 15 | import org.bukkit.Bukkit; |
16 | | -import org.bukkit.Server; |
17 | 16 | import org.bukkit.World; |
18 | 17 | import org.bukkit.event.HandlerList; |
19 | 18 | import org.bukkit.plugin.PluginManager; |
@@ -119,60 +118,48 @@ private void checkServerFork() { |
119 | 118 | } |
120 | 119 |
|
121 | 120 | /** |
122 | | - * Checks the server version and initializes the appropriate {@link VersionMapper}.<p> |
| 121 | + * Checks the server version and initializes the appropriate {@link VersionMapper}. |
| 122 | + * <p> |
123 | 123 | * This method determines the server version by extracting it from the Bukkit server class package name. |
124 | 124 | * It then sets the corresponding version mapper based on the extracted version. |
125 | 125 | * |
126 | 126 | * @return {@code true} if the version check and initialization are successful, {@code false} otherwise. |
127 | 127 | */ |
128 | 128 | private boolean checkServerVersion() { |
129 | | - |
130 | | - int minorReleaseVersion; |
131 | | - int microReleaseVersion; |
| 129 | + int minorVersion; |
| 130 | + int microVersion; |
132 | 131 |
|
133 | 132 | try { |
| 133 | + // Extract version numbers from Bukkit version string |
| 134 | + String[] versionParts = Bukkit.getBukkitVersion().split("-")[0].split("\\."); |
| 135 | + minorVersion = Integer.parseInt(versionParts[1]); |
| 136 | + microVersion = versionParts.length >= 3 ? Integer.parseInt(versionParts[2]) : 0; |
134 | 137 |
|
135 | | - String[] versionString = Bukkit.getBukkitVersion().split("-")[0].split("\\."); |
136 | | - minorReleaseVersion = Integer.parseInt(versionString[1]); |
137 | | - |
138 | | - if (versionString.length >= 3) { |
139 | | - microReleaseVersion = Integer.parseInt(versionString[2]); |
140 | | - } else { |
141 | | - microReleaseVersion = 0; |
142 | | - } |
143 | | - |
144 | | - logger.log("Your server is running version 1." + minorReleaseVersion + "." + microReleaseVersion); |
145 | | - |
146 | | - } catch (ArrayIndexOutOfBoundsException | NumberFormatException whatVersionAreYouUsingException) { |
| 138 | + logger.log("Your server is running version 1." + minorVersion + "." + microVersion); |
| 139 | + } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { |
147 | 140 | logger.error("Error extracting server version: Unable to parse Bukkit version format."); |
148 | 141 | return false; |
149 | 142 | } |
150 | 143 |
|
151 | | - // Warn if the server version is a snapshot version |
| 144 | + // Warn if using a snapshot version of the plugin |
152 | 145 | if (pluginVersion.contains("SNAPSHOT")) { |
153 | 146 | logger.warn("You are using a snapshot version of RealisticPlantGrowth!"); |
154 | 147 | } |
155 | 148 |
|
156 | 149 | // Version below Minecraft 1.20.1 are not supported (due to createBlockState API change). |
157 | | - if (minorReleaseVersion < 20 || (minorReleaseVersion == 20 && microReleaseVersion == 0)) { |
| 150 | + if (minorVersion < 20 || (minorVersion == 20 && microVersion == 0)) { |
158 | 151 | logger.error("Unsupported server version: This plugin requires Minecraft 1.20.1 or higher."); |
159 | 152 | return false; |
160 | 153 | } |
161 | 154 |
|
162 | | - // Assign the correct VersionMapper based on the server version |
163 | | - if (minorReleaseVersion == 20 && microReleaseVersion <= 3) { |
| 155 | + // Initialize VersionMapper based on server version |
| 156 | + if (minorVersion == 20 && microVersion <= 3) { |
164 | 157 | versionMapper = new Version_1_20(); |
165 | 158 | logger.log("Implementation initialized for Minecraft 1.20.1 - 1.20.3."); |
166 | | - } |
167 | | - |
168 | | - // Version 1.20.4 - 1.21.3 |
169 | | - if (minorReleaseVersion <= 21 && microReleaseVersion <= 3) { |
| 159 | + } else if (minorVersion < 21 || (minorVersion == 21 && microVersion <= 3)) { |
170 | 160 | versionMapper = new Version_1_20_4(); |
171 | 161 | logger.log("Implementation initialized for Minecraft 1.20.4 - 1.21.3."); |
172 | | - } |
173 | | - |
174 | | - // Version >= 1.21.4 |
175 | | - else { |
| 162 | + } else { |
176 | 163 | versionMapper = new Version_1_21_4(); |
177 | 164 | logger.log("Implementation initialized for Minecraft 1.21.4 and above."); |
178 | 165 | } |
|
0 commit comments