From ea1b86c0347f5c1990060212dd9f1e1ffb0d7beb Mon Sep 17 00:00:00 2001 From: Intelli Date: Tue, 20 Aug 2024 14:13:44 -0600 Subject: [PATCH] Only start CoreProtect on supported Minecraft versions --- src/main/java/net/coreprotect/CoreProtect.java | 8 ++++++-- src/main/java/net/coreprotect/command/PurgeCommand.java | 5 +++++ src/main/java/net/coreprotect/config/ConfigHandler.java | 3 ++- src/main/java/net/coreprotect/language/Language.java | 2 ++ src/main/java/net/coreprotect/language/Phrase.java | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/coreprotect/CoreProtect.java b/src/main/java/net/coreprotect/CoreProtect.java index 7530af16..9bc8a2f5 100755 --- a/src/main/java/net/coreprotect/CoreProtect.java +++ b/src/main/java/net/coreprotect/CoreProtect.java @@ -137,8 +137,12 @@ public void onDisable() { private static boolean performVersionChecks() { try { String[] bukkitVersion = Bukkit.getServer().getBukkitVersion().split("[-.]"); - if (Util.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.SPIGOT_VERSION)) { - Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Spigot", ConfigHandler.SPIGOT_VERSION)); + if (Util.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.MINECRAFT_VERSION)) { + Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Minecraft", ConfigHandler.MINECRAFT_VERSION)); + return false; + } + if (Util.newVersion(ConfigHandler.LATEST_VERSION, bukkitVersion[0] + "." + bukkitVersion[1]) && Util.isBranch("master")) { + Chat.console(Phrase.build(Phrase.VERSION_INCOMPATIBLE, "Minecraft", bukkitVersion[0] + "." + bukkitVersion[1])); return false; } String[] javaVersion = (System.getProperty("java.version").replaceAll("[^0-9.]", "") + ".0").split("\\."); diff --git a/src/main/java/net/coreprotect/command/PurgeCommand.java b/src/main/java/net/coreprotect/command/PurgeCommand.java index e6f2dd2d..73f48976 100755 --- a/src/main/java/net/coreprotect/command/PurgeCommand.java +++ b/src/main/java/net/coreprotect/command/PurgeCommand.java @@ -104,6 +104,11 @@ else if (endTime < 86400) { int restrictCount = 0; if (argBlocks.size() > 0) { + if (!Util.validDonationKey()) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DONATION_KEY_REQUIRED)); + return; + } + StringBuilder includeListMaterial = new StringBuilder(); StringBuilder includeListEntity = new StringBuilder(); diff --git a/src/main/java/net/coreprotect/config/ConfigHandler.java b/src/main/java/net/coreprotect/config/ConfigHandler.java index ab13b92a..50a4ec1e 100644 --- a/src/main/java/net/coreprotect/config/ConfigHandler.java +++ b/src/main/java/net/coreprotect/config/ConfigHandler.java @@ -45,7 +45,8 @@ public class ConfigHandler extends Queue { public static final String EDITION_NAME = Util.getPluginName(); public static final String COMMUNITY_EDITION = "Community Edition"; public static final String JAVA_VERSION = "11.0"; - public static final String SPIGOT_VERSION = "1.15"; + public static final String MINECRAFT_VERSION = "1.15"; + public static final String LATEST_VERSION = "1.21"; public static String path = "plugins/CoreProtect/"; public static String sqlite = "database.db"; public static String host = "127.0.0.1"; diff --git a/src/main/java/net/coreprotect/language/Language.java b/src/main/java/net/coreprotect/language/Language.java index a19004da..91f703bc 100644 --- a/src/main/java/net/coreprotect/language/Language.java +++ b/src/main/java/net/coreprotect/language/Language.java @@ -55,6 +55,7 @@ public static void loadPhrases() { phrases.put(Phrase.DEVELOPMENT_BRANCH, "Development branch detected, skipping patch scripts."); phrases.put(Phrase.DIRT_BLOCK, "Placed a temporary safety block under you."); phrases.put(Phrase.DISABLE_SUCCESS, "Success! Disabled {0}"); + phrases.put(Phrase.DONATION_KEY_REQUIRED, "A valid donation key is required for that command."); phrases.put(Phrase.ENABLE_FAILED, "{0} was unable to start."); phrases.put(Phrase.ENABLE_SUCCESS, "{0} has been successfully enabled!"); phrases.put(Phrase.ENJOY_COREPROTECT, "Enjoy {0}? Join our Discord!"); @@ -232,6 +233,7 @@ public static void loadPhrases() { phrases.put(Phrase.USING_SQLITE, "Using SQLite for data storage."); phrases.put(Phrase.VALID_DONATION_KEY, "Valid donation key."); phrases.put(Phrase.VERSION_NOTICE, "Version {0} is now available."); + phrases.put(Phrase.VERSION_INCOMPATIBLE, "{0} {1} is not supported."); phrases.put(Phrase.VERSION_REQUIRED, "{0} {1} or higher is required."); phrases.put(Phrase.WORLD_NOT_FOUND, "World \"{0}\" not found."); diff --git a/src/main/java/net/coreprotect/language/Phrase.java b/src/main/java/net/coreprotect/language/Phrase.java index 89e487f2..d99c4c31 100644 --- a/src/main/java/net/coreprotect/language/Phrase.java +++ b/src/main/java/net/coreprotect/language/Phrase.java @@ -38,6 +38,7 @@ public enum Phrase { DEVELOPMENT_BRANCH, DIRT_BLOCK, DISABLE_SUCCESS, + DONATION_KEY_REQUIRED, ENABLE_FAILED, ENABLE_SUCCESS, ENJOY_COREPROTECT, @@ -215,6 +216,7 @@ public enum Phrase { USING_SQLITE, VALID_DONATION_KEY, VERSION_NOTICE, + VERSION_INCOMPATIBLE, VERSION_REQUIRED, WORLD_NOT_FOUND;