Skip to content

Commit

Permalink
Check if package is relocated correctly to not conflict if any other …
Browse files Browse the repository at this point in the history
…plugin using that framework too
  • Loading branch information
Despical committed May 2, 2024
1 parent bdae5dc commit 3161f95
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/me/despical/commandframework/CommandFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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.
*
Expand Down

0 comments on commit 3161f95

Please sign in to comment.