forked from Upstream/CommandPanels
Merge pull request #313 from TheLonelyWolf1/master
Reimplement MC Version Checks and add Warning at Startup.
This commit is contained in:
commit
7ceddc926b
@ -112,6 +112,16 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Bukkit.getLogger().info("[CommandPanels] RockyHawk's CommandPanels v" + this.getDescription().getVersion() + " Plugin Loading...");
|
Bukkit.getLogger().info("[CommandPanels] RockyHawk's CommandPanels v" + this.getDescription().getVersion() + " Plugin Loading...");
|
||||||
|
|
||||||
|
// Check if Server is not supported by this version of CP
|
||||||
|
if(MinecraftVersions.lessThanOrEqualTo("1.20.5")){
|
||||||
|
Bukkit.getLogger().warning("======================================================");
|
||||||
|
Bukkit.getLogger().warning("CommandPanels v" + this.getDescription().getVersion() + " is developed for Minecraft 1.20.5 and newer!");
|
||||||
|
Bukkit.getLogger().warning("You're running on: " + Bukkit.getServer().getVersion());
|
||||||
|
Bukkit.getLogger().warning("Please Upgrade the server or downgrade the plugin!");
|
||||||
|
Bukkit.getLogger().warning("You can find other versions of the plugin on: https://commandpanels.net/download");
|
||||||
|
Bukkit.getLogger().warning("======================================================");
|
||||||
|
}
|
||||||
|
|
||||||
//register config files
|
//register config files
|
||||||
this.blockConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "blocks.yml"));
|
this.blockConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "blocks.yml"));
|
||||||
panelData.dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "data.yml"));
|
panelData.dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "data.yml"));
|
||||||
|
97
src/me/rockyhawk/commandpanels/MinecraftVersions.java
Normal file
97
src/me/rockyhawk/commandpanels/MinecraftVersions.java
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
package me.rockyhawk.commandpanels;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MinecraftVersions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the MC Version in multiple parts and returns them.
|
||||||
|
*
|
||||||
|
* @return String[]
|
||||||
|
*/
|
||||||
|
private static String[] getMinecraftVersionParts(){
|
||||||
|
String serverVersion = Bukkit.getServer().getVersion();
|
||||||
|
String[] versionParts = serverVersion.split(" "); // Splitting the version string by space
|
||||||
|
return versionParts[2].split("\\."); // Splitting the Minecraft version by dot
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the major MC version from the Server
|
||||||
|
* Example: Returns the 20 of 1.20.6.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
private static String getMajorVersion(){
|
||||||
|
String[] minecraftVersionParts = getMinecraftVersionParts();
|
||||||
|
// Returns the 20 of 1.20.6
|
||||||
|
return minecraftVersionParts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the minor MC version from the Server
|
||||||
|
* Example: Returns the 6 of 1.20.6.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
private static String getMinorVersion(){
|
||||||
|
String[] minecraftVersionParts = getMinecraftVersionParts();
|
||||||
|
|
||||||
|
// Returns the 6 of 1.20.6
|
||||||
|
return minecraftVersionParts[2];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the version of the Server is older or on the specified Version.
|
||||||
|
*
|
||||||
|
* @param specifiedVersion The version to check against
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static boolean lessThanOrEqualTo(String specifiedVersion){
|
||||||
|
// Split the Version into its parts
|
||||||
|
String[] specifiedVersionParts = specifiedVersion.split("\\.");
|
||||||
|
|
||||||
|
// Get the parts from the Version of the Server.
|
||||||
|
// The .replace turns 1.20.4) into 1.20.4
|
||||||
|
int serverMajorVersion = Integer.parseInt(String.valueOf(getMajorVersion()).replace(")", ""));
|
||||||
|
int serverMinorVersion = Integer.parseInt(String.valueOf(getMinorVersion()).replace(")", ""));
|
||||||
|
|
||||||
|
// Get the parts from the specified version
|
||||||
|
int specifiedMajorVersion = Integer.parseInt(specifiedVersionParts[1]);
|
||||||
|
int specifiedMinorVersion = Integer.parseInt(specifiedVersionParts[2]);
|
||||||
|
|
||||||
|
// If Major version is less or equal than the specified version.
|
||||||
|
if(serverMajorVersion < specifiedMajorVersion){
|
||||||
|
return true;
|
||||||
|
} // If Major version equal and Minor Version is less or equal than specified version.
|
||||||
|
else return serverMajorVersion == specifiedMajorVersion && serverMinorVersion <= specifiedMinorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the version of the Server is newer or on the specified Version.
|
||||||
|
*
|
||||||
|
* @param specifiedVersion The version to check against
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static boolean greaterThanOrEqualTo(String specifiedVersion){
|
||||||
|
// Split the Version into its parts
|
||||||
|
String[] specifiedVersionParts = specifiedVersion.split("\\.");
|
||||||
|
|
||||||
|
// Get the parts from the Version of the Server
|
||||||
|
// The .replace turns 1.20.4) into 1.20.4
|
||||||
|
int serverMajorVersion = Integer.parseInt(String.valueOf(getMajorVersion()).replace(")", ""));
|
||||||
|
int serverMinorVersion = Integer.parseInt(String.valueOf(getMinorVersion()).replace(")", ""));
|
||||||
|
|
||||||
|
// Get the parts from the specified version
|
||||||
|
int specifiedMajorVersion = Integer.parseInt(specifiedVersionParts[1]);
|
||||||
|
int specifiedMinorVersion = Integer.parseInt(specifiedVersionParts[2]);
|
||||||
|
|
||||||
|
// If Major version is less or equal than the specified version.
|
||||||
|
if(serverMajorVersion > specifiedMajorVersion){
|
||||||
|
return true;
|
||||||
|
} // If Major version equal and Minor Version is less or equal than specified version.
|
||||||
|
else return serverMajorVersion == specifiedMajorVersion && serverMinorVersion >= specifiedMinorVersion;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user