Skip to content

Commit 3161f95

Browse files
committed
Check if package is relocated correctly to not conflict if any other plugin using that framework too
1 parent bdae5dc commit 3161f95

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/me/despical/commandframework/CommandFramework.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public class CommandFramework implements CommandExecutor, TabCompleter {
136136
public static String WAIT_BEFORE_USING_AGAIN = ChatColor.RED + "You have to wait {0}s before using this command again!";
137137

138138
public CommandFramework(@NotNull Plugin plugin) {
139+
this.checkRelocation();
140+
139141
if (instance != null) {
140142
throw new IllegalStateException("Instance already initialized!");
141143
}
@@ -157,6 +159,22 @@ public CommandFramework(@NotNull Plugin plugin) {
157159
}
158160
}
159161

162+
private void checkRelocation() {
163+
String suppressRelocation = System.getProperty("commandframework.suppressrelocation");
164+
165+
if ("true".equals(suppressRelocation)) return;
166+
167+
String defaultPackage = new String(new byte[] {'m', 'e', '.', 'd', 'e', 's', 'p', 'i', 'c', 'a', 'l', '.',
168+
'c', 'o', 'm', 'm', 'a', 'n', 'd', 'f', 'r', 'a', 'm', 'e', 'w', 'o', 'r', 'k'});
169+
170+
String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
171+
String packageName = "me.despical.commandframework";
172+
173+
if (packageName.startsWith(defaultPackage) || packageName.startsWith(examplePackage)) {
174+
throw new IllegalStateException("Command Framework has not been relocated correctly!");
175+
}
176+
}
177+
160178
/**
161179
* For instance, can be used to translate Minecraft color and Hex color codes.
162180
*

0 commit comments

Comments
 (0)