From 3161f95c0aac3ed7d927b5bbfdb027b29d030555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berke=20Ak=C3=A7en?= Date: Thu, 2 May 2024 11:46:24 +0300 Subject: [PATCH] Check if package is relocated correctly to not conflict if any other plugin using that framework too --- .../commandframework/CommandFramework.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/me/despical/commandframework/CommandFramework.java b/src/main/java/me/despical/commandframework/CommandFramework.java index 77d725f..3341702 100644 --- a/src/main/java/me/despical/commandframework/CommandFramework.java +++ b/src/main/java/me/despical/commandframework/CommandFramework.java @@ -136,6 +136,8 @@ public class CommandFramework implements CommandExecutor, TabCompleter { public static String WAIT_BEFORE_USING_AGAIN = ChatColor.RED + "You have to wait {0}s before using this command again!"; public CommandFramework(@NotNull Plugin plugin) { + this.checkRelocation(); + if (instance != null) { throw new IllegalStateException("Instance already initialized!"); } @@ -157,6 +159,22 @@ public CommandFramework(@NotNull Plugin plugin) { } } + private void checkRelocation() { + String suppressRelocation = System.getProperty("commandframework.suppressrelocation"); + + if ("true".equals(suppressRelocation)) return; + + String defaultPackage = new String(new byte[] {'m', 'e', '.', 'd', 'e', 's', 'p', 'i', 'c', 'a', 'l', '.', + 'c', 'o', 'm', 'm', 'a', 'n', 'd', 'f', 'r', 'a', 'm', 'e', 'w', 'o', 'r', 'k'}); + + String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + String packageName = "me.despical.commandframework"; + + if (packageName.startsWith(defaultPackage) || packageName.startsWith(examplePackage)) { + throw new IllegalStateException("Command Framework has not been relocated correctly!"); + } + } + /** * For instance, can be used to translate Minecraft color and Hex color codes. *