Merge pull request #313 from TheLonelyWolf1/master

Reimplement MC Version Checks and add Warning at Startup.
This commit is contained in:
RockyHawk 2024-05-07 17:33:52 +10:00 committed by GitHub
commit 7ceddc926b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 111 additions and 4 deletions

View File

@ -112,6 +112,16 @@ public class CommandPanels extends JavaPlugin{
public void onEnable() {
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
this.blockConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "blocks.yml"));
panelData.dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "data.yml"));
@ -520,17 +530,17 @@ public class CommandPanels extends JavaPlugin{
}
//returns true if the item is the MMO Item
public boolean isMMOItem(ItemStack itm, String type, String id){
public boolean isMMOItem(ItemStack itm, String type, String id) {
try {
if (getServer().getPluginManager().isPluginEnabled("MMOItems")) {
NBTItem nbt = NBTItem.get(itm);
if (nbt.getType().equalsIgnoreCase(type) && nbt.getString("MMOITEMS_ITEM_ID").equalsIgnoreCase(id)){
if (nbt.getType().equalsIgnoreCase(type) && nbt.getString("MMOITEMS_ITEM_ID").equalsIgnoreCase(id)) {
return true;
}
itm.getType();
}
}catch (Exception ex){
debug(ex,null);
} catch (Exception ex) {
debug(ex, null);
}
return false;
}

View 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;
}
}