forked from Upstream/CommandPanels
Reimplement MC Version Checks and add Warning at Startup.
CommandPanels now warns the owner inside the console if the server runs an unsupported Version
This commit is contained in:
parent
bb50313587
commit
ba4195263b
@ -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"));
|
||||||
@ -519,17 +529,17 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//returns true if the item is the MMO Item
|
//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 {
|
try {
|
||||||
if (getServer().getPluginManager().isPluginEnabled("MMOItems")) {
|
if (getServer().getPluginManager().isPluginEnabled("MMOItems")) {
|
||||||
NBTItem nbt = NBTItem.get(itm);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
itm.getType();
|
itm.getType();
|
||||||
}
|
}
|
||||||
}catch (Exception ex){
|
} catch (Exception ex) {
|
||||||
debug(ex,null);
|
debug(ex, null);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
105
src/me/rockyhawk/commandpanels/MinecraftVersions.java
Normal file
105
src/me/rockyhawk/commandpanels/MinecraftVersions.java
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
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 if (serverMajorVersion == specifiedMajorVersion && serverMinorVersion <= specifiedMinorVersion) {
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 if (serverMajorVersion == specifiedMajorVersion && serverMinorVersion >= specifiedMinorVersion) {
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user